11const WebSocket = require ( 'ws' ) ;
22
3+ // Configuration constants
4+ const devConfig = {
5+ dbLocation : 'mongodb://localhost:27017/xforge' ,
6+ wsConnectionString : 'ws://127.0.0.1:5003/?server=true' ,
7+ origin : 'http://localhost:5000'
8+ } ;
9+
10+ const qaConfig = {
11+ dbLocation : 'mongodb://localhost:4017/xforge' ,
12+ wsConnectionString : 'ws://127.0.0.1:4003/?server=true' ,
13+ origin : 'https://qa.scriptureforge.org'
14+ } ;
15+
16+ const liveConfig = {
17+ dbLocation : 'mongodb://localhost:3017/xforge' ,
18+ wsConnectionString : 'ws://127.0.0.1:3003/?server=true' ,
19+ origin : 'https://scriptureforge.org'
20+ } ;
21+
22+ const databaseConfigs = new Map ( ) ;
23+ databaseConfigs . set ( 'dev' , devConfig ) ;
24+ databaseConfigs . set ( 'qa' , qaConfig ) ;
25+ databaseConfigs . set ( 'live' , liveConfig ) ;
26+
27+ /** Enum of colors and their bash 256-colour values. */
28+ const colors = Object . freeze ( {
29+ darkGrey : 241 ,
30+ red : 196 ,
31+ lightBlue : 39 ,
32+ lightGreen : 48 ,
33+ yellow : 190 ,
34+ orange : 208
35+ } ) ;
36+
37+ let shouldUseColor = true ;
38+
339/**
440 * @param {ShareDB.Doc } doc The doc to fetch
541 */
@@ -55,7 +91,7 @@ function deleteDoc(doc) {
5591function createDoc ( doc , data , type ) {
5692 return new Promise ( ( resolve , reject ) => {
5793 doc . create ( data , type , undefined , err => {
58- if ( err ) {
94+ if ( err != null ) {
5995 reject ( err ) ;
6096 } else {
6197 resolve ( ) ;
@@ -90,8 +126,6 @@ function fetchSnapshotByTimestamp(conn, collection, docId, time) {
90126 } ) ;
91127}
92128
93- let shouldUseColor = true ;
94-
95129/** Specify if `colored()` should use colouring. Nice for output to a dark terminal. Not nice in log files. */
96130function useColor ( ifUseColor ) {
97131 shouldUseColor = ifUseColor ;
@@ -113,20 +147,10 @@ function colored(colorCode, textToColor) {
113147 }
114148}
115149
116- /** Enum of colors and their bash 256-colour values. */
117- const colors = Object . freeze ( {
118- darkGrey : 241 ,
119- red : 196 ,
120- lightBlue : 39 ,
121- lightGreen : 48 ,
122- yellow : 190 ,
123- orange : 208
124- } ) ;
125-
126150/**
127151 * @param {Object[] } ops List of operations, where an operation can be any object for the purposes of this function
128152 * (though in practice the definition of an operation should be much more limited; this function is just flexible).
129- * @param {showAttributes } Describe some op attributes inline.
153+ * @param {boolean } showAttributes Describe some op attributes inline.
130154 */
131155function visualizeOps ( ops , showAttributes = false ) {
132156 const result = ops
@@ -157,29 +181,6 @@ function createWS(connectionConfig) {
157181 return new WebSocket ( connectionConfig . wsConnectionString , [ ] , { origin : connectionConfig . origin } ) ;
158182}
159183
160- const devConfig = {
161- dbLocation : 'mongodb://localhost:27017/xforge' ,
162- wsConnectionString : 'ws://127.0.0.1:5003/?server=true' ,
163- origin : 'http://localhost:5000'
164- } ;
165-
166- const qaConfig = {
167- dbLocation : 'mongodb://localhost:4017/xforge' ,
168- wsConnectionString : 'ws://127.0.0.1:4003/?server=true' ,
169- origin : 'https://qa.scriptureforge.org'
170- } ;
171-
172- const liveConfig = {
173- dbLocation : 'mongodb://localhost:3017/xforge' ,
174- wsConnectionString : 'ws://127.0.0.1:3003/?server=true' ,
175- origin : 'https://scriptureforge.org'
176- } ;
177-
178- const databaseConfigs = new Map ( ) ;
179- databaseConfigs . set ( 'dev' , devConfig ) ;
180- databaseConfigs . set ( 'qa' , qaConfig ) ;
181- databaseConfigs . set ( 'live' , liveConfig ) ;
182-
183184module . exports = {
184185 fetchDoc,
185186 submitDocOp,
0 commit comments