Skip to content

Commit a1b7de0

Browse files
romtorresphortx
andauthored
feat: compatibility with vue-orm-0.36 (#143)
* trivial upgrades * upgrade some dev dependencies * feat: compatibility with vue-orm-0.36 BREAKING CHANGE: `incremental` is now obsolete `uid` must be use instead * uid for Tariff more tests compatible with vue-orm 0.36 * regex $uid + clean orm store * wip * add more tests * Fix async * Fix linting * yarn * Tiny tweaks * Fix many to many test * Fix polymorphic many to many test * Fix test-utils * Fix unit tests * Remove .DS_Store * Fix build * Remove .DS_Store * Revert change * Revert change * Remove comment Co-authored-by: phortx <[email protected]>
1 parent 490532e commit a1b7de0

31 files changed

+7206
-5023
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ compiled
7272

7373
/dist/lib
7474
/dist/types
75+
76+
.DS_Store

package.json

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
"name": "@vuex-orm/plugin-graphql",
33
"version": "1.0.0-rc.36",
44
"description": "Vuex-ORM persistence plugin to sync the store against a GraphQL API.",
5-
"main": "dist/vuex-orm-graphql.umd.js",
6-
"module": "dist/vuex-orm-graphql.es5.js",
5+
"main": "dist/vuex-orm-graphql.cjs.js",
6+
"browser": "dist/vuex-orm-graphql.esm.js",
7+
"module": "dist/vuex-orm-graphql.esm-bundler.js",
8+
"unpkg": "dist/vuex-orm-graphql.global.js",
79
"typings": "dist/types/index.d.ts",
810
"files": [
911
"dist"
1012
],
1113
"scripts": {
1214
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
13-
"prebuild": "rimraf dist",
14-
"build": "tsc --module commonjs && rollup -c rollup.config.ts && npm run build:docs",
15+
"build": "node scripts/build.js && npm run build:docs",
1516
"build:docs": "vuepress build docs",
1617
"start": "rollup -c rollup.config.ts -w",
1718
"test": "jest",
@@ -52,21 +53,20 @@
5253
"url": "https://github.com/vuex-orm/plugin-graphql/issues"
5354
},
5455
"dependencies": {
55-
"apollo-cache-inmemory": "^1.1.7",
56+
"apollo-cache-inmemory": "^1.6.5",
5657
"app": "latest"
5758
},
5859
"peerDependencies": {
59-
"@vuex-orm/core": "^0.31.12"
60+
"@vuex-orm/core": "^0.36.3"
6061
},
6162
"devDependencies": {
62-
"@commitlint/cli": "^7.1.2",
63-
"@commitlint/config-conventional": "^7.1.2",
64-
"@types/graphql": "^14.2.0",
65-
"@types/jest": "^23.3.2",
66-
"@types/node": "^10.11.0",
67-
"@types/sinon": "^5.0.1",
68-
"@vuex-orm/core": "^0.31.12",
69-
"apollo-client": "^2.2.2",
63+
"@commitlint/cli": "^8.3.5",
64+
"@commitlint/config-conventional": "^8.3.4",
65+
"@types/jest": "^25.2.1",
66+
"@types/node": "^13.11.0",
67+
"@types/sinon": "^9.0.0",
68+
"@vuex-orm/core": "^0.36.3",
69+
"apollo-client": "^2.6.8",
7070
"apollo-link": "^1.2.0",
7171
"apollo-link-http": "^1.3.2",
7272
"apollo-link-schema": "^1.1.0",
@@ -78,12 +78,12 @@
7878
"cross-env": "^5.2.0",
7979
"cross-fetch": "^3.0.2",
8080
"cz-conventional-changelog": "^2.1.0",
81-
"graphql": "^0.12.3",
82-
"graphql-tag": "^2.6.1",
83-
"graphql-tools": "^3.0.4",
81+
"graphql": "^14.6.0",
82+
"graphql-tag": "^2.10.2",
83+
"graphql-tools": "^4.0.7",
8484
"husky": "^1.0.1",
85-
"jest": "^23.6.0",
86-
"jest-config": "^23.6.0",
85+
"jest": "^25.2.7",
86+
"jest-config": "^25.2.7",
8787
"lint-staged": "^7.3.0",
8888
"lodash.clone": "^4.5.0",
8989
"lodash.isequal": "^4.5.0",
@@ -94,24 +94,23 @@
9494
"prompt": "^1.0.0",
9595
"replace-in-file": "^3.4.2",
9696
"rimraf": "^2.6.2",
97-
"rollup": "^0.66.2",
98-
"rollup-plugin-babel": "^3.0.7",
99-
"rollup-plugin-commonjs": "^9.1.8",
100-
"rollup-plugin-json": "^3.1.0",
101-
"rollup-plugin-node-resolve": "^3.4.0",
102-
"rollup-plugin-sourcemaps": "^0.4.2",
103-
"rollup-plugin-typescript2": "^0.17.0",
104-
"rollup-plugin-uglify": "^3.0.0",
97+
"rollup": "^2.3.2",
98+
"@rollup/plugin-commonjs": "^11.0.2",
99+
"@rollup/plugin-node-resolve": "^7.1.1",
100+
"rollup-plugin-terser": "^5.3.0",
101+
"rollup-plugin-typescript2": "^0.27.0",
102+
"brotli": "^1.3.2",
105103
"sinon": "^6.0.0",
106-
"ts-jest": "^23.10.2",
107-
"ts-node": "^7.0.1",
108-
"tslint": "^5.11.0",
104+
"ts-jest": "^25.3.1",
105+
"ts-node": "^8.8.2",
106+
"tslint": "^6.1.1",
109107
"tslint-config-prettier": "^1.15.0",
110-
"tslint-config-standard": "^8.0.1",
111-
"typescript": "^3.0.3",
112-
"vue": "2.5.16",
113-
"vuepress": "^0.14.11",
114-
"vuex": "^3.0.1"
108+
"tslint-config-standard": "^9.0.0",
109+
"typescript": "^3.8.3",
110+
"vue": "^2.6.11",
111+
"vue-server-renderer": "^2.6.11",
112+
"vuepress": "^1.3.0",
113+
"vuex": "^3.1.3"
115114
},
116115
"jest": {
117116
"transform": {

rollup.config.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import path from 'path'
2+
import resolve from '@rollup/plugin-node-resolve'
3+
import commonjs from '@rollup/plugin-commonjs'
4+
import ts from 'rollup-plugin-typescript2'
5+
import { terser } from 'rollup-plugin-terser'
6+
7+
const configs = [
8+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.esm.js', format: 'es', browser: true, env: 'development' },
9+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.esm.prod.js', format: 'es', browser: true, env: 'production' },
10+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.esm-bundler.js', format: 'es', env: 'development' },
11+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.global.js', format: 'iife', env: 'development' },
12+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.global.prod.js', format: 'iife', minify: true, env: 'production' },
13+
{ input: 'src/index.ts', file: 'dist/vuex-orm-graphql.cjs.js', format: 'cjs', env: 'development' }
14+
]
15+
16+
function createEntries() {
17+
return configs.map((c) => createEntry(c))
18+
}
19+
20+
function createEntry(config) {
21+
const c = {
22+
input: config.input,
23+
plugins: [],
24+
output: {
25+
file: config.file,
26+
format: config.format,
27+
globals: {
28+
vue: 'Vue'
29+
}
30+
},
31+
onwarn: (msg, warn) => {
32+
if (!/Circular/.test(msg)) {
33+
warn(msg)
34+
}
35+
}
36+
}
37+
38+
if (config.format === 'iife') {
39+
c.output.name = 'VuexORMGraphQLPlugin'
40+
}
41+
42+
c.plugins.push(resolve())
43+
c.plugins.push( commonjs({
44+
exclude: ['node_modules/symbol-observable/es/*.js'],
45+
}))
46+
47+
c.plugins.push(ts({
48+
check: config.format === 'es' && config.browser && config.env === 'development',
49+
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
50+
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
51+
tsconfigOverride: {
52+
compilerOptions: {
53+
declaration: config.format === 'es' && config.browser && config.env === 'development',
54+
target: config.format === 'iife' || config.format === 'cjs' ? 'es5' : 'es2018'
55+
},
56+
exclude: ['test']
57+
}
58+
}))
59+
60+
if (config.minify) {
61+
c.plugins.push(terser({ module: config.format === 'es' }))
62+
}
63+
64+
return c
65+
}
66+
67+
export default createEntries()

rollup.config.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

scripts/build.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require('fs-extra')
2+
const chalk = require('chalk')
3+
const execa = require('execa')
4+
const { gzipSync } = require('zlib')
5+
const { compress } = require('brotli')
6+
7+
const files = [
8+
'dist/vuex-orm-graphql.esm.js',
9+
'dist/vuex-orm-graphql.esm.prod.js',
10+
'dist/vuex-orm-graphql.esm-bundler.js',
11+
'dist/vuex-orm-graphql.global.js',
12+
'dist/vuex-orm-graphql.global.prod.js',
13+
'dist/vuex-orm-graphql.cjs.js'
14+
]
15+
16+
async function run() {
17+
await build()
18+
checkAllSizes()
19+
}
20+
21+
async function build() {
22+
await fs.remove('dist')
23+
24+
await execa('rollup', ['-c', 'rollup.config.js'], { stdio: 'inherit' })
25+
}
26+
27+
function checkAllSizes() {
28+
console.log()
29+
files.map((f) => checkSize(f))
30+
console.log()
31+
}
32+
33+
function checkSize(file) {
34+
const f = fs.readFileSync(file)
35+
const minSize = (f.length / 1024).toFixed(2) + 'kb'
36+
const gzipped = gzipSync(f)
37+
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
38+
const compressed = compress(f)
39+
const compressedSize = (compressed.length / 1024).toFixed(2) + 'kb'
40+
console.log(
41+
`${chalk.gray(
42+
chalk.bold(file)
43+
)} size:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
44+
)
45+
}
46+
47+
run()

src/common/context.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Logger from "./logger";
22
import Model from "../orm/model";
33
import { Model as ORMModel } from "@vuex-orm/core";
4-
import { Components } from "@vuex-orm/core/lib/plugins/use";
4+
import { PluginComponents } from "@vuex-orm/core/lib/plugins/use";
55
import { downcaseFirstLetter, isEqual, pick, singularize } from "../support/utils";
66
import Apollo from "../graphql/apollo";
77
import Database from "@vuex-orm/core/lib/database/Database";
@@ -26,9 +26,9 @@ export default class Context {
2626

2727
/**
2828
* Components collection of Vuex-ORM
29-
* @type {Components}
29+
* @type {PluginComponents}
3030
*/
31-
public readonly components: Components;
31+
public readonly components: PluginComponents;
3232

3333
/**
3434
* The options which have been passed to VuexOrm.install
@@ -99,10 +99,10 @@ export default class Context {
9999
* Private constructor, called by the setup method
100100
*
101101
* @constructor
102-
* @param {Components} components The Vuex-ORM Components collection
102+
* @param {PluginComponents} components The Vuex-ORM Components collection
103103
* @param {Options} options The options passed to VuexORM.install
104104
*/
105-
private constructor(components: Components, options: Options) {
105+
private constructor(components: PluginComponents, options: Options) {
106106
this.components = components;
107107
this.options = options;
108108

@@ -127,11 +127,11 @@ export default class Context {
127127

128128
/**
129129
* This is called only once and creates a new instance of the Context.
130-
* @param {Components} components The Vuex-ORM Components collection
130+
* @param {PluginComponents} components The Vuex-ORM Components collection
131131
* @param {Options} options The options passed to VuexORM.install
132132
* @returns {Context}
133133
*/
134-
public static setup(components: Components, options: Options): Context {
134+
public static setup(components: PluginComponents, options: Options): Context {
135135
this.instance = new Context(components, options);
136136

137137
this.instance.apollo = new Apollo();

src/graphql/transformer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ export default class Transformer {
216216
// Ignore internal fields
217217
if (fieldName.startsWith("$")) return false;
218218

219+
// Ignore pivot objects
220+
if (fieldName === "pivot") return false;
221+
219222
// Ignore empty fields
220223
if (value === null || value === undefined) return false;
221224

src/orm/model.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ export default class Model {
6767
if (!field) return false;
6868

6969
const context = Context.getInstance();
70-
return (
71-
field instanceof context.components.Number || field instanceof context.components.Increment
72-
);
70+
// Remove UID cause it must be a string
71+
return field instanceof context.components.Number;
7372
}
7473

7574
/**
@@ -81,7 +80,7 @@ export default class Model {
8180
const context = Context.getInstance();
8281

8382
return (
84-
field instanceof context.components.Increment ||
83+
field instanceof context.components.Uid ||
8584
field instanceof context.components.Attr ||
8685
field instanceof context.components.String ||
8786
field instanceof context.components.Number ||
@@ -258,10 +257,10 @@ export default class Model {
258257

259258
/**
260259
* Returns a record of this model with the given ID.
261-
* @param {number} id
260+
* @param {string} id
262261
* @returns {any}
263262
*/
264-
public getRecordWithId(id: number) {
263+
public getRecordWithId(id: string) {
265264
return this.baseModel
266265
.query()
267266
.withAllRecursive()

0 commit comments

Comments
 (0)