ravendb
Version:
RavenDB client for Node.js
465 lines • 15.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabaseRecordBuilder = void 0;
const TypeUtil_js_1 = require("../../Utility/TypeUtil.js");
class DatabaseRecordBuilder {
static create() {
return new DatabaseRecordBuilder();
}
_shardTopology;
_databaseRecord;
constructor() {
this._databaseRecord = {
databaseName: undefined
};
}
addPeriodicBackup(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.periodicBackups ??= [];
this._databaseRecord.periodicBackups.push(configuration);
return this;
}
addRavenConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.ravenConnectionStrings ??= {};
this._databaseRecord.ravenConnectionStrings[connectionString.name] = connectionString;
return this;
}
addSqlConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.sqlConnectionStrings ??= {};
this._databaseRecord.sqlConnectionStrings[connectionString.name] = connectionString;
return this;
}
addOlapConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.olapConnectionStrings ??= {};
this._databaseRecord.olapConnectionStrings[connectionString.name] = connectionString;
return this;
}
addElasticSearchConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.elasticSearchConnectionStrings = {};
this._databaseRecord.elasticSearchConnectionStrings[connectionString.name] = connectionString;
return this;
}
addQueueConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.queueConnectionStrings ??= {};
this._databaseRecord.queueConnectionStrings[connectionString.name] = connectionString;
return this;
}
addAiConnectionString(connectionString) {
if (!connectionString) {
throw new Error("ConnectionString cannot be null");
}
this._databaseRecord.aiConnectionStrings ??= {};
this._databaseRecord.aiConnectionStrings[connectionString.name] = connectionString;
return this;
}
regular(databaseName) {
this._withName(databaseName);
return this;
}
sharded(databaseName, builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
this._withName(databaseName);
this._databaseRecord.sharding = {};
builder(this);
if (!this._databaseRecord.sharding.shards || Object.keys(this._databaseRecord.sharding.shards).length === 0) {
throw new Error("At least one shard is required. Use addShard to add a shard to the topology");
}
return this;
}
addRavenEtl(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.ravenEtls ??= [];
this._databaseRecord.ravenEtls.push(configuration);
return this;
}
addSqlEtl(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.sqlEtls ??= [];
this._databaseRecord.sqlEtls.push(configuration);
return this;
}
addElasticSearchEtl(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.elasticSearchEtls ??= [];
this._databaseRecord.elasticSearchEtls.push(configuration);
return this;
}
addOlapEtl(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.olapEtls ??= [];
this._databaseRecord.olapEtls.push(configuration);
return this;
}
addQueueEtl(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.queueEtls ??= [];
this._databaseRecord.queueEtls.push(configuration);
return this;
}
configurePostgreSql(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.integrations ??= {
postgreSql: null
};
this._databaseRecord.integrations.postgreSql = configuration;
return this;
}
addExternalReplication(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.externalReplications ??= [];
this._databaseRecord.externalReplications.push(configuration);
return this;
}
addPullReplicationSink(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.sinkPullReplications ??= [];
this._databaseRecord.sinkPullReplications.push(configuration);
return this;
}
addPullReplicationHub(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.hubPullReplications ??= [];
this._databaseRecord.hubPullReplications.push(configuration);
return this;
}
encrypted() {
this._databaseRecord.encrypted = true;
return this;
}
withLockMode(lockMode) {
this._databaseRecord.lockMode = lockMode;
return this;
}
configureDocumentsCompression(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.documentsCompression = configuration;
return this;
}
withSorters(...sorterDefinitions) {
if (!sorterDefinitions || sorterDefinitions.length === 0) {
return this;
}
this._databaseRecord.sorters ??= {};
for (const sorterDefinition of sorterDefinitions) {
this._databaseRecord.sorters[sorterDefinition.name] = sorterDefinition;
}
return this;
}
withAnalyzers(...analyzerDefinitions) {
if (!analyzerDefinitions || analyzerDefinitions.length === 0) {
return this;
}
this._databaseRecord.analyzers ??= {};
for (const analyzerDefinition of analyzerDefinitions) {
this._databaseRecord.analyzers[analyzerDefinition.name] = analyzerDefinition;
}
return this;
}
withIndexes(...indexDefinitions) {
if (!indexDefinitions || indexDefinitions.length === 0) {
return this;
}
this._databaseRecord.indexes ??= {};
for (const indexDefinition of indexDefinitions) {
this._databaseRecord.indexes[indexDefinition.name] = indexDefinition;
}
return this;
}
withSettings(settings) {
if (!settings) {
throw new Error("Settings cannot be null");
}
this._databaseRecord.settings = settings;
return this;
}
configureRevisions(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.revisions = configuration;
return this;
}
withEtls(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(this);
return this;
}
withBackups(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(this);
return this;
}
withReplication(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(this);
return this;
}
withConnectionStrings(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(this);
return this;
}
configureClient(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.client = configuration;
return this;
}
configureStudio(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.studio = configuration;
return this;
}
configureRefresh(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.refresh = configuration;
return this;
}
configureExpiration(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.expiration = configuration;
return this;
}
configureTimeSeries(configuration) {
if (!configuration) {
throw new Error("Configuration cannot be null");
}
this._databaseRecord.timeSeries = configuration;
return this;
}
withIntegrations(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(this);
return this;
}
toDatabaseRecord() {
return this._databaseRecord;
}
disabled() {
this._databaseRecord.disabled = true;
return this;
}
orchestrator(topologyOrBuilder) {
if (TypeUtil_js_1.TypeUtil.isFunction(topologyOrBuilder)) {
return this._orchestratorUsingBuilder(topologyOrBuilder);
}
return this._orchestratorUsingTopology(topologyOrBuilder);
}
_orchestratorUsingTopology(topology) {
if (!topology) {
throw new Error("Topology cannot be null");
}
this._databaseRecord.sharding.orchestrator ??= {
topology: null
};
this._databaseRecord.sharding.orchestrator.topology = topology;
return this;
}
_orchestratorUsingBuilder(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(new this.orchestratorTopologyConfigurationBuilder(this));
return this;
}
orchestratorTopologyConfigurationBuilder = class OrchestratorTopologyConfigurationBuilder {
_builder;
constructor(builder) {
this._builder = builder;
}
addNode(nodeTag) {
if (!nodeTag) {
throw new Error("NodeTag cannot be null");
}
this._builder._databaseRecord.sharding.orchestrator ??= {
topology: null
};
this._builder._databaseRecord.sharding.orchestrator.topology ??= {
members: [],
promotables: [],
rehabs: []
};
this._builder._databaseRecord.sharding.orchestrator.topology.members.push(nodeTag);
return this;
}
enableDynamicNodesDistribution() {
this._builder._databaseRecord.sharding.orchestrator ??= {
topology: null
};
this._builder._databaseRecord.sharding.orchestrator.topology ??= {
members: [],
rehabs: [],
promotables: []
};
this._builder._databaseRecord.sharding.orchestrator.topology.dynamicNodesDistribution = true;
return this;
}
};
addShard(shardNumber, topologyOrBuilder) {
if (TypeUtil_js_1.TypeUtil.isFunction(topologyOrBuilder)) {
return this._addShardUsingBuilder(shardNumber, topologyOrBuilder);
}
return this._addShardUsingTopology(shardNumber, topologyOrBuilder);
}
_addShardUsingTopology(shardNumber, topology) {
if (!topology) {
throw new Error("Topology cannot be null");
}
this._databaseRecord.sharding.shards ??= {};
this._databaseRecord.sharding.shards[shardNumber] = topology;
return this;
}
_addShardUsingBuilder(shardNumber, builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
this._shardTopology = {
members: [],
rehabs: [],
promotables: []
};
try {
builder(new this._shardTopologyConfigurationBuilder(this));
this._databaseRecord.sharding.shards ??= {};
this._databaseRecord.sharding.shards[shardNumber] = this._shardTopology;
}
finally {
this._shardTopology = null;
}
return this;
}
_shardTopologyConfigurationBuilder = class ShardTopologyConfigurationBuilder {
_builder;
constructor(builder) {
this._builder = builder;
}
addNode(nodeTag) {
if (!nodeTag) {
throw new Error("NodeTag cannot be null");
}
this._builder._shardTopology.members.push(nodeTag);
return this;
}
enableDynamicNodesDistribution() {
this._builder._shardTopology.dynamicNodesDistribution = true;
return this;
}
};
withTopology(builderOrTopology) {
if (TypeUtil_js_1.TypeUtil.isFunction(builderOrTopology)) {
return this._withTopologyUsingBuilder(builderOrTopology);
}
return this._withTopologyUsingTopology(builderOrTopology);
}
_withTopologyUsingTopology(topology) {
if (!topology) {
throw new Error("Topology cannot be null");
}
this._databaseRecord.topology = topology;
return this;
}
_withTopologyUsingBuilder(builder) {
if (!builder) {
throw new Error("Builder cannot be null");
}
builder(new this._topologyConfigurationBuilder(this));
return this;
}
_topologyConfigurationBuilder = class TopologyConfigurationBuilder {
_builder;
constructor(builder) {
this._builder = builder;
}
addNode(nodeTag) {
this._builder._databaseRecord.topology ??= {
members: [],
rehabs: [],
promotables: []
};
this._builder._databaseRecord.topology.members.push(nodeTag);
return this;
}
enableDynamicNodesDistribution() {
this._builder._databaseRecord.sharding.orchestrator ??= {
topology: null
};
this._builder._databaseRecord.sharding.orchestrator.topology ??= {
members: [],
promotables: [],
rehabs: []
};
this._builder._databaseRecord.sharding.orchestrator.topology.dynamicNodesDistribution = true;
return this;
}
};
withReplicationFactor(replicationFactor) {
this._databaseRecord.topology ??= {
members: [],
rehabs: [],
promotables: []
};
this._databaseRecord.topology.replicationFactor = replicationFactor;
return this;
}
_withName(databaseName) {
this._databaseRecord.databaseName = databaseName;
}
}
exports.DatabaseRecordBuilder = DatabaseRecordBuilder;
//# sourceMappingURL=DatabaseRecordBuilder.js.map