@xyo-network/os-runtime 3.0.0
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/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/neutral/index.d.ts +1656 -0
- package/dist/neutral/index.mjs +3432 -0
- package/dist/neutral/index.mjs.map +1 -0
- package/package.json +78 -0
- package/src/Caller.ts +221 -0
- package/src/DappCallerBase.ts +52 -0
- package/src/DefaultsQueries.ts +27 -0
- package/src/OsCallerBase.ts +55 -0
- package/src/PubSubBridgeCaller.ts +30 -0
- package/src/XyOs.ts +125 -0
- package/src/XyOsBase.ts +119 -0
- package/src/XyOsDapp.ts +90 -0
- package/src/access-interfaces/ValidDappAccessInterfaces.ts +8 -0
- package/src/access-interfaces/index.ts +2 -0
- package/src/access-interfaces/registered-names/helpers/AccessNodeQueries.ts +59 -0
- package/src/access-interfaces/registered-names/helpers/index.ts +2 -0
- package/src/access-interfaces/registered-names/helpers/resource/AbstractXnsCaller.ts +38 -0
- package/src/access-interfaces/registered-names/helpers/resource/RegistrationsResource.ts +54 -0
- package/src/access-interfaces/registered-names/helpers/resource/RegistrationsResourceQueries.ts +22 -0
- package/src/access-interfaces/registered-names/helpers/resource/index.ts +3 -0
- package/src/access-interfaces/registered-names/index.ts +1 -0
- package/src/adapter/Base.ts +96 -0
- package/src/adapter/Network.ts +31 -0
- package/src/adapter/Settings.ts +30 -0
- package/src/adapter/index.ts +2 -0
- package/src/adapters/OsPubSubBridgeNetwork.ts +10 -0
- package/src/adapters/OsSettings.ts +7 -0
- package/src/adapters/OsXyoPublicNetwork.ts +9 -0
- package/src/adapters/index.ts +3 -0
- package/src/classes/cache/RunningAccessDappCache.ts +21 -0
- package/src/classes/cache/RunningDappCache.ts +50 -0
- package/src/classes/cache/index.ts +2 -0
- package/src/classes/dapp/DefaultsResource.ts +65 -0
- package/src/classes/dapp/access/Caller.ts +73 -0
- package/src/classes/dapp/access/Queries.ts +38 -0
- package/src/classes/dapp/access/Resource.ts +63 -0
- package/src/classes/dapp/access/index.ts +3 -0
- package/src/classes/dapp/index.ts +2 -0
- package/src/classes/index.ts +8 -0
- package/src/classes/lib/DappCreatorParams.ts +16 -0
- package/src/classes/lib/Insertable.ts +14 -0
- package/src/classes/lib/index.ts +2 -0
- package/src/classes/menu/Caller.ts +76 -0
- package/src/classes/menu/Queries.ts +59 -0
- package/src/classes/menu/Resource.ts +103 -0
- package/src/classes/menu/index.ts +2 -0
- package/src/classes/node/Creator.ts +96 -0
- package/src/classes/node/DefaultPayloads/DappAccessPayloads.ts +17 -0
- package/src/classes/node/DefaultPayloads/DefaultPayloads.ts +33 -0
- package/src/classes/node/DefaultPayloads/NodeInfoPayload.ts +27 -0
- package/src/classes/node/DefaultPayloads/SigningKeyPayloads.ts +85 -0
- package/src/classes/node/DefaultPayloads/index.ts +1 -0
- package/src/classes/node/ExternalModulePermissions/ExternalModulePermissions.ts +47 -0
- package/src/classes/node/ExternalModulePermissions/index.ts +1 -0
- package/src/classes/node/createDappContext.ts +52 -0
- package/src/classes/node/index.ts +3 -0
- package/src/classes/registration/DappRegistrationService.ts +146 -0
- package/src/classes/registration/DappRegistry.ts +121 -0
- package/src/classes/registration/ValidateDappAccessDiviner/Config.ts +19 -0
- package/src/classes/registration/ValidateDappAccessDiviner/Diviner.ts +132 -0
- package/src/classes/registration/ValidateDappAccessDiviner/index.ts +2 -0
- package/src/classes/registration/index.ts +2 -0
- package/src/classes/settings/Caller.ts +76 -0
- package/src/classes/settings/CallerBase.ts +24 -0
- package/src/classes/settings/Resource.ts +79 -0
- package/src/classes/settings/SettingsQueries.ts +38 -0
- package/src/classes/settings/badge/Caller.ts +30 -0
- package/src/classes/settings/badge/Queries.ts +18 -0
- package/src/classes/settings/badge/Resource.ts +54 -0
- package/src/classes/settings/badge/index.ts +2 -0
- package/src/classes/settings/index.ts +5 -0
- package/src/classes/system/ManageSystemDapps.ts +131 -0
- package/src/classes/system/Queries.ts +69 -0
- package/src/classes/system/index.ts +1 -0
- package/src/event/bus/Connection.ts +31 -0
- package/src/event/bus/EventBus.ts +145 -0
- package/src/event/bus/PubSubConnection.ts +28 -0
- package/src/event/bus/index.ts +3 -0
- package/src/event/connections/DappAccessRequest.ts +11 -0
- package/src/event/connections/DappsReady.ts +9 -0
- package/src/event/connections/ExposeDappRequest.ts +11 -0
- package/src/event/connections/OsPubSubNetworkReady.ts +12 -0
- package/src/event/connections/OsSettingsReady.ts +12 -0
- package/src/event/connections/OsXyoPublicReady.ts +12 -0
- package/src/event/connections/index.ts +6 -0
- package/src/event/index.ts +2 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/monitor/XyOsMonitor.ts +52 -0
- package/src/helpers/monitor/index.ts +2 -0
- package/src/helpers/monitor/types.ts +5 -0
- package/src/index.ts +22 -0
- package/src/intent/Caller.ts +72 -0
- package/src/intent/Resource.ts +66 -0
- package/src/intent/index.ts +2 -0
- package/src/lib/ExternalStore.ts +7 -0
- package/src/lib/Listener.ts +1 -0
- package/src/lib/ModuleAccountPaths.ts +29 -0
- package/src/lib/ModuleNames.ts +3 -0
- package/src/lib/NameTransforms.ts +31 -0
- package/src/lib/PayloadStore.ts +98 -0
- package/src/lib/ResourceStores.ts +7 -0
- package/src/lib/index.ts +10 -0
- package/src/lib/initializeXns.ts +16 -0
- package/src/lib/isPayload.ts +24 -0
- package/src/lib/tokenPlacesSplit.ts +17 -0
- package/src/loadOsNode.ts +43 -0
- package/src/manifest/ManifestReplaceableTokens.ts +17 -0
- package/src/manifest/index.ts +2 -0
- package/src/manifest/os-node.manifest.json +132 -0
- package/src/manifests/dapp-window.manifest.json +36 -0
- package/src/manifests/index.ts +1 -0
- package/src/profileModuleEvents.ts +43 -0
- package/src/stack/Base.ts +153 -0
- package/src/stack/Manager.ts +48 -0
- package/src/stack/Map.ts +20 -0
- package/src/stack/OsPubSubNetworkStack.ts +70 -0
- package/src/stack/OsSettingsStack.ts +24 -0
- package/src/stack/XyoPublicNetworkStack.ts +32 -0
- package/src/stack/index.ts +6 -0
- package/src/types/global.d.ts +9 -0
- package/src/types/images.d.ts +5 -0
- package/src/utils/buildWalletSeedPhrasePayload.ts +41 -0
- package/src/utils/getApiDomain.ts +14 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/renameObjKey.ts +22 -0
- package/src/wallet/DappSeedPhraseRepository.ts +95 -0
- package/src/wallet/SeedPhraseRepository.ts +32 -0
- package/src/wallet/index.ts +2 -0
- package/typedoc.json +5 -0
- package/xy.config.ts +10 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { BaseParams } from '@xylabs/object'
|
|
3
|
+
import { BaseEmitter } from '@xyo-network/module-abstract'
|
|
4
|
+
import type { EventData } from '@xyo-network/module-events'
|
|
5
|
+
import type { EventBusConnectionInterface, EventBusConnectionRequest, EventBusConnectionType } from '@xyo-network/os-model'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A Generic Connection to add to an EventBus
|
|
9
|
+
* @param {EventBusConnectionRequest} request
|
|
10
|
+
*/
|
|
11
|
+
export class EventBusConnection<TEventData extends EventData = EventData>
|
|
12
|
+
extends BaseEmitter<BaseParams, TEventData>
|
|
13
|
+
implements EventBusConnectionInterface<TEventData> {
|
|
14
|
+
_id?: string
|
|
15
|
+
description?: string
|
|
16
|
+
type: EventBusConnectionType
|
|
17
|
+
|
|
18
|
+
constructor(request: EventBusConnectionRequest) {
|
|
19
|
+
super({})
|
|
20
|
+
this.description = request.description
|
|
21
|
+
this.type = request.type
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get id() {
|
|
25
|
+
return assertEx(this._id, () => 'Connection ID not set. Did you forget to call buildConnection()?')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
buildConnection(id: string) {
|
|
29
|
+
this._id = id
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { forget } from '@xylabs/forget'
|
|
3
|
+
import type { ArchivistModuleEventData } from '@xyo-network/archivist'
|
|
4
|
+
import { asArchivistInstance, MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
|
|
5
|
+
import type {
|
|
6
|
+
EventBusConnectionInterface,
|
|
7
|
+
EventBusEvent,
|
|
8
|
+
EventBusInterface,
|
|
9
|
+
EventBusPubSubConnectionInterface,
|
|
10
|
+
PublisherEventListener } from '@xyo-network/os-model'
|
|
11
|
+
import {
|
|
12
|
+
isEventBusEvent,
|
|
13
|
+
isPubSubConnections,
|
|
14
|
+
} from '@xyo-network/os-model'
|
|
15
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
16
|
+
import { v4 as uuid } from 'uuid'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Event Bus implementation inspired by the DBus protocol used in Linux desktop systems for inter-process communication.
|
|
20
|
+
*
|
|
21
|
+
* General flow:
|
|
22
|
+
* 1. Connection Added
|
|
23
|
+
* 2. Publisher and Subscriber Callbacks added
|
|
24
|
+
* 3. Events occurs and stored internally
|
|
25
|
+
* 4. Subscriber Callbacks called based off stored events
|
|
26
|
+
*/
|
|
27
|
+
export class EventBus implements EventBusInterface {
|
|
28
|
+
// Internal Archivist to store event data
|
|
29
|
+
private _archivist: MemoryArchivist | undefined
|
|
30
|
+
|
|
31
|
+
// Store all connections
|
|
32
|
+
private connections: Record<string, EventBusConnectionInterface> = {}
|
|
33
|
+
|
|
34
|
+
// Store all publisher callbacks for later removal
|
|
35
|
+
private publisherCallbacks: Record<string, PublisherEventListener> = {}
|
|
36
|
+
|
|
37
|
+
get archivist() {
|
|
38
|
+
return asArchivistInstance(
|
|
39
|
+
assertEx(this._archivist, () => 'Archivist not found. Did you forget to call start()?'),
|
|
40
|
+
'not a valid archivist instance',
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
addConnection(connection: EventBusConnectionInterface) {
|
|
45
|
+
// unique connection id
|
|
46
|
+
const id = uuid()
|
|
47
|
+
|
|
48
|
+
// store in local cache
|
|
49
|
+
this.connections[id] = connection
|
|
50
|
+
|
|
51
|
+
// update the connection id with the generated id
|
|
52
|
+
connection.buildConnection(id)
|
|
53
|
+
|
|
54
|
+
// let existing connections know about newly published events
|
|
55
|
+
if (isPubSubConnections(connection)) {
|
|
56
|
+
this.handlePublisherAdd(connection)
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error('Unsupported connection type. Must be PubSub')
|
|
59
|
+
}
|
|
60
|
+
return connection
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
removeConnection(connectionId: string) {
|
|
64
|
+
// find the existing connection
|
|
65
|
+
const connection = this.connections[connectionId]
|
|
66
|
+
if (!connection) {
|
|
67
|
+
throw new Error('Connection not found ' + connectionId)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (connection && isPubSubConnections(connection)) {
|
|
71
|
+
this.handlePublisherRemove(connection)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
delete this.connections[connectionId]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async start(storeName = 'EventBusArchivist') {
|
|
78
|
+
// Later versions could include a node that has a payload diviner to query past events
|
|
79
|
+
this._archivist = await MemoryArchivist.create({ config: { name: storeName, schema: MemoryArchivistConfigSchema } })
|
|
80
|
+
|
|
81
|
+
// start listening to inserted events from publishers
|
|
82
|
+
// NOTE: This is a very basic implementation and could be optimized by indexing on connection, eventName, and callback
|
|
83
|
+
// for faster lookups by event name
|
|
84
|
+
this.archivist.on('inserted', ({ payloads }: ArchivistModuleEventData['inserted']) => {
|
|
85
|
+
// confirm an eventBusPayload was inserted
|
|
86
|
+
const eventBusEvent = payloads.find(isEventBusEvent)
|
|
87
|
+
// if not an eventBusPayload, return
|
|
88
|
+
if (!eventBusEvent) return
|
|
89
|
+
// Loop through all connections
|
|
90
|
+
for (const connectionId in this.connections) {
|
|
91
|
+
const connection = this.connections[connectionId]
|
|
92
|
+
// Target PubSub connections
|
|
93
|
+
if (isPubSubConnections(connection) && connection.subscribableEvents) {
|
|
94
|
+
// Loop through all subscribable events
|
|
95
|
+
for (const [eventName, callback] of connection.subscribableEvents.entries()) {
|
|
96
|
+
// check if the event name matches the payload name
|
|
97
|
+
if (eventName !== eventBusEvent.name) continue
|
|
98
|
+
// pass the event payloads to the callback
|
|
99
|
+
if (callback) {
|
|
100
|
+
const forgettable = async () => await callback({ payloads })
|
|
101
|
+
forget(forgettable())
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private handlePublisherAdd(connection: EventBusPubSubConnectionInterface) {
|
|
110
|
+
// Loop through all publishable events
|
|
111
|
+
for (const eventName of connection.publishableEvents ?? []) {
|
|
112
|
+
// Create publisher callback
|
|
113
|
+
const connectionPublisherCallback: PublisherEventListener = async ({ payloads }) => {
|
|
114
|
+
// build the event payload
|
|
115
|
+
const event: EventBusEvent = { name: eventName, schema: 'network.xyo.event.bus.event' }
|
|
116
|
+
const eventPayloads = payloads ?? []
|
|
117
|
+
event.sources = await PayloadBuilder.dataHashes(eventPayloads)
|
|
118
|
+
// Sync events to archivist
|
|
119
|
+
try {
|
|
120
|
+
await this.archivist.insert([event, ...(payloads ?? [])])
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.error('Error inserting event into archivist', e)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Subscribe the publisher callback to the connection
|
|
126
|
+
connection.on(eventName, connectionPublisherCallback)
|
|
127
|
+
|
|
128
|
+
// store the publisher callback for later removal
|
|
129
|
+
const callbackId = connection.id + eventName
|
|
130
|
+
this.publisherCallbacks[callbackId] = connectionPublisherCallback
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private handlePublisherRemove(connection: EventBusPubSubConnectionInterface) {
|
|
135
|
+
// Loop through all publishable events
|
|
136
|
+
for (const [, event] of connection.publishableEvents?.entries() ?? []) {
|
|
137
|
+
// find the publisher callback
|
|
138
|
+
const id = connection.id + event
|
|
139
|
+
const callback = this.publisherCallbacks[id]
|
|
140
|
+
|
|
141
|
+
// unsubscribe the publisher callback from the connection
|
|
142
|
+
if (callback) connection.off(event, callback)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventBusPubSubConnectionInterface,
|
|
3
|
+
EventBusPubSubConnectionRequest,
|
|
4
|
+
PublisherEventListenerEventData,
|
|
5
|
+
SubscribableEventListeners,
|
|
6
|
+
} from '@xyo-network/os-model'
|
|
7
|
+
|
|
8
|
+
import { EventBusConnection } from './Connection.ts'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A PubSub Connection to add to an EventBus
|
|
12
|
+
* @param {EventBusPubSubConnectionRequest} request
|
|
13
|
+
*/
|
|
14
|
+
export class EventBusPubSubConnection<TPublisherEventData extends PublisherEventListenerEventData = PublisherEventListenerEventData>
|
|
15
|
+
extends EventBusConnection<TPublisherEventData>
|
|
16
|
+
implements EventBusPubSubConnectionInterface {
|
|
17
|
+
publishableEvents?: string[]
|
|
18
|
+
subscribableEvents?: SubscribableEventListeners
|
|
19
|
+
|
|
20
|
+
constructor(request: EventBusPubSubConnectionRequest) {
|
|
21
|
+
super(request)
|
|
22
|
+
if (request.type !== 'PubSub') {
|
|
23
|
+
throw new Error('Invalid connection type. Must be PubSub')
|
|
24
|
+
}
|
|
25
|
+
this.publishableEvents = request.publishableEvents
|
|
26
|
+
this.subscribableEvents = request.subscribableEvents
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
export const DappAccessRequestEvent = 'dappAccessRequest'
|
|
6
|
+
|
|
7
|
+
const dappAccessRequestConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
8
|
+
publishableEvents: [DappAccessRequestEvent],
|
|
9
|
+
type: 'PubSub',
|
|
10
|
+
}
|
|
11
|
+
export const dappAccessRequestConnection = () => new EventBusPubSubConnection(dappAccessRequestConnectionRequest)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
const dappsReadyConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
6
|
+
publishableEvents: ['dappsReady'],
|
|
7
|
+
type: 'PubSub',
|
|
8
|
+
}
|
|
9
|
+
export const dappsReadyConnection = () => new EventBusPubSubConnection(dappsReadyConnectionRequest)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
export const ExposeDappRequestEvent = 'exposeDappRequest'
|
|
6
|
+
|
|
7
|
+
const exposeDappConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
8
|
+
publishableEvents: [ExposeDappRequestEvent],
|
|
9
|
+
type: 'PubSub',
|
|
10
|
+
}
|
|
11
|
+
export const exposeDappRequestConnection = () => new EventBusPubSubConnection(exposeDappConnectionRequest)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
export const OsPubSubNetworkReadyEvent = 'osPubSubNetworkReady'
|
|
6
|
+
|
|
7
|
+
const osPubSubNetworkConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
8
|
+
publishableEvents: [OsPubSubNetworkReadyEvent],
|
|
9
|
+
type: 'PubSub',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const osPubSubNetworkReadyConnection = () => new EventBusPubSubConnection(osPubSubNetworkConnectionRequest)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
export const OsSettingsReadyEvent = 'osSettingsReady'
|
|
6
|
+
|
|
7
|
+
const osSettingsConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
8
|
+
publishableEvents: [OsSettingsReadyEvent],
|
|
9
|
+
type: 'PubSub',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const osSettingsReadyConnection = () => new EventBusPubSubConnection(osSettingsConnectionRequest)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventBusPubSubConnectionRequest } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import { EventBusPubSubConnection } from '../bus/index.ts'
|
|
4
|
+
|
|
5
|
+
export const OsXyoPublicNetworkReadyEvent = 'osXyoPublicNetworkReady'
|
|
6
|
+
|
|
7
|
+
const osXyoPublicNetworkConnectionRequest: EventBusPubSubConnectionRequest = {
|
|
8
|
+
publishableEvents: [OsXyoPublicNetworkReadyEvent],
|
|
9
|
+
type: 'PubSub',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const osXyoPublicNetworkReadyConnection = () => new EventBusPubSubConnection(osXyoPublicNetworkConnectionRequest)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './monitor/index.ts'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { XyOsGlobal } from '@xyo-network/os-model'
|
|
2
|
+
|
|
3
|
+
import type { MonitorEventConfig } from './types.ts'
|
|
4
|
+
|
|
5
|
+
// See - https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
|
|
6
|
+
export type Connection = { downlink: number; effectiveType: string; rtt: number }
|
|
7
|
+
|
|
8
|
+
const DEFAULT_MONITORING_EVENT_NAME = 'System Task Duration'
|
|
9
|
+
|
|
10
|
+
globalThis.getXyOsGlobal
|
|
11
|
+
= globalThis.getXyOsGlobal
|
|
12
|
+
?? ((): XyOsGlobal => {
|
|
13
|
+
return {
|
|
14
|
+
tracking: {
|
|
15
|
+
trackEvent: (_event: string, _properties?: Record<string, unknown>) => void {},
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// TODO: Make this node compatible
|
|
21
|
+
const xyOsGlobal = globalThis.getXyOsGlobal()
|
|
22
|
+
|
|
23
|
+
export abstract class XyOsMonitor {
|
|
24
|
+
static trackEvent = xyOsGlobal.tracking.trackEvent
|
|
25
|
+
|
|
26
|
+
private performanceTimers = new Map<string, number>()
|
|
27
|
+
|
|
28
|
+
startTimer(name: string): void {
|
|
29
|
+
this.performanceTimers.set(name, performance.now())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
stopTimer(eventConfig: MonitorEventConfig): void {
|
|
33
|
+
const { additionalProperties, name } = eventConfig
|
|
34
|
+
const start = this.performanceTimers.get(name)
|
|
35
|
+
if (start) {
|
|
36
|
+
const end = performance.now()
|
|
37
|
+
const duration = end - start
|
|
38
|
+
this.performanceTimers.delete(name)
|
|
39
|
+
const connection = this.connection()
|
|
40
|
+
XyOsMonitor.trackEvent(DEFAULT_MONITORING_EVENT_NAME, {
|
|
41
|
+
downloadSpeedMbps: connection?.downlink,
|
|
42
|
+
duration: duration.toString(),
|
|
43
|
+
effectiveConnectionSpeed: connection?.effectiveType,
|
|
44
|
+
name,
|
|
45
|
+
roundTripTime: connection?.rtt,
|
|
46
|
+
...additionalProperties,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected abstract connection(): Connection | undefined
|
|
52
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './access-interfaces/index.ts'
|
|
2
|
+
export * from './adapter/index.ts'
|
|
3
|
+
export * from './adapters/index.ts'
|
|
4
|
+
export * from './Caller.ts'
|
|
5
|
+
export * from './classes/index.ts'
|
|
6
|
+
export * from './DappCallerBase.ts'
|
|
7
|
+
export * from './DefaultsQueries.ts'
|
|
8
|
+
export * from './event/index.ts'
|
|
9
|
+
export * from './helpers/index.ts'
|
|
10
|
+
export * from './intent/index.ts'
|
|
11
|
+
export * from './lib/index.ts'
|
|
12
|
+
export * from './loadOsNode.ts'
|
|
13
|
+
export * from './manifest/index.ts'
|
|
14
|
+
export * from './OsCallerBase.ts'
|
|
15
|
+
export * from './profileModuleEvents.ts'
|
|
16
|
+
export * from './PubSubBridgeCaller.ts'
|
|
17
|
+
export * from './stack/index.ts'
|
|
18
|
+
export * from './utils/index.ts'
|
|
19
|
+
export * from './wallet/index.ts'
|
|
20
|
+
export * from './XyOs.ts'
|
|
21
|
+
export * from './XyOsBase.ts'
|
|
22
|
+
export * from './XyOsDapp.ts'
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
2
|
+
import type { DappId, DappIntent, DappIntentTypes, XyOsContext } from '@xyo-network/os-model'
|
|
3
|
+
import { DappIntentSchema, DappMode } from '@xyo-network/os-model'
|
|
4
|
+
import type { WithMeta } from '@xyo-network/payload-model'
|
|
5
|
+
|
|
6
|
+
import { DappCallerBase } from '../DappCallerBase.ts'
|
|
7
|
+
|
|
8
|
+
export class DappIntentCaller extends DappCallerBase {
|
|
9
|
+
static OsDappName = 'XyOs'
|
|
10
|
+
constructor(context: XyOsContext) {
|
|
11
|
+
super(context)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build a new intent
|
|
16
|
+
* @param {DappId} sourceDappId
|
|
17
|
+
* @param {DappIntentTypes} intent
|
|
18
|
+
* @param {DappId} targetDappId
|
|
19
|
+
* @param {DappMode} targetMode
|
|
20
|
+
* @param {DappIntent['params']} params?
|
|
21
|
+
* @returns DappIntent
|
|
22
|
+
*/
|
|
23
|
+
static buildIntent(
|
|
24
|
+
sourceDappId: DappId,
|
|
25
|
+
intent: DappIntentTypes,
|
|
26
|
+
targetDappId?: DappId,
|
|
27
|
+
targetMode: DappMode = DappMode.Window,
|
|
28
|
+
params?: DappIntent['params'],
|
|
29
|
+
): DappIntent {
|
|
30
|
+
return {
|
|
31
|
+
intent,
|
|
32
|
+
params: params || '',
|
|
33
|
+
schema: DappIntentSchema,
|
|
34
|
+
sourceDappId,
|
|
35
|
+
targetDappId,
|
|
36
|
+
targetMode: targetMode || DappMode.Window,
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Add a new intent
|
|
42
|
+
async addIntent(id: DappId, intent: DappIntentTypes, mode: DappMode) {
|
|
43
|
+
const intentArchivist = await this.getDappIntentArchivist()
|
|
44
|
+
const newIntent = DappIntentCaller.buildIntent(id, intent, mode)
|
|
45
|
+
await intentArchivist.insert([newIntent])
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Get all intents
|
|
49
|
+
async allIntents() {
|
|
50
|
+
const archivist = await this.getDappIntentArchivist()
|
|
51
|
+
return await archivist.all()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Get the latest intent saved to the archivist
|
|
55
|
+
async latestIntent() {
|
|
56
|
+
const archivist = await this.getDappIntentArchivist()
|
|
57
|
+
return (await archivist.all()).at(-1) as WithMeta<DappIntent>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get the latest intent for a dapp
|
|
61
|
+
async latestIntentForDappName(dappName: DappId) {
|
|
62
|
+
const diviner = await this.getDappIntentArchivistPayloadDiviner()
|
|
63
|
+
const query = {
|
|
64
|
+
limit: 1,
|
|
65
|
+
order: 'desc',
|
|
66
|
+
schema: PayloadDivinerQuerySchema,
|
|
67
|
+
sourceDappId: dappName,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (await diviner.divine([query])) as WithMeta<DappIntent>[]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { DappIntent, XyOsContext } from '@xyo-network/os-model'
|
|
3
|
+
import { isDappIntent } from '@xyo-network/os-model'
|
|
4
|
+
import type { WithMeta } from '@xyo-network/payload-model'
|
|
5
|
+
|
|
6
|
+
import { DappCallerBase } from '../DappCallerBase.ts'
|
|
7
|
+
import type { Listener, ResourceStore } from '../lib/index.ts'
|
|
8
|
+
import { PayloadStore } from '../lib/index.ts'
|
|
9
|
+
|
|
10
|
+
export type DappIntentViews = 'latestDappIntent' | 'allDappIntents'
|
|
11
|
+
const NO_RESULTS: [] = []
|
|
12
|
+
|
|
13
|
+
export class DappIntentResource extends DappCallerBase implements ResourceStore<DappIntentViews> {
|
|
14
|
+
private _allDappIntents: PayloadStore<DappIntent> | undefined
|
|
15
|
+
private _latestDappIntent: PayloadStore<DappIntent> | undefined
|
|
16
|
+
|
|
17
|
+
constructor(context: XyOsContext) {
|
|
18
|
+
super(context)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get allDappIntents() {
|
|
22
|
+
return assertEx(this._allDappIntents, () => 'allDappIntents not set')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get latestDappIntent() {
|
|
26
|
+
return assertEx(this._latestDappIntent, () => 'latestDappIntent not set')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get subscriptions() {
|
|
30
|
+
return {
|
|
31
|
+
allDappIntents: (cb: Listener) => this.allDappIntents.subscribe(cb),
|
|
32
|
+
latestDappIntent: (cb: Listener) => this.latestDappIntent.subscribe(cb),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get views() {
|
|
37
|
+
return {
|
|
38
|
+
allDappIntents: () => this.allDappIntents.getSnapshot(),
|
|
39
|
+
latestDappIntent: () => this.latestDappIntent.getSnapshot(),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
cleanupListeners() {
|
|
44
|
+
this.latestDappIntent.cleanupListeners()
|
|
45
|
+
this.allDappIntents.cleanupListeners()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async start() {
|
|
49
|
+
const archivist = await this.getDappIntentArchivist()
|
|
50
|
+
|
|
51
|
+
this._allDappIntents = await PayloadStore.create<DappIntent>({
|
|
52
|
+
archivist,
|
|
53
|
+
getLatest: async () => (await archivist.all()) as WithMeta<DappIntent>[],
|
|
54
|
+
idFunction: isDappIntent,
|
|
55
|
+
})
|
|
56
|
+
this._latestDappIntent = await PayloadStore.create<DappIntent>({
|
|
57
|
+
archivist,
|
|
58
|
+
getLatest: async () => {
|
|
59
|
+
const all = await archivist.all()
|
|
60
|
+
const result = all.length > 0 ? [all.at(-1)] : NO_RESULTS
|
|
61
|
+
return result as WithMeta<DappIntent>[]
|
|
62
|
+
},
|
|
63
|
+
idFunction: isDappIntent,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Listener = (...args: Array<unknown>) => void
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DevelopArchivist, NodeSentinel } from './ModuleNames.ts'
|
|
2
|
+
|
|
3
|
+
export const RemoteNodeArchivistOffsetPaths: Record<string, Record<string, string>> = {
|
|
4
|
+
Kerplunk: {
|
|
5
|
+
[DevelopArchivist]: '118',
|
|
6
|
+
},
|
|
7
|
+
Local: {
|
|
8
|
+
[DevelopArchivist]: '115',
|
|
9
|
+
},
|
|
10
|
+
Main: {
|
|
11
|
+
[DevelopArchivist]: '121',
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ModuleOffsetPaths: Record<string, string> = {
|
|
16
|
+
IdWitness: '1',
|
|
17
|
+
DomainWitness: '2',
|
|
18
|
+
LocationWitness: '3',
|
|
19
|
+
SchemaWitness: '4',
|
|
20
|
+
CryptoCardsGameWitness: '5',
|
|
21
|
+
CryptoCardsMoveWitness: '6',
|
|
22
|
+
EthereumGasEtherchainV2Witness: '7',
|
|
23
|
+
CoingeckoCryptoMarketWitness: '8',
|
|
24
|
+
UniswapCryptoMarketWitness: '9',
|
|
25
|
+
EthereumGasEtherscanWitness: '10',
|
|
26
|
+
[NodeSentinel]: '11',
|
|
27
|
+
[DevelopArchivist]: '12',
|
|
28
|
+
BowserSystemInfoPluginWitness: '13',
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class NameTransforms {
|
|
2
|
+
constructor(private value: string) {}
|
|
3
|
+
|
|
4
|
+
static deSlug(value: string) {
|
|
5
|
+
return value
|
|
6
|
+
.replaceAll('-', ' ')
|
|
7
|
+
.split(' ')
|
|
8
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
9
|
+
.join(' ')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static moduleName(value: string) {
|
|
13
|
+
return value.replaceAll(' ', '')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static slug(value: string) {
|
|
17
|
+
return value.replaceAll(' ', '-').toLocaleLowerCase()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
deSlug() {
|
|
21
|
+
return NameTransforms.deSlug(this.value)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
moduleName() {
|
|
25
|
+
return NameTransforms.moduleName(this.value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
slug() {
|
|
29
|
+
return NameTransforms.slug(this.value)
|
|
30
|
+
}
|
|
31
|
+
}
|