insomnia/app/models/environment.js
Gregory Schier e9b87686e1
Upgrade Electron Builder (#498)
* Upgrade electron-builder

* Fix optional dep

* Add another dep

* Fix travis

* Fix 7zip install

* Fix icons

* Minor fix

* Delete changelog

* Moved build scripts to JS

* Some adjustments

* Remove lines

* Add 7zip back

* Update scripts

* Small tweaks

* Fix electronbuilder config

* snap dependency

* Fix pkg

* Remove snapd dep

* Updated deps and lots of fixes

* Travis update

* Return package name

* Remove snap for now

* Remove portable

* Try fixing code signing

* Bump cache

* Disable automatic tests

* Fix windows artifacts

* package-lock for app/

* Try fix npm install

* Try again

* Some minor tweaks

* Preleases by default
2017-11-20 16:07:36 +00:00

79 lines
1.9 KiB
JavaScript

// @flow
import * as db from '../common/database';
import type {BaseModel} from './index';
import type {Workspace} from './workspace';
export const name = 'Environment';
export const type = 'Environment';
export const prefix = 'env';
export const canDuplicate = true;
type BaseEnvironment = {
name: string,
data: Object,
color: string | null,
// For sync control
isPrivate: boolean
};
export type Environment = BaseModel & BaseEnvironment;
export function init () {
return {
name: 'New Environment',
data: {},
color: null,
isPrivate: false
};
}
export function migrate (doc: Environment): Environment {
return doc;
}
export function create (patch: Object = {}): Promise<Environment> {
if (!patch.parentId) {
throw new Error(`New Environment missing \`parentId\`: ${JSON.stringify(patch)}`);
}
return db.docCreate(type, patch);
}
export function update (environment: Environment, patch: Object): Promise<Environment> {
return db.docUpdate(environment, patch);
}
export function findByParentId (parentId: string): Promise<Array<Environment>> {
return db.find(type, {parentId});
}
export async function getOrCreateForWorkspaceId (workspaceId: string): Promise<Environment> {
const environments = await db.find(type, {parentId: workspaceId});
if (!environments.length) {
return create({
parentId: workspaceId,
name: 'Base Environment'
});
}
return environments[environments.length - 1];
}
export async function getOrCreateForWorkspace (workspace: Workspace): Promise<Environment> {
return getOrCreateForWorkspaceId(workspace._id);
}
export function getById (id: string): Promise<Environment | null> {
return db.get(type, id);
}
export function remove (environment: Environment): Promise<void> {
return db.remove(environment);
}
export function all (): Promise<Array<Environment>> {
return db.all(type);
}