From b8c2a3a0a99a29a370f27065f6e3f3ce210984c2 Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Thu, 29 Feb 2024 15:12:52 -0500 Subject: [PATCH 1/2] feat: Use ajv-threads package for jsonSchema validation of ModelInstanceDocuments --- packages/core/package.json | 3 +- .../core/src/__tests__/handlers-map.test.ts | 9 +- packages/core/src/ceramic.ts | 17 +- packages/core/src/handlers-map.ts | 21 ++- .../__tests__/state-manipulator.test.ts | 7 +- .../__tests__/stream-loader.test.ts | 13 +- .../package.json | 3 +- .../model-instance-document-handler.test.ts | 9 +- .../src/__tests__/schema-utils.test.ts | 150 ------------------ .../src/model-instance-document-handler.ts | 8 +- .../src/schema-utils.ts | 43 ----- 11 files changed, 59 insertions(+), 224 deletions(-) delete mode 100644 packages/stream-model-instance-handler/src/__tests__/schema-utils.test.ts delete mode 100644 packages/stream-model-instance-handler/src/schema-utils.ts diff --git a/packages/core/package.json b/packages/core/package.json index 8de5507216..30f2a54eba 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -71,8 +71,7 @@ "@stablelib/random": "^1.0.1", "@stablelib/sha256": "^1.0.1", "@stablelib/uuid": "^1.0.1", - "ajv": "^8.8.2", - "ajv-formats": "^2.1.1", + "ajv-threads": "^1.0.3", "await-semaphore": "^0.1.3", "cartonne": "^3.0.1", "codeco": "^1.1.0", diff --git a/packages/core/src/__tests__/handlers-map.test.ts b/packages/core/src/__tests__/handlers-map.test.ts index 12991d0a46..126626f8b9 100644 --- a/packages/core/src/__tests__/handlers-map.test.ts +++ b/packages/core/src/__tests__/handlers-map.test.ts @@ -5,13 +5,14 @@ import { Caip10LinkHandler } from '@ceramicnetwork/stream-caip10-link-handler' import { ModelHandler } from '@ceramicnetwork/stream-model-handler' import { ModelInstanceDocumentHandler } from '@ceramicnetwork/stream-model-instance-handler' import { TileDocumentHandler } from '@ceramicnetwork/stream-tile-handler' +import type { SchemaValidation } from 'ajv-threads' const loggerProvider = new LoggerProvider() const logger = loggerProvider.getDiagnosticsLogger() describe('constructor', () => { test('default handlers', () => { - const handlers = new HandlersMap(logger) + const handlers = HandlersMap.makeWithDefaultHandlers(logger, null as SchemaValidation) expect(handlers.get('tile')).toBeInstanceOf(TileDocumentHandler) expect(handlers.get('caip10-link')).toBeInstanceOf(Caip10LinkHandler) expect(handlers.get('model')).toBeInstanceOf(ModelHandler) @@ -19,14 +20,14 @@ describe('constructor', () => { }) test('custom handlers', () => { const customHandler = jest.fn() as unknown as StreamHandler - const handlers = new HandlersMap(logger, new Map().set(13, customHandler)) + const handlers = HandlersMap.makeWithHandlers(logger, new Map().set(13, customHandler)) expect(handlers.get(13)).toBe(customHandler) }) }) test('set and get', () => { const customHandler = { name: 'custom', type: 13 } as unknown as StreamHandler - const handlers = new HandlersMap(logger) + const handlers = HandlersMap.makeEmpty(logger) expect(() => handlers.get('custom')).toThrow() handlers.add(customHandler) expect(() => handlers.get('custom')).toThrow() @@ -34,6 +35,6 @@ test('set and get', () => { }) test('get non-existing', () => { - const handlers = new HandlersMap(logger) + const handlers = HandlersMap.makeEmpty(logger) expect(() => handlers.get('custom')).toThrow() }) diff --git a/packages/core/src/ceramic.ts b/packages/core/src/ceramic.ts index 5512b1862b..d809780219 100644 --- a/packages/core/src/ceramic.ts +++ b/packages/core/src/ceramic.ts @@ -4,7 +4,6 @@ import { IpfsTopology } from '@ceramicnetwork/ipfs-topology' import { CreateOpts, Stream, - StreamHandler, DiagnosticsLogger, StreamUtils, LoadOpts, @@ -57,6 +56,7 @@ import { AnchorRequestCarBuilder } from './anchor/anchor-request-car-builder.js' import { makeStreamLoaderAndUpdater } from './initialization/stream-loading.js' import { Feed, type PublicFeed } from './feed.js' import { IReconApi, ReconApi } from './recon.js' +import { SchemaValidation } from 'ajv-threads' const DEFAULT_CACHE_LIMIT = 500 // number of streams stored in the cache const DEFAULT_QPS_LIMIT = 10 // Max number of pubsub query messages that can be published per second without rate limiting @@ -205,7 +205,8 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { private readonly providersCache: ProvidersCache private readonly syncApi: SyncApi - readonly _streamHandlers: HandlersMap + private readonly _streamHandlers: HandlersMap + private readonly _schemaValidator: SchemaValidation private readonly _readOnly: boolean private readonly _ipfsTopology: IpfsTopology private readonly _logger: DiagnosticsLogger @@ -243,7 +244,8 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { this._ipfs = modules.ipfs - this._streamHandlers = new HandlersMap(this._logger) + this._schemaValidator = new SchemaValidation() + this._streamHandlers = HandlersMap.makeWithDefaultHandlers(this._logger, this._schemaValidator) // This initialization block below has to be redone. // Things below should be passed here as `modules` variable. @@ -581,14 +583,6 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { } } - /** - * Register new stream handler - * @param streamHandler - Stream type handler - */ - addStreamHandler(streamHandler: StreamHandler): void { - this._streamHandlers.add(streamHandler) - } - async nodeStatus(): Promise { const anchor = { anchorServiceUrl: this.anchorService.url, @@ -893,6 +887,7 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { await this.syncApi.shutdown() await this.dispatcher.close() await this.repository.close() + await this._schemaValidator.shutdown() this._ipfsTopology.stop() this._logger.imp('Ceramic instance closed successfully') } diff --git a/packages/core/src/handlers-map.ts b/packages/core/src/handlers-map.ts index 4afdb89f6c..7422179376 100644 --- a/packages/core/src/handlers-map.ts +++ b/packages/core/src/handlers-map.ts @@ -5,14 +5,15 @@ import { ModelInstanceDocumentHandler } from '@ceramicnetwork/stream-model-insta import { Stream, StreamHandler } from '@ceramicnetwork/common' import { DiagnosticsLogger } from '@ceramicnetwork/common' import { StreamType } from '@ceramicnetwork/streamid' +import type { SchemaValidation } from 'ajv-threads' type Registry = Map> -function defaultHandlers(): Registry { +function defaultHandlers(schemaValidator: SchemaValidation): Registry { const tile = new TileDocumentHandler() const caip10Link = new Caip10LinkHandler() const model = new ModelHandler() - const instance = new ModelInstanceDocumentHandler() + const instance = new ModelInstanceDocumentHandler(schemaValidator) const handlers = new Map>() handlers.set(tile.type, tile) handlers.set(caip10Link.type, caip10Link) @@ -27,8 +28,20 @@ function defaultHandlers(): Registry { export class HandlersMap { private readonly handlers: Registry - constructor(private readonly logger: DiagnosticsLogger, handlers?: Registry) { - this.handlers = handlers || defaultHandlers() + private constructor(private readonly logger: DiagnosticsLogger, handlers: Registry) { + this.handlers = handlers + } + + static makeWithHandlers(logger: DiagnosticsLogger, handlers: Registry) { + return new HandlersMap(logger, handlers) + } + + static makeWithDefaultHandlers(logger: DiagnosticsLogger, schemaValidator: SchemaValidation) { + return new HandlersMap(logger, defaultHandlers(schemaValidator)) + } + + static makeEmpty(logger: DiagnosticsLogger) { + return new HandlersMap(logger, new Map()) } /** diff --git a/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts b/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts index c57a5f4f58..ca2fc96529 100644 --- a/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts +++ b/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts @@ -21,6 +21,7 @@ import { HandlersMap } from '../../handlers-map.js' import cloneDeep from 'lodash.clonedeep' import { CID } from 'multiformats/cid' import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' +import { SchemaValidation } from 'ajv-threads' const TOPIC = '/ceramic/test12345' const CONTENT0 = { step: 0 } @@ -41,6 +42,7 @@ describeIfV3('StateManipulator test', () => { let dispatcherIpfs: IpfsApi let logSyncer: LogSyncer let stateManipulator: StateManipulator + let schemaValidator: SchemaValidation let doc: TileDocument let commits: Array @@ -59,7 +61,9 @@ describeIfV3('StateManipulator test', () => { const logger = new LoggerProvider().getDiagnosticsLogger() logSyncer = new LogSyncer(dispatcher) - const handlers = new HandlersMap(logger) + + schemaValidator = new SchemaValidation() + const handlers = HandlersMap.makeWithDefaultHandlers(logger, schemaValidator) stateManipulator = new StateManipulator(logger, handlers, logSyncer, ceramic) await swarmConnect(dispatcherIpfs, ceramicIpfs) @@ -77,6 +81,7 @@ describeIfV3('StateManipulator test', () => { afterAll(async () => { await dispatcher.close() await ceramic.close() + await schemaValidator.shutdown() // Wait for pubsub unsubscribe to be processed // TODO(1963): Remove this once dispatcher.close() won't resolve until the pubsub unsubscribe diff --git a/packages/core/src/stream-loading/__tests__/stream-loader.test.ts b/packages/core/src/stream-loading/__tests__/stream-loader.test.ts index 25eb494305..618b3ca6c1 100644 --- a/packages/core/src/stream-loading/__tests__/stream-loader.test.ts +++ b/packages/core/src/stream-loading/__tests__/stream-loader.test.ts @@ -30,6 +30,7 @@ import { } from '../../pubsub/pubsub-message.js' import { asIpfsMessage } from '../../pubsub/__tests__/as-ipfs-message.js' import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' +import { SchemaValidation } from 'ajv-threads' const TOPIC = '/ceramic/test12345' const CONTENT0 = { step: 0 } @@ -58,6 +59,7 @@ describeIfV3('Streamloader', () => { let dispatcher: Dispatcher let dispatcherIpfs: IpfsApi + let schemaValidator: SchemaValidation let streamLoader: StreamLoader let ceramicIpfs: IpfsApi @@ -82,7 +84,9 @@ describeIfV3('Streamloader', () => { dispatcher, ceramic.anchorService.validator ) - const handlers = new HandlersMap(logger) + + schemaValidator = new SchemaValidation() + const handlers = HandlersMap.makeWithDefaultHandlers(logger, schemaValidator) const stateManipulator = new StateManipulator(logger, handlers, logSyncer, ceramic) streamLoader = new StreamLoader( logger, @@ -98,6 +102,7 @@ describeIfV3('Streamloader', () => { afterAll(async () => { await dispatcher.close() await ceramic.close() + await schemaValidator.shutdown() // Wait for pubsub unsubscribe to be processed // TODO(1963): Remove this once dispatcher.close() won't resolve until the pubsub unsubscribe @@ -302,6 +307,7 @@ describeIfV3('Streamloader', () => { let ipfs: IpfsApi let dispatcher: Dispatcher + let schemaValidator: SchemaValidation let streamLoader: StreamLoader let stream: TileDocument @@ -337,7 +343,9 @@ describeIfV3('Streamloader', () => { dispatcher, ceramic.anchorService.validator ) - const handlers = new HandlersMap(logger) + + schemaValidator = new SchemaValidation() + const handlers = HandlersMap.makeWithDefaultHandlers(logger, schemaValidator) const stateManipulator = new StateManipulator(logger, handlers, logSyncer, ceramic) streamLoader = new StreamLoader( logger, @@ -388,6 +396,7 @@ describeIfV3('Streamloader', () => { afterAll(async () => { await dispatcher.close() + await schemaValidator.shutdown() // Wait for pubsub unsubscribe to be processed // TODO(1963): Remove this once dispatcher.close() won't resolve until the pubsub unsubscribe diff --git a/packages/stream-model-instance-handler/package.json b/packages/stream-model-instance-handler/package.json index 810b14f1bd..719c54c727 100644 --- a/packages/stream-model-instance-handler/package.json +++ b/packages/stream-model-instance-handler/package.json @@ -43,8 +43,7 @@ "@ceramicnetwork/stream-model": "^4.2.0-rc.0", "@ceramicnetwork/stream-model-instance": "^4.3.0-rc.0", "@ceramicnetwork/streamid": "^5.0.0", - "ajv": "^8.8.2", - "ajv-formats": "^2.1.1", + "ajv-threads": "^1.0.3", "fast-json-patch": "^3.1.0", "least-recent": "^1.0.3", "lodash.clonedeep": "^4.5.0", diff --git a/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts b/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts index dcfad3b9be..b5585d8d07 100644 --- a/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts +++ b/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts @@ -31,6 +31,7 @@ import { } from '@ceramicnetwork/did-test-utils' import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' import { VerificationMethod } from 'did-resolver' +import { SchemaValidation } from 'ajv-threads' // because we're doing mocking weirdly, by mocking a function two libraries deep, to test a function // one library deep that is unrelated to TileDocumentHandler, we need to specifically duplicate @@ -414,6 +415,7 @@ const STREAMS = { describe('ModelInstanceDocumentHandler', () => { let handler: ModelInstanceDocumentHandler + let schemaValidator: SchemaValidation let context: StreamReaderWriter let defaultSigner: RotatingSigner let signerUsingNewKey: CeramicSigner @@ -421,6 +423,7 @@ describe('ModelInstanceDocumentHandler', () => { let ipfs: IpfsApi beforeAll(async () => { + schemaValidator = new SchemaValidation() const recs: Record = {} ipfs = { dag: { @@ -442,10 +445,14 @@ describe('ModelInstanceDocumentHandler', () => { } as IpfsApi }) + afterAll(async () => { + await schemaValidator.shutdown() + }) + beforeEach(async () => { ModelInstanceDocument.MAX_DOCUMENT_SIZE = 16_000_000 - handler = new ModelInstanceDocumentHandler() + handler = new ModelInstanceDocumentHandler(schemaValidator) defaultSigner = await DidTestUtils.rotatingSigner({}) context = DidTestUtils.api(defaultSigner) diff --git a/packages/stream-model-instance-handler/src/__tests__/schema-utils.test.ts b/packages/stream-model-instance-handler/src/__tests__/schema-utils.test.ts deleted file mode 100644 index a8e3b3aa0a..0000000000 --- a/packages/stream-model-instance-handler/src/__tests__/schema-utils.test.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { SchemaValidation } from '../schema-utils.js' -import { ModelDefinition } from '@ceramicnetwork/stream-model' - -const SCHEMA_COMMIT_ID = 'k3y52l7mkcvtg023bt9txegccxe1bah8os3naw5asin3baf3l3t54atn0cuy98yws' - -const MODEL_DEFINITION: ModelDefinition = { - name: 'MyModel', - version: '1.0', - accountRelation: { type: 'list' }, - schema: { - $schema: 'https://json-schema.org/draft/2020-12/schema', - type: 'object', - additionalProperties: false, - properties: { - arrayProperty: { - type: 'array', - items: { - type: 'integer', - }, - minItems: 2, - maxItems: 4, - }, - stringArrayProperty: { - type: 'array', - items: { - type: 'string', - maxLength: 6, - minLength: 2, - }, - }, - stringProperty: { - type: 'string', - maxLength: 8, - minLength: 3, - }, - intProperty: { - type: 'integer', - maximum: 100, - minimum: 2, - }, - floatProperty: { - type: 'number', - maximum: 110, - minimum: 3, - }, - }, - required: [ - 'arrayProperty', - 'stringArrayProperty', - 'stringProperty', - 'intProperty', - 'floatProperty', - ], - }, -} - -const CONTENT_VALID = { - arrayProperty: [0, 2, 3, 4], - stringArrayProperty: ['abcdef'], - stringProperty: 'abcdefgh', - intProperty: 80, - floatProperty: 104, -} - -const CONTENT_NO_REQ_PROPS = {} - -const CONTENT_MINS_NOT_RESPECTED = { - arrayProperty: [0], - stringArrayProperty: ['a'], - stringProperty: 'ab', - intProperty: 1, - floatProperty: 2.9, -} - -const CONTENT_MAXS_NOT_RESPECTED = { - arrayProperty: [0, 2, 3, 4, 5], - stringArrayProperty: ['abcdefg'], - stringProperty: 'abcdefghi', - intProperty: 101, - floatProperty: 115, -} - -const CONTENT_WITH_ADDITIONAL_PROPERTY = { - arrayProperty: [0, 2, 3, 4], - stringArrayProperty: ['abcdef'], - stringProperty: 'abcdefgh', - intProperty: 80, - floatProperty: 104, - additionalProperty: 'I should not be here', -} - -describe('SchemaValidation', () => { - let schemaValidator: SchemaValidation - - beforeAll(async () => { - schemaValidator = new SchemaValidation() - }) - - it('validates content that conforms to schema', () => { - expect(() => { - schemaValidator.validateSchema(CONTENT_VALID, MODEL_DEFINITION.schema, SCHEMA_COMMIT_ID) - }).not.toThrow() - }) - - it('throws when required properties are missing', () => { - expect(() => { - schemaValidator.validateSchema( - CONTENT_NO_REQ_PROPS, - MODEL_DEFINITION.schema, - SCHEMA_COMMIT_ID - ) - }).toThrow( - /data must have required property 'arrayProperty', data must have required property 'stringArrayProperty', data must have required property 'stringProperty', data must have required property 'intProperty', data must have required property 'floatProperty'/ - ) - }) - - it('throws when min values requirements are not respected', () => { - expect(() => { - schemaValidator.validateSchema( - CONTENT_MINS_NOT_RESPECTED, - MODEL_DEFINITION.schema, - SCHEMA_COMMIT_ID - ) - }).toThrow( - /data\/arrayProperty must NOT have fewer than 2 items, data\/stringArrayProperty\/0 must NOT have fewer than 2 characters, data\/stringProperty must NOT have fewer than 3 characters, data\/intProperty must be >= 2, data\/floatProperty must be >= 3/ - ) - }) - - it('throws when max values requirements are not respected', () => { - expect(() => { - schemaValidator.validateSchema( - CONTENT_MAXS_NOT_RESPECTED, - MODEL_DEFINITION.schema, - SCHEMA_COMMIT_ID - ) - }).toThrow( - /data\/arrayProperty must NOT have more than 4 items, data\/stringArrayProperty\/0 must NOT have more than 6 characters, data\/stringProperty must NOT have more than 8 characters, data\/intProperty must be <= 100, data\/floatProperty must be <= 110/ - ) - }) - - it('throws when additional values are given', () => { - expect(() => { - schemaValidator.validateSchema( - CONTENT_WITH_ADDITIONAL_PROPERTY, - MODEL_DEFINITION.schema, - SCHEMA_COMMIT_ID - ) - }).toThrow(/data must NOT have additional properties/) - }) -}) diff --git a/packages/stream-model-instance-handler/src/model-instance-document-handler.ts b/packages/stream-model-instance-handler/src/model-instance-document-handler.ts index 34863ed203..0434d0b5d3 100644 --- a/packages/stream-model-instance-handler/src/model-instance-document-handler.ts +++ b/packages/stream-model-instance-handler/src/model-instance-document-handler.ts @@ -20,7 +20,7 @@ import { UnreachableCaseError, } from '@ceramicnetwork/common' import { StreamID } from '@ceramicnetwork/streamid' -import { SchemaValidation } from './schema-utils.js' +import { SchemaValidation } from 'ajv-threads' import { Model, ModelDefinitionV2 } from '@ceramicnetwork/stream-model' import { applyAnchorCommit } from '@ceramicnetwork/stream-handler-common' import { toString } from 'uint8arrays' @@ -49,8 +49,8 @@ interface ModelInstanceDocumentHeader extends ModelInstanceDocumentMetadata { export class ModelInstanceDocumentHandler implements StreamHandler { private readonly _schemaValidator: SchemaValidation - constructor() { - this._schemaValidator = new SchemaValidation() + constructor(schemaValidator: SchemaValidation) { + this._schemaValidator = schemaValidator } get type(): number { @@ -264,7 +264,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler - - constructor() { - this.validators = new LRUCache(AJV_CACHE_SIZE) - } - - public validateSchema(content: Record, schema: SchemaObject, schemaId: string) { - let validator = this.validators.get(schemaId) - if (!validator) { - validator = buildAjv() - this.validators.set(schemaId, validator) - } - const isValid = validator.validate(schema, content) - - if (!isValid) { - const errorMessages = validator.errorsText() - throw new Error(`Validation Error: ${errorMessages}`) - } - } -} From 3a1e0db6474f04d78aa220130a70c4326d299f95 Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Wed, 6 Mar 2024 09:59:52 -0500 Subject: [PATCH 2/2] feat: Update ajv-threads package to version with worker pool (#3177) This will make schema validation in js-ceramic truly parallel for the first time --- packages/core/package.json | 2 +- packages/core/src/ceramic.ts | 6 +++++- .../src/stream-loading/__tests__/state-manipulator.test.ts | 3 ++- .../core/src/stream-loading/__tests__/stream-loader.test.ts | 3 ++- packages/stream-model-instance-handler/package.json | 2 +- .../src/__tests__/model-instance-document-handler.test.ts | 3 ++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 30f2a54eba..dc008e88b4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -71,7 +71,7 @@ "@stablelib/random": "^1.0.1", "@stablelib/sha256": "^1.0.1", "@stablelib/uuid": "^1.0.1", - "ajv-threads": "^1.0.3", + "ajv-threads": "^1.0.4", "await-semaphore": "^0.1.3", "cartonne": "^3.0.1", "codeco": "^1.1.0", diff --git a/packages/core/src/ceramic.ts b/packages/core/src/ceramic.ts index d809780219..57e29f7f50 100644 --- a/packages/core/src/ceramic.ts +++ b/packages/core/src/ceramic.ts @@ -244,7 +244,10 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { this._ipfs = modules.ipfs - this._schemaValidator = new SchemaValidation() + const numCores = os.cpus().length + // Use number of threads equal to half the available cores for schema validation. Leave the + // other half for signature validation. + this._schemaValidator = new SchemaValidation(Math.max(1, Math.ceil(numCores / 2))) this._streamHandlers = HandlersMap.makeWithDefaultHandlers(this._logger, this._schemaValidator) // This initialization block below has to be redone. @@ -484,6 +487,7 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader { this._logger.warn(`Starting in read-only mode. All write operations will fail`) } + await this._schemaValidator.init() await this.repository.init() await this.dispatcher.init() diff --git a/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts b/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts index ca2fc96529..b27fdd5118 100644 --- a/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts +++ b/packages/core/src/stream-loading/__tests__/state-manipulator.test.ts @@ -62,7 +62,8 @@ describeIfV3('StateManipulator test', () => { const logger = new LoggerProvider().getDiagnosticsLogger() logSyncer = new LogSyncer(dispatcher) - schemaValidator = new SchemaValidation() + schemaValidator = new SchemaValidation(1) + await schemaValidator.init() const handlers = HandlersMap.makeWithDefaultHandlers(logger, schemaValidator) stateManipulator = new StateManipulator(logger, handlers, logSyncer, ceramic) diff --git a/packages/core/src/stream-loading/__tests__/stream-loader.test.ts b/packages/core/src/stream-loading/__tests__/stream-loader.test.ts index 618b3ca6c1..acbdec6a21 100644 --- a/packages/core/src/stream-loading/__tests__/stream-loader.test.ts +++ b/packages/core/src/stream-loading/__tests__/stream-loader.test.ts @@ -85,7 +85,8 @@ describeIfV3('Streamloader', () => { ceramic.anchorService.validator ) - schemaValidator = new SchemaValidation() + schemaValidator = new SchemaValidation(1) + await schemaValidator.init() const handlers = HandlersMap.makeWithDefaultHandlers(logger, schemaValidator) const stateManipulator = new StateManipulator(logger, handlers, logSyncer, ceramic) streamLoader = new StreamLoader( diff --git a/packages/stream-model-instance-handler/package.json b/packages/stream-model-instance-handler/package.json index 719c54c727..3b23369587 100644 --- a/packages/stream-model-instance-handler/package.json +++ b/packages/stream-model-instance-handler/package.json @@ -43,7 +43,7 @@ "@ceramicnetwork/stream-model": "^4.2.0-rc.0", "@ceramicnetwork/stream-model-instance": "^4.3.0-rc.0", "@ceramicnetwork/streamid": "^5.0.0", - "ajv-threads": "^1.0.3", + "ajv-threads": "^1.0.4", "fast-json-patch": "^3.1.0", "least-recent": "^1.0.3", "lodash.clonedeep": "^4.5.0", diff --git a/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts b/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts index b5585d8d07..ff381fefb6 100644 --- a/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts +++ b/packages/stream-model-instance-handler/src/__tests__/model-instance-document-handler.test.ts @@ -423,7 +423,8 @@ describe('ModelInstanceDocumentHandler', () => { let ipfs: IpfsApi beforeAll(async () => { - schemaValidator = new SchemaValidation() + schemaValidator = new SchemaValidation(1) + await schemaValidator.init() const recs: Record = {} ipfs = { dag: {