pinstripe 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ export const Migrator = Class.extend().include({
17
17
  const migrations = Migration.names.map(name => Migration.for(name)).sort((a, b) => a.schemaVersion - b.schemaVersion);
18
18
  for(let i in migrations){
19
19
  const migration = migrations[i];
20
- const isMigrationApplied = this.database.table('pinstripeAppliedMigrations').where({ schemaVersion: migration.schemaVersion }).count() > 0;
20
+ const isMigrationApplied = await this.database.table('pinstripeAppliedMigrations').where({ schemaVersion: migration.schemaVersion }).count() > 0;
21
21
  if(!isMigrationApplied){
22
22
  if(isDevelopmentEnvironment) console.log(`Applying migration: ${migration.name}`);
23
23
  await migration.new(this.database).migrate();
@@ -168,11 +168,12 @@ export const Table = Class.extend().include({
168
168
  },
169
169
 
170
170
  where(...args){
171
- if(typeof args[0] == 'string'){
171
+ if(typeof args[0] == 'string' || Array.isArray(args[0])){
172
172
  this.expressions.push(args);
173
173
  return this;
174
174
  }
175
- const [ scopedBy = {} ] = args;
175
+ const [ scopedBy ] = args;
176
+ if(typeof scopedBy != 'object') throw new Error(`Invalid argument (0) - expected object, array or string.`);
176
177
  const names = Object.keys(scopedBy);
177
178
  while(names.length){
178
179
  const name = names.shift();
@@ -183,6 +184,11 @@ export const Table = Class.extend().include({
183
184
  return this;
184
185
  },
185
186
 
187
+ async tap(fn){
188
+ await fn.call(this);
189
+ return this;
190
+ },
191
+
186
192
  orderBy(...args){
187
193
  this.orderedBy.push(args);
188
194
  return this;
@@ -11,11 +11,9 @@ Database.include({
11
11
  const { tenant } = this.options;
12
12
  if(tenant && out.info.tenants){
13
13
  const { name, host } = tenant;
14
- if(name) {
15
- this.tenant = await out.tenants.where({ name }).first();
16
- } else {
17
- this.tenant = await out.tenants.where({ host }).first();
18
- }
14
+ this.tenant = await (await out.tenants.tap(function(){
15
+ this.where('(? = ? or ? = ?)', this.tableReference.createColumnReference('name'), name, this.tableReference.createColumnReference('host'), host);
16
+ })).first();
19
17
  }
20
18
  return out;
21
19
  },
@@ -4,14 +4,16 @@ import { Client } from "../../../database/client.js";
4
4
 
5
5
  export default {
6
6
  create(){
7
- if(!this.context.root.databaseClient){
8
- this.context.root.databaseClient = Client.new();
9
- }
10
- return this.defer(async () => Database.new(this.context.root.databaseClient, {
11
- tenant: {
12
- name: this.initialParams._headers['x-tenant'],
13
- host: this.initialParams._url.hostname
7
+ return this.defer(async () => {
8
+ if(!this.context.root.databaseClient){
9
+ this.context.root.databaseClient = Client.new(await this.config.database);
14
10
  }
15
- }));
11
+ return Database.new(this.context.root.databaseClient, {
12
+ tenant: {
13
+ name: this.initialParams._headers['x-tenant'] || this.initialParams._url.hostname.replace(/\..*$/, ''),
14
+ host: this.initialParams._url.hostname
15
+ }
16
+ })
17
+ });
16
18
  }
17
19
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "pinstripe",
4
4
  "description": "A slick web framework for Node.js.",
5
- "version": "0.16.1",
5
+ "version": "0.17.0",
6
6
  "author": "Jody Salt",
7
7
  "license": "MIT",
8
8
  "exports": {
@@ -48,5 +48,5 @@
48
48
  "tmp": "^0.2.1",
49
49
  "unionfs": "^4.4.0"
50
50
  },
51
- "gitHead": "f7dd0e3a3dd8391176c3f46aa383b1d921bdd713"
51
+ "gitHead": "ccfaad0d841d6404b4eec608f8c6e04ce83dcec5"
52
52
  }