@sanity/cli 4.8.1-next.1 → 4.9.0-next.1
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/lib/_chunks-cjs/cli.js +29 -3
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +7 -7
package/lib/_chunks-cjs/cli.js
CHANGED
@@ -8260,9 +8260,16 @@ Arguments
|
|
8260
8260
|
<name> The name of the Sanity Function
|
8261
8261
|
|
8262
8262
|
Options
|
8263
|
+
--event <create|update|delete> The type of event to simulate (default: 'create')
|
8263
8264
|
--data <data> Data to send to the function
|
8265
|
+
--data-before <data> Data to send to the function when event is update
|
8266
|
+
--data-after <data> Data to send to the function when event is update
|
8264
8267
|
--file <file> Read data from file and send to the function
|
8268
|
+
--file-before <file> Read data from file and send to the function when event is update
|
8269
|
+
--file-after <file> Read data from file and send to the function when event is update
|
8265
8270
|
--document-id <id> Document to fetch and send to function
|
8271
|
+
--document-id-before <id> Document to fetch and send to function when event is update
|
8272
|
+
--document-id-after <id> Document to fetch and send to function when event is update
|
8266
8273
|
--timeout <timeout> Execution timeout value in seconds
|
8267
8274
|
--api <version> Sanity API Version to use
|
8268
8275
|
--dataset <dataset> The Sanity dataset to use
|
@@ -8279,6 +8286,9 @@ Examples
|
|
8279
8286
|
|
8280
8287
|
# Test function passing event data on command line and cap execution time to 60 seconds
|
8281
8288
|
sanity functions test echo --data '{ "id": 1 }' --timeout 60
|
8289
|
+
|
8290
|
+
# Test function simulating an update event
|
8291
|
+
sanity functions test echo --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
8282
8292
|
`, defaultFlags$1 = {
|
8283
8293
|
timeout: 10,
|
8284
8294
|
// seconds
|
@@ -8287,7 +8297,7 @@ Examples
|
|
8287
8297
|
name: "test",
|
8288
8298
|
group: "functions",
|
8289
8299
|
helpText: helpText$c,
|
8290
|
-
signature: "<name> [--data <json>] [--file <filename>] [--document-id <id>] [--timeout <seconds>] [--api <version>] [--dataset <name>] [--project-id] <id>] [--with-user-token]",
|
8300
|
+
signature: "<name> [--event create|update|delete] [--data <json>] [--data-before <json>] [--data-after <json>] [--file <filename>] [--file-before <filename>] [--file-after <filename>] [--document-id <id>] [--document-id-before <id>] [--document-id-before <id>] [--timeout <seconds>] [--api <version>] [--dataset <name>] [--project-id] <id>] [--with-user-token]",
|
8291
8301
|
description: "Invoke a local Sanity Function",
|
8292
8302
|
async action(args, context) {
|
8293
8303
|
const { apiClient, output, chalk: chalk2 } = context, [name] = args.argsWithoutOptions, flags = { ...defaultFlags$1, ...args.extOptions }, client2 = apiClient({
|
@@ -8298,13 +8308,22 @@ Examples
|
|
8298
8308
|
if (!name)
|
8299
8309
|
throw new Error("You must provide a function name as the first argument");
|
8300
8310
|
const { initBlueprintConfig } = await import("@sanity/runtime-cli/cores"), { functionTestCore } = await import("@sanity/runtime-cli/cores/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { projectId: bpProjectId } = await blueprint.readLocalBlueprint();
|
8301
|
-
projectId && projectId !== bpProjectId && (output.print(
|
8311
|
+
if (projectId && projectId !== bpProjectId && (output.print(
|
8302
8312
|
chalk2.yellow("WARNING"),
|
8303
8313
|
`Project ID ${chalk2.cyan(projectId)} in ${chalk2.green("sanity.cli.ts")} does not match Project ID ${chalk2.cyan(bpProjectId)} in ${chalk2.green("./sanity/blueprint.config.json")}.`
|
8304
8314
|
), output.print(
|
8305
8315
|
`Defaulting to Project ID ${chalk2.cyan(bpProjectId)}. To override use the ${chalk2.green("--project-id")} flag.
|
8306
8316
|
`
|
8307
|
-
))
|
8317
|
+
)), flags.event === "update") {
|
8318
|
+
const hasDataPair = flags["data-before"] && flags["data-after"], hasFilePair = flags["file-before"] && flags["file-after"], hasDocPair = flags["document-id-before"] && flags["document-id-after"];
|
8319
|
+
if (!(hasDataPair || hasFilePair || hasDocPair))
|
8320
|
+
throw new Error(
|
8321
|
+
`When using --event=update, you must provide one of the following flag pairs:
|
8322
|
+
--data-before and --data-after
|
8323
|
+
--file-before and --file-after
|
8324
|
+
--document-id-before and --document-id-after`
|
8325
|
+
);
|
8326
|
+
}
|
8308
8327
|
const cmdConfig = await initBlueprintConfig({
|
8309
8328
|
bin: "sanity",
|
8310
8329
|
log: (message) => output.print(message),
|
@@ -8316,8 +8335,15 @@ Examples
|
|
8316
8335
|
args: { name },
|
8317
8336
|
flags: {
|
8318
8337
|
data: flags.data,
|
8338
|
+
"data-before": flags["data-before"],
|
8339
|
+
"data-after": flags["data-after"],
|
8319
8340
|
file: flags.file,
|
8341
|
+
"file-before": flags["file-before"],
|
8342
|
+
"file-after": flags["file-after"],
|
8320
8343
|
"document-id": flags["document-id"],
|
8344
|
+
"document-id-before": flags["document-id-before"],
|
8345
|
+
"document-id-after": flags["document-id-after"],
|
8346
|
+
event: flags.event,
|
8321
8347
|
timeout: flags.timeout,
|
8322
8348
|
api: flags.api,
|
8323
8349
|
dataset: flags.dataset || actualDataset,
|