From 060f3be04b0591fdc2e4a88a30a1e8617820ee15 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 1 Aug 2023 14:24:17 -0700 Subject: [PATCH] resolve up/down precision improved --- packages/manifest/src/spec/Manifest.spec.ts | 12 +- .../module-resolver/src/ModuleResolver.ts | 64 ++++--- .../packages/abstract/src/AbstractModule.ts | 8 +- .../abstract/src/AbstractModuleInstance.ts | 1 + .../src/Resolver/CompositeModuleResolver.ts | 26 ++- .../model/src/instance/ModuleInstance.ts | 1 + .../packages/node/packages/model/src/Node.ts | 2 +- .../WithArchivistAndDiviner.spec.ts | 10 ++ .../modules/packages/node/src/AbstractNode.ts | 2 +- .../modules/packages/sentinel/package.json | 1 + .../sentinel/packages/model/.npmignore | 21 +++ .../packages/sentinel/packages/model/LICENSE | 165 ++++++++++++++++++ .../sentinel/packages/model/README.md | 13 ++ .../sentinel/packages/model/package.json | 69 ++++++++ .../model => packages/model/src}/Config.ts | 0 .../model => packages/model/src}/EventData.ts | 0 .../model/src}/Events/ReportEnd.ts | 0 .../model/src}/Events/ReportStart.ts | 0 .../model/src}/Events/index.ts | 0 .../model => packages/model/src}/Instance.ts | 0 .../model => packages/model/src}/Module.ts | 0 .../model => packages/model/src}/Params.ts | 0 .../model/src}/Queries/Report.ts | 0 .../model/src}/Queries/index.ts | 0 .../model => packages/model/src}/Sentinel.ts | 0 .../model => packages/model/src}/index.ts | 1 + .../{ => packages/model}/src/typeChecks.ts | 4 +- .../sentinel/packages/model/tsconfig.json | 9 + .../packages/model/tsconfig.typedoc.json | 5 + .../sentinel/packages/model/typedoc.json | 5 + .../packages/sentinel/src/AbstractSentinel.ts | 7 +- .../packages/sentinel/src/MemorySentinel.ts | 9 +- .../packages/sentinel/src/SentinelRunner.ts | 2 +- .../modules/packages/sentinel/src/Wrapper.ts | 11 +- .../modules/packages/sentinel/src/index.ts | 3 +- .../sentinel/src/spec/Sentinel.spec.ts | 2 +- .../sentinel/src/spec/SentinelRunner.spec.ts | 2 +- yarn.lock | 27 +++ 38 files changed, 426 insertions(+), 56 deletions(-) create mode 100644 packages/modules/packages/sentinel/packages/model/.npmignore create mode 100644 packages/modules/packages/sentinel/packages/model/LICENSE create mode 100644 packages/modules/packages/sentinel/packages/model/README.md create mode 100644 packages/modules/packages/sentinel/packages/model/package.json rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Config.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/EventData.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Events/ReportEnd.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Events/ReportStart.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Events/index.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Instance.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Module.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Params.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Queries/Report.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Queries/index.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/Sentinel.ts (100%) rename packages/modules/packages/sentinel/{src/model => packages/model/src}/index.ts (87%) rename packages/modules/packages/sentinel/{ => packages/model}/src/typeChecks.ts (83%) create mode 100644 packages/modules/packages/sentinel/packages/model/tsconfig.json create mode 100644 packages/modules/packages/sentinel/packages/model/tsconfig.typedoc.json create mode 100644 packages/modules/packages/sentinel/packages/model/typedoc.json diff --git a/packages/manifest/src/spec/Manifest.spec.ts b/packages/manifest/src/spec/Manifest.spec.ts index 08f4f7bb96c..513e3f846b8 100644 --- a/packages/manifest/src/spec/Manifest.spec.ts +++ b/packages/manifest/src/spec/Manifest.spec.ts @@ -16,11 +16,11 @@ describe('Manifest', () => { expect(node).toBeDefined() const discover = await node.discover() const discoveredAddresses = discover.filter((item) => item.schema === AddressSchema) - expect(discoveredAddresses.length).toBeGreaterThan(4) - expect(await node.resolve()).toBeArrayOfSize(15) + expect(discoveredAddresses.length).toBe(4) + expect((await node.resolve()).length).toBeGreaterThan(10) const roundTrip = await node.manifest() expect(roundTrip.modules?.private).toBeArrayOfSize(1) - expect(roundTrip.modules?.public).toBeArrayOfSize(14) + expect(roundTrip.modules?.public?.length).toBeGreaterThan(10) }) }) describe('Create Node from Manifest [Lazy]', () => { @@ -32,11 +32,11 @@ describe('Manifest', () => { expect(node).toBeDefined() const discover = await node.discover() const discoveredAddresses = discover.filter((item) => item.schema === AddressSchema) - expect(discoveredAddresses.length).toBeGreaterThan(4) - expect(await node.resolve()).toBeArrayOfSize(15) + expect(discoveredAddresses.length).toBe(4) + expect((await node.resolve()).length).toBeGreaterThan(10) const roundTrip = await node.manifest() expect(roundTrip.modules?.private).toBeArrayOfSize(1) - expect(roundTrip.modules?.public).toBeArrayOfSize(14) + expect(roundTrip.modules?.public?.length).toBeGreaterThan(10) }) }) }) diff --git a/packages/modules/packages/bridge/packages/module-resolver/src/ModuleResolver.ts b/packages/modules/packages/bridge/packages/module-resolver/src/ModuleResolver.ts index 441ad26b7ed..b645b476997 100644 --- a/packages/modules/packages/bridge/packages/module-resolver/src/ModuleResolver.ts +++ b/packages/modules/packages/bridge/packages/module-resolver/src/ModuleResolver.ts @@ -11,6 +11,7 @@ import { AddressModuleFilter, Module, ModuleFilter, + ModuleFilterOptions, ModuleInstance, ModuleResolver, NameModuleFilter, @@ -93,22 +94,37 @@ export class BridgeModuleResolver extends CompositeModuleResolver implements Mod throw new Error('Method not implemented.') } - override async resolve(filter?: ModuleFilter): Promise - override async resolve(nameOrAddress: string): Promise - override async resolve(nameOrAddressOrFilter?: ModuleFilter | string): Promise { + override async resolve( + filter?: ModuleFilter, + options?: ModuleFilterOptions, + ): Promise + override async resolve( + nameOrAddress: string, + options?: ModuleFilterOptions, + ): Promise + override async resolve( + nameOrAddressOrFilter?: ModuleFilter | string, + options?: ModuleFilterOptions, + ): Promise { + const mutatedOptions = { ...options, maxDepth: (options?.maxDepth ?? BridgeModuleResolver.defaultMaxDepth) - 1 } await this.prime() await this.resolveRemoteModules() if (typeof nameOrAddressOrFilter === 'string') { - const result: ModuleInstance | undefined = - (await this.resolveByAddress(nameOrAddressOrFilter)) ?? (await this.resolveByName(nameOrAddressOrFilter)) + if (mutatedOptions.maxDepth < 0) { + return undefined + } + const result: T | undefined = (await this.resolveByAddress(nameOrAddressOrFilter)) ?? (await this.resolveByName(nameOrAddressOrFilter)) return result } else { - const result: ModuleInstance[] = await this.resolveRemoteModules(nameOrAddressOrFilter) + if (mutatedOptions.maxDepth < 0) { + return [] + } + const result: T[] = await this.resolveRemoteModules(nameOrAddressOrFilter) return result } } - private async resolveByAddress(targetAddress: string): Promise { + private async resolveByAddress(targetAddress: string): Promise { const remoteAddresses = await this.getRemoteAddresses() //check if it is even there @@ -118,7 +134,7 @@ export class BridgeModuleResolver extends CompositeModuleResolver implements Mod } const cached = this.resolvedModules[targetAddress] - if (cached) return await cached + if (cached) return (await cached) as T this.resolvedModules[targetAddress] = this.resolvedModules[targetAddress] ?? @@ -157,52 +173,52 @@ export class BridgeModuleResolver extends CompositeModuleResolver implements Mod } })(targetAddress) - return await this.resolvedModules[targetAddress] + return (await this.resolvedModules[targetAddress]) as T } - private async resolveByName(name: string): Promise { + private async resolveByName(name: string): Promise { const modules = await this.currentResolvedModules() return Object.values(modules) .filter((module) => module.config.name === name) - .pop() + .pop() as T } - private async resolveByQuery(queries: string[]): Promise { + private async resolveByQuery(queries: string[]): Promise { return Object.values(await this.currentResolvedModules()).filter((module) => { //filter out the requested queries const found = module.queries.filter((query) => queries.find((q) => q === query)) //did we find all the requested queries? return queries.length === found.length - }) + }) as T[] } - private async resolveRemoteModules(filter?: ModuleFilter): Promise { + private async resolveRemoteModules(filter?: ModuleFilter): Promise { if ((filter as AddressModuleFilter)?.address) { - return await this.resolveRemoteModulesByAddress(filter as AddressModuleFilter) + return await this.resolveRemoteModulesByAddress(filter as AddressModuleFilter) } if ((filter as NameModuleFilter)?.name) { - return await this.resolveRemoteModulesByName(filter as NameModuleFilter) + return await this.resolveRemoteModulesByName(filter as NameModuleFilter) } if ((filter as QueryModuleFilter)?.query) { - return await this.resolveRemoteModulesByQuery(filter as QueryModuleFilter) + return await this.resolveRemoteModulesByQuery(filter as QueryModuleFilter) } //get all of them - return await this.resolveRemoteModulesByAddress({ address: await this.getRemoteAddresses() }) + return await this.resolveRemoteModulesByAddress({ address: await this.getRemoteAddresses() }) } - private async resolveRemoteModulesByAddress(filter: AddressModuleFilter): Promise { - return compact(await Promise.all(filter.address.map((address) => this.resolveByAddress(address)))) + private async resolveRemoteModulesByAddress(filter: AddressModuleFilter): Promise { + return compact(await Promise.all(filter.address.map((address) => this.resolveByAddress(address)))) } - private async resolveRemoteModulesByName(filter: NameModuleFilter): Promise { - return compact(await Promise.all(filter.name.map(async (name) => await this.resolveByName(name)))) + private async resolveRemoteModulesByName(filter: NameModuleFilter): Promise { + return compact(await Promise.all(filter.name.map(async (name) => await this.resolveByName(name)))) } - private async resolveRemoteModulesByQuery(filter: QueryModuleFilter): Promise { - return compact((await Promise.all(filter.query.map(async (query) => await this.resolveByQuery(query)))).flat()) + private async resolveRemoteModulesByQuery(filter: QueryModuleFilter): Promise { + return compact((await Promise.all(filter.query.map(async (query) => await this.resolveByQuery(query)))).flat()) } } diff --git a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts index 4ba5cfbd8dd..ab5acd72089 100644 --- a/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts +++ b/packages/modules/packages/module/packages/abstract/src/AbstractModule.ts @@ -291,15 +291,15 @@ export abstract class AbstractModule< switch (typeof nameOrAddressOrFilter) { case 'string': { return ( - (down ? await (this.downResolver as CompositeModuleResolver).resolve(nameOrAddressOrFilter) : undefined) ?? - (up ? await (this.upResolver as ModuleResolver).resolve(nameOrAddressOrFilter) : undefined) + (down ? await (this.downResolver as CompositeModuleResolver).resolve(nameOrAddressOrFilter, options) : undefined) ?? + (up ? await (this.upResolver as ModuleResolver).resolve(nameOrAddressOrFilter, options) : undefined) ) } default: { const filter: ModuleFilter | undefined = nameOrAddressOrFilter return [ - ...(down ? await (this.downResolver as CompositeModuleResolver).resolve(filter) : []), - ...(up ? await (this.upResolver as ModuleResolver).resolve(filter) : []), + ...(down ? await (this.downResolver as CompositeModuleResolver).resolve(filter, options) : []), + ...(up ? await (this.upResolver as ModuleResolver).resolve(filter, options) : []), ].filter(duplicateModules) } } diff --git a/packages/modules/packages/module/packages/abstract/src/AbstractModuleInstance.ts b/packages/modules/packages/module/packages/abstract/src/AbstractModuleInstance.ts index 0cb9b6865f0..77e5c9571a7 100644 --- a/packages/modules/packages/module/packages/abstract/src/AbstractModuleInstance.ts +++ b/packages/modules/packages/module/packages/abstract/src/AbstractModuleInstance.ts @@ -26,6 +26,7 @@ export abstract class AbstractModuleInstance< // Clone params to prevent mutation of the incoming object const mutatedParams = { ...params } as TParams super(privateConstructorKey, mutatedParams, account) + this.upResolver.add(this) this.downResolver.add(this) } diff --git a/packages/modules/packages/module/packages/abstract/src/Resolver/CompositeModuleResolver.ts b/packages/modules/packages/module/packages/abstract/src/Resolver/CompositeModuleResolver.ts index 2e603e24542..4d34970f642 100644 --- a/packages/modules/packages/module/packages/abstract/src/Resolver/CompositeModuleResolver.ts +++ b/packages/modules/packages/module/packages/abstract/src/Resolver/CompositeModuleResolver.ts @@ -1,10 +1,11 @@ import { exists } from '@xylabs/exists' import { Base, BaseParams } from '@xyo-network/core' -import { duplicateModules, ModuleFilter, ModuleInstance, ModuleRepository, ModuleResolver } from '@xyo-network/module-model' +import { duplicateModules, ModuleFilter, ModuleFilterOptions, ModuleInstance, ModuleRepository, ModuleResolver } from '@xyo-network/module-model' import { SimpleModuleResolver } from './SimpleModuleResolver' export class CompositeModuleResolver extends Base implements ModuleRepository, ModuleResolver { + static defaultMaxDepth = 4 protected resolvers: ModuleResolver[] = [] private localResolver: SimpleModuleResolver @@ -49,22 +50,35 @@ export class CompositeModuleResolver extends Base implements ModuleRepository, M return this } - async resolve(filter?: ModuleFilter): Promise - async resolve(nameOrAddress: string): Promise - async resolve(nameOrAddressOrFilter?: ModuleFilter | string): Promise { + async resolve(filter?: ModuleFilter, options?: ModuleFilterOptions): Promise + async resolve( + nameOrAddress: string, + options?: ModuleFilterOptions, + ): Promise + async resolve( + nameOrAddressOrFilter?: ModuleFilter | string, + options?: ModuleFilterOptions, + ): Promise { + const mutatedOptions = { ...options, maxDepth: (options?.maxDepth ?? CompositeModuleResolver.defaultMaxDepth) - 1 } if (typeof nameOrAddressOrFilter === 'string') { + if (mutatedOptions.maxDepth < 0) { + return undefined + } const results = await Promise.all( this.resolvers.map(async (resolver) => { - const result: ModuleInstance | undefined = await resolver.resolve(nameOrAddressOrFilter) + const result: ModuleInstance | undefined = await resolver.resolve(nameOrAddressOrFilter, mutatedOptions) return result }), ) const result: ModuleInstance | undefined = results.filter(exists).filter(duplicateModules).pop() return result } else { + if (mutatedOptions.maxDepth < 0) { + return [] + } const result = await Promise.all( this.resolvers.map(async (resolver) => { - const result: ModuleInstance[] = await resolver.resolve(nameOrAddressOrFilter) + const result: ModuleInstance[] = await resolver.resolve(nameOrAddressOrFilter, mutatedOptions) return result }), ) diff --git a/packages/modules/packages/module/packages/model/src/instance/ModuleInstance.ts b/packages/modules/packages/module/packages/model/src/instance/ModuleInstance.ts index 442ae1905d7..9884b0b5806 100644 --- a/packages/modules/packages/module/packages/model/src/instance/ModuleInstance.ts +++ b/packages/modules/packages/module/packages/model/src/instance/ModuleInstance.ts @@ -39,6 +39,7 @@ export class IsInstanceFactory extend export interface ModuleFilterOptions { direction?: 'up' | 'down' | 'all' identity?: InstanceTypeCheck + maxDepth?: number visibility?: 'public' | 'private' | 'all' } diff --git a/packages/modules/packages/node/packages/model/src/Node.ts b/packages/modules/packages/node/packages/model/src/Node.ts index 356c5571bac..6afa4101ce8 100644 --- a/packages/modules/packages/node/packages/model/src/Node.ts +++ b/packages/modules/packages/node/packages/model/src/Node.ts @@ -37,6 +37,6 @@ export type NodeInstance< > = NodeModule & NodeQueryFunctions & ModuleInstance & { - register: (module: ModuleInstance) => void + register: (module: ModuleInstance) => Promisable registeredModules(): Promisable } diff --git a/packages/modules/packages/node/spec/MemoryNode/WithArchivistAndDiviner.spec.ts b/packages/modules/packages/node/spec/MemoryNode/WithArchivistAndDiviner.spec.ts index 866faee9d21..227caf90b5d 100644 --- a/packages/modules/packages/node/spec/MemoryNode/WithArchivistAndDiviner.spec.ts +++ b/packages/modules/packages/node/spec/MemoryNode/WithArchivistAndDiviner.spec.ts @@ -64,5 +64,15 @@ describe('MemoryNode', () => { } } } + + expect((await node.resolve(undefined, { direction: 'up' })).length).toBe(1) + expect((await node.resolve(undefined, { direction: 'down' })).length).toBe(3) + expect((await node.resolve(undefined, { direction: 'down', maxDepth: 1 })).length).toBe(1) + expect((await node.resolve(undefined, { direction: 'all' })).length).toBe(3) + + expect((await archivist.resolve(undefined, { direction: 'up' })).length).toBe(3) + expect((await archivist.resolve(undefined, { direction: 'up', maxDepth: 1 })).length).toBe(1) + expect((await archivist.resolve(undefined, { direction: 'down' })).length).toBe(1) + expect((await archivist.resolve(undefined, { direction: 'all' })).length).toBe(3) }) }) diff --git a/packages/modules/packages/node/src/AbstractNode.ts b/packages/modules/packages/node/src/AbstractNode.ts index 405e492bd40..740b6dfddd2 100644 --- a/packages/modules/packages/node/src/AbstractNode.ts +++ b/packages/modules/packages/node/src/AbstractNode.ts @@ -64,7 +64,7 @@ export abstract class AbstractNode { - return (await (this.resolve() ?? [])).filter((module) => module.address !== this.address) + return (await (this.resolve(undefined, { direction: 'down', maxDepth: 2 }) ?? [])).filter((module) => module.address !== this.address) } override async manifest(ignoreAddresses?: string[]): Promise { diff --git a/packages/modules/packages/sentinel/package.json b/packages/modules/packages/sentinel/package.json index 2e28f587e5a..37c469c1c86 100644 --- a/packages/modules/packages/sentinel/package.json +++ b/packages/modules/packages/sentinel/package.json @@ -23,6 +23,7 @@ "@xyo-network/payload-model": "workspace:~", "@xyo-network/payload-wrapper": "workspace:~", "@xyo-network/promise": "workspace:~", + "@xyo-network/sentinel-model": "workspace:~", "@xyo-network/witness": "workspace:~", "lodash": "^4.17.21" }, diff --git a/packages/modules/packages/sentinel/packages/model/.npmignore b/packages/modules/packages/sentinel/packages/model/.npmignore new file mode 100644 index 00000000000..0430e8967b1 --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/.npmignore @@ -0,0 +1,21 @@ +.* +.env +.eslintcache +.example.env +tsconfig* +jest.config.js +rollup.config.ts +yarn.lock +**/*.spec.ts +**/*.snap + +.github +docs +.pnp.* +.vscode +.yarn/* +coverage +cspell.json +node_modules +swagger.json +packages \ No newline at end of file diff --git a/packages/modules/packages/sentinel/packages/model/LICENSE b/packages/modules/packages/sentinel/packages/model/LICENSE new file mode 100644 index 00000000000..0a041280bd0 --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/packages/modules/packages/sentinel/packages/model/README.md b/packages/modules/packages/sentinel/packages/model/README.md new file mode 100644 index 00000000000..cd0084ca798 --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/README.md @@ -0,0 +1,13 @@ +[![logo][]](https://xyo.network) + +Part of [sdk-xyo-clint-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js) + +## License + +> See the [LICENSE](LICENSE) file for license details + +## Credits + +[Made with 🔥 and ❄️ by XYO](https://xyo.network) + +[logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png \ No newline at end of file diff --git a/packages/modules/packages/sentinel/packages/model/package.json b/packages/modules/packages/sentinel/packages/model/package.json new file mode 100644 index 00000000000..ad08cde2f67 --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/package.json @@ -0,0 +1,69 @@ +{ + "name": "@xyo-network/sentinel-model", + "author": { + "email": "support@xyo.network", + "name": "XYO Development Team", + "url": "https://xyo.network" + }, + "bugs": { + "email": "support@xyo.network", + "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues" + }, + "dependencies": { + "@xylabs/assert": "^2.9.3", + "@xylabs/promise": "^2.9.3", + "@xyo-network/archivist": "workspace:~", + "@xyo-network/boundwitness-builder": "workspace:~", + "@xyo-network/boundwitness-model": "workspace:~", + "@xyo-network/core": "workspace:~", + "@xyo-network/error": "workspace:~", + "@xyo-network/module": "workspace:~", + "@xyo-network/module-model": "workspace:~", + "@xyo-network/object-identity": "workspace:~", + "@xyo-network/payload-model": "workspace:~", + "@xyo-network/payload-wrapper": "workspace:~", + "@xyo-network/promise": "workspace:~", + "@xyo-network/witness": "workspace:~", + "lodash": "^4.17.21" + }, + "description": "Primary SDK for using XYO Protocol 2.0", + "devDependencies": { + "@types/lodash": "^4.14.196", + "@xylabs/ts-scripts-yarn3": "^2.19.0", + "@xylabs/tsconfig": "^2.19.0", + "typescript": "^5.1.6" + }, + "browser": "dist/esm/index.js", + "docs": "dist/docs.json", + "exports": { + ".": { + "node": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "browser": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "default": "./dist/esm/index.js" + }, + "./dist/docs.json": { + "default": "./dist/docs.json" + }, + "./package.json": "./package.json" + }, + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "homepage": "https://xyo.network", + "license": "LGPL-3.0", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git" + }, + "sideEffects": false, + "types": "dist/types/index.d.ts", + "version": "2.69.2" +} diff --git a/packages/modules/packages/sentinel/src/model/Config.ts b/packages/modules/packages/sentinel/packages/model/src/Config.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Config.ts rename to packages/modules/packages/sentinel/packages/model/src/Config.ts diff --git a/packages/modules/packages/sentinel/src/model/EventData.ts b/packages/modules/packages/sentinel/packages/model/src/EventData.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/EventData.ts rename to packages/modules/packages/sentinel/packages/model/src/EventData.ts diff --git a/packages/modules/packages/sentinel/src/model/Events/ReportEnd.ts b/packages/modules/packages/sentinel/packages/model/src/Events/ReportEnd.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Events/ReportEnd.ts rename to packages/modules/packages/sentinel/packages/model/src/Events/ReportEnd.ts diff --git a/packages/modules/packages/sentinel/src/model/Events/ReportStart.ts b/packages/modules/packages/sentinel/packages/model/src/Events/ReportStart.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Events/ReportStart.ts rename to packages/modules/packages/sentinel/packages/model/src/Events/ReportStart.ts diff --git a/packages/modules/packages/sentinel/src/model/Events/index.ts b/packages/modules/packages/sentinel/packages/model/src/Events/index.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Events/index.ts rename to packages/modules/packages/sentinel/packages/model/src/Events/index.ts diff --git a/packages/modules/packages/sentinel/src/model/Instance.ts b/packages/modules/packages/sentinel/packages/model/src/Instance.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Instance.ts rename to packages/modules/packages/sentinel/packages/model/src/Instance.ts diff --git a/packages/modules/packages/sentinel/src/model/Module.ts b/packages/modules/packages/sentinel/packages/model/src/Module.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Module.ts rename to packages/modules/packages/sentinel/packages/model/src/Module.ts diff --git a/packages/modules/packages/sentinel/src/model/Params.ts b/packages/modules/packages/sentinel/packages/model/src/Params.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Params.ts rename to packages/modules/packages/sentinel/packages/model/src/Params.ts diff --git a/packages/modules/packages/sentinel/src/model/Queries/Report.ts b/packages/modules/packages/sentinel/packages/model/src/Queries/Report.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Queries/Report.ts rename to packages/modules/packages/sentinel/packages/model/src/Queries/Report.ts diff --git a/packages/modules/packages/sentinel/src/model/Queries/index.ts b/packages/modules/packages/sentinel/packages/model/src/Queries/index.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Queries/index.ts rename to packages/modules/packages/sentinel/packages/model/src/Queries/index.ts diff --git a/packages/modules/packages/sentinel/src/model/Sentinel.ts b/packages/modules/packages/sentinel/packages/model/src/Sentinel.ts similarity index 100% rename from packages/modules/packages/sentinel/src/model/Sentinel.ts rename to packages/modules/packages/sentinel/packages/model/src/Sentinel.ts diff --git a/packages/modules/packages/sentinel/src/model/index.ts b/packages/modules/packages/sentinel/packages/model/src/index.ts similarity index 87% rename from packages/modules/packages/sentinel/src/model/index.ts rename to packages/modules/packages/sentinel/packages/model/src/index.ts index 7218d77b284..3706234d568 100644 --- a/packages/modules/packages/sentinel/src/model/index.ts +++ b/packages/modules/packages/sentinel/packages/model/src/index.ts @@ -6,3 +6,4 @@ export * from './Module' export * from './Params' export * from './Queries' export * from './Sentinel' +export * from './typeChecks' diff --git a/packages/modules/packages/sentinel/src/typeChecks.ts b/packages/modules/packages/sentinel/packages/model/src/typeChecks.ts similarity index 83% rename from packages/modules/packages/sentinel/src/typeChecks.ts rename to packages/modules/packages/sentinel/packages/model/src/typeChecks.ts index 3ef17f67192..b2b22f18086 100644 --- a/packages/modules/packages/sentinel/src/typeChecks.ts +++ b/packages/modules/packages/sentinel/packages/model/src/typeChecks.ts @@ -1,7 +1,9 @@ import { IsInstanceFactory, IsModuleFactory, isModuleInstance, WithFactory } from '@xyo-network/module-model' import { AsObjectFactory } from '@xyo-network/object-identity' -import { SentinelInstance, SentinelModule, SentinelReportQuerySchema } from './model' +import { SentinelInstance } from './Instance' +import { SentinelModule } from './Module' +import { SentinelReportQuerySchema } from './Queries' export const isSentinelInstance = new IsInstanceFactory().create({ report: 'function' }, [isModuleInstance]) export const isSentinelModule = new IsModuleFactory().create([SentinelReportQuerySchema]) diff --git a/packages/modules/packages/sentinel/packages/model/tsconfig.json b/packages/modules/packages/sentinel/packages/model/tsconfig.json new file mode 100644 index 00000000000..ee61985eb0f --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "declarationDir": "./dist/types", + "typeRoots": [] + }, + "exclude": ["dist", "docs"], + "extends": "@xylabs/tsconfig" +} \ No newline at end of file diff --git a/packages/modules/packages/sentinel/packages/model/tsconfig.typedoc.json b/packages/modules/packages/sentinel/packages/model/tsconfig.typedoc.json new file mode 100644 index 00000000000..8e79a613f42 --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/tsconfig.typedoc.json @@ -0,0 +1,5 @@ +{ + "exclude": ["**/spec/*", "**/*.spec.*", "dist", "docs", "packages"], + "extends": "./tsconfig.json" +} + diff --git a/packages/modules/packages/sentinel/packages/model/typedoc.json b/packages/modules/packages/sentinel/packages/model/typedoc.json new file mode 100644 index 00000000000..8eda4f2661e --- /dev/null +++ b/packages/modules/packages/sentinel/packages/model/typedoc.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "entryPoints": ["src/index.ts"], + "tsconfig": "./tsconfig.typedoc.json" +} \ No newline at end of file diff --git a/packages/modules/packages/sentinel/src/AbstractSentinel.ts b/packages/modules/packages/sentinel/src/AbstractSentinel.ts index e51101e3b9b..5158338b87e 100644 --- a/packages/modules/packages/sentinel/src/AbstractSentinel.ts +++ b/packages/modules/packages/sentinel/src/AbstractSentinel.ts @@ -4,9 +4,6 @@ import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundw import { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model' import { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' -import { isWitnessInstance, WitnessInstance } from '@xyo-network/witness' -import uniq from 'lodash/uniq' - import { CustomSentinelInstance, SentinelConfigSchema, @@ -15,7 +12,9 @@ import { SentinelParams, SentinelQueryBase, SentinelReportQuerySchema, -} from './model' +} from '@xyo-network/sentinel-model' +import { isWitnessInstance, WitnessInstance } from '@xyo-network/witness' +import uniq from 'lodash/uniq' export abstract class AbstractSentinel< TParams extends SentinelParams = SentinelParams, diff --git a/packages/modules/packages/sentinel/src/MemorySentinel.ts b/packages/modules/packages/sentinel/src/MemorySentinel.ts index e56e7a5a875..f442bc88ef4 100644 --- a/packages/modules/packages/sentinel/src/MemorySentinel.ts +++ b/packages/modules/packages/sentinel/src/MemorySentinel.ts @@ -3,10 +3,17 @@ import { fulfilled, rejected } from '@xylabs/promise' import { handleError } from '@xyo-network/error' import { AnyConfigSchema } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' +import { + SentinelConfig, + SentinelConfigSchema, + SentinelInstance, + SentinelModuleEventData, + SentinelParams, + SentinelReportQuerySchema, +} from '@xyo-network/sentinel-model' import { WitnessInstance } from '@xyo-network/witness' import { AbstractSentinel } from './AbstractSentinel' -import { SentinelConfig, SentinelConfigSchema, SentinelInstance, SentinelModuleEventData, SentinelParams, SentinelReportQuerySchema } from './model' export type MemorySentinelParams = AnyConfigSchema> = SentinelParams< AnyConfigSchema diff --git a/packages/modules/packages/sentinel/src/SentinelRunner.ts b/packages/modules/packages/sentinel/src/SentinelRunner.ts index 9c0cde1ad77..3c5d95df540 100644 --- a/packages/modules/packages/sentinel/src/SentinelRunner.ts +++ b/packages/modules/packages/sentinel/src/SentinelRunner.ts @@ -1,9 +1,9 @@ import { assertEx } from '@xylabs/assert' import { Payload } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' +import { SentinelInstance } from '@xyo-network/sentinel-model' import { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation' -import { SentinelInstance } from './model' import { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper' export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void diff --git a/packages/modules/packages/sentinel/src/Wrapper.ts b/packages/modules/packages/sentinel/src/Wrapper.ts index bd806de57b8..45a7110e076 100644 --- a/packages/modules/packages/sentinel/src/Wrapper.ts +++ b/packages/modules/packages/sentinel/src/Wrapper.ts @@ -1,8 +1,13 @@ import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' - -import { SentinelInstance, SentinelModule, SentinelReportQuery, SentinelReportQuerySchema } from './model' -import { isSentinelInstance, isSentinelModule } from './typeChecks' +import { + isSentinelInstance, + isSentinelModule, + SentinelInstance, + SentinelModule, + SentinelReportQuery, + SentinelReportQuerySchema, +} from '@xyo-network/sentinel-model' constructableModuleWrapper() export class SentinelWrapper diff --git a/packages/modules/packages/sentinel/src/index.ts b/packages/modules/packages/sentinel/src/index.ts index 1d1b366c444..6553744f1c3 100644 --- a/packages/modules/packages/sentinel/src/index.ts +++ b/packages/modules/packages/sentinel/src/index.ts @@ -1,8 +1,7 @@ export * from './AbstractSentinel' export * from './Automation' export * from './MemorySentinel' -export * from './model' export * from './SentinelIntervalAutomationWrapper' export * from './SentinelRunner' -export * from './typeChecks' export * from './Wrapper' +export * from '@xyo-network/sentinel-model' diff --git a/packages/modules/packages/sentinel/src/spec/Sentinel.spec.ts b/packages/modules/packages/sentinel/src/spec/Sentinel.spec.ts index fd2fb1a0f09..1de41c7aff6 100644 --- a/packages/modules/packages/sentinel/src/spec/Sentinel.spec.ts +++ b/packages/modules/packages/sentinel/src/spec/Sentinel.spec.ts @@ -12,11 +12,11 @@ import { MemoryNode } from '@xyo-network/node' import { NodeSystemInfoWitness, NodeSystemInfoWitnessConfigSchema } from '@xyo-network/node-system-info-plugin' import { Payload, PayloadSchema } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' +import { ReportEndEventArgs, SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel-model' import { AbstractWitness } from '@xyo-network/witness' import { AdhocWitness, AdhocWitnessConfigSchema } from '@xyo-network/witnesses' import { MemorySentinel, MemorySentinelParams } from '../MemorySentinel' -import { ReportEndEventArgs, SentinelConfig, SentinelConfigSchema } from '../model' describe('Sentinel', () => { test('all [simple panel send]', async () => { diff --git a/packages/modules/packages/sentinel/src/spec/SentinelRunner.spec.ts b/packages/modules/packages/sentinel/src/spec/SentinelRunner.spec.ts index f0b2af985b8..f37944eb437 100644 --- a/packages/modules/packages/sentinel/src/spec/SentinelRunner.spec.ts +++ b/packages/modules/packages/sentinel/src/spec/SentinelRunner.spec.ts @@ -3,11 +3,11 @@ import { BoundWitnessSchema } from '@xyo-network/boundwitness-model' import { IdSchema } from '@xyo-network/id-payload-plugin' import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin' import { MemoryNode } from '@xyo-network/node' +import { SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel-model' import { AbstractWitness } from '@xyo-network/witness' import { SentinelAutomationSchema, SentinelIntervalAutomationPayload } from '../Automation' import { MemorySentinel } from '../MemorySentinel' -import { SentinelConfig, SentinelConfigSchema } from '../model' import { OnSentinelRunnerTriggerResult, SentinelRunner } from '../SentinelRunner' describe('SentinelRunner', () => { diff --git a/yarn.lock b/yarn.lock index 18b3283202c..cb4eba1fad2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9002,6 +9002,32 @@ __metadata: languageName: unknown linkType: soft +"@xyo-network/sentinel-model@workspace:packages/modules/packages/sentinel/packages/model, @xyo-network/sentinel-model@workspace:~": + version: 0.0.0-use.local + resolution: "@xyo-network/sentinel-model@workspace:packages/modules/packages/sentinel/packages/model" + dependencies: + "@types/lodash": ^4.14.196 + "@xylabs/assert": ^2.9.3 + "@xylabs/promise": ^2.9.3 + "@xylabs/ts-scripts-yarn3": ^2.19.0 + "@xylabs/tsconfig": ^2.19.0 + "@xyo-network/archivist": "workspace:~" + "@xyo-network/boundwitness-builder": "workspace:~" + "@xyo-network/boundwitness-model": "workspace:~" + "@xyo-network/core": "workspace:~" + "@xyo-network/error": "workspace:~" + "@xyo-network/module": "workspace:~" + "@xyo-network/module-model": "workspace:~" + "@xyo-network/object-identity": "workspace:~" + "@xyo-network/payload-model": "workspace:~" + "@xyo-network/payload-wrapper": "workspace:~" + "@xyo-network/promise": "workspace:~" + "@xyo-network/witness": "workspace:~" + lodash: ^4.17.21 + typescript: ^5.1.6 + languageName: unknown + linkType: soft + "@xyo-network/sentinel@workspace:packages/modules/packages/sentinel, @xyo-network/sentinel@workspace:~": version: 0.0.0-use.local resolution: "@xyo-network/sentinel@workspace:packages/modules/packages/sentinel" @@ -9022,6 +9048,7 @@ __metadata: "@xyo-network/payload-model": "workspace:~" "@xyo-network/payload-wrapper": "workspace:~" "@xyo-network/promise": "workspace:~" + "@xyo-network/sentinel-model": "workspace:~" "@xyo-network/witness": "workspace:~" lodash: ^4.17.21 typescript: ^5.1.6