@tearleads/client-sdk 0.1.207 → 0.1.208

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.
Files changed (46) hide show
  1. package/client/documents/index.d.ts +8 -0
  2. package/client/documents/index.js +14 -1
  3. package/client/documents/index.js.map +1 -1
  4. package/client/index.d.ts +1 -1
  5. package/client/index.js.map +1 -1
  6. package/data/documents/documentRestore.d.ts +30 -0
  7. package/data/documents/documentRestore.js +77 -0
  8. package/data/documents/documentRestore.js.map +1 -0
  9. package/data/documents/documentRowList.d.ts +6 -0
  10. package/data/documents/documentRowList.js +31 -0
  11. package/data/documents/documentRowList.js.map +1 -1
  12. package/data/documents/index.d.ts +1 -0
  13. package/data/documents/index.js.map +1 -1
  14. package/index.d.ts +3 -3
  15. package/index.js +1 -1
  16. package/index.js.map +1 -1
  17. package/internal/loro/historyTimeline.d.ts +57 -0
  18. package/internal/loro/historyTimeline.js +271 -0
  19. package/internal/loro/historyTimeline.js.map +1 -0
  20. package/internal/loro/index.d.ts +1 -0
  21. package/internal/loro/index.js +1 -0
  22. package/internal/loro/index.js.map +1 -1
  23. package/package.json +1 -1
  24. package/stores/documents/documentStore/history/restoreContent.js +127 -0
  25. package/stores/documents/documentStore/history/restoreContent.js.map +1 -0
  26. package/stores/documents/documentStore/index.js +4 -4
  27. package/stores/documents/documentStore/index.js.map +1 -1
  28. package/stores/documents/documentStore/mutations.js +1 -1
  29. package/stores/documents/documentStore/mutations.js.map +1 -1
  30. package/stores/documents/documentStore/rows/index.js +8 -0
  31. package/stores/documents/documentStore/rows/index.js.map +1 -1
  32. package/stores/documents/registry.js +1 -0
  33. package/stores/documents/registry.js.map +1 -1
  34. package/stores/documents/removedDocumentStore.js +1 -0
  35. package/stores/documents/removedDocumentStore.js.map +1 -1
  36. package/stores/documents/types.d.ts +10 -1
  37. package/stores/documents/types.js.map +1 -1
  38. package/workflows/documents/history/documentHistory.d.ts +72 -0
  39. package/workflows/documents/history/documentHistory.js +103 -0
  40. package/workflows/documents/history/documentHistory.js.map +1 -0
  41. package/workflows/documents/history/documentHistoryChange.d.ts +51 -0
  42. package/workflows/documents/history/documentHistoryChange.js +110 -0
  43. package/workflows/documents/history/documentHistoryChange.js.map +1 -0
  44. package/workflows/documents/index.d.ts +2 -0
  45. package/workflows/documents/index.js +2 -0
  46. package/workflows/documents/index.js.map +1 -1
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,yEAAyE;AACzE,gEAAgE;AAChE,OAAO,EAGL,iBAAiB,GAElB,MAAM,uBAAuB,CAAC;AAwK/B,OAAO,EAEL,KAAK,EACL,yBAAyB,EACzB,sCAAsC,EACtC,gCAAgC,EAChC,sCAAsC,EACtC,iBAAiB,EACjB,wCAAwC,EACxC,kCAAkC,EAClC,kBAAkB,EAClB,2CAA2C,EAC3C,qCAAqC,EACrC,+BAA+B,EAC/B,gCAAgC,EAChC,gCAAgC,EAChC,yBAAyB,EACzB,+BAA+B,EAC/B,0BAA0B,EAC1B,yBAAyB,EACzB,QAAQ,EACR,mBAAmB,EAKnB,8BAA8B,EAC9B,2BAA2B,EAC3B,MAAM,EAGN,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,EAC3B,mCAAmC,EACnC,6BAA6B,EAC7B,oBAAoB,EACpB,OAAO,EACP,0BAA0B,EAG1B,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAE5B,yBAAyB,EACzB,8CAA8C,EAC9C,yBAAyB,EAKzB,eAAe,EAIf,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,UAAU,CAAC;AAwBlB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,qBAAqB,EACrB,gCAAgC,EAChC,yBAAyB,EACzB,sBAAsB,EACtB,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B,GAC9B,MAAM,2BAA2B,CAAC;AAWnC,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,+BAA+B,EAC/B,6BAA6B,EAC7B,8BAA8B,EAC9B,mCAAmC,GACpC,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACrC,kCAAkC,EAClC,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAelC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,8BAA8B,EAC9B,oCAAoC,EACpC,qBAAqB,EACrB,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAyB7B,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAe1B,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,gCAAgC,EAChC,mCAAmC,EACnC,yBAAyB,EACzB,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,kBAAkB,CAAC","sourcesContent":["// SDK: full-bundle identity trust and bounded Members admission.\n// Exact-head authority; canonical writer domains; restart-safe journals.\n// No pin promotion or legacy adapters. See workflows/README.md.\nexport {\n type ApiRequestCounts,\n type ApiRequestEndpointCounts,\n ApiRequestMetrics,\n type ApiRequestMetricsSnapshot,\n} from \"@tearleads/api-client\";\nexport type {\n AbandonOrganizationPolicyMutationInput,\n AddOrganizationGroupUserInput,\n BlobInfo,\n BlobInfoAttachmentKind,\n BlobInfoDocumentReference,\n BlobInfoInput,\n BlobInfoList,\n BlobInfoSort,\n BlobInfoSortDirection,\n BlobInfoSortKey,\n BrowserLocalKeyringOptions,\n ContainerContents,\n ContainerContentsContextValue,\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerDocumentLinkInput,\n ContainerDocumentLinks,\n ContainerDocumentObjectSyncState,\n ContainerDocumentObjectSyncStatus,\n ContainerDocumentQueries,\n ContainerDocumentSidebarRow,\n ContainerInfo,\n ContainerInfoInput,\n ContainerItemRow,\n ContainerItemSort,\n ContainerItemSortDirection,\n ContainerItemSortKey,\n ContainerNode,\n ContainerShareAccessLevel,\n CreateOrganizationOptions,\n DatabaseListener,\n DatabaseOptions,\n DatabaseSnapshot,\n DatabaseStatus,\n DeviceFirst,\n DeviceFirstContainerContents,\n DiscardUnreadableOrganizationPolicyMutationInput,\n DocumentAttachmentStatus,\n DocumentAttachmentUpload,\n DocumentAttributionRangesInput,\n DocumentAttributionRangesPage,\n DocumentContextValue,\n DocumentInfo,\n DocumentInfoInput,\n DocumentList,\n DocumentSort,\n DocumentSortDirection,\n DocumentSortKey,\n DocumentStore,\n DocumentSubscriptionOptions,\n Documents,\n DocumentsRuntime,\n DomainScope,\n FileSaver,\n Identity,\n IdentityGenerationResult,\n IdentityKeyPackage,\n IdentityListener,\n IdentityOptions,\n IdentitySnapshot,\n IndexedDbLocalKeyringManifestStoreOptions,\n IndexedDbWrappingKeyKeystoreOptions,\n LinkDocumentToContainerInput,\n ListDocumentsInput,\n LocalKeyPurpose,\n LocalKeyring,\n LocalKeyringManifest,\n LocalKeyringManifestFormat,\n LocalKeyringManifestStorage,\n LocalKeyringManifestStore,\n LocalKeyringOptions,\n LocalKeyringPinCode,\n LocalKeyringScope,\n LocalKeyringSession,\n LocalOrganizationSummary,\n LocalProjectionReconciledDelta,\n LocalProjectionSnapshot,\n LocalProjectionView,\n LocalSecretContext,\n LocalStorageLocalKeyringManifestStoreOptions,\n Logger,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n NetworkListener,\n NetworkMode,\n NetworkStatusSource,\n NormalizedLocalKeyringScope,\n OpenContainerDocumentInput,\n OpenDocumentInput,\n OpenDocumentOptions,\n OrganizationBilling,\n OrganizationBillingHistory,\n OrganizationBillingHistoryEntry,\n OrganizationBillingManagementUrl,\n OrganizationBillingView,\n OrganizationContainerGrant,\n OrganizationContainerGrants,\n OrganizationDataUsage,\n OrganizationDeviceDataUsage,\n OrganizationDeviceDocumentUsageCategoryBreakdown,\n OrganizationDirectory,\n OrganizationDirectoryAndGroups,\n OrganizationDirectoryUser,\n OrganizationGrantRef,\n OrganizationGroupContainer,\n OrganizationGroupContainers,\n OrganizationGroupDetails,\n OrganizationGroupMember,\n OrganizationGroupMembers,\n OrganizationGroupMutationReceipt,\n OrganizationGroupMutationResult,\n OrganizationGroupPolicyHistory,\n OrganizationGroupSummary,\n OrganizationLeaveRequestResult,\n OrganizationMembership,\n OrganizationMemberships,\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n /** Verified organization display page with an optional older-page cursor. */\n OrganizationPolicyHistory,\n OrganizationPolicyHistoryEntry,\n OrganizationProfile,\n OrganizationSyncPauseResult,\n Organizations,\n OrganizationUserDetail,\n PendingWriteQueueItem,\n PendingWriteQueueItemStatus,\n PendingWriteQueueObjectKind,\n PendingWriteQueueOperation,\n PendingWriteQueueOperationKind,\n PendingWriteQueueOperationStatus,\n // Persistence notifications distinguish placement changes from content saves.\n PersistedDocumentListener,\n PinCodeBrowserLocalKeyringOptions,\n PinCodeWrappingKeyKeystoreOptions,\n PurgeDocumentInput,\n PurgeDocumentResult,\n ReconciliationService,\n RemoveOrganizationGroupUserInput,\n ResolvedUserIdentity,\n SaveFileRequest,\n SecurityIncident,\n SecurityIncidentListener,\n SecurityIncidentObjectKind,\n SecurityIncidents,\n Session,\n SessionContext,\n SessionCreateOrganizationResult,\n SessionListener,\n SessionRecoverOrganizationResult,\n SessionRegistrationRefusal,\n SessionRegistrationResult,\n SessionSnapshot,\n SetActiveDocumentContainerInput,\n SetLinkedContainerIdsForDocument,\n UnlinkDocumentFromContainerInput,\n UnwrapLocalSecretInput,\n UserIdentities,\n UserSession,\n WrapLocalSecretInput,\n WrappedLocalSecretEnvelope,\n WrappedLocalSecretFormat,\n WrappingKeyHandle,\n WrappingKeyKeystore,\n WrappingKeyMaterialStorage,\n} from \"./client\";\nexport {\n type BlobStoreFactory,\n Blobs,\n createBrowserLocalKeyring,\n createBrowserLocalKeyringManifestStore,\n createBrowserNetworkStatusSource,\n createContainerDocumentObjectSyncState,\n createDomainScope,\n createIndexedDbLocalKeyringManifestStore,\n createIndexedDbWrappingKeyKeystore,\n createLocalKeyring,\n createLocalStorageLocalKeyringManifestStore,\n createMemoryLocalKeyringManifestStore,\n createMemoryWrappingKeyKeystore,\n createPinCodeBrowserLocalKeyring,\n createPinCodeWrappingKeyKeystore,\n createRevenueCatPurchases,\n createUnavailableDirectCheckout,\n createUnavailablePurchases,\n createWebViewLocalKeyring,\n Database,\n DEFAULT_DOCUMENT_ID,\n type DirectCheckoutAppearance,\n type DirectCheckoutCapability,\n type DirectCheckoutConfirmation,\n type DirectCheckoutSession,\n DirectCheckoutUnavailableError,\n decodeLocalKeyringSqliteKey,\n Events,\n type EventsListener,\n type EventsSnapshot,\n encodeLocalKeyringSqliteKey,\n enqueueReconciliationForEvents,\n IDENTITY_KEY_PACKAGE_FORMAT,\n isPinCodeWrappedLocalSecretEnvelope,\n LOCAL_KEYRING_MANIFEST_FORMAT,\n localKeyringScopeKey,\n Network,\n normalizeLocalKeyringScope,\n type PrincipalHistoryKeyProvider,\n type PrincipalHistoryKeyScope,\n PurchaseAbortedError,\n PurchaseAlreadyOwnedError,\n PurchaseCancelledError,\n PurchaseIdentityPendingError,\n PurchaseProviderStalledError,\n type PurchasesCapability,\n PurchasesUnavailableError,\n PurgedOrganizationRecoveryBillingRequiredError,\n parseLocalKeyringManifest,\n type RevenueCatBackend,\n type RevenueCatCustomerInfo,\n type RevenueCatPackage,\n type RevenueCatPurchasesConfig,\n SyncBillingGate,\n type SyncBillingGateListener,\n type SyncPurchaseResult,\n type SyncSubscriptionOption,\n serializeLocalKeyringManifest,\n UnverifiedUserIdentityError,\n WRAPPED_LOCAL_SECRET_FORMAT,\n} from \"./client\";\nexport type {\n DiscoveredDocumentInput,\n DocumentAttachment,\n DocumentClientProjectionDefinition,\n DocumentClientProjectionDeleteInput,\n DocumentClientProjectionSaveInput,\n DocumentFieldValidationIssue,\n DocumentProjection,\n DocumentProjectorDefinition,\n DocumentProjectorInput,\n DocumentProjectorRegistry,\n DocumentProjectorRegistryInput,\n DocumentRow,\n DocumentRowSummary,\n DocumentSummary,\n EnvFileVariable,\n StoredDocumentKind,\n StoredDocumentState,\n StructuredDocumentMap,\n StructuredDocumentShape,\n StructuredDocumentText,\n ValidatedDocumentFields,\n} from \"./data/documents\";\nexport {\n addDocumentAttachments,\n createDocumentProjectorRegistry,\n createDocumentSignerDeviceId,\n DEFAULT_DOCUMENT_ACCESS_EPOCH,\n DEFAULT_DOCUMENT_KIND,\n defaultDocumentProjectorRegistry,\n deriveStoredDocumentTitle,\n ENV_FILE_DOCUMENT_KIND,\n ENV_FILE_NAME_FIELD,\n ENV_FILE_VARIABLE_KEY_FIELD,\n ENV_FILE_VARIABLE_NAME_PATTERN,\n ENV_FILE_VARIABLE_VALUE_FIELD,\n ensureDocumentAttachmentStructure,\n getDocumentAttachments,\n getDocumentClientProjectionTables,\n getStoredDocumentTypeLabel,\n getUntitledDocumentTitle,\n initializeStoredDocumentKind,\n isValidEnvFileVariableName,\n parseEnvFileText,\n projectStoredDocumentState,\n readStoredDocumentState,\n readStringDocumentField,\n resolveOpIdAttribution,\n sameDocumentAttachments,\n summarizeDocumentContributors,\n writerByPeerId,\n writeStoredDocumentFields,\n} from \"./data/documents\";\nexport type {\n ContainerContentsSnapshot,\n ContainerContentsStoreRuntime,\n ContainerContentsStoreState,\n ContainerContentsStoreSyncAgent,\n ContainerContentsStoreSyncState,\n ContainerState,\n PurgeMoveSettlement,\n PurgeOptions,\n PurgeProgress,\n} from \"./stores/container-contents\";\nexport {\n createContainerContentsStore,\n createContainerContentsStoreState,\n createContainerContentsStoreSyncAgent,\n getOrCreateContainerContentsStore,\n isSystemContainerNode,\n requestContainerContentsDocumentPriming,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStoreRuntime,\n} from \"./stores/container-contents\";\nexport type {\n DocumentMutationGuard,\n DocumentMutationOptions,\n DocumentSnapshot,\n DocumentStoreFacade,\n DocumentStoreOpenOptions,\n DocumentStoreRelinkInput,\n DocumentStructuredFieldPatch,\n} from \"./stores/documents\";\nexport {\n createDocumentStore,\n discardRegisteredDocumentLocalState,\n getOrCreateDocumentStore,\n hasPendingLocalDocumentWrites,\n openDocumentStore,\n requestDomainDocumentSync,\n subscribeToPersistedDocuments,\n} from \"./stores/documents\";\nexport { Tearleads } from \"./Tearleads\";\nexport type {\n TearleadsDatabaseOptions,\n TearleadsOptions,\n} from \"./TearleadsOptions\";\nexport type {\n BlobAttachmentCollaborators,\n BlobAttachmentServiceApi,\n BlobByteSource,\n BlobByteSourceInput,\n BlobBytes,\n BlobStore,\n DecryptDocumentAttachmentBlobRequest,\n DetachDocumentAttachmentRequest,\n DetachDocumentAttachmentResult,\n EncryptedBlobStoreCipher,\n EncryptedBlobStoreKey,\n EncryptedBlobStoreOptions,\n HydrateDocumentAttachmentBlobsRequest,\n HydratedDocumentAttachmentBlob,\n UploadDocumentAttachmentRequest,\n UploadDocumentAttachmentResult,\n WrapEncryptedBlobStoreOptions,\n} from \"./workflows/blobs\";\nexport {\n BlobAttachmentService,\n blobByteSourceInputLength,\n createBlobByteSource,\n createBlobStore,\n createEncryptedBlobStore,\n createLazyEncryptedBlobStore,\n createMemoryBlobStore,\n purgeOpfsBlobStore,\n readBlobByteSource,\n wrapEncryptedBlobStore,\n} from \"./workflows/blobs\";\nexport type {\n ContainerContentsRootAdopter,\n ContainerContentsRootAdoptionInput,\n ContainerContentsStoreWorkflowRuntime,\n ContainerContentsWorkflowRuntime,\n // Distinct from the canonical `ContainerDocumentLinkInput` (./client); the\n // documentQueries variant has a different shape, so it keeps a disambiguating\n // alias on the public surface.\n ContainerDocumentLinkInput as ContainerDocumentQueriesLinkInput,\n ContainerSystemSlotDefinition,\n PendingDownloadQueueItem,\n RecoveryFolder,\n} from \"./workflows/container-contents\";\nexport {\n ContainerSyncWatermarkRepository,\n createContainerContentsDocumentsRuntime,\n createContainerContentsProjectionUserKeyResolver,\n createContainerContentsStoreWorkflowRuntime,\n createContainerContentsSyncLane,\n createContainerContentsWorkflowRuntime,\n createContainerParentSyncLane,\n createInitializedContainerMetadataDocument,\n defaultContainerContentsPersistence,\n deriveContainerSystemSlot,\n initializeDocumentLinksSchema,\n listBlobInfo,\n listDocumentLinkedContainerIds,\n loadContainerInfo,\n loadDocumentAttributionRanges,\n loadDocumentInfo,\n replaceDocumentLinks,\n syncedContainerDocumentObjectSyncState,\n} from \"./workflows/container-contents\";\nexport type {\n AggregatedContainerKekLog,\n ContainerMutationAuthor,\n ContainerMutationCollaborators,\n ContainerReciteApi,\n ContainerWriteRefusal,\n KeyringRebuildResult,\n MaterializedContainerRekeyPlan,\n} from \"./workflows/containers\";\nexport {\n buildMaterializedContainerRekeyPlan,\n buildRootContainerCreatePlan,\n ContainerAuthorAccessError,\n ContainerKekRepairInaccessibleError,\n ContainerKekRepairRequiredError,\n ContainerKeyringOverrideStaleError,\n ContainerMutationService,\n ContainerPathTooDeepError,\n classifyContainerWriteRefusal,\n containerWriterProjectionFromRekeyPlan,\n fetchContainerKekLog,\n HistoricalWrapUnavailableError,\n type HistoricalWrapUnavailableReason,\n isProjectionVerificationCancelledError,\n rebuildKeyringEntriesFromLog,\n recoverKeyringEntryFromWraps,\n rootContainerWriterProjectionFromCreatePlan,\n} from \"./workflows/containers\";\nexport type {\n DocumentBirthResult,\n DocumentRecord,\n DocumentSyncContainerRekeyBuilder,\n DocumentSyncPullContinuation,\n DocumentSyncUpdateIsolationError,\n DocumentsPersistence,\n DocumentsWorkflowRuntime,\n DocumentsWorkflowRuntimeInput,\n IncomingDocumentSyncUpdateValidator,\n LocalAttachmentRecord,\n PendingAttachmentRecord,\n PendingUpdateInsert,\n PendingUpdateRecord,\n QueuedPendingUpdateRecord,\n SyncRemoteDocumentInput,\n} from \"./workflows/documents\";\nexport {\n buildMaterializedDocumentCreatePlan,\n createDocumentProjectionUserKeyResolver,\n createDocumentsWorkflowRuntime,\n createRemoteDocument,\n DOCUMENT_SYNC_TRACE_FRAGMENT,\n DOCUMENT_SYNC_TRACE_PATTERN,\n DOCUMENTS_APP_KIND,\n DocumentRawHistoryUnavailableError,\n defaultDocumentsPersistence,\n deletePersistedDocument,\n deriveStableDocumentId,\n isDatabaseUnavailableError,\n isDocumentSyncUpdateIsolationError,\n persistedDocumentCreateStateFromResponse,\n readPullContinuation,\n syncRemoteDocument,\n unwrapContainerKekPath,\n unwrapDocumentContentKeyTarget,\n validateDocumentSyncUpdateImports,\n} from \"./workflows/documents\";\n// Nominal identity constructors are available only through the testing subpath\n// for low-level runtime tests.\nexport type {\n AcknowledgedPrincipalCurrentInput,\n AcknowledgedPrincipalCurrentRetirement,\n AuthoredPrincipalMutation,\n OrganizationDocumentUsageCategory,\n OrganizationGroupPolicyHistoryEntry,\n OrganizationNativePurchaseEligibility,\n OrganizationPrincipalMemberChange,\n OrganizationPrincipalMemberChangeType,\n OrganizationPrincipalPolicyHistory,\n OrganizationPrincipalPolicyHistoryEntry,\n PrincipalMutationJournalContext,\n PrincipalMutationJournalScope,\n PrincipalMutationResponse,\n ReconcileOrganizationDataUsageInput,\n} from \"./workflows/organizations\";\nexport {\n abandonJournaledPrincipalMutation,\n addOrganizationGroupUser,\n buildInitialGroupPolicyRequest,\n buildInitialMemberGroupPolicyRequest,\n buildOrganizationGroupPolicyHistory,\n buildOrganizationProfileDocumentPatch,\n buildRosterProfileDocumentPatch,\n checkNativePurchaseEligibility,\n createInitializedRosterProfileDocument,\n createOrganizationGroup,\n DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME,\n deriveOrganizationMetadataContainerSystemSlot,\n deriveOrganizationRosterProfileContainerSystemSlot,\n discardUnreadableJournaledPrincipalMutation,\n GroupMembershipNameMismatchError,\n GroupShareNameMismatchError,\n getOrganizationProfileDocumentLocalId,\n getRosterProfileDocumentLocalId,\n loadLocalOrganizationDataUsage,\n loadLocalOrganizationDirectoryAndGroups,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n ORGANIZATION_DOCUMENT_USAGE_CATEGORIES,\n ORGANIZATION_METADATA_CONTAINER_NAME,\n ORGANIZATION_PROFILE_DOCUMENT_KIND,\n ORGANIZATION_ROSTER_PROFILE_CONTAINER_NAME,\n PendingPrincipalMutationError,\n PrincipalMutationOutcomeUnknownError,\n ROSTER_PROFILE_DOCUMENT_KIND,\n readJournaledPrincipalMutation,\n readOrganizationProfileName,\n reconcileOrganizationDataUsage,\n reconcileOrganizationDirectoryAndGroups,\n recoverJournaledPrincipalMutation,\n removeOrganizationGroupUser,\n resolveOrganizationBillingView,\n retainAcknowledgedPrincipalCurrents,\n revokeOrganizationContainerGrant,\n shareRemoteContainerWithGroup,\n startOrganizationTrial,\n submitJournaledPrincipalMutation,\n subscribeOrganizationReadModelInvalidation,\n UnreadablePrincipalMutationError,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n} from \"./workflows/organizations\";\nexport type {\n AcknowledgedPrincipalPredecessor,\n CacheReferencedPrincipalPoliciesOptions,\n PrincipalHistoryProtectionLease,\n ProjectionPolicyHistoryRecoveryOptions,\n RecoveredPrincipalPolicyHistory,\n RecoveredScopedPrincipalPolicyHistory,\n RecoverPrincipalPolicyHistoryOptions,\n RecoverScopedPrincipalPolicyHistoryOptions,\n} from \"./workflows/principals\";\nexport {\n cacheReferencedPrincipalPolicies,\n captureAcknowledgedPrincipalPredecessor,\n PrincipalPolicyHistoryReadError,\n recoverPrincipalPolicyHistory,\n recoverProjectionPolicyHistory,\n recoverScopedPrincipalPolicyHistory,\n} from \"./workflows/principals\";\nexport type {\n InitialRootMetadataBootstrap,\n ProvisionedSystemContainerSpec,\n RegisterIdentityInput,\n RegistrationApi,\n} from \"./workflows/registration\";\nexport {\n bootstrapRootContainer,\n buildInitialOrganizationPolicyRequest,\n createInitialRootMetadataBootstrap,\n persistRegistrationBootstrap,\n registerIdentity,\n} from \"./workflows/registration\";\nexport type {\n PendingBlobDeletion,\n PendingBlobDeletionsPage,\n PendingBlobDeletionsQueryInput,\n RootIdentitiesApi,\n RootIdentitiesPage,\n RootIdentitiesQueryInput,\n RootIdentity,\n RootIdentityDetail,\n RootIdentityOrganization,\n RootIdentitySession,\n RootPendingBlobDeletionsQueryInput,\n RootRequestOutcome,\n} from \"./workflows/root\";\nexport {\n liftRootIdentitySuspension,\n listRootAuditEvents,\n listRootDataUsageReport,\n listRootIdentities,\n listRootIdentityOrganizations,\n listRootOrganizationIdentities,\n listRootOrganizationRevenuecatEvents,\n listRootOrganizations,\n listRootRevenuecatEventsReport,\n loadRootIdentity,\n loadRootOpsHealthReport,\n loadRootOrganization,\n loadRootOrganizationDataUsage,\n type RootAuditApi,\n type RootAuditEvent,\n type RootAuditEventsPage,\n type RootAuditEventsQueryInput,\n type RootDataUsageApi,\n type RootDataUsageReportPage,\n type RootOpsHealthApi,\n type RootOpsHealthReport,\n type RootOrganization,\n type RootOrganizationDetail,\n type RootOrganizationIdentitiesPage,\n type RootOrganizationIdentity,\n type RootOrganizationPageQueryInput,\n type RootOrganizationRevenuecatEvent,\n type RootOrganizationRevenuecatEventsPage,\n type RootOrganizationsApi,\n type RootOrganizationsPage,\n type RootOrganizationsQueryInput,\n type RootRevenuecatApi,\n type RootRevenuecatEvent,\n type RootRevenuecatEventsQueryInput,\n type RootRevenuecatEventsReportPage,\n type RootRevenuecatEventsReportQueryInput,\n type RootSuspensionApi,\n suspendRootIdentity,\n} from \"./workflows/root\";\nexport type {\n ClearRemoteSyncStateResult,\n DomainSyncCoordinator,\n DomainSyncSnapshot,\n RemoteResetInput,\n RemoteResetReplacement,\n SyncIdleOptions,\n SyncLane,\n SyncLaneConfig,\n SyncLaneLastAction,\n SyncLanePhase,\n SyncLaneSnapshot,\n SyncLaneStatus,\n} from \"./workflows/sync\";\nexport {\n clearRemoteSyncState,\n getDomainSyncCoordinatorSnapshot,\n getOrCreateDomainSyncCoordinator,\n hasDomainSyncCoordinatorPendingWork,\n requestAllDomainSyncLanes,\n subscribeToDomainSyncCoordinator,\n waitForDomainSyncCoordinatorToSettle,\n} from \"./workflows/sync\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,yEAAyE;AACzE,gEAAgE;AAChE,OAAO,EAGL,iBAAiB,GAElB,MAAM,uBAAuB,CAAC;AAgL/B,OAAO,EAEL,KAAK,EACL,yBAAyB,EACzB,sCAAsC,EACtC,gCAAgC,EAChC,sCAAsC,EACtC,iBAAiB,EACjB,wCAAwC,EACxC,kCAAkC,EAClC,kBAAkB,EAClB,2CAA2C,EAC3C,qCAAqC,EACrC,+BAA+B,EAC/B,gCAAgC,EAChC,gCAAgC,EAChC,yBAAyB,EACzB,+BAA+B,EAC/B,0BAA0B,EAC1B,yBAAyB,EACzB,QAAQ,EACR,mBAAmB,EAKnB,8BAA8B,EAC9B,2BAA2B,EAC3B,MAAM,EAGN,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,EAC3B,mCAAmC,EACnC,6BAA6B,EAC7B,oBAAoB,EACpB,OAAO,EACP,0BAA0B,EAG1B,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAE5B,yBAAyB,EACzB,8CAA8C,EAC9C,yBAAyB,EAKzB,eAAe,EAIf,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,UAAU,CAAC;AAyBlB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,qBAAqB,EACrB,gCAAgC,EAChC,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,sBAAsB,EACtB,iCAAiC,EACjC,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,0BAA0B,EAC1B,gBAAgB,E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AOhC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACrC,kCAAkC,EAClC,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAelC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,8BAA8B,EAC9B,oCAAoC,EACpC,qBAAqB,EACrB,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAyB7B,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAe1B,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,gCAAgC,EAChC,mCAAmC,EACnC,yBAAyB,EACzB,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,kBAAkB,CAAC","sourcesContent":["// SDK: full-bundle identity trust and bounded Members admission.\n// Exact-head authority; canonical writer domains; restart-safe journals.\n// No pin promotion or legacy adapters. See workflows/README.md.\nexport {\n type ApiRequestCounts,\n type ApiRequestEndpointCounts,\n ApiRequestMetrics,\n type ApiRequestMetricsSnapshot,\n} from \"@tearleads/api-client\";\nexport type {\n AbandonOrganizationPolicyMutationInput,\n AddOrganizationGroupUserInput,\n BlobInfo,\n BlobInfoAttachmentKind,\n BlobInfoDocumentReference,\n BlobInfoInput,\n BlobInfoList,\n BlobInfoSort,\n BlobInfoSortDirection,\n BlobInfoSortKey,\n BrowserLocalKeyringOptions,\n ContainerContents,\n ContainerContentsContextValue,\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerDocumentLinkInput,\n ContainerDocumentLinks,\n ContainerDocumentObjectSyncState,\n ContainerDocumentObjectSyncStatus,\n ContainerDocumentQueries,\n ContainerDocumentSidebarRow,\n ContainerInfo,\n ContainerInfoInput,\n ContainerItemRow,\n ContainerItemSort,\n ContainerItemSortDirection,\n ContainerItemSortKey,\n ContainerNode,\n ContainerShareAccessLevel,\n CreateOrganizationOptions,\n DatabaseListener,\n DatabaseOptions,\n DatabaseSnapshot,\n DatabaseStatus,\n DeviceFirst,\n DeviceFirstContainerContents,\n DiscardUnreadableOrganizationPolicyMutationInput,\n DocumentAttachmentStatus,\n DocumentAttachmentUpload,\n DocumentAttributionRangesInput,\n DocumentAttributionRangesPage,\n DocumentContextValue,\n DocumentHistory,\n DocumentHistoryChange,\n DocumentHistoryRowChange,\n DocumentHistoryStop,\n DocumentHistoryTextChange,\n DocumentHistoryVersion,\n DocumentHistoryVersionEntry,\n DocumentHistoryView,\n DocumentInfo,\n DocumentInfoInput,\n DocumentList,\n DocumentSort,\n DocumentSortDirection,\n DocumentSortKey,\n DocumentStore,\n DocumentSubscriptionOptions,\n Documents,\n DocumentsRuntime,\n DomainScope,\n FileSaver,\n Identity,\n IdentityGenerationResult,\n IdentityKeyPackage,\n IdentityListener,\n IdentityOptions,\n IdentitySnapshot,\n IndexedDbLocalKeyringManifestStoreOptions,\n IndexedDbWrappingKeyKeystoreOptions,\n LinkDocumentToContainerInput,\n ListDocumentsInput,\n LocalKeyPurpose,\n LocalKeyring,\n LocalKeyringManifest,\n LocalKeyringManifestFormat,\n LocalKeyringManifestStorage,\n LocalKeyringManifestStore,\n LocalKeyringOptions,\n LocalKeyringPinCode,\n LocalKeyringScope,\n LocalKeyringSession,\n LocalOrganizationSummary,\n LocalProjectionReconciledDelta,\n LocalProjectionSnapshot,\n LocalProjectionView,\n LocalSecretContext,\n LocalStorageLocalKeyringManifestStoreOptions,\n Logger,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n NetworkListener,\n NetworkMode,\n NetworkStatusSource,\n NormalizedLocalKeyringScope,\n OpenContainerDocumentInput,\n OpenDocumentInput,\n OpenDocumentOptions,\n OrganizationBilling,\n OrganizationBillingHistory,\n OrganizationBillingHistoryEntry,\n OrganizationBillingManagementUrl,\n OrganizationBillingView,\n OrganizationContainerGrant,\n OrganizationContainerGrants,\n OrganizationDataUsage,\n OrganizationDeviceDataUsage,\n OrganizationDeviceDocumentUsageCategoryBreakdown,\n OrganizationDirectory,\n OrganizationDirectoryAndGroups,\n OrganizationDirectoryUser,\n OrganizationGrantRef,\n OrganizationGroupContainer,\n OrganizationGroupContainers,\n OrganizationGroupDetails,\n OrganizationGroupMember,\n OrganizationGroupMembers,\n OrganizationGroupMutationReceipt,\n OrganizationGroupMutationResult,\n OrganizationGroupPolicyHistory,\n OrganizationGroupSummary,\n OrganizationLeaveRequestResult,\n OrganizationMembership,\n OrganizationMemberships,\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n /** Verified organization display page with an optional older-page cursor. */\n OrganizationPolicyHistory,\n OrganizationPolicyHistoryEntry,\n OrganizationProfile,\n OrganizationSyncPauseResult,\n Organizations,\n OrganizationUserDetail,\n PendingWriteQueueItem,\n PendingWriteQueueItemStatus,\n PendingWriteQueueObjectKind,\n PendingWriteQueueOperation,\n PendingWriteQueueOperationKind,\n PendingWriteQueueOperationStatus,\n // Persistence notifications distinguish placement changes from content saves.\n PersistedDocumentListener,\n PinCodeBrowserLocalKeyringOptions,\n PinCodeWrappingKeyKeystoreOptions,\n PurgeDocumentInput,\n PurgeDocumentResult,\n ReconciliationService,\n RemoveOrganizationGroupUserInput,\n ResolvedUserIdentity,\n SaveFileRequest,\n SecurityIncident,\n SecurityIncidentListener,\n SecurityIncidentObjectKind,\n SecurityIncidents,\n Session,\n SessionContext,\n SessionCreateOrganizationResult,\n SessionListener,\n SessionRecoverOrganizationResult,\n SessionRegistrationRefusal,\n SessionRegistrationResult,\n SessionSnapshot,\n SetActiveDocumentContainerInput,\n SetLinkedContainerIdsForDocument,\n UnlinkDocumentFromContainerInput,\n UnwrapLocalSecretInput,\n UserIdentities,\n UserSession,\n WrapLocalSecretInput,\n WrappedLocalSecretEnvelope,\n WrappedLocalSecretFormat,\n WrappingKeyHandle,\n WrappingKeyKeystore,\n WrappingKeyMaterialStorage,\n} from \"./client\";\nexport {\n type BlobStoreFactory,\n Blobs,\n createBrowserLocalKeyring,\n createBrowserLocalKeyringManifestStore,\n createBrowserNetworkStatusSource,\n createContainerDocumentObjectSyncState,\n createDomainScope,\n createIndexedDbLocalKeyringManifestStore,\n createIndexedDbWrappingKeyKeystore,\n createLocalKeyring,\n createLocalStorageLocalKeyringManifestStore,\n createMemoryLocalKeyringManifestStore,\n createMemoryWrappingKeyKeystore,\n createPinCodeBrowserLocalKeyring,\n createPinCodeWrappingKeyKeystore,\n createRevenueCatPurchases,\n createUnavailableDirectCheckout,\n createUnavailablePurchases,\n createWebViewLocalKeyring,\n Database,\n DEFAULT_DOCUMENT_ID,\n type DirectCheckoutAppearance,\n type DirectCheckoutCapability,\n type DirectCheckoutConfirmation,\n type DirectCheckoutSession,\n DirectCheckoutUnavailableError,\n decodeLocalKeyringSqliteKey,\n Events,\n type EventsListener,\n type EventsSnapshot,\n encodeLocalKeyringSqliteKey,\n enqueueReconciliationForEvents,\n IDENTITY_KEY_PACKAGE_FORMAT,\n isPinCodeWrappedLocalSecretEnvelope,\n LOCAL_KEYRING_MANIFEST_FORMAT,\n localKeyringScopeKey,\n Network,\n normalizeLocalKeyringScope,\n type PrincipalHistoryKeyProvider,\n type PrincipalHistoryKeyScope,\n PurchaseAbortedError,\n PurchaseAlreadyOwnedError,\n PurchaseCancelledError,\n PurchaseIdentityPendingError,\n PurchaseProviderStalledError,\n type PurchasesCapability,\n PurchasesUnavailableError,\n PurgedOrganizationRecoveryBillingRequiredError,\n parseLocalKeyringManifest,\n type RevenueCatBackend,\n type RevenueCatCustomerInfo,\n type RevenueCatPackage,\n type RevenueCatPurchasesConfig,\n SyncBillingGate,\n type SyncBillingGateListener,\n type SyncPurchaseResult,\n type SyncSubscriptionOption,\n serializeLocalKeyringManifest,\n UnverifiedUserIdentityError,\n WRAPPED_LOCAL_SECRET_FORMAT,\n} from \"./client\";\nexport type {\n DiscoveredDocumentInput,\n DocumentAttachment,\n DocumentClientProjectionDefinition,\n DocumentClientProjectionDeleteInput,\n DocumentClientProjectionSaveInput,\n DocumentFieldValidationIssue,\n DocumentProjection,\n DocumentProjectorDefinition,\n DocumentProjectorInput,\n DocumentProjectorRegistry,\n DocumentProjectorRegistryInput,\n DocumentRestoreContent,\n DocumentRow,\n DocumentRowSummary,\n DocumentSummary,\n EnvFileVariable,\n StoredDocumentKind,\n StoredDocumentState,\n StructuredDocumentMap,\n StructuredDocumentShape,\n StructuredDocumentText,\n ValidatedDocumentFields,\n} from \"./data/documents\";\nexport {\n addDocumentAttachments,\n createDocumentProjectorRegistry,\n createDocumentSignerDeviceId,\n DEFAULT_DOCUMENT_ACCESS_EPOCH,\n DEFAULT_DOCUMENT_KIND,\n defaultDocumentProjectorRegistry,\n deriveStoredDocumentTitle,\n ENV_FILE_DOCUMENT_KIND,\n ENV_FILE_NAME_FIELD,\n ENV_FILE_VARIABLE_KEY_FIELD,\n ENV_FILE_VARIABLE_NAME_PATTERN,\n ENV_FILE_VARIABLE_VALUE_FIELD,\n ensureDocumentAttachmentStructure,\n getDocumentAttachments,\n getDocumentClientProjectionTables,\n getStoredDocumentTypeLabel,\n getUntitledDocumentTitle,\n initializeStoredDocumentKind,\n isValidEnvFileVariableName,\n parseEnvFileText,\n projectStoredDocumentState,\n readStoredDocumentState,\n readStringDocumentField,\n resolveOpIdAttribution,\n sameDocumentAttachments,\n summarizeDocumentContributors,\n writerByPeerId,\n writeStoredDocumentFields,\n} from \"./data/documents\";\nexport type {\n ContainerContentsSnapshot,\n ContainerContentsStoreRuntime,\n ContainerContentsStoreState,\n ContainerContentsStoreSyncAgent,\n ContainerContentsStoreSyncState,\n ContainerState,\n PurgeMoveSettlement,\n PurgeOptions,\n PurgeProgress,\n} from \"./stores/container-contents\";\nexport {\n createContainerContentsStore,\n createContainerContentsStoreState,\n createContainerContentsStoreSyncAgent,\n getOrCreateContainerContentsStore,\n isSystemContainerNode,\n requestContainerContentsDocumentPriming,\n subscribeToContainerContentsStore,\n updateContainerContentsSnapshot,\n updateContainerContentsStoreRuntime,\n} from \"./stores/container-contents\";\nexport type {\n DocumentMutationGuard,\n DocumentMutationOptions,\n DocumentSnapshot,\n DocumentStoreFacade,\n DocumentStoreOpenOptions,\n DocumentStoreRelinkInput,\n DocumentStructuredFieldPatch,\n} from \"./stores/documents\";\nexport {\n createDocumentStore,\n discardRegisteredDocumentLocalState,\n getOrCreateDocumentStore,\n hasPendingLocalDocumentWrites,\n openDocumentStore,\n requestDomainDocumentSync,\n subscribeToPersistedDocuments,\n} from \"./stores/documents\";\nexport { Tearleads } from \"./Tearleads\";\nexport type {\n TearleadsDatabaseOptions,\n TearleadsOptions,\n} from \"./TearleadsOptions\";\nexport type {\n BlobAttachmentCollaborators,\n BlobAttachmentServiceApi,\n BlobByteSource,\n BlobByteSourceInput,\n BlobBytes,\n BlobStore,\n DecryptDocumentAttachmentBlobRequest,\n DetachDocumentAttachmentRequest,\n DetachDocumentAttachmentResult,\n EncryptedBlobStoreCipher,\n EncryptedBlobStoreKey,\n EncryptedBlobStoreOptions,\n HydrateDocumentAttachmentBlobsRequest,\n HydratedDocumentAttachmentBlob,\n UploadDocumentAttachmentRequest,\n UploadDocumentAttachmentResult,\n WrapEncryptedBlobStoreOptions,\n} from \"./workflows/blobs\";\nexport {\n BlobAttachmentService,\n blobByteSourceInputLength,\n createBlobByteSource,\n createBlobStore,\n createEncryptedBlobStore,\n createLazyEncryptedBlobStore,\n createMemoryBlobStore,\n purgeOpfsBlobStore,\n readBlobByteSource,\n wrapEncryptedBlobStore,\n} from \"./workflows/blobs\";\nexport type {\n ContainerContentsRootAdopter,\n ContainerContentsRootAdoptionInput,\n ContainerContentsStoreWorkflowRuntime,\n ContainerContentsWorkflowRuntime,\n // Distinct from the canonical `ContainerDocumentLinkInput` (./client); the\n // documentQueries variant has a different shape, so it keeps a disambiguating\n // alias on the public surface.\n ContainerDocumentLinkInput as ContainerDocumentQueriesLinkInput,\n ContainerSystemSlotDefinition,\n PendingDownloadQueueItem,\n RecoveryFolder,\n} from \"./workflows/container-contents\";\nexport {\n ContainerSyncWatermarkRepository,\n createContainerContentsDocumentsRuntime,\n createContainerContentsProjectionUserKeyResolver,\n createContainerContentsStoreWorkflowRuntime,\n createContainerContentsSyncLane,\n createContainerContentsWorkflowRuntime,\n createContainerParentSyncLane,\n createInitializedContainerMetadataDocument,\n defaultContainerContentsPersistence,\n deriveContainerSystemSlot,\n initializeDocumentLinksSchema,\n listBlobInfo,\n listDocumentLinkedContainerIds,\n loadContainerInfo,\n loadDocumentAttributionRanges,\n loadDocumentInfo,\n replaceDocumentLinks,\n syncedContainerDocumentObjectSyncState,\n} from \"./workflows/container-contents\";\nexport type {\n AggregatedContainerKekLog,\n ContainerMutationAuthor,\n ContainerMutationCollaborators,\n ContainerReciteApi,\n ContainerWriteRefusal,\n KeyringRebuildResult,\n MaterializedContainerRekeyPlan,\n} from \"./workflows/containers\";\nexport {\n buildMaterializedContainerRekeyPlan,\n buildRootContainerCreatePlan,\n ContainerAuthorAccessError,\n ContainerKekRepairInaccessibleError,\n ContainerKekRepairRequiredError,\n ContainerKeyringOverrideStaleError,\n ContainerMutationService,\n ContainerPathTooDeepError,\n classifyContainerWriteRefusal,\n containerWriterProjectionFromRekeyPlan,\n fetchContainerKekLog,\n HistoricalWrapUnavailableError,\n type HistoricalWrapUnavailableReason,\n isProjectionVerificationCancelledError,\n rebuildKeyringEntriesFromLog,\n recoverKeyringEntryFromWraps,\n rootContainerWriterProjectionFromCreatePlan,\n} from \"./workflows/containers\";\nexport type {\n DocumentBirthResult,\n DocumentRecord,\n DocumentSyncContainerRekeyBuilder,\n DocumentSyncPullContinuation,\n DocumentSyncUpdateIsolationError,\n DocumentsPersistence,\n DocumentsWorkflowRuntime,\n DocumentsWorkflowRuntimeInput,\n IncomingDocumentSyncUpdateValidator,\n LocalAttachmentRecord,\n PendingAttachmentRecord,\n PendingUpdateInsert,\n PendingUpdateRecord,\n QueuedPendingUpdateRecord,\n SyncRemoteDocumentInput,\n} from \"./workflows/documents\";\nexport {\n buildMaterializedDocumentCreatePlan,\n createDocumentProjectionUserKeyResolver,\n createDocumentsWorkflowRuntime,\n createRemoteDocument,\n DOCUMENT_SYNC_TRACE_FRAGMENT,\n DOCUMENT_SYNC_TRACE_PATTERN,\n DOCUMENTS_APP_KIND,\n DocumentRawHistoryUnavailableError,\n defaultDocumentsPersistence,\n deletePersistedDocument,\n deriveStableDocumentId,\n isDatabaseUnavailableError,\n isDocumentSyncUpdateIsolationError,\n isEmptyDocumentHistoryChange,\n persistedDocumentCreateStateFromResponse,\n readPullContinuation,\n syncRemoteDocument,\n unwrapContainerKekPath,\n unwrapDocumentContentKeyTarget,\n validateDocumentSyncUpdateImports,\n} from \"./workflows/documents\";\n// Nominal identity constructors are available only through the testing subpath\n// for low-level runtime tests.\nexport type {\n AcknowledgedPrincipalCurrentInput,\n AcknowledgedPrincipalCurrentRetirement,\n AuthoredPrincipalMutation,\n OrganizationDocumentUsageCategory,\n OrganizationGroupPolicyHistoryEntry,\n OrganizationNativePurchaseEligibility,\n OrganizationPrincipalMemberChange,\n OrganizationPrincipalMemberChangeType,\n OrganizationPrincipalPolicyHistory,\n OrganizationPrincipalPolicyHistoryEntry,\n PrincipalMutationJournalContext,\n PrincipalMutationJournalScope,\n PrincipalMutationResponse,\n ReconcileOrganizationDataUsageInput,\n} from \"./workflows/organizations\";\nexport {\n abandonJournaledPrincipalMutation,\n addOrganizationGroupUser,\n buildInitialGroupPolicyRequest,\n buildInitialMemberGroupPolicyRequest,\n buildOrganizationGroupPolicyHistory,\n buildOrganizationProfileDocumentPatch,\n buildRosterProfileDocumentPatch,\n checkNativePurchaseEligibility,\n createInitializedRosterProfileDocument,\n createOrganizationGroup,\n DEFAULT_PERSONAL_ORGANIZATION_PROFILE_NAME,\n deriveOrganizationMetadataContainerSystemSlot,\n deriveOrganizationRosterProfileContainerSystemSlot,\n discardUnreadableJournaledPrincipalMutation,\n GroupMembershipNameMismatchError,\n GroupShareNameMismatchError,\n getOrganizationProfileDocumentLocalId,\n getRosterProfileDocumentLocalId,\n loadLocalOrganizationDataUsage,\n loadLocalOrganizationDirectoryAndGroups,\n loadOrganizationBilling,\n loadOrganizationBillingHistory,\n loadOrganizationBillingManagementUrl,\n ORGANIZATION_DOCUMENT_USAGE_CATEGORIES,\n ORGANIZATION_METADATA_CONTAINER_NAME,\n ORGANIZATION_PROFILE_DOCUMENT_KIND,\n ORGANIZATION_ROSTER_PROFILE_CONTAINER_NAME,\n PendingPrincipalMutationError,\n PrincipalMutationOutcomeUnknownError,\n ROSTER_PROFILE_DOCUMENT_KIND,\n readJournaledPrincipalMutation,\n readOrganizationProfileName,\n reconcileOrganizationDataUsage,\n reconcileOrganizationDirectoryAndGroups,\n recoverJournaledPrincipalMutation,\n removeOrganizationGroupUser,\n resolveOrganizationBillingView,\n retainAcknowledgedPrincipalCurrents,\n revokeOrganizationContainerGrant,\n shareRemoteContainerWithGroup,\n startOrganizationTrial,\n submitJournaledPrincipalMutation,\n subscribeOrganizationReadModelInvalidation,\n UnreadablePrincipalMutationError,\n updateOrganizationProfile,\n updateOrganizationRosterEntry,\n} from \"./workflows/organizations\";\nexport type {\n AcknowledgedPrincipalPredecessor,\n CacheReferencedPrincipalPoliciesOptions,\n PrincipalHistoryProtectionLease,\n ProjectionPolicyHistoryRecoveryOptions,\n RecoveredPrincipalPolicyHistory,\n RecoveredScopedPrincipalPolicyHistory,\n RecoverPrincipalPolicyHistoryOptions,\n RecoverScopedPrincipalPolicyHistoryOptions,\n} from \"./workflows/principals\";\nexport {\n cacheReferencedPrincipalPolicies,\n captureAcknowledgedPrincipalPredecessor,\n PrincipalPolicyHistoryReadError,\n recoverPrincipalPolicyHistory,\n recoverProjectionPolicyHistory,\n recoverScopedPrincipalPolicyHistory,\n} from \"./workflows/principals\";\nexport type {\n InitialRootMetadataBootstrap,\n ProvisionedSystemContainerSpec,\n RegisterIdentityInput,\n RegistrationApi,\n} from \"./workflows/registration\";\nexport {\n bootstrapRootContainer,\n buildInitialOrganizationPolicyRequest,\n createInitialRootMetadataBootstrap,\n persistRegistrationBootstrap,\n registerIdentity,\n} from \"./workflows/registration\";\nexport type {\n PendingBlobDeletion,\n PendingBlobDeletionsPage,\n PendingBlobDeletionsQueryInput,\n RootIdentitiesApi,\n RootIdentitiesPage,\n RootIdentitiesQueryInput,\n RootIdentity,\n RootIdentityDetail,\n RootIdentityOrganization,\n RootIdentitySession,\n RootPendingBlobDeletionsQueryInput,\n RootRequestOutcome,\n} from \"./workflows/root\";\nexport {\n liftRootIdentitySuspension,\n listRootAuditEvents,\n listRootDataUsageReport,\n listRootIdentities,\n listRootIdentityOrganizations,\n listRootOrganizationIdentities,\n listRootOrganizationRevenuecatEvents,\n listRootOrganizations,\n listRootRevenuecatEventsReport,\n loadRootIdentity,\n loadRootOpsHealthReport,\n loadRootOrganization,\n loadRootOrganizationDataUsage,\n type RootAuditApi,\n type RootAuditEvent,\n type RootAuditEventsPage,\n type RootAuditEventsQueryInput,\n type RootDataUsageApi,\n type RootDataUsageReportPage,\n type RootOpsHealthApi,\n type RootOpsHealthReport,\n type RootOrganization,\n type RootOrganizationDetail,\n type RootOrganizationIdentitiesPage,\n type RootOrganizationIdentity,\n type RootOrganizationPageQueryInput,\n type RootOrganizationRevenuecatEvent,\n type RootOrganizationRevenuecatEventsPage,\n type RootOrganizationsApi,\n type RootOrganizationsPage,\n type RootOrganizationsQueryInput,\n type RootRevenuecatApi,\n type RootRevenuecatEvent,\n type RootRevenuecatEventsQueryInput,\n type RootRevenuecatEventsReportPage,\n type RootRevenuecatEventsReportQueryInput,\n type RootSuspensionApi,\n suspendRootIdentity,\n} from \"./workflows/root\";\nexport type {\n ClearRemoteSyncStateResult,\n DomainSyncCoordinator,\n DomainSyncSnapshot,\n RemoteResetInput,\n RemoteResetReplacement,\n SyncIdleOptions,\n SyncLane,\n SyncLaneConfig,\n SyncLaneLastAction,\n SyncLanePhase,\n SyncLaneSnapshot,\n SyncLaneStatus,\n} from \"./workflows/sync\";\nexport {\n clearRemoteSyncState,\n getDomainSyncCoordinatorSnapshot,\n getOrCreateDomainSyncCoordinator,\n hasDomainSyncCoordinatorPendingWork,\n requestAllDomainSyncLanes,\n subscribeToDomainSyncCoordinator,\n waitForDomainSyncCoordinatorToSettle,\n} from \"./workflows/sync\";\n"]}
@@ -0,0 +1,57 @@
1
+ import { type Change, LoroDoc, type PeerID } from "loro-crdt";
2
+ /** One step of a document's history: a single change by a single peer. */
3
+ export interface HistoryStop {
4
+ peerId: PeerID;
5
+ /** Counter of the change's first operation. */
6
+ startCounter: number;
7
+ /** One past the counter of the change's last operation. */
8
+ endCounter: number;
9
+ lamport: number;
10
+ /** Unix seconds the writer recorded, or null when the change carries none. */
11
+ timestamp: number | null;
12
+ }
13
+ /** One entry of a version: the last operation it includes for a peer. */
14
+ export interface HistoryVersionEntry {
15
+ peerId: PeerID;
16
+ counter: number;
17
+ }
18
+ export interface HistoryViewer {
19
+ /**
20
+ * The scratch document, showing the version last checked out. Read it; do
21
+ * not edit it. It is detached from its own latest version.
22
+ */
23
+ readonly doc: LoroDoc;
24
+ /** Every change in the document, in the order the timeline plays them. */
25
+ readonly stops: ReadonlyArray<HistoryStop>;
26
+ /**
27
+ * Show the document as it was after `stops[0..index]`. `-1` shows the empty
28
+ * document before the first change.
29
+ */
30
+ checkout(index: number): void;
31
+ /** The version after `stops[0..index]`, as the operations that head it. */
32
+ versionAt(index: number): HistoryVersionEntry[];
33
+ /** Release the WASM document. The viewer is unusable afterwards. */
34
+ free(): void;
35
+ }
36
+ /**
37
+ * A document that only ever imports and reads. It has no stable peer and does
38
+ * not record change times, so it must never author.
39
+ */
40
+ export declare function createReadOnlyDocument(): LoroDoc;
41
+ /**
42
+ * Order every change into one timeline: by recorded time, then Lamport time,
43
+ * then peer. A change never plays before a change it depends on, whatever
44
+ * times were recorded, so every prefix of the result is a real version of the
45
+ * document. Honest writers already record times that respect dependencies (a
46
+ * change is never stamped earlier than the newest time its document holds);
47
+ * the dependency check keeps a wrong or hostile clock from producing a prefix
48
+ * that was never a version.
49
+ */
50
+ export declare function orderHistoryStops(changes: ReadonlyMap<PeerID, readonly Change[]>): HistoryStop[];
51
+ /**
52
+ * Build a timeline over a document that already holds the history to browse,
53
+ * and take ownership of it. Pass a scratch document from
54
+ * {@link createReadOnlyDocument}, never a document that is being edited:
55
+ * checking out a version makes the document read-only.
56
+ */
57
+ export declare function openHistoryViewer(doc: LoroDoc): HistoryViewer;
@@ -0,0 +1,271 @@
1
+ import { LoroDoc, VersionVector } from "loro-crdt";
2
+ /**
3
+ * A document that only ever imports and reads. It has no stable peer and does
4
+ * not record change times, so it must never author.
5
+ */
6
+ export function createReadOnlyDocument() {
7
+ return new LoroDoc();
8
+ }
9
+ function comparePeerIds(left, right) {
10
+ // Peer ids are decimal strings of unequal length: order them numerically.
11
+ if (left.length !== right.length)
12
+ return left.length - right.length;
13
+ return left < right ? -1 : Number(left > right);
14
+ }
15
+ function playsBefore(left, right) {
16
+ if (left.time !== right.time)
17
+ return left.time < right.time;
18
+ if (left.stop.lamport !== right.stop.lamport) {
19
+ return left.stop.lamport < right.stop.lamport;
20
+ }
21
+ const peerOrder = comparePeerIds(left.stop.peerId, right.stop.peerId);
22
+ if (peerOrder !== 0)
23
+ return peerOrder < 0;
24
+ return left.stop.startCounter < right.stop.startCounter;
25
+ }
26
+ /** A binary min-heap of node indexes ordered by {@link playsBefore}. */
27
+ class ReadyQueue {
28
+ nodes;
29
+ heap = [];
30
+ constructor(nodes) {
31
+ this.nodes = nodes;
32
+ }
33
+ get size() {
34
+ return this.heap.length;
35
+ }
36
+ push(nodeIndex) {
37
+ const { heap } = this;
38
+ let position = heap.length;
39
+ heap.push(nodeIndex);
40
+ while (position > 0) {
41
+ const parent = (position - 1) >> 1;
42
+ if (!this.before(heap[position], heap[parent]))
43
+ break;
44
+ this.swap(position, parent);
45
+ position = parent;
46
+ }
47
+ }
48
+ pop() {
49
+ const { heap } = this;
50
+ const first = heap[0];
51
+ const last = heap.pop();
52
+ if (first === undefined || last === undefined)
53
+ return undefined;
54
+ if (heap.length === 0)
55
+ return first;
56
+ heap[0] = last;
57
+ let position = 0;
58
+ for (;;) {
59
+ const left = position * 2 + 1;
60
+ const right = left + 1;
61
+ let smallest = position;
62
+ if (this.before(heap[left], heap[smallest]))
63
+ smallest = left;
64
+ if (this.before(heap[right], heap[smallest]))
65
+ smallest = right;
66
+ if (smallest === position)
67
+ break;
68
+ this.swap(position, smallest);
69
+ position = smallest;
70
+ }
71
+ return first;
72
+ }
73
+ before(left, right) {
74
+ const leftNode = left === undefined ? undefined : this.nodes[left];
75
+ const rightNode = right === undefined ? undefined : this.nodes[right];
76
+ return (leftNode !== undefined &&
77
+ rightNode !== undefined &&
78
+ playsBefore(leftNode, rightNode));
79
+ }
80
+ swap(left, right) {
81
+ const { heap } = this;
82
+ const leftValue = heap[left];
83
+ const rightValue = heap[right];
84
+ if (leftValue === undefined || rightValue === undefined)
85
+ return;
86
+ heap[left] = rightValue;
87
+ heap[right] = leftValue;
88
+ }
89
+ }
90
+ /** Index of the peer's change that holds `counter`, or -1 when none does. */
91
+ function findChangeIndex(peerNodes, counter) {
92
+ let low = 0;
93
+ let high = peerNodes.length - 1;
94
+ while (low <= high) {
95
+ const middle = (low + high) >> 1;
96
+ const candidate = peerNodes[middle];
97
+ if (candidate === undefined)
98
+ return -1;
99
+ if (counter < candidate.stop.startCounter) {
100
+ high = middle - 1;
101
+ }
102
+ else if (counter >= candidate.stop.endCounter) {
103
+ low = middle + 1;
104
+ }
105
+ else {
106
+ return candidate.index;
107
+ }
108
+ }
109
+ return -1;
110
+ }
111
+ function toHistoryStop(peerId, change) {
112
+ return {
113
+ peerId,
114
+ startCounter: change.counter,
115
+ endCounter: change.counter + change.length,
116
+ lamport: change.lamport,
117
+ timestamp: change.timestamp > 0 ? change.timestamp : null,
118
+ };
119
+ }
120
+ function buildTimelineGraph(changes) {
121
+ const graph = {
122
+ nodes: [],
123
+ nodesByPeer: new Map(),
124
+ declaredDependencies: [],
125
+ };
126
+ for (const [peerId, peerChanges] of changes) {
127
+ const peerNodes = [];
128
+ const ordered = [...peerChanges].sort((left, right) => left.counter - right.counter);
129
+ for (const change of ordered) {
130
+ const stop = toHistoryStop(peerId, change);
131
+ peerNodes.push({ index: graph.nodes.length, stop });
132
+ graph.nodes.push({
133
+ stop,
134
+ time: stop.timestamp ?? 0,
135
+ dependents: [],
136
+ unmetDependencies: 0,
137
+ });
138
+ graph.declaredDependencies.push(change.deps);
139
+ }
140
+ graph.nodesByPeer.set(peerId, peerNodes);
141
+ }
142
+ return graph;
143
+ }
144
+ /** The nodes that must play before `peerNodes[position]`. */
145
+ function dependenciesOf(graph, peerNodes, position) {
146
+ const dependencies = new Set();
147
+ const current = peerNodes[position];
148
+ if (current === undefined)
149
+ return dependencies;
150
+ // A peer's own changes always play in counter order.
151
+ const previous = peerNodes[position - 1];
152
+ if (previous !== undefined)
153
+ dependencies.add(previous.index);
154
+ for (const dependency of graph.declaredDependencies[current.index] ?? []) {
155
+ const holder = findChangeIndex(graph.nodesByPeer.get(dependency.peer) ?? [], dependency.counter);
156
+ // History that is not held locally cannot be ordered against.
157
+ if (holder >= 0 && holder !== current.index)
158
+ dependencies.add(holder);
159
+ }
160
+ return dependencies;
161
+ }
162
+ function linkDependencies(graph) {
163
+ for (const peerNodes of graph.nodesByPeer.values()) {
164
+ for (const [position, { index }] of peerNodes.entries()) {
165
+ const node = graph.nodes[index];
166
+ if (node === undefined)
167
+ continue;
168
+ const dependencies = dependenciesOf(graph, peerNodes, position);
169
+ node.unmetDependencies = dependencies.size;
170
+ for (const dependency of dependencies) {
171
+ graph.nodes[dependency]?.dependents.push(index);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ /** Play every node whose dependencies have played, earliest first. */
177
+ function playInOrder(nodes) {
178
+ const ready = new ReadyQueue(nodes);
179
+ for (const [index, node] of nodes.entries()) {
180
+ if (node.unmetDependencies === 0)
181
+ ready.push(index);
182
+ }
183
+ const stops = [];
184
+ for (let index = ready.pop(); index !== undefined; index = ready.pop()) {
185
+ const node = nodes[index];
186
+ if (node === undefined)
187
+ continue;
188
+ stops.push(node.stop);
189
+ for (const dependent of node.dependents) {
190
+ const dependentNode = nodes[dependent];
191
+ if (dependentNode === undefined)
192
+ continue;
193
+ dependentNode.unmetDependencies -= 1;
194
+ if (dependentNode.unmetDependencies === 0)
195
+ ready.push(dependent);
196
+ }
197
+ }
198
+ return stops;
199
+ }
200
+ /**
201
+ * Order every change into one timeline: by recorded time, then Lamport time,
202
+ * then peer. A change never plays before a change it depends on, whatever
203
+ * times were recorded, so every prefix of the result is a real version of the
204
+ * document. Honest writers already record times that respect dependencies (a
205
+ * change is never stamped earlier than the newest time its document holds);
206
+ * the dependency check keeps a wrong or hostile clock from producing a prefix
207
+ * that was never a version.
208
+ */
209
+ export function orderHistoryStops(changes) {
210
+ const graph = buildTimelineGraph(changes);
211
+ linkDependencies(graph);
212
+ const stops = playInOrder(graph.nodes);
213
+ if (stops.length !== graph.nodes.length) {
214
+ // Unreachable for a real document: its changes form an acyclic graph.
215
+ throw new Error("Document history has a dependency cycle.");
216
+ }
217
+ return stops;
218
+ }
219
+ class LoroHistoryViewer {
220
+ doc;
221
+ stops;
222
+ /** The version after `stops[0..cursorIndex]`, extended as the cursor moves. */
223
+ cursorIndex = -1;
224
+ cursorVersion = new Map();
225
+ constructor(doc) {
226
+ this.doc = doc;
227
+ doc.detach();
228
+ this.stops = orderHistoryStops(doc.getAllChanges());
229
+ }
230
+ checkout(index) {
231
+ this.doc.checkout(this.versionAt(index).map(({ counter, peerId }) => ({
232
+ counter,
233
+ peer: peerId,
234
+ })));
235
+ // Checking out the newest version re-attaches the document, which would
236
+ // make it editable; a viewer is read-only at every stop.
237
+ this.doc.detach();
238
+ }
239
+ versionAt(index) {
240
+ if (!Number.isInteger(index) || index < -1 || index >= this.stops.length) {
241
+ throw new RangeError(`History stop ${index} is out of range.`);
242
+ }
243
+ if (index < this.cursorIndex) {
244
+ this.cursorIndex = -1;
245
+ this.cursorVersion = new Map();
246
+ }
247
+ while (this.cursorIndex < index) {
248
+ this.cursorIndex += 1;
249
+ const stop = this.stops[this.cursorIndex];
250
+ if (stop !== undefined) {
251
+ this.cursorVersion.set(stop.peerId, stop.endCounter);
252
+ }
253
+ }
254
+ return this.doc
255
+ .vvToFrontiers(VersionVector.parseJSON(this.cursorVersion))
256
+ .map(({ counter, peer }) => ({ counter, peerId: peer }));
257
+ }
258
+ free() {
259
+ this.doc.free();
260
+ }
261
+ }
262
+ /**
263
+ * Build a timeline over a document that already holds the history to browse,
264
+ * and take ownership of it. Pass a scratch document from
265
+ * {@link createReadOnlyDocument}, never a document that is being edited:
266
+ * checking out a version makes the document read-only.
267
+ */
268
+ export function openHistoryViewer(doc) {
269
+ return new LoroHistoryViewer(doc);
270
+ }
271
+ //# sourceMappingURL=historyTimeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"historyTimeline.js","sourceRoot":"","sources":["historyTimeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAe,aAAa,EAAE,MAAM,WAAW,CAAC;AAuC7E;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,OAAO,EAAE,CAAC;AACvB,CAAC;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,0EAA0E;IAC1E,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IACpE,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAClD,CAAC;AAWD,SAAS,WAAW,CAAC,IAAkB,EAAE,KAAmB;IAC1D,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAC5D,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CA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AAI,KAAK,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACzE,MAAM,IAAI,UAAU,CAAC,gBAAgB,KAAK,mBAAmB,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;YACtB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC1C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,GAAG;aACZ,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC1D,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI;QACF,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { type Change, LoroDoc, type PeerID, VersionVector } from \"loro-crdt\";\n\n/** One step of a document's history: a single change by a single peer. */\nexport interface HistoryStop {\n peerId: PeerID;\n /** Counter of the change's first operation. */\n startCounter: number;\n /** One past the counter of the change's last operation. */\n endCounter: number;\n lamport: number;\n /** Unix seconds the writer recorded, or null when the change carries none. */\n timestamp: number | null;\n}\n\n/** One entry of a version: the last operation it includes for a peer. */\nexport interface HistoryVersionEntry {\n peerId: PeerID;\n counter: number;\n}\n\nexport interface HistoryViewer {\n /**\n * The scratch document, showing the version last checked out. Read it; do\n * not edit it. It is detached from its own latest version.\n */\n readonly doc: LoroDoc;\n /** Every change in the document, in the order the timeline plays them. */\n readonly stops: ReadonlyArray<HistoryStop>;\n /**\n * Show the document as it was after `stops[0..index]`. `-1` shows the empty\n * document before the first change.\n */\n checkout(index: number): void;\n /** The version after `stops[0..index]`, as the operations that head it. */\n versionAt(index: number): HistoryVersionEntry[];\n /** Release the WASM document. The viewer is unusable afterwards. */\n free(): void;\n}\n\n/**\n * A document that only ever imports and reads. It has no stable peer and does\n * not record change times, so it must never author.\n */\nexport function createReadOnlyDocument(): LoroDoc {\n return new LoroDoc();\n}\n\nfunction comparePeerIds(left: PeerID, right: PeerID): number {\n // Peer ids are decimal strings of unequal length: order them numerically.\n if (left.length !== right.length) return left.length - right.length;\n return left < right ? -1 : Number(left > right);\n}\n\ninterface TimelineNode {\n readonly stop: HistoryStop;\n /** Sort key: the recorded time, or 0 when there is none. */\n readonly time: number;\n /** Nodes that cannot play before this one. */\n readonly dependents: number[];\n unmetDependencies: number;\n}\n\nfunction playsBefore(left: TimelineNode, right: TimelineNode): boolean {\n if (left.time !== right.time) return left.time < right.time;\n if (left.stop.lamport !== right.stop.lamport) {\n return left.stop.lamport < right.stop.lamport;\n }\n const peerOrder = comparePeerIds(left.stop.peerId, right.stop.peerId);\n if (peerOrder !== 0) return peerOrder < 0;\n return left.stop.startCounter < right.stop.startCounter;\n}\n\n/** A binary min-heap of node indexes ordered by {@link playsBefore}. */\nclass ReadyQueue {\n private readonly heap: number[] = [];\n\n constructor(private readonly nodes: readonly TimelineNode[]) {}\n\n get size(): number {\n return this.heap.length;\n }\n\n push(nodeIndex: number): void {\n const { heap } = this;\n let position = heap.length;\n heap.push(nodeIndex);\n while (position > 0) {\n const parent = (position - 1) >> 1;\n if (!this.before(heap[position], heap[parent])) break;\n this.swap(position, parent);\n position = parent;\n }\n }\n\n pop(): number | undefined {\n const { heap } = this;\n const first = heap[0];\n const last = heap.pop();\n if (first === undefined || last === undefined) return undefined;\n if (heap.length === 0) return first;\n heap[0] = last;\n let position = 0;\n for (;;) {\n const left = position * 2 + 1;\n const right = left + 1;\n let smallest = position;\n if (this.before(heap[left], heap[smallest])) smallest = left;\n if (this.before(heap[right], heap[smallest])) smallest = right;\n if (smallest === position) break;\n this.swap(position, smallest);\n position = smallest;\n }\n return first;\n }\n\n private before(left: number | undefined, right: number | undefined): boolean {\n const leftNode = left === undefined ? undefined : this.nodes[left];\n const rightNode = right === undefined ? undefined : this.nodes[right];\n return (\n leftNode !== undefined &&\n rightNode !== undefined &&\n playsBefore(leftNode, rightNode)\n );\n }\n\n private swap(left: number, right: number): void {\n const { heap } = this;\n const leftValue = heap[left];\n const rightValue = heap[right];\n if (leftValue === undefined || rightValue === undefined) return;\n heap[left] = rightValue;\n heap[right] = leftValue;\n }\n}\n\ninterface PeerNode {\n readonly index: number;\n readonly stop: HistoryStop;\n}\n\ninterface TimelineGraph {\n readonly nodes: TimelineNode[];\n readonly nodesByPeer: Map<PeerID, PeerNode[]>;\n /** The dependencies each change declares, by node index. */\n readonly declaredDependencies: Change[\"deps\"][];\n}\n\n/** Index of the peer's change that holds `counter`, or -1 when none does. */\nfunction findChangeIndex(\n peerNodes: readonly PeerNode[],\n counter: number,\n): number {\n let low = 0;\n let high = peerNodes.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n const candidate = peerNodes[middle];\n if (candidate === undefined) return -1;\n if (counter < candidate.stop.startCounter) {\n high = middle - 1;\n } else if (counter >= candidate.stop.endCounter) {\n low = middle + 1;\n } else {\n return candidate.index;\n }\n }\n return -1;\n}\n\nfunction toHistoryStop(peerId: PeerID, change: Change): HistoryStop {\n return {\n peerId,\n startCounter: change.counter,\n endCounter: change.counter + change.length,\n lamport: change.lamport,\n timestamp: change.timestamp > 0 ? change.timestamp : null,\n };\n}\n\nfunction buildTimelineGraph(\n changes: ReadonlyMap<PeerID, readonly Change[]>,\n): TimelineGraph {\n const graph: TimelineGraph = {\n nodes: [],\n nodesByPeer: new Map(),\n declaredDependencies: [],\n };\n for (const [peerId, peerChanges] of changes) {\n const peerNodes: PeerNode[] = [];\n const ordered = [...peerChanges].sort(\n (left, right) => left.counter - right.counter,\n );\n for (const change of ordered) {\n const stop = toHistoryStop(peerId, change);\n peerNodes.push({ index: graph.nodes.length, stop });\n graph.nodes.push({\n stop,\n time: stop.timestamp ?? 0,\n dependents: [],\n unmetDependencies: 0,\n });\n graph.declaredDependencies.push(change.deps);\n }\n graph.nodesByPeer.set(peerId, peerNodes);\n }\n return graph;\n}\n\n/** The nodes that must play before `peerNodes[position]`. */\nfunction dependenciesOf(\n graph: TimelineGraph,\n peerNodes: readonly PeerNode[],\n position: number,\n): Set<number> {\n const dependencies = new Set<number>();\n const current = peerNodes[position];\n if (current === undefined) return dependencies;\n // A peer's own changes always play in counter order.\n const previous = peerNodes[position - 1];\n if (previous !== undefined) dependencies.add(previous.index);\n for (const dependency of graph.declaredDependencies[current.index] ?? []) {\n const holder = findChangeIndex(\n graph.nodesByPeer.get(dependency.peer) ?? [],\n dependency.counter,\n );\n // History that is not held locally cannot be ordered against.\n if (holder >= 0 && holder !== current.index) dependencies.add(holder);\n }\n return dependencies;\n}\n\nfunction linkDependencies(graph: TimelineGraph): void {\n for (const peerNodes of graph.nodesByPeer.values()) {\n for (const [position, { index }] of peerNodes.entries()) {\n const node = graph.nodes[index];\n if (node === undefined) continue;\n const dependencies = dependenciesOf(graph, peerNodes, position);\n node.unmetDependencies = dependencies.size;\n for (const dependency of dependencies) {\n graph.nodes[dependency]?.dependents.push(index);\n }\n }\n }\n}\n\n/** Play every node whose dependencies have played, earliest first. */\nfunction playInOrder(nodes: readonly TimelineNode[]): HistoryStop[] {\n const ready = new ReadyQueue(nodes);\n for (const [index, node] of nodes.entries()) {\n if (node.unmetDependencies === 0) ready.push(index);\n }\n const stops: HistoryStop[] = [];\n for (let index = ready.pop(); index !== undefined; index = ready.pop()) {\n const node = nodes[index];\n if (node === undefined) continue;\n stops.push(node.stop);\n for (const dependent of node.dependents) {\n const dependentNode = nodes[dependent];\n if (dependentNode === undefined) continue;\n dependentNode.unmetDependencies -= 1;\n if (dependentNode.unmetDependencies === 0) ready.push(dependent);\n }\n }\n return stops;\n}\n\n/**\n * Order every change into one timeline: by recorded time, then Lamport time,\n * then peer. A change never plays before a change it depends on, whatever\n * times were recorded, so every prefix of the result is a real version of the\n * document. Honest writers already record times that respect dependencies (a\n * change is never stamped earlier than the newest time its document holds);\n * the dependency check keeps a wrong or hostile clock from producing a prefix\n * that was never a version.\n */\nexport function orderHistoryStops(\n changes: ReadonlyMap<PeerID, readonly Change[]>,\n): HistoryStop[] {\n const graph = buildTimelineGraph(changes);\n linkDependencies(graph);\n const stops = playInOrder(graph.nodes);\n if (stops.length !== graph.nodes.length) {\n // Unreachable for a real document: its changes form an acyclic graph.\n throw new Error(\"Document history has a dependency cycle.\");\n }\n return stops;\n}\n\nclass LoroHistoryViewer implements HistoryViewer {\n readonly stops: ReadonlyArray<HistoryStop>;\n /** The version after `stops[0..cursorIndex]`, extended as the cursor moves. */\n private cursorIndex = -1;\n private cursorVersion = new Map<PeerID, number>();\n\n constructor(readonly doc: LoroDoc) {\n doc.detach();\n this.stops = orderHistoryStops(doc.getAllChanges());\n }\n\n checkout(index: number): void {\n this.doc.checkout(\n this.versionAt(index).map(({ counter, peerId }) => ({\n counter,\n peer: peerId,\n })),\n );\n // Checking out the newest version re-attaches the document, which would\n // make it editable; a viewer is read-only at every stop.\n this.doc.detach();\n }\n\n versionAt(index: number): HistoryVersionEntry[] {\n if (!Number.isInteger(index) || index < -1 || index >= this.stops.length) {\n throw new RangeError(`History stop ${index} is out of range.`);\n }\n if (index < this.cursorIndex) {\n this.cursorIndex = -1;\n this.cursorVersion = new Map();\n }\n while (this.cursorIndex < index) {\n this.cursorIndex += 1;\n const stop = this.stops[this.cursorIndex];\n if (stop !== undefined) {\n this.cursorVersion.set(stop.peerId, stop.endCounter);\n }\n }\n return this.doc\n .vvToFrontiers(VersionVector.parseJSON(this.cursorVersion))\n .map(({ counter, peer }) => ({ counter, peerId: peer }));\n }\n\n free(): void {\n this.doc.free();\n }\n}\n\n/**\n * Build a timeline over a document that already holds the history to browse,\n * and take ownership of it. Pass a scratch document from\n * {@link createReadOnlyDocument}, never a document that is being edited:\n * checking out a version makes the document read-only.\n */\nexport function openHistoryViewer(doc: LoroDoc): HistoryViewer {\n return new LoroHistoryViewer(doc);\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  export { LoroList, LoroMap } from "loro-crdt";
2
2
  export { DOCUMENT_CHANGE_MERGE_INTERVAL_SECONDS } from "./changeTimestamps.js";
3
3
  export { createDocument, decodeVersionVector, derivePeerId, emptyVersionVector, encodeEncodedVersionVector, encodeVersionVector, exportAllUpdates, exportFullHistoryIdentity, exportFullHistorySnapshot, exportUpdatesSince, type FieldEditor, getImportBlobMetadata, getTextValue, getUpdateVersionVectors, type ImportBlobMode, importSnapshot, importUpdates, LoroImportUnresolvedDependenciesError, listSnapshotCharBlameSource, listSnapshotCharOpIds, listSnapshotFieldEditors, listTextCharOpIds, listVersionVectorSpans, mergeVersionVectors, satisfiesVersionVector, type TextCharBlameSource, type TextCharOpId, type VersionVectorSpan, versionVectorsEqual, } from "./document.js";
4
+ export { createReadOnlyDocument, type HistoryStop, type HistoryVersionEntry, type HistoryViewer, openHistoryViewer, orderHistoryStops, } from "./historyTimeline.js";
4
5
  export * from "./shared/index.js";
5
6
  export { updateMatchesDocumentHistory } from "./updateIdentity.js";
6
7
  export { exportUpdatesInVersionRange, minimumVersionVectors, } from "./versionRange.js";
@@ -1,6 +1,7 @@
1
1
  export { LoroList, LoroMap } from "loro-crdt";
2
2
  export { DOCUMENT_CHANGE_MERGE_INTERVAL_SECONDS } from "./changeTimestamps.js";
3
3
  export { createDocument, decodeVersionVector, derivePeerId, emptyVersionVector, encodeEncodedVersionVector, encodeVersionVector, exportAllUpdates, exportFullHistoryIdentity, exportFullHistorySnapshot, exportUpdatesSince, getImportBlobMetadata, getTextValue, getUpdateVersionVectors, importSnapshot, importUpdates, LoroImportUnresolvedDependenciesError, listSnapshotCharBlameSource, listSnapshotCharOpIds, listSnapshotFieldEditors, listTextCharOpIds, listVersionVectorSpans, mergeVersionVectors, satisfiesVersionVector, versionVectorsEqual, } from "./document.js";
4
+ export { createReadOnlyDocument, openHistoryViewer, orderHistoryStops, } from "./historyTimeline.js";
4
5
  export * from "./shared/index.js";
5
6
  export { updateMatchesDocumentHistory } from "./updateIdentity.js";
6
7
  export { exportUpdatesInVersionRange, minimumVersionVectors, } from "./versionRange.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,0BAA0B,EAC1B,mBAAmB,EACnB,gBAAgB,EAChB,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAElB,qBAAqB,EACrB,YAAY,EACZ,uBAAuB,EAEvB,cAAc,EACd,aAAa,EACb,qCAAqC,EACrC,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EAItB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC","sourcesContent":["export { LoroList, LoroMap } from \"loro-crdt\";\nexport { DOCUMENT_CHANGE_MERGE_INTERVAL_SECONDS } from \"./changeTimestamps\";\nexport {\n createDocument,\n decodeVersionVector,\n derivePeerId,\n emptyVersionVector,\n encodeEncodedVersionVector,\n encodeVersionVector,\n exportAllUpdates,\n exportFullHistoryIdentity,\n exportFullHistorySnapshot,\n exportUpdatesSince,\n type FieldEditor,\n getImportBlobMetadata,\n getTextValue,\n getUpdateVersionVectors,\n type ImportBlobMode,\n importSnapshot,\n importUpdates,\n LoroImportUnresolvedDependenciesError,\n listSnapshotCharBlameSource,\n listSnapshotCharOpIds,\n listSnapshotFieldEditors,\n listTextCharOpIds,\n listVersionVectorSpans,\n mergeVersionVectors,\n satisfiesVersionVector,\n type TextCharBlameSource,\n type TextCharOpId,\n type VersionVectorSpan,\n versionVectorsEqual,\n} from \"./document\";\nexport * from \"./shared\";\nexport { updateMatchesDocumentHistory } from \"./updateIdentity\";\nexport {\n exportUpdatesInVersionRange,\n minimumVersionVectors,\n} from \"./versionRange\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,0BAA0B,EAC1B,mBAAmB,EACnB,gBAAgB,EAChB,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAElB,qBAAqB,EACrB,YAAY,EACZ,uBAAuB,EAEvB,cAAc,EACd,aAAa,EACb,qCAAqC,EACrC,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EAItB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EAItB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC","sourcesContent":["export { LoroList, LoroMap } from \"loro-crdt\";\nexport { DOCUMENT_CHANGE_MERGE_INTERVAL_SECONDS } from \"./changeTimestamps\";\nexport {\n createDocument,\n decodeVersionVector,\n derivePeerId,\n emptyVersionVector,\n encodeEncodedVersionVector,\n encodeVersionVector,\n exportAllUpdates,\n exportFullHistoryIdentity,\n exportFullHistorySnapshot,\n exportUpdatesSince,\n type FieldEditor,\n getImportBlobMetadata,\n getTextValue,\n getUpdateVersionVectors,\n type ImportBlobMode,\n importSnapshot,\n importUpdates,\n LoroImportUnresolvedDependenciesError,\n listSnapshotCharBlameSource,\n listSnapshotCharOpIds,\n listSnapshotFieldEditors,\n listTextCharOpIds,\n listVersionVectorSpans,\n mergeVersionVectors,\n satisfiesVersionVector,\n type TextCharBlameSource,\n type TextCharOpId,\n type VersionVectorSpan,\n versionVectorsEqual,\n} from \"./document\";\nexport {\n createReadOnlyDocument,\n type HistoryStop,\n type HistoryVersionEntry,\n type HistoryViewer,\n openHistoryViewer,\n orderHistoryStops,\n} from \"./historyTimeline\";\nexport * from \"./shared\";\nexport { updateMatchesDocumentHistory } from \"./updateIdentity\";\nexport {\n exportUpdatesInVersionRange,\n minimumVersionVectors,\n} from \"./versionRange\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.207",
3
+ "version": "0.1.208",
4
4
  "description": "React-free Tearleads client runtime: local SQLite persistence, keys, sync, encrypted blobs, and domain workflows.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {