Skip to content

Commit

Permalink
Change to use compareLayouts for namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 20, 2023
1 parent c01d6c8 commit 3443421
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 3 additions & 7 deletions packages/core/src/storage/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ export class StorageLayoutComparator {
readonly unsafeAllowRenames = false,
) {}

getStorageOperations(
compareLayouts(
original: StorageItem[],
updated: StorageItem[],
originalNamespaces?: Record<string, StorageItem[]>,
updatedNamespaces?: Record<string, StorageItem[]>,
): StorageOperation<StorageItem>[] {
): LayoutCompatibilityReport {
const ops = this.layoutLevenshtein(original, updated, { allowAppend: true });
const namespacedOps = this.getNamespacedStorageOperations(originalNamespaces, updatedNamespaces);

return [...ops, ...namespacedOps];
return new LayoutCompatibilityReport([...ops, ...namespacedOps]);
}

private getNamespacedStorageOperations(
Expand All @@ -144,10 +144,6 @@ export class StorageLayoutComparator {
return ops;
}

compareLayouts(original: StorageItem[], updated: StorageItem[]): LayoutCompatibilityReport {
return new LayoutCompatibilityReport(this.getStorageOperations(original, updated));
}

private layoutLevenshtein<F extends StorageField>(
original: F[],
updated: F[],
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ export function getStorageUpgradeReport(
const updatedDetailedNamespaces = getDetailedNamespacedLayout(updated);

const comparator = new StorageLayoutComparator(opts.unsafeAllowCustomTypes, opts.unsafeAllowRenames);
const ops = comparator.getStorageOperations(
const report = comparator.compareLayouts(
originalDetailed,
updatedDetailed,
originalDetailedNamespaces,
updatedDetailedNamespaces,
);

const report = new LayoutCompatibilityReport(ops);

if (comparator.hasAllowedUncheckedCustomTypes) {
logWarning(`Potentially unsafe deployment`, [
`You are using \`unsafeAllowCustomTypes\` to force approve structs or enums with missing data.`,
Expand Down

0 comments on commit 3443421

Please sign in to comment.