Skip to content

Commit a98ce89

Browse files
committed
[PRETTIER] Apply prettier autoformatter
Turns out prettier is currently incompatible with the `onespace` colon rule of tslint, so I had to remove it, even though I prefer the onespace variety. Also hands off enforcement of semicolons to prettier instead of tslint.
1 parent a3cbd74 commit a98ce89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2963
-2561
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*.json

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ to install, so implementation is up to you. Here are two recommendations:
4343

4444
```js
4545
// node
46-
require('isomorphic-fetch')
46+
require("isomorphic-fetch")
4747
```
4848

4949
```js
5050
// browser
51-
import 'whatwg-fetch'
51+
import "whatwg-fetch"
5252
```
5353

5454
### JSON Web Tokens
@@ -60,22 +60,22 @@ during `Config.setup` and all subsequents will pass it using the
6060
```es6
6161
const ApplicationRecord = Model.extend({
6262
// code
63-
});
63+
})
6464

6565
const Person = ApplicationRecord.extend({
6666
// code
67-
});
67+
})
6868

6969
const Author = ApplicationRecord.extend({
7070
// code
71-
});
71+
})
7272

73-
Config.setup({ jwtOwners: [ApplicationRecord] });
73+
Config.setup({ jwtOwners: [ApplicationRecord] })
7474

75-
ApplicationRecord.jwt = 's0m3t0k3n';
76-
Author.all(); // sends JWT in Authorization header
77-
Author.getJWT(); // grabs from ApplicationRecord
78-
Author.setJWT('t0k3n'); // sets on ApplicationRecord
75+
ApplicationRecord.jwt = "s0m3t0k3n"
76+
Author.all() // sends JWT in Authorization header
77+
Author.getJWT() // grabs from ApplicationRecord
78+
Author.setJWT("t0k3n") // sets on ApplicationRecord
7979
```
8080

8181
This means you could define `OtherApplicationRecord`, whose

banner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
* @version ${version}
44
* @copyright (c) 2016 - ${author}
55
* @license MIT <${homepage}/blob/master/LICENSE>
6-
*/
6+
*/

docs/index.md

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,58 @@ Let's say we have a `/api/v1/people` endpoint:
1313
```js
1414
// es6 import syntax
1515
// vanilla JS would expose 'jsorm' as a global
16-
import 'isomorphic-fetch';
17-
import { Model, attr } from 'jsorm';
16+
import "isomorphic-fetch"
17+
import { Model, attr } from "jsorm"
1818

1919
var Person = Model.extend({
2020
static: {
21-
baseUrl: 'http://localhost:3000', // set to '' in browser for relative URLs
22-
apiNamespace: '/api/v1',
23-
jsonapiType: 'people'
21+
baseUrl: "http://localhost:3000", // set to '' in browser for relative URLs
22+
apiNamespace: "/api/v1",
23+
jsonapiType: "people"
2424
},
2525

2626
firstName: attr(),
2727
lastName: attr()
28-
});
28+
})
2929
```
3030

3131
Alternatively, in Typescript:
3232

3333
```ts
3434
// typescript
3535
class Person extends Model {
36-
static baseUrl = 'http://localhost:3000';
37-
static apiNamespace = '/api/v1';
38-
static jsonapiType = 'people';
36+
static baseUrl = "http://localhost:3000"
37+
static apiNamespace = "/api/v1"
38+
static jsonapiType = "people"
3939

40-
firstName = attr();
41-
lastName = attr();
40+
firstName = attr()
41+
lastName = attr()
4242
}
4343
```
4444

45-
**NOTE**: *Once your models are defined, you must call `Config.setup()`:
45+
**NOTE**: \*Once your models are defined, you must call `Config.setup()`:
4646

4747
```js
48-
import { Config } from 'jsorm';
49-
Config.setup();
48+
import { Config } from "jsorm"
49+
Config.setup()
5050
```
5151

5252
### ES6/Typescript Classes
5353

5454
ES6 and TypeScript classes do not have an `inherited` hook. Because this hook provides critical functionality, you have three options:
5555

5656
* Edit your `.tsconfig`:
57+
5758
* Set `target` to `es5`.
5859
* Add `noEmitHelpers: "true"`
59-
60+
6061
* Call the inherited hook manually after each class definition:
62+
6163
```ts
6264
class Author extends Person { ... }
6365
Person.inherited(Author);
6466
```
65-
67+
6668
* Use the `let Person = Model.extend({ ... })` pattern shown above instead of native classes.
6769

6870
## Basic Usage
@@ -79,17 +81,24 @@ Call `all()`, `first()`, or `find()` to actually fire the query.
7981
All of the following examples can be chained together:
8082

8183
```js
82-
let scope = new Person();
84+
let scope = new Person()
8385
if (should_include_admins) {
84-
scope = scope.where({ admin: true });
86+
scope = scope.where({ admin: true })
8587
}
86-
scope.all().then((people) => {
87-
people.data.map((p) => { return p.firstName; }); // => ['Joe', 'Jane', 'Bill']
88-
});
89-
90-
scope.page(2).all().then((people) => {
91-
people.data.map((p) => { return p.firstName; }); // => ['Chris', 'Sarah', 'Ben']
92-
});
88+
scope.all().then(people => {
89+
people.data.map(p => {
90+
return p.firstName
91+
}) // => ['Joe', 'Jane', 'Bill']
92+
})
93+
94+
scope
95+
.page(2)
96+
.all()
97+
.then(people => {
98+
people.data.map(p => {
99+
return p.firstName
100+
}) // => ['Chris', 'Sarah', 'Ben']
101+
})
93102
```
94103

95104
### Pagination
@@ -99,7 +108,9 @@ scope.page(2).all().then((people) => {
99108
Use `per` and `page`. To limit 10 per page, viewing the second page:
100109

101110
```js
102-
Person.per(10).page(2).all();
111+
Person.per(10)
112+
.page(2)
113+
.all()
103114
```
104115

105116
> GET /people?page[number]=2&page[size]=10
@@ -113,15 +124,15 @@ Use `order`. Passing an attribute will default to ascending order.
113124
Ascending:
114125

115126
```js
116-
Person.order('name');
127+
Person.order("name")
117128
```
118129

119130
> GET /people?sort=name
120131
121132
Descending:
122133

123134
```js
124-
Person.order({ name: 'desc' });
135+
Person.order({ name: "desc" })
125136
```
126137

127138
> GET /people?sort=-name
@@ -133,23 +144,25 @@ Person.order({ name: 'desc' });
133144
Use `where`:
134145

135146
```js
136-
Person.where({ name: 'Joe' }).where({ age: 30 }).all();
147+
Person.where({ name: "Joe" })
148+
.where({ age: 30 })
149+
.all()
137150
```
138151

139152
> GET /people?filter[name]=Joe&filter[age]=30
140153
141154
Filters are based on swagger documentation, not object attributes. This means you can do stuff like:
142155

143156
```js
144-
Person.where({ age_greater_than: 30 }).all();
157+
Person.where({ age_greater_than: 30 }).all()
145158
```
146159

147160
> GET /people?filter[age_greater_than]=30
148161
149162
Arrays are supported automatically, defaulting to an OR clause:
150163

151164
```js
152-
Person.where({ name: ['Joe', 'Bill'] }).all();
165+
Person.where({ name: ["Joe", "Bill"] }).all()
153166
```
154167

155168
> GET /people?&filter[name][]=Joe&filter[name][]=Bill
@@ -161,7 +174,7 @@ Person.where({ name: ['Joe', 'Bill'] }).all();
161174
Use `select`:
162175

163176
```js
164-
Person.select({ people: ['name', 'age'] }).all();
177+
Person.select({ people: ["name", "age"] }).all()
165178
```
166179

167180
> GET /people?fields[people]=name,age
@@ -173,7 +186,7 @@ This functionality is enabled by [jsonapi_suite](https://jsonapi-suite.github.io
173186
Use `selectExtra`:
174187

175188
```js
176-
Person.selectExtra({ people: ['name', 'age'] }).all();
189+
Person.selectExtra({ people: ["name", "age"] }).all()
177190
```
178191

179192
> GET /people?extra_fields[people]=name,age
@@ -187,17 +200,21 @@ Use `includes`. This can be a symbol, array, hash, or combination of all. In sho
187200
```js
188201
// a person has many tags, and has many pets
189202
// a pet has many toys, and many tags
190-
Person.includes(['tags', { pets: ['toys', 'tags'] }]);
203+
Person.includes(["tags", { pets: ["toys", "tags"] }])
191204
```
192205

193206
> GET /people?include=tags,pets.toys,pets.tags
194207
195208
The included resources will now be present:
196209

197210
```js
198-
Person.includes('tags').all().then((person) => {
199-
person.data.tags.map((t) => { return t.name; }); // #=> ['funny', 'smart']
200-
});
211+
Person.includes("tags")
212+
.all()
213+
.then(person => {
214+
person.data.tags.map(t => {
215+
return t.name
216+
}) // #=> ['funny', 'smart']
217+
})
201218
```
202219

203220
> GET /people?include=tags
@@ -207,7 +224,7 @@ Person.includes('tags').all().then((person) => {
207224
`all`, `first`, and `find` can be used in conjunction with scopes.
208225

209226
```js
210-
Person.all();
227+
Person.all()
211228
```
212229

213230
> GET /people
@@ -223,9 +240,11 @@ Use `first` to grab the first result:
223240

224241
```js
225242
// Limits per_page to 1, result is first element in the array
226-
Person.where({ name: 'Bill' }).first().then((person) => {
227-
// ...
228-
});
243+
Person.where({ name: "Bill" })
244+
.first()
245+
.then(person => {
246+
// ...
247+
})
229248
```
230249

231250
> GET /people?page[size]=1&page[number]=1&filter[name]=Bill
@@ -237,11 +256,11 @@ Finally, use `find` to find a record by ID. This will hit the `show` action.
237256
By default we will use `console` to log to STDOUT (or the browser's console log). If you are using node and want more in-depth options, inject another logger (we suggest [winston](https://github.com/winstonjs/winston)):
238257

239258
```js
240-
import { Config } from 'jsorm';
241-
let winston = require('winston');
259+
import { Config } from "jsorm"
260+
let winston = require("winston")
242261

243-
winston.level = 'warn';
244-
Config.logger = winston;
262+
winston.level = "warn"
263+
Config.logger = winston
245264
```
246265

247266
This will log colorized request/responses when the log_level is debug, and only the request when the log level is info.

esm-shims/clonedeep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as cloneDeep } from 'lodash-es/cloneDeep'
1+
export { default as cloneDeep } from "lodash-es/cloneDeep"

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"lint:tests": "tslint test/**/*.test.ts test/**/*.test.tsx",
2828
"update:dependencies": "ncu -u"
2929
},
30+
"prettier": {
31+
"semi": false
32+
},
3033
"devDependencies": {
3134
"@types/chai": "^4.0.4",
3235
"@types/chai-as-promised": "^7.1.0",
@@ -51,6 +54,7 @@
5154
"chai-things": "^0.2.0",
5255
"es6-promise": "^4.0.5",
5356
"fetch-mock": "^5.10.0",
57+
"husky": "0.14.3",
5458
"isomorphic-fetch": "^2.2.1",
5559
"istanbul": "0.4.5",
5660
"mocha": "^4.0.1",

rollup.config.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
import { readFileSync } from 'fs';
2-
import uglify from 'rollup-plugin-uglify';
3-
import commonjs from 'rollup-plugin-commonjs';
4-
import resolve from 'rollup-plugin-node-resolve';
1+
import { readFileSync } from "fs"
2+
import uglify from "rollup-plugin-uglify"
3+
import commonjs from "rollup-plugin-commonjs"
4+
import resolve from "rollup-plugin-node-resolve"
55

6-
const pkg = require('./package.json')
6+
const pkg = require("./package.json")
77

8-
const isProduction = process.env.NODE_ENV === 'production';
8+
const isProduction = process.env.NODE_ENV === "production"
99

10-
const banner = readFileSync( 'banner.js', 'utf-8' )
11-
.replace( '${name}', pkg.name )
12-
.replace( '${version}', pkg.version )
13-
.replace( '${author}', pkg.author )
14-
.replace( '${homepage}', pkg.homepage )
10+
const banner = readFileSync("banner.js", "utf-8")
11+
.replace("${name}", pkg.name)
12+
.replace("${version}", pkg.version)
13+
.replace("${author}", pkg.author)
14+
.replace("${homepage}", pkg.homepage)
1515

1616
export default {
1717
input: pkg.module,
1818
plugins: [
1919
isProduction ? uglify({}) : {},
2020
resolve(),
21-
commonjs({ include: './node_modules/**' }),
21+
commonjs({ include: "./node_modules/**" })
2222
],
23-
banner: banner,
23+
banner: banner,
2424
sourceMap: false,
2525
name: pkg.name,
2626
output: [
2727
{
28-
file: `./dist/${pkg.name}.${isProduction ? 'min.js' : 'js'}`,
29-
format: 'umd'
28+
file: `./dist/${pkg.name}.${isProduction ? "min.js" : "js"}`,
29+
format: "umd"
3030
}
3131
]
32-
};
33-
32+
}

0 commit comments

Comments
 (0)