@lincyaw/kernel 1.0.0-rc.48 → 1.0.0-rc.49

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "1.0.0-rc.48",
3
+ "version": "1.0.0-rc.49",
4
4
  "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -12,11 +12,14 @@ export const AUTHORING_CLIENT_MAX_REQUESTS = 64
12
12
  export const AUTHORING_CLIENT_REQUEST_TIMEOUT_MS = 30000
13
13
  export const AUTHORING_CLIENT_ACK_MAX_BYTES = 32768
14
14
  export const AUTHORING_CLIENT_EVENT_MAX_BYTES = 8 << 10
15
- export const AUTHORING_CLIENT_ACTIONS = ['state.read', 'source.flush', 'preview.prepare', 'view.set', 'native-history.undo', 'native-history.redo', 'recording.start', 'recording.stop', 'recording.cancel', 'recording.discard', 'recording.save', 'recording.listen', 'recording.pause', 'comment-drafts.inspect', 'comment-drafts.read', 'comment-drafts.restore', 'comment-drafts.discard', 'component-drafts.inspect', 'component-drafts.read', 'component-drafts.restore', 'component-drafts.discard', 'playback.pause', 'position.step', 'playback.play', 'playback.seek', 'playback.rate'] as const
15
+ export const AUTHORING_CLIENT_ACTIONS = ['state.read', 'source.flush', 'preview.prepare', 'view.set', 'native-history.undo', 'native-history.redo', 'recording.start', 'recording.stop', 'recording.cancel', 'recording.discard', 'recording.save', 'recording.listen', 'recording.pause', 'comment-drafts.inspect', 'comment-drafts.read', 'comment-drafts.restore', 'comment-drafts.discard', 'body-drafts.inspect', 'body-drafts.read', 'body-drafts.restore', 'body-drafts.discard', 'body-drafts.retry', 'component-drafts.inspect', 'component-drafts.read', 'component-drafts.restore', 'component-drafts.discard', 'playback.pause', 'position.step', 'playback.play', 'playback.seek', 'playback.rate'] as const
16
16
  export type AuthoringClientActionType = typeof AUTHORING_CLIENT_ACTIONS[number]
17
17
  export type AuthoringClientView = 'document' | 'reading' | 'presentation' | 'production'
18
- /** Only these browser-owned actions may finish at a new saved source of the same document. */
19
- export const authoringClientActionChangesSource = (type: AuthoringClientActionType): boolean => ['source.flush', 'native-history.undo', 'native-history.redo', 'recording.save'].includes(type)
18
+ /** Browser-owned actions that may write the saved source of the same document. */
19
+ export const authoringClientActionChangesSource = (type: AuthoringClientActionType): boolean => ['source.flush', 'native-history.undo', 'native-history.redo', 'recording.save', 'body-drafts.retry'].includes(type)
20
+ /** Local backup operations retain lease/input checks without requiring a readable current source. */
21
+ export const authoringClientActionUsesLocalDraft = (type: AuthoringClientActionType): boolean => ['body-drafts.inspect', 'body-drafts.read', 'body-drafts.restore', 'body-drafts.discard'].includes(type)
22
+ export const authoringClientActionMutatesDraft = (type: AuthoringClientActionType): boolean => ['comment-drafts.restore', 'comment-drafts.discard', 'component-drafts.restore', 'component-drafts.discard', 'body-drafts.restore', 'body-drafts.discard', 'body-drafts.retry'].includes(type)
20
23
  export type AuthoringClientAction =
21
24
  | { type: 'state.read' }
22
25
  | { type: 'source.flush' }
@@ -29,6 +32,11 @@ export type AuthoringClientAction =
29
32
  | { type: 'comment-drafts.read', draft: ClientCommentDraftReference, offset: number, maxChars?: number }
30
33
  | { type: 'comment-drafts.restore', draft: ClientCommentDraftReference, composerId: string, expectedCurrent: ClientCommentDraftReference | null }
31
34
  | { type: 'comment-drafts.discard', draft: ClientCommentDraftReference }
35
+ | { type: 'body-drafts.inspect', cursor?: { after: string, token: string }, limit?: number }
36
+ | { type: 'body-drafts.read', draft: ClientBodyDraftReference, offset: number, maxChars?: number }
37
+ | { type: 'body-drafts.restore', draft: ClientBodyDraftReference }
38
+ | { type: 'body-drafts.discard', draft: ClientBodyDraftReference, confirm: true }
39
+ | { type: 'body-drafts.retry', draft: ClientBodyDraftReference }
32
40
  | { type: 'component-drafts.inspect', cursor?: { after: string, token: string }, limit?: number }
33
41
  | { type: 'component-drafts.read', draft: ClientComponentDraftReference, offset: number, maxChars?: number }
34
42
  | { type: 'component-drafts.restore', draft: ClientComponentDraftReference, expectedCurrent: ClientComponentDraftReference | null }
@@ -39,6 +47,19 @@ export type AuthoringClientAction =
39
47
  | { type: 'playback.seek', binding: ProductionBinding, timeMs: number }
40
48
  | { type: 'playback.rate', binding: ProductionBinding, rate: number }
41
49
 
50
+ /** Opaque exact-branch reference resolved only by the native document actor. */
51
+ export type ClientBodyDraftReference = string
52
+ export interface ClientBodyDraftMetadata {
53
+ draft: ClientBodyDraftReference
54
+ current: boolean
55
+ storage: 'durable' | 'rescue' | 'session'
56
+ updatedAt: number
57
+ baseVersion: string
58
+ /** Matches the browser's last observed saved version; does not assert server freshness. */
59
+ baseObserved: boolean
60
+ composing: boolean
61
+ pendingSubmission: boolean
62
+ }
42
63
  export interface ClientCommentDraftReference { id: string, revision: number, token: string }
43
64
  export interface ClientComponentDraftReference { id: string, revision: number, token: string, blockId: string, stepId?: string }
44
65
  /** No parameter values, baselines, workspace identity or member IDs enter this metadata. */
@@ -71,6 +92,11 @@ export interface ClientCommentDraftMetadata {
71
92
  commentId?: string
72
93
  }
73
94
  export type AuthoringClientActionResult =
95
+ | { type: 'body-drafts.inspect', family: 'body', coverage: 'stored-and-session' | 'partial', token: string, drafts: ClientBodyDraftMetadata[], next?: { after: string, token: string } }
96
+ | { type: 'body-drafts.read', family: 'body', draft: ClientBodyDraftReference, storage: 'durable' | 'rescue' | 'session', format: 'presmium-document-json-v1', offset: number, endOffset: number, totalUtf16: number, totalUtf8: number, sha256: string, jsonText: string }
97
+ | { type: 'body-drafts.restore' | 'body-drafts.discard' | 'body-drafts.retry', family: 'body', draft: ClientBodyDraftReference,
98
+ outcome: 'restored' | 'already-saved' | 'source-restored' | 'backup-discarded' | 'saved', dirty: boolean, conflicted: boolean, backupPending?: true, backupRetained?: true }
99
+
74
100
  | { type: 'comment-drafts.inspect', family: 'comment', coverage: 'stored-and-session' | 'session-only', skippedInvalid: number, token: string, drafts: ClientCommentDraftMetadata[], next?: { after: string, token: string } }
75
101
  | { type: 'comment-drafts.read', family: 'comment', draft: ClientCommentDraftReference, storage: 'durable' | 'session', format: 'presmium-rich-text-json-v1', offset: number, endOffset: number, totalUtf16: number, totalUtf8: number, sha256: string, jsonText: string }
76
102
  | { type: 'comment-drafts.restore', family: 'comment', draft: ClientCommentDraftReference, composerId: string, restored: ClientCommentDraftReference, preservedCurrent: ClientCommentDraftReference | null, targetState: 'current' | 'changed' }
@@ -175,6 +201,8 @@ const bool: Schema = { type: 'boolean' }
175
201
  const object = (properties: Record<string, Schema>, required = Object.keys(properties)): Schema => ({ type: 'object', additionalProperties: false, properties, required })
176
202
  const digest: Schema = { type: 'string', pattern: '^[a-f0-9]{64}$' }
177
203
  const draftReference = object({ id: entity, revision: { type: 'integer', minimum: 1, maximum: Number.MAX_SAFE_INTEGER }, token: digest })
204
+ const bodyDraftReference = digest
205
+ const bodyMetadata = object({ draft: bodyDraftReference, current: bool, storage: { enum: ['durable', 'rescue', 'session'] }, updatedAt: integer, baseVersion: entity, baseObserved: bool, composing: bool, pendingSubmission: bool })
178
206
  const componentDraftReference = object({ id: entity, revision: { type: 'integer', minimum: 1, maximum: Number.MAX_SAFE_INTEGER }, token: digest, blockId: entity, stepId: entity }, ['id', 'revision', 'token', 'blockId'])
179
207
  const componentMetadata = object({ draft: componentDraftReference, definitionId: entity, current: bool, storage: { enum: ['durable', 'session'] }, status: { enum: ['available', 'pending', 'session-only'] }, updatedAt: integer, baseVersion: entity, sourceCurrent: bool, composing: bool, reset: bool })
180
208
  const nullableComponentReference: Schema = { oneOf: [componentDraftReference, { type: 'null' }] }
@@ -182,6 +210,11 @@ const nullableCommentReference: Schema = { oneOf: [draftReference, { type: 'null
182
210
  const commentRestore = object({ composerId: id, expectedCurrent: nullableCommentReference })
183
211
  const cursor = object({ after: entity, token: digest })
184
212
  export const AUTHORING_CLIENT_ACTION_RESULT_SCHEMA: Schema = { oneOf: [
213
+ object({ type: { const: 'body-drafts.inspect' }, family: { const: 'body' }, coverage: { enum: ['stored-and-session', 'partial'] }, token: digest,
214
+ drafts: { type: 'array', maxItems: 10, items: bodyMetadata }, next: cursor }, ['type', 'family', 'coverage', 'token', 'drafts']),
215
+ object({ type: { const: 'body-drafts.read' }, family: { const: 'body' }, draft: bodyDraftReference, storage: { enum: ['durable', 'rescue', 'session'] }, format: { const: 'presmium-document-json-v1' }, offset: integer, endOffset: integer, totalUtf16: integer, totalUtf8: integer, sha256: digest, jsonText: { type: 'string', maxLength: 2048 } }),
216
+ object({ type: { enum: ['body-drafts.restore', 'body-drafts.discard', 'body-drafts.retry'] }, family: { const: 'body' }, draft: bodyDraftReference,
217
+ outcome: { enum: ['restored', 'already-saved', 'source-restored', 'backup-discarded', 'saved'] }, dirty: bool, conflicted: bool, backupPending: { const: true }, backupRetained: { const: true } }, ['type', 'family', 'draft', 'outcome', 'dirty', 'conflicted']),
185
218
  object({ type: { const: 'comment-drafts.inspect' }, family: { const: 'comment' }, coverage: { enum: ['stored-and-session', 'session-only'] }, skippedInvalid: integer,
186
219
  token: digest, drafts: { type: 'array', maxItems: 10, items: object({ draft: draftReference, kind: { enum: ['create', 'reply', 'edit'] }, storage: { enum: ['durable', 'session'] }, updatedAt: integer, baseVersion: entity, composing: bool, pendingSubmission: bool, ownersKnown: bool, active: bool, discardable: bool, restore: commentRestore, threadId: entity, commentId: entity }, ['draft', 'kind', 'storage', 'updatedAt', 'baseVersion', 'composing', 'pendingSubmission', 'ownersKnown', 'active', 'discardable']) }, next: cursor }, ['type', 'family', 'coverage', 'skippedInvalid', 'token', 'drafts']),
187
220
  object({ type: { const: 'comment-drafts.read' }, family: { const: 'comment' }, draft: draftReference, storage: { enum: ['durable', 'session'] }, format: { const: 'presmium-rich-text-json-v1' }, offset: integer, endOffset: integer, totalUtf16: integer, totalUtf8: integer, sha256: digest, jsonText: { type: 'string', maxLength: 2048 } }),
@@ -217,6 +250,11 @@ export const AUTHORING_CLIENT_ACTION_SCHEMA: Schema = { oneOf: [
217
250
  object({ type: { const: 'comment-drafts.read' }, draft: draftReference, offset: integer, maxChars: { type: 'integer', minimum: 2, maximum: 2048 } }, ['type', 'draft', 'offset']),
218
251
  action('comment-drafts.restore', { draft: draftReference, composerId: id, expectedCurrent: nullableCommentReference }),
219
252
  action('comment-drafts.discard', { draft: draftReference }),
253
+ object({ type: { const: 'body-drafts.inspect' }, cursor, limit: { type: 'integer', minimum: 1, maximum: 10 } }, ['type']),
254
+ object({ type: { const: 'body-drafts.read' }, draft: bodyDraftReference, offset: integer, maxChars: { type: 'integer', minimum: 2, maximum: 2048 } }, ['type', 'draft', 'offset']),
255
+ action('body-drafts.restore', { draft: bodyDraftReference }),
256
+ action('body-drafts.discard', { draft: bodyDraftReference, confirm: { const: true } }),
257
+ action('body-drafts.retry', { draft: bodyDraftReference }),
220
258
  object({ type: { const: 'component-drafts.inspect' }, cursor, limit: { type: 'integer', minimum: 1, maximum: 10 } }, ['type']),
221
259
  object({ type: { const: 'component-drafts.read' }, draft: componentDraftReference, offset: integer, maxChars: { type: 'integer', minimum: 2, maximum: 2048 } }, ['type', 'draft', 'offset']),
222
260
  action('component-drafts.restore', { draft: componentDraftReference, expectedCurrent: nullableComponentReference }),