mindoodb-app-sdk 0.0.64 → 0.0.66

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 { ay as MindooDBAppComponentInfo, bq as MindooDBAppEmbedRect, I as MindooDBAppAgentToolDescriptor, f as MindooDBAppAgentToolErrorCode, V as MindooDBAppBridgeAgentResultMessage, U as MindooDBAppBridgeAgentInvokeMessage, aU as MindooDBAppCreateViewNavigatorInput, de as MindooDBAppViewNavigator, ad as MindooDBAppBridgeRpcRequest, bC as MindooDBAppHostTheme, av as MindooDBAppCapability, j as MindooDBAppDefinition, J as MindooDBAppAttachmentApi, e as MindooDBAppBridge, cQ as MindooDBAppSession, cg as MindooDBAppProposeAppInput, dm as MindooDBAppViewport, d8 as MindooDBAppUiPreferences, cm as MindooDBAppQueryResult, dl as MindooDBAppViewUpdateStats, a9 as MindooDBAppBridgePortMessage, aV as MindooDBAppDatabaseInfo, bl as MindooDBAppEmbedCloseReason, a4 as MindooDBAppBridgeErrorPayload, bX as MindooDBAppLaunchContext, b2 as MindooDBAppDocumentApi, dg as MindooDBAppViewNavigatorOpenOptions, bD as MindooDBAppIdentityApi, d4 as MindooDBAppTimestampApi, b0 as MindooDBAppDirectoryApi, l as MindooDBAppDocument, bz as MindooDBAppFulltextSetup, by as MindooDBAppExtractionSetup, cY as MindooDBAppSummarySetup, ch as MindooDBAppProposeAppResult, bN as MindooDBAppIncomingSource, c as MindooDBAppDragStartResult, bj as MindooDBAppDragProfile, bM as MindooDBAppIncomingResult } from '../types-BeRUxGKN.js';
1
+ import { aC as MindooDBAppComponentInfo, bx as MindooDBAppEmbedRect, bq as MindooDBAppEmbedAgentTools, bz as MindooDBAppEmbeddingLookupOptions, bA as MindooDBAppEmbeddingLookupResult, J as MindooDBAppAgentToolDescriptor, f as MindooDBAppAgentToolErrorCode, X as MindooDBAppBridgeAgentResultMessage, W as MindooDBAppBridgeAgentInvokeMessage, aZ as MindooDBAppCreateViewNavigatorInput, dn as MindooDBAppViewNavigator, af as MindooDBAppBridgeRpcRequest, bL as MindooDBAppHostTheme, ax as MindooDBAppCapability, di as MindooDBAppUpdateDocumentInput, l as MindooDBAppDocument, j as MindooDBAppDefinition, L as MindooDBAppAttachmentApi, e as MindooDBAppBridge, cZ as MindooDBAppSession, cp as MindooDBAppProposeAppInput, dw as MindooDBAppViewport, dh as MindooDBAppUiPreferences, cv as MindooDBAppQueryResult, dv as MindooDBAppViewUpdateStats, ab as MindooDBAppBridgePortMessage, a_ as MindooDBAppDatabaseInfo, bs as MindooDBAppEmbedCloseReason, a6 as MindooDBAppBridgeErrorPayload, c4 as MindooDBAppLaunchContext, b7 as MindooDBAppDocumentApi, dq as MindooDBAppViewNavigatorOpenOptions, bM as MindooDBAppIdentityApi, dd as MindooDBAppTimestampApi, b5 as MindooDBAppDirectoryApi, bI as MindooDBAppFulltextSetup, bH as MindooDBAppExtractionSetup, d5 as MindooDBAppSummarySetup, cq as MindooDBAppProposeAppResult, bW as MindooDBAppIncomingSource, c as MindooDBAppDragStartResult, bo as MindooDBAppDragProfile, bV as MindooDBAppIncomingResult } from '../types-Cuw-0Iou.js';
2
2
  import * as mindoodb from 'mindoodb';
3
3
  import 'mindoodb-view-language';
4
4
 
@@ -13,6 +13,10 @@ interface MockEmbedState {
13
13
  visible: boolean;
14
14
  /** What the component last reported (`setEmbedDirty`); `undefined` until then. */
15
15
  dirty?: boolean;
16
+ /** Whether it is the active one of its app's embeds (`embed.setActive`, or the newest). */
17
+ active: boolean;
18
+ /** The agent tools it offers (`setEmbedAgentTools`), as the host app sees them. */
19
+ agentTools: MindooDBAppEmbedAgentTools | null;
16
20
  }
17
21
  /** How an app running as an embedded component finished (`session.embedding`). */
18
22
  interface MockEmbeddingFinish {
@@ -20,6 +24,18 @@ interface MockEmbeddingFinish {
20
24
  result?: unknown;
21
25
  message?: string;
22
26
  }
27
+ interface MockEmbedHostOptions {
28
+ /** What `session.components.list` offers. */
29
+ components?: MindooDBAppComponentInfo[];
30
+ /** Called when the app opens an embed, e.g. to draw a stand-in in the test host page. */
31
+ onEmbedChange?: (embeds: readonly MockEmbedState[]) => void;
32
+ /**
33
+ * For an app under test that runs as a component: answers its
34
+ * `session.embedding.lookup`, as Haven would from the host's database. No results
35
+ * without it.
36
+ */
37
+ embeddingLookup?: (field: string, options: MindooDBAppEmbeddingLookupOptions) => MindooDBAppEmbeddingLookupResult[] | Promise<MindooDBAppEmbeddingLookupResult[]>;
38
+ }
23
39
 
24
40
  /**
25
41
  * Haven's side of agent tools, for tests: what `session.agent` talks to.
@@ -131,6 +147,8 @@ declare function createMockAgentHost(options: MockAgentHostOptions & {
131
147
  /** Posts to the app's port; `false` when no app is connected. */
132
148
  post(message: MindooDBAppBridgeAgentInvokeMessage): boolean;
133
149
  onChange?(): void;
150
+ /** Whether the app runs as an embedded component: then only its `document` tools count. */
151
+ embedded?(): boolean;
134
152
  }): MockAgentHost;
135
153
 
136
154
  type EvaluatingViewDocument = {
@@ -152,6 +170,33 @@ declare function loadMindoodbForTesting(): Promise<MindoodbVirtualViews | null>;
152
170
  */
153
171
  declare function createEvaluatingViewNavigator(input: MindooDBAppCreateViewNavigatorInput, documents: EvaluatingViewDocument[]): Promise<MindooDBAppViewNavigator | null>;
154
172
 
173
+ interface TestHostUser {
174
+ /** Shown above the user's frame. */
175
+ name: string;
176
+ username: string;
177
+ }
178
+ declare const DEFAULT_TEST_HOST_USERS: readonly [TestHostUser, TestHostUser];
179
+ /** Window handles of the two-user mode, for Playwright. */
180
+ interface TwoUserTestHost {
181
+ hosts: [BrowserTestHost, BrowserTestHost];
182
+ /** Merge the two replicas now; resolves with the number of documents that changed. */
183
+ sync(): Promise<number>;
184
+ setAutoSync(on: boolean): void;
185
+ /** Documents that differ between the replicas. */
186
+ differences(): number;
187
+ }
188
+ declare global {
189
+ interface Window {
190
+ /** Set in two-user mode. */
191
+ __havenTwoUsers?: TwoUserTestHost;
192
+ }
193
+ }
194
+ declare function mountTwoUserTestHost(options: Omit<CreateBrowserTestHostOptions, "frame"> & {
195
+ container?: HTMLElement;
196
+ title?: string;
197
+ users?: readonly [TestHostUser, TestHostUser];
198
+ }, createHost: (options: CreateBrowserTestHostOptions) => BrowserTestHost): TwoUserTestHost;
199
+
155
200
  /**
156
201
  * A stand-in Haven for a real browser: the app runs in an iframe, exactly as Haven frames
157
202
  * it, and talks to the same in-memory mock host the Vitest helpers use.
@@ -244,6 +289,14 @@ interface BrowserTestHost {
244
289
  setEnforceCapabilities(enforce: boolean): void;
245
290
  /** Replaces the usernames of the tenant directory (`directory.listUsers()`). */
246
291
  setDirectoryUsers(users: readonly string[]): void;
292
+ /**
293
+ * Another device edits a document and the change syncs in: the app's live queries
294
+ * update. With Automerge-backed databases (`automerge=1` / `automerge: true`) the
295
+ * edit is made at `input.json.baseHeads` by another actor and merged, so it is
296
+ * concurrent to app saves at the same heads. See
297
+ * `MockMindooDBAppSessionController.applyRemoteUpdate`.
298
+ */
299
+ applyRemoteUpdate(databaseId: string, docId: string, input: MindooDBAppUpdateDocumentInput, options?: MockRemoteUpdateOptions): Promise<MindooDBAppDocument>;
247
300
  /** Reloads the app frame. The mock data survives; the app's in-memory state does not. */
248
301
  reloadApp(): void;
249
302
  dispose(): void;
@@ -271,6 +324,8 @@ interface MockDatabasesFromDefinitionOptions {
271
324
  * `"none"`: the mock's stateless default.
272
325
  */
273
326
  attachments?: "memory" | "none";
327
+ /** Back documents with real Automerge documents (`MockMindooDBAppDatabaseDefinition.automerge`). */
328
+ automerge?: boolean;
274
329
  }
275
330
  /**
276
331
  * Mock databases for every database a `haven-app.json` declares, granted as requested
@@ -284,10 +339,13 @@ declare function mockDatabasesFromDefinition(definition: Pick<MindooDBAppDefinit
284
339
  * - `enforce=1` turns the capability checks on
285
340
  * - `users=<count>` fills the directory with generated users
286
341
  * - `locale=<tag>`, `theme=dark|light`
342
+ * - `automerge=1` backs every database with real Automerge documents (concurrent
343
+ * `baseHeads` merges, real heads); `automerge=0` turns it off
287
344
  */
288
345
  interface TestHostUrlSettings {
289
346
  overrides: Record<string, MockDatabaseOverride>;
290
347
  enforceCapabilities?: boolean;
348
+ automerge?: boolean;
291
349
  directoryUserCount?: number;
292
350
  locale?: string;
293
351
  theme?: "dark" | "light";
@@ -305,11 +363,19 @@ interface MountHavenTestHostOptions extends Omit<CreateBrowserTestHostOptions, "
305
363
  label: string;
306
364
  }>;
307
365
  /**
308
- * Read `db=`, `enforce=`, `users=`, `locale=` and `theme=` from the page URL (see
366
+ * Read `db=`, `enforce=`, `users=`, `locale=`, `theme=` and `automerge=` from the page URL (see
309
367
  * {@link readTestHostUrlSettings}) and keep the URL in sync with the panel. Default
310
368
  * true. URL settings win over the options passed here.
311
369
  */
312
370
  urlSettings?: boolean;
371
+ /**
372
+ * Two app frames side by side, each on its own replica of the databases, merged by
373
+ * "Sync" / auto-sync — for testing concurrent editing by hand. Also `?twoUsers=1`.
374
+ * See {@link mountTwoUserTestHost}.
375
+ */
376
+ twoUsers?: boolean;
377
+ /** Names of the two users in two-user mode (default Anna and Ben). */
378
+ users?: readonly [TestHostUser, TestHostUser];
313
379
  }
314
380
  /** The locales Haven's UI offers; the default of the panel's language switcher. */
315
381
  declare const TEST_HOST_LOCALES: ReadonlyArray<{
@@ -333,6 +399,11 @@ declare function previewJson(value: unknown, maxString?: number, maxItems?: numb
333
399
  * of notifications, previews, scans and requests (click an entry for details).
334
400
  * The returned host is also available as `window.__havenTestHost`.
335
401
  */
402
+ /**
403
+ * "Single user" / "Two users": links to the same test page with or without
404
+ * `twoUsers=1`, keeping the other URL settings (db, enforce, users, locale, …).
405
+ */
406
+ declare function modeSwitch(current: "single" | "two"): HTMLElement;
336
407
  declare function mountHavenTestHost(options: MountHavenTestHostOptions): BrowserTestHost;
337
408
 
338
409
  /**
@@ -413,6 +484,22 @@ interface MockMindooDBAppDatabaseDefinition {
413
484
  * results the same way they would in Haven.
414
485
  */
415
486
  summarySetup?: MindooDBAppSummarySetup | null;
487
+ /**
488
+ * Back every document with a real Automerge document, like Haven: `update`
489
+ * applies `set`/`unset`, `json` (at `json.baseHeads`) and `text` patches as
490
+ * Automerge changes, heads are real Automerge heads, and `applyRemoteUpdate`
491
+ * on the controller writes as another device so concurrent edits truly
492
+ * merge. Off by default (plain JSON with `mock-head-N` heads).
493
+ */
494
+ automerge?: boolean;
495
+ }
496
+ /** Options of `applyRemoteUpdate`. */
497
+ interface MockRemoteUpdateOptions {
498
+ /**
499
+ * Automerge actor id (hex) of the simulated device. Defaults to one fixed
500
+ * "remote" actor; pass different ids to simulate several devices.
501
+ */
502
+ actor?: string;
416
503
  }
417
504
  /**
418
505
  * Stands in for the host-owned sealed channel.
@@ -458,10 +545,22 @@ interface CreateMockMindooDBAppSessionOptions {
458
545
  * `methods.directory` still wins.
459
546
  */
460
547
  directoryUsers?: readonly string[];
548
+ /**
549
+ * Automerge actor (hex) of the app's writes in `automerge: true` databases. Mocks
550
+ * that are synced with each other (`syncMockReplicas`, the test host's two-user
551
+ * mode) need distinct actors, like two devices.
552
+ */
553
+ automergeActor?: string;
461
554
  /** What `session.components.list` offers; see `closeEmbed` on the controller. */
462
555
  components?: MindooDBAppComponentInfo[];
463
556
  /** Called whenever the app opens, moves or closes an embed. */
464
557
  onEmbedChange?: (embeds: readonly MockEmbedState[]) => void;
558
+ /**
559
+ * For an app under test that runs as a component: answers its
560
+ * `session.embedding.lookup` (documents a reference may point at), as Haven would
561
+ * from the host's database. No results without it.
562
+ */
563
+ embeddingLookup?: MockEmbedHostOptions["embeddingLookup"];
465
564
  /**
466
565
  * Answer `embeds.open` with a `container` like a current Haven: with this page
467
566
  * for the SDK to frame (e.g. `about:blank`). Without it the host behaves like an
@@ -497,6 +596,15 @@ interface MockMindooDBAppSessionController {
497
596
  setEnforceCapabilities(enforce: boolean): void;
498
597
  /** Replaces the directory's usernames (see `directoryUsers`). */
499
598
  setDirectoryUsers(users: readonly string[]): void;
599
+ /**
600
+ * Writes `input` to a document as another device would, then syncs it in:
601
+ * live queries update like after any write. With `automerge: true` on the
602
+ * database the edit is made by a different Automerge actor on the history
603
+ * up to `input.json.baseHeads` (the current state when omitted) and merged,
604
+ * so it is truly concurrent to app writes at the same heads. Without it, it
605
+ * is a plain update. Bypasses capability checks (it is not the app writing).
606
+ */
607
+ applyRemoteUpdate(databaseId: string, docId: string, input: MindooDBAppUpdateDocumentInput, options?: MockRemoteUpdateOptions): Promise<MindooDBAppDocument>;
500
608
  emitThemeChange(theme: MindooDBAppHostTheme): void;
501
609
  emitViewportChange(viewport: MindooDBAppViewport): void;
502
610
  emitUiPreferencesChange(uiPreferences: MindooDBAppUiPreferences): void;
@@ -523,6 +631,10 @@ interface MockMindooDBAppSessionController {
523
631
  getEmbeddingFinish(): MockEmbeddingFinish | null;
524
632
  /** As if the embedded component reported (un)saved changes; the app's embed follows. */
525
633
  setEmbedDirty(embedId: string, dirty: boolean): void;
634
+ /** As if the embedded component registered these agent tools (names without prefix). */
635
+ setEmbedAgentTools(embedId: string, names: string[] | null, options?: {
636
+ enabled?: boolean;
637
+ }): void;
526
638
  /** Makes the app's next `embed.save()` fail with this message. */
527
639
  failNextEmbedSave(message: string): void;
528
640
  /** For an app under test that runs as a component: its last `embedding.setDirty`. */
@@ -548,6 +660,20 @@ interface MockIncomingContentInput {
548
660
  }>;
549
661
  }
550
662
 
663
+ type MockReplica = MockMindooDBAppSessionController | FakeBridgeHostController;
664
+ /**
665
+ * How many documents differ between two mocks (missing on one side, other heads, or
666
+ * deleted on one side only): what `syncMockReplicas` would bring over.
667
+ */
668
+ declare function mockReplicaDifferences(a: MockReplica, b: MockReplica): number;
669
+ /**
670
+ * Syncs two mocks like two Haven devices: every document of every database both have
671
+ * is merged both ways (Automerge histories with `automerge: true`, so concurrent edits
672
+ * merge as in Haven; otherwise the newer copy wins), deletions spread, and attachments
673
+ * missing on one side are copied. Give the mocks distinct `automergeActor`s. Returns
674
+ * the number of documents that changed on either side.
675
+ */
676
+ declare function syncMockReplicas(a: MockReplica, b: MockReplica): Promise<number>;
551
677
  declare function createMockMindooDBAppSession(options?: CreateMockMindooDBAppSessionOptions): MockMindooDBAppSessionController;
552
678
  declare function createMockMindooDBAppBridge(options?: CreateMockMindooDBAppSessionOptions): MockMindooDBAppSessionController;
553
679
  type FakeBridgeRequestHandler = (params: unknown, context: {
@@ -622,6 +748,8 @@ interface FakeBridgeHostController {
622
748
  /** See {@link CreateMockMindooDBAppSessionOptions.directoryUsers}. */
623
749
  setDirectoryUsers(users: readonly string[]): void;
624
750
  getDirectoryUsers(): string[];
751
+ /** See {@link MockMindooDBAppSessionController.applyRemoteUpdate}. */
752
+ applyRemoteUpdate(databaseId: string, docId: string, input: MindooDBAppUpdateDocumentInput, options?: MockRemoteUpdateOptions): Promise<MindooDBAppDocument>;
625
753
  /** Embeds the app has open (`session.embeds.open`). */
626
754
  listEmbeds(): MockEmbedState[];
627
755
  /** Closes an embed and pushes the `embed-event` to the app. */
@@ -630,6 +758,13 @@ interface FakeBridgeHostController {
630
758
  getEmbeddingFinish(): MockEmbeddingFinish | null;
631
759
  /** As if the embedded component reported (un)saved changes; pushes the `embed-event`. */
632
760
  setEmbedDirty(embedId: string, dirty: boolean): void;
761
+ /**
762
+ * As if the embedded component registered these agent tools (names without prefix);
763
+ * pushes the `embed-event`. `null` or `[]` withdraws them.
764
+ */
765
+ setEmbedAgentTools(embedId: string, names: string[] | null, options?: {
766
+ enabled?: boolean;
767
+ }): void;
633
768
  /** Makes the app's next `embed.save()` fail with this message. */
634
769
  failNextEmbedSave(message: string): void;
635
770
  /** For an app under test that runs as a component: its last `embedding.setDirty`. */
@@ -647,4 +782,4 @@ interface FakeBridgeHostController {
647
782
  }
648
783
  declare function createFakeBridgeHost(options?: CreateFakeBridgeHostOptions): FakeBridgeHostController;
649
784
 
650
- export { ALL_CAPABILITIES, type BrowserTestHost, type BrowserTestHostLog, type BrowserTestHostScan, type BrowserTestHostScanMode, type CreateBrowserTestHostOptions, type CreateFakeBridgeHostOptions, type CreateMockMindooDBAppSessionOptions, type EvaluatingViewDocument, type FakeBridgeHostController, type FakeBridgePortMessageHandler, type FakeBridgeRequestHandler, type FakeBridgeRpcResponse, type MockAgentCall, type MockAgentCallResult, type MockAgentConsent, type MockAgentFile, type MockAgentHost, type MockAgentHostController, type MockAgentHostOptions, type MockDatabaseOverride, type MockDatabasesFromDefinitionOptions, type MockEmbedState, type MockEmbeddingFinish, MockForbiddenError, type MockIncomingContentInput, type MockMindooDBAppDatabaseDefinition, type MockMindooDBAppSessionController, type MockSealedChannelOptions, type MockSeedDocument, type MountHavenTestHostOptions, TEST_HOST_LOCALES, type TestHostUrlSettings, capabilitiesForDefinitionPermissions, createBrowserTestHost, createEvaluatingViewNavigator, createFakeBridgeHost, createMemoryAttachments, createMockAgentHost, createMockMindooDBAppBridge, createMockMindooDBAppSession, generateDirectoryUsers, loadMindoodbForTesting, mockAgentToolPrefix, mockDatabasesFromDefinition, mountHavenTestHost, previewJson, readTestHostUrlSettings, validateMockAgentTools };
785
+ export { ALL_CAPABILITIES, type BrowserTestHost, type BrowserTestHostLog, type BrowserTestHostScan, type BrowserTestHostScanMode, type CreateBrowserTestHostOptions, type CreateFakeBridgeHostOptions, type CreateMockMindooDBAppSessionOptions, DEFAULT_TEST_HOST_USERS, type EvaluatingViewDocument, type FakeBridgeHostController, type FakeBridgePortMessageHandler, type FakeBridgeRequestHandler, type FakeBridgeRpcResponse, type MockAgentCall, type MockAgentCallResult, type MockAgentConsent, type MockAgentFile, type MockAgentHost, type MockAgentHostController, type MockAgentHostOptions, type MockDatabaseOverride, type MockDatabasesFromDefinitionOptions, type MockEmbedState, type MockEmbeddingFinish, MockForbiddenError, type MockIncomingContentInput, type MockMindooDBAppDatabaseDefinition, type MockMindooDBAppSessionController, type MockRemoteUpdateOptions, type MockSealedChannelOptions, type MockSeedDocument, type MountHavenTestHostOptions, TEST_HOST_LOCALES, type TestHostUrlSettings, type TestHostUser, type TwoUserTestHost, capabilitiesForDefinitionPermissions, createBrowserTestHost, createEvaluatingViewNavigator, createFakeBridgeHost, createMemoryAttachments, createMockAgentHost, createMockMindooDBAppBridge, createMockMindooDBAppSession, generateDirectoryUsers, loadMindoodbForTesting, mockAgentToolPrefix, mockDatabasesFromDefinition, mockReplicaDifferences, modeSwitch, mountHavenTestHost, mountTwoUserTestHost, previewJson, readTestHostUrlSettings, syncMockReplicas, validateMockAgentTools };