@casual-simulation/aux-runtime 3.3.12 → 3.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10986,6 +10986,562 @@ export interface SendNotificationOptions extends RecordActionOptions {
10986
10986
  topic?: string;
10987
10987
  }
10988
10988
 
10989
+
10990
+ /**
10991
+ * Defines an interface for objects that are able to synchronize data between multiple clients.
10992
+ */
10993
+ export interface SharedDocument extends SubscriptionLike {
10994
+ /**
10995
+ * The name of the record that the document is stored under.
10996
+ * If null, then the document is public.
10997
+ */
10998
+ recordName: string | null;
10999
+
11000
+ /**
11001
+ * The address of the document.
11002
+ * If null, then the document is stored locally.
11003
+ */
11004
+ address: string | null;
11005
+
11006
+ /**
11007
+ * The branch that was loaded for the document.
11008
+ */
11009
+ branch: string;
11010
+
11011
+ /**
11012
+ * The ID of the remote client that the document is associated with.
11013
+ */
11014
+ clientId: number;
11015
+
11016
+ /**
11017
+ * Gets an observable list that resolves whenever the partition state version is updated.
11018
+ */
11019
+ onVersionUpdated: Observable<CurrentVersion>;
11020
+
11021
+ /**
11022
+ * Gets an observable list of errors from the partition.
11023
+ * That is, errors that the client cannot handle.
11024
+ */
11025
+ onError: Observable<any>;
11026
+
11027
+ /**
11028
+ * Gets the observable list of remote events from the partition.
11029
+ */
11030
+ onEvents: Observable<Action[]>;
11031
+
11032
+ /**
11033
+ * Gets the observable list of status updates from the partition.
11034
+ */
11035
+ onStatusUpdated: Observable<StatusUpdate>;
11036
+
11037
+ /**
11038
+ * Gets the observable list of client errors from the document.
11039
+ * That is, errors that were caused by the client's behavior.
11040
+ */
11041
+ onClientError: Observable<ClientError>;
11042
+
11043
+ /**
11044
+ * Tells the document to connect to its backing store.
11045
+ */
11046
+ connect(): void;
11047
+
11048
+ /**
11049
+ * Gets a top-level map that can be used to store key/value data.
11050
+ * @param name The name of the map.
11051
+ */
11052
+ getMap<T = any>(name: string): SharedMap<T>;
11053
+
11054
+ /**
11055
+ * Gets a top-level array that can be used to store a list of items.
11056
+ * @param name The name of the array.
11057
+ */
11058
+ getArray<T = any>(name: string): SharedArray<T>;
11059
+
11060
+ /**
11061
+ * Gets a top-level text object that can be used to store rich text.
11062
+ * @param name The name of the text.
11063
+ */
11064
+ getText(name: string): SharedText;
11065
+
11066
+ /**
11067
+ * Creates a new map that can be shared between multiple clients.
11068
+ */
11069
+ createMap<T = any>(): SharedMap<T>;
11070
+
11071
+ /**
11072
+ * Creates a new array that can be shared between multiple clients.
11073
+ */
11074
+ createArray<T = any>(): SharedArray<T>;
11075
+
11076
+ /**
11077
+ * Batches changes that occur within the given callback function into a single transaction.
11078
+ * This makes multiple updates more efficient.
11079
+ * @param callback The function to execute.
11080
+ */
11081
+ transact(callback: () => void): void;
11082
+
11083
+ /**
11084
+ * Gets the update that represents the current state of the document.
11085
+ */
11086
+ getStateUpdate(): InstUpdate;
11087
+
11088
+ /**
11089
+ * Applies the given updates to the document.
11090
+ * @param updates The updates to apply.
11091
+ */
11092
+ applyStateUpdates(updates: InstUpdate[]): void;
11093
+ }
11094
+
11095
+ export type SharedType = SharedMap | SharedArray | SharedText;
11096
+
11097
+ export type SharedTypeChanges =
11098
+ | SharedMapChanges<any>
11099
+ | SharedArrayChanges<any>
11100
+ | SharedTextChanges;
11101
+
11102
+ export interface SharedTypeBase {
11103
+ /**
11104
+ * The document that the map is associated with.
11105
+ */
11106
+ readonly doc: SharedDocument;
11107
+
11108
+ /**
11109
+ * The type that this map is stored in.
11110
+ */
11111
+ readonly parent: SharedType | null;
11112
+ }
11113
+
11114
+ /**
11115
+ * Defines a map that can be shared between multiple clients.
11116
+ */
11117
+ export interface SharedMap<T = any> extends SharedTypeBase {
11118
+ /**
11119
+ * Gets the number of keys that are in the map.
11120
+ */
11121
+ readonly size: number;
11122
+
11123
+ /**
11124
+ * Sets the given key to the given value.
11125
+ * @param key The key to set.
11126
+ * @param value The value to set.
11127
+ */
11128
+ set(key: string, value: T): void;
11129
+
11130
+ /**
11131
+ * Gets the value for the given key.
11132
+ * @param key The key to get.
11133
+ */
11134
+ get(key: string): T;
11135
+
11136
+ /**
11137
+ * Deletes the given key from the map.
11138
+ * @param key Deletes the given key.
11139
+ */
11140
+ delete(key: string): void;
11141
+
11142
+ /**
11143
+ * Determines if the given key exists in the map.
11144
+ * @param key The key.
11145
+ */
11146
+ has(key: string): boolean;
11147
+
11148
+ /**
11149
+ * Clears the map.
11150
+ */
11151
+ clear(): void;
11152
+
11153
+ /**
11154
+ * Creates a new map that is a clone of this map.
11155
+ */
11156
+ clone(): SharedMap;
11157
+
11158
+ /**
11159
+ * Transforms this map into an object that can be serialized to JSON.
11160
+ */
11161
+ toJSON(): { [key: string]: T };
11162
+
11163
+ /**
11164
+ * Execute the provided function once on every key/value pair.
11165
+ * @param callback The function to execute.
11166
+ */
11167
+ forEach(callback: (value: T, key: string, map: SharedMap<T>) => void): void;
11168
+
11169
+ /**
11170
+ * Gets an iterator for the key/value pairs stored in the map.
11171
+ */
11172
+ [Symbol.iterator](): IterableIterator<[string, T]>;
11173
+
11174
+ /**
11175
+ * Gets an iterator for the key/value pairs stored in the map.
11176
+ */
11177
+ entries(): IterableIterator<[string, T]>;
11178
+
11179
+ /**
11180
+ * Gets an iterator for the keys stored in the map.
11181
+ */
11182
+ keys(): IterableIterator<string>;
11183
+
11184
+ /**
11185
+ * Gets an iterator for the values stored in the map.
11186
+ */
11187
+ values(): IterableIterator<T>;
11188
+
11189
+ /**
11190
+ * Gets an observable that resolves whenever the map is changed.
11191
+ */
11192
+ readonly changes: Observable<SharedMapChanges<T>>;
11193
+
11194
+ /**
11195
+ * Gets an observable that resolves whenever this map or any children are changed.
11196
+ */
11197
+ readonly deepChanges: Observable<SharedTypeChanges[]>;
11198
+ }
11199
+
11200
+ /**
11201
+ * Defines an array that can be shared between multiple clients.
11202
+ */
11203
+ export interface SharedArray<T = any> extends SharedTypeBase {
11204
+ /**
11205
+ * Gets the number of elements in the array.
11206
+ */
11207
+ readonly length: number;
11208
+
11209
+ /**
11210
+ * Gets the number of elements in the array.
11211
+ */
11212
+ readonly size: number;
11213
+
11214
+ /**
11215
+ * Insert items at the given index.
11216
+ * @param index The index to insert the items at. Items at or after this index will be pushed back to make space for the new items. If the index is greater than the length of the array, then the items are appended to the end of the array.
11217
+ * @param items The items to insert.
11218
+ */
11219
+ insert(index: number, items: T[]): void;
11220
+
11221
+ /**
11222
+ * Deletes the given number of items, starting at the given index.
11223
+ * @param index The index of the first item to be deleted.
11224
+ * @param count The number of items to delete.
11225
+ */
11226
+ delete(index: number, count: number): void;
11227
+
11228
+ /**
11229
+ * Applies the given delta to the array.
11230
+ * @param delta The delta to apply.
11231
+ */
11232
+ applyDelta(delta: SharedArrayDelta<T>): void;
11233
+
11234
+ /**
11235
+ * Append items to the end of the array.
11236
+ * @param items The items to add.
11237
+ */
11238
+ push(...items: T[]): void;
11239
+
11240
+ /**
11241
+ * Removes the last item from the array and returns it.
11242
+ */
11243
+ pop(): T | undefined;
11244
+
11245
+ /**
11246
+ * Prepend items to the beginning of the array.
11247
+ * @param items The items to add.
11248
+ */
11249
+ unshift(...items: T[]): void;
11250
+
11251
+ /**
11252
+ * Removes the first item from the array and returns it.
11253
+ */
11254
+ shift(): T | undefined;
11255
+
11256
+ /**
11257
+ * Gets the item at the given index.
11258
+ * @param index The index to get.
11259
+ */
11260
+ get(index: number): T;
11261
+
11262
+ /**
11263
+ * Gets a range of items from the array.
11264
+ * Negative indexes can be used to start from the end of the array.
11265
+ * @param start The index of the first item to retrieve.
11266
+ * @param end The index of the last item to retrieve.
11267
+ */
11268
+ slice(start?: number, end?: number): T[];
11269
+
11270
+ /**
11271
+ * Changes the contents of the array by removing or replacing existing elements and/or adding new elements.
11272
+ * Returns a JavaScript array containing the removed elements.
11273
+ * @param start The index at which to start changing the array.
11274
+ * @param deleteCount The number of elements in the array to remove from start.
11275
+ * @param items The elements to add to the array.
11276
+ */
11277
+ splice(start: number, deleteCount: number, ...items: T[]): T[];
11278
+
11279
+ /**
11280
+ * Creates a new JavaScript array that is a clone of this array.
11281
+ */
11282
+ toArray(): T[];
11283
+
11284
+ /**
11285
+ * Transforms this map into an array that can be serialized to JSON.
11286
+ */
11287
+ toJSON(): T[];
11288
+
11289
+ /**
11290
+ * Execute the given callback function for each item in the array.
11291
+ * @param callback The function to execute.
11292
+ */
11293
+ forEach(
11294
+ callback: (value: T, index: number, array: SharedArray<T>) => void
11295
+ ): void;
11296
+
11297
+ /**
11298
+ * Creates a new JavaScript array with the results of calling a provided function on every element in this array.
11299
+ * @param callback The function to execute.
11300
+ */
11301
+ map(callback: (value: T, index: number, array: SharedArray<T>) => T): T[];
11302
+
11303
+ /**
11304
+ * Creates a new JavaScript array with all elements that pass the test implemented by the provided function.
11305
+ * @param predicate The function to execute.
11306
+ */
11307
+ filter(
11308
+ predicate: (value: T, index: number, array: SharedArray<T>) => boolean
11309
+ ): T[];
11310
+
11311
+ /**
11312
+ * Gets an iterator for the items in the array.
11313
+ */
11314
+ [Symbol.iterator](): IterableIterator<T>;
11315
+
11316
+ /**
11317
+ * Creates a new shared array that is a clone of this array.
11318
+ */
11319
+ clone(): SharedArray<T>;
11320
+
11321
+ /**
11322
+ * Gets an observable that resolves whenever the array is changed.
11323
+ */
11324
+ readonly changes: Observable<SharedArrayChanges<T>>;
11325
+
11326
+ /**
11327
+ * Gets an observable that resolves whenever this array or any children are changed.
11328
+ */
11329
+ readonly deepChanges: Observable<SharedTypeChanges[]>;
11330
+ }
11331
+
11332
+ /**
11333
+ * Defines an object that represents rich text that can be shared between multiple clients.
11334
+ */
11335
+ export interface SharedText extends SharedTypeBase {
11336
+ /**
11337
+ * Gets the length of the string in UTF-16 code units.
11338
+ */
11339
+ readonly length: number;
11340
+
11341
+ /**
11342
+ * Insert text at the given index.
11343
+ * Optionally apply formatting to the inserted text.
11344
+ * @param index The index to insert the text at.
11345
+ * @param text The text to insert.
11346
+ * @param attribtues The formatting attributes to apply to the inserted text.
11347
+ */
11348
+ insert(index: number, text: string, attribtues?: Record<string, any>): void;
11349
+
11350
+ /**
11351
+ * Deletes the given number of items, starting at the given index.
11352
+ * @param index The index of the first item to be deleted.
11353
+ * @param count The number of items to delete.
11354
+ */
11355
+ delete(index: number, count: number): void;
11356
+
11357
+ /**
11358
+ * Applies the given delta to the text.
11359
+ * @param delta The delta to apply.
11360
+ */
11361
+ applyDelta(delta: SharedTextDelta): void;
11362
+
11363
+ /**
11364
+ * Converts this text into a delta that can be applied to another text object.
11365
+ */
11366
+ toDelta(): SharedTextDelta;
11367
+
11368
+ /**
11369
+ * Creates a relative position that is fixed to the code point at the given index.
11370
+ * @param index The index of the character to create the relative position for.
11371
+ * @param assoc The association of the relative position to the character. < 0 is before, >= 0 is after.
11372
+ */
11373
+ encodeRelativePosition(index: number, assoc?: number): RelativePosition;
11374
+
11375
+ /**
11376
+ * Gets the index that the given relative position is associated with.
11377
+ * @param position The relative position to decode.
11378
+ */
11379
+ decodeRelativePosition(position: RelativePosition): number;
11380
+
11381
+ /**
11382
+ * Gets a range of text from this object.
11383
+ * Negative indexes can be used to start from the end of the string.
11384
+ * @param start The index of the first code point to retrieve.
11385
+ * @param end The index of the last code point to retrieve.
11386
+ */
11387
+ slice(start?: number, end?: number): string;
11388
+
11389
+ /**
11390
+ * Creates a new JavaScript string that is a clone of this text.
11391
+ */
11392
+ toString(): string;
11393
+
11394
+ /**
11395
+ * Transforms this text into a string that can be serialized to JSON.
11396
+ */
11397
+ toJSON(): string;
11398
+
11399
+ /**
11400
+ * Creates a new shared array that is a clone of this array.
11401
+ */
11402
+ clone(): SharedText;
11403
+
11404
+ /**
11405
+ * Gets an observable that resolves whenever the array is changed.
11406
+ */
11407
+ readonly changes: Observable<SharedTextChanges>;
11408
+
11409
+ /**
11410
+ * Gets an observable that resolves whenever this array or any children are changed.
11411
+ */
11412
+ readonly deepChanges: Observable<SharedTextChanges[]>;
11413
+ }
11414
+
11415
+ export interface SharedMapChanges<T> {
11416
+ type: 'map';
11417
+
11418
+ /**
11419
+ * The map that was changed.
11420
+ */
11421
+ target: SharedMap<T>;
11422
+
11423
+ /**
11424
+ * The keys that were changed, along with their old values.
11425
+ */
11426
+ changes: Map<string, SharedMapChange<T>>;
11427
+ }
11428
+
11429
+ export interface SharedMapChange<T> {
11430
+ /**
11431
+ * The action that caused this change.
11432
+ */
11433
+ action: 'add' | 'update' | 'delete';
11434
+
11435
+ /**
11436
+ * The old value of the key.
11437
+ */
11438
+ oldValue: T | undefined;
11439
+ }
11440
+
11441
+ export interface SharedArrayChanges<T> {
11442
+ type: 'array';
11443
+
11444
+ /**
11445
+ * The array that was changed.
11446
+ */
11447
+ target: SharedArray<T>;
11448
+
11449
+ /**
11450
+ * The changes that were made to the array.
11451
+ */
11452
+ delta: SharedArrayDelta<T>;
11453
+ }
11454
+
11455
+ export type SharedArrayDelta<T> = SharedArrayOp<T>[];
11456
+
11457
+ export type SharedArrayOp<T> =
11458
+ | SharedArrayPreserveOp
11459
+ | SharedArrayInsertOp<T>
11460
+ | SharedArrayDeleteOp<T>;
11461
+
11462
+ export interface SharedArrayPreserveOp {
11463
+ type: 'preserve';
11464
+
11465
+ /**
11466
+ * The number of items that were preserved.
11467
+ */
11468
+ count: number;
11469
+ }
11470
+
11471
+ export interface SharedArrayInsertOp<T> {
11472
+ type: 'insert';
11473
+
11474
+ /**
11475
+ * The values that were inserted.
11476
+ */
11477
+ values: T[];
11478
+ }
11479
+
11480
+ export interface SharedArrayDeleteOp<T> {
11481
+ type: 'delete';
11482
+
11483
+ /**
11484
+ * The number of items that were deleted.
11485
+ */
11486
+ count: number;
11487
+ }
11488
+
11489
+ export interface SharedTextChanges {
11490
+ type: 'text';
11491
+
11492
+ /**
11493
+ * The text that was changed.
11494
+ */
11495
+ target: SharedText;
11496
+
11497
+ /**
11498
+ * The changes that were made to the array.
11499
+ */
11500
+ delta: SharedTextDelta;
11501
+ }
11502
+
11503
+ export type SharedTextDelta = SharedTextOp[];
11504
+
11505
+ export type SharedTextOp =
11506
+ | SharedTextPreserveOp
11507
+ | SharedTextInsertOp
11508
+ | SharedTextDeleteOp;
11509
+
11510
+ export interface SharedTextPreserveOp {
11511
+ type: 'preserve';
11512
+
11513
+ /**
11514
+ * The number of characters that were preserved.
11515
+ */
11516
+ count: number;
11517
+ }
11518
+
11519
+ export interface SharedTextInsertOp {
11520
+ type: 'insert';
11521
+
11522
+ /**
11523
+ * The text that was inserted.
11524
+ */
11525
+ text: string;
11526
+
11527
+ /**
11528
+ * The formatting that was applied to the inserted text.
11529
+ */
11530
+ attributes: Record<string, any>;
11531
+ }
11532
+
11533
+ export interface SharedTextDeleteOp {
11534
+ type: 'delete';
11535
+
11536
+ /**
11537
+ * The number of items that were deleted.
11538
+ */
11539
+ count: number;
11540
+ }
11541
+
11542
+ export interface RelativePosition {}
11543
+
11544
+
10989
11545
  interface Ai {
10990
11546
  /**
10991
11547
  * Sends a chat message to the AI.
@@ -13621,6 +14177,33 @@ interface Os {
13621
14177
  */
13622
14178
  remoteCount(inst?: string): Promise<number>;
13623
14179
 
14180
+ /**
14181
+ * Gets a shared document record from this inst by its name.
14182
+ *
14183
+ * Shared documents are a way to share data across insts in a easy and secure manner.
14184
+ *
14185
+ * Returns a promise that resolves with the shared document.
14186
+ *
14187
+ * @param name The name of the shared document.
14188
+ *
14189
+ * @example Get a shared document from the current inst by name.
14190
+ * const sharedDocument = await os.getSharedDocument('myDocument');
14191
+ */
14192
+ getSharedDocument(name: string): Promise<SharedDocument>;
14193
+
14194
+ /**
14195
+ * Gets a shared document record from the given inst by its name.
14196
+ *
14197
+ * Shared documents are a way to share data across insts in a easy and secure manner.
14198
+ *
14199
+ * Returns a promise that resolves with the shared document.
14200
+ * @param recordName The name of the record. If null, then a public inst will be used.
14201
+ * @param inst The name of the inst that the shared document is in.
14202
+ * @param branch The name of the branch that the shared document is in.
14203
+ */
14204
+ getSharedDocument(recordName: string | null, inst: string, name: string): Promise<SharedDocument>;
14205
+ getSharedDocument(recordOrName: string, inst?: string, name?: string): Promise<SharedDocument>;
14206
+
13624
14207
  /**
13625
14208
  * Gets the list of remote IDs that are connected to the inst.
13626
14209
  */