From 2111d6523ef560fe801fb5785e94b93c5945eddf Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 19 Mar 2024 10:06:59 -0400 Subject: [PATCH 01/12] feat: update how we check immutability --- .../model-instance-document-handler.test.ts | 6 ++-- .../src/model-instance-document-handler.ts | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) 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..2eaeaf72e2 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 @@ -189,6 +189,7 @@ const MODEL_DEFINITION_SET: ModelDefinition = { properties: { one: { type: 'string', minLength: 2 }, two: { type: 'string', minLength: 2 }, + three: { type: 'string', minLength: 2 }, myData: { type: 'integer', maximum: 100, @@ -197,6 +198,7 @@ const MODEL_DEFINITION_SET: ModelDefinition = { }, required: ['myData'], }, + immutableFields: ['three'], } const MODEL_DEFINITION_BLOB: ModelDefinition = { @@ -915,7 +917,7 @@ describe('ModelInstanceDocumentHandler', () => { context.signer, null, { ...DETERMINISTIC_METADATA, model: FAKE_MODEL_SET_ID }, - ['a', 'b'] + ['a', 'b', 'c'] )) as GenesisCommit await ipfs.dag.put(genesisCommit, FAKE_CID_1) @@ -926,7 +928,7 @@ describe('ModelInstanceDocumentHandler', () => { commit: genesisCommit, } - // The deterministic genesis creation works independently of content validation as determinitic commits have no content + // The deterministic genesis creation works independently of content validation as deterministic commits have no content const state = await handler.applyCommit(genesisCommitData, context) const state$ = TestUtils.runningState(state) const doc = new ModelInstanceDocument(state$, context) 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..731f6f1009 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 @@ -24,6 +24,7 @@ import { SchemaValidation } from './schema-utils.js' import { Model, ModelDefinitionV2 } from '@ceramicnetwork/stream-model' import { applyAnchorCommit } from '@ceramicnetwork/stream-handler-common' import { toString } from 'uint8arrays' +import _ from 'lodash' // Hardcoding the model streamtype id to avoid introducing a dependency on the stream-model package const MODEL_STREAM_TYPE_ID = 2 @@ -194,9 +195,9 @@ export class ModelInstanceDocumentHandler implements StreamHandler(metadata.model) - await this._validateContent(context, modelStream, newContent, false, payload) + await this._validateContent(context, modelStream, newContent, false, payload, oldContent) await this._validateUnique( modelStream, metadata as unknown as ModelInstanceDocumentMetadata, @@ -247,7 +248,8 @@ export class ModelInstanceDocumentHandler implements StreamHandler { if ( genesis && @@ -269,7 +271,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler { + async _validateLockedFieldsUpdate( + model: Model, + payload: Payload, + oldContent: any + ): Promise { if (!ModelDefinitionV2.is(model.content)) return const immutableFields = model.content.immutableFields const hasImmutableFields = immutableFields && immutableFields.length > 0 if (!hasImmutableFields) return + const newContent = jsonpatch.applyPatch( + oldContent, + payload.data as any, + undefined, + false + ).newDocument for (const lockedField of immutableFields) { - const mutated = payload.data.some( - (entry) => entry.path.slice(1).split('/').shift() === lockedField - ) + const mutated = + JSON.stringify(newContent[lockedField]) !== JSON.stringify(oldContent[lockedField]) + if (mutated) { throw new Error(`Immutable field "${lockedField}" cannot be updated`) } From 51d75491ce55377d0255c3744f963c6ed68fe07c Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 19 Mar 2024 10:49:39 -0400 Subject: [PATCH 02/12] chore:remove unused library --- .../src/model-instance-document-handler.ts | 1 - 1 file changed, 1 deletion(-) 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 731f6f1009..71372761cb 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 @@ -24,7 +24,6 @@ import { SchemaValidation } from './schema-utils.js' import { Model, ModelDefinitionV2 } from '@ceramicnetwork/stream-model' import { applyAnchorCommit } from '@ceramicnetwork/stream-handler-common' import { toString } from 'uint8arrays' -import _ from 'lodash' // Hardcoding the model streamtype id to avoid introducing a dependency on the stream-model package const MODEL_STREAM_TYPE_ID = 2 From 2e6eea49f52e029f1e8d27108e3a7040937b11ed Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 19 Mar 2024 14:14:52 -0400 Subject: [PATCH 03/12] feat: return on empty oldContent and add tests --- .../model-instance-document-handler.test.ts | 8 ++-- .../src/model-instance-document-handler.ts | 4 +- .../__tests__/model-instance-document.test.ts | 46 +++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) 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 2eaeaf72e2..e07ed68175 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 @@ -850,7 +850,7 @@ describe('ModelInstanceDocumentHandler', () => { expect(state).toMatchSnapshot() }) - it('MIDs with SET account relation validate signed commit fields', async () => { + it.only('MIDs with SET account relation validate signed commit fields', async () => { const genesisCommit = (await ModelInstanceDocument.makeGenesis( context.signer, null, @@ -890,12 +890,12 @@ describe('ModelInstanceDocumentHandler', () => { await expect(handler.applyCommit(signedCommitDataFail, context, state)).rejects.toThrow( 'Unique content fields value does not match metadata. If you are trying to change the value of these fields, this is causing this error: these fields values are not mutable.' ) - + console.log('voy') const signedCommitOK = (await ModelInstanceDocument.makeUpdateCommit( context.signer, doc.commitId, doc.content, - { one: 'foo', two: 'bar', myData: 2 } + { one: 'foo', two: 'bar', three: 'three', myData: 2 } )) as SignedCommitContainer await ipfs.dag.put(signedCommitOK, FAKE_CID_3) @@ -917,7 +917,7 @@ describe('ModelInstanceDocumentHandler', () => { context.signer, null, { ...DETERMINISTIC_METADATA, model: FAKE_MODEL_SET_ID }, - ['a', 'b', 'c'] + ['a', 'b'] )) as GenesisCommit await ipfs.dag.put(genesisCommit, FAKE_CID_1) 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 71372761cb..39492d77d4 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 @@ -366,7 +366,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler 0 - if (!hasImmutableFields) return + if (!hasImmutableFields || Object.keys(oldContent).length === 0) return const newContent = jsonpatch.applyPatch( oldContent, @@ -374,10 +374,10 @@ export class ModelInstanceDocumentHandler implements StreamHandler { let midRelationMetadata: ModelInstanceDocumentMetadataArgs let modelSingle: Model let midSingleMetadata: ModelInstanceDocumentMetadataArgs + let modelSet: Model + let midSetMetadata: ModelInstanceDocumentMetadataArgs beforeAll(async () => { ipfs = await createIPFS() @@ -129,6 +156,8 @@ describe('ModelInstanceDocument API http-client tests', () => { midRelationMetadata = { model: modelWithRelation.id } modelSingle = await Model.create(ceramic, MODEL_DEFINITION_SINGLE) midSingleMetadata = { model: modelSingle.id } + modelSet = await Model.create(ceramic, MODEL_DEFINITION_SET) + midSetMetadata = { model: modelSet.id } await core.index.indexModels([{ streamID: model.id }]) }, 12000) @@ -224,6 +253,23 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.state.log[1].type).toEqual(EventType.DATA) }) + test('Can upsert immutable fields in a set relation model', async () => { + const doc = await ModelInstanceDocument.set( + ceramic, + { controller: ceramic.did!.id, model: modelSet.id }, + ['foo', 'bar'] + ) + + expect(doc.content).toBeNull() + const newContent = { one: 'foo', two: 'bar', three: 'foobar', myData: 1 } + await doc.replace(newContent) + + expect(doc.content).toEqual(newContent) + expect(doc.state.log.length).toEqual(2) + expect(doc.state.log[0].type).toEqual(EventType.INIT) + expect(doc.state.log[1].type).toEqual(EventType.DATA) + }) + test(`Cannot create document with relation that isn't a valid streamid`, async () => { const relationContent = { linkedDoc: 'this is a streamid' } await expect( From bbba30d5bb0ef8a5ae5937d13c374bfc7180f185 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 19 Mar 2024 14:34:32 -0400 Subject: [PATCH 04/12] chore: remove .only from test --- .../__snapshots__/model-instance-document-handler.test.ts.snap | 1 + .../src/__tests__/model-instance-document-handler.test.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/stream-model-instance-handler/src/__tests__/__snapshots__/model-instance-document-handler.test.ts.snap b/packages/stream-model-instance-handler/src/__tests__/__snapshots__/model-instance-document-handler.test.ts.snap index f4e75d2b03..e930b2486a 100644 --- a/packages/stream-model-instance-handler/src/__tests__/__snapshots__/model-instance-document-handler.test.ts.snap +++ b/packages/stream-model-instance-handler/src/__tests__/__snapshots__/model-instance-document-handler.test.ts.snap @@ -6,6 +6,7 @@ exports[`ModelInstanceDocumentHandler MIDs with SET account relation validate si "content": { "myData": 2, "one": "foo", + "three": "three", "two": "bar", }, "log": [ 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 e07ed68175..9ec7c2acc7 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 @@ -850,7 +850,7 @@ describe('ModelInstanceDocumentHandler', () => { expect(state).toMatchSnapshot() }) - it.only('MIDs with SET account relation validate signed commit fields', async () => { + it('MIDs with SET account relation validate signed commit fields', async () => { const genesisCommit = (await ModelInstanceDocument.makeGenesis( context.signer, null, From be5e8266c4078286b5a3f8afff8c0fac26b562f5 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 20 Mar 2024 07:54:35 -0400 Subject: [PATCH 05/12] chore: remove console.log --- .../src/__tests__/model-instance-document-handler.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9ec7c2acc7..aed413d5bf 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 @@ -890,7 +890,7 @@ describe('ModelInstanceDocumentHandler', () => { await expect(handler.applyCommit(signedCommitDataFail, context, state)).rejects.toThrow( 'Unique content fields value does not match metadata. If you are trying to change the value of these fields, this is causing this error: these fields values are not mutable.' ) - console.log('voy') + const signedCommitOK = (await ModelInstanceDocument.makeUpdateCommit( context.signer, doc.commitId, From 2d3abf92a249cff712a0637376201a39b99d98d7 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 20 Mar 2024 07:59:35 -0400 Subject: [PATCH 06/12] refactor: bypass check if oldContent is empty --- .../src/model-instance-document-handler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 39492d77d4..4ed7e6dc71 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 @@ -269,7 +269,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler 0) { await this._validateLockedFieldsUpdate(model, payload, oldContent) } } @@ -366,7 +366,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler 0 - if (!hasImmutableFields || Object.keys(oldContent).length === 0) return + if (!hasImmutableFields) return const newContent = jsonpatch.applyPatch( oldContent, From 1d4e6d8f1e5fa8948676cf206a19835fac6676ee Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 10:15:35 -0400 Subject: [PATCH 07/12] refactor: immutability check --- .../src/model-instance-document-handler.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) 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 4ed7e6dc71..52b3775018 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 @@ -196,7 +196,10 @@ export class ModelInstanceDocumentHandler implements StreamHandler(metadata.model) - await this._validateContent(context, modelStream, newContent, false, payload, oldContent) + const isSetType = modelStream.content.accountRelation.type === 'set' + const isFirstDataCommit = !state.log.some(c => c.type === EventType.DATA) + + await this._validateContent(context, modelStream, newContent, false, payload, isSetType && isFirstDataCommit) await this._validateUnique( modelStream, metadata as unknown as ModelInstanceDocumentMetadata, @@ -248,7 +251,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler { if ( genesis && @@ -269,8 +272,8 @@ export class ModelInstanceDocumentHandler implements StreamHandler 0) { - await this._validateLockedFieldsUpdate(model, payload, oldContent) + if (!genesis && payload && !hasContent) { + await this._validateLockedFieldsUpdate(model, payload) } } @@ -360,24 +363,17 @@ export class ModelInstanceDocumentHandler implements StreamHandler { if (!ModelDefinitionV2.is(model.content)) return const immutableFields = model.content.immutableFields const hasImmutableFields = immutableFields && immutableFields.length > 0 if (!hasImmutableFields) return - const newContent = jsonpatch.applyPatch( - oldContent, - payload.data as any, - undefined, - false - ).newDocument - for (const lockedField of immutableFields) { - const mutated = - JSON.stringify(newContent[lockedField]) !== JSON.stringify(oldContent[lockedField]) + const mutated = payload.data.some( + (entry) => entry.path.slice(1).split('/').shift() === lockedField + ) if (mutated) { throw new Error(`Immutable field "${lockedField}" cannot be updated`) } From 69e6f522e8793cdcaf8d264a8d0a53e89d558b4a Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 10:18:43 -0400 Subject: [PATCH 08/12] chore: lint run --- .../src/model-instance-document-handler.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 52b3775018..a5eff45319 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 @@ -197,9 +197,16 @@ export class ModelInstanceDocumentHandler implements StreamHandler(metadata.model) const isSetType = modelStream.content.accountRelation.type === 'set' - const isFirstDataCommit = !state.log.some(c => c.type === EventType.DATA) + const isFirstDataCommit = !state.log.some((c) => c.type === EventType.DATA) - await this._validateContent(context, modelStream, newContent, false, payload, isSetType && isFirstDataCommit) + await this._validateContent( + context, + modelStream, + newContent, + false, + payload, + isSetType && isFirstDataCommit + ) await this._validateUnique( modelStream, metadata as unknown as ModelInstanceDocumentMetadata, @@ -361,10 +368,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler { + async _validateLockedFieldsUpdate(model: Model, payload: Payload): Promise { if (!ModelDefinitionV2.is(model.content)) return const immutableFields = model.content.immutableFields const hasImmutableFields = immutableFields && immutableFields.length > 0 From b3198dec0ddde79d61f7e1aa4f2457a82c31f559 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 10:43:17 -0400 Subject: [PATCH 09/12] feat: include single type check --- .../src/model-instance-document-handler.ts | 5 +++-- .../src/__tests__/model-instance-document.test.ts | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) 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 a5eff45319..62582873eb 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 @@ -161,6 +161,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler, context: StreamReaderWriter ): Promise { + const deterministicTypes = ['set', 'single'] // Retrieve the payload const payload = commitData.commit StreamUtils.assertCommitLinksToState(state, payload) @@ -196,7 +197,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler(metadata.model) - const isSetType = modelStream.content.accountRelation.type === 'set' + const isDetType = deterministicTypes.includes(modelStream.content.accountRelation.type) const isFirstDataCommit = !state.log.some((c) => c.type === EventType.DATA) await this._validateContent( @@ -205,7 +206,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler { expect(doc.state.log[1].type).toEqual(EventType.DATA) }) - test('Can upsert immutable fields in a set relation model', async () => { + test('Can upsert immutable fields in a set/single relation model', async () => { + // set const doc = await ModelInstanceDocument.set( ceramic, { controller: ceramic.did!.id, model: modelSet.id }, @@ -268,6 +271,16 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.state.log.length).toEqual(2) expect(doc.state.log[0].type).toEqual(EventType.INIT) expect(doc.state.log[1].type).toEqual(EventType.DATA) + // single + const singleDoc = await ModelInstanceDocument.single(ceramic, midSingleMetadata) + expect(singleDoc.content).toBeNull() + const singleNewContent = { one: 'foo', myData: 1 } + await singleDoc.replace(singleNewContent) + + expect(singleDoc.content).toEqual(singleNewContent) + expect(singleDoc.state.log.length).toEqual(2) + expect(singleDoc.state.log[0].type).toEqual(EventType.INIT) + expect(singleDoc.state.log[1].type).toEqual(EventType.DATA) }) test(`Cannot create document with relation that isn't a valid streamid`, async () => { From 002970790d109e439103de2c8d22c1483082e5b8 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 11:25:08 -0400 Subject: [PATCH 10/12] chore: add documentation for parameter --- .../src/model-instance-document-handler.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 62582873eb..9db373e500 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 @@ -195,7 +195,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler(metadata.model) const isDetType = deterministicTypes.includes(modelStream.content.accountRelation.type) const isFirstDataCommit = !state.log.some((c) => c.type === EventType.DATA) @@ -249,8 +249,9 @@ export class ModelInstanceDocumentHandler implements StreamHandler { if ( genesis && @@ -280,7 +281,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler Date: Thu, 21 Mar 2024 12:02:48 -0400 Subject: [PATCH 11/12] feat: add more tests --- .../__tests__/model-instance-document.test.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 024ffc2adf..298a0a8994 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -39,8 +39,10 @@ const MODEL_DEFINITION: ModelDefinition = { } const MODEL_DEFINITION_SINGLE: ModelDefinition = { - name: 'MySingleModel', - version: '1.0', + name: 'MyModel', + version: '2.0', + interface: false, + implements: [], accountRelation: { type: 'single' }, schema: { $schema: 'https://json-schema.org/draft/2020-12/schema', @@ -50,7 +52,7 @@ const MODEL_DEFINITION_SINGLE: ModelDefinition = { one: { type: 'string', minLength: 2 }, myData: { type: 'integer', - maximum: 10000, + maximum: 100, minimum: 0, }, }, @@ -125,7 +127,6 @@ describe('ModelInstanceDocument API http-client tests', () => { let modelSingle: Model let midSingleMetadata: ModelInstanceDocumentMetadataArgs let modelSet: Model - let midSetMetadata: ModelInstanceDocumentMetadataArgs beforeAll(async () => { ipfs = await createIPFS() @@ -159,7 +160,6 @@ describe('ModelInstanceDocument API http-client tests', () => { modelSingle = await Model.create(ceramic, MODEL_DEFINITION_SINGLE) midSingleMetadata = { model: modelSingle.id } modelSet = await Model.create(ceramic, MODEL_DEFINITION_SET) - midSetMetadata = { model: modelSet.id } await core.index.indexModels([{ streamID: model.id }]) }, 12000) @@ -271,6 +271,13 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.state.log.length).toEqual(2) expect(doc.state.log[0].type).toEqual(EventType.INIT) expect(doc.state.log[1].type).toEqual(EventType.DATA) + + //second update + newContent.three = 'barfoo' + await expect(doc.replace(newContent)).rejects.toThrow( + new RegExp(`.*Immutable field \\\\\\"three\\\\\\" cannot be updated.*`) + ) + // single const singleDoc = await ModelInstanceDocument.single(ceramic, midSingleMetadata) expect(singleDoc.content).toBeNull() @@ -281,6 +288,12 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(singleDoc.state.log.length).toEqual(2) expect(singleDoc.state.log[0].type).toEqual(EventType.INIT) expect(singleDoc.state.log[1].type).toEqual(EventType.DATA) + + //second update + singleNewContent.one = 'barfoo' + await expect(singleDoc.replace(singleNewContent)).rejects.toThrow( + new RegExp(`.*Immutable field \\\\\\"one\\\\\\" cannot be updated.*`) + ) }) test(`Cannot create document with relation that isn't a valid streamid`, async () => { From 005b45b715bbef60038e6ae21c06809042342b92 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 15:18:11 -0400 Subject: [PATCH 12/12] chore: rename param --- .../src/model-instance-document-handler.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 9db373e500..f2a11fd9f6 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 @@ -251,7 +251,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler { if ( genesis && @@ -281,7 +281,7 @@ export class ModelInstanceDocumentHandler implements StreamHandler