Skip to content

Commit a0b6b20

Browse files
authored
Merge pull request #17 from ritaagarwala-sf/main
Updating sf data-code-extension function init to accept --use-ini-feature
2 parents 9ae8c42 + b4772c5 commit a0b6b20

15 files changed

Lines changed: 194 additions & 134 deletions

File tree

README.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,18 @@ Deploy a Data Code Extension function package to a Salesforce org.
8686

8787
```
8888
USAGE
89-
$ sf data-code-extension function deploy -n <value> --package-version <value> -d <value> -p <value> -o <value> --function-invoke-opt
90-
UnstructuredChunking [--flags-dir <value>] [--network <value>] [--cpu-size CPU_L|CPU_XL|CPU_2XL|CPU_4XL]
89+
$ sf data-code-extension function deploy -n <value> --package-version <value> -d <value> -p <value> -o <value> [--flags-dir <value>]
90+
[--network <value>] [--cpu-size CPU_L|CPU_XL|CPU_2XL|CPU_4XL]
9191
9292
FLAGS
93-
-d, --description=<value> (required) Description of the package.
94-
-n, --name=<value> (required) Name of the package to deploy.
95-
-o, --target-org=<value> (required) Target Salesforce org for deployment.
96-
-p, --package-dir=<value> (required) Directory containing the packaged code.
97-
--cpu-size=<option> [default: CPU_2XL] CPU size for the deployment.
98-
<options: CPU_L|CPU_XL|CPU_2XL|CPU_4XL>
99-
--function-invoke-opt=<option> (required) Function invocation option (function packages only).
100-
<options: UnstructuredChunking>
101-
--network=<value> Network configuration for Jupyter notebooks.
102-
--package-version=<value> (required) Version of the package to deploy.
93+
-d, --description=<value> (required) Description of the package.
94+
-n, --name=<value> (required) Name of the package to deploy.
95+
-o, --target-org=<value> (required) Target Salesforce org for deployment.
96+
-p, --package-dir=<value> (required) Directory containing the packaged code.
97+
--cpu-size=<option> [default: CPU_2XL] CPU size for the deployment.
98+
<options: CPU_L|CPU_XL|CPU_2XL|CPU_4XL>
99+
--network=<value> Network configuration for Jupyter notebooks.
100+
--package-version=<value> (required) Version of the package to deploy.
103101
104102
GLOBAL FLAGS
105103
--flags-dir=<value> Import flag values from a directory.
@@ -115,12 +113,12 @@ EXAMPLES
115113
Deploy a function package to the org with alias "myorg":
116114
117115
$ sf data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" \
118-
--package-dir ./payload --target-org myorg --function-invoke-opt UnstructuredChunking
116+
--package-dir ./payload --target-org myorg
119117
120118
Deploy with a specific CPU size:
121119
122120
$ sf data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" \
123-
--package-dir ./payload --target-org myorg --cpu-size CPU_4XL --function-invoke-opt UnstructuredChunking
121+
--package-dir ./payload --target-org myorg --cpu-size CPU_4XL
124122
125123
FLAG DESCRIPTIONS
126124
-d, --description=<value> Description of the package.
@@ -148,10 +146,6 @@ FLAG DESCRIPTIONS
148146
The CPU allocation size for your deployed package. Options are: CPU_L (small), CPU_XL (large), CPU_2XL (extra large,
149147
default), CPU_4XL (maximum). Higher CPU sizes provide more processing power but may have quota implications.
150148
151-
--function-invoke-opt=UnstructuredChunking Function invocation option (function packages only).
152-
153-
Configuration for how functions should be invoked. UnstructuredChunking is only valid option at this point
154-
155149
--network=<value> Network configuration for Jupyter notebooks.
156150
157151
Optional network configuration setting for packages that include Jupyter notebooks. Common values include 'host' for
@@ -171,10 +165,13 @@ Initialize the Data Code Extension function package.
171165

172166
```
173167
USAGE
174-
$ sf data-code-extension function init -p <value> [--flags-dir <value>]
168+
$ sf data-code-extension function init -p <value> [--flags-dir <value>] [-u SearchIndexChunking]
175169
176170
FLAGS
177-
-p, --package-dir=<value> (required) Directory path where the package will be created.
171+
-p, --package-dir=<value> (required) Directory path where the package will be created.
172+
-u, --use-in-feature=<option> [default: SearchIndexChunking] Feature flag for function initialization (function
173+
packages only).
174+
<options: SearchIndexChunking>
178175
179176
GLOBAL FLAGS
180177
--flags-dir=<value> Import flag values from a directory.
@@ -193,6 +190,11 @@ FLAG DESCRIPTIONS
193190
-p, --package-dir=<value> Directory path where the package will be created.
194191
195192
The directory path where the new package will be initialized. The directory will be created if it doesn't exist.
193+
194+
-u, --use-in-feature=SearchIndexChunking Feature flag for function initialization (function packages only).
195+
196+
Configuration for which feature this function will be used in. SearchIndexChunking is the only valid option and is
197+
used by default if not specified.
196198
```
197199

198200
_See code: [src/commands/data-code-extension/function/init.ts](https://github.com/salesforcecli/plugin-data-code-extension/blob/0.1.5/src/commands/data-code-extension/function/init.ts)_
@@ -203,12 +205,12 @@ Run a Data Code Extension function package locally using data from your Salesfor
203205

204206
```
205207
USAGE
206-
$ sf data-code-extension function run -e <value> -o <value> [--flags-dir <value>] [--config-file <value>]
208+
$ sf data-code-extension function run -e <value> -t <value> [--flags-dir <value>] [--config-file <value>]
207209
[--dependencies <value>]
208210
209211
FLAGS
210212
-e, --entrypoint=<value> (required) Entrypoint file for the package to run.
211-
-o, --target-org=<value> (required) Target Salesforce org to run against.
213+
-t, --test-with=<value> (required) Path to test.json file to test Data Code Extension function
212214
--config-file=<value> Path to a config file.
213215
--dependencies=<value> Dependencies override for the run.
214216
@@ -222,25 +224,24 @@ DESCRIPTION
222224
before running. Supports both script and function packages with optional config file and dependencies overrides.
223225
224226
EXAMPLES
225-
Run a function package against the org with alias "myorg":
227+
Run a function package:
226228
227-
$ sf data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --target-org \
228-
myorg
229+
$ sf data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --test-with \
230+
./my-function-package/payload/tests/test.json
229231
230232
Run with a custom config file:
231233
232-
$ sf data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --target-org \
233-
myorg --config-file ./my-function-package/payload/config.json
234+
$ sf data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --test-with \
235+
./my-function-package/payload/tests/test.json --config-file ./my-function-package/payload/config.json
234236
235237
FLAG DESCRIPTIONS
236238
-e, --entrypoint=<value> Entrypoint file for the package to run.
237239
238240
The path to the entrypoint file of your initialized Data Cloud custom code package.
239241
240-
-o, --target-org=<value> Target Salesforce org to run against.
242+
-t, --test-with=<value> Path to test.json file to test Data Code Extension function
241243
242-
The alias or username of the Salesforce org where you want to run the Data Cloud custom code package. The org must
243-
have Data Cloud enabled and appropriate permissions.
244+
Path to a JSON file that provides input request for the function.
244245
245246
--config-file=<value> Path to a config file.
246247

messages/deploy.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Deploys an initialized and packaged Data Cloud code extension to a Salesforce or
3030

3131
- Deploy a function package to the org with alias "myorg":
3232

33-
<%= config.bin %> data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" --package-dir ./payload --target-org myorg --function-invoke-opt UnstructuredChunking
33+
<%= config.bin %> data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" --package-dir ./payload --target-org myorg
3434

3535
- Deploy with a specific CPU size:
3636

37-
<%= config.bin %> data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" --package-dir ./payload --target-org myorg --cpu-size CPU_4XL --function-invoke-opt UnstructuredChunking
37+
<%= config.bin %> data-code-extension function deploy --name my-package --package-version 1.0.0 --description "My package" --package-dir ./payload --target-org myorg --cpu-size CPU_4XL
3838

3939
# info.checkingPython
4040

@@ -152,14 +152,6 @@ Target Salesforce org for deployment.
152152

153153
The alias or username of the Salesforce org where you want to deploy the Data Cloud custom code package. The org must have Data Cloud enabled and appropriate permissions.
154154

155-
# flags.functionInvokeOpt.summary
156-
157-
Function invocation option (function packages only).
158-
159-
# flags.functionInvokeOpt.description
160-
161-
Configuration for how functions should be invoked. UnstructuredChunking is only valid option at this point
162-
163155
# error.flagEmpty
164156

165157
The --%s flag requires a non-empty value.

messages/init.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ Initializes the Data Code Extension by checking system requirements and setting
1212

1313
<%= config.bin %> data-code-extension %s init --package-dir ./my-%s-package
1414

15+
# examples.function
16+
17+
- Initialize a function package (uses SearchIndexChunking by default):
18+
19+
<%= config.bin %> data-code-extension function init --package-dir ./my-function-package
20+
21+
- Initialize a function package with explicit feature flag:
22+
23+
<%= config.bin %> data-code-extension function init --package-dir ./my-function-package --use-in-feature SearchIndexChunking
24+
25+
# examples.script
26+
27+
- Initialize a script package:
28+
29+
<%= config.bin %> data-code-extension script init --package-dir ./my-script-package
30+
1531
# info.checkingPython
1632

1733
Checking Python version...
@@ -67,3 +83,11 @@ Directory path where the package will be created.
6783
# flags.packageDir.description
6884

6985
The directory path where the new package will be initialized. The directory will be created if it doesn't exist.
86+
87+
# flags.useInFeature.summary
88+
89+
Feature flag for function initialization (function packages only).
90+
91+
# flags.useInFeature.description
92+
93+
Configuration for which feature this function will be used in. SearchIndexChunking is the only valid option and is used by default if not specified.

messages/run.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Executes an initialized Data Cloud custom code package against a Salesforce org.
1818

1919
# examples.function
2020

21-
- Run a function package against the org with alias "myorg":
21+
- Run a function package:
2222

23-
<%= config.bin %> data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --target-org myorg
23+
<%= config.bin %> data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --test-with ./my-function-package/payload/tests/test.json
2424

2525
- Run with a custom config file:
2626

27-
<%= config.bin %> data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --target-org myorg --config-file ./my-function-package/payload/config.json
27+
<%= config.bin %> data-code-extension function run --entrypoint ./my-function-package/payload/entrypoint.py --test-with ./my-function-package/payload/tests/tests.json --config-file ./my-function-package/payload/config.json
2828

2929
# info.checkingPython
3030

@@ -98,6 +98,14 @@ Target Salesforce org to run against.
9898

9999
The alias or username of the Salesforce org where you want to run the Data Cloud custom code package. The org must have Data Cloud enabled and appropriate permissions.
100100

101+
# flags.testWith.summary
102+
103+
Path to test.json file to test Data Code Extension function
104+
105+
# flags.testWith.description
106+
107+
Path to a JSON file that provides input request for the function.
108+
101109
# flags.configFile.summary
102110

103111
Path to a config file.

src/base/deployBase.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export abstract class DeployBase<TFlags extends BaseDeployFlags = BaseDeployFlag
130130
const cpuSize = flags['cpu-size'] || 'CPU_2XL';
131131
const network = flags.network;
132132

133-
const additionalFlags = this.getAdditionalFlags(flags);
134-
135133
if (packageDir.length === 0) {
136134
throw new SfError(messages.getMessage('error.flagEmpty', ['package-dir']), 'InvalidFlagValue');
137135
}
@@ -160,8 +158,7 @@ export abstract class DeployBase<TFlags extends BaseDeployFlags = BaseDeployFlag
160158
packageDir,
161159
orgUsername,
162160
cpuSize,
163-
network,
164-
additionalFlags.functionInvokeOpt as string | undefined
161+
network
165162
);
166163

167164
this.log(cmdMessages.getMessage('info.deploymentComplete', [name, version]));
@@ -193,5 +190,4 @@ export abstract class DeployBase<TFlags extends BaseDeployFlags = BaseDeployFlag
193190

194191
protected abstract getCodeType(): 'script' | 'function';
195192
protected abstract getMessages(): Messages<string>;
196-
protected abstract getAdditionalFlags(flags: TFlags): Record<string, unknown>;
197193
}

src/base/initBase.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ export type InitResult = SharedResultProps & {
2828
};
2929

3030
// eslint-disable-next-line sf-plugin/command-summary, sf-plugin/command-example
31-
export abstract class InitBase extends SfCommand<InitResult> {
31+
export abstract class InitBase<TFlags extends BaseInitFlags = BaseInitFlags> extends SfCommand<InitResult> {
3232
public static enableJsonFlag = false;
3333

3434
public async run(): Promise<InitResult> {
35-
const { flags } = (await this.parse(this.constructor as typeof InitBase)) as unknown as { flags: BaseInitFlags };
35+
const { flags } = (await this.parse(this.constructor as typeof InitBase)) as unknown as { flags: TFlags };
3636
const codeType = this.getCodeType();
3737
const messages = this.getMessages();
3838
const packageDir = flags['package-dir'];
3939

40+
const additionalFlags = this.getAdditionalFlags(flags);
41+
4042
try {
4143
const { pythonInfo, packageInfo, binaryInfo } = await checkEnvironment(
4244
this.spinner,
@@ -45,7 +47,11 @@ export abstract class InitBase extends SfCommand<InitResult> {
4547
);
4648

4749
this.spinner.start(messages.getMessage('info.executingInit'));
48-
const executionResult = await DatacodeBinaryExecutor.executeBinaryInit(codeType, packageDir);
50+
const executionResult = await DatacodeBinaryExecutor.executeBinaryInit(
51+
codeType,
52+
packageDir,
53+
additionalFlags.useInFeature as string | undefined
54+
);
4955

5056
this.spinner.stop();
5157
this.log(messages.getMessage('info.initExecuted', [packageDir]));
@@ -77,4 +83,5 @@ export abstract class InitBase extends SfCommand<InitResult> {
7783

7884
protected abstract getCodeType(): 'script' | 'function';
7985
protected abstract getMessages(): Messages<string>;
86+
protected abstract getAdditionalFlags(flags: TFlags): Record<string, unknown>;
8087
}

src/base/runBase.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import { type SharedResultProps } from './types.js';
2121

2222
export type BaseRunFlags = {
2323
entrypoint: string;
24-
'target-org': Org;
24+
'target-org'?: Org;
25+
'test-with'?: string;
2526
'config-file'?: string;
2627
dependencies?: string;
2728
};
2829

2930
export type RunResult = SharedResultProps & {
30-
targetOrg: string;
31+
targetOrg?: string;
3132
status?: string;
3233
output?: string;
3334
executionResult?: DatacodeRunExecutionResult;
@@ -44,6 +45,7 @@ export abstract class RunBase extends SfCommand<RunResult> {
4445

4546
const packageDir = flags.entrypoint;
4647
const targetOrg = flags['target-org'];
48+
const testWith = flags['test-with'];
4749
const configFile = flags['config-file'];
4850
const dependencies = flags.dependencies;
4951

@@ -54,19 +56,24 @@ export abstract class RunBase extends SfCommand<RunResult> {
5456
messages
5557
);
5658

57-
const orgUsername = targetOrg.getUsername() ?? 'target org';
58-
this.spinner.start(messages.getMessage('info.authenticating', [orgUsername]));
59+
let orgUsername: string | undefined;
5960

60-
const connection = targetOrg.getConnection();
61-
await connection.refreshAuth();
61+
if (targetOrg) {
62+
orgUsername = targetOrg.getUsername() ?? 'target org';
63+
this.spinner.start(messages.getMessage('info.authenticating', [orgUsername]));
6264

63-
this.spinner.stop();
64-
this.log(messages.getMessage('info.authenticated', [orgUsername]));
65+
const connection = targetOrg.getConnection();
66+
await connection.refreshAuth();
67+
68+
this.spinner.stop();
69+
this.log(messages.getMessage('info.authenticated', [orgUsername]));
70+
}
6571

6672
this.spinner.start(messages.getMessage('info.runningPackage'));
6773
const executionResult = await DatacodeBinaryExecutor.executeBinaryRun(
6874
packageDir,
6975
orgUsername,
76+
testWith,
7077
configFile,
7178
dependencies
7279
);

src/commands/data-code-extension/function/deploy.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,21 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { Flags } from '@salesforce/sf-plugins-core';
1716
import { Messages } from '@salesforce/core';
18-
import { DeployBase, type BaseDeployFlags } from '../../../base/deployBase.js';
17+
import { DeployBase } from '../../../base/deployBase.js';
1918

2019
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2120
const messages = Messages.loadMessages('@salesforce/plugin-data-code-extension', 'deploy');
2221

23-
export type FunctionDeployFlags = BaseDeployFlags & {
24-
'function-invoke-opt': string;
25-
};
26-
2722
// eslint-disable-next-line sf-plugin/only-extend-SfCommand
28-
export default class Deploy extends DeployBase<FunctionDeployFlags> {
23+
export default class Deploy extends DeployBase {
2924
public static readonly state = 'beta';
3025
public static readonly summary = messages.getMessage('summary', ['function']);
3126
public static readonly description = messages.getMessage('description');
3227
public static readonly examples = messages.getMessages('examples.function');
3328

3429
public static readonly flags = {
3530
...DeployBase.flags,
36-
// Function-specific flag
37-
'function-invoke-opt': Flags.string({
38-
summary: messages.getMessage('flags.functionInvokeOpt.summary'),
39-
description: messages.getMessage('flags.functionInvokeOpt.description'),
40-
options: ['UnstructuredChunking'],
41-
required: true,
42-
}),
4331
};
4432

4533
// eslint-disable-next-line class-methods-use-this
@@ -51,11 +39,4 @@ export default class Deploy extends DeployBase<FunctionDeployFlags> {
5139
protected getMessages(): Messages<string> {
5240
return messages;
5341
}
54-
55-
// eslint-disable-next-line class-methods-use-this
56-
protected getAdditionalFlags(flags: FunctionDeployFlags): Record<string, unknown> {
57-
return {
58-
functionInvokeOpt: flags['function-invoke-opt'],
59-
};
60-
}
6142
}

0 commit comments

Comments
 (0)