@abraca/dabra 0.6.0 → 0.8.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 +747 -66
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +725 -62
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +269 -31
- package/package.json +1 -2
- package/src/{HocuspocusProvider.ts → AbracadabraBaseProvider.ts} +33 -22
- package/src/AbracadabraClient.ts +96 -3
- package/src/AbracadabraProvider.ts +11 -11
- 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/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 +59 -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);
|
|
@@ -163,6 +206,7 @@ declare class AbracadabraClient {
|
|
|
163
206
|
password: string;
|
|
164
207
|
email?: string;
|
|
165
208
|
displayName?: string;
|
|
209
|
+
inviteCode?: string;
|
|
166
210
|
}): Promise<UserProfile>;
|
|
167
211
|
/**
|
|
168
212
|
* Register a new user with an Ed25519 public key (crypto auth).
|
|
@@ -174,6 +218,7 @@ declare class AbracadabraClient {
|
|
|
174
218
|
deviceName?: string;
|
|
175
219
|
displayName?: string;
|
|
176
220
|
email?: string;
|
|
221
|
+
inviteCode?: string;
|
|
177
222
|
}): Promise<UserProfile>;
|
|
178
223
|
/** Login with username + password. Auto-persists returned token. */
|
|
179
224
|
login(opts: {
|
|
@@ -246,8 +291,25 @@ declare class AbracadabraClient {
|
|
|
246
291
|
getUpload(docId: string, uploadId: string): Promise<Blob>;
|
|
247
292
|
/** Delete an upload (requires uploader or document Owner). */
|
|
248
293
|
deleteUpload(docId: string, uploadId: string): Promise<void>;
|
|
294
|
+
/** Create an invite code (requires permission per server config). */
|
|
295
|
+
createInvite(opts?: {
|
|
296
|
+
role?: string;
|
|
297
|
+
maxUses?: number;
|
|
298
|
+
expiresIn?: number;
|
|
299
|
+
}): Promise<InviteRow>;
|
|
300
|
+
/** List invite codes visible to the current user. */
|
|
301
|
+
listInvites(): Promise<InviteRow[]>;
|
|
302
|
+
/** Revoke an invite by its code. */
|
|
303
|
+
revokeInvite(code: string): Promise<void>;
|
|
304
|
+
/** Redeem an invite code for the currently authenticated user. */
|
|
305
|
+
redeemInvite(code: string): Promise<void>;
|
|
249
306
|
/** Health check — no auth required. */
|
|
250
307
|
health(): Promise<HealthStatus>;
|
|
308
|
+
/**
|
|
309
|
+
* Fetch server metadata including the optional `index_doc_id` entry point.
|
|
310
|
+
* No auth required.
|
|
311
|
+
*/
|
|
312
|
+
serverInfo(): Promise<ServerInfo>;
|
|
251
313
|
private request;
|
|
252
314
|
private toError;
|
|
253
315
|
private loadPersistedToken;
|
|
@@ -256,7 +318,7 @@ declare class AbracadabraClient {
|
|
|
256
318
|
}
|
|
257
319
|
//#endregion
|
|
258
320
|
//#region packages/provider/src/AbracadabraProvider.d.ts
|
|
259
|
-
interface AbracadabraProviderConfiguration extends Omit<
|
|
321
|
+
interface AbracadabraProviderConfiguration extends Omit<AbracadabraBaseProviderConfiguration, "url" | "websocketProvider"> {
|
|
260
322
|
/**
|
|
261
323
|
* Subdocument loading strategy.
|
|
262
324
|
* - "lazy" (default) – child providers are created only when explicitly requested.
|
|
@@ -291,10 +353,10 @@ interface AbracadabraProviderConfiguration extends Omit<HocuspocusProviderConfig
|
|
|
291
353
|
/** WebSocket URL. Derived from client.wsUrl if client is provided. */
|
|
292
354
|
url?: string;
|
|
293
355
|
/** Shared WebSocket connection (use when multiplexing multiple root documents). */
|
|
294
|
-
websocketProvider?:
|
|
356
|
+
websocketProvider?: AbracadabraWS;
|
|
295
357
|
}
|
|
296
358
|
/**
|
|
297
|
-
* AbracadabraProvider extends
|
|
359
|
+
* AbracadabraProvider extends AbracadabraBaseProvider with:
|
|
298
360
|
*
|
|
299
361
|
* 1. Subdocument lifecycle – intercepts Y.Doc subdoc events and syncs them
|
|
300
362
|
* with the server via MSG_SUBDOC (4) frames. Child documents get their
|
|
@@ -314,7 +376,7 @@ interface AbracadabraProviderConfiguration extends Omit<HocuspocusProviderConfig
|
|
|
314
376
|
* can gate write operations without a network round-trip. Role is
|
|
315
377
|
* refreshed from the server on every reconnect.
|
|
316
378
|
*/
|
|
317
|
-
declare class AbracadabraProvider extends
|
|
379
|
+
declare class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
318
380
|
effectiveRole: EffectiveRole;
|
|
319
381
|
private _client;
|
|
320
382
|
private offlineStore;
|
|
@@ -426,6 +488,37 @@ declare class Encoder {
|
|
|
426
488
|
bufs: Array<Uint8Array>;
|
|
427
489
|
}
|
|
428
490
|
//#endregion
|
|
491
|
+
//#region packages/provider/src/CloseEvents.d.ts
|
|
492
|
+
interface CloseEvent {
|
|
493
|
+
code: number;
|
|
494
|
+
reason: string;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The server is terminating the connection because a data frame was received
|
|
498
|
+
* that is too large.
|
|
499
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
|
500
|
+
*/
|
|
501
|
+
declare const MessageTooBig: CloseEvent;
|
|
502
|
+
/**
|
|
503
|
+
* The server successfully processed the request, asks that the requester reset
|
|
504
|
+
* its document view, and is not returning any content.
|
|
505
|
+
*/
|
|
506
|
+
declare const ResetConnection: CloseEvent;
|
|
507
|
+
/**
|
|
508
|
+
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
509
|
+
* failed or has not yet been provided.
|
|
510
|
+
*/
|
|
511
|
+
declare const Unauthorized: CloseEvent;
|
|
512
|
+
/**
|
|
513
|
+
* The request contained valid data and was understood by the server, but the server
|
|
514
|
+
* is refusing action.
|
|
515
|
+
*/
|
|
516
|
+
declare const Forbidden: CloseEvent;
|
|
517
|
+
/**
|
|
518
|
+
* The server timed out waiting for the request.
|
|
519
|
+
*/
|
|
520
|
+
declare const ConnectionTimeout: CloseEvent;
|
|
521
|
+
//#endregion
|
|
429
522
|
//#region node_modules/lib0/decoding.d.ts
|
|
430
523
|
/**
|
|
431
524
|
* A Decoder handles the decoding of an Uint8Array.
|
|
@@ -518,6 +611,16 @@ declare class UpdateMessage extends OutgoingMessage {
|
|
|
518
611
|
}
|
|
519
612
|
//#endregion
|
|
520
613
|
//#region packages/provider/src/types.d.ts
|
|
614
|
+
/**
|
|
615
|
+
* State of the WebSocket connection.
|
|
616
|
+
* https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
|
|
617
|
+
*/
|
|
618
|
+
declare enum WsReadyStates {
|
|
619
|
+
Connecting = 0,
|
|
620
|
+
Open = 1,
|
|
621
|
+
Closing = 2,
|
|
622
|
+
Closed = 3
|
|
623
|
+
}
|
|
521
624
|
declare enum MessageType {
|
|
522
625
|
Sync = 0,
|
|
523
626
|
Awareness = 1,
|
|
@@ -661,14 +764,55 @@ interface HealthStatus {
|
|
|
661
764
|
version: string;
|
|
662
765
|
active_documents: number;
|
|
663
766
|
}
|
|
767
|
+
interface ServerInfo {
|
|
768
|
+
/** Human-readable server name set by the operator. */
|
|
769
|
+
name?: string;
|
|
770
|
+
/** Server version string. */
|
|
771
|
+
version?: string;
|
|
772
|
+
/** Entry-point document ID advertised by the server, if configured. */
|
|
773
|
+
index_doc_id?: string;
|
|
774
|
+
}
|
|
775
|
+
interface SearchResult {
|
|
776
|
+
docId: string;
|
|
777
|
+
/** Number of matching trigrams — higher is better. */
|
|
778
|
+
score: number;
|
|
779
|
+
}
|
|
780
|
+
interface InviteRow {
|
|
781
|
+
code: string;
|
|
782
|
+
createdBy: string | null;
|
|
783
|
+
role: string;
|
|
784
|
+
maxUses: number;
|
|
785
|
+
useCount: number;
|
|
786
|
+
expiresAt: number | null;
|
|
787
|
+
revoked: boolean;
|
|
788
|
+
createdAt: number;
|
|
789
|
+
}
|
|
790
|
+
type UploadQueueStatus = "pending" | "uploading" | "done" | "error";
|
|
791
|
+
interface UploadQueueEntry {
|
|
792
|
+
/** Client-generated UUID. */
|
|
793
|
+
id: string;
|
|
794
|
+
docId: string;
|
|
795
|
+
/** File or Blob to upload. File extends Blob and survives IDB as Blob. */
|
|
796
|
+
file: Blob;
|
|
797
|
+
/** Eagerly captured filename (from File.name or explicit arg). */
|
|
798
|
+
filename: string;
|
|
799
|
+
status: UploadQueueStatus;
|
|
800
|
+
createdAt: number;
|
|
801
|
+
error?: string;
|
|
802
|
+
}
|
|
664
803
|
//#endregion
|
|
665
|
-
//#region packages/provider/src/
|
|
666
|
-
type
|
|
804
|
+
//#region packages/provider/src/AbracadabraWS.d.ts
|
|
805
|
+
type AbracadabraWebSocketConn = WebSocket & {
|
|
667
806
|
identifier: string;
|
|
668
807
|
};
|
|
669
|
-
|
|
670
|
-
type
|
|
671
|
-
|
|
808
|
+
/** @deprecated Use AbracadabraWebSocketConn */
|
|
809
|
+
type HocuspocusWebSocket = AbracadabraWebSocketConn;
|
|
810
|
+
/** @deprecated Use AbracadabraWebSocketConn */
|
|
811
|
+
type HocusPocusWebSocket = AbracadabraWebSocketConn;
|
|
812
|
+
type AbracadabraWSConfiguration = Required<Pick<CompleteAbracadabraWSConfiguration, "url">> & Partial<CompleteAbracadabraWSConfiguration>;
|
|
813
|
+
/** @deprecated Use AbracadabraWSConfiguration */
|
|
814
|
+
type HocuspocusProviderWebsocketConfiguration = AbracadabraWSConfiguration;
|
|
815
|
+
interface CompleteAbracadabraWSConfiguration {
|
|
672
816
|
/**
|
|
673
817
|
* Whether to connect automatically when creating the provider instance. Default=true
|
|
674
818
|
*/
|
|
@@ -736,12 +880,14 @@ interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
736
880
|
/**
|
|
737
881
|
* Map of attached providers keyed by documentName.
|
|
738
882
|
*/
|
|
739
|
-
providerMap: Map<string,
|
|
883
|
+
providerMap: Map<string, AbracadabraBaseProvider>;
|
|
740
884
|
}
|
|
741
|
-
|
|
885
|
+
/** @deprecated Use CompleteAbracadabraWSConfiguration */
|
|
886
|
+
type CompleteHocuspocusProviderWebsocketConfiguration = CompleteAbracadabraWSConfiguration;
|
|
887
|
+
declare class AbracadabraWS extends EventEmitter {
|
|
742
888
|
private messageQueue;
|
|
743
|
-
configuration:
|
|
744
|
-
webSocket:
|
|
889
|
+
configuration: CompleteAbracadabraWSConfiguration;
|
|
890
|
+
webSocket: AbracadabraWebSocketConn | null;
|
|
745
891
|
webSocketHandlers: {
|
|
746
892
|
[key: string]: any;
|
|
747
893
|
};
|
|
@@ -754,15 +900,15 @@ declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
754
900
|
resolve: (value?: any) => void;
|
|
755
901
|
reject: (reason?: any) => void;
|
|
756
902
|
} | null;
|
|
757
|
-
constructor(configuration:
|
|
903
|
+
constructor(configuration: AbracadabraWSConfiguration);
|
|
758
904
|
receivedOnOpenPayload?: Event | undefined;
|
|
759
905
|
onOpen(event: Event): Promise<void>;
|
|
760
|
-
attach(provider:
|
|
761
|
-
detach(provider:
|
|
762
|
-
setConfiguration(configuration?: Partial<
|
|
906
|
+
attach(provider: AbracadabraBaseProvider): void;
|
|
907
|
+
detach(provider: AbracadabraBaseProvider): void;
|
|
908
|
+
setConfiguration(configuration?: Partial<AbracadabraWSConfiguration>): void;
|
|
763
909
|
cancelWebsocketRetry?: () => void;
|
|
764
910
|
connect(): Promise<unknown>;
|
|
765
|
-
attachWebSocketListeners(ws:
|
|
911
|
+
attachWebSocketListeners(ws: AbracadabraWebSocketConn, reject: Function): void;
|
|
766
912
|
cleanupWebSocket(): void;
|
|
767
913
|
createWebSocketConnection(): Promise<unknown>;
|
|
768
914
|
onMessage(event: MessageEvent): void;
|
|
@@ -780,10 +926,16 @@ declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
780
926
|
}: onCloseParameters): void;
|
|
781
927
|
destroy(): void;
|
|
782
928
|
}
|
|
929
|
+
/** @deprecated Use AbracadabraWS */
|
|
930
|
+
declare const HocuspocusProviderWebsocket: typeof AbracadabraWS;
|
|
931
|
+
/** @deprecated Use AbracadabraWS */
|
|
932
|
+
type HocuspocusProviderWebsocket = AbracadabraWS;
|
|
783
933
|
//#endregion
|
|
784
|
-
//#region packages/provider/src/
|
|
785
|
-
type
|
|
786
|
-
|
|
934
|
+
//#region packages/provider/src/AbracadabraBaseProvider.d.ts
|
|
935
|
+
type AbracadabraBaseProviderConfiguration = Required<Pick<CompleteAbracadabraBaseProviderConfiguration, "name">> & Partial<CompleteAbracadabraBaseProviderConfiguration> & ((Required<Pick<CompleteAbracadabraWSConfiguration, "url">> & Partial<Pick<CompleteAbracadabraWSConfiguration, "preserveTrailingSlash">>) | Required<Pick<CompleteAbracadabraBaseProviderConfiguration, "websocketProvider">>);
|
|
936
|
+
/** @deprecated Use AbracadabraBaseProviderConfiguration */
|
|
937
|
+
type HocuspocusProviderConfiguration = AbracadabraBaseProviderConfiguration;
|
|
938
|
+
interface CompleteAbracadabraBaseProviderConfiguration {
|
|
787
939
|
/**
|
|
788
940
|
* The identifier/name of your document
|
|
789
941
|
*/
|
|
@@ -798,17 +950,17 @@ interface CompleteHocuspocusProviderConfiguration {
|
|
|
798
950
|
* You can disable sharing awareness information by passing `null`.
|
|
799
951
|
* Note that having no awareness information shared across all connections will break our ping checks
|
|
800
952
|
* 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 `
|
|
953
|
+
* socket connection, or ensure that the Provider receives messages before running into `AbracadabraWS.messageReconnectTimeout`.
|
|
802
954
|
*/
|
|
803
955
|
awareness: Awareness | null;
|
|
804
956
|
/**
|
|
805
|
-
* A token that
|
|
957
|
+
* A token that's sent to the backend for authentication purposes.
|
|
806
958
|
*/
|
|
807
959
|
token: string | (() => string) | (() => Promise<string>) | null;
|
|
808
960
|
/**
|
|
809
|
-
*
|
|
961
|
+
* Abracadabra websocket provider
|
|
810
962
|
*/
|
|
811
|
-
websocketProvider:
|
|
963
|
+
websocketProvider: AbracadabraWS;
|
|
812
964
|
/**
|
|
813
965
|
* Force syncing the document in the defined interval.
|
|
814
966
|
*/
|
|
@@ -830,11 +982,13 @@ interface CompleteHocuspocusProviderConfiguration {
|
|
|
830
982
|
onStateless: (data: onStatelessParameters) => void;
|
|
831
983
|
onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
|
|
832
984
|
}
|
|
985
|
+
/** @deprecated Use CompleteAbracadabraBaseProviderConfiguration */
|
|
986
|
+
type CompleteHocuspocusProviderConfiguration = CompleteAbracadabraBaseProviderConfiguration;
|
|
833
987
|
declare class AwarenessError extends Error {
|
|
834
988
|
code: number;
|
|
835
989
|
}
|
|
836
|
-
declare class
|
|
837
|
-
configuration:
|
|
990
|
+
declare class AbracadabraBaseProvider extends EventEmitter {
|
|
991
|
+
configuration: CompleteAbracadabraBaseProviderConfiguration;
|
|
838
992
|
isSynced: boolean;
|
|
839
993
|
unsyncedChanges: number;
|
|
840
994
|
isAuthenticated: boolean;
|
|
@@ -842,7 +996,7 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
842
996
|
manageSocket: boolean;
|
|
843
997
|
private _isAttached;
|
|
844
998
|
intervals: any;
|
|
845
|
-
constructor(configuration:
|
|
999
|
+
constructor(configuration: AbracadabraBaseProviderConfiguration);
|
|
846
1000
|
boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
|
|
847
1001
|
boundAwarenessUpdateHandler: ({
|
|
848
1002
|
added,
|
|
@@ -858,7 +1012,7 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
858
1012
|
forwardDisconnect: (e: onDisconnectParameters) => this;
|
|
859
1013
|
forwardDestroy: () => this;
|
|
860
1014
|
forwardRateLimited: () => this;
|
|
861
|
-
setConfiguration(configuration?: Partial<
|
|
1015
|
+
setConfiguration(configuration?: Partial<AbracadabraBaseProviderConfiguration>): void;
|
|
862
1016
|
get document(): Y.Doc;
|
|
863
1017
|
get isAttached(): boolean;
|
|
864
1018
|
get awareness(): Awareness | null;
|
|
@@ -901,6 +1055,10 @@ declare class HocuspocusProvider extends EventEmitter {
|
|
|
901
1055
|
authenticatedHandler(scope: string): void;
|
|
902
1056
|
setAwarenessField(key: string, value: any): void;
|
|
903
1057
|
}
|
|
1058
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
1059
|
+
declare const HocuspocusProvider: typeof AbracadabraBaseProvider;
|
|
1060
|
+
/** @deprecated Use AbracadabraBaseProvider */
|
|
1061
|
+
type HocuspocusProvider = AbracadabraBaseProvider;
|
|
904
1062
|
//#endregion
|
|
905
1063
|
//#region packages/provider/src/OfflineStore.d.ts
|
|
906
1064
|
/**
|
|
@@ -957,6 +1115,23 @@ declare class OfflineStore {
|
|
|
957
1115
|
destroy(): void;
|
|
958
1116
|
}
|
|
959
1117
|
//#endregion
|
|
1118
|
+
//#region packages/provider/src/auth.d.ts
|
|
1119
|
+
declare enum AuthMessageType {
|
|
1120
|
+
Token = 0,
|
|
1121
|
+
PermissionDenied = 1,
|
|
1122
|
+
Authenticated = 2
|
|
1123
|
+
}
|
|
1124
|
+
declare const writeAuthentication: (encoder: Encoder, auth: string) => void;
|
|
1125
|
+
declare const writePermissionDenied: (encoder: Encoder, reason: string) => void;
|
|
1126
|
+
declare const writeAuthenticated: (encoder: Encoder, scope: AuthorizedScope) => void;
|
|
1127
|
+
declare const writeTokenSyncRequest: (encoder: Encoder) => void;
|
|
1128
|
+
declare const readAuthMessage: (decoder: Decoder, sendToken: () => void, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
|
|
1129
|
+
//#endregion
|
|
1130
|
+
//#region packages/provider/src/awarenessStatesToArray.d.ts
|
|
1131
|
+
declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
|
|
1132
|
+
clientId: number;
|
|
1133
|
+
}[];
|
|
1134
|
+
//#endregion
|
|
960
1135
|
//#region packages/provider/src/OutgoingMessages/SubdocMessage.d.ts
|
|
961
1136
|
/**
|
|
962
1137
|
* Registers a new subdocument with the Abracadabra server.
|
|
@@ -1029,4 +1204,67 @@ declare class CryptoIdentityKeystore {
|
|
|
1029
1204
|
clear(): Promise<void>;
|
|
1030
1205
|
}
|
|
1031
1206
|
//#endregion
|
|
1032
|
-
|
|
1207
|
+
//#region packages/provider/src/SearchIndex.d.ts
|
|
1208
|
+
declare class SearchIndex {
|
|
1209
|
+
private readonly origin;
|
|
1210
|
+
private dbPromise;
|
|
1211
|
+
private db;
|
|
1212
|
+
constructor(serverOrigin: string);
|
|
1213
|
+
private getDb;
|
|
1214
|
+
/**
|
|
1215
|
+
* Replace the index for docId with the given texts.
|
|
1216
|
+
* Old trigram associations are removed before new ones are added.
|
|
1217
|
+
*/
|
|
1218
|
+
index(docId: string, texts: string[]): Promise<void>;
|
|
1219
|
+
/** Remove all indexed content for a document. */
|
|
1220
|
+
remove(docId: string): Promise<void>;
|
|
1221
|
+
/**
|
|
1222
|
+
* Search for documents matching the query.
|
|
1223
|
+
* Returns results sorted by score (matching trigram count) descending.
|
|
1224
|
+
*/
|
|
1225
|
+
search(query: string, limit?: number): Promise<SearchResult[]>;
|
|
1226
|
+
destroy(): void;
|
|
1227
|
+
}
|
|
1228
|
+
//#endregion
|
|
1229
|
+
//#region packages/provider/src/FileBlobStore.d.ts
|
|
1230
|
+
declare class FileBlobStore extends EventEmitter {
|
|
1231
|
+
private readonly origin;
|
|
1232
|
+
private readonly client;
|
|
1233
|
+
private dbPromise;
|
|
1234
|
+
private db;
|
|
1235
|
+
/** Tracks active object URLs so we can revoke them on destroy. */
|
|
1236
|
+
private readonly objectUrls;
|
|
1237
|
+
/** Prevents concurrent flush runs. */
|
|
1238
|
+
private _flushing;
|
|
1239
|
+
private readonly _onlineHandler;
|
|
1240
|
+
constructor(serverOrigin: string, client: AbracadabraClient);
|
|
1241
|
+
private getDb;
|
|
1242
|
+
private blobKey;
|
|
1243
|
+
/**
|
|
1244
|
+
* Return a local object URL for a file.
|
|
1245
|
+
* On first call the blob is downloaded from the server and cached in IDB.
|
|
1246
|
+
* Returns null when offline and the blob is not yet cached, or when
|
|
1247
|
+
* URL.createObjectURL is unavailable (e.g. Node.js / SSR).
|
|
1248
|
+
*/
|
|
1249
|
+
getBlobUrl(docId: string, uploadId: string): Promise<string | null>;
|
|
1250
|
+
/** Revoke the object URL and remove the blob from cache. */
|
|
1251
|
+
evictBlob(docId: string, uploadId: string): Promise<void>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Queue a file for upload. Works offline — the entry is persisted to IDB
|
|
1254
|
+
* and flushed the next time the queue is flushed.
|
|
1255
|
+
* Returns the generated queue entry id.
|
|
1256
|
+
*/
|
|
1257
|
+
queueUpload(docId: string, file: File | Blob, filename?: string): Promise<string>;
|
|
1258
|
+
/** Return all upload queue entries. */
|
|
1259
|
+
getQueue(): Promise<UploadQueueEntry[]>;
|
|
1260
|
+
/**
|
|
1261
|
+
* Upload all pending queue entries via AbracadabraClient.
|
|
1262
|
+
* Safe to call repeatedly — a concurrent call is a no-op.
|
|
1263
|
+
* Entries that fail are marked with status "error" and left in the queue.
|
|
1264
|
+
*/
|
|
1265
|
+
flushQueue(): Promise<void>;
|
|
1266
|
+
private _updateQueueEntry;
|
|
1267
|
+
destroy(): void;
|
|
1268
|
+
}
|
|
1269
|
+
//#endregion
|
|
1270
|
+
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, InviteRow, 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.8.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;
|