tailflow / laravel-orion-ts Goto Github PK
View Code? Open in Web Editor NEWTypeScript SDK for Laravel Orion
TypeScript SDK for Laravel Orion
First of all, thank you for making this library, I love working with it.
Issue description:
When making a request with trailing slash api/somemodel/
, the web server respond with 301 Moved Permanently
this will result in losing the data when you make a post request.
I'm using Laravel 8 and apache.
The only other way to solve this that I know of is changing your .htaccess.
See these issues:
laravel/framework#32955
laravel/framework#23
https://stackoverflow.com/questions/18934588/json-giving-301-moved-permanently
https://stackoverflow.com/questions/48805861/laravel-301-moved-permanently-from-disk-cache
Hi, thanks for this amazing package!
Is it possible to create a model instance from some JSON data? We store some user-specific data in the local storage and would be nice to call say user.projects.store({...})
w/o having to populate the user object from the API every time.
I've seen the Model class constructor takes optional attributes and relations (https://github.com/tailflow/laravel-orion-ts/blob/main/src/model.ts#L19) , but I'm not sure how that would work. Could you please let me know if this scenario is supported or if there's a better alternative?
Thanks!
Thank you for the great project. Do you have any plan to implement batch support?
https://tailflow.github.io/laravel-orion-docs/v2.x/guide/batch-operations.html#batch-store
Please add an ability to use Alova.js instead Axios for Orion.makeHttpClientUsing(...)
Something like that:
makeHttpClientUsing(callback: () => AxiosInstance | Alova): Orion;
Orion.makeHttpClientUsing(() => {
// 1. Create an alova instance
const alovaInstance = createAlova({
// ReactHook is used to create ref status, including request status loading, response data data, request error object error, etc.
statesHook: ReactHook,
// request adapter, it is recommended to use the fetch request adapter
requestAdapter: GlobalFetch()
});
return alovaInstance;
});
Hi,
I was running into some learning with this awesome TS Sdk. And I ran into an issue regarding GET requests (find() and get()) for models.
Both requests find()
and get()
I'm getting an [Error: Network Error]
.
And every other method is working fine.
After some research, I found some issues in the axios repository, saying about the data
option for the request. When being data: "{}"
this error should happen.
I've added a transformRequest, to test it (like some devs reported in the issue from axios repo, and I was able to successfully get the data I want.. like the code below:
// Orion init and set token here...
// setting data = undefined like mentioned in the issue
const cfg = Orion.getHttpClientConfig();
cfg.transformRequest = [
(data, headers) => {
return undefined;
},
];
Orion.setHttpClientConfig(cfg);
// and then, my find request
Employee.$query()
.find('f2d827a8-6e65-4bbf-ae35-d6a14b7adc27')
.then((employeeProfile) =>
console.log(JSON.stringify(employeeProfile.$attributes, null, 2)),
)
.catch((e) => {
console.log(e); // No error, when data=undefined in the transformRequest
});
it resolves the promise, and logs the result:
{
"id": "f2d827a8-6e65-4bbf-ae35-d6a14b7adc27",
"name": "Rodrigo Brun",
"email": "[email protected]",
"companies": []
}
This "solves" the problem for both find()
and get()
. But will get some inconsistencies with other requests methods of course. But it is just a test.
My question is, is there already some work around for this? Like, sending undefined
to data
when using GET requests. At least until axios should fix this issue with something ?
--
My axios": "^0.21.1",
And I'm testing this in a react-native project, in iOS device. (not tested on the web, or Android)
Thanks.
Is it possible to make the data returned from orion-ts queries reactive in a Vue3 project? Currently if I update MyModel.$attributes.some_attribute, changes aren't picked up by reactivity in vue. I've tried wrapping instances of MyModal in reactive(MyModel) but that doesn't help. Sorry if this is more of a noob Vue reactivity question than an issue with orion-ts but just hoping to get some help!
Hello.
How can I receive meta information for pagination like current_page, last_page after model.$query.get() request?
This information stored in every element of array but it seems to me that this is not the right solution.
Thanks.
Hi,
I'm evaluating Orion for a new project. It looks very promising so far. I am wondering if you have any plans to enable automatic generation of the API client that matches the actual models in Laravel without the need to manually specify the attributes?
It looks like most of the parts are there: an OpenAPI spec that knows the models and code that knows how to handle communication with the API.
This last piece would make Orion the ultimate one and only super power API package for Laravel. ๐ค๐
Is there any way to configure a relation that is the same model type to use a different resource url when using it as a relation. e.g. With the model below I want to the relationship url to be /api/paddocks/{paddock_id}/prior_paddocks/sync however the SDK attempting to use /api/paddocks/{paddock_id}/paddocks/sync
export default class Paddock extends Model<{
id: number
...
},
DefaultPersistedAttributes > {
public $resource (): string {
return 'paddocks'
}
...
public prior_paddocks (): BelongsToMany {
return new BelongsToMany(Paddock, this)
}
...}
Hi,
I've just discovered your library and I really think It worth to try it :)
I'm facing issue with Next.js compatibility. So I quickly tried with a CRA, it does work without any problem
import logo from './logo.svg';
import './App.css';
import {Orion} from "@tailflow/laravel-orion/lib/orion";
Orion.init('https://your-api.test');
Orion.setToken('access-token-here');
function App() {
console.debug(Orion.getToken())// Will output 'access-token-here' as expected
return (
<div className="App">[...]</div>
);
}
export default App;
With a Next.js, I got the error SyntaxError: Cannot use import statement outside a module
.
Some related issues:
Digging deeper, I found this: https://stackoverflow.com/questions/62422174/cannot-use-import-statement-outside-a-module-with-next-js (answer: https://stackoverflow.com/a/62423865/2098861) ;
Related issue, if I understand it correctly:
Could you take a look and make your library compatible both server&client side (if it's not really the case)?
In the meantime, I'm trying the "dynamic" imports or "useEffect" with import inside (found in related issues linked above).
I don't know how to help more, but ask if you need more details / help / reproducible example...
Thanks,
Regards.
Edit: looking further, it seems that the problem is more on next.js side than on libraries...
I have a project made with NuxtJs.
I want to know if is it possible to build the project ts to javascript and import, configure and use in my project Js?
After updating to v3.3.0 from v2.1.2 requests that were being made correctly before were all being made to the url of, and with all the scope and filter options of the last called models search method. Given the below functions
const fetchPaddocks = async () => {
repo.flush()
const response = await orionPaddock.$query().scope('PeriodIdIn', [[app.currentPeriodId, app.priorPeriod.id]]).search(0)
repo.insert(response.map(m => m.$attributes))
}
const fetchPriorPaddocks = async () => {
priorRepo.flush()
const priorResponse = await orionPaddockPriorPaddock.$query().scope('PeriodIdIn', [[app.currentPeriodId]]).search(0)
priorRepo.insert(priorResponse.map(m => m.$attributes))
}
Calling it this way works.
await fetchPaddocks()
await fetchPriorPaddocks()
Calling it this way results in two requests made to the orionPaddockPriorPaddock endpoint, with the scope payload of that query, for both of the orionPaddock and orionPaddockPriorPaddock search calls. This doesn't occur if calling get() on the orion models instead of search.
fetchPaddocks()
fetchPriorPaddocks()
I can't find a way to access axios instance, is the there anyway I can add interceptor?
When relation return null
we have error: Cannot convert undefined or null to object
in hydrate method
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.