tibianmod / vuex-orm-decorators Goto Github PK
View Code? Open in Web Editor NEWDecorator Syntax for Vuex ORM for better type safety.
License: MIT License
Decorator Syntax for Vuex ORM for better type safety.
License: MIT License
ERROR Failed to compile with 1 errors
This relative module was not found:
- ./model in ./node_modules/vuex-orm-decorators/dist/index.js
The dist folder contains both Model.js
and model.js
(and map and ts files also) and this messes up (case insensitive) Windows.
I recently switched to using vuex-orm-decorators from the normal way. Now, I'm getting a Cannot read property 'localKey' of undefined
. Any ideas? I debugged the setup and thought this screenshot below might be helpful. It shows some of the classes not being imported correctly. This might not be a vuex-orm-decorators problem but do you have any suggestions for why this might be happening?
Stack Trace:
vuex-orm.esm.js:2592 Uncaught TypeError: Cannot read property 'localKey' of undefined
at Function.Model.belongsTo (vuex-orm.esm.js:2592)
at BelongsToField (attributes.js:79)
at eval (appUser.ts:20)
at Module../src/store/models/appUser.ts (app.js:1608)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (role.ts:9)
at Module../src/store/models/role.ts (app.js:1656)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
appUser.ts
import { Model } from "@vuex-orm/core";
import {
AttrField,
BelongsToField,
BelongsToManyField,
OrmModel,
PrimaryKey,
} from "vuex-orm-decorators";
import { Role } from "./role";
import { AppUserRole } from "./appUserRole";
import { App } from "./app";
import { User } from "./user";
@OrmModel("appUsers")
export class AppUser extends Model {
@PrimaryKey()
@AttrField(null)
id!: number;
@BelongsToField(App, "appId")
app!: App;
@AttrField(null)
appId!: number;
@AttrField(null)
createdDate!: Date;
@BelongsToManyField(Role, AppUserRole, "appUserId", "roleId")
roles!: Role[];
@AttrField(null)
updatedDate!: Date;
@BelongsToField(User, "userId")
user!: User;
@AttrField(null)
userId!: number;
}
app.ts
import { Model } from "@vuex-orm/core";
import {
AttrField,
HasManyField,
OrmModel,
PrimaryKey,
} from "vuex-orm-decorators";
import { AppRequest } from "./appRequest";
import { AppUser } from "./appUser";
import { Role } from "./role";
@OrmModel("apps")
export class App extends Model {
@PrimaryKey()
@AttrField(null)
id!: number;
@HasManyField(AppRequest, "appId")
appRequests!: AppRequest[];
@HasManyField(AppUser, "appId")
appUsers!: AppUser[];
@AttrField("")
description!: string;
@AttrField("")
longName!: string;
@HasManyField(AppUser, "appId")
roles!: Role[];
@AttrField("")
shortName!: string;
}
Hi,
the decorator for AttrField produces a string field. From attributes.ts, line 46:
export function AttrField(defaultValue?: any) {
return Field(Model.string(defaultValue));
}
I suggest this should be: Model.attr(defaultValue)
.
best regards,
Arno
Hi! I'm the author of Vuex ORM and just started implementing our own decorator feature. It's at https://github.com/vuex-orm/vuex-orm-decorator.
Then, I found out this repo! Sorry I didn't know. It looks wonderful! I would really love to have decorator feature in the Vuex ORM family.
If I may, I would like to invite you to the discussion for the repo. At least, credit you for this wonderful work.
If it sounds good to you, please ping me at Vuex ORM Slack channel! Or email me! ๐ค
I have 2 models; Setting
and FooSetting
. According to the docs I setup Single Table Inheritance the following way.
import { OrmModel, StringField } from 'vuex-orm-decorators';
import Setting from '@/models/Setting';
@OrmModel('foo-settings', 'settings', {
FOO: FooSetting,
GENERAL: Setting,
})
export class FooSetting extends Setting {
@StringField('')
test!: string;
}
export default FooSetting;
I get the following warning within the console.
[Vuex ORM] Model `FooSetting` extends `Setting` which doesn't overwrite Model.types(). You will not be able to use type mapping.
Am I implementing this correctly?
It should be work like other decorators, but cast date strings in ISO format to Date object.
I know what I can use {mutate: mutator} param of decorator params, but it is less clearly and less readable )))
class User extends Model {
static entity = 'users'
static fields () {
return {
id: this.uid(() => uuid())
}
}
}
Seems like there is no UidField
decorator?
Hi @Scotley,
the publishing jobs started to fail with the following error..
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/vuex-orm-decorators - Not found
npm ERR! 404
npm ERR! 404 '[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm
and re run the following job please to make sure is working again.
- Note: The workflow file is 100% correct, is not there the problem
I have already published 4 releases with this workflow
Please take care of it @Scotley :)
When I try to insert into the DB, I get the error TypeError: this.types is not a function
Entity looks like this
import { Model } from "@vuex-orm/core";
import { NumberField, OrmModel, StringField } from "vuex-orm-decorators";
@OrmModel("races")
export default class Race extends Model {
@NumberField()
public ID!: number;
@StringField()
public Name!: string;
}
store looks like this:
import Vue from "vue";
import Vuex from "vuex";
import { ORMDatabase } from "vuex-orm-decorators";
Vue.use(Vuex);
export default new Vuex.Store({
.
.
.
plugins: [ORMDatabase.install()]
});
Also, maybe this is a clue.... in Vuex-Orm, this.setters is returning a value, but this.setters('all') is returning undefined.
/**
* Get all records.
*/
Model.all = function () {
return this.getters('all')();
};
From seeing the undefined basic fields and functions, it seems like the vuex-orm database isn't getting set up correctly. Any ideas?
I also posted this on StackOverflow to see if other people have ideas.
https://stackoverflow.com/questions/59020879/typeerror-this-types-is-not-a-function-when-using-vuex-orm-decorators
Similar to this issue: vuex-orm/vuex-orm#724
vuex-orm 0.36.4 remove the /lib/ folder and only contains a dist. Some of the imports in this library do not work anymore. I tried to replace them with imports from /dist/src/โฆ
but had other issues (not sure if they were related).
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.