@abraca/dabra 0.5.0 → 0.7.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.
- package/dist/abracadabra-provider.cjs +737 -81
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +715 -77
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +246 -31
- package/package.json +1 -2
- package/src/{HocuspocusProvider.ts → AbracadabraBaseProvider.ts} +33 -22
- package/src/AbracadabraClient.ts +69 -3
- package/src/AbracadabraProvider.ts +18 -14
- package/src/{HocuspocusProviderWebsocket.ts → AbracadabraWS.ts} +36 -22
- package/src/CloseEvents.ts +49 -0
- package/src/DocumentCache.ts +210 -0
- package/src/FileBlobStore.ts +300 -0
- package/src/MessageReceiver.ts +8 -8
- package/src/OfflineStore.ts +11 -5
- package/src/OutgoingMessages/AuthenticationMessage.ts +1 -1
- package/src/SearchIndex.ts +247 -0
- package/src/auth.ts +62 -0
- package/src/awarenessStatesToArray.ts +10 -0
- package/src/index.ts +9 -2
- package/src/types.ts +46 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Event, MessageEvent } from "ws";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
|
-
import { CloseEvent } from "@abraca/dabra-common";
|
|
4
3
|
|
|
5
4
|
//#region node_modules/lib0/observable.d.ts
|
|
6
5
|
/**
|
|
@@ -132,6 +131,42 @@ declare class EventEmitter {
|
|
|
132
131
|
removeAllListeners(): void;
|
|
133
132
|
}
|
|
134
133
|
//#endregion
|
|
134
|
+
//#region packages/provider/src/DocumentCache.d.ts
|
|
135
|
+
interface DocumentCacheOptions {
|
|
136
|
+
/** How long cached entries remain valid. Default: 5 minutes. */
|
|
137
|
+
ttlMs?: number;
|
|
138
|
+
}
|
|
139
|
+
declare class DocumentCache {
|
|
140
|
+
private readonly origin;
|
|
141
|
+
private readonly ttlMs;
|
|
142
|
+
private dbPromise;
|
|
143
|
+
private db;
|
|
144
|
+
constructor(serverOrigin: string, opts?: DocumentCacheOptions);
|
|
145
|
+
private getDb;
|
|
146
|
+
private isExpired;
|
|
147
|
+
private getWithTtl;
|
|
148
|
+
private setWithTtl;
|
|
149
|
+
private deleteKey;
|
|
150
|
+
getDoc(docId: string): Promise<DocumentMeta | null>;
|
|
151
|
+
setDoc(meta: DocumentMeta): Promise<void>;
|
|
152
|
+
invalidateDoc(docId: string): Promise<void>;
|
|
153
|
+
getChildren(parentId: string): Promise<string[] | null>;
|
|
154
|
+
setChildren(parentId: string, items: string[]): Promise<void>;
|
|
155
|
+
invalidateChildren(parentId: string): Promise<void>;
|
|
156
|
+
getProfile(userId: string): Promise<UserProfile | null>;
|
|
157
|
+
setProfile(profile: UserProfile): Promise<void>;
|
|
158
|
+
/** Get the cached profile for the currently authenticated user. */
|
|
159
|
+
getCurrentProfile(): Promise<UserProfile | null>;
|
|
160
|
+
/** Cache a profile both by its ID and as the current user. */
|
|
161
|
+
setCurrentProfile(profile: UserProfile): Promise<void>;
|
|
162
|
+
getPermissions(docId: string): Promise<PermissionEntry[] | null>;
|
|
163
|
+
setPermissions(docId: string, items: PermissionEntry[]): Promise<void>;
|
|
164
|
+
getUploads(docId: string): Promise<UploadInfo[] | null>;
|
|
165
|
+
setUploads(docId: string, items: UploadInfo[]): Promise<void>;
|
|
166
|
+
invalidateUploads(docId: string): Promise<void>;
|
|
167
|
+
destroy(): void;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
135
170
|
//#region packages/provider/src/AbracadabraClient.d.ts
|
|
136
171
|
interface AbracadabraClientConfig {
|
|
137
172
|
/** Server base URL (http or https). WebSocket URL is derived automatically. */
|
|
@@ -144,6 +179,13 @@ interface AbracadabraClientConfig {
|
|
|
144
179
|
storageKey?: string;
|
|
145
180
|
/** Custom fetch implementation (useful for Node.js or testing). */
|
|
146
181
|
fetch?: typeof globalThis.fetch;
|
|
182
|
+
/**
|
|
183
|
+
* Optional metadata cache. When provided, read methods (getDoc, listChildren,
|
|
184
|
+
* getMe, listPermissions, listUploads) check the cache before hitting the
|
|
185
|
+
* network. Write methods (deleteDoc, upload, deleteUpload) invalidate affected
|
|
186
|
+
* cache entries automatically.
|
|
187
|
+
*/
|
|
188
|
+
cache?: DocumentCache;
|
|
147
189
|
}
|
|
148
190
|
declare class AbracadabraClient {
|
|
149
191
|
private _token;
|
|
@@ -151,6 +193,7 @@ declare class AbracadabraClient {
|
|
|
151
193
|
private readonly persistAuth;
|
|
152
194
|
private readonly storageKey;
|
|
153
195
|
private readonly _fetch;
|
|
196
|
+
readonly cache: DocumentCache | null;
|
|
154
197
|
constructor(config: AbracadabraClientConfig);
|
|
155
198
|
get token(): string | null;
|
|
156
199
|
set token(value: string | null);
|
|
@@ -248,6 +291,11 @@ declare class AbracadabraClient {
|
|
|
248
291
|
deleteUpload(docId: string, uploadId: string): Promise<void>;
|
|
249
292
|
/** Health check — no auth required. */
|
|
250
293
|
health(): Promise<HealthStatus>;
|
|
294
|
+
/**
|
|
295
|
+
* Fetch server metadata including the optional `index_doc_id` entry point.
|
|
296
|
+
* No auth required.
|
|
297
|
+
*/
|
|
298
|
+
serverInfo(): Promise<ServerInfo>;
|
|
251
299
|
private request;
|
|
252
300
|
private toError;
|
|
253
301
|
private loadPersistedToken;
|
|
@@ -256,7 +304,7 @@ declare class AbracadabraClient {
|
|
|
256
304
|
}
|
|
257
305
|
//#endregion
|
|
258
306
|
//#region packages/provider/src/AbracadabraProvider.d.ts
|
|
259
|
-
interface AbracadabraProviderConfiguration extends Omit<
|
|
307
|
+
interface AbracadabraProviderConfiguration extends Omit<AbracadabraBaseProviderConfiguration, "url" | "websocketProvider"> {
|
|
260
308
|
/**
|
|
261
309
|
* Subdocument loading strategy.
|
|
262
310
|
* - "lazy" (default) – child providers are created only when explicitly requested.
|
|
@@ -291,10 +339,10 @@ interface AbracadabraProviderConfiguration extends Omit<HocuspocusProviderConfig
|
|
|
291
339
|
/** WebSocket URL. Derived from client.wsUrl if client is provided. */
|
|
292
340
|
url?: string;
|
|
293
341
|
/** Shared WebSocket connection (use when multiplexing multiple root documents). */
|
|
294
|
-
websocketProvider?:
|
|
342
|
+
websocketProvider?: AbracadabraWS;
|
|
295
343
|
}
|
|
296
344
|
/**
|
|
297
|
-
* AbracadabraProvider extends
|
|
345
|
+
* AbracadabraProvider extends AbracadabraBaseProvider with:
|
|
298
346
|
*
|
|
299
347
|
* 1. Subdocument lifecycle – intercepts Y.Doc subdoc events and syncs them
|
|
300
348
|
* with the server via MSG_SUBDOC (4) frames. Child documents get their
|
|
@@ -314,7 +362,7 @@ interface AbracadabraProviderConfiguration extends Omit<HocuspocusProviderConfig
|
|
|
314
362
|
* can gate write operations without a network round-trip. Role is
|
|
315
363
|
* refreshed from the server on every reconnect.
|
|
316
364
|
*/
|
|
317
|
-
declare class AbracadabraProvider extends
|
|
365
|
+
declare class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
318
366
|
effectiveRole: EffectiveRole;
|
|
319
367
|
private _client;
|
|
320
368
|
private offlineStore;
|
|
@@ -426,6 +474,37 @@ declare class Encoder {
|
|
|
426
474
|
bufs: Array<Uint8Array>;
|
|
427
475
|
}
|
|
428
476
|
//#endregion
|
|
477
|
+
//#region packages/provider/src/CloseEvents.d.ts
|
|
478
|
+
interface CloseEvent {
|
|
479
|
+
code: number;
|
|
480
|
+
reason: string;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The server is terminating the connection because a data frame was received
|
|
484
|
+
* that is too large.
|
|
485
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
|
486
|
+
*/
|
|
487
|
+
declare const MessageTooBig: CloseEvent;
|
|
488
|
+
/**
|
|
489
|
+
* The server successfully processed the request, asks that the requester reset
|
|
490
|
+
* its document view, and is not returning any content.
|
|
491
|
+
*/
|
|
492
|
+
declare const ResetConnection: CloseEvent;
|
|
493
|
+
/**
|
|
494
|
+
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
495
|
+
* failed or has not yet been provided.
|
|
496
|
+
*/
|
|
497
|
+
declare const Unauthorized: CloseEvent;
|
|
498
|
+
/**
|
|
499
|
+
* The request contained valid data and was understood by the server, but the server
|
|
500
|
+
* is refusing action.
|
|
501
|
+
*/
|
|
502
|
+
declare const Forbidden: CloseEvent;
|
|
503
|
+
/**
|
|
504
|
+
* The server timed out waiting for the request.
|
|
505
|
+
*/
|
|
506
|
+
declare const ConnectionTimeout: CloseEvent;
|
|
507
|
+
//#endregion
|
|
429
508
|
//#region node_modules/lib0/decoding.d.ts
|
|
430
509
|
/**
|
|
431
510
|
* A Decoder handles the decoding of an Uint8Array.
|
|
@@ -518,6 +597,16 @@ declare class UpdateMessage extends OutgoingMessage {
|
|
|
518
597
|
}
|
|
519
598
|
//#endregion
|
|
520
599
|
//#region packages/provider/src/types.d.ts
|
|
600
|
+
/**
|
|
601
|
+
* State of the WebSocket connection.
|
|
602
|
+
* https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
|
|
603
|
+
*/
|
|
604
|
+
declare enum WsReadyStates {
|
|
605
|
+
Connecting = 0,
|
|
606
|
+
Open = 1,
|
|
607
|
+
Closing = 2,
|
|
608
|
+
Closed = 3
|
|
609
|
+
}
|
|
521
610
|
declare enum MessageType {
|
|
522
611
|
Sync = 0,
|
|
523
612
|
Awareness = 1,
|
|
@@ -661,14 +750,45 @@ interface HealthStatus {
|
|
|
661
750
|
version: string;
|
|
662
751
|
active_documents: number;
|
|
663
752
|
}
|
|
753
|
+
interface ServerInfo {
|
|
754
|
+
/** Human-readable server name set by the operator. */
|
|
755
|
+
name?: string;
|
|
756
|
+
/** Server version string. */
|
|
757
|
+
version?: string;
|
|
758
|
+
/** Entry-point document ID advertised by the server, if configured. */
|
|
759
|
+
index_doc_id?: string;
|
|
760
|
+
}
|
|
761
|
+
interface SearchResult {
|
|
762
|
+
docId: string;
|
|
763
|
+
/** Number of matching trigrams — higher is better. */
|
|
764
|
+
score: number;
|
|
765
|
+
}
|
|
766
|
+
type UploadQueueStatus = "pending" | "uploading" | "done" | "error";
|
|
767
|
+
interface UploadQueueEntry {
|
|
768
|
+
/** Client-generated UUID. */
|
|
769
|
+
id: string;
|
|
770
|
+
docId: string;
|
|
771
|
+
/** File or Blob to upload. File extends Blob and survives IDB as Blob. */
|
|
772
|
+
file: Blob;
|
|
773
|
+
/** Eagerly captured filename (from File.name or explicit arg). */
|
|
774
|
+
filename: string;
|
|
775
|
+
status: UploadQueueStatus;
|
|
776
|
+
createdAt: number;
|
|
777
|
+
error?: string;
|
|
778
|
+
}
|
|
664
779
|
//#endregion
|
|
665
|
-
//#region packages/provider/src/
|
|
666
|
-
type
|
|
780
|
+
//#region packages/provider/src/AbracadabraWS.d.ts
|
|
781
|
+
type AbracadabraWebSocketConn = WebSocket & {
|
|
667
782
|
identifier: string;
|
|
668
783
|
};
|
|
669
|
-
|
|
670
|
-
type
|
|
671
|
-
|
|
784
|
+
/** @deprecated Use AbracadabraWebSocketConn */
|
|
785
|
+
type HocuspocusWebSocket = AbracadabraWebSocketConn;
|
|
786
|
+
/** @deprecated Use AbracadabraWebSocketConn */
|
|
787
|
+
type HocusPocusWebSocket = AbracadabraWebSocketConn;
|
|
788
|
+
type AbracadabraWSConfiguration = Required<Pick<CompleteAbracadabraWSConfiguration, "url">> & Partial<CompleteAbracadabraWSConfiguration>;
|
|
789
|
+
/** @deprecated Use AbracadabraWSConfiguration */
|
|
790
|
+
type HocuspocusProviderWebsocketConfiguration = AbracadabraWSConfiguration;
|
|
791
|
+
interface CompleteAbracadabraWSConfiguration {
|
|
672
792
|
/**
|
|
673
793
|
* Whether to connect automatically when creating the provider instance. Default=true
|
|
674
794
|
*/
|
|
@@ -736,12 +856,14 @@ interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
736
856
|
/**
|
|
737
857
|
* Map of attached providers keyed by documentName.
|
|
738
858
|
*/
|
|
739
|
-
providerMap: Map<string,
|
|
859
|
+
providerMap: Map<string, AbracadabraBaseProvider>;
|
|
740
860
|
}
|
|
741
|
-
|
|
861
|
+
/** @deprecated Use CompleteAbracadabraWSConfiguration */
|
|
862
|
+
type CompleteHocuspocusProviderWebsocketConfiguration = CompleteAbracadabraWSConfiguration;
|
|
863
|
+
declare class AbracadabraWS extends EventEmitter {
|
|
742
864
|
private messageQueue;
|
|
743
|
-
configuration:
|
|
744
|
-
webSocket:
|
|
865
|
+
configuration: CompleteAbracadabraWSConfiguration;
|
|
866
|
+
webSocket: AbracadabraWebSocketConn | null;
|
|
745
867
|
webSocketHandlers: {
|
|
746
868
|
[key: string]: any;
|
|
747
869
|
};
|
|
@@ -754,15 +876,15 @@ declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
754
876
|
resolve: (value?: any) => void;
|
|
755
877
|
reject: (reason?: any) => void;
|
|
756
878
|
} | null;
|
|
757
|
-
constructor(configuration:
|
|
879
|
+
constructor(configuration: AbracadabraWSConfiguration);
|
|
758
880
|
receivedOnOpenPayload?: Event | undefined;
|
|
759
881
|
onOpen(event: Event): Promise<void>;
|
|
760
|
-
attach(provider:
|
|
761
|
-
detach(provider:
|
|
762
|
-
setConfiguration(configuration?: Partial<
|
|
882
|
+
attach(provider: AbracadabraBaseProvider): void;
|
|
883
|
+
detach(provider: AbracadabraBaseProvider): void;
|
|
884
|
+
setConfiguration(configuration?: Partial<AbracadabraWSConfiguration>): void;
|
|
763
885
|
cancelWebsocketRetry?: () => void;
|
|
764
886
|
connect(): Promise<unknown>;
|
|
765
|
-
attachWebSocketListeners(ws:
|
|
887
|
+
attachWebSocketListeners(ws: AbracadabraWebSocketConn, reject: Function): void;
|
|
766
888
|
cleanupWebSocket(): void;
|
|
767
889
|
createWebSocketConnection(): Promise<unknown>;
|
|
768
890
|
onMessage(event: MessageEvent): void;
|
|
@@ -780,10 +902,16 @@ declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
780
902
|
}: onCloseParameters): void;
|
|
781
903
|
destroy(): void;
|
|
782
904
|
}
|
|
905
|
+
/** @deprecated Use AbracadabraWS */
|
|
906
|
+
declare const HocuspocusProviderWebsocket: typeof AbracadabraWS;
|
|
907
|
+
/** @deprecated Use AbracadabraWS */
|
|
908
|
+
type HocuspocusProviderWebsocket = AbracadabraWS;
|
|
783
909
|
//#endregion
|
|
784
|
-
//#region packages/provider/src/
|
|
785
|
-
type
|
|
786
|
-
|
|
910
|
+
//#region packages/provider/src/AbracadabraBaseProvider.d.ts
|
|
911
|
+
type AbracadabraBaseProviderConfiguration = Required<Pick<CompleteAbracadabraBaseProviderConfiguration, "name">> & Partial<CompleteAbracadabraBaseProviderConfiguration> & ((Required<Pick<CompleteAbracadabraWSConfiguration, "url">> & Partial<Pick<CompleteAbracadabraWSConfiguration, "preserveTrailingSlash">>) | Required<Pick<CompleteAbracadabraBaseProviderConfiguration, "websocketProvider">>);
|
|
912
|
+
/** @deprecated Use AbracadabraBaseProviderConfiguration */
|
|
913
|
+
type HocuspocusProviderConfiguration = AbracadabraBaseProviderConfiguration;
|
|
914
|
+
interface CompleteAbracadabraBaseProviderConfiguration {
|
|
787
915
|
/**
|
|
788
916
|
* The identifier/name of your document
|
|
789
917
|
*/
|
|
@@ -798,17 +926,17 @@ interface CompleteHocuspocusProviderConfiguration {
|
|
|
798
926
|
* You can disable sharing awareness information by passing `null`.
|
|
799
927
|
* Note that having no awareness information shared across all connections will break our ping checks
|
|
800
928
|
* and thus trigger reconnects. You should always have at least one Provider with enabled awareness per
|
|
801
|
-
* socket connection, or ensure that the Provider receives messages before running into `
|
|
929
|
+
* socket connection, or ensure that the Provider receives messages before running into `AbracadabraWS.messageReconnectTimeout`.
|
|
802
930
|
*/
|
|
803
931
|
awareness: Awareness | null;
|
|
804
932
|
/**
|
|
805
|
-
* A token that
|
|
933
|
+
* A token that's sent to the backend for authentication purposes.
|
|
806
934
|
*/
|
|
807
935
|
token: string | (() => string) | (() => Promise<string>) | null;
|
|
808
936
|
/**
|
|
809
|
-
*
|
|
937
|
+
* Abracadabra websocket provider
|
|
810
938
|
*/
|
|
811
|
-
websocketProvider:
|
|
939
|
+
websocketProvider: AbracadabraWS;
|
|
812
940
|
/**
|
|
813
941
|
* Force syncing the document in the defined interval.
|
|
814
942
|
*/
|
|
@@ -830,11 +958,13 @@ interface CompleteHocuspocusProviderConfiguration {
|
|
|
830
958
|
onStateless: (data: onStatelessParameters) => void;
|
|
831
959
|
onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
|
|
832
960
|
}
|
|
961
|
+
/** @deprecated Use CompleteAbracadabraBaseProviderConfiguration */
|
|
962
|
+
type CompleteHocuspocusProviderConfiguration = CompleteAbracadabraBaseProviderConfiguration;
|
|
833
963
|
declare class AwarenessError extends Error {
|
|
834
964
|
code: number;
|
|
835
965
|
}
|
|
836
|
-
declare class
|
|
837
|
-
configuration:
|
|
966
|
+
declare class AbracadabraBaseProvider extends EventEmitter {
|
|
967
|
+
configuration: CompleteAbracadabraBaseProviderConfiguration;
|
|
838
968
|
isSynced: boolean;
|
|
839
969
|
unsyncedChanges: number;
|
|
840
970
|
isAuthenticated: boolean;
|
|
@@ -842,7 +972,7 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
842
972
|
manageSocket: boolean;
|
|
843
973
|
private _isAttached;
|
|
844
974
|
intervals: any;
|
|
845
|
-
constructor(configuration:
|
|
975
|
+
constructor(configuration: AbracadabraBaseProviderConfiguration);
|
|
846
976
|
boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
|
|
847
977
|
boundAwarenessUpdateHandler: ({
|
|
848
978
|
added,
|
|
@@ -858,7 +988,7 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
858
988
|
forwardDisconnect: (e: onDisconnectParameters) => this;
|
|
859
989
|
forwardDestroy: () => this;
|
|
860
990
|
forwardRateLimited: () => this;
|
|
861
|
-
setConfiguration(configuration?: Partial<
|
|
991
|
+
setConfiguration(configuration?: Partial<AbracadabraBaseProviderConfiguration>): void;
|
|
862
992
|
get document(): Y.Doc;
|
|
863
993
|
get isAttached(): boolean;
|
|
864
994
|
get awareness(): Awareness | null;
|
|
@@ -901,6 +1031,10 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
901
1031
|
authenticatedHandler(scope: string): void;
|
|
902
1032
|
setAwarenessField(key: string, value: any): void;
|
|
903
1033
|
}
|
|
1034
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
1035
|
+
declare const HocuspocusProvider: typeof AbracadabraBaseProvider;
|
|
1036
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
1037
|
+
type HocuspocusProvider = AbracadabraBaseProvider;
|
|
904
1038
|
//#endregion
|
|
905
1039
|
//#region packages/provider/src/OfflineStore.d.ts
|
|
906
1040
|
/**
|
|
@@ -933,6 +1067,7 @@ declare class OfflineStore {
|
|
|
933
1067
|
* per-server, preventing cross-server data contamination.
|
|
934
1068
|
*/
|
|
935
1069
|
constructor(docId: string, serverOrigin?: string);
|
|
1070
|
+
private dbPromise;
|
|
936
1071
|
private getDb;
|
|
937
1072
|
persistUpdate(update: Uint8Array): Promise<void>;
|
|
938
1073
|
getPendingUpdates(): Promise<Uint8Array[]>;
|
|
@@ -956,6 +1091,23 @@ declare class OfflineStore {
|
|
|
956
1091
|
destroy(): void;
|
|
957
1092
|
}
|
|
958
1093
|
//#endregion
|
|
1094
|
+
//#region packages/provider/src/auth.d.ts
|
|
1095
|
+
declare enum AuthMessageType {
|
|
1096
|
+
Token = 0,
|
|
1097
|
+
PermissionDenied = 1,
|
|
1098
|
+
Authenticated = 2
|
|
1099
|
+
}
|
|
1100
|
+
declare const writeAuthentication: (encoder: Encoder, auth: string) => void;
|
|
1101
|
+
declare const writePermissionDenied: (encoder: Encoder, reason: string) => void;
|
|
1102
|
+
declare const writeAuthenticated: (encoder: Encoder, scope: AuthorizedScope) => void;
|
|
1103
|
+
declare const writeTokenSyncRequest: (encoder: Encoder) => void;
|
|
1104
|
+
declare const readAuthMessage: (decoder: Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region packages/provider/src/awarenessStatesToArray.d.ts
|
|
1107
|
+
declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
|
|
1108
|
+
clientId: number;
|
|
1109
|
+
}[];
|
|
1110
|
+
//#endregion
|
|
959
1111
|
//#region packages/provider/src/OutgoingMessages/SubdocMessage.d.ts
|
|
960
1112
|
/**
|
|
961
1113
|
* Registers a new subdocument with the Abracadabra server.
|
|
@@ -1028,4 +1180,67 @@ declare class CryptoIdentityKeystore {
|
|
|
1028
1180
|
clear(): Promise<void>;
|
|
1029
1181
|
}
|
|
1030
1182
|
//#endregion
|
|
1031
|
-
|
|
1183
|
+
//#region packages/provider/src/SearchIndex.d.ts
|
|
1184
|
+
declare class SearchIndex {
|
|
1185
|
+
private readonly origin;
|
|
1186
|
+
private dbPromise;
|
|
1187
|
+
private db;
|
|
1188
|
+
constructor(serverOrigin: string);
|
|
1189
|
+
private getDb;
|
|
1190
|
+
/**
|
|
1191
|
+
* Replace the index for docId with the given texts.
|
|
1192
|
+
* Old trigram associations are removed before new ones are added.
|
|
1193
|
+
*/
|
|
1194
|
+
index(docId: string, texts: string[]): Promise<void>;
|
|
1195
|
+
/** Remove all indexed content for a document. */
|
|
1196
|
+
remove(docId: string): Promise<void>;
|
|
1197
|
+
/**
|
|
1198
|
+
* Search for documents matching the query.
|
|
1199
|
+
* Returns results sorted by score (matching trigram count) descending.
|
|
1200
|
+
*/
|
|
1201
|
+
search(query: string, limit?: number): Promise<SearchResult[]>;
|
|
1202
|
+
destroy(): void;
|
|
1203
|
+
}
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region packages/provider/src/FileBlobStore.d.ts
|
|
1206
|
+
declare class FileBlobStore extends EventEmitter {
|
|
1207
|
+
private readonly origin;
|
|
1208
|
+
private readonly client;
|
|
1209
|
+
private dbPromise;
|
|
1210
|
+
private db;
|
|
1211
|
+
/** Tracks active object URLs so we can revoke them on destroy. */
|
|
1212
|
+
private readonly objectUrls;
|
|
1213
|
+
/** Prevents concurrent flush runs. */
|
|
1214
|
+
private _flushing;
|
|
1215
|
+
private readonly _onlineHandler;
|
|
1216
|
+
constructor(serverOrigin: string, client: AbracadabraClient);
|
|
1217
|
+
private getDb;
|
|
1218
|
+
private blobKey;
|
|
1219
|
+
/**
|
|
1220
|
+
* Return a local object URL for a file.
|
|
1221
|
+
* On first call the blob is downloaded from the server and cached in IDB.
|
|
1222
|
+
* Returns null when offline and the blob is not yet cached, or when
|
|
1223
|
+
* URL.createObjectURL is unavailable (e.g. Node.js / SSR).
|
|
1224
|
+
*/
|
|
1225
|
+
getBlobUrl(docId: string, uploadId: string): Promise<string | null>;
|
|
1226
|
+
/** Revoke the object URL and remove the blob from cache. */
|
|
1227
|
+
evictBlob(docId: string, uploadId: string): Promise<void>;
|
|
1228
|
+
/**
|
|
1229
|
+
* Queue a file for upload. Works offline — the entry is persisted to IDB
|
|
1230
|
+
* and flushed the next time the queue is flushed.
|
|
1231
|
+
* Returns the generated queue entry id.
|
|
1232
|
+
*/
|
|
1233
|
+
queueUpload(docId: string, file: File | Blob, filename?: string): Promise<string>;
|
|
1234
|
+
/** Return all upload queue entries. */
|
|
1235
|
+
getQueue(): Promise<UploadQueueEntry[]>;
|
|
1236
|
+
/**
|
|
1237
|
+
* Upload all pending queue entries via AbracadabraClient.
|
|
1238
|
+
* Safe to call repeatedly — a concurrent call is a no-op.
|
|
1239
|
+
* Entries that fail are marked with status "error" and left in the queue.
|
|
1240
|
+
*/
|
|
1241
|
+
flushQueue(): Promise<void>;
|
|
1242
|
+
private _updateQueueEntry;
|
|
1243
|
+
destroy(): void;
|
|
1244
|
+
}
|
|
1245
|
+
//#endregion
|
|
1246
|
+
export { AbracadabraBaseProvider, AbracadabraBaseProviderConfiguration, AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AbracadabraWS, AbracadabraWSConfiguration, AbracadabraWebSocketConn, AuthMessageType, AuthorizedScope, AwarenessError, CloseEvent, CompleteAbracadabraBaseProviderConfiguration, CompleteAbracadabraWSConfiguration, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, ConnectionTimeout, Constructable, ConstructableOutgoingMessage, CryptoIdentity, CryptoIdentityKeystore, DocumentCache, type DocumentCacheOptions, DocumentMeta, EffectiveRole, FileBlobStore, Forbidden, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, MessageTooBig, MessageType, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PendingSubdoc, PermissionEntry, PublicKeyInfo, ResetConnection, SearchIndex, SearchResult, ServerInfo, StatesArray, SubdocMessage, SubdocRegisteredEvent, Unauthorized, UploadInfo, UploadMeta, UploadQueueEntry, UploadQueueStatus, UserProfile, WebSocketStatus, WsReadyStates, awarenessStatesToArray, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters, readAuthMessage, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@abraca/dabra-common": "^0.1.1",
|
|
32
31
|
"@lifeomic/attempt": "^3.1.0",
|
|
33
32
|
"@noble/ed25519": "^2.3.0",
|
|
34
33
|
"@noble/hashes": "^1.8.0",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { awarenessStatesToArray } from "
|
|
1
|
+
import { awarenessStatesToArray } from "./awarenessStatesToArray.ts";
|
|
2
2
|
import type { Event, MessageEvent } from "ws";
|
|
3
3
|
import { Awareness, removeAwarenessStates } from "y-protocols/awareness";
|
|
4
4
|
import * as Y from "yjs";
|
|
5
5
|
import EventEmitter from "./EventEmitter.ts";
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
6
|
+
import type { CompleteAbracadabraWSConfiguration } from "./AbracadabraWS.ts";
|
|
7
|
+
import { AbracadabraWS } from "./AbracadabraWS.ts";
|
|
8
8
|
import { IncomingMessage } from "./IncomingMessage.ts";
|
|
9
9
|
import { MessageReceiver } from "./MessageReceiver.ts";
|
|
10
10
|
import { MessageSender } from "./MessageSender.ts";
|
|
@@ -31,17 +31,20 @@ import type {
|
|
|
31
31
|
onUnsyncedChangesParameters,
|
|
32
32
|
} from "./types.ts";
|
|
33
33
|
|
|
34
|
-
export type
|
|
35
|
-
Pick<
|
|
34
|
+
export type AbracadabraBaseProviderConfiguration = Required<
|
|
35
|
+
Pick<CompleteAbracadabraBaseProviderConfiguration, "name">
|
|
36
36
|
> &
|
|
37
|
-
Partial<
|
|
37
|
+
Partial<CompleteAbracadabraBaseProviderConfiguration> &
|
|
38
38
|
(
|
|
39
|
-
| (Required<Pick<
|
|
40
|
-
Partial<Pick<
|
|
41
|
-
| Required<Pick<
|
|
39
|
+
| (Required<Pick<CompleteAbracadabraWSConfiguration, "url">> &
|
|
40
|
+
Partial<Pick<CompleteAbracadabraWSConfiguration, "preserveTrailingSlash">>)
|
|
41
|
+
| Required<Pick<CompleteAbracadabraBaseProviderConfiguration, "websocketProvider">>
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
/** @deprecated Use AbracadabraBaseProviderConfiguration */
|
|
45
|
+
export type HocuspocusProviderConfiguration = AbracadabraBaseProviderConfiguration;
|
|
46
|
+
|
|
47
|
+
export interface CompleteAbracadabraBaseProviderConfiguration {
|
|
45
48
|
/**
|
|
46
49
|
* The identifier/name of your document
|
|
47
50
|
*/
|
|
@@ -57,19 +60,19 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
57
60
|
* You can disable sharing awareness information by passing `null`.
|
|
58
61
|
* Note that having no awareness information shared across all connections will break our ping checks
|
|
59
62
|
* and thus trigger reconnects. You should always have at least one Provider with enabled awareness per
|
|
60
|
-
* socket connection, or ensure that the Provider receives messages before running into `
|
|
63
|
+
* socket connection, or ensure that the Provider receives messages before running into `AbracadabraWS.messageReconnectTimeout`.
|
|
61
64
|
*/
|
|
62
65
|
awareness: Awareness | null;
|
|
63
66
|
|
|
64
67
|
/**
|
|
65
|
-
* A token that
|
|
68
|
+
* A token that's sent to the backend for authentication purposes.
|
|
66
69
|
*/
|
|
67
70
|
token: string | (() => string) | (() => Promise<string>) | null;
|
|
68
71
|
|
|
69
72
|
/**
|
|
70
|
-
*
|
|
73
|
+
* Abracadabra websocket provider
|
|
71
74
|
*/
|
|
72
|
-
websocketProvider:
|
|
75
|
+
websocketProvider: AbracadabraWS;
|
|
73
76
|
|
|
74
77
|
/**
|
|
75
78
|
* Force syncing the document in the defined interval.
|
|
@@ -94,12 +97,15 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
94
97
|
onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
|
|
95
98
|
}
|
|
96
99
|
|
|
100
|
+
/** @deprecated Use CompleteAbracadabraBaseProviderConfiguration */
|
|
101
|
+
export type CompleteHocuspocusProviderConfiguration = CompleteAbracadabraBaseProviderConfiguration;
|
|
102
|
+
|
|
97
103
|
export class AwarenessError extends Error {
|
|
98
104
|
code = 1001;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
export class
|
|
102
|
-
public configuration:
|
|
107
|
+
export class AbracadabraBaseProvider extends EventEmitter {
|
|
108
|
+
public configuration: CompleteAbracadabraBaseProviderConfiguration = {
|
|
103
109
|
name: "",
|
|
104
110
|
// @ts-ignore
|
|
105
111
|
document: undefined,
|
|
@@ -142,7 +148,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
142
148
|
forceSync: null,
|
|
143
149
|
};
|
|
144
150
|
|
|
145
|
-
constructor(configuration:
|
|
151
|
+
constructor(configuration: AbracadabraBaseProviderConfiguration) {
|
|
146
152
|
super();
|
|
147
153
|
this.setConfiguration(configuration);
|
|
148
154
|
|
|
@@ -220,11 +226,11 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
220
226
|
|
|
221
227
|
forwardRateLimited = () => this.emit("rateLimited");
|
|
222
228
|
|
|
223
|
-
public setConfiguration(configuration: Partial<
|
|
229
|
+
public setConfiguration(configuration: Partial<AbracadabraBaseProviderConfiguration> = {}): void {
|
|
224
230
|
if (!configuration.websocketProvider) {
|
|
225
231
|
this.manageSocket = true;
|
|
226
|
-
this.configuration.websocketProvider = new
|
|
227
|
-
configuration as
|
|
232
|
+
this.configuration.websocketProvider = new AbracadabraWS(
|
|
233
|
+
configuration as CompleteAbracadabraWSConfiguration,
|
|
228
234
|
);
|
|
229
235
|
}
|
|
230
236
|
|
|
@@ -366,7 +372,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
366
372
|
}
|
|
367
373
|
|
|
368
374
|
console.warn(
|
|
369
|
-
"
|
|
375
|
+
"AbracadabraBaseProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.",
|
|
370
376
|
);
|
|
371
377
|
}
|
|
372
378
|
|
|
@@ -376,7 +382,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
376
382
|
}
|
|
377
383
|
|
|
378
384
|
console.warn(
|
|
379
|
-
"
|
|
385
|
+
"AbracadabraBaseProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.",
|
|
380
386
|
);
|
|
381
387
|
}
|
|
382
388
|
|
|
@@ -553,3 +559,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
553
559
|
this.awareness.setLocalStateField(key, value);
|
|
554
560
|
}
|
|
555
561
|
}
|
|
562
|
+
|
|
563
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
564
|
+
export const HocuspocusProvider = AbracadabraBaseProvider;
|
|
565
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
566
|
+
export type HocuspocusProvider = AbracadabraBaseProvider;
|