@live-change/framework 0.8.50 → 0.8.52

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/lib/App.js CHANGED
@@ -323,7 +323,7 @@ class App {
323
323
  const command = data
324
324
  const service = this.startedServices[data.service]
325
325
  const action = service.actions[data.type]
326
- const reportFinished = action.definition.waitForEvents ? 'command_' + command.id : undefined
326
+ const reportFinished = action.definition.waitForEvents ? command.id : undefined
327
327
  const flags = {commandId: command.id, reportFinished}
328
328
  const emit = (!this.splitEvents || this.shortEvents)
329
329
  ? new SingleEmitQueue(service, flags)
@@ -458,10 +458,9 @@ class App {
458
458
  return
459
459
  }
460
460
  const [action, id] = reportId.split('_')
461
- const triggerId = action === 'trigger' ? id : undefined
462
- const commandId = action === 'command' ? id : undefined
461
+ const commandId = id
463
462
  const profileOp = await this.profileLog.begin({
464
- operation: "waitForEvents", action: action, commandId, triggerId, reportId, events, timeout
463
+ operation: "waitForEvents", action: action, commandId, reportId, events, timeout
465
464
  })
466
465
  const promise = new Promise((resolve, reject) => {
467
466
  let done = false
@@ -524,6 +523,12 @@ class App {
524
523
  return promise
525
524
  }
526
525
 
526
+ async emitEventsAndWait(service, events, flags = {}) {
527
+ const reportId = 'trigger_' + this.generateUid()
528
+ await this.emitEvents(service, events, { reportFinished: reportId, ...flags })
529
+ return await this.waitForEvents(reportId, events)
530
+ }
531
+
527
532
  async assertTime(taskName, duration, task, ...data) {
528
533
  const profileOp = await this.profileLog.begin({ operation: 'assertTime', taskName })
529
534
  const taskTimeout = setTimeout(() => {
@@ -85,6 +85,7 @@ class ServiceDefinition {
85
85
  this.processors = []
86
86
  this.authenticators = []
87
87
  this.beforeStartCallbacks = []
88
+ this.afterStartCallbacks = []
88
89
  this.endpoints = []
89
90
  this.validators = { ...defaultValidators }
90
91
  this.clientSideFilters = []
@@ -158,6 +159,10 @@ class ServiceDefinition {
158
159
  this.beforeStartCallbacks.push(callback)
159
160
  }
160
161
 
162
+ afterStart(callback) {
163
+ this.afterStartCallbacks.push(callback)
164
+ }
165
+
161
166
  endpoint(endpoint) {
162
167
  this.endpoints.push(endpoint)
163
168
  }
@@ -26,7 +26,7 @@ async function startCommandExecutor(service, config) {
26
26
  commandId: command.id, client: command.client
27
27
  })
28
28
  const reportFinished = action.definition.waitForEvents ? 'command_' + command.id : undefined
29
- const flags = {commandId: command.id, reportFinished}
29
+ const flags = { commandId: command.id, reportFinished }
30
30
  const emit = (!service.app.splitEvents || this.shortEvents)
31
31
  ? new SingleEmitQueue(service, flags)
32
32
  : new SplitEmitQueue(service, flags)
@@ -93,6 +93,14 @@ class Service {
93
93
  console.log("Service", this.definition.name, "started")
94
94
  }
95
95
 
96
+ async afterStart(config){
97
+ if(config.runCommands) {
98
+ for (const afterStartCallback of this.definition.afterStartCallbacks) {
99
+ await afterStartCallback(this)
100
+ }
101
+ }
102
+ }
103
+
96
104
  async trigger(trigger, data) {
97
105
  return this.app.trigger({
98
106
  causeType: 'service',
@@ -95,9 +95,6 @@ class CommandQueue {
95
95
  delay: command.timestamp && (started.getTime() - (new Date(command.timestamp)).getTime()),
96
96
  execution: finished.getTime() - started.getTime()
97
97
  }
98
- console.log("UPDATE DATABASE", ['database', 'update'], this.database, this.tableName, command.id, [
99
- { op: 'merge', property: null, value: { state: 'done', result, stats } }
100
- ])
101
98
  await this.connection.request(['database', 'update'], this.database, this.tableName, command.id, [
102
99
  { op: 'merge', property: null, value: { state: 'done', result, stats } }
103
100
  ])
@@ -26,7 +26,7 @@ class SingleEmitQueue {
26
26
  events.push(event)
27
27
  }
28
28
  if(this.commited) {
29
- if(events.length == 0) return
29
+ if(events.length === 0) return
30
30
  this.service.dao.request(['database', 'putLog'], this.service.databaseName,
31
31
  'events', { type: 'bucket', events, ...this.flags })
32
32
  }
@@ -34,7 +34,7 @@ class SingleEmitQueue {
34
34
 
35
35
  async commit() {
36
36
  this.commited = true
37
- if(this.emittedEvents.length == 0) return []
37
+ if(this.emittedEvents.length === 0) return []
38
38
  await this.service.dao.request(['database', 'putLog'], this.service.databaseName,
39
39
  'events', { type: 'bucket', events: this.emittedEvents, ...this.flags })
40
40
  return this.emittedEvents
@@ -43,7 +43,7 @@ class SplitEmitQueue {
43
43
  events.push(event)
44
44
  }
45
45
  if(this.commited) {
46
- if(events.length == 0) return
46
+ if(events.length === 0) return
47
47
  this.service.dao.request(['database', 'putLog'], this.service.databaseName,
48
48
  this.service.name+'_events', { type: 'bucket', events, ...this.flags })
49
49
  }
@@ -52,7 +52,7 @@ class SplitEmitQueue {
52
52
  async commit() {
53
53
  let promises = []
54
54
  this.commited = true
55
- if(this.emittedEvents.length == 0) return []
55
+ if(this.emittedEvents.length === 0) return []
56
56
  let allEvents = []
57
57
  for(const [service, events] of this.emittedEvents.keys()) {
58
58
  promises.push(this.service.dao.request(['database', 'putLog'], this.service.databaseName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.8.50",
3
+ "version": "0.8.52",
4
4
  "description": "Live Change Framework - ultimate solution for real time mobile/web apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "homepage": "https://github.com/live-change/live-change-stack",
24
24
  "devDependencies": {
25
- "@live-change/dao": "^0.8.50",
26
- "@live-change/uid": "^0.8.50"
25
+ "@live-change/dao": "^0.8.52",
26
+ "@live-change/uid": "^0.8.52"
27
27
  },
28
- "gitHead": "c967d5304bdac5150a6272c8d7cbe8974d7c25e6"
28
+ "gitHead": "d06ad62415cc92e15b5dee87078614d4f883eb83"
29
29
  }