@abraca/dabra 2.7.0 → 2.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 +41 -4
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +41 -5
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +25 -2
- package/package.json +2 -2
- package/src/DocUtils.ts +62 -3
- package/src/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -5264,6 +5264,15 @@ declare function toPlain(val: unknown): unknown;
|
|
|
5264
5264
|
* omitted; `null` is kept (a real value, e.g. top-level `parentId`).
|
|
5265
5265
|
*/
|
|
5266
5266
|
declare function makeEntryMap(fields: Record<string, unknown>): Y.Map<unknown>;
|
|
5267
|
+
/**
|
|
5268
|
+
* A label is a "placeholder" — i.e. carries no real user title — when it is
|
|
5269
|
+
* empty/whitespace, null/undefined, or the literal `"Untitled"` sentinel
|
|
5270
|
+
* (case-insensitive, so `"untitled"` from a `labelToFilename` round-trip is
|
|
5271
|
+
* caught too). The whole tree-label corruption class boils down to a
|
|
5272
|
+
* placeholder being allowed to overwrite a real title; `patchEntry` refuses
|
|
5273
|
+
* exactly that. Mirrors cou-sh's `isEmptyTreeLabel`.
|
|
5274
|
+
*/
|
|
5275
|
+
declare function isPlaceholderLabel(label: unknown): boolean;
|
|
5267
5276
|
/**
|
|
5268
5277
|
* Patch an EXISTING entry's fields per-key on its nested `Y.Map`, so a
|
|
5269
5278
|
* concurrent edit to a *different* field by a peer is preserved instead
|
|
@@ -5279,7 +5288,21 @@ declare function makeEntryMap(fields: Record<string, unknown>): Y.Map<unknown>;
|
|
|
5279
5288
|
* Self-transacting: it batches its writes in one `Y.Doc` transaction
|
|
5280
5289
|
* (a safe reentrant no-op join when already inside one), so callers
|
|
5281
5290
|
* don't need to pass or own a transaction.
|
|
5291
|
+
*
|
|
5292
|
+
* ── NO-DESTROY LABEL INVARIANT ──────────────────────────────────────────
|
|
5293
|
+
* A `label` patch that is a placeholder (empty/whitespace/"Untitled") is
|
|
5294
|
+
* DROPPED when the entry already holds a real (non-placeholder) label —
|
|
5295
|
+
* regardless of which consumer (cou-sh title-sync, fs-sync rename
|
|
5296
|
+
* detection, MCP, table renderers, a stale snapshot) tried it. This is the
|
|
5297
|
+
* source-of-truth guard against the "card title silently becomes Untitled
|
|
5298
|
+
* / files renamed to untitled.md" corruption: a placeholder must never win
|
|
5299
|
+
* over a real title. Creating a brand-new entry with an empty label (e.g.
|
|
5300
|
+
* a fresh kanban card) is still allowed — the guard only fires when a real
|
|
5301
|
+
* label already exists. Pass `{ allowLabelClear: true }` to override (the
|
|
5302
|
+
* single legitimate "user explicitly cleared it" path).
|
|
5282
5303
|
*/
|
|
5283
|
-
declare function patchEntry(treeMap: Y.Map<unknown>, id: string, patch: Record<string, unknown>, removeKeys?: string[]
|
|
5304
|
+
declare function patchEntry(treeMap: Y.Map<unknown>, id: string, patch: Record<string, unknown>, removeKeys?: string[], opts?: {
|
|
5305
|
+
allowLabelClear?: boolean;
|
|
5306
|
+
}): void;
|
|
5284
5307
|
//#endregion
|
|
5285
|
-
export { AbracadabraBaseProvider, AbracadabraBaseProviderConfiguration, AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AbracadabraWS, AbracadabraWSConfiguration, AbracadabraWebRTC, type AbracadabraWebRTCConfiguration, AbracadabraWebSocketConn, AdminConfigField, AdminConfigOriginKind, AuditLogEntry, AuditQueryOpts, AuditVerifyResult, AuthFailureContext, AuthFailureReason, AuthMessageType, AuthorizedScope, AwarenessError, BackgroundSyncManager, type BackgroundSyncManagerOptions, BackgroundSyncPersistence, BroadcastChannelSync, CHANNEL_NAMES, ChannelKeyResolver, type ChatChannel, ChatClient, type ChatClientTransport, type MarkReadInput as ChatMarkReadInput, type ChatMessage, type ChatReadCursor, type ChatReadReceipt, type ChatTypingEvent, type ChildrenPage, CloseEvent, CompleteAbracadabraBaseProviderConfiguration, CompleteAbracadabraWSConfiguration, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, ConnectionTimeout, Constructable, ConstructableOutgoingMessage, ContentManager, type CreateNotificationInput, CryptoIdentity, CryptoIdentityKeystore, DEFAULT_FILE_CHUNK_SIZE, DEFAULT_ICE_SERVERS, DataChannelRouter, type DeleteMessageInput, DevicePairingChannel, type DevicePairingConfig, DeviceRegistrationService, type DeviceServerStatus, type DeviceSessionRecord, type DeviceSessionStorage, type DeviceTier, type DocEncryptionInfo, DocKeyManager, DocSearchHit, type DocSyncState, type DocumentBlock, DocumentCache, type DocumentCacheOptions, type DocumentContent, DocumentManager, type DocumentManagerConfig, DocumentMeta, type DocumentMetaInfo, type DocumentMetaWire, E2EAbracadabraProvider, E2EEChannel, type E2EEIdentity, E2EOfflineStore, type EditMessageInput, EffectivePermissionEntry, EffectivePermissionsResponse, EffectiveRole, EncryptedChatClient, EncryptedYMap, EncryptedYText, EnvSnapshotExtension, EnvSnapshotItem, EnvSnapshotResponse, type FetchInboxInput, type FetchNotificationsInput, FileBlobStore, FileTransferChannel, FileTransferHandle, type FileTransferMeta, type FileTransferStatus, type FoldedMessage, Forbidden, GEO_TYPE_META_SCHEMAS, type GetChatHistoryInput, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, type IdentityDeviceEntry, type IdentityDocConfiguration, IdentityDocProvider, type IdentityProfile, type IdentityServerEntry, type IdentitySpaceEntry, type InboxEntry, type MarkReadInput$1 as InboxMarkReadInput, InviteRow, KEY_EXCHANGE_CHANNEL, Kind, LocalStorageDeviceSessionStorage, ManualSignaling, type ManualSignalingBlob, type MessageRecord, MessageTooBig, MessageType, MetaFieldType, MetaManager, MetaValidationError, type NotificationReadUpdate, type NotificationRecord, NotificationsClient, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PAGE_TYPES, PageMeta, PageTypeInfo, PageTypeMetaField, type PairingRequest, type PairingResult, PeerConnection, type PeerInfo, type PeerState, PendingSubdoc, PermissionEntry, PublicKeyInfo, QUERY_PREFIX, QueryClient, QueryError, type QueryFrame, type QueryKind, type QuerySpec, type QuerySubscriptionHandle, type QuerySubscriptionHandlers, type QueryTransport, RPC_PREFIX, ReadyzStatus, ResetConnection, type RpcCallHandle, type RpcCallOptions, RpcClient, RpcError, type RpcErrorCode, type RpcErrorPayload, type RpcFrame, type RpcHandler, type RpcHandlerContext, type RpcKind, type RpcTarget, type RpcTransport, SERVER_ROOT_ID, type SchemaDocTypeName, type SchemaMetaOf, type SchemaRegistryLike, type SchemaValidatorLike, SearchIndex, SearchResult, type SendChatMessageInput, type SendMessageInput, type SendMessageResult, ServerInfo, type SignalingIncoming, type SignalingOutgoing, SignalingSocket, SnapshotCreateResult, SnapshotData, SnapshotFileEntry, SnapshotForkResult, SnapshotMeta, SnapshotRestoreResult, StatesArray, SubdocMessage, SubdocRegisteredEvent, TYPE_ALIASES, TokenManager, type TokenManagerOptions, TreeEntry, TreeManager, TreeNode, TreeSearchResult, TypedDocTypeMismatchError, type TypedDocsClient, type TypedTreeEntry, Unauthorized, UploadInfo, UploadMeta, UploadQueueEntry, UploadQueueStatus, UserMetaField, UserProfile, WebSocketStatus, WsReadyStates, YjsDataChannel, attachUpdatedAtObserver, awarenessStatesToArray, wordlist as bip39Wordlist, buildBlockquoteElement, buildBlocksFromMarkdown, buildBulletListElement, buildCodeBlockElement, buildHeadingElement, buildHorizontalRuleElement, buildOrderedListElement, buildParagraphElement, buildTaskListElement, decryptChatContent, decryptField, deriveIdentityDocId, deriveSeedWrappingKey, encryptChatContent, encryptField, filenameToLabel, foldRecords, generateMnemonic, isEncryptedContent, makeEncryptedYMap, makeEncryptedYText, makeEntryMap, mnemonicToEd25519Seed, mnemonicToKeyPair, normalizeRootId, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onCompactedParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onServerErrorParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters, parseFrontmatter, patchEntry, populateYDocFromMarkdown, readAuthMessage, readBlocksFromFragment, recordFromYAny, resolvePageType, toPlain, unwrapSeed, validateMnemonic, waitForSync, withTimeout, wrapSeed, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest, yjsToMarkdown };
|
|
5308
|
+
export { AbracadabraBaseProvider, AbracadabraBaseProviderConfiguration, AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AbracadabraWS, AbracadabraWSConfiguration, AbracadabraWebRTC, type AbracadabraWebRTCConfiguration, AbracadabraWebSocketConn, AdminConfigField, AdminConfigOriginKind, AuditLogEntry, AuditQueryOpts, AuditVerifyResult, AuthFailureContext, AuthFailureReason, AuthMessageType, AuthorizedScope, AwarenessError, BackgroundSyncManager, type BackgroundSyncManagerOptions, BackgroundSyncPersistence, BroadcastChannelSync, CHANNEL_NAMES, ChannelKeyResolver, type ChatChannel, ChatClient, type ChatClientTransport, type MarkReadInput as ChatMarkReadInput, type ChatMessage, type ChatReadCursor, type ChatReadReceipt, type ChatTypingEvent, type ChildrenPage, CloseEvent, CompleteAbracadabraBaseProviderConfiguration, CompleteAbracadabraWSConfiguration, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, ConnectionTimeout, Constructable, ConstructableOutgoingMessage, ContentManager, type CreateNotificationInput, CryptoIdentity, CryptoIdentityKeystore, DEFAULT_FILE_CHUNK_SIZE, DEFAULT_ICE_SERVERS, DataChannelRouter, type DeleteMessageInput, DevicePairingChannel, type DevicePairingConfig, DeviceRegistrationService, type DeviceServerStatus, type DeviceSessionRecord, type DeviceSessionStorage, type DeviceTier, type DocEncryptionInfo, DocKeyManager, DocSearchHit, type DocSyncState, type DocumentBlock, DocumentCache, type DocumentCacheOptions, type DocumentContent, DocumentManager, type DocumentManagerConfig, DocumentMeta, type DocumentMetaInfo, type DocumentMetaWire, E2EAbracadabraProvider, E2EEChannel, type E2EEIdentity, E2EOfflineStore, type EditMessageInput, EffectivePermissionEntry, EffectivePermissionsResponse, EffectiveRole, EncryptedChatClient, EncryptedYMap, EncryptedYText, EnvSnapshotExtension, EnvSnapshotItem, EnvSnapshotResponse, type FetchInboxInput, type FetchNotificationsInput, FileBlobStore, FileTransferChannel, FileTransferHandle, type FileTransferMeta, type FileTransferStatus, type FoldedMessage, Forbidden, GEO_TYPE_META_SCHEMAS, type GetChatHistoryInput, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, type IdentityDeviceEntry, type IdentityDocConfiguration, IdentityDocProvider, type IdentityProfile, type IdentityServerEntry, type IdentitySpaceEntry, type InboxEntry, type MarkReadInput$1 as InboxMarkReadInput, InviteRow, KEY_EXCHANGE_CHANNEL, Kind, LocalStorageDeviceSessionStorage, ManualSignaling, type ManualSignalingBlob, type MessageRecord, MessageTooBig, MessageType, MetaFieldType, MetaManager, MetaValidationError, type NotificationReadUpdate, type NotificationRecord, NotificationsClient, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PAGE_TYPES, PageMeta, PageTypeInfo, PageTypeMetaField, type PairingRequest, type PairingResult, PeerConnection, type PeerInfo, type PeerState, PendingSubdoc, PermissionEntry, PublicKeyInfo, QUERY_PREFIX, QueryClient, QueryError, type QueryFrame, type QueryKind, type QuerySpec, type QuerySubscriptionHandle, type QuerySubscriptionHandlers, type QueryTransport, RPC_PREFIX, ReadyzStatus, ResetConnection, type RpcCallHandle, type RpcCallOptions, RpcClient, RpcError, type RpcErrorCode, type RpcErrorPayload, type RpcFrame, type RpcHandler, type RpcHandlerContext, type RpcKind, type RpcTarget, type RpcTransport, SERVER_ROOT_ID, type SchemaDocTypeName, type SchemaMetaOf, type SchemaRegistryLike, type SchemaValidatorLike, SearchIndex, SearchResult, type SendChatMessageInput, type SendMessageInput, type SendMessageResult, ServerInfo, type SignalingIncoming, type SignalingOutgoing, SignalingSocket, SnapshotCreateResult, SnapshotData, SnapshotFileEntry, SnapshotForkResult, SnapshotMeta, SnapshotRestoreResult, StatesArray, SubdocMessage, SubdocRegisteredEvent, TYPE_ALIASES, TokenManager, type TokenManagerOptions, TreeEntry, TreeManager, TreeNode, TreeSearchResult, TypedDocTypeMismatchError, type TypedDocsClient, type TypedTreeEntry, Unauthorized, UploadInfo, UploadMeta, UploadQueueEntry, UploadQueueStatus, UserMetaField, UserProfile, WebSocketStatus, WsReadyStates, YjsDataChannel, attachUpdatedAtObserver, awarenessStatesToArray, wordlist as bip39Wordlist, buildBlockquoteElement, buildBlocksFromMarkdown, buildBulletListElement, buildCodeBlockElement, buildHeadingElement, buildHorizontalRuleElement, buildOrderedListElement, buildParagraphElement, buildTaskListElement, decryptChatContent, decryptField, deriveIdentityDocId, deriveSeedWrappingKey, encryptChatContent, encryptField, filenameToLabel, foldRecords, generateMnemonic, isEncryptedContent, isPlaceholderLabel, makeEncryptedYMap, makeEncryptedYText, makeEntryMap, mnemonicToEd25519Seed, mnemonicToKeyPair, normalizeRootId, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onCompactedParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onServerErrorParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters, parseFrontmatter, patchEntry, populateYDocFromMarkdown, readAuthMessage, readBlocksFromFragment, recordFromYAny, resolvePageType, toPlain, unwrapSeed, validateMnemonic, waitForSync, withTimeout, wrapSeed, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest, yjsToMarkdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yjs": "^13.6.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@abraca/schema": "2.
|
|
44
|
+
"@abraca/schema": "2.8.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
package/src/DocUtils.ts
CHANGED
|
@@ -104,6 +104,20 @@ export function makeEntryMap(
|
|
|
104
104
|
return m;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A label is a "placeholder" — i.e. carries no real user title — when it is
|
|
109
|
+
* empty/whitespace, null/undefined, or the literal `"Untitled"` sentinel
|
|
110
|
+
* (case-insensitive, so `"untitled"` from a `labelToFilename` round-trip is
|
|
111
|
+
* caught too). The whole tree-label corruption class boils down to a
|
|
112
|
+
* placeholder being allowed to overwrite a real title; `patchEntry` refuses
|
|
113
|
+
* exactly that. Mirrors cou-sh's `isEmptyTreeLabel`.
|
|
114
|
+
*/
|
|
115
|
+
export function isPlaceholderLabel(label: unknown): boolean {
|
|
116
|
+
if (typeof label !== "string") return label == null;
|
|
117
|
+
const t = label.trim();
|
|
118
|
+
return t === "" || t.toLowerCase() === "untitled";
|
|
119
|
+
}
|
|
120
|
+
|
|
107
121
|
/**
|
|
108
122
|
* Patch an EXISTING entry's fields per-key on its nested `Y.Map`, so a
|
|
109
123
|
* concurrent edit to a *different* field by a peer is preserved instead
|
|
@@ -119,17 +133,62 @@ export function makeEntryMap(
|
|
|
119
133
|
* Self-transacting: it batches its writes in one `Y.Doc` transaction
|
|
120
134
|
* (a safe reentrant no-op join when already inside one), so callers
|
|
121
135
|
* don't need to pass or own a transaction.
|
|
136
|
+
*
|
|
137
|
+
* ── NO-DESTROY LABEL INVARIANT ──────────────────────────────────────────
|
|
138
|
+
* A `label` patch that is a placeholder (empty/whitespace/"Untitled") is
|
|
139
|
+
* DROPPED when the entry already holds a real (non-placeholder) label —
|
|
140
|
+
* regardless of which consumer (cou-sh title-sync, fs-sync rename
|
|
141
|
+
* detection, MCP, table renderers, a stale snapshot) tried it. This is the
|
|
142
|
+
* source-of-truth guard against the "card title silently becomes Untitled
|
|
143
|
+
* / files renamed to untitled.md" corruption: a placeholder must never win
|
|
144
|
+
* over a real title. Creating a brand-new entry with an empty label (e.g.
|
|
145
|
+
* a fresh kanban card) is still allowed — the guard only fires when a real
|
|
146
|
+
* label already exists. Pass `{ allowLabelClear: true }` to override (the
|
|
147
|
+
* single legitimate "user explicitly cleared it" path).
|
|
122
148
|
*/
|
|
123
149
|
export function patchEntry(
|
|
124
150
|
treeMap: Y.Map<unknown>,
|
|
125
151
|
id: string,
|
|
126
152
|
patch: Record<string, unknown>,
|
|
127
153
|
removeKeys: string[] = [],
|
|
154
|
+
opts: { allowLabelClear?: boolean } = {},
|
|
128
155
|
): void {
|
|
129
156
|
const apply = (): void => {
|
|
130
157
|
const raw = treeMap.get(id);
|
|
158
|
+
|
|
159
|
+
// NO-DESTROY label guard: strip a placeholder `label` from the patch
|
|
160
|
+
// when a real label already exists on the entry. The existing-label
|
|
161
|
+
// read is DUCK-TYPED (not `instanceof Y.Map`): under a host that
|
|
162
|
+
// resolves a second physical yjs (cou-sh's local file-link), a
|
|
163
|
+
// foreign Y.Map fails `instanceof` and would read `undefined` —
|
|
164
|
+
// disabling the guard in the very environment that needs it. `.get`
|
|
165
|
+
// / `.toJSON` work regardless of which yjs constructed the map.
|
|
166
|
+
let effectivePatch = patch;
|
|
167
|
+
if (
|
|
168
|
+
!opts.allowLabelClear &&
|
|
169
|
+
Object.hasOwn(patch, "label") &&
|
|
170
|
+
isPlaceholderLabel(patch.label)
|
|
171
|
+
) {
|
|
172
|
+
let existingLabel: unknown;
|
|
173
|
+
if (raw != null && typeof (raw as { get?: unknown }).get === "function") {
|
|
174
|
+
existingLabel = (raw as Y.Map<unknown>).get("label");
|
|
175
|
+
} else if (
|
|
176
|
+
raw != null &&
|
|
177
|
+
typeof (raw as { toJSON?: unknown }).toJSON === "function"
|
|
178
|
+
) {
|
|
179
|
+
existingLabel = ((raw as { toJSON: () => Record<string, unknown> }).toJSON())
|
|
180
|
+
?.label;
|
|
181
|
+
} else if (raw != null && typeof raw === "object") {
|
|
182
|
+
existingLabel = (raw as Record<string, unknown>).label;
|
|
183
|
+
}
|
|
184
|
+
if (!isPlaceholderLabel(existingLabel)) {
|
|
185
|
+
const { label: _dropped, ...rest } = patch;
|
|
186
|
+
effectivePatch = rest;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
131
190
|
if (raw instanceof Y.Map) {
|
|
132
|
-
for (const [k, v] of Object.entries(
|
|
191
|
+
for (const [k, v] of Object.entries(effectivePatch)) {
|
|
133
192
|
if (v === undefined) raw.delete(k);
|
|
134
193
|
else raw.set(k, v);
|
|
135
194
|
}
|
|
@@ -138,8 +197,8 @@ export function patchEntry(
|
|
|
138
197
|
}
|
|
139
198
|
const base =
|
|
140
199
|
raw == null ? {} : (toPlain(raw) as Record<string, unknown>);
|
|
141
|
-
const merged: Record<string, unknown> = { ...base, ...
|
|
142
|
-
for (const [k, v] of Object.entries(
|
|
200
|
+
const merged: Record<string, unknown> = { ...base, ...effectivePatch };
|
|
201
|
+
for (const [k, v] of Object.entries(effectivePatch)) {
|
|
143
202
|
if (v === undefined) delete merged[k];
|
|
144
203
|
}
|
|
145
204
|
for (const k of removeKeys) delete merged[k];
|