Skip to content

Commit 64198d2

Browse files
committed
Update dependencies
1 parent 6c5a0cb commit 64198d2

8 files changed

+1404
-1297
lines changed

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"repository": "https://github.com/tchak/orbit-sql",
1616
"license": "MIT",
1717
"dependencies": {
18-
"@orbit/data": "^0.16.3",
18+
"@orbit/data": "^0.16.5",
1919
"inflected": "^2.0.4",
20-
"knex": "^0.20.2",
21-
"objection": "^1.6.11"
20+
"knex": "^0.21.1",
21+
"objection": "^2.1.3"
2222
},
2323
"scripts": {
2424
"build": "rm -rf ./dist && tsc",
@@ -29,19 +29,19 @@
2929
},
3030
"devDependencies": {
3131
"@types/inflected": "^1.1.29",
32-
"@types/node": "^12.12.12",
33-
"@types/qunit": "^2.9.0",
34-
"@typescript-eslint/eslint-plugin": "^2.8.0",
35-
"@typescript-eslint/parser": "^2.8.0",
36-
"eslint": "^6.7.0",
37-
"eslint-config-prettier": "^6.7.0",
38-
"eslint-plugin-prettier": "^3.1.1",
39-
"prettier": "^1.19.1",
32+
"@types/node": "^13.13.4",
33+
"@types/qunit": "^2.9.1",
34+
"@typescript-eslint/eslint-plugin": "^2.30.0",
35+
"@typescript-eslint/parser": "^2.30.0",
36+
"eslint": "^6.8.0",
37+
"eslint-config-prettier": "^6.11.0",
38+
"eslint-plugin-prettier": "^3.1.3",
39+
"prettier": "^2.0.5",
4040
"qunit": "^2.9.3",
41-
"release-it": "^12.4.3",
42-
"sqlite3": "^4.1.0",
43-
"ts-node": "^8.5.2",
44-
"typescript": "^3.7.2"
41+
"release-it": "^13.5.7",
42+
"sqlite3": "^4.2.0",
43+
"ts-node": "^8.9.1",
44+
"typescript": "^3.8.3"
4545
},
4646
"publishConfig": {
4747
"access": "public",

src/build-models.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import {
22
Model,
33
ModelClass,
44
RelationMapping,
5-
snakeCaseMappers
5+
snakeCaseMappers,
66
} from 'objection';
77
import {
88
Schema,
99
RecordNotFoundException,
1010
RecordRelationship,
11-
Record as OrbitRecord
11+
Record as OrbitRecord,
1212
} from '@orbit/data';
1313
import { foreignKey, tableize } from 'inflected';
1414

@@ -52,7 +52,7 @@ export class BaseModel extends Model {
5252
const result = this.toJSON() as any;
5353
const record: OrbitRecord = {
5454
type,
55-
id: result.id
55+
id: result.id,
5656
};
5757

5858
schema.eachAttribute(type, (property, attribute) => {
@@ -72,8 +72,8 @@ export class BaseModel extends Model {
7272
(relationships as Record<string, unknown>)[property] = {
7373
data: {
7474
type: type as string,
75-
id: id as string
76-
}
75+
id: id as string,
76+
},
7777
};
7878
record.relationships = relationships;
7979
}
@@ -117,7 +117,7 @@ export function buildModel(
117117
}
118118

119119
static get relationMappings() {
120-
const relationMappings: Record<string, RelationMapping> = {};
120+
const relationMappings: Record<string, RelationMapping<BaseModel>> = {};
121121
schema.eachRelationship(
122122
type,
123123
(property, { type: kind, model: type, inverse }) => {
@@ -137,16 +137,16 @@ export function buildModel(
137137
const inverseColumnName = foreignKey(inverse);
138138
const relationTableName = tableize(type);
139139
const relationModel = buildModel(schema, type, models);
140-
let relationMapping: RelationMapping;
140+
let relationMapping: RelationMapping<BaseModel>;
141141

142142
if (kind === 'hasOne') {
143143
relationMapping = {
144144
relation: Model.BelongsToOneRelation,
145145
modelClass: relationModel,
146146
join: {
147147
from: `${tableName}.${relationColumnName}`,
148-
to: `${relationTableName}.id`
149-
}
148+
to: `${relationTableName}.id`,
149+
},
150150
};
151151
} else {
152152
const { type: inverseKind } = schema.getRelationship(
@@ -164,19 +164,19 @@ export function buildModel(
164164
from: `${tableName}.id`,
165165
through: {
166166
from: `${joinTableName}.${relationColumnName}`,
167-
to: `${joinTableName}.${inverseColumnName}`
167+
to: `${joinTableName}.${inverseColumnName}`,
168168
},
169-
to: `${relationTableName}.id`
170-
}
169+
to: `${relationTableName}.id`,
170+
},
171171
};
172172
} else {
173173
relationMapping = {
174174
relation: Model.HasManyRelation,
175175
modelClass: relationModel,
176176
join: {
177177
from: `${tableName}.id`,
178-
to: `${relationTableName}.${inverseColumnName}`
179-
}
178+
to: `${relationTableName}.${inverseColumnName}`,
179+
},
180180
};
181181
}
182182
}

src/migrate-models.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function migrateModel(db: Knex, schema: Schema, type: string) {
1919
return;
2020
}
2121

22-
await db.schema.createTable(tableName, table => {
22+
await db.schema.createTable(tableName, (table) => {
2323
table.uuid('id').primary();
2424
table.timestamps(true, true);
2525

@@ -70,7 +70,7 @@ export async function migrateModel(db: Knex, schema: Schema, type: string) {
7070
if (inverseKind === 'hasMany') {
7171
joinTables[tableizeJoinTable(property, inverse)] = [
7272
columnName,
73-
foreignKey(inverse)
73+
foreignKey(inverse),
7474
];
7575
}
7676
}
@@ -80,7 +80,7 @@ export async function migrateModel(db: Knex, schema: Schema, type: string) {
8080

8181
for (let joinTableName in joinTables) {
8282
if (!(await db.schema.hasTable(joinTableName))) {
83-
await db.schema.createTable(joinTableName, table => {
83+
await db.schema.createTable(joinTableName, (table) => {
8484
table.uuid(joinTables[joinTableName][0]);
8585
table.uuid(joinTables[joinTableName][1]);
8686
});

src/processor.ts

+27-25
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
RecordIdentity,
2121
AttributeFilterSpecifier,
2222
Schema,
23-
QueryExpression
23+
QueryExpression,
2424
} from '@orbit/data';
2525
import Knex, { Config } from 'knex';
2626
import { QueryBuilder, ModelClass, transaction, Transaction } from 'objection';
@@ -70,7 +70,7 @@ export class Processor {
7070
}
7171

7272
async patch(operations: RecordOperation[]) {
73-
return transaction(this._db as Knex, async trx => {
73+
return transaction(this._db as Knex, async (trx) => {
7474
const result: OrbitRecord[] = [];
7575
for (let operation of operations) {
7676
result.push(await this.processOperation(operation, trx));
@@ -80,7 +80,7 @@ export class Processor {
8080
}
8181

8282
async query(query: Query) {
83-
return transaction(this._db as Knex, async trx => {
83+
return transaction(this._db as Knex, async (trx) => {
8484
return this.processQueryExpression(query.expression, trx);
8585
});
8686
}
@@ -133,21 +133,21 @@ export class Processor {
133133
const model = await qb.upsertGraph(data, {
134134
insertMissing: true,
135135
relate: true,
136-
unrelate: true
136+
unrelate: true,
137137
});
138138

139139
return model.toOrbitRecord();
140140
}
141141

142142
protected async updateRecord(op: UpdateRecordOperation, trx: Transaction) {
143143
const qb = this.queryForType(trx, op.record.type).mergeContext({
144-
recordId: op.record.id
144+
recordId: op.record.id,
145145
});
146146
const data = this.parseOrbitRecord(op.record);
147147

148148
const model = await qb.upsertGraph(data, {
149149
relate: true,
150-
unrelate: true
150+
unrelate: true,
151151
});
152152

153153
return model.toOrbitRecord();
@@ -156,7 +156,7 @@ export class Processor {
156156
protected async removeRecord(op: RemoveRecordOperation, trx: Transaction) {
157157
const { type, id } = op.record;
158158
const qb = this.queryForType(trx, type).mergeContext({
159-
recordId: id
159+
recordId: id,
160160
});
161161

162162
const model = (await qb.findById(id)) as BaseModel;
@@ -171,11 +171,11 @@ export class Processor {
171171
) {
172172
const { type, id } = op.record;
173173
const qb = this.queryForType(trx, type).mergeContext({
174-
recordId: id
174+
recordId: id,
175175
});
176176

177177
const model = await qb.patchAndFetchById(id, {
178-
[op.attribute]: op.value
178+
[op.attribute]: op.value,
179179
});
180180

181181
return model.toOrbitRecord();
@@ -187,7 +187,7 @@ export class Processor {
187187
) {
188188
const { type, id } = op.record;
189189
const qb = this.queryForType(trx, type).mergeContext({
190-
recordId: id
190+
recordId: id,
191191
});
192192
const relatedId = op.relatedRecord ? op.relatedRecord.id : null;
193193

@@ -207,19 +207,19 @@ export class Processor {
207207
) {
208208
const { type, id } = op.record;
209209
const qb = this.queryForType(trx, type).mergeContext({
210-
recordId: id
210+
recordId: id,
211211
});
212212
const relatedIds = op.relatedRecords.map(({ id }) => id);
213213

214214
const model = await qb.upsertGraph(
215215
{
216216
id,
217-
[op.relationship]: relatedIds.map(id => ({ id }))
217+
[op.relationship]: relatedIds.map((id) => ({ id })),
218218
},
219219
{
220220
insertMissing: false,
221221
relate: false,
222-
unrelate: true
222+
unrelate: true,
223223
}
224224
);
225225

@@ -232,7 +232,7 @@ export class Processor {
232232
) {
233233
const { type, id } = op.record;
234234
const qb = this.queryForType(trx, type).mergeContext({
235-
recordId: id
235+
recordId: id,
236236
});
237237
const relatedId = op.relatedRecord.id;
238238

@@ -248,7 +248,7 @@ export class Processor {
248248
) {
249249
const { type, id } = op.record;
250250
const qb = this.queryForType(trx, type).mergeContext({
251-
recordId: id
251+
recordId: id,
252252
});
253253

254254
const model = (await qb.findById(id)) as BaseModel;
@@ -264,7 +264,7 @@ export class Processor {
264264
protected async findRecord(expression: FindRecord, trx: Transaction) {
265265
const { id, type } = expression.record;
266266
const qb = this.queryForType(trx, type).mergeContext({
267-
recordId: id
267+
recordId: id,
268268
});
269269

270270
const model = (await qb.findById(id)) as BaseModel;
@@ -280,7 +280,7 @@ export class Processor {
280280
qb,
281281
expression
282282
)) as BaseModel[];
283-
return models.map(model => model.toOrbitRecord());
283+
return models.map((model) => model.toOrbitRecord());
284284
} else if (records) {
285285
const recordsByType = groupRecordsByType(records);
286286
const recordsById: Record<string, OrbitRecord> = {};
@@ -292,7 +292,9 @@ export class Processor {
292292
recordsById[record.id] = record.toOrbitRecord();
293293
}
294294
}
295-
return records.map(({ id }) => recordsById[id]).filter(record => record);
295+
return records
296+
.map(({ id }) => recordsById[id])
297+
.filter((record) => record);
296298
}
297299
throw new QueryExpressionParseError(
298300
`FindRecords with no type or records is not recognized for SQLSource.`,
@@ -306,11 +308,11 @@ export class Processor {
306308
) {
307309
const {
308310
record: { id, type },
309-
relationship
311+
relationship,
310312
} = expression;
311313

312314
let qb = this.queryForType(trx, type).mergeContext({
313-
recordId: id
315+
recordId: id,
314316
});
315317
const parent = (await qb.findById(id)) as BaseModel;
316318
qb = this.queryForRelationship(trx, parent, relationship);
@@ -325,19 +327,19 @@ export class Processor {
325327
) {
326328
const {
327329
record: { id, type },
328-
relationship
330+
relationship,
329331
} = expression;
330332

331333
let qb = this.queryForType(trx, type).mergeContext({
332-
recordId: id
334+
recordId: id,
333335
});
334336
const parent = (await qb.findById(id)) as BaseModel;
335337
const models = (await this.parseQueryExpression(
336338
this.queryForRelationship(trx, parent, relationship),
337339
expression
338340
)) as BaseModel[];
339341

340-
return models.map(model => model.toOrbitRecord());
342+
return models.map((model) => model.toOrbitRecord());
341343
}
342344

343345
modelForType(type: string): ModelClass<BaseModel> {
@@ -487,7 +489,7 @@ export class Processor {
487489
}
488490

489491
if (record.attributes) {
490-
this.schema.eachAttribute(record.type, property => {
492+
this.schema.eachAttribute(record.type, (property) => {
491493
if (record.attributes && record.attributes[property] !== undefined) {
492494
properties[property] = record.attributes[property];
493495
}
@@ -517,7 +519,7 @@ export class Processor {
517519
const tableName = tableize(type);
518520
const fields: string[] = [`${tableName}.id`];
519521

520-
this.schema.eachAttribute(type, property => {
522+
this.schema.eachAttribute(type, (property) => {
521523
fields.push(`${tableName}.${underscore(property)}`);
522524
});
523525

src/sql-source.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Orbit, {
1010
RecordOperation,
1111
updatable,
1212
Updatable,
13-
Schema
13+
Schema,
1414
} from '@orbit/data';
1515
import Knex from 'knex';
1616

@@ -65,7 +65,7 @@ export default class SQLSource extends Source implements Queryable, Updatable {
6565
let processorSettings: ProcessorSettings = {
6666
knex: settings.knex as Knex.Config,
6767
schema: settings.schema as Schema,
68-
autoMigrate: settings.autoMigrate
68+
autoMigrate: settings.autoMigrate,
6969
};
7070

7171
this._processor = new Processor(processorSettings);

0 commit comments

Comments
 (0)