rapidjs / rapid.js Goto Github PK
View Code? Open in Web Editor NEWAn ORM-like Interface and a Router For Your API Requests
Home Page: https://rapidjs.drewjbartlett.com
An ORM-like Interface and a Router For Your API Requests
Home Page: https://rapidjs.drewjbartlett.com
I might be nitpicking here but since the classes return instances (objects) and not function constructors they should (per convention) not start with a Capital in the readme.
var Post = new Rapid({ modelName: 'Post' });
Post.find(1).then((response) => {
// GET => /api/post/1
});
Should be:
var post = new Rapid({ modelName: 'Post' });
post.find(1).then((response) => {
// GET => /api/post/1
});
By convention, functions that are intended to be used with new should be given names with initial capital letters, and names with initial capital letters should be used only with constructor functions that take the new prefix. This convention gives us a visual cue that can help spot expensive mistakes that the language itself is keen to overlook.
http://archive.oreilly.com/pub/a/javascript/excerpts/javascript-good-parts/bad-parts.html
The setters of the Core
class are wrongly typed in the declaration file index.d.ts
declare class Core {
debug: void;
baseURL: void;
modelName: void;
routeDelimiter: void;
caseSensitive: void;
}
Therefore the typescript compiler complains at the following code:
import { Rapid } from 'rapid.js';
class Resource extends Rapid {
boot() {
this.modelName = 'my-resource';
}
}
with the following error:
error TS2322: Type '"my-resource"' is not assignable to type 'void'
According to the defaults.js
they simply need to have this types defined:
declare class Core {
debug: boolean;
baseURL: string;
modelName: string;
routeDelimiter: string;
caseSensitive: boolean;
}
Run tsc -p .
tsconfig.json(49,5): error TS5023: Unknown compiler option 'esModuleInterop'.
src/auth.ts(36,33): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(36,65): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(41,33): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(41,66): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(46,33): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(46,64): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(51,33): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(51,68): error TS2339: Property 'auth' does not exist on type 'Config'.
src/auth.ts(55,24): error TS2339: Property 'auth' does not exist on type 'Config'.
src/core/core.ts(77,60): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Route'.
src/core/core.ts(133,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
src/core/custom-route.ts(4,10): error TS2339: Property 'route' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(11,10): error TS2339: Property 'config' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(25,51): error TS2339: Property 'config' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(28,46): error TS2339: Property 'config' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(70,17): error TS2339: Property 'route' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(79,17): error TS2339: Property 'route' does not exist on type 'CustomRoute'.
src/core/custom-route.ts(88,17): error TS2339: Property 'route' does not exist on type 'CustomRoute'.
src/core/request.ts(26,49): error TS2339: Property 'globalParameters' does not exist on type 'Config'.
src/core/request.ts(30,15): error TS2339: Property 'params' does not exist on type 'object'.
src/core/request.ts(30,57): error TS2339: Property 'globalParameters' does not exist on type 'Config'.
src/core/request.ts(45,5): error TS2322: Type 'string' is not assignable to type 'RequestType'.
src/core/request.ts(79,22): error TS2339: Property 'allowedRequestTypes' does not exist on type 'Config'.
src/core/request.ts(81,80): error TS2339: Property 'allowedRequestTypes' does not exist on type 'Config'.
src/core/request.ts(241,24): error TS2339: Property 'beforeRequest' does not exist on type 'Config'.
src/core/request.ts(251,17): error TS2339: Property 'afterRequest' does not exist on type 'Config'.
src/core/request.ts(261,17): error TS2339: Property 'onError' does not exist on type 'Config'.
src/core/url.ts(4,8): error TS6133: 'store' is declared but its value is never read.
src/core/url.ts(4,19): error TS2307: Cannot find module '../store/index'.
src/core/url.ts(28,21): error TS2339: Property 'extension' does not exist on type 'Config'.
src/core/url.ts(29,30): error TS2339: Property 'extension' does not exist on type 'Config'.
src/debug/debugger.ts(5,10): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(6,10): error TS2339: Property 'data' does not exist on type 'default'.
src/debug/debugger.ts(7,10): error TS2339: Property 'logEnabled' does not exist on type 'default'.
src/debug/debugger.ts(11,25): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(14,5): error TS2556: Expected 2-4 arguments, but got a minimum of 0.
src/debug/debugger.ts(16,14): error TS2339: Property 'logEnabled' does not exist on type 'default'.
src/debug/debugger.ts(17,12): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(17,40): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(18,12): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(21,10): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(30,22): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(30,47): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(32,32): error TS2339: Property 'params' does not exist on type '{}'.
src/debug/debugger.ts(35,22): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(35,47): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(38,20): error TS2339: Property 'caller' does not exist on type 'default'.
src/debug/debugger.ts(40,10): error TS2339: Property 'data' does not exist on type 'default'.
src/debug/debugger.ts(46,10): error TS2339: Property 'data' does not exist on type 'default'.
src/rapid.ts(4,1): error TS2304: Cannot find name 'module'.
src/rapid.ts(5,1): error TS2304: Cannot find name 'module'.
src/rapid.ts(6,1): error TS2304: Cannot find name 'module'.
Just stumbled onto this library. It is extremely interesting and fresh but its a shame that there doesn't seems to be a community around it. Adding a simple Gitter chatroom will a step in this direction.
This issue is for fixing all tests
npm run unit
Consider storing the response from the request in data object
Making a place to document the changes on V2
api
renamed to http
qs
for qs-stringify
since we only use that method https://www.npmjs.com/package/qs-stringifyENV
rapid.use(customRouter)
For people that prefer to work in typescript, would you be interested in adding type definitions? I can work on the PR if you are.
I see that there's no top level index.js
or even on in the src
folder that reexports Rapid
and Auth
. The docs suggest import Rapid from 'rapid.js';
which seems like it clearly won't work.
Am I missing something here?
Say I have a User model and that user has Notifications. It'd be nice to either say this:
class User extends Rapid {
boot () {
this.notifications = new Rapid({ childOf: this });
}
}
Or it'd be nice to:
let User = new Rapid({
modelName: 'user',
children: [{ modelName: 'notifications' }, { modelName: 'meta' }]
})
this would result in being able to do:
User.notifications.post('mark-as-read'); // => /api/user/notifications/mark-as-read
export default new Base({
routes: {
model: 'data/account/user',
collection: 'data/account/user'
},
suffixes: {
create: '',
update: '',
destroy: ''
},
methods: {
update: 'put',
destroy: 'delete'
}
});
Not work
await Phone.update(phone.id, phone);
await Phone.save(phone.id, phone);
Work
await Phone
.id(phone.id)
.withParams(phone)
.put();
Hi and thank you for rapid.js, it's awesome!
When a request is made using rapid, the entire response gets returned. While that may be correct in general I would like to have a way to return only the data.
Because usually the final methods that use my Api doesn't know anything, and should not, about the response. It only expect the data and if there is any error retrieving it, it is the Api Class the one that deals with it.
// current approach
const response = await ApiR.withParams(query).all()
data = response.data
// a not very good solution
const { data } = await ApiR.withParams(query).all()
I'm not sure about the best approach to solve it, perhaps a config or a new method, but would like to hear your thoughts.
Move debugger to separate repo
Hi
I tried, but it appends data into the URL. In my case it's not a valid way to call 'delete' api endpoint. How to achieve this - call custom route for delete with data?
When using rapid.js with TypeScript the compiler alerts about a missing name in the definition file.
Reproduce:
tsc index.d.ts
index.d.ts(80,10): error TS2304: Cannot find name 'AxiosInstance'.
Is there a way, or you planning to implement a config option where i can set a file extension prefix?
I wanted to try this library a project of mine, but the API (Redmine) which i'm using is not following the REST standards at all.
In my case, an url looks like this: //example.com/issues/3.json
or //example.com/users.json
so i always have to specify the file extension, but in the docs i have not found option to to do this.
Add the inverse of .destroy()
for any sort of softDeletes functionality.
I need to test my async actions for redux. With axios I could use moxios. What about this lib?
Hi, I am using rapid.js v1.0.11 and seems there is a bug.
const query = {...}
Api.withParams(query).all()
// sending Query string parameters - OK
const data = {...}
Api.withParams(data).post()
// sending Request Payload - OK
// sending Query string parameters from previous request - NOT OK
Or perhaps I am missing something...
api
renamed to http
apiConfig
to httpConfig
qs
for qs-stringify
since we only use that method https://www.npmjs.com/package/qs-stringify.default
helper to go with model
/ collection
photo.get('/tags', { order: orders.ASC })
.js
filesdeepmerge
instead of lodashwithData
to withConfig
qs-stringify
with old debuggeraxios
entirelyhttpConfig
from configdebug
from configprepublish
hook and replace with: Use prepare
for build steps and prepublishOnly
for upload-only.model
, collection
, default
I can add a contributing guide for this. But for now:
npm run unit:watch
while working on new features and fixes. Do you best to make small changes while always keeping the tests green.For now we can use issues or projects. @mgred I have not used projects for this but we can look into it!
Hi. Just stumbled upon this library and it looks really interesting.
One feature I would like to see is a CLI tool or a yeoman generator for building custom config files (similar to the config builder tool on the website) and custom routes which then could be instantly added to the project. Just a suggestion the would make the whole proces of building a routing even faster.
Thanks for your work so far.
package.json
.Error thrown on linux when booting a file that extends RapidJS.
Error: Cannot find module './core/rapid'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/lib/jenkins/workspace/vernight_highstreet_develop-Z4EJGYUMCGUJXLSZ5RREIJWO3ZYMIKFLYOSGEMPIHGYF6PMVVKIQ/node_modules/rapid.js/dist/rapid.js:3:14)
My dist folder looks like this:
Looks like a problem with case insensitivity
How to get a response from the server in "catch"?
model
.withParams(credentials)
.post()
.then((success) => {
/* Set data. */
commit('setUser', success.data.data.user);
})
.catch((error) => {
if (error.data.data.message) {
commit('setErrors', [error.data.data.message]);
}
});
Instead, the error object:
Error: Request failed with status code 422
at createError (D:\Projects\Desionlab\Alex south\fastPanel\terminal\Source\node_modules\axios\lib\core\createError.js:16)
at settle (D:\Projects\Desionlab\Alex south\fastPanel\terminal\Source\node_modules\axios\lib\core\settle.js:18)
at XMLHttpRequest.handleLoad (D:\Projects\Desionlab\Alex south\fastPanel\terminal\Source\node_modules\axios\lib\adapters\xhr.js:77)
Thanks in advance.
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.