Closed boumaza-samir closed 4 months ago
TypeError
indicates that you likely misconfigured your service.
Check if you're using ModelInstance
in your setupService
and replace with ServiceInstance
. More in the migration guides.
TypeError
indicates that you likely misconfigured your service.Check if you're using
ModelInstance
in yoursetupService
and replace withServiceInstance
. More in the migration guides.
Thank you for your reply ! Yes I used the migration guide and feather-pinia works in my project up to version 4.1.1 if I go to version 4.2.2 or higher I get the error on the createInStore
Then you need to provide a repro or at least more context about your setup
Ok, I found something interesting In createPiniaClient in setupInstance, we spread the data value as follows
export const api = createPiniaClient(feathersClient, {
pinia,
idField: 'id',
// optional
ssr: false,
whitelist: [],
defaultLimit: 100,
paramsForServer: [],
skipGetIfExists: false,
customSiftOperators: {},
syncWithStorage: false,
storage: window.localStorage,
setupInstance(data: AnyData): AnyData {
return {
id: undefined,
pathId: undefined,
created_at: undefined,
created_by: undefined,
updated_at: undefined,
updated_by: undefined,
deleted_at: undefined,
deleted_by: undefined,
...data, // <-- data spreaded
};
},
customizeStore(defaultStore: AnyData): AnyData {
return {};
},
If I return directly data it work
export const api = createPiniaClient(feathersClient, {
pinia,
idField: 'id',
// optional
ssr: false,
whitelist: [],
defaultLimit: 100,
paramsForServer: [],
skipGetIfExists: false,
customSiftOperators: {},
syncWithStorage: false,
storage: window.localStorage,
setupInstance(data: AnyData): AnyData { return data; },
customizeStore(defaultStore: AnyData): AnyData {
return {};
},
But I still don't know why the problem only appears with version 4.2.X ... If anyone has any idea where this problem might be coming from, it would be appreciated.
Some of the issues that immediately jump out:
setupInstance
in the root of your options will run for every single service... this seems unintentional.data
in your return, you are only returning the enumerable
properties, so you effectively throw away all of the methods (like createInStore
).data
object is of a ServiceInstance
type - by casting it to AnyData
you are losing all type inference, along with all the helpful error messages that would be warning you when you write bad code.Based on your snippets, simply removing your entire setupInstance
block should resolve the issue...
To customise individual services, add them under the services
key in options.
I warmly suggest re-reading the docs...
Thanks for your reply!
This code is historic I discovered it today ah ah it's done on purpose so that we have the created etc in all instances when I saw it I said to myself the same thing that it wasn't the best strategy just like anydata I'm going to delete that
When I do a service, I do it in a dedicated file, following the procedure in the documentation if I need to.
The thing I don't understand is that it should never work... But it only crashes in versions 4.2.X
Anyway I will close the issue thanks @gorango !
Hello everyone
I have a strange behaviour since version 4.2.X (last try 4.2.4) If I do a new and then do a
createInStore()
like thisI get the following error
Uncaught TypeError: instance.createInStore is not a function
In the return from new, there is no
createInStore()
If I do this
It works, but it's not the excepted behaviour I've never had a problem until now, I've been updating my project regularly since version 3.
Can't we use the createInStore function after a new in the 4.2.X?