@docx-editor.dev/editor-api 2.27.0 → 2.29.0

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.
@@ -1,4 +1,4 @@
1
- import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, AutomationHost, AutomationCapabilities, AutomationPaginationOptions } from '@docx-editor.dev/core/automation';
1
+ import { AutomationHandle, AutomationSpan, AutomationOperation, AutomationValue, AutomationSpanRef, RevisionBatchResult, RevisionAuthorResult, DiagnosticCode, AutomationHost, AutomationCapabilities, AutomationPaginationOptions, ByteSizeBucket, DocumentOpenDiagnosticCode, DocumentPartKind, DiagnosticErrorName, EditDiagnosticCode } from '@docx-editor.dev/core/automation';
2
2
  import { CollaborationModuleContribution } from '@docx-editor.dev/core/collaboration';
3
3
 
4
4
  /**
@@ -1352,7 +1352,25 @@ declare class Revision extends ModelObject implements PromisedItem {
1352
1352
  /** @internal Plan the read this object's `load(...)` asked for. */
1353
1353
  protected onLoad(request: ResolvedLoadOptions): void;
1354
1354
  /** @internal Capture a batch target without exposing engine identity. */
1355
- static batchHandle(revision: Revision, context: RequestContext): AutomationHandle;
1355
+ static batchHandle(revision: Revision, context: RequestContext, target?: string): AutomationHandle;
1356
+ }
1357
+ /**
1358
+ * Select every change these authors made, for {@link RevisionCollection.setAuthor}.
1359
+ * Matches `w:author` exactly.
1360
+ *
1361
+ * @public
1362
+ */
1363
+ interface RevisionAuthorSelection {
1364
+ readonly authors: readonly string[];
1365
+ }
1366
+ /**
1367
+ * Options for {@link RevisionCollection.setAuthor}.
1368
+ *
1369
+ * @public
1370
+ */
1371
+ interface RevisionAuthorOptions {
1372
+ /** The date to record. Omit it to keep each change's own date. */
1373
+ readonly date?: Date;
1356
1374
  }
1357
1375
  /**
1358
1376
  * The tracked changes on a document, story or range, as of the batch that loaded them.
@@ -1395,6 +1413,23 @@ declare class RevisionCollection extends HandleCollection<Revision> {
1395
1413
  * ```
1396
1414
  */
1397
1415
  resolve(action: 'accept' | 'reject', revisions?: readonly Revision[]): ClientResult<RevisionBatchResult>;
1416
+ /**
1417
+ * Attribute changes in this story to another author. The changes stay pending.
1418
+ *
1419
+ * Pass revision objects to change those changes, or `{ authors }` to change every change
1420
+ * those authors made. Omit the selection to change every change in the story, by every
1421
+ * author, including structural ones absent from `items`. An empty array selects nothing.
1422
+ * Each change keeps its date unless you pass `options.date`. Keep this the only write in
1423
+ * its sync batch. Revision objects you pass stay valid and read the new author after a load.
1424
+ *
1425
+ * @example
1426
+ * ```ts
1427
+ * const result = context.document.revisions.setAuthor('Ada Lovelace', { authors: ['AI'] });
1428
+ * await context.sync();
1429
+ * console.log(result.value.updated.length, result.value.skipped);
1430
+ * ```
1431
+ */
1432
+ setAuthor(author: string, selection?: readonly Revision[] | RevisionAuthorSelection, options?: RevisionAuthorOptions): ClientResult<RevisionAuthorResult>;
1398
1433
  /** @internal The read that answers this collection's members. */
1399
1434
  protected listing(): AutomationOperation;
1400
1435
  /** @internal Build one member from an address the listing answered. */
@@ -1438,10 +1473,12 @@ interface SearchOptions {
1438
1473
  * A range is a SNAPSHOT, not a tracked region. Its endpoints name the paragraphs they were found
1439
1474
  * in and the offsets they were found at, so it stays meaningful across edits ELSEWHERE in the
1440
1475
  * document and becomes an explicit `InvalidObjectPath` refusal once one of its paragraphs is
1441
- * gone. What it deliberately does not do is follow edits INSIDE itself: a range over `"alpha"`
1442
- * whose paragraph then gains a word at offset 0 still names offsets 0..5. Word's own ranges do
1443
- * move, by keeping a live region in the document; this API has none, and pretending otherwise
1444
- * would answer text from a place the caller was not looking at.
1476
+ * gone. What it deliberately does not do is follow edits INSIDE itself: once its paragraph
1477
+ * gains a word at offset 0, a range over `"alpha"` fails with `StaleDocument` when used, rather
1478
+ * than reading or editing whatever now sits at offsets 0..5. Edits after the range, and formatting
1479
+ * changes, keep it valid. Word's own ranges do move, by keeping a live region in the document;
1480
+ * this API has none, and pretending otherwise would answer text from a place the caller was not
1481
+ * looking at.
1445
1482
  *
1446
1483
  * That is also why `start` and `end` are absent rather than unimplemented — they are
1447
1484
  * document-wide character positions, a different addressing scheme from this API's paragraph
@@ -1516,7 +1553,15 @@ declare class Range extends ModelObject implements PromisedItem {
1516
1553
  * gets back is a range naming the text that was written, in every case.
1517
1554
  */
1518
1555
  insertText(text: string, insertLocation: InsertLocation | 'Replace' | 'Start' | 'End' | 'Before' | 'After'): Range;
1519
- /** Delete range content. Tracking supports adjacent sibling paragraphs outside collaboration. */
1556
+ /**
1557
+ * Delete range content.
1558
+ *
1559
+ * With `TrackMineOnly`, text becomes deleted runs and each paragraph mark the range covers
1560
+ * becomes a deleted paragraph mark, also in collaboration. Marks that `Paragraph.delete()`
1561
+ * refuses to strike refuse here with the same codes. A tracked deletion or replacement that
1562
+ * starts a paragraph whose previous mark you already proposed deleting refuses with
1563
+ * `NotImplemented`.
1564
+ */
1520
1565
  delete(): void;
1521
1566
  /** Clear this range's content, preserving the surrounding structure. */
1522
1567
  clear(): void;
@@ -1586,6 +1631,12 @@ declare class Range extends ModelObject implements PromisedItem {
1586
1631
 
1587
1632
  /** Paragraph alignment values readable and writable through this object model. */
1588
1633
  type ParagraphAlignment = Alignment | 'Mixed' | 'Unknown' | 'Left' | 'Centered' | 'Right' | 'Justified';
1634
+ /**
1635
+ * A paragraph's base direction, as {@link Paragraph.readingOrder} reads and writes it.
1636
+ *
1637
+ * @public
1638
+ */
1639
+ type ParagraphReadingOrder = 'LeftToRight' | 'RightToLeft';
1589
1640
  /**
1590
1641
  * One paragraph: what it says, what it is, and the ways it can be changed.
1591
1642
  *
@@ -1645,6 +1696,21 @@ declare class Paragraph extends ModelObject implements PromisedItem {
1645
1696
  */
1646
1697
  get alignment(): ParagraphAlignment;
1647
1698
  set alignment(value: ParagraphAlignment);
1699
+ /**
1700
+ * The direction the paragraph reads in: `LeftToRight` or `RightToLeft`.
1701
+ *
1702
+ * A DocxEditor addition: Office.js has no paragraph direction member. The values follow
1703
+ * `Word.SectionDirection`. The read resolves the paragraph's own `w:bidi`, then its style, its
1704
+ * list level, an enclosing cell's table style, and the document defaults, as the page shows them.
1705
+ *
1706
+ * A write changes nothing when the paragraph already reads that way. Otherwise it removes the
1707
+ * paragraph's own direction when that alone set the other one, or states the asked direction,
1708
+ * which also overrides a style. The write keeps `alignment` as authored: in a right-to-left
1709
+ * paragraph, `Left` and `Right` name the start and end edges. With change tracking on, a write
1710
+ * that changes the direction is recorded as a paragraph formatting revision.
1711
+ */
1712
+ get readingOrder(): ParagraphReadingOrder;
1713
+ set readingOrder(value: ParagraphReadingOrder);
1648
1714
  /** Points. Negative for a hanging indent — the first line starting left of the rest. */
1649
1715
  get firstLineIndent(): number;
1650
1716
  set firstLineIndent(value: number);
@@ -1683,7 +1749,23 @@ declare class Paragraph extends ModelObject implements PromisedItem {
1683
1749
  get listItem(): ListItem;
1684
1750
  /** Empty this paragraph's text, leaving the paragraph itself where it is. */
1685
1751
  clear(): void;
1686
- /** Remove this paragraph and everything in it. */
1752
+ /**
1753
+ * Remove this paragraph and everything in it.
1754
+ *
1755
+ * With `document.changeTrackingMode = 'TrackMineOnly'`, this records a tracked deletion of the
1756
+ * paragraph's text and its paragraph mark. Accepting it removes the paragraph; rejecting it
1757
+ * restores the paragraph.
1758
+ *
1759
+ * A tracked deletion refuses with `NotSupported` for the last paragraph of a story, table
1760
+ * cell, or content control; a paragraph directly before a table or block content control; a
1761
+ * paragraph whose mark ends a section; a paragraph with an inline content control; a
1762
+ * paragraph with a complex field boundary whose matching boundary is in another paragraph;
1763
+ * and a paragraph that nests inline content more than 64 levels deep. It refuses with
1764
+ * `NotImplemented` when the paragraph or the start of the next paragraph has a pending change,
1765
+ * including your own. Delete adjacent paragraphs in one sync:
1766
+ * a later sync beside your own pending deletion refuses, because the two would review as one
1767
+ * decision. A refusal refuses the whole sync.
1768
+ */
1687
1769
  delete(): void;
1688
1770
  /** Write text over this paragraph or at either edge of it. Answers the written text's range. */
1689
1771
  insertText(text: string, insertLocation: InsertLocation.replace | InsertLocation.start | InsertLocation.end | 'Replace' | 'Start' | 'End'): Range;
@@ -2059,6 +2141,186 @@ declare class Document extends ModelObject {
2059
2141
  protected onLoad(request: ResolvedLoadOptions): void;
2060
2142
  }
2061
2143
 
2144
+ /** What went wrong, as a value a consumer may branch on. */
2145
+ type DocxEditorErrorCode =
2146
+ /** A property was read before a `load(...)` for it completed in a `sync()`. */
2147
+ 'PropertyNotLoaded'
2148
+ /** A `ClientResult` value was read before the sync that fills it. */
2149
+ | 'ValueNotLoaded'
2150
+ /**
2151
+ * The object cannot be addressed, in either of the two ways that happens.
2152
+ *
2153
+ * NOT YET: an item accessor answers a proxy the read that names it has not answered for, and it
2154
+ * becomes usable at the next `sync()`. NOT ANY MORE: its run ended and nothing tracked it, which
2155
+ * is terminal. One code because from a consumer's side both are "this object cannot be used
2156
+ * here"; the message says which one, because the fix for one is not the fix for the other.
2157
+ */
2158
+ | 'InvalidObjectPath'
2159
+ /** The object still belongs to a run that has not finished, so it cannot be handed over. */
2160
+ | 'ObjectInUse'
2161
+ /** An argument or load option this API does not accept. */
2162
+ | 'InvalidArgument'
2163
+ /** Opening the document exceeded a bounded reader resource limit. */
2164
+ | 'ResourceLimitExceeded'
2165
+ /** The collection has no such item — `getFirst()` on an empty one. */
2166
+ | 'ItemNotFound'
2167
+ /** The host cannot do this at all — a capability it reports false. */
2168
+ | 'NotSupported'
2169
+ /**
2170
+ * The member exists in this API's shape but this version does not implement it.
2171
+ *
2172
+ * Distinct from `NotSupported`, which is about the HOST: a headless document really has no
2173
+ * caret, and no version of this library will give it one. This code means the library, not the
2174
+ * document, is the limit — so a consumer knows to check the release notes rather than the host.
2175
+ */
2176
+ | 'NotImplemented'
2177
+ /**
2178
+ * Two calls in one batch make claims on the same paragraph that cannot both hold.
2179
+ *
2180
+ * A batch is one transaction planned against the state at its start, which stops being
2181
+ * unambiguous once two calls restructure the same paragraph. Split them across two `sync()`
2182
+ * calls and each gets exactly what it asked for.
2183
+ */
2184
+ | 'ConflictingChanges'
2185
+ /** The request context's `run` has finished, so it can no longer be used. */
2186
+ | 'InvalidRequestContext'
2187
+ /** The runtime was disposed. Every later operation fails this way. */
2188
+ | 'RuntimeDisposed'
2189
+ /**
2190
+ * The request was built from an older read, so nothing was applied: another writer moved the
2191
+ * document, or a range's text moved since the range was read, including by this context's own
2192
+ * earlier sync. Read again before retrying.
2193
+ */
2194
+ | 'StaleDocument'
2195
+ /** The host is live but holds no document right now — an editor between mounts. */
2196
+ | 'DocumentUnavailable'
2197
+ /** The document refused the change, or answered something this runtime cannot use. */
2198
+ | 'GeneralException';
2199
+ /**
2200
+ * The fields a {@link DocxEditorError} is constructed from.
2201
+ *
2202
+ * @public
2203
+ */
2204
+ interface DocxEditorErrorInit {
2205
+ /** Which refusal this is. The stable thing to branch on. */
2206
+ readonly code: DocxEditorErrorCode;
2207
+ /** The resource limit exceeded while opening a document. */
2208
+ readonly limit?: 'zip.maxEntries' | 'zip.maxTotalBytes' | 'zip.maxRatio' | 'xml.maxBytes' | 'xml.maxElements' | 'xml.maxDepth' | 'maxXmlParts' | 'maxRelationships';
2209
+ /**
2210
+ * The consumer-facing path of the object or property involved — `document.body.text`, not a
2211
+ * handle. Omitted when there is nothing to name.
2212
+ */
2213
+ readonly target?: string;
2214
+ /** The revision the context had read at, for `StaleDocument`. */
2215
+ readonly expectedRevision?: number;
2216
+ /** The revision the document was actually at, for `StaleDocument`. */
2217
+ readonly actualRevision?: number;
2218
+ /**
2219
+ * The engine's public diagnostic code for this refusal, when it has one. It becomes
2220
+ * `debugInfo.innerError`.
2221
+ */
2222
+ readonly diagnostic?: DiagnosticCode;
2223
+ }
2224
+ /**
2225
+ * Why the engine refused, as a public diagnostic code with its fixed hint.
2226
+ *
2227
+ * @public
2228
+ */
2229
+ interface DocxEditorInnerError {
2230
+ /** A stable public diagnostic code, such as `edit.tracked-drawing-delete-unsupported`. */
2231
+ readonly code: DiagnosticCode;
2232
+ /** The fixed hint for the code: the cause, then the action. Never document content. */
2233
+ readonly message: string;
2234
+ }
2235
+ /**
2236
+ * Debug details in the shape of Office.js `OfficeExtension.DebugInfo`.
2237
+ *
2238
+ * @public
2239
+ */
2240
+ interface DocxEditorDebugInfo {
2241
+ /** The same code as {@link DocxEditorError.code}. */
2242
+ readonly code: DocxEditorErrorCode;
2243
+ /** The same message as the error's own. */
2244
+ readonly message: string;
2245
+ /** The consumer-facing path of the object or property involved, when there is one. */
2246
+ readonly errorLocation?: string;
2247
+ /**
2248
+ * Why the engine refused, when it knows a specific reason. Handle the outer `code`; read
2249
+ * `innerError.message` to tell a person or a model what to change.
2250
+ */
2251
+ readonly innerError?: DocxEditorInnerError;
2252
+ }
2253
+ /**
2254
+ * Every refusal this runtime throws.
2255
+ *
2256
+ * Branch on {@link DocxEditorError.code}, never on the message. Codes are stable public API —
2257
+ * added rather than repurposed — so a consumer that handles `PropertyNotLoaded` by loading and
2258
+ * syncing again keeps working across versions.
2259
+ *
2260
+ * Nothing from the engine appears in the message. Host rejection reasons, opaque handle refs and
2261
+ * offset ranges are all withheld: a ref in a message is a name a consumer can start depending on,
2262
+ * and a store's rejection reason would become a documented one the moment somebody matched on it.
2263
+ * What a consumer gets instead is a stable code, a fixed sentence, and `target` — the
2264
+ * consumer-facing path they wrote themselves.
2265
+ *
2266
+ * @example
2267
+ * ```ts
2268
+ * try {
2269
+ * await context.sync();
2270
+ * } catch (error) {
2271
+ * if (isDocxEditorError(error) && error.code === 'StaleDocument') {
2272
+ * // Re-read, re-anchor, and reconsider: someone else changed the document first.
2273
+ * }
2274
+ * }
2275
+ * ```
2276
+ *
2277
+ * @public
2278
+ */
2279
+ declare class DocxEditorError extends Error {
2280
+ /** Which refusal this is. Stable across versions; the thing to branch on. */
2281
+ readonly code: DocxEditorErrorCode;
2282
+ /** For `ResourceLimitExceeded`: the resource limit that prevented opening. */
2283
+ readonly limit?: DocxEditorErrorInit['limit'];
2284
+ /** Consumer-facing path of the object or property involved, when there is one to name. */
2285
+ readonly target?: string;
2286
+ /**
2287
+ * For `StaleDocument`: the revision the context had last read at, when the refused batch
2288
+ * wrote. Absent for a batch that only read, on every host.
2289
+ *
2290
+ * When it equals {@link DocxEditorError.actualRevision}, the document is where this context
2291
+ * last saw it, and a range it holds is out of date: an edit after the range was read (often
2292
+ * this context's own earlier sync) moved its text. Search for the text again. When the two
2293
+ * differ, another writer changed the document after this context's last read. Read again
2294
+ * before you decide.
2295
+ */
2296
+ readonly expectedRevision?: number;
2297
+ /** For `StaleDocument`: the revision the document was actually at. */
2298
+ readonly actualRevision?: number;
2299
+ /**
2300
+ * Debug details, as Office.js `OfficeExtension.Error.debugInfo` has them. `innerError` names
2301
+ * the engine's reason with a stable diagnostic code and a fixed hint, when there is one.
2302
+ *
2303
+ * @example
2304
+ * ```ts
2305
+ * catch (error) {
2306
+ * if (isDocxEditorError(error) && error.debugInfo.innerError) {
2307
+ * console.warn(error.debugInfo.innerError.code, error.debugInfo.innerError.message);
2308
+ * }
2309
+ * }
2310
+ * ```
2311
+ */
2312
+ readonly debugInfo: DocxEditorDebugInfo;
2313
+ constructor(init: DocxEditorErrorInit);
2314
+ }
2315
+ /**
2316
+ * Whether a caught value is one of ours.
2317
+ *
2318
+ * By `name` as well as by `instanceof`: a consumer can end up with two copies of this module
2319
+ * (a bundle plus a dependency's), and an `instanceof` that fails across them would send a
2320
+ * perfectly ordinary `PropertyNotLoaded` down a consumer's unexpected-error path.
2321
+ */
2322
+ declare function isDocxEditorError(value: unknown): value is DocxEditorError;
2323
+
2062
2324
  /** What a `run` callback is given, and what it may answer with. */
2063
2325
  type RunCallback<T> = (context: RequestContext) => Promise<T>;
2064
2326
  /** Capabilities exposed by a DocxEditor runtime, frozen for its lifetime. */
@@ -2155,6 +2417,16 @@ interface RuntimeSession {
2155
2417
  readonly author?: string;
2156
2418
  /** Revision view used by standard Office-compatible text reads and searches. */
2157
2419
  readonly revisionTextView: RevisionTextView;
2420
+ /**
2421
+ * Told about each refused batch before it is thrown, with the batch's operations. A listener
2422
+ * that throws is ignored.
2423
+ */
2424
+ readonly onRefusal?: (error: DocxEditorError, operations: readonly AutomationOperation[]) => void;
2425
+ /**
2426
+ * Told about each batch that threw an error other than a refusal, before it propagates: an
2427
+ * engine defect. A listener that throws is ignored.
2428
+ */
2429
+ readonly onException?: (error: unknown, operations: readonly AutomationOperation[]) => void;
2158
2430
  /** Identity for adoption checks. The session object itself. */
2159
2431
  readonly id: object;
2160
2432
  roots(): RootHandles;
@@ -2404,125 +2676,6 @@ declare abstract class ClientObject implements RuntimeManagedObject {
2404
2676
  [REBIND](context: RequestContext): void;
2405
2677
  }
2406
2678
 
2407
- /** What went wrong, as a value a consumer may branch on. */
2408
- type DocxEditorErrorCode =
2409
- /** A property was read before a `load(...)` for it completed in a `sync()`. */
2410
- 'PropertyNotLoaded'
2411
- /** A `ClientResult` value was read before the sync that fills it. */
2412
- | 'ValueNotLoaded'
2413
- /**
2414
- * The object cannot be addressed, in either of the two ways that happens.
2415
- *
2416
- * NOT YET: an item accessor answers a proxy the read that names it has not answered for, and it
2417
- * becomes usable at the next `sync()`. NOT ANY MORE: its run ended and nothing tracked it, which
2418
- * is terminal. One code because from a consumer's side both are "this object cannot be used
2419
- * here"; the message says which one, because the fix for one is not the fix for the other.
2420
- */
2421
- | 'InvalidObjectPath'
2422
- /** The object still belongs to a run that has not finished, so it cannot be handed over. */
2423
- | 'ObjectInUse'
2424
- /** An argument or load option this API does not accept. */
2425
- | 'InvalidArgument'
2426
- /** Opening the document exceeded a bounded reader resource limit. */
2427
- | 'ResourceLimitExceeded'
2428
- /** The collection has no such item — `getFirst()` on an empty one. */
2429
- | 'ItemNotFound'
2430
- /** The host cannot do this at all — a capability it reports false. */
2431
- | 'NotSupported'
2432
- /**
2433
- * The member exists in this API's shape but this version does not implement it.
2434
- *
2435
- * Distinct from `NotSupported`, which is about the HOST: a headless document really has no
2436
- * caret, and no version of this library will give it one. This code means the library, not the
2437
- * document, is the limit — so a consumer knows to check the release notes rather than the host.
2438
- */
2439
- | 'NotImplemented'
2440
- /**
2441
- * Two calls in one batch make claims on the same paragraph that cannot both hold.
2442
- *
2443
- * A batch is one transaction planned against the state at its start, which stops being
2444
- * unambiguous once two calls restructure the same paragraph. Split them across two `sync()`
2445
- * calls and each gets exactly what it asked for.
2446
- */
2447
- | 'ConflictingChanges'
2448
- /** The request context's `run` has finished, so it can no longer be used. */
2449
- | 'InvalidRequestContext'
2450
- /** The runtime was disposed. Every later operation fails this way. */
2451
- | 'RuntimeDisposed'
2452
- /** The document moved under a context that had already read from it; nothing was applied. */
2453
- | 'StaleDocument'
2454
- /** The host is live but holds no document right now — an editor between mounts. */
2455
- | 'DocumentUnavailable'
2456
- /** The document refused the change, or answered something this runtime cannot use. */
2457
- | 'GeneralException';
2458
- /**
2459
- * The fields a {@link DocxEditorError} is constructed from.
2460
- *
2461
- * @public
2462
- */
2463
- interface DocxEditorErrorInit {
2464
- /** Which refusal this is. The stable thing to branch on. */
2465
- readonly code: DocxEditorErrorCode;
2466
- /** The resource limit exceeded while opening a document. */
2467
- readonly limit?: 'zip.maxEntries' | 'zip.maxTotalBytes' | 'zip.maxRatio' | 'xml.maxBytes' | 'xml.maxElements' | 'xml.maxDepth' | 'maxXmlParts' | 'maxRelationships';
2468
- /**
2469
- * The consumer-facing path of the object or property involved — `document.body.text`, not a
2470
- * handle. Omitted when there is nothing to name.
2471
- */
2472
- readonly target?: string;
2473
- /** The revision the context had read at, for `StaleDocument`. */
2474
- readonly expectedRevision?: number;
2475
- /** The revision the document was actually at, for `StaleDocument`. */
2476
- readonly actualRevision?: number;
2477
- }
2478
- /**
2479
- * Every refusal this runtime throws.
2480
- *
2481
- * Branch on {@link DocxEditorError.code}, never on the message. Codes are stable public API —
2482
- * added rather than repurposed — so a consumer that handles `PropertyNotLoaded` by loading and
2483
- * syncing again keeps working across versions.
2484
- *
2485
- * Nothing from the engine appears in the message. Host rejection reasons, opaque handle refs and
2486
- * offset ranges are all withheld: a ref in a message is a name a consumer can start depending on,
2487
- * and a store's rejection reason would become a documented one the moment somebody matched on it.
2488
- * What a consumer gets instead is a stable code, a fixed sentence, and `target` — the
2489
- * consumer-facing path they wrote themselves.
2490
- *
2491
- * @example
2492
- * ```ts
2493
- * try {
2494
- * await context.sync();
2495
- * } catch (error) {
2496
- * if (isDocxEditorError(error) && error.code === 'StaleDocument') {
2497
- * // Re-read, re-anchor, and reconsider: someone else changed the document first.
2498
- * }
2499
- * }
2500
- * ```
2501
- *
2502
- * @public
2503
- */
2504
- declare class DocxEditorError extends Error {
2505
- /** Which refusal this is. Stable across versions; the thing to branch on. */
2506
- readonly code: DocxEditorErrorCode;
2507
- /** For `ResourceLimitExceeded`: the resource limit that prevented opening. */
2508
- readonly limit?: DocxEditorErrorInit['limit'];
2509
- /** Consumer-facing path of the object or property involved, when there is one to name. */
2510
- readonly target?: string;
2511
- /** For `StaleDocument`: the revision the context had read at. */
2512
- readonly expectedRevision?: number;
2513
- /** For `StaleDocument`: the revision the document was actually at. */
2514
- readonly actualRevision?: number;
2515
- constructor(init: DocxEditorErrorInit);
2516
- }
2517
- /**
2518
- * Whether a caught value is one of ours.
2519
- *
2520
- * By `name` as well as by `instanceof`: a consumer can end up with two copies of this module
2521
- * (a bundle plus a dependency's), and an `instanceof` that fails across them would send a
2522
- * perfectly ordinary `PropertyNotLoaded` down a consumer's unexpected-error path.
2523
- */
2524
- declare function isDocxEditorError(value: unknown): value is DocxEditorError;
2525
-
2526
2679
  /** Word's shape types. Supported text-bearing shapes expose their own body. @public */
2527
2680
  declare enum ShapeType {
2528
2681
  unsupported = "Unsupported",
@@ -2712,6 +2865,47 @@ declare class Body extends ModelObject {
2712
2865
  interface ServerPaginationOptions extends AutomationPaginationOptions {
2713
2866
  }
2714
2867
 
2868
+ /**
2869
+ * A diagnostic from a headless runtime: the open, and each refused batch.
2870
+ * Each one is also a valid `EditorDiagnostic`, so a telemetry module written for the editor
2871
+ * receives these unchanged.
2872
+ *
2873
+ * @public
2874
+ */
2875
+ type RuntimeDiagnostic = {
2876
+ readonly schemaVersion: number;
2877
+ /** Random for each runtime and never stored. */
2878
+ readonly editorSessionId: string;
2879
+ readonly time: number;
2880
+ } & ({
2881
+ readonly kind: 'document.open';
2882
+ readonly outcome: 'opened';
2883
+ readonly sizeBucket: ByteSizeBucket;
2884
+ readonly durationMs: number;
2885
+ } | {
2886
+ readonly kind: 'document.open';
2887
+ readonly outcome: 'rejected';
2888
+ readonly code: DocumentOpenDiagnosticCode;
2889
+ readonly sizeBucket?: ByteSizeBucket;
2890
+ /** The engine's own reason. See `diagnosticCauses()`. */
2891
+ readonly cause?: string;
2892
+ /** The role of the part that failed. Never its name. */
2893
+ readonly part?: DocumentPartKind;
2894
+ /** The class of the exception when `cause` is `exception`. */
2895
+ readonly errorName?: DiagnosticErrorName;
2896
+ } | {
2897
+ readonly kind: 'edit.rejected';
2898
+ readonly code: EditDiagnosticCode;
2899
+ readonly origin: 'automation';
2900
+ readonly tracked: boolean;
2901
+ /** The engine's own reason. See `diagnosticCauses()`. */
2902
+ readonly cause?: string;
2903
+ /** The class of the exception when `cause` is `exception`. */
2904
+ readonly errorName?: DiagnosticErrorName;
2905
+ /** `automation` when `cause` is `exception`. */
2906
+ readonly stage?: 'automation';
2907
+ });
2908
+
2715
2909
  /**
2716
2910
  * Capability module accepted by {@link createServer}. Collaboration attaches
2717
2911
  * through a collaboration contribution. Other contributions are ignored here.
@@ -2721,6 +2915,11 @@ interface ServerPaginationOptions extends AutomationPaginationOptions {
2721
2915
  interface EditorModule {
2722
2916
  readonly id: string;
2723
2917
  readonly collaboration?: CollaborationModuleContribution;
2918
+ /**
2919
+ * Told about this runtime's anonymous diagnostics: the open, and each refused batch with a
2920
+ * known reason. A telemetry module's listener fits here unchanged.
2921
+ */
2922
+ readonly onDiagnostic?: (event: RuntimeDiagnostic) => void;
2724
2923
  }
2725
2924
  /** Resource limits for the DOCX archive. */
2726
2925
  interface DocumentZipLimits {
@@ -2774,7 +2973,9 @@ interface CreateServerOptions {
2774
2973
  readonly pagination?: ServerPaginationOptions;
2775
2974
  /**
2776
2975
  * Capability modules to register. Collaboration attaches only through a
2777
- * collaboration contribution on this list.
2976
+ * collaboration contribution on this list. A module with `onDiagnostic`, such as a telemetry
2977
+ * module, receives the anonymous diagnostics of this runtime: the open, and each refused
2978
+ * batch with a known reason.
2778
2979
  */
2779
2980
  readonly modules?: readonly EditorModule[];
2780
2981
  /**
@@ -2803,5 +3004,5 @@ interface CreateServerOptions {
2803
3004
  /** Options for {@link createCollaborative}. @public */
2804
3005
  type CreateCollaborativeOptions = CreateServerOptions;
2805
3006
 
2806
- export { Alignment as A, DocxEditorError as E, Field as J, FieldCollection as K, FieldType as L, Font as N, InlinePicture as P, InlinePictureCollection as Q, InsertLocation as R, List as S, ListBullet as T, ListCollection as U, ListItem as V, ListNumbering as W, NoteItem as Z, NoteItemCollection as _, PageOrientation as a0, PageSetup as a1, Paragraph as a2, ParagraphCollection as a4, Range as a6, RangeCollection as a7, RemoveDocInfoType as a9, RequestContext as aa, Revision as ab, RevisionCollection as ac, Section as ah, SectionCollection as ai, Shape as al, ShapeCollection as am, ShapeType as an, Table as ao, TableCell as ap, TableCellCollection as aq, TableCollection as ar, TableRow as as, TableRowCollection as at, TrackedObjects as au, UnderlineType as av, VerticalAlignment as aw, isDocxEditorError as ax, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ClientObject as i, ClientResult as j, Comment as k, CommentCollection as l, CommentReply as m, CommentReplyCollection as n, ContentControl as o, ContentControlCollection as p, ContentControlType as s, Document as u, DocumentProperties as x };
2807
- export type { NoteItemType as $, BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocxEditorErrorCode as F, DocxEditorErrorInit as G, DocxEditorRuntime as H, EditorModule as I, FieldTypeLiteral as M, HeaderFooterType as O, LoadOption as X, LoadQueryOptions as Y, CreateCollaborativeOptions as a, ParagraphAlignment as a3, ParagraphInsertTextLocation as a5, RangeInsertTextLocation as a8, RevisionTextView as ad, RevisionType as ae, RunCallback as af, SearchOptions as ag, SelectionMode as aj, ServerPaginationOptions as ak, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, ContentControlLockState as q, ContentControlSubtype as r, ContentControlValue as t, DocumentCapabilities as v, DocumentLimits as w, DocumentXmlLimits as y, DocumentZipLimits as z };
3007
+ export { NoteItem as $, Alignment as A, DocxEditorError as F, Field as L, FieldCollection as M, FieldType as N, Font as P, InlinePicture as R, InlinePictureCollection as S, InsertLocation as T, List as U, ListBullet as V, ListCollection as W, ListItem as X, ListNumbering as Y, NoteItemCollection as a0, PageOrientation as a2, PageSetup as a3, Paragraph as a4, ParagraphCollection as a6, Range as a9, TrackedObjects as aA, UnderlineType as aB, VerticalAlignment as aC, isDocxEditorError as aD, RangeCollection as aa, RemoveDocInfoType as ac, RequestContext as ad, Revision as ae, RevisionCollection as ah, Section as an, SectionCollection as ao, Shape as ar, ShapeCollection as as, ShapeType as at, Table as au, TableCell as av, TableCellCollection as aw, TableCollection as ax, TableRow as ay, TableRowCollection as az, Body as b, Bookmark as e, BookmarkCollection as f, BreakType as g, ChangeTrackingMode as h, ClientObject as i, ClientResult as j, Comment as k, CommentCollection as l, CommentReply as m, CommentReplyCollection as n, ContentControl as o, ContentControlCollection as p, ContentControlType as s, Document as u, DocumentProperties as x };
3008
+ export type { BesideLocation as B, CreateServerOptions as C, DocxEditorServerRuntime as D, DocxEditorDebugInfo as E, DocxEditorErrorCode as G, DocxEditorErrorInit as H, DocxEditorInnerError as I, DocxEditorRuntime as J, EditorModule as K, FieldTypeLiteral as O, HeaderFooterType as Q, LoadOption as Z, LoadQueryOptions as _, CreateCollaborativeOptions as a, NoteItemType as a1, ParagraphAlignment as a5, ParagraphInsertTextLocation as a7, ParagraphReadingOrder as a8, RangeInsertTextLocation as ab, RevisionAuthorOptions as af, RevisionAuthorSelection as ag, RevisionTextView as ai, RevisionType as aj, RunCallback as ak, RuntimeDiagnostic as al, SearchOptions as am, SelectionMode as ap, ServerPaginationOptions as aq, BodyInsertParagraphLocation as c, BodyInsertTextLocation as d, ContentControlLockState as q, ContentControlSubtype as r, ContentControlValue as t, DocumentCapabilities as v, DocumentLimits as w, DocumentXmlLimits as y, DocumentZipLimits as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docx-editor.dev/editor-api",
3
- "version": "2.27.0",
3
+ "version": "2.29.0",
4
4
  "description": "Document automation for DOCX: a batching object model that drives a document from a server or from an editor already open in a page",
5
5
  "sideEffects": false,
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  ],
47
47
  "scripts": {
48
48
  "build": "node ../../scripts/check-built-siblings.mjs && tsup && node ../../scripts/inject-package-doc.mjs --package @docx-editor.dev/editor-api",
49
- "typecheck": "tsc --noEmit",
49
+ "typecheck": "bun check",
50
50
  "license:check": "license-check-and-add check -f license-check.json",
51
51
  "license:add": "license-check-and-add add -f license-check.json",
52
52
  "api:extract": "node ../../scripts/api-extractor.mjs --package @docx-editor.dev/editor-api --local",
@@ -83,6 +83,6 @@
83
83
  "access": "public"
84
84
  },
85
85
  "peerDependencies": {
86
- "@docx-editor.dev/core": "~2.27.0"
86
+ "@docx-editor.dev/core": "~2.29.0"
87
87
  }
88
88
  }