mindoodb-app-sdk 0.0.65 → 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.
- package/README.md +70 -0
- package/TESTING.md +38 -1
- package/dist/{chunk-BE7LLFFE.js → chunk-B3K3I2S2.js} +185 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/testing/index.d.ts +97 -2
- package/dist/testing/index.js +833 -164
- package/dist/{types-BeRUxGKN.d.ts → types-Cuw-0Iou.d.ts} +121 -2
- package/package.json +3 -3
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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.
|
|
@@ -323,6 +368,14 @@ interface MountHavenTestHostOptions extends Omit<CreateBrowserTestHostOptions, "
|
|
|
323
368
|
* true. URL settings win over the options passed here.
|
|
324
369
|
*/
|
|
325
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];
|
|
326
379
|
}
|
|
327
380
|
/** The locales Haven's UI offers; the default of the panel's language switcher. */
|
|
328
381
|
declare const TEST_HOST_LOCALES: ReadonlyArray<{
|
|
@@ -346,6 +399,11 @@ declare function previewJson(value: unknown, maxString?: number, maxItems?: numb
|
|
|
346
399
|
* of notifications, previews, scans and requests (click an entry for details).
|
|
347
400
|
* The returned host is also available as `window.__havenTestHost`.
|
|
348
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;
|
|
349
407
|
declare function mountHavenTestHost(options: MountHavenTestHostOptions): BrowserTestHost;
|
|
350
408
|
|
|
351
409
|
/**
|
|
@@ -487,10 +545,22 @@ interface CreateMockMindooDBAppSessionOptions {
|
|
|
487
545
|
* `methods.directory` still wins.
|
|
488
546
|
*/
|
|
489
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;
|
|
490
554
|
/** What `session.components.list` offers; see `closeEmbed` on the controller. */
|
|
491
555
|
components?: MindooDBAppComponentInfo[];
|
|
492
556
|
/** Called whenever the app opens, moves or closes an embed. */
|
|
493
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"];
|
|
494
564
|
/**
|
|
495
565
|
* Answer `embeds.open` with a `container` like a current Haven: with this page
|
|
496
566
|
* for the SDK to frame (e.g. `about:blank`). Without it the host behaves like an
|
|
@@ -561,6 +631,10 @@ interface MockMindooDBAppSessionController {
|
|
|
561
631
|
getEmbeddingFinish(): MockEmbeddingFinish | null;
|
|
562
632
|
/** As if the embedded component reported (un)saved changes; the app's embed follows. */
|
|
563
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;
|
|
564
638
|
/** Makes the app's next `embed.save()` fail with this message. */
|
|
565
639
|
failNextEmbedSave(message: string): void;
|
|
566
640
|
/** For an app under test that runs as a component: its last `embedding.setDirty`. */
|
|
@@ -586,6 +660,20 @@ interface MockIncomingContentInput {
|
|
|
586
660
|
}>;
|
|
587
661
|
}
|
|
588
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>;
|
|
589
677
|
declare function createMockMindooDBAppSession(options?: CreateMockMindooDBAppSessionOptions): MockMindooDBAppSessionController;
|
|
590
678
|
declare function createMockMindooDBAppBridge(options?: CreateMockMindooDBAppSessionOptions): MockMindooDBAppSessionController;
|
|
591
679
|
type FakeBridgeRequestHandler = (params: unknown, context: {
|
|
@@ -670,6 +758,13 @@ interface FakeBridgeHostController {
|
|
|
670
758
|
getEmbeddingFinish(): MockEmbeddingFinish | null;
|
|
671
759
|
/** As if the embedded component reported (un)saved changes; pushes the `embed-event`. */
|
|
672
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;
|
|
673
768
|
/** Makes the app's next `embed.save()` fail with this message. */
|
|
674
769
|
failNextEmbedSave(message: string): void;
|
|
675
770
|
/** For an app under test that runs as a component: its last `embedding.setDirty`. */
|
|
@@ -687,4 +782,4 @@ interface FakeBridgeHostController {
|
|
|
687
782
|
}
|
|
688
783
|
declare function createFakeBridgeHost(options?: CreateFakeBridgeHostOptions): FakeBridgeHostController;
|
|
689
784
|
|
|
690
|
-
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 MockRemoteUpdateOptions, 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 };
|