From 0d380fae9f18659865c53243e048b92659349ad7 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 07:45:20 -0500 Subject: [PATCH 01/11] Modularize Witness --- .../witness/packages/abstract/.npmignore | 21 +++ .../witness/packages/abstract/LICENSE | 165 ++++++++++++++++++ .../witness/packages/abstract/README.md | 13 ++ .../witness/packages/abstract/package.json | 61 +++++++ .../packages/abstract/src/AbstractWitness.ts | 90 ++++++++++ .../witness/packages/abstract/src/Config.ts | 16 ++ .../packages/abstract/src/Queries/Observe.ts | 9 + .../packages/abstract/src/Queries/index.ts | 9 + .../packages/abstract/src/TimestampWitness.ts | 15 ++ .../witness/packages/abstract/src/Witness.ts | 47 +++++ .../packages/abstract/src/WitnessWrapper.ts | 16 ++ .../witness/packages/abstract/src/index.ts | 6 + .../abstract/src/spec/AbstractWitness.spec.ts | 61 +++++++ .../packages/abstract/src/spec/tsconfig.json | 3 + .../witness/packages/abstract/tsconfig.json | 11 ++ .../packages/abstract/tsconfig.typedoc.json | 5 + .../witness/packages/abstract/typedoc.json | 5 + .../witness/packages/model/.npmignore | 21 +++ .../packages/witness/packages/model/LICENSE | 165 ++++++++++++++++++ .../packages/witness/packages/model/README.md | 13 ++ .../witness/packages/model/package.json | 61 +++++++ .../packages/model/src/AbstractWitness.ts | 90 ++++++++++ .../witness/packages/model/src/Config.ts | 16 ++ .../packages/model/src/Queries/Observe.ts | 9 + .../packages/model/src/Queries/index.ts | 9 + .../packages/model/src/TimestampWitness.ts | 15 ++ .../witness/packages/model/src/Witness.ts | 47 +++++ .../packages/model/src/WitnessWrapper.ts | 16 ++ .../witness/packages/model/src/index.ts | 6 + .../model/src/spec/AbstractWitness.spec.ts | 61 +++++++ .../packages/model/src/spec/tsconfig.json | 3 + .../witness/packages/model/tsconfig.json | 11 ++ .../packages/model/tsconfig.typedoc.json | 5 + .../witness/packages/model/typedoc.json | 5 + .../witness/packages/timestamp/.npmignore | 21 +++ .../witness/packages/timestamp/LICENSE | 165 ++++++++++++++++++ .../witness/packages/timestamp/README.md | 13 ++ .../witness/packages/timestamp/package.json | 61 +++++++ .../packages/timestamp/src/AbstractWitness.ts | 90 ++++++++++ .../witness/packages/timestamp/src/Config.ts | 16 ++ .../packages/timestamp/src/Queries/Observe.ts | 9 + .../packages/timestamp/src/Queries/index.ts | 9 + .../timestamp/src/TimestampWitness.ts | 15 ++ .../witness/packages/timestamp/src/Witness.ts | 47 +++++ .../packages/timestamp/src/WitnessWrapper.ts | 16 ++ .../witness/packages/timestamp/src/index.ts | 6 + .../src/spec/AbstractWitness.spec.ts | 61 +++++++ .../packages/timestamp/src/spec/tsconfig.json | 3 + .../witness/packages/timestamp/tsconfig.json | 11 ++ .../packages/timestamp/tsconfig.typedoc.json | 5 + .../witness/packages/timestamp/typedoc.json | 5 + .../witness/packages/wrapper/.npmignore | 21 +++ .../packages/witness/packages/wrapper/LICENSE | 165 ++++++++++++++++++ .../witness/packages/wrapper/README.md | 13 ++ .../witness/packages/wrapper/package.json | 61 +++++++ .../packages/wrapper/src/AbstractWitness.ts | 90 ++++++++++ .../witness/packages/wrapper/src/Config.ts | 16 ++ .../packages/wrapper/src/Queries/Observe.ts | 9 + .../packages/wrapper/src/Queries/index.ts | 9 + .../packages/wrapper/src/TimestampWitness.ts | 15 ++ .../witness/packages/wrapper/src/Witness.ts | 47 +++++ .../packages/wrapper/src/WitnessWrapper.ts | 16 ++ .../witness/packages/wrapper/src/index.ts | 6 + .../wrapper/src/spec/AbstractWitness.spec.ts | 61 +++++++ .../packages/wrapper/src/spec/tsconfig.json | 3 + .../witness/packages/wrapper/tsconfig.json | 11 ++ .../packages/wrapper/tsconfig.typedoc.json | 5 + .../witness/packages/wrapper/typedoc.json | 5 + 68 files changed, 2212 insertions(+) create mode 100644 packages/modules/packages/witness/packages/abstract/.npmignore create mode 100644 packages/modules/packages/witness/packages/abstract/LICENSE create mode 100644 packages/modules/packages/witness/packages/abstract/README.md create mode 100644 packages/modules/packages/witness/packages/abstract/package.json create mode 100644 packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/Config.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/Queries/index.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/Witness.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/index.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/spec/AbstractWitness.spec.ts create mode 100644 packages/modules/packages/witness/packages/abstract/src/spec/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/abstract/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/abstract/tsconfig.typedoc.json create mode 100644 packages/modules/packages/witness/packages/abstract/typedoc.json create mode 100644 packages/modules/packages/witness/packages/model/.npmignore create mode 100644 packages/modules/packages/witness/packages/model/LICENSE create mode 100644 packages/modules/packages/witness/packages/model/README.md create mode 100644 packages/modules/packages/witness/packages/model/package.json create mode 100644 packages/modules/packages/witness/packages/model/src/AbstractWitness.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Config.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Queries/Observe.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Queries/index.ts create mode 100644 packages/modules/packages/witness/packages/model/src/TimestampWitness.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Witness.ts create mode 100644 packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts create mode 100644 packages/modules/packages/witness/packages/model/src/index.ts create mode 100644 packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts create mode 100644 packages/modules/packages/witness/packages/model/src/spec/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/model/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/model/tsconfig.typedoc.json create mode 100644 packages/modules/packages/witness/packages/model/typedoc.json create mode 100644 packages/modules/packages/witness/packages/timestamp/.npmignore create mode 100644 packages/modules/packages/witness/packages/timestamp/LICENSE create mode 100644 packages/modules/packages/witness/packages/timestamp/README.md create mode 100644 packages/modules/packages/witness/packages/timestamp/package.json create mode 100644 packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/Config.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/Witness.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/index.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts create mode 100644 packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/timestamp/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/timestamp/tsconfig.typedoc.json create mode 100644 packages/modules/packages/witness/packages/timestamp/typedoc.json create mode 100644 packages/modules/packages/witness/packages/wrapper/.npmignore create mode 100644 packages/modules/packages/witness/packages/wrapper/LICENSE create mode 100644 packages/modules/packages/witness/packages/wrapper/README.md create mode 100644 packages/modules/packages/witness/packages/wrapper/package.json create mode 100644 packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/Config.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/Witness.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/index.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts create mode 100644 packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/wrapper/tsconfig.json create mode 100644 packages/modules/packages/witness/packages/wrapper/tsconfig.typedoc.json create mode 100644 packages/modules/packages/witness/packages/wrapper/typedoc.json diff --git a/packages/modules/packages/witness/packages/abstract/.npmignore b/packages/modules/packages/witness/packages/abstract/.npmignore new file mode 100644 index 00000000000..0430e8967b1 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/.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/witness/packages/abstract/LICENSE b/packages/modules/packages/witness/packages/abstract/LICENSE new file mode 100644 index 00000000000..0a041280bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/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/witness/packages/abstract/README.md b/packages/modules/packages/witness/packages/abstract/README.md new file mode 100644 index 00000000000..cd0084ca798 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/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/witness/packages/abstract/package.json b/packages/modules/packages/witness/packages/abstract/package.json new file mode 100644 index 00000000000..771334a893a --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/package.json @@ -0,0 +1,61 @@ +{ + "name": "@xyo-network/abstract-witness", + "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", + "@xyo-network/account": "workspace:^", + "@xyo-network/core": "workspace:^", + "@xyo-network/module": "workspace:^", + "@xyo-network/module-model": "workspace:^", + "@xyo-network/payload-model": "workspace:^", + "@xyo-network/payload-wrapper": "workspace:^", + "@xyo-network/promise": "workspace:^" + }, + "devDependencies": { + "@xylabs/ts-scripts-yarn3": "^2.17.17", + "@xylabs/tsconfig": "^2.17.17", + "typescript": "^5.1.3" + }, + "description": "Primary SDK for using XYO Protocol 2.0", + "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.63.12" +} diff --git a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts new file mode 100644 index 00000000000..a10f40cb39b --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts @@ -0,0 +1,90 @@ +import { assertEx } from '@xylabs/assert' +import { Account } from '@xyo-network/account' +import { PayloadHasher } from '@xyo-network/core' +import { + AbstractModule, + creatableModule, + ModuleConfig, + ModuleErrorBuilder, + ModuleQueryResult, + QueryBoundWitness, + QueryBoundWitnessWrapper, +} from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfigSchema } from './Config' +import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' +import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' + +creatableModule() +export class AbstractWitness + extends AbstractModule + implements WitnessModule +{ + static override configSchema: string = WitnessConfigSchema + + override get queries(): string[] { + return [WitnessObserveQuerySchema, ...super.queries] + } + + get targetSet() { + return this.config?.targetSet + } + + protected override get _queryAccountPaths(): Record { + return { + 'network.xyo.query.witness.observe': '1/1', + } + } + + observe(payloads?: Payload[]): Promisable { + this.started('throw') + const payloadList = assertEx(payloads, 'Trying to witness nothing') + assertEx(payloadList.length > 0, 'Trying to witness empty list') + payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) + return payloadList + } + + protected override async queryHandler( + query: T, + payloads?: Payload[], + queryConfig?: TConfig, + ): Promise { + const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) + const queryPayload = await wrapper.getQuery() + assertEx(this.queryable(query, payloads, queryConfig)) + // Remove the query payload from the arguments passed to us so we don't observe it + const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) + const queryAccount = Account.random() + try { + switch (queryPayload.schema) { + case WitnessObserveQuerySchema: { + await this.emit('reportStart', { inPayloads: payloads, module: this }) + const resultPayloads = await this.observe(filteredObservation) + await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) + return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] + } + default: { + return super.queryHandler(query, payloads) + } + } + } catch (ex) { + const error = ex as Error + const [result] = await this.bindQueryResult( + queryPayload, + [], + [queryAccount], + [ + new ModuleErrorBuilder() + .sources([await wrapper.hashAsync()]) + .name(this.config.name ?? '') + .query(query.schema) + .message(error.message) + .build(), + ], + ) + return result + } + } +} diff --git a/packages/modules/packages/witness/packages/abstract/src/Config.ts b/packages/modules/packages/witness/packages/abstract/src/Config.ts new file mode 100644 index 00000000000..6ddc09184bd --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/Config.ts @@ -0,0 +1,16 @@ +import { WithAdditional } from '@xyo-network/core' +import { ModuleConfig } from '@xyo-network/module' +import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' + +export type WitnessConfigSchema = 'network.xyo.witness.config' +export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' + +export type WitnessConfig = ModuleConfig< + WithAdditional< + { + schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema + targetSet?: PayloadSetPayload + }, + TConfig + > +> diff --git a/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts new file mode 100644 index 00000000000..5d5cf3f152d --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts @@ -0,0 +1,9 @@ +import { Query } from '@xyo-network/module-model' + +export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' +export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' + +export type WitnessObserveQuery = Query<{ + payloads?: string[] + schema: WitnessObserveQuerySchema +}> diff --git a/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts b/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts new file mode 100644 index 00000000000..576d9567561 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts @@ -0,0 +1,9 @@ +import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' + +import { WitnessObserveQuery } from './Observe' + +export * from './Observe' + +export type WitnessQueryBase = WitnessObserveQuery +export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase +export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts new file mode 100644 index 00000000000..a8742621596 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts @@ -0,0 +1,15 @@ +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { AbstractWitness } from './AbstractWitness' +import { WitnessParams } from './Witness' + +export abstract class TimestampWitness

extends AbstractWitness

{ + override observe(fields?: Payload[] | undefined): Promisable { + return super.observe( + fields?.map((fieldItem) => { + return { ...fieldItem, timestamp: Date.now() } + }), + ) + } +} diff --git a/packages/modules/packages/witness/packages/abstract/src/Witness.ts b/packages/modules/packages/witness/packages/abstract/src/Witness.ts new file mode 100644 index 00000000000..c0e02597bf6 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/Witness.ts @@ -0,0 +1,47 @@ +import { AnyObject } from '@xyo-network/core' +import { EventData } from '@xyo-network/module' +import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfig } from './Config' + +export interface Witness { + observe: (payloads?: Payload[]) => Promisable +} + +export type WitnessReportEndEventArgs = ModuleEventArgs< + WitnessModule, + { + errors?: Error[] + inPayloads?: Payload[] + outPayloads?: Payload[] + } +> + +export interface WitnessReportEndEventData extends EventData { + reportEnd: WitnessReportEndEventArgs +} + +export type WitnessReportStartEventArgs = ModuleEventArgs< + WitnessModule, + { + inPayloads?: Payload[] + } +> + +export interface WitnessReportStartEventData extends EventData { + reportStart: WitnessReportStartEventArgs +} + +export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} + +export type WitnessParams< + TConfig extends AnyConfigSchema = AnyConfigSchema, + TAdditionalParams extends AnyObject | undefined = undefined, +> = ModuleParams + +export type WitnessModule< + TParams extends WitnessParams = WitnessParams, + TEventData extends WitnessModuleEventData = WitnessModuleEventData, +> = Witness & Module diff --git a/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts new file mode 100644 index 00000000000..46efba3a773 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts @@ -0,0 +1,16 @@ +import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { PayloadWrapper } from '@xyo-network/payload-wrapper' + +import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' +import { Witness } from './Witness' + +constructableModuleWrapper() +export class WitnessWrapper extends ModuleWrapper implements Witness { + static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] + + observe(payloads?: Payload[]): Promise { + const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) + return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) + } +} diff --git a/packages/modules/packages/witness/packages/abstract/src/index.ts b/packages/modules/packages/witness/packages/abstract/src/index.ts new file mode 100644 index 00000000000..8a2cfcb34a2 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/index.ts @@ -0,0 +1,6 @@ +export * from './AbstractWitness' +export * from './Config' +export * from './Queries' +export * from './TimestampWitness' +export * from './Witness' +export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/abstract/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/abstract/src/spec/AbstractWitness.spec.ts new file mode 100644 index 00000000000..ba072f2ceba --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/spec/AbstractWitness.spec.ts @@ -0,0 +1,61 @@ +import { Account } from '@xyo-network/account' +import { AccountInstance } from '@xyo-network/account-model' +import { Module, ModuleParams } from '@xyo-network/module' +import { PayloadBuilder } from '@xyo-network/payload-builder' + +import { AbstractWitness } from '../AbstractWitness' +import { WitnessConfig, WitnessConfigSchema } from '../Config' +import { WitnessModule } from '../Witness' +import { WitnessWrapper } from '../WitnessWrapper' + +describe('Witness', () => { + const config: WitnessConfig = { schema: WitnessConfigSchema } + const params: ModuleParams = { config } + const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() + + describe('fulfills type of', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('Module', async () => { + const witness: Module = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('AbstractModule', async () => { + const witness = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('WitnessModule', async () => { + const witness: WitnessModule = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + }) + describe('observe', () => { + describe('with payload supplied to observe', () => { + describe('returns payloads', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('when module queried directly', async () => { + const witness = await AbstractWitness.create(params) + const observation = await witness.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + it('when module queried with WitnessWrapper', async () => { + const witness = await AbstractWitness.create(params) + const wrapper = new WitnessWrapper({ account, module: witness }) + const observation = await wrapper.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + }) + }) + }) +}) diff --git a/packages/modules/packages/witness/packages/abstract/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/abstract/src/spec/tsconfig.json new file mode 100644 index 00000000000..16980bd0bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/src/spec/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/abstract/tsconfig.json b/packages/modules/packages/witness/packages/abstract/tsconfig.json new file mode 100644 index 00000000000..d55197bca10 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "declarationDir": "./dist/types", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "typeRoots": [] + }, + + "extends": "@xylabs/tsconfig" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/abstract/tsconfig.typedoc.json b/packages/modules/packages/witness/packages/abstract/tsconfig.typedoc.json new file mode 100644 index 00000000000..a77abc2f4f0 --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/tsconfig.typedoc.json @@ -0,0 +1,5 @@ +{ + "exclude": ["**/spec/*", "**/*.spec.*"], + "extends": "./tsconfig.json" +} + diff --git a/packages/modules/packages/witness/packages/abstract/typedoc.json b/packages/modules/packages/witness/packages/abstract/typedoc.json new file mode 100644 index 00000000000..8eda4f2661e --- /dev/null +++ b/packages/modules/packages/witness/packages/abstract/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/witness/packages/model/.npmignore b/packages/modules/packages/witness/packages/model/.npmignore new file mode 100644 index 00000000000..0430e8967b1 --- /dev/null +++ b/packages/modules/packages/witness/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/witness/packages/model/LICENSE b/packages/modules/packages/witness/packages/model/LICENSE new file mode 100644 index 00000000000..0a041280bd0 --- /dev/null +++ b/packages/modules/packages/witness/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/witness/packages/model/README.md b/packages/modules/packages/witness/packages/model/README.md new file mode 100644 index 00000000000..cd0084ca798 --- /dev/null +++ b/packages/modules/packages/witness/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/witness/packages/model/package.json b/packages/modules/packages/witness/packages/model/package.json new file mode 100644 index 00000000000..f0a50da9415 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/package.json @@ -0,0 +1,61 @@ +{ + "name": "@xyo-network/witness-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", + "@xyo-network/account": "workspace:^", + "@xyo-network/core": "workspace:^", + "@xyo-network/module": "workspace:^", + "@xyo-network/module-model": "workspace:^", + "@xyo-network/payload-model": "workspace:^", + "@xyo-network/payload-wrapper": "workspace:^", + "@xyo-network/promise": "workspace:^" + }, + "devDependencies": { + "@xylabs/ts-scripts-yarn3": "^2.17.17", + "@xylabs/tsconfig": "^2.17.17", + "typescript": "^5.1.3" + }, + "description": "Primary SDK for using XYO Protocol 2.0", + "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.63.12" +} diff --git a/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts new file mode 100644 index 00000000000..a10f40cb39b --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts @@ -0,0 +1,90 @@ +import { assertEx } from '@xylabs/assert' +import { Account } from '@xyo-network/account' +import { PayloadHasher } from '@xyo-network/core' +import { + AbstractModule, + creatableModule, + ModuleConfig, + ModuleErrorBuilder, + ModuleQueryResult, + QueryBoundWitness, + QueryBoundWitnessWrapper, +} from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfigSchema } from './Config' +import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' +import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' + +creatableModule() +export class AbstractWitness + extends AbstractModule + implements WitnessModule +{ + static override configSchema: string = WitnessConfigSchema + + override get queries(): string[] { + return [WitnessObserveQuerySchema, ...super.queries] + } + + get targetSet() { + return this.config?.targetSet + } + + protected override get _queryAccountPaths(): Record { + return { + 'network.xyo.query.witness.observe': '1/1', + } + } + + observe(payloads?: Payload[]): Promisable { + this.started('throw') + const payloadList = assertEx(payloads, 'Trying to witness nothing') + assertEx(payloadList.length > 0, 'Trying to witness empty list') + payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) + return payloadList + } + + protected override async queryHandler( + query: T, + payloads?: Payload[], + queryConfig?: TConfig, + ): Promise { + const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) + const queryPayload = await wrapper.getQuery() + assertEx(this.queryable(query, payloads, queryConfig)) + // Remove the query payload from the arguments passed to us so we don't observe it + const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) + const queryAccount = Account.random() + try { + switch (queryPayload.schema) { + case WitnessObserveQuerySchema: { + await this.emit('reportStart', { inPayloads: payloads, module: this }) + const resultPayloads = await this.observe(filteredObservation) + await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) + return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] + } + default: { + return super.queryHandler(query, payloads) + } + } + } catch (ex) { + const error = ex as Error + const [result] = await this.bindQueryResult( + queryPayload, + [], + [queryAccount], + [ + new ModuleErrorBuilder() + .sources([await wrapper.hashAsync()]) + .name(this.config.name ?? '') + .query(query.schema) + .message(error.message) + .build(), + ], + ) + return result + } + } +} diff --git a/packages/modules/packages/witness/packages/model/src/Config.ts b/packages/modules/packages/witness/packages/model/src/Config.ts new file mode 100644 index 00000000000..6ddc09184bd --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Config.ts @@ -0,0 +1,16 @@ +import { WithAdditional } from '@xyo-network/core' +import { ModuleConfig } from '@xyo-network/module' +import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' + +export type WitnessConfigSchema = 'network.xyo.witness.config' +export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' + +export type WitnessConfig = ModuleConfig< + WithAdditional< + { + schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema + targetSet?: PayloadSetPayload + }, + TConfig + > +> diff --git a/packages/modules/packages/witness/packages/model/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/model/src/Queries/Observe.ts new file mode 100644 index 00000000000..5d5cf3f152d --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Queries/Observe.ts @@ -0,0 +1,9 @@ +import { Query } from '@xyo-network/module-model' + +export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' +export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' + +export type WitnessObserveQuery = Query<{ + payloads?: string[] + schema: WitnessObserveQuerySchema +}> diff --git a/packages/modules/packages/witness/packages/model/src/Queries/index.ts b/packages/modules/packages/witness/packages/model/src/Queries/index.ts new file mode 100644 index 00000000000..576d9567561 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Queries/index.ts @@ -0,0 +1,9 @@ +import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' + +import { WitnessObserveQuery } from './Observe' + +export * from './Observe' + +export type WitnessQueryBase = WitnessObserveQuery +export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase +export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts new file mode 100644 index 00000000000..a8742621596 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts @@ -0,0 +1,15 @@ +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { AbstractWitness } from './AbstractWitness' +import { WitnessParams } from './Witness' + +export abstract class TimestampWitness

extends AbstractWitness

{ + override observe(fields?: Payload[] | undefined): Promisable { + return super.observe( + fields?.map((fieldItem) => { + return { ...fieldItem, timestamp: Date.now() } + }), + ) + } +} diff --git a/packages/modules/packages/witness/packages/model/src/Witness.ts b/packages/modules/packages/witness/packages/model/src/Witness.ts new file mode 100644 index 00000000000..c0e02597bf6 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Witness.ts @@ -0,0 +1,47 @@ +import { AnyObject } from '@xyo-network/core' +import { EventData } from '@xyo-network/module' +import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfig } from './Config' + +export interface Witness { + observe: (payloads?: Payload[]) => Promisable +} + +export type WitnessReportEndEventArgs = ModuleEventArgs< + WitnessModule, + { + errors?: Error[] + inPayloads?: Payload[] + outPayloads?: Payload[] + } +> + +export interface WitnessReportEndEventData extends EventData { + reportEnd: WitnessReportEndEventArgs +} + +export type WitnessReportStartEventArgs = ModuleEventArgs< + WitnessModule, + { + inPayloads?: Payload[] + } +> + +export interface WitnessReportStartEventData extends EventData { + reportStart: WitnessReportStartEventArgs +} + +export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} + +export type WitnessParams< + TConfig extends AnyConfigSchema = AnyConfigSchema, + TAdditionalParams extends AnyObject | undefined = undefined, +> = ModuleParams + +export type WitnessModule< + TParams extends WitnessParams = WitnessParams, + TEventData extends WitnessModuleEventData = WitnessModuleEventData, +> = Witness & Module diff --git a/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts new file mode 100644 index 00000000000..46efba3a773 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts @@ -0,0 +1,16 @@ +import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { PayloadWrapper } from '@xyo-network/payload-wrapper' + +import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' +import { Witness } from './Witness' + +constructableModuleWrapper() +export class WitnessWrapper extends ModuleWrapper implements Witness { + static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] + + observe(payloads?: Payload[]): Promise { + const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) + return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) + } +} diff --git a/packages/modules/packages/witness/packages/model/src/index.ts b/packages/modules/packages/witness/packages/model/src/index.ts new file mode 100644 index 00000000000..8a2cfcb34a2 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/index.ts @@ -0,0 +1,6 @@ +export * from './AbstractWitness' +export * from './Config' +export * from './Queries' +export * from './TimestampWitness' +export * from './Witness' +export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts new file mode 100644 index 00000000000..ba072f2ceba --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts @@ -0,0 +1,61 @@ +import { Account } from '@xyo-network/account' +import { AccountInstance } from '@xyo-network/account-model' +import { Module, ModuleParams } from '@xyo-network/module' +import { PayloadBuilder } from '@xyo-network/payload-builder' + +import { AbstractWitness } from '../AbstractWitness' +import { WitnessConfig, WitnessConfigSchema } from '../Config' +import { WitnessModule } from '../Witness' +import { WitnessWrapper } from '../WitnessWrapper' + +describe('Witness', () => { + const config: WitnessConfig = { schema: WitnessConfigSchema } + const params: ModuleParams = { config } + const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() + + describe('fulfills type of', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('Module', async () => { + const witness: Module = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('AbstractModule', async () => { + const witness = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('WitnessModule', async () => { + const witness: WitnessModule = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + }) + describe('observe', () => { + describe('with payload supplied to observe', () => { + describe('returns payloads', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('when module queried directly', async () => { + const witness = await AbstractWitness.create(params) + const observation = await witness.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + it('when module queried with WitnessWrapper', async () => { + const witness = await AbstractWitness.create(params) + const wrapper = new WitnessWrapper({ account, module: witness }) + const observation = await wrapper.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + }) + }) + }) +}) diff --git a/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json new file mode 100644 index 00000000000..16980bd0bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/model/tsconfig.json b/packages/modules/packages/witness/packages/model/tsconfig.json new file mode 100644 index 00000000000..d55197bca10 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "declarationDir": "./dist/types", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "typeRoots": [] + }, + + "extends": "@xylabs/tsconfig" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/model/tsconfig.typedoc.json b/packages/modules/packages/witness/packages/model/tsconfig.typedoc.json new file mode 100644 index 00000000000..a77abc2f4f0 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/tsconfig.typedoc.json @@ -0,0 +1,5 @@ +{ + "exclude": ["**/spec/*", "**/*.spec.*"], + "extends": "./tsconfig.json" +} + diff --git a/packages/modules/packages/witness/packages/model/typedoc.json b/packages/modules/packages/witness/packages/model/typedoc.json new file mode 100644 index 00000000000..8eda4f2661e --- /dev/null +++ b/packages/modules/packages/witness/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/witness/packages/timestamp/.npmignore b/packages/modules/packages/witness/packages/timestamp/.npmignore new file mode 100644 index 00000000000..0430e8967b1 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/.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/witness/packages/timestamp/LICENSE b/packages/modules/packages/witness/packages/timestamp/LICENSE new file mode 100644 index 00000000000..0a041280bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/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/witness/packages/timestamp/README.md b/packages/modules/packages/witness/packages/timestamp/README.md new file mode 100644 index 00000000000..cd0084ca798 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/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/witness/packages/timestamp/package.json b/packages/modules/packages/witness/packages/timestamp/package.json new file mode 100644 index 00000000000..286a701871e --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/package.json @@ -0,0 +1,61 @@ +{ + "name": "@xyo-network/witness-timestamp", + "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", + "@xyo-network/account": "workspace:^", + "@xyo-network/core": "workspace:^", + "@xyo-network/module": "workspace:^", + "@xyo-network/module-model": "workspace:^", + "@xyo-network/payload-model": "workspace:^", + "@xyo-network/payload-wrapper": "workspace:^", + "@xyo-network/promise": "workspace:^" + }, + "devDependencies": { + "@xylabs/ts-scripts-yarn3": "^2.17.17", + "@xylabs/tsconfig": "^2.17.17", + "typescript": "^5.1.3" + }, + "description": "Primary SDK for using XYO Protocol 2.0", + "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.63.12" +} diff --git a/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts new file mode 100644 index 00000000000..a10f40cb39b --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts @@ -0,0 +1,90 @@ +import { assertEx } from '@xylabs/assert' +import { Account } from '@xyo-network/account' +import { PayloadHasher } from '@xyo-network/core' +import { + AbstractModule, + creatableModule, + ModuleConfig, + ModuleErrorBuilder, + ModuleQueryResult, + QueryBoundWitness, + QueryBoundWitnessWrapper, +} from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfigSchema } from './Config' +import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' +import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' + +creatableModule() +export class AbstractWitness + extends AbstractModule + implements WitnessModule +{ + static override configSchema: string = WitnessConfigSchema + + override get queries(): string[] { + return [WitnessObserveQuerySchema, ...super.queries] + } + + get targetSet() { + return this.config?.targetSet + } + + protected override get _queryAccountPaths(): Record { + return { + 'network.xyo.query.witness.observe': '1/1', + } + } + + observe(payloads?: Payload[]): Promisable { + this.started('throw') + const payloadList = assertEx(payloads, 'Trying to witness nothing') + assertEx(payloadList.length > 0, 'Trying to witness empty list') + payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) + return payloadList + } + + protected override async queryHandler( + query: T, + payloads?: Payload[], + queryConfig?: TConfig, + ): Promise { + const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) + const queryPayload = await wrapper.getQuery() + assertEx(this.queryable(query, payloads, queryConfig)) + // Remove the query payload from the arguments passed to us so we don't observe it + const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) + const queryAccount = Account.random() + try { + switch (queryPayload.schema) { + case WitnessObserveQuerySchema: { + await this.emit('reportStart', { inPayloads: payloads, module: this }) + const resultPayloads = await this.observe(filteredObservation) + await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) + return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] + } + default: { + return super.queryHandler(query, payloads) + } + } + } catch (ex) { + const error = ex as Error + const [result] = await this.bindQueryResult( + queryPayload, + [], + [queryAccount], + [ + new ModuleErrorBuilder() + .sources([await wrapper.hashAsync()]) + .name(this.config.name ?? '') + .query(query.schema) + .message(error.message) + .build(), + ], + ) + return result + } + } +} diff --git a/packages/modules/packages/witness/packages/timestamp/src/Config.ts b/packages/modules/packages/witness/packages/timestamp/src/Config.ts new file mode 100644 index 00000000000..6ddc09184bd --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/Config.ts @@ -0,0 +1,16 @@ +import { WithAdditional } from '@xyo-network/core' +import { ModuleConfig } from '@xyo-network/module' +import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' + +export type WitnessConfigSchema = 'network.xyo.witness.config' +export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' + +export type WitnessConfig = ModuleConfig< + WithAdditional< + { + schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema + targetSet?: PayloadSetPayload + }, + TConfig + > +> diff --git a/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts new file mode 100644 index 00000000000..5d5cf3f152d --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts @@ -0,0 +1,9 @@ +import { Query } from '@xyo-network/module-model' + +export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' +export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' + +export type WitnessObserveQuery = Query<{ + payloads?: string[] + schema: WitnessObserveQuerySchema +}> diff --git a/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts b/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts new file mode 100644 index 00000000000..576d9567561 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts @@ -0,0 +1,9 @@ +import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' + +import { WitnessObserveQuery } from './Observe' + +export * from './Observe' + +export type WitnessQueryBase = WitnessObserveQuery +export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase +export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts new file mode 100644 index 00000000000..a8742621596 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts @@ -0,0 +1,15 @@ +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { AbstractWitness } from './AbstractWitness' +import { WitnessParams } from './Witness' + +export abstract class TimestampWitness

extends AbstractWitness

{ + override observe(fields?: Payload[] | undefined): Promisable { + return super.observe( + fields?.map((fieldItem) => { + return { ...fieldItem, timestamp: Date.now() } + }), + ) + } +} diff --git a/packages/modules/packages/witness/packages/timestamp/src/Witness.ts b/packages/modules/packages/witness/packages/timestamp/src/Witness.ts new file mode 100644 index 00000000000..c0e02597bf6 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/Witness.ts @@ -0,0 +1,47 @@ +import { AnyObject } from '@xyo-network/core' +import { EventData } from '@xyo-network/module' +import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfig } from './Config' + +export interface Witness { + observe: (payloads?: Payload[]) => Promisable +} + +export type WitnessReportEndEventArgs = ModuleEventArgs< + WitnessModule, + { + errors?: Error[] + inPayloads?: Payload[] + outPayloads?: Payload[] + } +> + +export interface WitnessReportEndEventData extends EventData { + reportEnd: WitnessReportEndEventArgs +} + +export type WitnessReportStartEventArgs = ModuleEventArgs< + WitnessModule, + { + inPayloads?: Payload[] + } +> + +export interface WitnessReportStartEventData extends EventData { + reportStart: WitnessReportStartEventArgs +} + +export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} + +export type WitnessParams< + TConfig extends AnyConfigSchema = AnyConfigSchema, + TAdditionalParams extends AnyObject | undefined = undefined, +> = ModuleParams + +export type WitnessModule< + TParams extends WitnessParams = WitnessParams, + TEventData extends WitnessModuleEventData = WitnessModuleEventData, +> = Witness & Module diff --git a/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts new file mode 100644 index 00000000000..46efba3a773 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts @@ -0,0 +1,16 @@ +import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { PayloadWrapper } from '@xyo-network/payload-wrapper' + +import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' +import { Witness } from './Witness' + +constructableModuleWrapper() +export class WitnessWrapper extends ModuleWrapper implements Witness { + static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] + + observe(payloads?: Payload[]): Promise { + const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) + return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) + } +} diff --git a/packages/modules/packages/witness/packages/timestamp/src/index.ts b/packages/modules/packages/witness/packages/timestamp/src/index.ts new file mode 100644 index 00000000000..8a2cfcb34a2 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/index.ts @@ -0,0 +1,6 @@ +export * from './AbstractWitness' +export * from './Config' +export * from './Queries' +export * from './TimestampWitness' +export * from './Witness' +export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts new file mode 100644 index 00000000000..ba072f2ceba --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts @@ -0,0 +1,61 @@ +import { Account } from '@xyo-network/account' +import { AccountInstance } from '@xyo-network/account-model' +import { Module, ModuleParams } from '@xyo-network/module' +import { PayloadBuilder } from '@xyo-network/payload-builder' + +import { AbstractWitness } from '../AbstractWitness' +import { WitnessConfig, WitnessConfigSchema } from '../Config' +import { WitnessModule } from '../Witness' +import { WitnessWrapper } from '../WitnessWrapper' + +describe('Witness', () => { + const config: WitnessConfig = { schema: WitnessConfigSchema } + const params: ModuleParams = { config } + const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() + + describe('fulfills type of', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('Module', async () => { + const witness: Module = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('AbstractModule', async () => { + const witness = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('WitnessModule', async () => { + const witness: WitnessModule = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + }) + describe('observe', () => { + describe('with payload supplied to observe', () => { + describe('returns payloads', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('when module queried directly', async () => { + const witness = await AbstractWitness.create(params) + const observation = await witness.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + it('when module queried with WitnessWrapper', async () => { + const witness = await AbstractWitness.create(params) + const wrapper = new WitnessWrapper({ account, module: witness }) + const observation = await wrapper.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + }) + }) + }) +}) diff --git a/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json new file mode 100644 index 00000000000..16980bd0bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/timestamp/tsconfig.json b/packages/modules/packages/witness/packages/timestamp/tsconfig.json new file mode 100644 index 00000000000..d55197bca10 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "declarationDir": "./dist/types", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "typeRoots": [] + }, + + "extends": "@xylabs/tsconfig" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/timestamp/tsconfig.typedoc.json b/packages/modules/packages/witness/packages/timestamp/tsconfig.typedoc.json new file mode 100644 index 00000000000..a77abc2f4f0 --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/tsconfig.typedoc.json @@ -0,0 +1,5 @@ +{ + "exclude": ["**/spec/*", "**/*.spec.*"], + "extends": "./tsconfig.json" +} + diff --git a/packages/modules/packages/witness/packages/timestamp/typedoc.json b/packages/modules/packages/witness/packages/timestamp/typedoc.json new file mode 100644 index 00000000000..8eda4f2661e --- /dev/null +++ b/packages/modules/packages/witness/packages/timestamp/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/witness/packages/wrapper/.npmignore b/packages/modules/packages/witness/packages/wrapper/.npmignore new file mode 100644 index 00000000000..0430e8967b1 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/.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/witness/packages/wrapper/LICENSE b/packages/modules/packages/witness/packages/wrapper/LICENSE new file mode 100644 index 00000000000..0a041280bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/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/witness/packages/wrapper/README.md b/packages/modules/packages/witness/packages/wrapper/README.md new file mode 100644 index 00000000000..cd0084ca798 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/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/witness/packages/wrapper/package.json b/packages/modules/packages/witness/packages/wrapper/package.json new file mode 100644 index 00000000000..952451d1ac4 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/package.json @@ -0,0 +1,61 @@ +{ + "name": "@xyo-network/witness-wrapper", + "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", + "@xyo-network/account": "workspace:^", + "@xyo-network/core": "workspace:^", + "@xyo-network/module": "workspace:^", + "@xyo-network/module-model": "workspace:^", + "@xyo-network/payload-model": "workspace:^", + "@xyo-network/payload-wrapper": "workspace:^", + "@xyo-network/promise": "workspace:^" + }, + "devDependencies": { + "@xylabs/ts-scripts-yarn3": "^2.17.17", + "@xylabs/tsconfig": "^2.17.17", + "typescript": "^5.1.3" + }, + "description": "Primary SDK for using XYO Protocol 2.0", + "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.63.12" +} diff --git a/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts new file mode 100644 index 00000000000..a10f40cb39b --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts @@ -0,0 +1,90 @@ +import { assertEx } from '@xylabs/assert' +import { Account } from '@xyo-network/account' +import { PayloadHasher } from '@xyo-network/core' +import { + AbstractModule, + creatableModule, + ModuleConfig, + ModuleErrorBuilder, + ModuleQueryResult, + QueryBoundWitness, + QueryBoundWitnessWrapper, +} from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfigSchema } from './Config' +import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' +import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' + +creatableModule() +export class AbstractWitness + extends AbstractModule + implements WitnessModule +{ + static override configSchema: string = WitnessConfigSchema + + override get queries(): string[] { + return [WitnessObserveQuerySchema, ...super.queries] + } + + get targetSet() { + return this.config?.targetSet + } + + protected override get _queryAccountPaths(): Record { + return { + 'network.xyo.query.witness.observe': '1/1', + } + } + + observe(payloads?: Payload[]): Promisable { + this.started('throw') + const payloadList = assertEx(payloads, 'Trying to witness nothing') + assertEx(payloadList.length > 0, 'Trying to witness empty list') + payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) + return payloadList + } + + protected override async queryHandler( + query: T, + payloads?: Payload[], + queryConfig?: TConfig, + ): Promise { + const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) + const queryPayload = await wrapper.getQuery() + assertEx(this.queryable(query, payloads, queryConfig)) + // Remove the query payload from the arguments passed to us so we don't observe it + const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) + const queryAccount = Account.random() + try { + switch (queryPayload.schema) { + case WitnessObserveQuerySchema: { + await this.emit('reportStart', { inPayloads: payloads, module: this }) + const resultPayloads = await this.observe(filteredObservation) + await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) + return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] + } + default: { + return super.queryHandler(query, payloads) + } + } + } catch (ex) { + const error = ex as Error + const [result] = await this.bindQueryResult( + queryPayload, + [], + [queryAccount], + [ + new ModuleErrorBuilder() + .sources([await wrapper.hashAsync()]) + .name(this.config.name ?? '') + .query(query.schema) + .message(error.message) + .build(), + ], + ) + return result + } + } +} diff --git a/packages/modules/packages/witness/packages/wrapper/src/Config.ts b/packages/modules/packages/witness/packages/wrapper/src/Config.ts new file mode 100644 index 00000000000..6ddc09184bd --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/Config.ts @@ -0,0 +1,16 @@ +import { WithAdditional } from '@xyo-network/core' +import { ModuleConfig } from '@xyo-network/module' +import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' + +export type WitnessConfigSchema = 'network.xyo.witness.config' +export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' + +export type WitnessConfig = ModuleConfig< + WithAdditional< + { + schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema + targetSet?: PayloadSetPayload + }, + TConfig + > +> diff --git a/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts new file mode 100644 index 00000000000..5d5cf3f152d --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts @@ -0,0 +1,9 @@ +import { Query } from '@xyo-network/module-model' + +export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' +export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' + +export type WitnessObserveQuery = Query<{ + payloads?: string[] + schema: WitnessObserveQuerySchema +}> diff --git a/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts b/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts new file mode 100644 index 00000000000..576d9567561 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts @@ -0,0 +1,9 @@ +import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' + +import { WitnessObserveQuery } from './Observe' + +export * from './Observe' + +export type WitnessQueryBase = WitnessObserveQuery +export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase +export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts new file mode 100644 index 00000000000..a8742621596 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts @@ -0,0 +1,15 @@ +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { AbstractWitness } from './AbstractWitness' +import { WitnessParams } from './Witness' + +export abstract class TimestampWitness

extends AbstractWitness

{ + override observe(fields?: Payload[] | undefined): Promisable { + return super.observe( + fields?.map((fieldItem) => { + return { ...fieldItem, timestamp: Date.now() } + }), + ) + } +} diff --git a/packages/modules/packages/witness/packages/wrapper/src/Witness.ts b/packages/modules/packages/witness/packages/wrapper/src/Witness.ts new file mode 100644 index 00000000000..c0e02597bf6 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/Witness.ts @@ -0,0 +1,47 @@ +import { AnyObject } from '@xyo-network/core' +import { EventData } from '@xyo-network/module' +import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' +import { Promisable } from '@xyo-network/promise' + +import { WitnessConfig } from './Config' + +export interface Witness { + observe: (payloads?: Payload[]) => Promisable +} + +export type WitnessReportEndEventArgs = ModuleEventArgs< + WitnessModule, + { + errors?: Error[] + inPayloads?: Payload[] + outPayloads?: Payload[] + } +> + +export interface WitnessReportEndEventData extends EventData { + reportEnd: WitnessReportEndEventArgs +} + +export type WitnessReportStartEventArgs = ModuleEventArgs< + WitnessModule, + { + inPayloads?: Payload[] + } +> + +export interface WitnessReportStartEventData extends EventData { + reportStart: WitnessReportStartEventArgs +} + +export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} + +export type WitnessParams< + TConfig extends AnyConfigSchema = AnyConfigSchema, + TAdditionalParams extends AnyObject | undefined = undefined, +> = ModuleParams + +export type WitnessModule< + TParams extends WitnessParams = WitnessParams, + TEventData extends WitnessModuleEventData = WitnessModuleEventData, +> = Witness & Module diff --git a/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts new file mode 100644 index 00000000000..46efba3a773 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts @@ -0,0 +1,16 @@ +import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' +import { Payload } from '@xyo-network/payload-model' +import { PayloadWrapper } from '@xyo-network/payload-wrapper' + +import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' +import { Witness } from './Witness' + +constructableModuleWrapper() +export class WitnessWrapper extends ModuleWrapper implements Witness { + static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] + + observe(payloads?: Payload[]): Promise { + const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) + return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) + } +} diff --git a/packages/modules/packages/witness/packages/wrapper/src/index.ts b/packages/modules/packages/witness/packages/wrapper/src/index.ts new file mode 100644 index 00000000000..8a2cfcb34a2 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/index.ts @@ -0,0 +1,6 @@ +export * from './AbstractWitness' +export * from './Config' +export * from './Queries' +export * from './TimestampWitness' +export * from './Witness' +export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts new file mode 100644 index 00000000000..ba072f2ceba --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts @@ -0,0 +1,61 @@ +import { Account } from '@xyo-network/account' +import { AccountInstance } from '@xyo-network/account-model' +import { Module, ModuleParams } from '@xyo-network/module' +import { PayloadBuilder } from '@xyo-network/payload-builder' + +import { AbstractWitness } from '../AbstractWitness' +import { WitnessConfig, WitnessConfigSchema } from '../Config' +import { WitnessModule } from '../Witness' +import { WitnessWrapper } from '../WitnessWrapper' + +describe('Witness', () => { + const config: WitnessConfig = { schema: WitnessConfigSchema } + const params: ModuleParams = { config } + const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() + + describe('fulfills type of', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('Module', async () => { + const witness: Module = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('AbstractModule', async () => { + const witness = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + it('WitnessModule', async () => { + const witness: WitnessModule = await AbstractWitness.create(params) + expect(witness).toBeObject() + const wrapper = new WitnessWrapper({ account, module: witness }) + expect(wrapper).toBeObject() + }) + }) + describe('observe', () => { + describe('with payload supplied to observe', () => { + describe('returns payloads', () => { + let account: AccountInstance + beforeAll(() => { + account = Account.random() + }) + it('when module queried directly', async () => { + const witness = await AbstractWitness.create(params) + const observation = await witness.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + it('when module queried with WitnessWrapper', async () => { + const witness = await AbstractWitness.create(params) + const wrapper = new WitnessWrapper({ account, module: witness }) + const observation = await wrapper.observe([observed]) + expect(observation).toBeArrayOfSize(1) + }) + }) + }) + }) +}) diff --git a/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json new file mode 100644 index 00000000000..16980bd0bd0 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@xylabs/tsconfig-jest" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/wrapper/tsconfig.json b/packages/modules/packages/witness/packages/wrapper/tsconfig.json new file mode 100644 index 00000000000..d55197bca10 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "declarationDir": "./dist/types", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "typeRoots": [] + }, + + "extends": "@xylabs/tsconfig" +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/wrapper/tsconfig.typedoc.json b/packages/modules/packages/witness/packages/wrapper/tsconfig.typedoc.json new file mode 100644 index 00000000000..a77abc2f4f0 --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/tsconfig.typedoc.json @@ -0,0 +1,5 @@ +{ + "exclude": ["**/spec/*", "**/*.spec.*"], + "extends": "./tsconfig.json" +} + diff --git a/packages/modules/packages/witness/packages/wrapper/typedoc.json b/packages/modules/packages/witness/packages/wrapper/typedoc.json new file mode 100644 index 00000000000..8eda4f2661e --- /dev/null +++ b/packages/modules/packages/witness/packages/wrapper/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 From 69da22e161b76a499bb795c69aba0cde3fb96c4f Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 07:50:59 -0500 Subject: [PATCH 02/11] Reference packages --- package.json | 2 +- .../witness/packages/abstract/package.json | 3 +- .../witness/packages/abstract/src/Config.ts | 16 ---- .../packages/abstract/src/Queries/Observe.ts | 9 -- .../packages/abstract/src/Queries/index.ts | 9 -- .../packages/abstract/src/TimestampWitness.ts | 15 ---- .../witness/packages/abstract/src/Witness.ts | 47 ---------- .../packages/abstract/src/WitnessWrapper.ts | 16 ---- .../witness/packages/abstract/src/index.ts | 6 +- .../packages/model/src/AbstractWitness.ts | 90 ------------------- .../packages/model/src/TimestampWitness.ts | 15 ---- .../packages/model/src/WitnessWrapper.ts | 16 ---- .../witness/packages/model/src/index.ts | 3 - .../model/src/spec/AbstractWitness.spec.ts | 61 ------------- .../packages/model/src/spec/tsconfig.json | 3 - .../witness/packages/timestamp/package.json | 4 +- .../packages/timestamp/src/AbstractWitness.ts | 90 ------------------- .../witness/packages/timestamp/src/Config.ts | 16 ---- .../packages/timestamp/src/Queries/Observe.ts | 9 -- .../packages/timestamp/src/Queries/index.ts | 9 -- .../witness/packages/timestamp/src/Witness.ts | 47 ---------- .../packages/timestamp/src/WitnessWrapper.ts | 16 ---- .../witness/packages/timestamp/src/index.ts | 6 +- .../src/spec/AbstractWitness.spec.ts | 61 ------------- .../packages/timestamp/src/spec/tsconfig.json | 3 - .../witness/packages/wrapper/package.json | 3 +- .../packages/wrapper/src/AbstractWitness.ts | 90 ------------------- .../witness/packages/wrapper/src/Config.ts | 16 ---- .../packages/wrapper/src/Queries/Observe.ts | 9 -- .../packages/wrapper/src/Queries/index.ts | 9 -- .../packages/wrapper/src/TimestampWitness.ts | 15 ---- .../witness/packages/wrapper/src/Witness.ts | 47 ---------- .../witness/packages/wrapper/src/index.ts | 5 -- .../wrapper/src/spec/AbstractWitness.spec.ts | 61 ------------- .../packages/wrapper/src/spec/tsconfig.json | 3 - yarn.lock | 76 ++++++++++++++++ 36 files changed, 86 insertions(+), 820 deletions(-) delete mode 100644 packages/modules/packages/witness/packages/abstract/src/Config.ts delete mode 100644 packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts delete mode 100644 packages/modules/packages/witness/packages/abstract/src/Queries/index.ts delete mode 100644 packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts delete mode 100644 packages/modules/packages/witness/packages/abstract/src/Witness.ts delete mode 100644 packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts delete mode 100644 packages/modules/packages/witness/packages/model/src/AbstractWitness.ts delete mode 100644 packages/modules/packages/witness/packages/model/src/TimestampWitness.ts delete mode 100644 packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts delete mode 100644 packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts delete mode 100644 packages/modules/packages/witness/packages/model/src/spec/tsconfig.json delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/Config.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/Witness.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts delete mode 100644 packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/Config.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/Witness.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts delete mode 100644 packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json diff --git a/package.json b/package.json index 4bc41245549..70b3f23b177 100644 --- a/package.json +++ b/package.json @@ -106,4 +106,4 @@ "node": "18.13.0", "yarn": "1.22.19" } -} \ No newline at end of file +} diff --git a/packages/modules/packages/witness/packages/abstract/package.json b/packages/modules/packages/witness/packages/abstract/package.json index 771334a893a..eba2254a974 100644 --- a/packages/modules/packages/witness/packages/abstract/package.json +++ b/packages/modules/packages/witness/packages/abstract/package.json @@ -17,7 +17,8 @@ "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/promise": "workspace:^" + "@xyo-network/promise": "workspace:^", + "@xyo-network/witness-model": "workspace:^" }, "devDependencies": { "@xylabs/ts-scripts-yarn3": "^2.17.17", diff --git a/packages/modules/packages/witness/packages/abstract/src/Config.ts b/packages/modules/packages/witness/packages/abstract/src/Config.ts deleted file mode 100644 index 6ddc09184bd..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/Config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { WithAdditional } from '@xyo-network/core' -import { ModuleConfig } from '@xyo-network/module' -import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' - -export type WitnessConfigSchema = 'network.xyo.witness.config' -export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' - -export type WitnessConfig = ModuleConfig< - WithAdditional< - { - schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema - targetSet?: PayloadSetPayload - }, - TConfig - > -> diff --git a/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts deleted file mode 100644 index 5d5cf3f152d..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/Queries/Observe.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Query } from '@xyo-network/module-model' - -export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' -export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' - -export type WitnessObserveQuery = Query<{ - payloads?: string[] - schema: WitnessObserveQuerySchema -}> diff --git a/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts b/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts deleted file mode 100644 index 576d9567561..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/Queries/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' - -import { WitnessObserveQuery } from './Observe' - -export * from './Observe' - -export type WitnessQueryBase = WitnessObserveQuery -export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase -export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts deleted file mode 100644 index a8742621596..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/TimestampWitness.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { AbstractWitness } from './AbstractWitness' -import { WitnessParams } from './Witness' - -export abstract class TimestampWitness

extends AbstractWitness

{ - override observe(fields?: Payload[] | undefined): Promisable { - return super.observe( - fields?.map((fieldItem) => { - return { ...fieldItem, timestamp: Date.now() } - }), - ) - } -} diff --git a/packages/modules/packages/witness/packages/abstract/src/Witness.ts b/packages/modules/packages/witness/packages/abstract/src/Witness.ts deleted file mode 100644 index c0e02597bf6..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/Witness.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { AnyObject } from '@xyo-network/core' -import { EventData } from '@xyo-network/module' -import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfig } from './Config' - -export interface Witness { - observe: (payloads?: Payload[]) => Promisable -} - -export type WitnessReportEndEventArgs = ModuleEventArgs< - WitnessModule, - { - errors?: Error[] - inPayloads?: Payload[] - outPayloads?: Payload[] - } -> - -export interface WitnessReportEndEventData extends EventData { - reportEnd: WitnessReportEndEventArgs -} - -export type WitnessReportStartEventArgs = ModuleEventArgs< - WitnessModule, - { - inPayloads?: Payload[] - } -> - -export interface WitnessReportStartEventData extends EventData { - reportStart: WitnessReportStartEventArgs -} - -export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} - -export type WitnessParams< - TConfig extends AnyConfigSchema = AnyConfigSchema, - TAdditionalParams extends AnyObject | undefined = undefined, -> = ModuleParams - -export type WitnessModule< - TParams extends WitnessParams = WitnessParams, - TEventData extends WitnessModuleEventData = WitnessModuleEventData, -> = Witness & Module diff --git a/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts deleted file mode 100644 index 46efba3a773..00000000000 --- a/packages/modules/packages/witness/packages/abstract/src/WitnessWrapper.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { PayloadWrapper } from '@xyo-network/payload-wrapper' - -import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' -import { Witness } from './Witness' - -constructableModuleWrapper() -export class WitnessWrapper extends ModuleWrapper implements Witness { - static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] - - observe(payloads?: Payload[]): Promise { - const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) - return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) - } -} diff --git a/packages/modules/packages/witness/packages/abstract/src/index.ts b/packages/modules/packages/witness/packages/abstract/src/index.ts index 8a2cfcb34a2..436c815d7a0 100644 --- a/packages/modules/packages/witness/packages/abstract/src/index.ts +++ b/packages/modules/packages/witness/packages/abstract/src/index.ts @@ -1,6 +1,2 @@ export * from './AbstractWitness' -export * from './Config' -export * from './Queries' -export * from './TimestampWitness' -export * from './Witness' -export * from './WitnessWrapper' + diff --git a/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts deleted file mode 100644 index a10f40cb39b..00000000000 --- a/packages/modules/packages/witness/packages/model/src/AbstractWitness.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { assertEx } from '@xylabs/assert' -import { Account } from '@xyo-network/account' -import { PayloadHasher } from '@xyo-network/core' -import { - AbstractModule, - creatableModule, - ModuleConfig, - ModuleErrorBuilder, - ModuleQueryResult, - QueryBoundWitness, - QueryBoundWitnessWrapper, -} from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfigSchema } from './Config' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' - -creatableModule() -export class AbstractWitness - extends AbstractModule - implements WitnessModule -{ - static override configSchema: string = WitnessConfigSchema - - override get queries(): string[] { - return [WitnessObserveQuerySchema, ...super.queries] - } - - get targetSet() { - return this.config?.targetSet - } - - protected override get _queryAccountPaths(): Record { - return { - 'network.xyo.query.witness.observe': '1/1', - } - } - - observe(payloads?: Payload[]): Promisable { - this.started('throw') - const payloadList = assertEx(payloads, 'Trying to witness nothing') - assertEx(payloadList.length > 0, 'Trying to witness empty list') - payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) - return payloadList - } - - protected override async queryHandler( - query: T, - payloads?: Payload[], - queryConfig?: TConfig, - ): Promise { - const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) - const queryPayload = await wrapper.getQuery() - assertEx(this.queryable(query, payloads, queryConfig)) - // Remove the query payload from the arguments passed to us so we don't observe it - const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) - const queryAccount = Account.random() - try { - switch (queryPayload.schema) { - case WitnessObserveQuerySchema: { - await this.emit('reportStart', { inPayloads: payloads, module: this }) - const resultPayloads = await this.observe(filteredObservation) - await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) - return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] - } - default: { - return super.queryHandler(query, payloads) - } - } - } catch (ex) { - const error = ex as Error - const [result] = await this.bindQueryResult( - queryPayload, - [], - [queryAccount], - [ - new ModuleErrorBuilder() - .sources([await wrapper.hashAsync()]) - .name(this.config.name ?? '') - .query(query.schema) - .message(error.message) - .build(), - ], - ) - return result - } - } -} diff --git a/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts deleted file mode 100644 index a8742621596..00000000000 --- a/packages/modules/packages/witness/packages/model/src/TimestampWitness.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { AbstractWitness } from './AbstractWitness' -import { WitnessParams } from './Witness' - -export abstract class TimestampWitness

extends AbstractWitness

{ - override observe(fields?: Payload[] | undefined): Promisable { - return super.observe( - fields?.map((fieldItem) => { - return { ...fieldItem, timestamp: Date.now() } - }), - ) - } -} diff --git a/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts deleted file mode 100644 index 46efba3a773..00000000000 --- a/packages/modules/packages/witness/packages/model/src/WitnessWrapper.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { PayloadWrapper } from '@xyo-network/payload-wrapper' - -import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' -import { Witness } from './Witness' - -constructableModuleWrapper() -export class WitnessWrapper extends ModuleWrapper implements Witness { - static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] - - observe(payloads?: Payload[]): Promise { - const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) - return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) - } -} diff --git a/packages/modules/packages/witness/packages/model/src/index.ts b/packages/modules/packages/witness/packages/model/src/index.ts index 8a2cfcb34a2..25d721c3780 100644 --- a/packages/modules/packages/witness/packages/model/src/index.ts +++ b/packages/modules/packages/witness/packages/model/src/index.ts @@ -1,6 +1,3 @@ -export * from './AbstractWitness' export * from './Config' export * from './Queries' -export * from './TimestampWitness' export * from './Witness' -export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts deleted file mode 100644 index ba072f2ceba..00000000000 --- a/packages/modules/packages/witness/packages/model/src/spec/AbstractWitness.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Account } from '@xyo-network/account' -import { AccountInstance } from '@xyo-network/account-model' -import { Module, ModuleParams } from '@xyo-network/module' -import { PayloadBuilder } from '@xyo-network/payload-builder' - -import { AbstractWitness } from '../AbstractWitness' -import { WitnessConfig, WitnessConfigSchema } from '../Config' -import { WitnessModule } from '../Witness' -import { WitnessWrapper } from '../WitnessWrapper' - -describe('Witness', () => { - const config: WitnessConfig = { schema: WitnessConfigSchema } - const params: ModuleParams = { config } - const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() - - describe('fulfills type of', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('Module', async () => { - const witness: Module = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('AbstractModule', async () => { - const witness = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('WitnessModule', async () => { - const witness: WitnessModule = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - }) - describe('observe', () => { - describe('with payload supplied to observe', () => { - describe('returns payloads', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('when module queried directly', async () => { - const witness = await AbstractWitness.create(params) - const observation = await witness.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - it('when module queried with WitnessWrapper', async () => { - const witness = await AbstractWitness.create(params) - const wrapper = new WitnessWrapper({ account, module: witness }) - const observation = await wrapper.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - }) - }) - }) -}) diff --git a/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json deleted file mode 100644 index 16980bd0bd0..00000000000 --- a/packages/modules/packages/witness/packages/model/src/spec/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@xylabs/tsconfig-jest" -} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/timestamp/package.json b/packages/modules/packages/witness/packages/timestamp/package.json index 286a701871e..a07165f4b2e 100644 --- a/packages/modules/packages/witness/packages/timestamp/package.json +++ b/packages/modules/packages/witness/packages/timestamp/package.json @@ -11,13 +11,15 @@ }, "dependencies": { "@xylabs/assert": "^2.9.3", + "@xyo-network/abstract-witness": "workspace:^", "@xyo-network/account": "workspace:^", "@xyo-network/core": "workspace:^", "@xyo-network/module": "workspace:^", "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/promise": "workspace:^" + "@xyo-network/promise": "workspace:^", + "@xyo-network/witness-model": "workspace:^" }, "devDependencies": { "@xylabs/ts-scripts-yarn3": "^2.17.17", diff --git a/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts deleted file mode 100644 index a10f40cb39b..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/AbstractWitness.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { assertEx } from '@xylabs/assert' -import { Account } from '@xyo-network/account' -import { PayloadHasher } from '@xyo-network/core' -import { - AbstractModule, - creatableModule, - ModuleConfig, - ModuleErrorBuilder, - ModuleQueryResult, - QueryBoundWitness, - QueryBoundWitnessWrapper, -} from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfigSchema } from './Config' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' - -creatableModule() -export class AbstractWitness - extends AbstractModule - implements WitnessModule -{ - static override configSchema: string = WitnessConfigSchema - - override get queries(): string[] { - return [WitnessObserveQuerySchema, ...super.queries] - } - - get targetSet() { - return this.config?.targetSet - } - - protected override get _queryAccountPaths(): Record { - return { - 'network.xyo.query.witness.observe': '1/1', - } - } - - observe(payloads?: Payload[]): Promisable { - this.started('throw') - const payloadList = assertEx(payloads, 'Trying to witness nothing') - assertEx(payloadList.length > 0, 'Trying to witness empty list') - payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) - return payloadList - } - - protected override async queryHandler( - query: T, - payloads?: Payload[], - queryConfig?: TConfig, - ): Promise { - const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) - const queryPayload = await wrapper.getQuery() - assertEx(this.queryable(query, payloads, queryConfig)) - // Remove the query payload from the arguments passed to us so we don't observe it - const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) - const queryAccount = Account.random() - try { - switch (queryPayload.schema) { - case WitnessObserveQuerySchema: { - await this.emit('reportStart', { inPayloads: payloads, module: this }) - const resultPayloads = await this.observe(filteredObservation) - await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) - return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] - } - default: { - return super.queryHandler(query, payloads) - } - } - } catch (ex) { - const error = ex as Error - const [result] = await this.bindQueryResult( - queryPayload, - [], - [queryAccount], - [ - new ModuleErrorBuilder() - .sources([await wrapper.hashAsync()]) - .name(this.config.name ?? '') - .query(query.schema) - .message(error.message) - .build(), - ], - ) - return result - } - } -} diff --git a/packages/modules/packages/witness/packages/timestamp/src/Config.ts b/packages/modules/packages/witness/packages/timestamp/src/Config.ts deleted file mode 100644 index 6ddc09184bd..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/Config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { WithAdditional } from '@xyo-network/core' -import { ModuleConfig } from '@xyo-network/module' -import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' - -export type WitnessConfigSchema = 'network.xyo.witness.config' -export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' - -export type WitnessConfig = ModuleConfig< - WithAdditional< - { - schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema - targetSet?: PayloadSetPayload - }, - TConfig - > -> diff --git a/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts deleted file mode 100644 index 5d5cf3f152d..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/Queries/Observe.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Query } from '@xyo-network/module-model' - -export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' -export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' - -export type WitnessObserveQuery = Query<{ - payloads?: string[] - schema: WitnessObserveQuerySchema -}> diff --git a/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts b/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts deleted file mode 100644 index 576d9567561..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/Queries/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' - -import { WitnessObserveQuery } from './Observe' - -export * from './Observe' - -export type WitnessQueryBase = WitnessObserveQuery -export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase -export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/timestamp/src/Witness.ts b/packages/modules/packages/witness/packages/timestamp/src/Witness.ts deleted file mode 100644 index c0e02597bf6..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/Witness.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { AnyObject } from '@xyo-network/core' -import { EventData } from '@xyo-network/module' -import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfig } from './Config' - -export interface Witness { - observe: (payloads?: Payload[]) => Promisable -} - -export type WitnessReportEndEventArgs = ModuleEventArgs< - WitnessModule, - { - errors?: Error[] - inPayloads?: Payload[] - outPayloads?: Payload[] - } -> - -export interface WitnessReportEndEventData extends EventData { - reportEnd: WitnessReportEndEventArgs -} - -export type WitnessReportStartEventArgs = ModuleEventArgs< - WitnessModule, - { - inPayloads?: Payload[] - } -> - -export interface WitnessReportStartEventData extends EventData { - reportStart: WitnessReportStartEventArgs -} - -export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} - -export type WitnessParams< - TConfig extends AnyConfigSchema = AnyConfigSchema, - TAdditionalParams extends AnyObject | undefined = undefined, -> = ModuleParams - -export type WitnessModule< - TParams extends WitnessParams = WitnessParams, - TEventData extends WitnessModuleEventData = WitnessModuleEventData, -> = Witness & Module diff --git a/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts deleted file mode 100644 index 46efba3a773..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/WitnessWrapper.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { PayloadWrapper } from '@xyo-network/payload-wrapper' - -import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' -import { Witness } from './Witness' - -constructableModuleWrapper() -export class WitnessWrapper extends ModuleWrapper implements Witness { - static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] - - observe(payloads?: Payload[]): Promise { - const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) - return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) - } -} diff --git a/packages/modules/packages/witness/packages/timestamp/src/index.ts b/packages/modules/packages/witness/packages/timestamp/src/index.ts index 8a2cfcb34a2..b05d2febaee 100644 --- a/packages/modules/packages/witness/packages/timestamp/src/index.ts +++ b/packages/modules/packages/witness/packages/timestamp/src/index.ts @@ -1,6 +1,2 @@ -export * from './AbstractWitness' -export * from './Config' -export * from './Queries' export * from './TimestampWitness' -export * from './Witness' -export * from './WitnessWrapper' + diff --git a/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts deleted file mode 100644 index ba072f2ceba..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/spec/AbstractWitness.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Account } from '@xyo-network/account' -import { AccountInstance } from '@xyo-network/account-model' -import { Module, ModuleParams } from '@xyo-network/module' -import { PayloadBuilder } from '@xyo-network/payload-builder' - -import { AbstractWitness } from '../AbstractWitness' -import { WitnessConfig, WitnessConfigSchema } from '../Config' -import { WitnessModule } from '../Witness' -import { WitnessWrapper } from '../WitnessWrapper' - -describe('Witness', () => { - const config: WitnessConfig = { schema: WitnessConfigSchema } - const params: ModuleParams = { config } - const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() - - describe('fulfills type of', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('Module', async () => { - const witness: Module = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('AbstractModule', async () => { - const witness = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('WitnessModule', async () => { - const witness: WitnessModule = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - }) - describe('observe', () => { - describe('with payload supplied to observe', () => { - describe('returns payloads', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('when module queried directly', async () => { - const witness = await AbstractWitness.create(params) - const observation = await witness.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - it('when module queried with WitnessWrapper', async () => { - const witness = await AbstractWitness.create(params) - const wrapper = new WitnessWrapper({ account, module: witness }) - const observation = await wrapper.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - }) - }) - }) -}) diff --git a/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json deleted file mode 100644 index 16980bd0bd0..00000000000 --- a/packages/modules/packages/witness/packages/timestamp/src/spec/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@xylabs/tsconfig-jest" -} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/wrapper/package.json b/packages/modules/packages/witness/packages/wrapper/package.json index 952451d1ac4..d7ef59cc9d4 100644 --- a/packages/modules/packages/witness/packages/wrapper/package.json +++ b/packages/modules/packages/witness/packages/wrapper/package.json @@ -17,7 +17,8 @@ "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/promise": "workspace:^" + "@xyo-network/promise": "workspace:^", + "@xyo-network/witness-model": "workspace:^" }, "devDependencies": { "@xylabs/ts-scripts-yarn3": "^2.17.17", diff --git a/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts deleted file mode 100644 index a10f40cb39b..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/AbstractWitness.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { assertEx } from '@xylabs/assert' -import { Account } from '@xyo-network/account' -import { PayloadHasher } from '@xyo-network/core' -import { - AbstractModule, - creatableModule, - ModuleConfig, - ModuleErrorBuilder, - ModuleQueryResult, - QueryBoundWitness, - QueryBoundWitnessWrapper, -} from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfigSchema } from './Config' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' - -creatableModule() -export class AbstractWitness - extends AbstractModule - implements WitnessModule -{ - static override configSchema: string = WitnessConfigSchema - - override get queries(): string[] { - return [WitnessObserveQuerySchema, ...super.queries] - } - - get targetSet() { - return this.config?.targetSet - } - - protected override get _queryAccountPaths(): Record { - return { - 'network.xyo.query.witness.observe': '1/1', - } - } - - observe(payloads?: Payload[]): Promisable { - this.started('throw') - const payloadList = assertEx(payloads, 'Trying to witness nothing') - assertEx(payloadList.length > 0, 'Trying to witness empty list') - payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) - return payloadList - } - - protected override async queryHandler( - query: T, - payloads?: Payload[], - queryConfig?: TConfig, - ): Promise { - const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) - const queryPayload = await wrapper.getQuery() - assertEx(this.queryable(query, payloads, queryConfig)) - // Remove the query payload from the arguments passed to us so we don't observe it - const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) - const queryAccount = Account.random() - try { - switch (queryPayload.schema) { - case WitnessObserveQuerySchema: { - await this.emit('reportStart', { inPayloads: payloads, module: this }) - const resultPayloads = await this.observe(filteredObservation) - await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) - return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] - } - default: { - return super.queryHandler(query, payloads) - } - } - } catch (ex) { - const error = ex as Error - const [result] = await this.bindQueryResult( - queryPayload, - [], - [queryAccount], - [ - new ModuleErrorBuilder() - .sources([await wrapper.hashAsync()]) - .name(this.config.name ?? '') - .query(query.schema) - .message(error.message) - .build(), - ], - ) - return result - } - } -} diff --git a/packages/modules/packages/witness/packages/wrapper/src/Config.ts b/packages/modules/packages/witness/packages/wrapper/src/Config.ts deleted file mode 100644 index 6ddc09184bd..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/Config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { WithAdditional } from '@xyo-network/core' -import { ModuleConfig } from '@xyo-network/module' -import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' - -export type WitnessConfigSchema = 'network.xyo.witness.config' -export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' - -export type WitnessConfig = ModuleConfig< - WithAdditional< - { - schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema - targetSet?: PayloadSetPayload - }, - TConfig - > -> diff --git a/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts b/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts deleted file mode 100644 index 5d5cf3f152d..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/Queries/Observe.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Query } from '@xyo-network/module-model' - -export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' -export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' - -export type WitnessObserveQuery = Query<{ - payloads?: string[] - schema: WitnessObserveQuerySchema -}> diff --git a/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts b/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts deleted file mode 100644 index 576d9567561..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/Queries/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' - -import { WitnessObserveQuery } from './Observe' - -export * from './Observe' - -export type WitnessQueryBase = WitnessObserveQuery -export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase -export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts deleted file mode 100644 index a8742621596..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/TimestampWitness.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { AbstractWitness } from './AbstractWitness' -import { WitnessParams } from './Witness' - -export abstract class TimestampWitness

extends AbstractWitness

{ - override observe(fields?: Payload[] | undefined): Promisable { - return super.observe( - fields?.map((fieldItem) => { - return { ...fieldItem, timestamp: Date.now() } - }), - ) - } -} diff --git a/packages/modules/packages/witness/packages/wrapper/src/Witness.ts b/packages/modules/packages/witness/packages/wrapper/src/Witness.ts deleted file mode 100644 index c0e02597bf6..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/Witness.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { AnyObject } from '@xyo-network/core' -import { EventData } from '@xyo-network/module' -import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfig } from './Config' - -export interface Witness { - observe: (payloads?: Payload[]) => Promisable -} - -export type WitnessReportEndEventArgs = ModuleEventArgs< - WitnessModule, - { - errors?: Error[] - inPayloads?: Payload[] - outPayloads?: Payload[] - } -> - -export interface WitnessReportEndEventData extends EventData { - reportEnd: WitnessReportEndEventArgs -} - -export type WitnessReportStartEventArgs = ModuleEventArgs< - WitnessModule, - { - inPayloads?: Payload[] - } -> - -export interface WitnessReportStartEventData extends EventData { - reportStart: WitnessReportStartEventArgs -} - -export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} - -export type WitnessParams< - TConfig extends AnyConfigSchema = AnyConfigSchema, - TAdditionalParams extends AnyObject | undefined = undefined, -> = ModuleParams - -export type WitnessModule< - TParams extends WitnessParams = WitnessParams, - TEventData extends WitnessModuleEventData = WitnessModuleEventData, -> = Witness & Module diff --git a/packages/modules/packages/witness/packages/wrapper/src/index.ts b/packages/modules/packages/witness/packages/wrapper/src/index.ts index 8a2cfcb34a2..14abde6f53f 100644 --- a/packages/modules/packages/witness/packages/wrapper/src/index.ts +++ b/packages/modules/packages/witness/packages/wrapper/src/index.ts @@ -1,6 +1 @@ -export * from './AbstractWitness' -export * from './Config' -export * from './Queries' -export * from './TimestampWitness' -export * from './Witness' export * from './WitnessWrapper' diff --git a/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts deleted file mode 100644 index ba072f2ceba..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/spec/AbstractWitness.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Account } from '@xyo-network/account' -import { AccountInstance } from '@xyo-network/account-model' -import { Module, ModuleParams } from '@xyo-network/module' -import { PayloadBuilder } from '@xyo-network/payload-builder' - -import { AbstractWitness } from '../AbstractWitness' -import { WitnessConfig, WitnessConfigSchema } from '../Config' -import { WitnessModule } from '../Witness' -import { WitnessWrapper } from '../WitnessWrapper' - -describe('Witness', () => { - const config: WitnessConfig = { schema: WitnessConfigSchema } - const params: ModuleParams = { config } - const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() - - describe('fulfills type of', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('Module', async () => { - const witness: Module = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('AbstractModule', async () => { - const witness = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('WitnessModule', async () => { - const witness: WitnessModule = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - }) - describe('observe', () => { - describe('with payload supplied to observe', () => { - describe('returns payloads', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('when module queried directly', async () => { - const witness = await AbstractWitness.create(params) - const observation = await witness.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - it('when module queried with WitnessWrapper', async () => { - const witness = await AbstractWitness.create(params) - const wrapper = new WitnessWrapper({ account, module: witness }) - const observation = await wrapper.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - }) - }) - }) -}) diff --git a/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json b/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json deleted file mode 100644 index 16980bd0bd0..00000000000 --- a/packages/modules/packages/witness/packages/wrapper/src/spec/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@xylabs/tsconfig-jest" -} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 60bb64b4e28..969e1bc6581 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5434,6 +5434,25 @@ __metadata: languageName: unknown linkType: soft +"@xyo-network/abstract-witness@workspace:^, @xyo-network/abstract-witness@workspace:packages/modules/packages/witness/packages/abstract": + version: 0.0.0-use.local + resolution: "@xyo-network/abstract-witness@workspace:packages/modules/packages/witness/packages/abstract" + dependencies: + "@xylabs/assert": ^2.9.3 + "@xylabs/ts-scripts-yarn3": ^2.17.17 + "@xylabs/tsconfig": ^2.17.17 + "@xyo-network/account": "workspace:^" + "@xyo-network/core": "workspace:^" + "@xyo-network/module": "workspace:^" + "@xyo-network/module-model": "workspace:^" + "@xyo-network/payload-model": "workspace:^" + "@xyo-network/payload-wrapper": "workspace:^" + "@xyo-network/promise": "workspace:^" + "@xyo-network/witness-model": "workspace:^" + typescript: ^5.1.3 + languageName: unknown + linkType: soft + "@xyo-network/account-model@workspace:^, @xyo-network/account-model@workspace:packages/protocol/packages/account/packages/account-model": version: 0.0.0-use.local resolution: "@xyo-network/account-model@workspace:packages/protocol/packages/account/packages/account-model" @@ -8812,6 +8831,63 @@ __metadata: languageName: unknown linkType: soft +"@xyo-network/witness-model@workspace:^, @xyo-network/witness-model@workspace:packages/modules/packages/witness/packages/model": + version: 0.0.0-use.local + resolution: "@xyo-network/witness-model@workspace:packages/modules/packages/witness/packages/model" + dependencies: + "@xylabs/assert": ^2.9.3 + "@xylabs/ts-scripts-yarn3": ^2.17.17 + "@xylabs/tsconfig": ^2.17.17 + "@xyo-network/account": "workspace:^" + "@xyo-network/core": "workspace:^" + "@xyo-network/module": "workspace:^" + "@xyo-network/module-model": "workspace:^" + "@xyo-network/payload-model": "workspace:^" + "@xyo-network/payload-wrapper": "workspace:^" + "@xyo-network/promise": "workspace:^" + typescript: ^5.1.3 + languageName: unknown + linkType: soft + +"@xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp": + version: 0.0.0-use.local + resolution: "@xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp" + dependencies: + "@xylabs/assert": ^2.9.3 + "@xylabs/ts-scripts-yarn3": ^2.17.17 + "@xylabs/tsconfig": ^2.17.17 + "@xyo-network/abstract-witness": "workspace:^" + "@xyo-network/account": "workspace:^" + "@xyo-network/core": "workspace:^" + "@xyo-network/module": "workspace:^" + "@xyo-network/module-model": "workspace:^" + "@xyo-network/payload-model": "workspace:^" + "@xyo-network/payload-wrapper": "workspace:^" + "@xyo-network/promise": "workspace:^" + "@xyo-network/witness-model": "workspace:^" + typescript: ^5.1.3 + languageName: unknown + linkType: soft + +"@xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper": + version: 0.0.0-use.local + resolution: "@xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper" + dependencies: + "@xylabs/assert": ^2.9.3 + "@xylabs/ts-scripts-yarn3": ^2.17.17 + "@xylabs/tsconfig": ^2.17.17 + "@xyo-network/account": "workspace:^" + "@xyo-network/core": "workspace:^" + "@xyo-network/module": "workspace:^" + "@xyo-network/module-model": "workspace:^" + "@xyo-network/payload-model": "workspace:^" + "@xyo-network/payload-wrapper": "workspace:^" + "@xyo-network/promise": "workspace:^" + "@xyo-network/witness-model": "workspace:^" + typescript: ^5.1.3 + languageName: unknown + linkType: soft + "@xyo-network/witness@workspace:^, @xyo-network/witness@workspace:packages/modules/packages/witness": version: 0.0.0-use.local resolution: "@xyo-network/witness@workspace:packages/modules/packages/witness" From 0b8f6f4660a1a7f2016dae6565b67ab26e301d1b Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:09:53 -0500 Subject: [PATCH 03/11] Reference witness packages --- .../witness/packages/abstract/src/AbstractWitness.ts | 6 +++--- .../witness/packages/timestamp/src/TimestampWitness.ts | 4 ++-- .../packages/witness/packages/wrapper/src/WitnessWrapper.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts index a10f40cb39b..0e210af300e 100644 --- a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts +++ b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts @@ -13,9 +13,9 @@ import { import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' -import { WitnessConfigSchema } from './Config' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' +import { WitnessConfigSchema } from '@xyo-network/witness-model' +import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from '@xyo-network/witness-model' +import { WitnessModule, WitnessModuleEventData, WitnessParams } from '@xyo-network/witness-model' creatableModule() export class AbstractWitness diff --git a/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts index a8742621596..40dd9f5e0fb 100644 --- a/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts +++ b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts @@ -1,8 +1,8 @@ import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' -import { AbstractWitness } from './AbstractWitness' -import { WitnessParams } from './Witness' +import { AbstractWitness } from '@xyo-network/abstract-witness' +import { WitnessParams } from '@xyo-network/witness-model' export abstract class TimestampWitness

extends AbstractWitness

{ override observe(fields?: Payload[] | undefined): Promisable { diff --git a/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts index 46efba3a773..b47b2a78518 100644 --- a/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts +++ b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts @@ -2,8 +2,8 @@ import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' -import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' -import { Witness } from './Witness' +import { WitnessObserveQuery, WitnessObserveQuerySchema } from '@xyo-network/witness-model' +import { Witness } from '@xyo-network/witness-model' constructableModuleWrapper() export class WitnessWrapper extends ModuleWrapper implements Witness { From d559a5430c7fae55b4e7468d87efbc91cd11236b Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:13:31 -0500 Subject: [PATCH 04/11] Export witness via barrel package --- .../modules/packages/witness/package.json | 12 +-- .../packages/witness/src/AbstractWitness.ts | 90 ------------------- .../modules/packages/witness/src/Config.ts | 16 ---- .../packages/witness/src/Queries/Observe.ts | 9 -- .../packages/witness/src/Queries/index.ts | 9 -- .../packages/witness/src/TimestampWitness.ts | 15 ---- .../modules/packages/witness/src/Witness.ts | 47 ---------- .../packages/witness/src/WitnessWrapper.ts | 16 ---- .../modules/packages/witness/src/index.ts | 11 ++- .../witness/src/spec/AbstractWitness.spec.ts | 61 ------------- .../packages/witness/src/spec/tsconfig.json | 3 - yarn.lock | 16 ++-- 12 files changed, 15 insertions(+), 290 deletions(-) delete mode 100644 packages/modules/packages/witness/src/AbstractWitness.ts delete mode 100644 packages/modules/packages/witness/src/Config.ts delete mode 100644 packages/modules/packages/witness/src/Queries/Observe.ts delete mode 100644 packages/modules/packages/witness/src/Queries/index.ts delete mode 100644 packages/modules/packages/witness/src/TimestampWitness.ts delete mode 100644 packages/modules/packages/witness/src/Witness.ts delete mode 100644 packages/modules/packages/witness/src/WitnessWrapper.ts delete mode 100644 packages/modules/packages/witness/src/spec/AbstractWitness.spec.ts delete mode 100644 packages/modules/packages/witness/src/spec/tsconfig.json diff --git a/packages/modules/packages/witness/package.json b/packages/modules/packages/witness/package.json index 5dffa78713b..a9ce3ab7ddb 100644 --- a/packages/modules/packages/witness/package.json +++ b/packages/modules/packages/witness/package.json @@ -10,14 +10,10 @@ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues" }, "dependencies": { - "@xylabs/assert": "^2.9.3", - "@xyo-network/account": "workspace:^", - "@xyo-network/core": "workspace:^", - "@xyo-network/module": "workspace:^", - "@xyo-network/module-model": "workspace:^", - "@xyo-network/payload-model": "workspace:^", - "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/promise": "workspace:^" + "@xyo-network/abstract-witness": "workspace:^", + "@xyo-network/witness-model": "workspace:^", + "@xyo-network/witness-timestamp": "workspace:^", + "@xyo-network/witness-wrapper": "workspace:^" }, "devDependencies": { "@xylabs/ts-scripts-yarn3": "^2.17.17", diff --git a/packages/modules/packages/witness/src/AbstractWitness.ts b/packages/modules/packages/witness/src/AbstractWitness.ts deleted file mode 100644 index a10f40cb39b..00000000000 --- a/packages/modules/packages/witness/src/AbstractWitness.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { assertEx } from '@xylabs/assert' -import { Account } from '@xyo-network/account' -import { PayloadHasher } from '@xyo-network/core' -import { - AbstractModule, - creatableModule, - ModuleConfig, - ModuleErrorBuilder, - ModuleQueryResult, - QueryBoundWitness, - QueryBoundWitnessWrapper, -} from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfigSchema } from './Config' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from './Queries' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from './Witness' - -creatableModule() -export class AbstractWitness - extends AbstractModule - implements WitnessModule -{ - static override configSchema: string = WitnessConfigSchema - - override get queries(): string[] { - return [WitnessObserveQuerySchema, ...super.queries] - } - - get targetSet() { - return this.config?.targetSet - } - - protected override get _queryAccountPaths(): Record { - return { - 'network.xyo.query.witness.observe': '1/1', - } - } - - observe(payloads?: Payload[]): Promisable { - this.started('throw') - const payloadList = assertEx(payloads, 'Trying to witness nothing') - assertEx(payloadList.length > 0, 'Trying to witness empty list') - payloadList?.forEach((payload) => assertEx(payload.schema, 'observe: Missing Schema')) - return payloadList - } - - protected override async queryHandler( - query: T, - payloads?: Payload[], - queryConfig?: TConfig, - ): Promise { - const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads) - const queryPayload = await wrapper.getQuery() - assertEx(this.queryable(query, payloads, queryConfig)) - // Remove the query payload from the arguments passed to us so we don't observe it - const filteredObservation = await PayloadHasher.filterExclude(payloads, query.query) - const queryAccount = Account.random() - try { - switch (queryPayload.schema) { - case WitnessObserveQuerySchema: { - await this.emit('reportStart', { inPayloads: payloads, module: this }) - const resultPayloads = await this.observe(filteredObservation) - await this.emit('reportEnd', { inPayloads: payloads, module: this, outPayloads: resultPayloads }) - return (await this.bindQueryResult(queryPayload, resultPayloads, [queryAccount]))[0] - } - default: { - return super.queryHandler(query, payloads) - } - } - } catch (ex) { - const error = ex as Error - const [result] = await this.bindQueryResult( - queryPayload, - [], - [queryAccount], - [ - new ModuleErrorBuilder() - .sources([await wrapper.hashAsync()]) - .name(this.config.name ?? '') - .query(query.schema) - .message(error.message) - .build(), - ], - ) - return result - } - } -} diff --git a/packages/modules/packages/witness/src/Config.ts b/packages/modules/packages/witness/src/Config.ts deleted file mode 100644 index 6ddc09184bd..00000000000 --- a/packages/modules/packages/witness/src/Config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { WithAdditional } from '@xyo-network/core' -import { ModuleConfig } from '@xyo-network/module' -import { Payload, PayloadSetPayload } from '@xyo-network/payload-model' - -export type WitnessConfigSchema = 'network.xyo.witness.config' -export const WitnessConfigSchema: WitnessConfigSchema = 'network.xyo.witness.config' - -export type WitnessConfig = ModuleConfig< - WithAdditional< - { - schema: TConfig extends Payload ? TConfig['schema'] : WitnessConfigSchema - targetSet?: PayloadSetPayload - }, - TConfig - > -> diff --git a/packages/modules/packages/witness/src/Queries/Observe.ts b/packages/modules/packages/witness/src/Queries/Observe.ts deleted file mode 100644 index 5d5cf3f152d..00000000000 --- a/packages/modules/packages/witness/src/Queries/Observe.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Query } from '@xyo-network/module-model' - -export type WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' -export const WitnessObserveQuerySchema: WitnessObserveQuerySchema = 'network.xyo.query.witness.observe' - -export type WitnessObserveQuery = Query<{ - payloads?: string[] - schema: WitnessObserveQuerySchema -}> diff --git a/packages/modules/packages/witness/src/Queries/index.ts b/packages/modules/packages/witness/src/Queries/index.ts deleted file mode 100644 index 576d9567561..00000000000 --- a/packages/modules/packages/witness/src/Queries/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ModuleQuery, ModuleQueryBase, Query } from '@xyo-network/module-model' - -import { WitnessObserveQuery } from './Observe' - -export * from './Observe' - -export type WitnessQueryBase = WitnessObserveQuery -export type WitnessModuleQueries = ModuleQueryBase | WitnessQueryBase -export type WitnessQuery = ModuleQuery diff --git a/packages/modules/packages/witness/src/TimestampWitness.ts b/packages/modules/packages/witness/src/TimestampWitness.ts deleted file mode 100644 index a8742621596..00000000000 --- a/packages/modules/packages/witness/src/TimestampWitness.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { AbstractWitness } from './AbstractWitness' -import { WitnessParams } from './Witness' - -export abstract class TimestampWitness

extends AbstractWitness

{ - override observe(fields?: Payload[] | undefined): Promisable { - return super.observe( - fields?.map((fieldItem) => { - return { ...fieldItem, timestamp: Date.now() } - }), - ) - } -} diff --git a/packages/modules/packages/witness/src/Witness.ts b/packages/modules/packages/witness/src/Witness.ts deleted file mode 100644 index c0e02597bf6..00000000000 --- a/packages/modules/packages/witness/src/Witness.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { AnyObject } from '@xyo-network/core' -import { EventData } from '@xyo-network/module' -import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' -import { Payload } from '@xyo-network/payload-model' -import { Promisable } from '@xyo-network/promise' - -import { WitnessConfig } from './Config' - -export interface Witness { - observe: (payloads?: Payload[]) => Promisable -} - -export type WitnessReportEndEventArgs = ModuleEventArgs< - WitnessModule, - { - errors?: Error[] - inPayloads?: Payload[] - outPayloads?: Payload[] - } -> - -export interface WitnessReportEndEventData extends EventData { - reportEnd: WitnessReportEndEventArgs -} - -export type WitnessReportStartEventArgs = ModuleEventArgs< - WitnessModule, - { - inPayloads?: Payload[] - } -> - -export interface WitnessReportStartEventData extends EventData { - reportStart: WitnessReportStartEventArgs -} - -export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} - -export type WitnessParams< - TConfig extends AnyConfigSchema = AnyConfigSchema, - TAdditionalParams extends AnyObject | undefined = undefined, -> = ModuleParams - -export type WitnessModule< - TParams extends WitnessParams = WitnessParams, - TEventData extends WitnessModuleEventData = WitnessModuleEventData, -> = Witness & Module diff --git a/packages/modules/packages/witness/src/WitnessWrapper.ts b/packages/modules/packages/witness/src/WitnessWrapper.ts deleted file mode 100644 index 46efba3a773..00000000000 --- a/packages/modules/packages/witness/src/WitnessWrapper.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' -import { Payload } from '@xyo-network/payload-model' -import { PayloadWrapper } from '@xyo-network/payload-wrapper' - -import { WitnessObserveQuery, WitnessObserveQuerySchema } from './Queries' -import { Witness } from './Witness' - -constructableModuleWrapper() -export class WitnessWrapper extends ModuleWrapper implements Witness { - static override requiredQueries = [WitnessObserveQuerySchema, ...super.requiredQueries] - - observe(payloads?: Payload[]): Promise { - const queryPayload = PayloadWrapper.wrap({ schema: WitnessObserveQuerySchema }) - return this.sendQuery(queryPayload, [queryPayload.payload(), ...(payloads ?? [])]) - } -} diff --git a/packages/modules/packages/witness/src/index.ts b/packages/modules/packages/witness/src/index.ts index 8a2cfcb34a2..914b2508e9b 100644 --- a/packages/modules/packages/witness/src/index.ts +++ b/packages/modules/packages/witness/src/index.ts @@ -1,6 +1,5 @@ -export * from './AbstractWitness' -export * from './Config' -export * from './Queries' -export * from './TimestampWitness' -export * from './Witness' -export * from './WitnessWrapper' +export * from '@xyo-network/abstract-witness' +export * from '@xyo-network/witness-model' +export * from '@xyo-network/witness-timestamp' +export * from '@xyo-network/witness-wrapper' + diff --git a/packages/modules/packages/witness/src/spec/AbstractWitness.spec.ts b/packages/modules/packages/witness/src/spec/AbstractWitness.spec.ts deleted file mode 100644 index ba072f2ceba..00000000000 --- a/packages/modules/packages/witness/src/spec/AbstractWitness.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Account } from '@xyo-network/account' -import { AccountInstance } from '@xyo-network/account-model' -import { Module, ModuleParams } from '@xyo-network/module' -import { PayloadBuilder } from '@xyo-network/payload-builder' - -import { AbstractWitness } from '../AbstractWitness' -import { WitnessConfig, WitnessConfigSchema } from '../Config' -import { WitnessModule } from '../Witness' -import { WitnessWrapper } from '../WitnessWrapper' - -describe('Witness', () => { - const config: WitnessConfig = { schema: WitnessConfigSchema } - const params: ModuleParams = { config } - const observed = new PayloadBuilder({ schema: 'network.xyo.test' }).build() - - describe('fulfills type of', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('Module', async () => { - const witness: Module = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('AbstractModule', async () => { - const witness = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - it('WitnessModule', async () => { - const witness: WitnessModule = await AbstractWitness.create(params) - expect(witness).toBeObject() - const wrapper = new WitnessWrapper({ account, module: witness }) - expect(wrapper).toBeObject() - }) - }) - describe('observe', () => { - describe('with payload supplied to observe', () => { - describe('returns payloads', () => { - let account: AccountInstance - beforeAll(() => { - account = Account.random() - }) - it('when module queried directly', async () => { - const witness = await AbstractWitness.create(params) - const observation = await witness.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - it('when module queried with WitnessWrapper', async () => { - const witness = await AbstractWitness.create(params) - const wrapper = new WitnessWrapper({ account, module: witness }) - const observation = await wrapper.observe([observed]) - expect(observation).toBeArrayOfSize(1) - }) - }) - }) - }) -}) diff --git a/packages/modules/packages/witness/src/spec/tsconfig.json b/packages/modules/packages/witness/src/spec/tsconfig.json deleted file mode 100644 index 16980bd0bd0..00000000000 --- a/packages/modules/packages/witness/src/spec/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@xylabs/tsconfig-jest" -} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 969e1bc6581..2b74843f76d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8849,7 +8849,7 @@ __metadata: languageName: unknown linkType: soft -"@xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp": +"@xyo-network/witness-timestamp@workspace:^, @xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp": version: 0.0.0-use.local resolution: "@xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp" dependencies: @@ -8869,7 +8869,7 @@ __metadata: languageName: unknown linkType: soft -"@xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper": +"@xyo-network/witness-wrapper@workspace:^, @xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper": version: 0.0.0-use.local resolution: "@xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper" dependencies: @@ -8892,16 +8892,12 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/witness@workspace:packages/modules/packages/witness" dependencies: - "@xylabs/assert": ^2.9.3 "@xylabs/ts-scripts-yarn3": ^2.17.17 "@xylabs/tsconfig": ^2.17.17 - "@xyo-network/account": "workspace:^" - "@xyo-network/core": "workspace:^" - "@xyo-network/module": "workspace:^" - "@xyo-network/module-model": "workspace:^" - "@xyo-network/payload-model": "workspace:^" - "@xyo-network/payload-wrapper": "workspace:^" - "@xyo-network/promise": "workspace:^" + "@xyo-network/abstract-witness": "workspace:^" + "@xyo-network/witness-model": "workspace:^" + "@xyo-network/witness-timestamp": "workspace:^" + "@xyo-network/witness-wrapper": "workspace:^" typescript: ^5.1.3 languageName: unknown linkType: soft From a4dd77daef051f619ea6adcc425c3f3fed4df637 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:23:23 -0500 Subject: [PATCH 05/11] Modularize witness events --- .../packages/model/src/Events/ReportEnd.ts | 17 +++++++++++++++++ .../packages/model/src/Events/ReportStart.ts | 16 ++++++++++++++++ .../witness/packages/model/src/Events/index.ts | 2 ++ .../witness/packages/model/src/index.ts | 1 + 4 files changed, 36 insertions(+) create mode 100644 packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Events/index.ts diff --git a/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts b/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts new file mode 100644 index 00000000000..da821231a25 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts @@ -0,0 +1,17 @@ +import { ModuleEventArgs } from "@xyo-network/module-model" +import { EventData } from '@xyo-network/module' +import { Payload } from "@xyo-network/payload-model" +import { WitnessModule } from "../Module" + +export type WitnessReportEndEventArgs = ModuleEventArgs< + WitnessModule, + { + errors?: Error[] + inPayloads?: Payload[] + outPayloads?: Payload[] + } +> + +export interface WitnessReportEndEventData extends EventData { + reportEnd: WitnessReportEndEventArgs +} \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts b/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts new file mode 100644 index 00000000000..5f0748ce317 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts @@ -0,0 +1,16 @@ +import { ModuleEventArgs } from "@xyo-network/module-model" +import { EventData } from '@xyo-network/module' +import { Payload } from "@xyo-network/payload-model" +import { WitnessModule } from "../Module" + +export interface WitnessReportStartEventData extends EventData { + reportStart: WitnessReportStartEventArgs +} + + +export type WitnessReportStartEventArgs = ModuleEventArgs< + WitnessModule, + { + inPayloads?: Payload[] + } +> \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/model/src/Events/index.ts b/packages/modules/packages/witness/packages/model/src/Events/index.ts new file mode 100644 index 00000000000..73b15276e48 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Events/index.ts @@ -0,0 +1,2 @@ +export * from './ReportEnd' +export * from './ReportStart' \ No newline at end of file diff --git a/packages/modules/packages/witness/packages/model/src/index.ts b/packages/modules/packages/witness/packages/model/src/index.ts index 25d721c3780..f859f0f9386 100644 --- a/packages/modules/packages/witness/packages/model/src/index.ts +++ b/packages/modules/packages/witness/packages/model/src/index.ts @@ -1,3 +1,4 @@ export * from './Config' +export * from './Events' export * from './Queries' export * from './Witness' From e61165df51d6893c1409f24e5b0036fd7e4b5c8a Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:23:54 -0500 Subject: [PATCH 06/11] Modularize witness --- .../witness/packages/model/src/Module.ts | 12 ++++++ .../witness/packages/model/src/Params.ts | 8 ++++ .../witness/packages/model/src/Witness.ts | 41 ------------------- 3 files changed, 20 insertions(+), 41 deletions(-) create mode 100644 packages/modules/packages/witness/packages/model/src/Module.ts create mode 100644 packages/modules/packages/witness/packages/model/src/Params.ts diff --git a/packages/modules/packages/witness/packages/model/src/Module.ts b/packages/modules/packages/witness/packages/model/src/Module.ts new file mode 100644 index 00000000000..d74ac2edfb8 --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Module.ts @@ -0,0 +1,12 @@ +import { Module, ModuleEventData } from '@xyo-network/module-model' + +import { WitnessReportEndEventData, WitnessReportStartEventData } from './Events' +import { WitnessParams } from './Params' +import { Witness } from './Witness' + +export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} + +export type WitnessModule< + TParams extends WitnessParams = WitnessParams, + TEventData extends WitnessModuleEventData = WitnessModuleEventData, +> = Witness & Module diff --git a/packages/modules/packages/witness/packages/model/src/Params.ts b/packages/modules/packages/witness/packages/model/src/Params.ts new file mode 100644 index 00000000000..4feb8ac144e --- /dev/null +++ b/packages/modules/packages/witness/packages/model/src/Params.ts @@ -0,0 +1,8 @@ +import { AnyObject } from '@xyo-network/core' +import { AnyConfigSchema, ModuleParams } from '@xyo-network/module-model' + +import { WitnessConfig } from './Config' +export type WitnessParams< + TConfig extends AnyConfigSchema = AnyConfigSchema, + TAdditionalParams extends AnyObject | undefined = undefined, +> = ModuleParams diff --git a/packages/modules/packages/witness/packages/model/src/Witness.ts b/packages/modules/packages/witness/packages/model/src/Witness.ts index c0e02597bf6..2c7a4589fc1 100644 --- a/packages/modules/packages/witness/packages/model/src/Witness.ts +++ b/packages/modules/packages/witness/packages/model/src/Witness.ts @@ -1,47 +1,6 @@ -import { AnyObject } from '@xyo-network/core' -import { EventData } from '@xyo-network/module' -import { AnyConfigSchema, Module, ModuleEventArgs, ModuleEventData, ModuleParams } from '@xyo-network/module-model' import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' -import { WitnessConfig } from './Config' - export interface Witness { observe: (payloads?: Payload[]) => Promisable } - -export type WitnessReportEndEventArgs = ModuleEventArgs< - WitnessModule, - { - errors?: Error[] - inPayloads?: Payload[] - outPayloads?: Payload[] - } -> - -export interface WitnessReportEndEventData extends EventData { - reportEnd: WitnessReportEndEventArgs -} - -export type WitnessReportStartEventArgs = ModuleEventArgs< - WitnessModule, - { - inPayloads?: Payload[] - } -> - -export interface WitnessReportStartEventData extends EventData { - reportStart: WitnessReportStartEventArgs -} - -export interface WitnessModuleEventData extends WitnessReportEndEventData, WitnessReportStartEventData, ModuleEventData {} - -export type WitnessParams< - TConfig extends AnyConfigSchema = AnyConfigSchema, - TAdditionalParams extends AnyObject | undefined = undefined, -> = ModuleParams - -export type WitnessModule< - TParams extends WitnessParams = WitnessParams, - TEventData extends WitnessModuleEventData = WitnessModuleEventData, -> = Witness & Module From 26cba190937ae97f1b2cc201785c8f76b7a5ffcd Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:26:12 -0500 Subject: [PATCH 07/11] Update exports --- packages/modules/packages/witness/packages/model/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/modules/packages/witness/packages/model/src/index.ts b/packages/modules/packages/witness/packages/model/src/index.ts index f859f0f9386..d21411ed9ca 100644 --- a/packages/modules/packages/witness/packages/model/src/index.ts +++ b/packages/modules/packages/witness/packages/model/src/index.ts @@ -1,4 +1,6 @@ export * from './Config' export * from './Events' +export * from './Module' +export * from './Params' export * from './Queries' export * from './Witness' From 20cc2b183eece51762397e94f4cf30ed49f3e99a Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:26:18 -0500 Subject: [PATCH 08/11] Formatting --- .../witness/packages/model/src/Events/ReportEnd.ts | 9 +++++---- .../witness/packages/model/src/Events/ReportStart.ts | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts b/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts index da821231a25..2eb6dcbf937 100644 --- a/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts +++ b/packages/modules/packages/witness/packages/model/src/Events/ReportEnd.ts @@ -1,7 +1,8 @@ -import { ModuleEventArgs } from "@xyo-network/module-model" import { EventData } from '@xyo-network/module' -import { Payload } from "@xyo-network/payload-model" -import { WitnessModule } from "../Module" +import { ModuleEventArgs } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' + +import { WitnessModule } from '../Module' export type WitnessReportEndEventArgs = ModuleEventArgs< WitnessModule, @@ -14,4 +15,4 @@ export type WitnessReportEndEventArgs = ModuleEventArgs< export interface WitnessReportEndEventData extends EventData { reportEnd: WitnessReportEndEventArgs -} \ No newline at end of file +} diff --git a/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts b/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts index 5f0748ce317..9fe63f92ba1 100644 --- a/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts +++ b/packages/modules/packages/witness/packages/model/src/Events/ReportStart.ts @@ -1,16 +1,16 @@ -import { ModuleEventArgs } from "@xyo-network/module-model" import { EventData } from '@xyo-network/module' -import { Payload } from "@xyo-network/payload-model" -import { WitnessModule } from "../Module" +import { ModuleEventArgs } from '@xyo-network/module-model' +import { Payload } from '@xyo-network/payload-model' + +import { WitnessModule } from '../Module' export interface WitnessReportStartEventData extends EventData { reportStart: WitnessReportStartEventArgs } - export type WitnessReportStartEventArgs = ModuleEventArgs< WitnessModule, { inPayloads?: Payload[] } -> \ No newline at end of file +> From 26bde17f8cc27e581aac79e33e1ca7ff890726ee Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:27:18 -0500 Subject: [PATCH 09/11] Formatting --- .../modules/packages/witness/packages/model/src/Events/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/packages/witness/packages/model/src/Events/index.ts b/packages/modules/packages/witness/packages/model/src/Events/index.ts index 73b15276e48..9610e349c2f 100644 --- a/packages/modules/packages/witness/packages/model/src/Events/index.ts +++ b/packages/modules/packages/witness/packages/model/src/Events/index.ts @@ -1,2 +1,2 @@ export * from './ReportEnd' -export * from './ReportStart' \ No newline at end of file +export * from './ReportStart' From 0576871a3be58eb31ee92a8117f929073e697e69 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:34:07 -0500 Subject: [PATCH 10/11] Curate deps --- packages/manifest/package.json | 3 ++- .../witness/packages/abstract/package.json | 2 -- .../witness/packages/model/package.json | 3 --- .../witness/packages/timestamp/package.json | 6 ------ .../witness/packages/wrapper/package.json | 5 ----- yarn.lock | 17 +---------------- 6 files changed, 3 insertions(+), 33 deletions(-) diff --git a/packages/manifest/package.json b/packages/manifest/package.json index ffa3b23506c..2014c074849 100644 --- a/packages/manifest/package.json +++ b/packages/manifest/package.json @@ -20,7 +20,8 @@ "@xyo-network/node": "workspace:^", "@xyo-network/payload-model": "workspace:^", "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/sentinel": "workspace:^" + "@xyo-network/sentinel": "workspace:^", + "@xyo-network/wallet-model": "workspace:^" }, "devDependencies": { "@xylabs/ts-scripts-yarn3": "^2.17.17", diff --git a/packages/modules/packages/witness/packages/abstract/package.json b/packages/modules/packages/witness/packages/abstract/package.json index eba2254a974..e04f3e60b1b 100644 --- a/packages/modules/packages/witness/packages/abstract/package.json +++ b/packages/modules/packages/witness/packages/abstract/package.json @@ -14,9 +14,7 @@ "@xyo-network/account": "workspace:^", "@xyo-network/core": "workspace:^", "@xyo-network/module": "workspace:^", - "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", - "@xyo-network/payload-wrapper": "workspace:^", "@xyo-network/promise": "workspace:^", "@xyo-network/witness-model": "workspace:^" }, diff --git a/packages/modules/packages/witness/packages/model/package.json b/packages/modules/packages/witness/packages/model/package.json index f0a50da9415..07c3e81769c 100644 --- a/packages/modules/packages/witness/packages/model/package.json +++ b/packages/modules/packages/witness/packages/model/package.json @@ -10,13 +10,10 @@ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues" }, "dependencies": { - "@xylabs/assert": "^2.9.3", - "@xyo-network/account": "workspace:^", "@xyo-network/core": "workspace:^", "@xyo-network/module": "workspace:^", "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", - "@xyo-network/payload-wrapper": "workspace:^", "@xyo-network/promise": "workspace:^" }, "devDependencies": { diff --git a/packages/modules/packages/witness/packages/timestamp/package.json b/packages/modules/packages/witness/packages/timestamp/package.json index a07165f4b2e..06cab1b4b07 100644 --- a/packages/modules/packages/witness/packages/timestamp/package.json +++ b/packages/modules/packages/witness/packages/timestamp/package.json @@ -10,14 +10,8 @@ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues" }, "dependencies": { - "@xylabs/assert": "^2.9.3", "@xyo-network/abstract-witness": "workspace:^", - "@xyo-network/account": "workspace:^", - "@xyo-network/core": "workspace:^", - "@xyo-network/module": "workspace:^", - "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", - "@xyo-network/payload-wrapper": "workspace:^", "@xyo-network/promise": "workspace:^", "@xyo-network/witness-model": "workspace:^" }, diff --git a/packages/modules/packages/witness/packages/wrapper/package.json b/packages/modules/packages/witness/packages/wrapper/package.json index d7ef59cc9d4..b6567fc19da 100644 --- a/packages/modules/packages/witness/packages/wrapper/package.json +++ b/packages/modules/packages/witness/packages/wrapper/package.json @@ -10,14 +10,9 @@ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues" }, "dependencies": { - "@xylabs/assert": "^2.9.3", - "@xyo-network/account": "workspace:^", - "@xyo-network/core": "workspace:^", "@xyo-network/module": "workspace:^", - "@xyo-network/module-model": "workspace:^", "@xyo-network/payload-model": "workspace:^", "@xyo-network/payload-wrapper": "workspace:^", - "@xyo-network/promise": "workspace:^", "@xyo-network/witness-model": "workspace:^" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 2b74843f76d..29598fc7b49 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5444,9 +5444,7 @@ __metadata: "@xyo-network/account": "workspace:^" "@xyo-network/core": "workspace:^" "@xyo-network/module": "workspace:^" - "@xyo-network/module-model": "workspace:^" "@xyo-network/payload-model": "workspace:^" - "@xyo-network/payload-wrapper": "workspace:^" "@xyo-network/promise": "workspace:^" "@xyo-network/witness-model": "workspace:^" typescript: ^5.1.3 @@ -7761,6 +7759,7 @@ __metadata: "@xyo-network/payload-model": "workspace:^" "@xyo-network/payload-wrapper": "workspace:^" "@xyo-network/sentinel": "workspace:^" + "@xyo-network/wallet-model": "workspace:^" typescript: ^5.1.3 languageName: unknown linkType: soft @@ -8835,15 +8834,12 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/witness-model@workspace:packages/modules/packages/witness/packages/model" dependencies: - "@xylabs/assert": ^2.9.3 "@xylabs/ts-scripts-yarn3": ^2.17.17 "@xylabs/tsconfig": ^2.17.17 - "@xyo-network/account": "workspace:^" "@xyo-network/core": "workspace:^" "@xyo-network/module": "workspace:^" "@xyo-network/module-model": "workspace:^" "@xyo-network/payload-model": "workspace:^" - "@xyo-network/payload-wrapper": "workspace:^" "@xyo-network/promise": "workspace:^" typescript: ^5.1.3 languageName: unknown @@ -8853,16 +8849,10 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/witness-timestamp@workspace:packages/modules/packages/witness/packages/timestamp" dependencies: - "@xylabs/assert": ^2.9.3 "@xylabs/ts-scripts-yarn3": ^2.17.17 "@xylabs/tsconfig": ^2.17.17 "@xyo-network/abstract-witness": "workspace:^" - "@xyo-network/account": "workspace:^" - "@xyo-network/core": "workspace:^" - "@xyo-network/module": "workspace:^" - "@xyo-network/module-model": "workspace:^" "@xyo-network/payload-model": "workspace:^" - "@xyo-network/payload-wrapper": "workspace:^" "@xyo-network/promise": "workspace:^" "@xyo-network/witness-model": "workspace:^" typescript: ^5.1.3 @@ -8873,16 +8863,11 @@ __metadata: version: 0.0.0-use.local resolution: "@xyo-network/witness-wrapper@workspace:packages/modules/packages/witness/packages/wrapper" dependencies: - "@xylabs/assert": ^2.9.3 "@xylabs/ts-scripts-yarn3": ^2.17.17 "@xylabs/tsconfig": ^2.17.17 - "@xyo-network/account": "workspace:^" - "@xyo-network/core": "workspace:^" "@xyo-network/module": "workspace:^" - "@xyo-network/module-model": "workspace:^" "@xyo-network/payload-model": "workspace:^" "@xyo-network/payload-wrapper": "workspace:^" - "@xyo-network/promise": "workspace:^" "@xyo-network/witness-model": "workspace:^" typescript: ^5.1.3 languageName: unknown From 5c1818c8a68ed269a94ade345ae10169826b01b1 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 28 Jun 2023 08:37:33 -0500 Subject: [PATCH 11/11] Formatting --- .../packages/abstract/src/AbstractWitness.ts | 13 +++++++++---- .../packages/witness/packages/abstract/src/index.ts | 1 - .../packages/timestamp/src/TimestampWitness.ts | 3 +-- .../witness/packages/timestamp/src/index.ts | 1 - .../witness/packages/wrapper/src/WitnessWrapper.ts | 4 +--- packages/modules/packages/witness/src/index.ts | 1 - 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts index 0e210af300e..5334d628f1b 100644 --- a/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts +++ b/packages/modules/packages/witness/packages/abstract/src/AbstractWitness.ts @@ -12,10 +12,15 @@ import { } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' - -import { WitnessConfigSchema } from '@xyo-network/witness-model' -import { WitnessObserveQuerySchema, WitnessQuery, WitnessQueryBase } from '@xyo-network/witness-model' -import { WitnessModule, WitnessModuleEventData, WitnessParams } from '@xyo-network/witness-model' +import { + WitnessConfigSchema, + WitnessModule, + WitnessModuleEventData, + WitnessObserveQuerySchema, + WitnessParams, + WitnessQuery, + WitnessQueryBase, +} from '@xyo-network/witness-model' creatableModule() export class AbstractWitness diff --git a/packages/modules/packages/witness/packages/abstract/src/index.ts b/packages/modules/packages/witness/packages/abstract/src/index.ts index 436c815d7a0..9f4895987c8 100644 --- a/packages/modules/packages/witness/packages/abstract/src/index.ts +++ b/packages/modules/packages/witness/packages/abstract/src/index.ts @@ -1,2 +1 @@ export * from './AbstractWitness' - diff --git a/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts index 40dd9f5e0fb..a7ce9825a79 100644 --- a/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts +++ b/packages/modules/packages/witness/packages/timestamp/src/TimestampWitness.ts @@ -1,7 +1,6 @@ +import { AbstractWitness } from '@xyo-network/abstract-witness' import { Payload } from '@xyo-network/payload-model' import { Promisable } from '@xyo-network/promise' - -import { AbstractWitness } from '@xyo-network/abstract-witness' import { WitnessParams } from '@xyo-network/witness-model' export abstract class TimestampWitness

extends AbstractWitness

{ diff --git a/packages/modules/packages/witness/packages/timestamp/src/index.ts b/packages/modules/packages/witness/packages/timestamp/src/index.ts index b05d2febaee..89401e8485a 100644 --- a/packages/modules/packages/witness/packages/timestamp/src/index.ts +++ b/packages/modules/packages/witness/packages/timestamp/src/index.ts @@ -1,2 +1 @@ export * from './TimestampWitness' - diff --git a/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts index b47b2a78518..3b4d71f3c8e 100644 --- a/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts +++ b/packages/modules/packages/witness/packages/wrapper/src/WitnessWrapper.ts @@ -1,9 +1,7 @@ import { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module' import { Payload } from '@xyo-network/payload-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' - -import { WitnessObserveQuery, WitnessObserveQuerySchema } from '@xyo-network/witness-model' -import { Witness } from '@xyo-network/witness-model' +import { Witness, WitnessObserveQuery, WitnessObserveQuerySchema } from '@xyo-network/witness-model' constructableModuleWrapper() export class WitnessWrapper extends ModuleWrapper implements Witness { diff --git a/packages/modules/packages/witness/src/index.ts b/packages/modules/packages/witness/src/index.ts index 914b2508e9b..66eef304cde 100644 --- a/packages/modules/packages/witness/src/index.ts +++ b/packages/modules/packages/witness/src/index.ts @@ -2,4 +2,3 @@ export * from '@xyo-network/abstract-witness' export * from '@xyo-network/witness-model' export * from '@xyo-network/witness-timestamp' export * from '@xyo-network/witness-wrapper' -