@azure/app-configuration-importer 2.0.0-preview → 3.0.1-preview

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.
package/dist/index.js CHANGED
@@ -527,7 +527,17 @@
527
527
  (function (ImportMode) {
528
528
  ImportMode[ImportMode["All"] = 0] = "All";
529
529
  ImportMode[ImportMode["IgnoreMatch"] = 1] = "IgnoreMatch";
530
- })(exports.ImportMode || (exports.ImportMode = {}));
530
+ })(exports.ImportMode || (exports.ImportMode = {}));
531
+ /**
532
+ * Enums of change type for configuration settings changes
533
+ */
534
+ exports.ChangeType = void 0;
535
+ (function (ChangeType) {
536
+ ChangeType[ChangeType["None"] = 0] = "None";
537
+ ChangeType[ChangeType["Create"] = 1] = "Create";
538
+ ChangeType[ChangeType["Delete"] = 2] = "Delete";
539
+ ChangeType[ChangeType["Update"] = 3] = "Update";
540
+ })(exports.ChangeType || (exports.ChangeType = {}));
531
541
 
532
542
  function isFunction(value) {
533
543
  return typeof value === 'function';
@@ -19056,7 +19066,13 @@
19056
19066
  }
19057
19067
  };
19058
19068
  const configurationChanges = await this.GetConfigurationChanges(configurationSettingsSource, options === null || options === void 0 ? void 0 : options.strict, options === null || options === void 0 ? void 0 : options.importMode, customHeadersOption);
19059
- return await this.applyUpdatesToServer([...configurationChanges.ToAdd, ...configurationChanges.ToModify, ...configurationChanges.ToRefresh], configurationChanges.ToDelete, options.timeout, customHeadersOption, options.progressCallback);
19069
+ const settingsToWrite = configurationChanges
19070
+ .filter(c => (c.changeType === exports.ChangeType.Create || c.changeType === exports.ChangeType.Update || c.changeType === exports.ChangeType.None) && c.newValue)
19071
+ .map(c => c.newValue);
19072
+ const settingsToDelete = configurationChanges
19073
+ .filter(c => c.changeType === exports.ChangeType.Delete && c.currentValue)
19074
+ .map(c => c.currentValue);
19075
+ return await this.applyUpdatesToServer(settingsToWrite, settingsToDelete, options.timeout, customHeadersOption, options.progressCallback);
19060
19076
  }
19061
19077
  /**
19062
19078
  * Get configuration changes between source settings and existing settings in Azure App Configuration service without applying any changes
@@ -19077,10 +19093,11 @@
19077
19093
  * 'All' will include all key-values.
19078
19094
  * 'Ignore-Match' will exclude settings that have matching key-values in App Configuration.
19079
19095
  * @param customHeadersOption - Custom headers for the operation.
19080
- * @returns ConfigurationChanges object containing Added, Modified, and Deleted settings
19096
+ * @returns Array of ConfigurationSettingChange objects representing the changes
19081
19097
  */
19082
19098
  async GetConfigurationChanges(configSettingsSource, strict = false, importMode = exports.ImportMode.IgnoreMatch, customHeadersOption) {
19083
19099
  var _a, e_1, _b, _c;
19100
+ var _d, _e;
19084
19101
  this.validateImportMode(importMode);
19085
19102
  // Generate correlationRequestId for operations in the same activity
19086
19103
  if (!customHeadersOption) {
@@ -19100,60 +19117,70 @@
19100
19117
  return configSettingsResult;
19101
19118
  }
19102
19119
  const configSettings = configSettingsResult;
19103
- const configurationSettingToDelete = [];
19104
- const configurationSettingToModify = [];
19105
- const configurationSettingToAdd = [];
19106
- const configurationSettingToRefresh = [];
19107
- const srcKeyLabelLookUp = {};
19108
- configSettings.forEach((config) => {
19109
- if (!srcKeyLabelLookUp[config.key]) {
19110
- srcKeyLabelLookUp[config.key] = {};
19111
- }
19112
- srcKeyLabelLookUp[config.key][config.label || ""] = true;
19113
- });
19114
- configurationSettingToAdd.push(...configSettings);
19120
+ const configurationChanges = [];
19121
+ // Build O(1) lookup structures keyed by "key\0label" composite.
19122
+ const srcMap = new Map();
19123
+ const toAddKeys = new Set();
19124
+ for (const config of configSettings) {
19125
+ const composite = `${config.key}\u0000${(_d = config.label) !== null && _d !== void 0 ? _d : ""}`;
19126
+ srcMap.set(composite, config);
19127
+ toAddKeys.add(composite);
19128
+ }
19115
19129
  try {
19116
- for (var _d = true, _e = __asyncValues(this.configurationClient.listConfigurationSettings(Object.assign(Object.assign({}, configSettingsSource.FilterOptions), customHeadersOption))), _f; _f = await _e.next(), _a = _f.done, !_a;) {
19117
- _c = _f.value;
19118
- _d = false;
19130
+ // Stream target settings so we don't hold the entire remote store in memory.
19131
+ for (var _f = true, _g = __asyncValues(this.configurationClient.listConfigurationSettings(Object.assign(Object.assign({}, configSettingsSource.FilterOptions), customHeadersOption))), _h; _h = await _g.next(), _a = _h.done, !_a;) {
19132
+ _c = _h.value;
19133
+ _f = false;
19119
19134
  try {
19120
19135
  const existing = _c;
19121
- const isKeyLabelPresent = srcKeyLabelLookUp[existing.key] && srcKeyLabelLookUp[existing.key][existing.label || ""];
19122
- if (strict && !isKeyLabelPresent) {
19123
- configurationSettingToDelete.push(existing);
19136
+ const composite = `${existing.key}\u0000${(_e = existing.label) !== null && _e !== void 0 ? _e : ""}`;
19137
+ const incoming = srcMap.get(composite);
19138
+ if (strict && !incoming) {
19139
+ configurationChanges.push({
19140
+ changeType: exports.ChangeType.Delete,
19141
+ currentValue: existing,
19142
+ newValue: null
19143
+ });
19124
19144
  }
19125
- const incoming = configSettings.find(configSetting => configSetting.key == existing.key && configSetting.label === existing.label);
19126
19145
  if (incoming) {
19127
19146
  // Remove from add list since it already exists
19128
- configurationSettingToAdd.splice(configurationSettingToAdd.indexOf(incoming), 1);
19147
+ toAddKeys.delete(composite);
19129
19148
  if (!isConfigSettingEqual(incoming, existing)) {
19130
- // Key-value has changed, add to ToModify
19131
- configurationSettingToModify.push(incoming);
19149
+ configurationChanges.push({
19150
+ changeType: exports.ChangeType.Update,
19151
+ currentValue: existing,
19152
+ newValue: incoming
19153
+ });
19132
19154
  }
19133
19155
  else if (importMode === exports.ImportMode.All) {
19134
- // Key-value is unchanged and importMode is All, add to ToRefresh
19135
- configurationSettingToRefresh.push(incoming);
19156
+ configurationChanges.push({
19157
+ changeType: exports.ChangeType.None,
19158
+ currentValue: existing,
19159
+ newValue: incoming
19160
+ });
19136
19161
  }
19137
19162
  }
19138
19163
  }
19139
19164
  finally {
19140
- _d = true;
19165
+ _f = true;
19141
19166
  }
19142
19167
  }
19143
19168
  }
19144
19169
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
19145
19170
  finally {
19146
19171
  try {
19147
- if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
19172
+ if (!_f && !_a && (_b = _g.return)) await _b.call(_g);
19148
19173
  }
19149
19174
  finally { if (e_1) throw e_1.error; }
19150
19175
  }
19151
- return {
19152
- ToAdd: configurationSettingToAdd,
19153
- ToModify: configurationSettingToModify,
19154
- ToDelete: configurationSettingToDelete,
19155
- ToRefresh: configurationSettingToRefresh
19156
- };
19176
+ for (const composite of toAddKeys) {
19177
+ configurationChanges.push({
19178
+ changeType: exports.ChangeType.Create,
19179
+ currentValue: null,
19180
+ newValue: srcMap.get(composite)
19181
+ });
19182
+ }
19183
+ return configurationChanges;
19157
19184
  }
19158
19185
  async applyUpdatesToServer(settingsToPut, settingsToDelete, timeout, options, progressCallback) {
19159
19186
  const deleteTaskManager = this.newAdaptiveTaskManager((setting) => this.configurationClient.deleteConfigurationSetting(setting, options), settingsToDelete);
@@ -19198,14 +19225,16 @@
19198
19225
  * @internal
19199
19226
  */
19200
19227
  isConfigurationChanges(obj) {
19201
- if (obj === null || typeof obj !== "object") {
19228
+ if (!Array.isArray(obj)) {
19202
19229
  return false;
19203
19230
  }
19204
- const configChanges = obj;
19205
- return Array.isArray(configChanges.ToAdd) &&
19206
- Array.isArray(configChanges.ToModify) &&
19207
- Array.isArray(configChanges.ToDelete) &&
19208
- Array.isArray(configChanges.ToRefresh);
19231
+ // Validate it's an array of ConfigurationSettingChange objects
19232
+ return obj.every(item => item &&
19233
+ typeof item === "object" &&
19234
+ "changeType" in item &&
19235
+ "currentValue" in item &&
19236
+ "newValue" in item &&
19237
+ Object.values(exports.ChangeType).includes(item.changeType));
19209
19238
  }
19210
19239
  }
19211
19240