Skip to content

Commit 617a598

Browse files
committed
fix(sdk): use correct controller during stream creation
1 parent 19cd57b commit 617a598

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

sdk/packages/model-instance-client/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import type { DocumentState, UnknownContent } from './types.js'
2828
export type CreateSingletonParams = {
2929
/** The model's stream ID */
3030
model: StreamID
31-
/** The controller of the stream (DID string or literal string) */
32-
controller: DIDString | string
31+
/** The controller of the stream */
32+
controller: DID
3333
/** A unique value to ensure determinism of the event */
3434
uniqueValue?: Uint8Array
3535
}

sdk/packages/model-instance-client/src/events.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
type EncodedDeterministicInitEventPayload,
1313
type JSONPatchOperation,
1414
} from '@ceramic-sdk/model-instance-protocol'
15-
import type { DIDString } from '@didtools/codecs'
1615
import type { DID } from 'dids'
1716
import type { CID } from 'multiformats/cid'
1817

@@ -57,7 +56,7 @@ export async function createInitEvent<
5756
const { content, controller, ...headerParams } = params
5857
const header = createInitHeader({
5958
...headerParams,
60-
controller: controller.id,
59+
controller,
6160
unique: false, // non-deterministic event
6261
})
6362
return await createSignedInitEvent(controller, content, header)
@@ -77,7 +76,7 @@ export async function createInitEvent<
7776
*/
7877
export function getDeterministicInitEventPayload(
7978
model: StreamID,
80-
controller: DIDString | string,
79+
controller: DID,
8180
uniqueValue?: Uint8Array,
8281
): DeterministicInitEventPayload {
8382
return {
@@ -100,7 +99,7 @@ export function getDeterministicInitEventPayload(
10099
*/
101100
export function getDeterministicInitEvent(
102101
model: StreamID,
103-
controller: DIDString | string,
102+
controller: DID,
104103
uniqueValue?: Uint8Array,
105104
): EncodedDeterministicInitEventPayload {
106105
const { header } = getDeterministicInitEventPayload(

sdk/packages/model-instance-client/src/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
DocumentInitEventHeader,
44
type JSONPatchOperation,
55
} from '@ceramic-sdk/model-instance-protocol'
6-
import { type DIDString, asDIDString } from '@didtools/codecs'
6+
import { asDIDString } from '@didtools/codecs'
7+
import type { DID } from 'dids'
78
import jsonpatch from 'fast-json-patch'
89
import type { CID } from 'multiformats/cid'
910

@@ -38,8 +39,8 @@ export type CreateInitHeaderParams = {
3839
/** CID of specific model version to use when validating this instance.
3940
* When empty the the init commit of the model is used */
4041
modelVersion?: CID
41-
/** The DID string or literal string representing the controller of the document. */
42-
controller: DIDString | string
42+
/** The controller of the document. */
43+
controller: DID
4344
/** A unique value to ensure determinism, or a boolean to indicate uniqueness type. */
4445
unique?: Uint8Array | boolean
4546
/** Optional context for the document. */
@@ -68,8 +69,9 @@ export type CreateInitHeaderParams = {
6869
export function createInitHeader(
6970
params: CreateInitHeaderParams,
7071
): DocumentInitEventHeader {
72+
const did = params.controller.hasParent ? params.controller.parent : params.controller.id
7173
const header: DocumentInitEventHeader = {
72-
controllers: [asDIDString(params.controller)],
74+
controllers: [asDIDString(did)],
7375
model: params.model,
7476
sep: 'model',
7577
}

tests/suite/src/__tests__/correctness/fast/model-mid-singleType.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('model integration test for single model and MID', () => {
7878
})
7979
const documentStream = await modelInstanceClient.createSingleton({
8080
model: modelStream,
81-
controller: authenticatedDID.id,
81+
controller: authenticatedDID,
8282
})
8383

8484
// Use the flightsql stream behavior to ensure the events states have been process before querying their states.
@@ -97,7 +97,7 @@ describe('model integration test for single model and MID', () => {
9797
})
9898
const documentStream = await modelInstanceClient.createSingleton({
9999
model: modelStream,
100-
controller: authenticatedDID.id,
100+
controller: authenticatedDID,
101101
})
102102
// Use the flightsql stream behavior to ensure the events states have been process before querying their states.
103103
await waitForEventState(flightClient, documentStream.commit)
@@ -117,11 +117,11 @@ describe('model integration test for single model and MID', () => {
117117
})
118118
const documentStream1 = await modelInstanceClient.createSingleton({
119119
model: modelStream,
120-
controller: authenticatedDID.id,
120+
controller: authenticatedDID,
121121
})
122122
const documentStream2 = await modelInstanceClient.createSingleton({
123123
model: modelStream,
124-
controller: authenticatedDID.id,
124+
controller: authenticatedDID,
125125
})
126126
expect(documentStream1.baseID).toEqual(documentStream2.baseID)
127127
})
@@ -138,11 +138,11 @@ describe('model integration test for single model and MID', () => {
138138
})
139139
const documentStream1 = await modelInstanceClient1.createSingleton({
140140
model: modelStream,
141-
controller: authenticatedDID1.id,
141+
controller: authenticatedDID1,
142142
})
143143
const documentStream2 = await modelInstanceClient2.createSingleton({
144144
model: modelStream,
145-
controller: authenticatedDID2.id,
145+
controller: authenticatedDID2,
146146
})
147147
expect(documentStream1.baseID).not.toEqual(documentStream2.baseID)
148148
})

0 commit comments

Comments
 (0)