UNPKG

weaviate-client

Version:
58 lines (57 loc) • 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BeaconPath = void 0; const string_js_1 = require("../validation/string.js"); const version_js_1 = require("../validation/version.js"); const beaconPathPrefix = 'weaviate://localhost'; class BeaconPath { dbVersionSupport; beaconRegExp; constructor(dbVersionSupport) { this.dbVersionSupport = dbVersionSupport; // matches // weaviate://localhost/class/id => match[2] = class, match[4] = id // weaviate://localhost/class/id/ => match[2] = class, match[4] = id // weaviate://localhost/id => match[2] = id, match[4] = undefined // weaviate://localhost/id/ => match[2] = id, match[4] = undefined this.beaconRegExp = /^weaviate:\/\/localhost(\/([^\\/]+))?(\/([^\\/]+))?[\\/]?$/gi; } async rebuild(beacon) { const support = await this.dbVersionSupport.supportsClassNameNamespacedEndpointsPromise(); const match = new RegExp(this.beaconRegExp).exec(beacon); if (!match) { return beacon; } let className; let id; if (match[4] !== undefined) { id = match[4]; className = match[2]; } else { id = match[2]; } let beaconPath = beaconPathPrefix; if (support.supports) { if ((0, string_js_1.isValidStringProperty)(className)) { beaconPath = `${beaconPath}/${className}`; } else { support.warns.deprecatedNonClassNameNamespacedEndpointsForBeacons(); } } else { support.warns.notSupportedClassNamespacedEndpointsForBeacons(); } if (support.version) { if (!(0, version_js_1.isValidWeaviateVersion)(support.version)) { support.warns.deprecatedWeaviateTooOld(); } } if ((0, string_js_1.isValidStringProperty)(id)) { beaconPath = `${beaconPath}/${id}`; } return beaconPath; } } exports.BeaconPath = BeaconPath;