import { IChannelAttributes , IFluidDataStoreRuntime , IChannelServices , IChannelFactory , } from "@fluidframework/datastore-definitions" ; import { IJSONSegment , Marker , TextSegment , } from "@fluidframework/merge-tree" ; import { ISharedObject } from "@fluidframework/shared-object-base" ; import { pkgVersion } from "./packageVersion" ; import { SharedNumberSequence } from "./sharedNumberSequence" ; import { SharedObjectSequence } from "./sharedObjectSequence" ; import { IJSONRunSegment , SubSequence } from "./sharedSequence" ; import { SharedString , SharedStringSegment } from "./sharedString" ; export class SharedStringFactory implements IChannelFactory { public static Type = "https://graph.microsoft.com/types/mergeTree" ; public static readonly Attributes : IChannelAttributes = { type : SharedStringFactory . Type , snapshotFormatVersion : "0.1" , packageVersion : pkgVersion } ; public static segmentFromSpec ( spec ) { const maybeText = TextSegment . fromJSONObject ( spec ) ; if ( maybeText ) { return maybeText ; } const maybeMarker = Marker . fromJSONObject ( spec ) ; if ( maybeMarker ) { return maybeMarker ; } } public get type ( ) { return SharedStringFactory . Type ; } public get attributes ( ) { return SharedStringFactory . Attributes ; } /**
     * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
     */ public async load ( runtime , id , services , attributes ) { const sharedString = new SharedString ( runtime , id , attributes ) ; await sharedString . load ( services ) ; return sharedString ; } public create ( document , id ) { const sharedString = new SharedString ( document , id , this . attributes ) ; sharedString . initializeLocal ( ) ; return sharedString ; } } deprecated export class SharedObjectSequenceFactory implements IChannelFactory { deprecated public static Type = "https://graph.microsoft.com/types/mergeTree/object-sequence" ; deprecated public static readonly Attributes : IChannelAttributes = { type : SharedObjectSequenceFactory . Type , snapshotFormatVersion : "0.1" , packageVersion : pkgVersion } ; deprecated public static segmentFromSpec ( segSpec ) { const runSegment = segSpec as IJSONRunSegment < object > ; if ( runSegment . items ) { const seg = new SubSequence < object > ( runSegment . items ) ; if ( runSegment . props ) { seg . addProperties ( runSegment . props ) ; } return seg ; } } deprecated public get type ( ) { return SharedObjectSequenceFactory . Type ; } deprecated public get attributes ( ) { return SharedObjectSequenceFactory . Attributes ; } deprecated public async load ( runtime , id , services , attributes ) { const sharedSeq = new SharedObjectSequence < object > ( runtime , id , attributes ) ; await sharedSeq . load ( services ) ; return sharedSeq ; } deprecated public create ( document , id ) { const sharedString = new SharedObjectSequence ( document , id , this . attributes ) ; sharedString . initializeLocal ( ) ; return sharedString ; } } deprecated export class SharedNumberSequenceFactory implements IChannelFactory { deprecated public static Type = "https://graph.microsoft.com/types/mergeTree/number-sequence" ; deprecated public static readonly Attributes : IChannelAttributes = { type : SharedNumberSequenceFactory . Type , snapshotFormatVersion : "0.1" , packageVersion : pkgVersion } ; deprecated public static segmentFromSpec ( segSpec ) { const runSegment = segSpec as IJSONRunSegment < number > ; if ( runSegment . items ) { const seg = new SubSequence < number > ( runSegment . items ) ; if ( runSegment . props ) { seg . addProperties ( runSegment . props ) ; } return seg ; } } deprecated public get type ( ) { return SharedNumberSequenceFactory . Type ; } deprecated public get attributes ( ) { return SharedNumberSequenceFactory . Attributes ; } deprecated public async load ( runtime , id , services , attributes ) { const sharedSeq = new SharedNumberSequence ( runtime , id , attributes ) ; await sharedSeq . load ( services ) ; return sharedSeq ; } deprecated public create ( document , id ) { const sharedString = new SharedNumberSequence ( document , id , this . attributes ) ; sharedString . initializeLocal ( ) ; return sharedString ; } }