@@ -145,6 +145,23 @@ export declare interface RestObject {
145145 * @returns A promise which, upon success, will be fulfilled with a {@link RestObjectPublishResult} containing information about the published operations. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
146146 */
147147 publish ( op : RestObjectOperation | RestObjectOperation [ ] ) : Promise < RestObjectPublishResult > ;
148+
149+ /**
150+ * Generates an object ID for a create operation. The returned ID, nonce, and initial value
151+ * can be used to construct a {@link RestObjectOperationMapCreateWithObjectId} or
152+ * {@link RestObjectOperationCounterCreateWithObjectId} operation for use with {@link publish}.
153+ *
154+ * Client-generated object IDs enable atomic batch operations with cross-references between
155+ * newly created objects. When publishing a batch of operations using {@link publish}, you
156+ * can reference an object by its pre-computed ID in the same batch - for example, creating
157+ * a map and assigning it to a key in another map in a single atomic publish call.
158+ *
159+ * @param createBody - The create operation body, either a {@link RestObjectOperationMapCreateBody} or {@link RestObjectOperationCounterCreateBody}.
160+ * @returns A promise which, upon success, will be fulfilled with a {@link RestObjectGenerateIdResult}. Upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error.
161+ */
162+ generateObjectId (
163+ createBody : RestObjectOperationMapCreateBody | RestObjectOperationCounterCreateBody ,
164+ ) : Promise < RestObjectGenerateIdResult > ;
148165}
149166
150167/**
@@ -252,44 +269,58 @@ export type PublishObjectData =
252269 /** Not applicable. */ json ?: never ;
253270 } ;
254271
272+ /**
273+ * The map creation payload, specifying the semantics and initial entries for a new map object.
274+ * Used as the body of {@link RestObjectOperationMapCreate} and as input to {@link RestObject.generateObjectId}.
275+ */
276+ export interface RestObjectOperationMapCreateBody {
277+ /** The map creation parameters. */
278+ mapCreate : {
279+ /** The conflict-resolution semantics for the map. */
280+ semantics : Exclude < ObjectsMapSemantics , ObjectsMapSemanticsNamespace . UNKNOWN > ;
281+ /** Initial key-value pairs for the map. */
282+ entries : Record <
283+ string ,
284+ {
285+ /**
286+ * The initial value for this key, which is either a primitive value or the ID of another LiveObject.
287+ */
288+ data : PublishObjectData ;
289+ }
290+ > ;
291+ } ;
292+ }
293+
255294/**
256295 * Operation to create a new map object at the specified path with initial entries.
257296 */
258297export type RestObjectOperationMapCreate = RestObjectOperationBase &
259- Partial < TargetByPath > & {
260- /** The map creation parameters. */
261- mapCreate : {
262- /** The conflict-resolution semantics for the map. */
263- semantics : Exclude < ObjectsMapSemantics , ObjectsMapSemanticsNamespace . UNKNOWN > ;
264- /** Initial key-value pairs for the map. */
265- entries : Record <
266- string ,
267- {
268- /**
269- * The initial value for this key, which is either a primitive value or the ID of another LiveObject.
270- */
271- data : PublishObjectData ;
272- }
273- > ;
274- } ;
275- } ;
298+ Partial < TargetByPath > &
299+ RestObjectOperationMapCreateBody ;
276300
277301/**
278302 * Operation to create a new map object with a client-generated object ID and initial entries.
303+ * Use {@link RestObject.generateObjectId} to generate the object ID, nonce, and initial value
304+ * needed for this operation.
279305 */
280- export type RestObjectOperationMapCreateWithObjectId = RestObjectOperationBase &
281- TargetByObjectId & {
282- /** The map creation parameters for a pre-computed object ID. */
283- mapCreateWithObjectId : {
284- /**
285- * JSON-encoded string representation of the {@link RestObjectOperationMapCreate.mapCreate} object.
286- * For example: `'{"semantics":"lww","entries":{"name":{"data":{"string":"Alice"}}}}'`.
287- */
288- initialValue : string ;
289- /** Random string used to generate the object ID */
290- nonce : string ;
291- } ;
306+ export type RestObjectOperationMapCreateWithObjectId = RestObjectOperationBase & {
307+ /**
308+ * The object ID for the new map object.
309+ * Use {@link RestObject.generateObjectId} to generate this value along with the matching nonce and initial value.
310+ */
311+ objectId : string ;
312+ /** The map creation parameters for a pre-computed object ID. */
313+ mapCreateWithObjectId : {
314+ /**
315+ * JSON-encoded string representation of the {@link RestObjectOperationMapCreate.mapCreate} object.
316+ * Binary values in entries must be Base64-encoded in this JSON string.
317+ * For example: `'{"semantics":"lww","entries":{"name":{"data":{"string":"Alice"}}}}'`.
318+ */
319+ initialValue : string ;
320+ /** Random string used to generate the object ID. */
321+ nonce : string ;
292322 } ;
323+ } ;
293324
294325/**
295326 * Operation to set a key to a specified value in an existing map object.
@@ -317,34 +348,47 @@ export type RestObjectOperationMapRemove = AnyTargetRestObjectOperationBase & {
317348 } ;
318349} ;
319350
351+ /**
352+ * The counter creation payload, specifying the initial count for a new counter object.
353+ * Used as the body of {@link RestObjectOperationCounterCreate} and as input to {@link RestObject.generateObjectId}.
354+ */
355+ export interface RestObjectOperationCounterCreateBody {
356+ /** The counter creation parameters. */
357+ counterCreate : {
358+ /** The initial value of the counter. */
359+ count : number ;
360+ } ;
361+ }
362+
320363/**
321364 * Operation to create a new counter object at the specified path with an initial count value.
322365 */
323366export type RestObjectOperationCounterCreate = RestObjectOperationBase &
324- Partial < TargetByPath > & {
325- /** The counter creation parameters. */
326- counterCreate : {
327- /** The initial value of the counter. */
328- count : number ;
329- } ;
330- } ;
367+ Partial < TargetByPath > &
368+ RestObjectOperationCounterCreateBody ;
331369
332370/**
333371 * Operation to create a new counter object with a client-generated object ID and an initial count value.
372+ * Use {@link RestObject.generateObjectId} to generate the object ID, nonce, and initial value
373+ * needed for this operation.
334374 */
335- export type RestObjectOperationCounterCreateWithObjectId = RestObjectOperationBase &
336- TargetByObjectId & {
337- /** The counter creation parameters for a pre-computed object ID. */
338- counterCreateWithObjectId : {
339- /**
340- * JSON-encoded string representation of the {@link RestObjectOperationCounterCreate.counterCreate} object.
341- * For example: `'{"counter":0}'`.
342- */
343- initialValue : string ;
344- /** Random string used to generate the object ID */
345- nonce : string ;
346- } ;
375+ export type RestObjectOperationCounterCreateWithObjectId = RestObjectOperationBase & {
376+ /**
377+ * The object ID for the new counter object.
378+ * Use {@link RestObject.generateObjectId} to generate this value along with the matching nonce and initial value.
379+ */
380+ objectId : string ;
381+ /** The counter creation parameters for a pre-computed object ID. */
382+ counterCreateWithObjectId : {
383+ /**
384+ * JSON-encoded string representation of the {@link RestObjectOperationCounterCreate.counterCreate} object.
385+ * For example: `'{"count":0}'`.
386+ */
387+ initialValue : string ;
388+ /** Random string used to generate the object ID. */
389+ nonce : string ;
347390 } ;
391+ } ;
348392
349393/**
350394 * Operation to increment (or decrement with negative values) an existing counter object.
@@ -386,6 +430,20 @@ export interface RestObjectPublishResult {
386430 objectIds : string [ ] ;
387431}
388432
433+ /**
434+ * Result returned by {@link RestObject.generateObjectId}, containing the generated object ID
435+ * and the values needed to construct a {@link RestObjectOperationMapCreateWithObjectId}
436+ * or {@link RestObjectOperationCounterCreateWithObjectId} operation.
437+ */
438+ export interface RestObjectGenerateIdResult {
439+ /** The generated object ID. */
440+ objectId : string ;
441+ /** The nonce used in ID generation. */
442+ nonce : string ;
443+ /** The JSON-encoded initial value used in ID generation. */
444+ initialValue : string ;
445+ }
446+
389447/**
390448 * Request parameters for {@link RestObject.get}.
391449 */
0 commit comments