source/node/archiveManagement/marshalling.js
function credentialsToSource(sourceCredentials, archiveCredentials, initialise = false, contentOverride = null) {
    let updated = false;
    const onUpdate = () => {
        updated = true;
    };
    return credentialsToDatasource(sourceCredentials)
        .then(function __handleInitialisation(result) {
            const datasource = result.datasource;
            const defaultArchive = Archive.createWithDefaults();
            if (typeof contentOverride === "string") {
                datasource.setContent(contentOverride);
            }
            datasource.once("updated", onUpdate);
            return initialise
                ? datasource.save(defaultArchive.getHistory(), archiveCredentials).then(() =>
                      Object.assign(
                          {
                              archive: defaultArchive
                          },
                          result
                      )
                  )
                : datasource
                      .load(archiveCredentials)
                      .then(history => Archive.createFromHistory(history))
                      .then(archive =>
                          Object.assign(
                              {
                                  archive
                              },
                              result
                          )
                      );
        })
        .then(function __datasourceToSource(result) {
            const workspace = new Workspace();
            if (typeof contentOverride === "string") {
                // Content is overridden, so it cannot be modified:
                // Setting to readOnly is a safety measure
                const westley = result.archive._getWestley();
                westley.readOnly = true;
            }
            result.datasource.removeListener("updated", onUpdate);
            workspace.setArchive(result.archive, result.datasource, archiveCredentials);
            return {
                workspace,
                sourceCredentials,
                archiveCredentials,
                updated
            };
        });
}
function credentialsToSource(sourceCredentials, archiveCredentials, initialise = false, contentOverride = null) {
    let updated = false;
    const onUpdate = () => {
        updated = true;
    };
    return credentialsToDatasource(sourceCredentials)
        .then(function __handleInitialisation(result) {
            const datasource = result.datasource;
            const defaultArchive = Archive.createWithDefaults();
            if (typeof contentOverride === "string") {
                datasource.setContent(contentOverride);
            }
            datasource.once("updated", onUpdate);
            return initialise
                ? datasource.save(defaultArchive.getHistory(), archiveCredentials).then(() =>
                      Object.assign(
                          {
                              archive: defaultArchive
                          },
                          result
                      )
                  )
                : datasource
                      .load(archiveCredentials)
                      .then(history => Archive.createFromHistory(history))
                      .then(archive =>
                          Object.assign(
                              {
                                  archive
                              },
                              result
                          )
                      );
        })
        .then(function __datasourceToSource(result) {
            const workspace = new Workspace();
            if (typeof contentOverride === "string") {
                // Content is overridden, so it cannot be modified:
                // Setting to readOnly is a safety measure
                const westley = result.archive._getWestley();
                westley.readOnly = true;
            }
            result.datasource.removeListener("updated", onUpdate);
            workspace.setArchive(result.archive, result.datasource, archiveCredentials);
            return {
                workspace,
                sourceCredentials,
                archiveCredentials,
                updated
            };
        });
}
function credentialsToSource ( sourceCredentials , archiveCredentials , initialise = false , contentOverride = null ) { let updated = false ; const onUpdate = ( ) => { updated = true ; } ; return credentialsToDatasource ( sourceCredentials ) . then ( function __handleInitialisation ( result ) { const datasource = result . datasource ; const defaultArchive = Archive . createWithDefaults ( ) ; if ( typeof contentOverride === "string" ) { datasource . setContent ( contentOverride ) ; } datasource . once ( "updated" , onUpdate ) ; return initialise ? datasource . save ( defaultArchive . getHistory ( ) , archiveCredentials ) . then ( ( ) => Object . assign ( { archive : defaultArchive } , result ) ) : datasource . load ( archiveCredentials ) . then ( history => Archive . createFromHistory ( history ) ) . then ( archive => Object . assign ( { archive } , result ) ) ; } ) . then ( function __datasourceToSource ( result ) { const workspace = new Workspace ( ) ; if ( typeof contentOverride === "string" ) { // Content is overridden, so it cannot be modified: // Setting to readOnly is a safety measure const westley = result . archive . _getWestley ( ) ; westley . readOnly = true ; } result . datasource . removeListener ( "updated" , onUpdate ) ; workspace . setArchive ( result . archive , result . datasource , archiveCredentials ) ; return { workspace , sourceCredentials , archiveCredentials , updated } ; } ) ; }
Convert credentials to a source for the ArchiveManager
@param {Credentials} sourceCredentials The remote archive credentials
@param {Credentials} archiveCredentials Credentials for unlocking the archive
@param {Boolean=} initialise Whether or not to initialise a new archive (defaults to false)
@param {String=} contentOverride Content for overriding the fetch operation in the
datasource, for loading offline content
@returns {Promise.<Object>} A promise that resolves with an object containing a workspace,
the source credentials and archive credentials
Convert credentials to a source for the ArchiveManager