@lincyaw/kernel 1.0.0-rc.50 → 1.0.0-rc.51

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.50",
3
+ "version": "1.0.0-rc.51",
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": {
@@ -0,0 +1,47 @@
1
+ import type { Schema } from '@cfworker/json-schema'
2
+ import type { Member } from './server.ts'
3
+ import type { AuthoringClientConnection, AuthoringClientLease, AuthoringClientRequestState } from './authoring-clients.ts'
4
+
5
+ /** Window lifetime survives home and document changes; it never asserts a CanonicalSource. */
6
+ export const AUTHORING_WINDOW_ACTIONS = ['window.read', 'document.open', 'document.close'] as const
7
+ export type AuthoringWindowAction = { type: 'window.read' } | { type: 'document.open', document: string } | { type: 'document.close' }
8
+ export type AuthoringWindowLocation = { type: 'home' } | { type: 'document', document: string, documentId?: string, status: 'loading' | 'ready' | 'failed' }
9
+ export interface AuthoringWindowSnapshot { revision: number, location: AuthoringWindowLocation, actions: (typeof AUTHORING_WINDOW_ACTIONS[number])[] }
10
+ export interface AuthoringWindowOpen { clientId: string, epoch: string, snapshot: AuthoringWindowSnapshot }
11
+ export interface AuthoringWindowDescriptor extends AuthoringClientConnection { connected: boolean, snapshot: AuthoringWindowSnapshot, observedAt: string, pendingRequest?: { requestId: string, action: AuthoringWindowAction['type'], cancellationRequested?: true } }
12
+ export interface AuthoringWindowRequest extends AuthoringClientConnection {
13
+ requestId: string
14
+ revision: number
15
+ action: AuthoringWindowAction
16
+ /** Pinned internally before approval; path reuse cannot select a different document. */
17
+ target?: { document: string, documentId: string }
18
+ }
19
+ export interface AuthoringWindowRequestResult extends AuthoringClientConnection {
20
+ requestId: string, action: AuthoringWindowAction['type'], state: AuthoringClientRequestState, admittedAt: string, expiresAt: string,
21
+ snapshot?: AuthoringWindowSnapshot, outcome?: 'observed' | 'opened' | 'closed' | 'unchanged', cancellationRequested?: true, error?: { code: string }, acknowledged: boolean, current: boolean
22
+ }
23
+ export type AuthoringWindowEvent = { type: 'connected', connectionId: string } | { type: 'request', request: AuthoringWindowRequest, expiresAt: string } | { type: 'cancel', connectionId: string, requestId: string }
24
+ export interface AuthoringWindowReport { sequence: number, snapshot: AuthoringWindowSnapshot }
25
+ export interface AuthoringWindowAcknowledgement extends AuthoringWindowReport { requestId: string, state: 'executing' | 'done' | 'refused' | 'failed', outcome?: AuthoringWindowRequestResult['outcome'], error?: { code: string } }
26
+ export type AuthoringWindowReference = Pick<AuthoringWindowRequest, 'clientId' | 'epoch' | 'requestId'>
27
+ export interface AuthoringWindows {
28
+ list(query: { clientId?: string, after?: string }, member: Member): Promise<{ scope: 'workspace', clients: AuthoringWindowDescriptor[], nextAfter?: string }>
29
+ request(request: AuthoringWindowRequest, member: Member): Promise<AuthoringWindowRequestResult>
30
+ get(reference: AuthoringWindowReference | string, member: Member): Promise<AuthoringWindowRequestResult>
31
+ cancel(reference: AuthoringWindowReference | string, member: Member): Promise<AuthoringWindowRequestResult>
32
+ }
33
+
34
+ const id: Schema = { type: 'string', minLength: 1, maxLength: 80, pattern: '^[a-zA-Z0-9.-]+$' }
35
+ export const AUTHORING_WINDOW_HANDLE_SCHEMA: Schema = id
36
+ const directory: Schema = { type: 'string', maxLength: 200 }
37
+ const entity: Schema = { type: 'string', minLength: 1, maxLength: 200 }
38
+ const integer: Schema = { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER }
39
+ const object = (properties: Record<string, Schema>, required = Object.keys(properties)): Schema => ({ type: 'object', additionalProperties: false, properties, required })
40
+ const connection = { clientId: id, epoch: id, connectionId: id }
41
+ export const AUTHORING_WINDOW_ACTION_SCHEMA: Schema = { oneOf: [object({ type: { const: 'window.read' } }), object({ type: { const: 'document.open' }, document: directory }), object({ type: { const: 'document.close' } })] }
42
+ export const AUTHORING_WINDOW_SNAPSHOT_SCHEMA: Schema = object({ revision: integer, location: { oneOf: [object({ type: { const: 'home' } }), object({ type: { const: 'document' }, document: directory, documentId: entity, status: { enum: ['loading', 'ready', 'failed'] } }, ['type', 'document', 'status'])] }, actions: { type: 'array', items: { enum: [...AUTHORING_WINDOW_ACTIONS] }, maxItems: AUTHORING_WINDOW_ACTIONS.length, uniqueItems: true } })
43
+ export const AUTHORING_WINDOW_OPEN_SCHEMA: Schema = object({ clientId: id, epoch: id, snapshot: AUTHORING_WINDOW_SNAPSHOT_SCHEMA })
44
+ export const AUTHORING_WINDOW_REQUEST_SCHEMA: Schema = object({ ...connection, requestId: id, revision: integer, action: AUTHORING_WINDOW_ACTION_SCHEMA, target: object({ document: directory, documentId: entity }) }, [...Object.keys(connection), 'requestId', 'revision', 'action'])
45
+ export const AUTHORING_WINDOW_REPORT_SCHEMA: Schema = object({ sequence: integer, snapshot: AUTHORING_WINDOW_SNAPSHOT_SCHEMA })
46
+ export const AUTHORING_WINDOW_ACK_SCHEMA: Schema = object({ sequence: integer, snapshot: AUTHORING_WINDOW_SNAPSHOT_SCHEMA, requestId: id, state: { enum: ['executing', 'done', 'refused', 'failed'] }, outcome: { enum: ['observed', 'opened', 'closed', 'unchanged'] }, error: object({ code: { type: 'string', minLength: 1, maxLength: 160 } }) }, ['sequence', 'snapshot', 'requestId', 'state'])
47
+ export type AuthoringWindowLease = AuthoringClientLease
package/src/contracts.ts CHANGED
@@ -35,5 +35,6 @@ export * from './contracts/document-comments.ts'
35
35
  export * from './contracts/authoring-actions.ts'
36
36
  export * from './contracts/document-history.ts'
37
37
  export * from './contracts/authoring-clients.ts'
38
+ export * from './contracts/authoring-windows.ts'
38
39
  export * from './contracts/projects.ts'
39
40
  export * from './contracts/document-image.ts'
@@ -0,0 +1,11 @@
1
+ import { Validator } from '@cfworker/json-schema'
2
+ import { AUTHORING_WINDOW_ACK_SCHEMA, AUTHORING_WINDOW_HANDLE_SCHEMA, AUTHORING_WINDOW_OPEN_SCHEMA, AUTHORING_WINDOW_REPORT_SCHEMA, AUTHORING_WINDOW_REQUEST_SCHEMA } from '../contracts/authoring-windows.ts'
3
+ import type { AuthoringWindowAcknowledgement, AuthoringWindowOpen, AuthoringWindowReport, AuthoringWindowRequest } from '../contracts/authoring-windows.ts'
4
+ const validator = (schema: typeof AUTHORING_WINDOW_REQUEST_SCHEMA) => new Validator(structuredClone(schema), '2020-12', false)
5
+ const request = validator(AUTHORING_WINDOW_REQUEST_SCHEMA), open = validator(AUTHORING_WINDOW_OPEN_SCHEMA), report = validator(AUTHORING_WINDOW_REPORT_SCHEMA), ack = validator(AUTHORING_WINDOW_ACK_SCHEMA)
6
+ const handle = validator(AUTHORING_WINDOW_HANDLE_SCHEMA)
7
+ export const validateAuthoringWindowHandle = (value: unknown): value is string => handle.validate(value).valid
8
+ export const validateAuthoringWindowRequest = (value: unknown): value is AuthoringWindowRequest => request.validate(value).valid
9
+ export const validateAuthoringWindowOpen = (value: unknown): value is AuthoringWindowOpen => open.validate(value).valid
10
+ export const validateAuthoringWindowReport = (value: unknown): value is AuthoringWindowReport => report.validate(value).valid
11
+ export const validateAuthoringWindowAcknowledgement = (value: unknown): value is AuthoringWindowAcknowledgement => ack.validate(value).valid
package/src/node/index.ts CHANGED
@@ -23,6 +23,7 @@ export { findInstalledPackage } from './installed-packages.ts'
23
23
  export { directSandbox, minimalRunEnv, RUN_REQUEST_FILE, RUN_RESULT_PREFIX, runResultFile } from './run-directory.ts'
24
24
  export { validateDocumentHistoryQuery, validateDocumentHistoryRead, validateDocumentHistoryChange } from './document-history.ts'
25
25
  export { validateAuthoringClientRequest, validateAuthoringClientQuery, validateAuthoringClientRequestQuery, validateAuthoringClientOpen, validateAuthoringClientReport, validateAuthoringClientAcknowledgement, validateAuthoringClientLease } from './authoring-clients.ts'
26
+ export { validateAuthoringWindowHandle, validateAuthoringWindowRequest, validateAuthoringWindowOpen, validateAuthoringWindowReport, validateAuthoringWindowAcknowledgement } from './authoring-windows.ts'
26
27
  export { validateProjectPlan, validateProjectApply } from './projects.ts'
27
28
  export { validateDocumentWorkspaceImageInspect, validateDocumentWorkspaceImageImport } from './document-image.ts'
28
29
  export { systemLocale } from './locale.ts'