@xyo-network/os-runtime 3.0.5 → 3.0.7

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
@@ -27,8 +27,8 @@
27
27
  "@xyo-network/diviner-payload-indexeddb": "^3.0.5",
28
28
  "@xyo-network/diviner-payload-model": "^3.0.5",
29
29
  "@xyo-network/diviner-temporal-indexing-model": "^3.0.5",
30
- "@xyo-network/kernel": "^3.0.5",
31
- "@xyo-network/kernel-model": "^3.0.5",
30
+ "@xyo-network/kernel": "^3.0.7",
31
+ "@xyo-network/kernel-model": "^3.0.7",
32
32
  "@xyo-network/manifest": "^3.0.5",
33
33
  "@xyo-network/manifest-wrapper": "^3.0.5",
34
34
  "@xyo-network/module-abstract": "^3.0.5",
@@ -37,7 +37,7 @@
37
37
  "@xyo-network/module-model": "^3.0.5",
38
38
  "@xyo-network/module-resolver": "^3.0.5",
39
39
  "@xyo-network/node-model": "^3.0.5",
40
- "@xyo-network/os-model": "^3.0.5",
40
+ "@xyo-network/os-model": "^3.0.7",
41
41
  "@xyo-network/payload-builder": "^3.0.5",
42
42
  "@xyo-network/payload-model": "^3.0.5",
43
43
  "@xyo-network/wallet-model": "^3.0.5",
@@ -51,7 +51,9 @@
51
51
  "@types/uuid": "^10.0.0",
52
52
  "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.29",
53
53
  "@xylabs/tsconfig": "^4.0.0-rc.29",
54
- "typescript": "^5.5.4"
54
+ "@xyo-network/bios-nodejs": "^3.0.7",
55
+ "typescript": "^5.5.4",
56
+ "vitest": "^2.0.5"
55
57
  },
56
58
  "description": "Primary SDK for using XYO Protocol 2.0",
57
59
  "exports": {
@@ -73,6 +75,6 @@
73
75
  "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
74
76
  },
75
77
  "sideEffects": false,
76
- "version": "3.0.5",
78
+ "version": "3.0.7",
77
79
  "type": "module"
78
80
  }
package/src/XyOs.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { Promisable } from '@xylabs/promise'
3
+ import { boot } from '@xyo-network/bios'
3
4
  import { Kernel } from '@xyo-network/kernel'
4
5
  import type { KernelExternal } from '@xyo-network/kernel-model'
5
6
  import type { PackageManifest } from '@xyo-network/manifest'
@@ -40,7 +41,7 @@ export interface XyOsParams<TManifest extends PackageManifest = PackageManifest>
40
41
  export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
41
42
  protected _exposedNode: NodeInstance | undefined
42
43
  protected _exposedNodeOuter: NodeInstance | undefined
43
- protected _kernel: KernelExternal | undefined
44
+ protected _kernel: KernelExternal
44
45
  protected _locator: ModuleFactoryLocator
45
46
  protected dappRegistrationService: DappRegistrationService
46
47
  private stackManager: StackManager
@@ -103,6 +104,13 @@ export class XyOs extends XyOsContextBase<XyOsParams> implements XyOsContext {
103
104
  console.warn('XyOs:boot', wallet.address)
104
105
  const fullLocator = this._locator.merge(locator)
105
106
  return await this._bootMutex.runExclusive(async () => {
107
+ await this.eventBus.start()
108
+ if (this.kernel?.status === 'created') {
109
+ await this.kernel.boot(await boot(), { locator: fullLocator })
110
+ }
111
+ if (this.kernel?.status !== 'booted') {
112
+ throw new Error('Kernel not booted')
113
+ }
106
114
  assertEx(this._root === undefined, () => 'XyOs already booted')
107
115
  const [root] = await XyOs.monitor(async () => await loadOsNode(wallet, fullLocator), { name: 'Load XyOs' })
108
116
  this._root = root
@@ -16,6 +16,7 @@ import {
16
16
  isPubSubConnections,
17
17
  } from '@xyo-network/os-model'
18
18
  import { PayloadBuilder } from '@xyo-network/payload-builder'
19
+ import { Mutex } from 'async-mutex'
19
20
  import { v4 as uuid } from 'uuid'
20
21
 
21
22
  /**
@@ -37,6 +38,8 @@ export class EventBus implements EventBusInterface {
37
38
  // Store all publisher callbacks for later removal
38
39
  private publisherCallbacks: Record<string, PublisherEventListener> = {}
39
40
 
41
+ private startMutex = new Mutex()
42
+
40
43
  get archivist() {
41
44
  return asArchivistInstance(
42
45
  assertEx(this._archivist, () => 'Archivist not found. Did you forget to call start()?'),
@@ -78,38 +81,45 @@ export class EventBus implements EventBusInterface {
78
81
  }
79
82
 
80
83
  async start(storeName = 'EventBusArchivist') {
81
- // Later versions could include a node that has a payload diviner to query past events
82
- this._archivist = await MemoryArchivist.create({
83
- config: {
84
- name: storeName, schema: MemoryArchivistConfigSchema,
85
- },
86
- })
87
-
88
- // start listening to inserted events from publishers
89
- // NOTE: This is a very basic implementation and could be optimized by indexing on connection, eventName, and callback
90
- // for faster lookups by event name
91
- this.archivist.on('inserted', ({ payloads }: ArchivistModuleEventData['inserted']) => {
84
+ return await this.startMutex.runExclusive(async () => {
85
+ if (this._archivist) {
86
+ console.warn('EventBus already started')
87
+ return this
88
+ }
89
+ // Later versions could include a node that has a payload diviner to query past events
90
+ this._archivist = await MemoryArchivist.create({
91
+ config: {
92
+ name: storeName, schema: MemoryArchivistConfigSchema,
93
+ },
94
+ })
95
+
96
+ // start listening to inserted events from publishers
97
+ // NOTE: This is a very basic implementation and could be optimized by indexing on connection, eventName, and callback
98
+ // for faster lookups by event name
99
+ this.archivist.on('inserted', ({ payloads }: ArchivistModuleEventData['inserted']) => {
92
100
  // confirm an eventBusPayload was inserted
93
- const eventBusEvent = payloads.find(isEventBusEvent)
94
- // if not an eventBusPayload, return
95
- if (!eventBusEvent) return
96
- // Loop through all connections
97
- for (const connectionId in this.connections) {
98
- const connection = this.connections[connectionId]
99
- // Target PubSub connections
100
- if (isPubSubConnections(connection) && connection.subscribableEvents) {
101
+ const eventBusEvent = payloads.find(isEventBusEvent)
102
+ // if not an eventBusPayload, return
103
+ if (!eventBusEvent) return
104
+ // Loop through all connections
105
+ for (const connectionId in this.connections) {
106
+ const connection = this.connections[connectionId]
107
+ // Target PubSub connections
108
+ if (isPubSubConnections(connection) && connection.subscribableEvents) {
101
109
  // Loop through all subscribable events
102
- for (const [eventName, callback] of connection.subscribableEvents.entries()) {
110
+ for (const [eventName, callback] of connection.subscribableEvents.entries()) {
103
111
  // check if the event name matches the payload name
104
- if (eventName !== eventBusEvent.name) continue
105
- // pass the event payloads to the callback
106
- if (callback) {
107
- const forgettable = async () => await callback({ payloads })
108
- forget(forgettable())
112
+ if (eventName !== eventBusEvent.name) continue
113
+ // pass the event payloads to the callback
114
+ if (callback) {
115
+ const forgettable = async () => await callback({ payloads })
116
+ forget(forgettable())
117
+ }
109
118
  }
110
119
  }
111
120
  }
112
- }
121
+ })
122
+ return this
113
123
  })
114
124
  }
115
125