@google-cloud/bigtable
Version:
Cloud Bigtable Client Library for Node.js
63 lines • 2.31 kB
JavaScript
;
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.GCRuleMaker = void 0;
var RuleType;
(function (RuleType) {
RuleType["union"] = "union";
RuleType["intersection"] = "intersection";
})(RuleType || (RuleType = {}));
class GCRuleMaker {
static makeRule(gcRule) {
const rules = [];
if (gcRule.maxAge) {
rules.push({
maxAge: gcRule.maxAge,
});
}
if (gcRule.maxVersions) {
rules.push({
maxNumVersions: gcRule.maxVersions,
});
}
if (gcRule.rule) {
rules.push(this.makeRule(gcRule.rule));
}
if (rules.length === 1) {
if (gcRule.ruleType === RuleType.union) {
throw new Error('A union must have more than one garbage collection rule.');
}
if (gcRule.ruleType === RuleType.intersection) {
throw new Error('An intersection must have more than one garbage collection rule.');
}
if (gcRule.ruleType === RuleType.union &&
gcRule.ruleType === RuleType.intersection) {
throw new Error('A garbage collection rule cannot be both a union and an intersection.');
}
return rules[0];
}
if (rules.length === 0) {
throw new Error('No garbage collection rules were specified.');
}
const rule = {};
const ruleType = gcRule.ruleType === RuleType.union ? 'union' : 'intersection';
rule[ruleType] = {
rules,
};
return rule;
}
}
exports.GCRuleMaker = GCRuleMaker;
//# sourceMappingURL=gc-rule-maker.js.map