@grafana/plugin-ui 0.14.1-dsconfig.9143abf → 0.14.1-dsconfig.a233348

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12722,6 +12722,101 @@ const convertUnits = (queryStats) => {
12722
12722
  return text + suffix;
12723
12723
  };
12724
12724
 
12725
+ const ROOT_CONFIG_FIELDS = [
12726
+ "name",
12727
+ "type",
12728
+ "id",
12729
+ "uid",
12730
+ "access",
12731
+ "url",
12732
+ "basicAuth",
12733
+ "basicAuthUser",
12734
+ "user",
12735
+ "isDefault",
12736
+ "database",
12737
+ "withCredentials"
12738
+ ];
12739
+ const buildCreateDatasourcePayload = (input) => {
12740
+ const body = { name: input.name, type: input.type, access: "proxy" };
12741
+ if (input.jsonData !== void 0) {
12742
+ body.jsonData = { ...input.jsonData };
12743
+ }
12744
+ normalizeDatasourceConfig(body, input, { inferAuthMethod: true });
12745
+ return body;
12746
+ };
12747
+ const buildCloneDatasourcePayload = (source, name) => {
12748
+ var _a;
12749
+ return { ...source, name, access: (_a = source.access) != null ? _a : "proxy", isDefault: false };
12750
+ };
12751
+ const buildUpdateDatasourcePayload = (existing, input) => {
12752
+ var _a;
12753
+ const body = {
12754
+ name: existing.name,
12755
+ type: existing.type,
12756
+ access: existing.access,
12757
+ url: existing.url,
12758
+ database: existing.database,
12759
+ basicAuth: existing.basicAuth,
12760
+ basicAuthUser: existing.basicAuthUser,
12761
+ isDefault: existing.isDefault,
12762
+ user: existing.user,
12763
+ withCredentials: existing.withCredentials,
12764
+ jsonData: existing.jsonData
12765
+ };
12766
+ let hasChanges = false;
12767
+ const UPDATE_COMPARABLE_FIELDS = ["name", "url", "database", "isDefault", "basicAuth"];
12768
+ for (const key of UPDATE_COMPARABLE_FIELDS) {
12769
+ if (input[key] !== void 0 && input[key] !== existing[key]) {
12770
+ body[key] = input[key];
12771
+ hasChanges = true;
12772
+ }
12773
+ }
12774
+ if (input.jsonData !== void 0) {
12775
+ body.jsonData = { ...(_a = existing.jsonData) != null ? _a : {}, ...input.jsonData };
12776
+ hasChanges = true;
12777
+ hasChanges = normalizeDatasourceConfig(body, input) || hasChanges;
12778
+ }
12779
+ return { body, hasChanges };
12780
+ };
12781
+ const normalizeDatasourceConfig = (body, input, options = {}) => {
12782
+ const changed = hoistRootConfigFields(body, input);
12783
+ if (options.inferAuthMethod) {
12784
+ applyInferredAuthMethod(body, input);
12785
+ }
12786
+ return changed;
12787
+ };
12788
+ const hoistRootConfigFields = (body, input) => {
12789
+ var _a;
12790
+ const jsonData = (_a = body.jsonData) != null ? _a : {};
12791
+ let changed = false;
12792
+ for (const key of ROOT_CONFIG_FIELDS) {
12793
+ if (jsonData[key] === void 0) {
12794
+ continue;
12795
+ }
12796
+ if (input[key] === void 0) {
12797
+ body[key] = jsonData[key];
12798
+ changed = true;
12799
+ }
12800
+ delete jsonData[key];
12801
+ }
12802
+ body.jsonData = jsonData;
12803
+ return changed;
12804
+ };
12805
+ const applyInferredAuthMethod = (body, input) => {
12806
+ var _a;
12807
+ const jsonData = (_a = body.jsonData) != null ? _a : {};
12808
+ if (jsonData.authMethod !== void 0) {
12809
+ body.jsonData = jsonData;
12810
+ return;
12811
+ }
12812
+ if (jsonData.oauthPassThru === true) {
12813
+ jsonData.authMethod = "forward_oauth";
12814
+ } else if (body.basicAuth === true || input.basicAuth === true) {
12815
+ jsonData.authMethod = "basic";
12816
+ }
12817
+ body.jsonData = jsonData;
12818
+ };
12819
+
12725
12820
  function generateLLMHint(schema) {
12726
12821
  var _a, _b, _c, _d;
12727
12822
  const hints = [];
@@ -12774,21 +12869,6 @@ function generateTroubleshootingFields(schema) {
12774
12869
  return result;
12775
12870
  }
12776
12871
 
12777
- const ROOT_CONFIG_FIELDS = [
12778
- "name",
12779
- "type",
12780
- "id",
12781
- "uid",
12782
- "access",
12783
- "url",
12784
- "basicAuth",
12785
- "basicAuthUser",
12786
- "user",
12787
- "isDefault",
12788
- "database",
12789
- "withCredentials"
12790
- ];
12791
-
12792
12872
  function yamlIndent(depth) {
12793
12873
  return " ".repeat(depth);
12794
12874
  }
@@ -13272,6 +13352,7 @@ exports.QueryFormat = QueryFormat;
13272
13352
  exports.QueryHeaderSwitch = QueryHeaderSwitch;
13273
13353
  exports.QueryModellerBase = QueryModellerBase;
13274
13354
  exports.QueryOptionGroup = QueryOptionGroup;
13355
+ exports.ROOT_CONFIG_FIELDS = ROOT_CONFIG_FIELDS;
13275
13356
  exports.RawQuery = RawQuery;
13276
13357
  exports.RunQueryButton = RunQueryButton;
13277
13358
  exports.SECURE_FIELD_CONFIGURED = SECURE_FIELD_CONFIGURED;
@@ -13288,7 +13369,10 @@ exports.SuggestionKind = SuggestionKind;
13288
13369
  exports.TLSSettings = TLSSettings;
13289
13370
  exports.TableSelector = TableSelector;
13290
13371
  exports.TokenType = TokenType;
13372
+ exports.buildCloneDatasourcePayload = buildCloneDatasourcePayload;
13373
+ exports.buildCreateDatasourcePayload = buildCreateDatasourcePayload;
13291
13374
  exports.buildDatasourceConfigPayload = buildDatasourceConfigPayload;
13375
+ exports.buildUpdateDatasourcePayload = buildUpdateDatasourcePayload;
13292
13376
  exports.computeVirtualFieldValues = computeVirtualFieldValues;
13293
13377
  exports.configToYaml = configToYaml;
13294
13378
  exports.convertLegacyAuthProps = convertLegacyAuthProps;