Skip to content

Commit

Permalink
Module types to interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Jan 17, 2024
1 parent 9ec1709 commit b14f3ae
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ export interface Archivist<TReadResponse = Payload, TWriteResponse = Payload, TW

export interface ArchivistModuleEventData extends InsertedEventData, DeletedEventData, ClearedEventData, ModuleEventData {}

export type ArchivistQueryFunctions<TReadResponse = Payload, TWriteResponse = Payload, TWrite = TReadResponse, TId = string> = Archivist<
TReadResponse,
TWriteResponse,
TWrite,
TId
> &
ModuleQueryFunctions

export type ArchivistModule<
export interface ArchivistQueryFunctions<TReadResponse = Payload, TWriteResponse = Payload, TWrite = TReadResponse, TId = string>
extends Archivist<TReadResponse, TWriteResponse, TWrite, TId>,
ModuleQueryFunctions {}

export interface ArchivistModule<
TParams extends ModuleParams<AnyConfigSchema<ArchivistConfig>> = ModuleParams<AnyConfigSchema<ArchivistConfig>>,
TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
> = Module<TParams, TEventData>
> extends Module<TParams, TEventData> {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { ModuleInstance } from '@xyo-network/module-model'
import { ArchivistModule, ArchivistModuleEventData, ArchivistQueryFunctions } from './Archivist'
import { ArchivistParams } from './Params'

export type ArchivistInstance<
export interface ArchivistInstance<
TParams extends ArchivistParams = ArchivistParams,
TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,
> = ArchivistModule<TParams, TEventData> & ArchivistQueryFunctions & ModuleInstance<TParams, TEventData>
> extends ArchivistModule<TParams, TEventData>,
ArchivistQueryFunctions,
ModuleInstance<TParams, TEventData> {}
12 changes: 6 additions & 6 deletions packages/modules/packages/bridge/packages/model/src/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export interface Bridge {
disconnect: () => Promisable<boolean>
}

export type BridgeParams<TConfig extends AnyConfigSchema<BridgeConfig> = AnyConfigSchema<BridgeConfig>> = ModuleParams<TConfig> & ModuleParams
export interface BridgeParams<TConfig extends AnyConfigSchema<BridgeConfig> = AnyConfigSchema<BridgeConfig>>
extends ModuleParams<TConfig>,
ModuleParams<TConfig> {}

export interface BridgeModule<TParams extends BridgeParams = BridgeParams, TEventData extends ModuleEventData = ModuleEventData>
extends ModuleInstance<TParams, TEventData> {
Expand All @@ -44,8 +46,6 @@ export interface BridgeModule<TParams extends BridgeParams = BridgeParams, TEven
): Promisable<ModuleInstance | ModuleInstance[] | undefined>
}

export type BridgeInstance<TParams extends BridgeParams = BridgeParams, TEventData extends ModuleEventData = ModuleEventData> = BridgeModule<
TParams,
TEventData
> &
Bridge
export interface BridgeInstance<TParams extends BridgeParams = BridgeParams, TEventData extends ModuleEventData = ModuleEventData>
extends BridgeModule<TParams, TEventData>,
Bridge {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Query } from '@xyo-network/payload-model'
export type BridgeConnectQuerySchema = 'network.xyo.query.bridge.connect'
export const BridgeConnectQuerySchema: BridgeConnectQuerySchema = 'network.xyo.query.bridge.connect'

export type BridgeConnectQuery = Query<{
schema: BridgeConnectQuerySchema
uri?: string
}>
export interface BridgeConnectQuery
extends Query<{
schema: BridgeConnectQuerySchema
uri?: string
}> {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Query } from '@xyo-network/payload-model'
export type BridgeConnectedQuerySchema = 'network.xyo.query.bridge.connected'
export const BridgeConnectedQuerySchema: BridgeConnectedQuerySchema = 'network.xyo.query.bridge.connected'

export type BridgeConnectedQuery = Query<{
schema: BridgeConnectedQuerySchema
}>
export interface BridgeConnectedQuery
extends Query<{
schema: BridgeConnectedQuerySchema
}> {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Query } from '@xyo-network/payload-model'
export type BridgeDisconnectQuerySchema = 'network.xyo.query.bridge.disconnect'
export const BridgeDisconnectQuerySchema: BridgeDisconnectQuerySchema = 'network.xyo.query.bridge.disconnect'

export type BridgeDisconnectQuery = Query<{
schema: BridgeDisconnectQuerySchema
uri?: string
}>
export interface BridgeDisconnectQuery
extends Query<{
schema: BridgeDisconnectQuerySchema
uri?: string
}> {}
17 changes: 9 additions & 8 deletions packages/modules/packages/diviner/packages/model/src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { DivinerModuleEventData } from './EventData'
import { CustomDivinerModule, DivinerModule } from './Module'
import { DivinerParams } from './Params'

export type DivinerInstance<
TParams extends DivinerParams = DivinerParams,
TIn extends Payload = Payload,
TOut extends Payload = Payload,
> = DivinerModule<TParams, TIn, TOut> & DivinerQueryFunctions & ModuleInstance
export interface DivinerInstance<TParams extends DivinerParams = DivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload>
extends DivinerModule<TParams, TIn, TOut>,
DivinerQueryFunctions,
ModuleInstance<TParams, DivinerModuleEventData<DivinerModule<TParams, TIn, TOut>>> {}

export type CustomDivinerInstance<
export interface CustomDivinerInstance<
TParams extends DivinerParams = DivinerParams,
TIn extends Payload = Payload,
TOut extends Payload = Payload,
Expand All @@ -21,7 +20,9 @@ export type CustomDivinerInstance<
TIn,
TOut
>,
> = CustomDivinerModule<TParams, TIn, TOut, TEvents> & DivinerQueryFunctions & ModuleInstance
> extends CustomDivinerModule<TParams, TIn, TOut, TEvents>,
DivinerQueryFunctions,
ModuleInstance<TParams, TEvents> {}

/** @deprecated use DivinerInstance instead */
export type Diviner = DivinerInstance
export interface Diviner extends DivinerInstance {}
10 changes: 4 additions & 6 deletions packages/modules/packages/diviner/packages/model/src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Payload } from '@xyo-network/payload-model'
import { DivinerModuleEventData } from './EventData'
import { DivinerParams } from './Params'

export type DivinerModule<TParams extends DivinerParams = DivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload> = Module<
TParams,
DivinerModuleEventData<DivinerModule<TParams, TIn, TOut>>
>
export interface DivinerModule<TParams extends DivinerParams = DivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload>
extends Module<TParams, DivinerModuleEventData<DivinerModule<TParams, TIn, TOut>>> {}

export type CustomDivinerModule<
export interface CustomDivinerModule<
TParams extends DivinerParams = DivinerParams,
TIn extends Payload = Payload,
TOut extends Payload = Payload,
TEvents extends DivinerModuleEventData<DivinerModule<TParams, TIn, TOut>> = DivinerModuleEventData<DivinerModule<TParams, TIn, TOut>>,
> = Module<TParams, TEvents>
> extends Module<TParams, TEvents> {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ export interface ModuleResolver extends ResolveFunctions {
removeResolver: (resolver: ModuleResolver) => this
}

export type ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData> = Module<
TParams,
TEventData
> &
ResolveFunctions &
ModuleQueryFunctions & {
/* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/
readonly downResolver: Omit<ModuleResolver, 'resolve'>
export interface ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>
extends Module<TParams, TEventData>,
ResolveFunctions,
ModuleQueryFunctions {
/* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/
readonly downResolver: Omit<ModuleResolver, 'resolve'>

/* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/
/* This is set by a NodeModule when attaching to the module */
readonly upResolver: Omit<ModuleResolver, 'resolve'>
}
/* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/
/* This is set by a NodeModule when attaching to the module */
readonly upResolver: Omit<ModuleResolver, 'resolve'>
}

export type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ModuleEventData } from '../EventsModels'
import { ModuleParams } from '../ModuleParams'
import { ModuleFields } from './ModuleFields'

export type Module<
TParams extends ModuleParams = ModuleParams,
TEventData extends ModuleEventData<object> = ModuleEventData<object>,
> = ModuleFields<TParams> & EventFunctions<TEventData>
export interface Module<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData<object> = ModuleEventData<object>>
extends ModuleFields<TParams>,
EventFunctions<TEventData> {}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function constructableModuleWrapper<TWrapper extends ModuleWrapper>() {
@constructableModuleWrapper()
export class ModuleWrapper<TWrappedModule extends Module = Module>
extends Base<Exclude<Omit<TWrappedModule['params'], 'config'> & { config: Exclude<TWrappedModule['params']['config'], undefined> }, undefined>>
implements ModuleInstance<TWrappedModule['params']>
implements ModuleInstance<TWrappedModule['params'], TWrappedModule['eventData']>
{
static instanceIdentityCheck: InstanceTypeCheck = isModuleInstance
static moduleIdentityCheck: ModuleTypeCheck = isModule
Expand Down
24 changes: 9 additions & 15 deletions packages/modules/packages/node/packages/model/src/Node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Promisable } from '@xylabs/promise'
import { ModuleManifestPayload } from '@xyo-network/manifest-model'
import { Module, ModuleEventData, ModuleInstance } from '@xyo-network/module-model'

import { ModuleAttachedEventData, ModuleDetachedEventData, ModuleRegisteredEventData, ModuleUnregisteredEventData } from './EventsModels'
Expand All @@ -9,7 +8,6 @@ export interface NodeQueryFunctions {
attach(nameOrAddress: string, external?: boolean): Promisable<string | undefined>
attached(): Promisable<string[]>
detach(nameOrAddress: string): Promisable<string | undefined>
manifest(maxDepth?: number): Promise<ModuleManifestPayload>
registered(): Promisable<string[]>
}

Expand All @@ -20,17 +18,13 @@ export interface NodeModuleEventData
ModuleUnregisteredEventData,
ModuleEventData {}

export type NodeModule<TParams extends NodeParams = NodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData> = Module<
TParams,
TEventData
>
export interface NodeModule<TParams extends NodeParams = NodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>
extends Module<TParams, TEventData> {}

export type NodeInstance<TParams extends NodeParams = NodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData> = NodeModule<
TParams,
TEventData
> &
NodeQueryFunctions &
ModuleInstance & {
register: (mod: ModuleInstance) => Promisable<void>
registeredModules(): Promisable<ModuleInstance[]>
}
export interface NodeInstance<TParams extends NodeParams = NodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>
extends NodeModule<TParams, TEventData>,
NodeQueryFunctions,
ModuleInstance<TParams, TEventData> {
register: (mod: ModuleInstance) => Promisable<void>
registeredModules(): Promisable<ModuleInstance[]>
}
13 changes: 10 additions & 3 deletions packages/modules/packages/sentinel/packages/model/src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import { CustomSentinelModule, SentinelModule } from './Module'
import { SentinelParams } from './Params'
import { Sentinel } from './Sentinel'

export type SentinelInstance<TParams extends SentinelParams = SentinelParams> = SentinelModule<TParams> & Sentinel & ModuleInstance<TParams>
export interface SentinelInstance<
TParams extends SentinelParams = SentinelParams,
TEventData extends SentinelModuleEventData = SentinelModuleEventData,
> extends SentinelModule<TParams, TEventData>,
Sentinel,
ModuleInstance<TParams, TEventData> {}

export type CustomSentinelInstance<
export interface CustomSentinelInstance<
TParams extends SentinelParams = SentinelParams,
TEvents extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,
> = CustomSentinelModule<TParams, TEvents> & Sentinel & SentinelInstance<TParams>
> extends CustomSentinelModule<TParams, TEvents>,
Sentinel,
SentinelInstance<TParams, TEvents> {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Module } from '@xyo-network/module-model'
import { SentinelModuleEventData } from './EventData'
import { SentinelParams } from './Params'

export type SentinelModule<TParams extends SentinelParams = SentinelParams> = Module<TParams, SentinelModuleEventData<SentinelModule>>
export interface SentinelModule<TParams extends SentinelParams = SentinelParams, TEventData extends SentinelModuleEventData = SentinelModuleEventData>
extends Module<TParams, TEventData> {}

export type CustomSentinelModule<
export interface CustomSentinelModule<
TParams extends SentinelParams = SentinelParams,
TEvents extends SentinelModuleEventData<SentinelModule<TParams>> = SentinelModuleEventData<SentinelModule<TParams>>,
> = Module<TParams, TEvents>
> extends Module<TParams, TEvents> {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CustomWitnessModule } from './CustomModule'
import { WitnessModuleEventData } from './EventData'
import { WitnessInstance } from './Instance'
import { WitnessParams } from './Params'
import { Witness } from './Witness'
import { WitnessQueryFunctions } from './QueryFunctions'

export type CustomWitnessInstance<
TParams extends WitnessParams = WitnessParams,
Expand All @@ -16,4 +16,4 @@ export type CustomWitnessInstance<
TIn,
TOut
>,
> = CustomWitnessModule<TParams, TIn, TOut, TEvents> & Witness<TIn, TOut> & ModuleInstance
> = CustomWitnessModule<TParams, TIn, TOut, TEvents> & WitnessQueryFunctions<TIn, TOut> & ModuleInstance
12 changes: 6 additions & 6 deletions packages/modules/packages/witness/packages/model/src/Instance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ModuleInstance } from '@xyo-network/module-model'
import { Payload } from '@xyo-network/payload-model'

import { WitnessModuleEventData } from './EventData'
import { WitnessModule } from './Module'
import { WitnessParams } from './Params'
import { Witness } from './Witness'
import { WitnessQueryFunctions } from './QueryFunctions'

export type WitnessInstance<
TParams extends WitnessParams = WitnessParams,
TIn extends Payload = Payload,
TOut extends Payload = Payload,
> = WitnessModule<TParams> & Witness<TIn, TOut> & ModuleInstance
export interface WitnessInstance<TParams extends WitnessParams = WitnessParams, TIn extends Payload = Payload, TOut extends Payload = Payload>
extends WitnessModule<TParams, TIn, TOut>,
WitnessQueryFunctions,
ModuleInstance<TParams, WitnessModuleEventData<WitnessModule<TParams, TIn, TOut>>> {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import { Payload } from '@xyo-network/payload-model'
import { WitnessModuleEventData } from './EventData'
import { WitnessParams } from './Params'

export type WitnessModule<TParams extends WitnessParams = WitnessParams, TIn extends Payload = Payload, TOut extends Payload = Payload> = Module<
TParams,
WitnessModuleEventData<WitnessModule, TIn, TOut>
>
export interface WitnessModule<TParams extends WitnessParams = WitnessParams, TIn extends Payload = Payload, TOut extends Payload = Payload>
extends Module<TParams, WitnessModuleEventData<WitnessModule<TParams, TIn, TOut>>> {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Promisable } from '@xylabs/promise'
import { Payload } from '@xyo-network/payload-model'

export interface Witness<TIn extends Payload = Payload, TOut extends Payload = Payload> {
export interface WitnessQueryFunctions<TIn extends Payload = Payload, TOut extends Payload = Payload> {
observe: (payloads?: TIn[]) => Promisable<TOut[]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export * from './Instance'
export * from './Module'
export * from './Params'
export * from './Queries'
export * from './QueryFunctions'
export * from './typeChecks'
export * from './Witness'
18 changes: 9 additions & 9 deletions packages/payload/packages/address/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"typescript": "^5.3.3"
},
"description": "Typescript/Javascript Plugins for XYO Platform",
"docs": "dist/docs.json",
"exports": {
".": {
"browser": {
Expand All @@ -34,19 +33,20 @@
},
"node": {
"require": {
"types": "./dist/node/index.d.ts",
"default": "./dist/node/index.js"
"types": "./dist/node/index.d.cts",
"default": "./dist/node/index.cjs"
},
"import": {
"types": "./dist/node/index.d.mts",
"default": "./dist/node/index.mjs"
"default": "./dist/node/index.js"
}
}
},
"./package.json": "./package.json"
},
"main": "dist/node/index.js",
"module": "dist/node/index.mjs",
"main": "dist/node/index.cjs",
"module": "dist/node/index.js",
"types": "dist/node/index.d.ts",
"homepage": "https://xyo.network",
"license": "LGPL-3.0-only",
"publishConfig": {
Expand All @@ -57,6 +57,6 @@
"url": "https://github.com/XYOracleNetwork/plugins.git"
},
"sideEffects": false,
"types": "dist/node/index.d.ts",
"version": "2.87.0"
}
"version": "2.87.0",
"type": "module"
}
Loading

0 comments on commit b14f3ae

Please sign in to comment.