holepunch-hop 0.2.7 → 0.2.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holepunch-hop",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "data interface to HOP",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -29,12 +29,49 @@ class SqliteAdapter extends EventEmitter {
29
29
  this.createDbConnection(db)
30
30
  // ask for tables
31
31
  let tables = await this.discoverTables()
32
- let header = await this.discoverColumns()
32
+ // let header = await this.discoverColumns()
33
33
  newSqlite.tables = tables
34
- newSqlite.headers = header
34
+ // newSqlite.headers = header
35
35
  return newSqlite
36
36
  }
37
37
 
38
+ /**
39
+ * discover colum names in a table
40
+ * @method tableQuery
41
+ *
42
+ */
43
+ tableQuery = async function (data) {
44
+ let newSqlite = {}
45
+ this.createDbConnection(data.file)
46
+ // ask for tables
47
+ let headers = await this.discoverColumns(data.table)
48
+ newSqlite.headers = headers
49
+ return newSqlite
50
+ }
51
+
52
+ /**
53
+ * setup sqlite db and get tables and columns
54
+ * @method discoverColumns
55
+ *
56
+ */
57
+ discoverColumns = async function (table) {
58
+ // columns in table
59
+ let header = []
60
+ const res = await new Promise((resolve, reject) => {
61
+ let sqlTableCols = `PRAGMA table_info('` + table + `')`
62
+ this.dataBase.all(sqlTableCols, [], (err, rows) => {
63
+ if (err) {
64
+ reject(err)
65
+ }
66
+ rows.forEach((row) => {
67
+ header.push(row)
68
+ })
69
+ resolve(header)
70
+ })
71
+ })
72
+ return res
73
+ }
74
+
38
75
  /**
39
76
  * setup sqlite db and get tables and columns
40
77
  * @method createDbConnection
@@ -74,40 +111,79 @@ class SqliteAdapter extends EventEmitter {
74
111
  return res
75
112
  }
76
113
 
114
+
77
115
  /**
78
- * setup sqlite db and get tables and columns
79
- * @method discoverColumns
116
+ * query a table for data
117
+ * @method queryTable
80
118
  *
81
119
  */
82
- discoverColumns = async function (table) {
120
+ queryTable = async function (table) {
121
+ console.log('HP--first SQL query')
122
+ console.log(table)
123
+ let tableName = table.context.deviceTable
124
+ // let devicetableName = table.context.devicetablename
125
+ let tableTimestamp = table.context.timestamp // timecolumn
126
+ let deviceColumn = ''
127
+ if (table?.context?.deviceCol) {
128
+ deviceColumn = table?.context?.deviceCol?.name
129
+ } else {
130
+ deviceColumn = ''
131
+ }
132
+ let queryDevice = 0
133
+ if (table.context?.deviceID) {
134
+ queryDevice = table.context?.deviceID
135
+ } else {
136
+ queryDevice = 1 // table?.context?.device?._id
137
+ }
138
+ let queryLimit = true
139
+ let queryLevel = 1400
140
+ let blindTimestart = 0
141
+ let blindTimeend = 0
83
142
  // columns in table
84
- let header = []
143
+ let data = []
85
144
  const res = await new Promise((resolve, reject) => {
86
- let sqlTableCols = `PRAGMA table_info('MI_BAND_ACTIVITY_SAMPLE')`
87
-
88
- this.dataBase.all(sqlTableCols, [], (err, rows) => {
145
+ let sqlQuery = `SELECT * FROM ` + tableName
146
+ // now build filter of query based on input if any
147
+ if (deviceColumn.length > 0) {
148
+ sqlQuery += ` WHERE ` + deviceColumn + ` = ` + queryDevice
149
+ }
150
+ if (tableTimestamp.length > 0) {
151
+ sqlQuery += ` ORDER BY TIMESTAMP DEC` // + tableTimestamp
152
+ }
153
+ if (blindTimestart) {
154
+ sqlQuery += ` AND TIMESTAMP BETWEEN ` + blindTimestart + ` AND ` + blindTimeend
155
+
156
+ }
157
+ // lastly set hard limit on length
158
+ if (queryLimit) {
159
+ sqlQuery += ` LIMIT ` + queryLevel
160
+ }
161
+ console.log('HP------formed ----------')
162
+ console.log(sqlQuery)
163
+ this.dataBase.all(sqlQuery, [], (err, rows) => {
89
164
  if (err) {
90
165
  reject(err)
91
166
  }
92
167
  rows.forEach((row) => {
93
- header.push(row)
168
+ data.push(row)
94
169
  })
95
- resolve(header)
170
+ resolve(data)
96
171
  })
97
172
  })
98
173
  return res
99
174
  }
100
175
 
176
+
101
177
  /**
102
- * query a table for data
103
- * @method queryTable
178
+ * query device table
179
+ * @method deviceQuery
104
180
  *
105
181
  */
106
- queryTable = async function (table) {
107
- // columns in table
182
+ deviceQuery = async function (table) {
183
+ console.log('HOLEP---adtpSQL--query device SQLite ad')
108
184
  let data = []
109
185
  const res = await new Promise((resolve, reject) => {
110
- let sqlQuery = `SELECT * FROM MI_BAND_ACTIVITY_SAMPLE WHERE DEVICE_ID = 3 ORDER BY TIMESTAMP DESC LIMIT 1400` // AND TIMESTAMP BETWEEN 1627677840 AND 1627678380`
186
+ let sqlQuery = `SELECT * FROM ` + table
111
187
 
112
188
  this.dataBase.all(sqlQuery, [], (err, rows) => {
113
189
  if (err) {
package/src/bees.js CHANGED
@@ -113,6 +113,7 @@ class HyperBee extends EventEmitter {
113
113
  *
114
114
  */
115
115
  savePubliclibrary = async function (refContract) {
116
+ console.log(refContract)
116
117
  let beeSave = await this.dbPublicLibrary.put(refContract.data.hash, refContract.data.contract)
117
118
  // go query the key are return the info. to ensure data save asplanned.
118
119
  let saveCheck = await this.getPublicLibrary(refContract.data.hash)
@@ -131,8 +132,8 @@ class HyperBee extends EventEmitter {
131
132
  *
132
133
  */
133
134
  savePeerLibrary = async function (refContract) {
134
- await this.dbPeerLibrary.put(refContract.hash, refContract.contract)
135
- let saveCheck = await this.getPeerLibrary(refContract.hash)
135
+ await this.dbPeerLibrary.put(refContract.data.hash, refContract.data.contract)
136
+ let saveCheck = await this.getPeerLibrary(refContract.data.hash)
136
137
  let returnMessage = {}
137
138
  returnMessage.stored = true
138
139
  returnMessage.type = refContract.reftype
@@ -342,6 +343,17 @@ class HyperBee extends EventEmitter {
342
343
  return nodeData
343
344
  }
344
345
 
346
+ /**
347
+ * filter peer library to get compute modules with a key
348
+ * @method getPeerLibComputeModules
349
+ *
350
+ */
351
+ getPeerLibComputeModules = async function () {
352
+ const moduleData = await this.dbPeerLibrary.createHistoryStream({ reverse: true, limit: 10 })
353
+ return moduleData
354
+ }
355
+
356
+
345
357
  /**
346
358
  * get all kbl entries
347
359
  * @method KBLentries
@@ -398,6 +410,21 @@ class HyperBee extends EventEmitter {
398
410
 
399
411
  }
400
412
 
413
+
414
+
415
+ /**
416
+ * delete nxp ref contract public
417
+ * @method deleteRefcontPubliclibrary
418
+ *
419
+ */
420
+ deleteRefcontPubliclibrary = async function (nxpID) {
421
+ let deleteInfo = {}
422
+ let deleteStatus = await this.dbPublicLibrary.del(nxpID)
423
+ deleteInfo.success = deleteStatus
424
+ deleteInfo.nxp = nxpID
425
+ return deleteInfo
426
+ }
427
+
401
428
  /**
402
429
  * delete nxp ref contract from peer library
403
430
  * @method deleteRefcontPeerlibrary
package/src/drive.js CHANGED
@@ -88,7 +88,6 @@ class HypDrive extends EventEmitter {
88
88
  */
89
89
  listFilesFolder = function (folder) {
90
90
  const stream = this.drive.list('') // [options])
91
- // console.log(stream)
92
91
  // Handle stream events --> data, end, and error
93
92
  let dataDrive = []
94
93
  stream.on('data', function(chunk) {
@@ -170,7 +169,7 @@ class HypDrive extends EventEmitter {
170
169
  const parseData = await this.SQLiteSetup(name)
171
170
  fileResponse.filename = name
172
171
  fileResponse.header = parseData.headers
173
- fileResponse.data = parseData.tables
172
+ fileResponse.tables = parseData.tables
174
173
  return fileResponse
175
174
  }
176
175
 
@@ -264,33 +263,74 @@ class HypDrive extends EventEmitter {
264
263
  return summarySQLinfo
265
264
  }
266
265
 
267
- /**
266
+ /**
267
+ * set file path, read and make sqlite3 connect db
268
+ * @method SQLiteSourceSetup
269
+ *
270
+ */
271
+ SQLiteSourceSetup = async function (data) {
272
+ // const stream = this.liveDataAPI.DriveFiles.listFilesFolder('sqlite/')
273
+ let dbFile = await this.hyperdriveLocalfile('sqlite/' + data.db)
274
+ data.file = dbFile
275
+ let summarySQLinfo = await this.AdapterSqlite.tableQuery(data)
276
+ return summarySQLinfo
277
+ }
278
+
279
+
280
+ /**
281
+ * ask for device tables and info.
282
+ * @method SQLiteDeviceSetup
283
+ *
284
+ */
285
+ SQLiteDeviceSetup = async function (data) {
286
+ // const stream = this.liveDataAPI.DriveFiles.listFilesFolder('sqlite/')
287
+ let dbFile = await this.hyperdriveLocalfile('sqlite/' + data.db)
288
+ data.file = dbFile
289
+ let summaryTable = await this.AdapterSqlite.tableQuery(data)
290
+ let summaryDevice = await this.AdapterSqlite.deviceQuery(data.table)
291
+ let summarySQLinfo = {}
292
+ summarySQLinfo.tables = summaryTable
293
+ summarySQLinfo.devices = summaryDevice
294
+ return summarySQLinfo
295
+ }
296
+
297
+ /**
268
298
  * set file path, read and make sqlite3 connect db
269
299
  * @method SQLiteQuery
270
300
  *
271
301
  */
272
302
  SQLiteQuery = async function (dataInfo) {
303
+ console.log('HP--DRIVE--sqlite')
273
304
  let timestampCol = ''
274
305
  // is the sqliite database sill accive?
275
306
  // const stream = this.liveDataAPI.DriveFiles.listFilesFolder('sqlite/')
276
307
  let dbFile = await this.hyperdriveLocalfile('sqlite/' + dataInfo.file.file)
277
308
  let queryData = await this.AdapterSqlite.queryTable(dataInfo)
278
- let contextKeys = Object.keys(queryData[0])
279
- timestampCol = contextKeys[dataInfo.context.timestamp]
280
- // now prepare into data and labels
281
- let blindData = {}
282
- let extractCol = []
283
- let extractLabel = []
284
- for (let rowi of queryData) {
285
- extractCol.push(rowi[dataInfo.context.name.name])
286
- // assume data column for now and parse to mills seconds
287
- let testCH1 = chrono.parseDate(rowi[timestampCol])
288
- let parseDate = testCH1 * 1000 // this.testDataExtact(testCH1)
289
- extractLabel.push(parseDate)
309
+ if (queryData.length > 0) {
310
+ let contextKeys = Object.keys(queryData[0])
311
+ timestampCol = contextKeys[dataInfo.context.timestamp]
312
+ // now prepare into data and labels
313
+ let blindData = {}
314
+ let extractCol = []
315
+ let extractLabel = []
316
+ for (let rowi of queryData) {
317
+ extractCol.push(rowi[dataInfo.context.name.name])
318
+ // assume data column for now and parse to mills seconds
319
+ let testCH1 = chrono.parseDate(rowi[timestampCol])
320
+ let parseDate = testCH1 * 1000 // this.testDataExtact(testCH1)
321
+ extractLabel.push(parseDate)
322
+ }
323
+ blindData.data = extractCol
324
+ blindData.label = extractLabel
325
+ return blindData
326
+ } else {
327
+ console.log('no data for that query')
328
+ let blindData = {}
329
+ blindData.data = []
330
+ blindData.label = []
331
+ return blindData
290
332
  }
291
- blindData.data = extractCol
292
- blindData.label = extractLabel
293
- return blindData
333
+
294
334
  }
295
335
 
296
336
 
package/src/fileParser.js CHANGED
@@ -137,6 +137,26 @@ FileParser.prototype.webCSVparse = function (fData) {
137
137
  // this.convertJSON(o, ws, headerInfo, praser, 'web', fileNewName)
138
138
  }
139
139
 
140
+ /**
141
+ * TEMP blind json content
142
+ * @method TEMPwebJSONparse
143
+ *
144
+ */
145
+ FileParser.prototype.TEMPwebJSONparse = function (fjData) {
146
+ console.log(fjData)
147
+ let extractLabel = []
148
+ let extractCol = []
149
+ for (let df of fjData.content) {
150
+ extractLabel.push(df[fjData.context.timestampname])
151
+ extractCol.push(df[fjData.context.name])
152
+ }
153
+ // extract out price and time
154
+ let extractedPair = {}
155
+ extractedPair.label = extractLabel
156
+ extractedPair.data = extractCol
157
+ return extractedPair
158
+ }
159
+
140
160
  /**
141
161
  * TEMP blind csv content files from web
142
162
  * @method TEMPwebCSVparse
package/src/index.js CHANGED
@@ -130,6 +130,8 @@ class HolepunchWorker extends EventEmitter {
130
130
  this.warmPeers.push(message.data)
131
131
  this.Peers.peerJoin(message.data)
132
132
  }
133
+ } else if (message.task === 'peer-board') {
134
+ console.log('public board share with peer')
133
135
  } else if (message.task === 'peer-write') {
134
136
  this.emit('peer-write', message.data)
135
137
  } else if (message.task === 'topic') {