-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Wr/decompose permission sets (#1412)
* chore: add initial dpsb2 preset / cloned from dpsb * chore: add new transformer/adapter, default for now * chore: update adapters/transformers with decomposed as base * chore: a lot of changes, writing xml in dirs, now to group by object * fix: decomposing - very messy * fix: recomposing writing file, wrong child entry name CA, not cA * fix: decomposing, recomposing * chore: remove unused adapter * refactor: first round of cleanup * test: add snapshot * refactor: combine writeInfo methods * test: filter decompPS2 preset, not valid as registry entry * chore: bump core * test: export shared functions from Decomposed, add UT * docs: update preset description * chore: code review I * chore: code review II * test: udpate test name, merge main * chore: get name from path correctly * chore: work with singular child type * test: update test name * chore: remove clean up writeInfos * fix: allow for multiple PS's, not 'full' PS * test: add snapshot variation * refactor: simplify names * chore: supporting MPD retrieve * chore: simplify MPD logic * chore: fix merge with parent
- Loading branch information
1 parent
abc4d38
commit 3650332
Showing
55 changed files
with
4,297 additions
and
1,969 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/convert/convertContext/decomposedPermissionSetFinalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { join } from 'node:path'; | ||
import { ensure, ensureString } from '@salesforce/ts-types'; | ||
import type { PermissionSet } from '@jsforce/jsforce-node/lib/api/metadata/schema'; | ||
import { MetadataType } from '../../registry'; | ||
import { XML_NS_KEY, XML_NS_URL } from '../../common/constants'; | ||
import { JsToXml } from '../streams'; | ||
import { WriterFormat } from '../types'; | ||
import { ConvertTransactionFinalizer } from './transactionFinalizer'; | ||
|
||
type PermissionSetState = { | ||
/* | ||
* Incoming child xml (children of PS) which will be partial parts of a PermissionSet, keyed by the parent they belong to | ||
*/ | ||
parentToChild: Map<string, PermissionSet[]>; | ||
}; | ||
|
||
/** | ||
* Merges child components that share the same related object (/objectSettings/<object name>.objectSettings) in the conversion pipeline | ||
* into a single file. | ||
* | ||
* Inserts unclaimed child components into the parent that belongs to the default package | ||
*/ | ||
export class DecomposedPermissionSetFinalizer extends ConvertTransactionFinalizer<PermissionSetState> { | ||
public transactionState: PermissionSetState = { | ||
parentToChild: new Map(), | ||
}; | ||
|
||
/** to support custom presets (the only way this code should get hit at all pass in the type from a transformer that has registry access */ | ||
public permissionSetType?: MetadataType; | ||
|
||
// have to maintain the existing interface | ||
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars | ||
public async finalize(defaultDirectory?: string): Promise<WriterFormat[]> { | ||
if (this.transactionState.parentToChild.size === 0) { | ||
return []; | ||
} | ||
|
||
const agg: WriterFormat[] = []; | ||
this.transactionState.parentToChild.forEach((children, parent) => { | ||
agg.push({ | ||
component: { | ||
type: ensure(this.permissionSetType, 'DecomposedPermissionSetFinalizer should have set PermissionSetType'), | ||
fullName: ensureString(parent), | ||
}, | ||
writeInfos: [ | ||
{ | ||
output: join( | ||
ensure(this.permissionSetType?.directoryName, 'directoryName missing from PermissionSet type'), | ||
`${parent}.permissionset` | ||
), | ||
source: new JsToXml({ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
PermissionSet: { | ||
[XML_NS_KEY]: XML_NS_URL, | ||
...Object.assign( | ||
{}, | ||
// sort the children by fullName | ||
...Object.values(children.sort((a, b) => ((a.fullName ?? '') > (b.fullName ?? '') ? -1 : 1))) | ||
), | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
return agg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.