@xano/cli 1.0.6-beta.15 → 1.0.6-beta.16

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/README.md CHANGED
@@ -323,6 +323,7 @@ xano function run <name> --data email=jo@x.com --data age:=30 --data active:=tru
323
323
  xano function run <name> --json @payload.json --data env=staging # base payload + override
324
324
  echo '{"email":"jo@x.com"}' | xano function run <name> --stdin -o json | jq .result
325
325
  xano function run <name> --branch dev --logs # run on a branch, show execution logs
326
+ xano function run <name> --datasource test # run against the 'test' data source
326
327
  ```
327
328
 
328
329
  Input flexibility for `function run` (assembled into one JSON `input` object):
@@ -335,6 +336,11 @@ Input flexibility for `function run` (assembled into one JSON `input` object):
335
336
  | `--json '<inline>'` / `--json @file.json` / `--json -` | a base JSON object (stdin with `-`) |
336
337
  | `--stdin` | read the JSON object from stdin (same as `--json -`) |
337
338
 
339
+ `--datasource <label>` runs the function against a non-live data source by sending the
340
+ `X-Data-Source` header, so table reads and writes hit that data source's tables. Omit it
341
+ to run against `live`; an unknown label is rejected by the server with
342
+ `Invalid data source.`
343
+
338
344
  Merge order is JSON base first, then `--data` overrides. Missing required inputs are
339
345
  prompted for on an interactive terminal; in a non-TTY (CI) context the command fails
340
346
  listing them. Output defaults to the raw `result` (`-o json`); the exit code is non-zero
@@ -8,6 +8,7 @@ export default class FunctionRun extends BaseCommand {
8
8
  static flags: {
9
9
  branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  data: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ datasource: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  json: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  logs: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
14
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -17,6 +17,8 @@ export default class FunctionRun extends BaseCommand {
17
17
  `$ xano function:run calcScore --json @payload.json --data env=staging`,
18
18
  `$ echo '{"email":"jo@x.com"}' | xano function:run calcScore --stdin -o json | jq .result`,
19
19
  `$ xano function:run calcScore --branch dev --logs`,
20
+ `$ xano function:run calcScore --datasource test
21
+ # Runs against the 'test' data source instead of 'live'`,
20
22
  ];
21
23
  static flags = {
22
24
  ...BaseCommand.baseFlags,
@@ -30,6 +32,10 @@ export default class FunctionRun extends BaseCommand {
30
32
  multiple: true,
31
33
  required: false,
32
34
  }),
35
+ datasource: Flags.string({
36
+ description: 'Data source to run against, e.g. test (defaults to live)',
37
+ required: false,
38
+ }),
33
39
  json: Flags.string({
34
40
  description: "Input as a JSON object: inline, @file.json, or '-' for stdin",
35
41
  exclusive: ['stdin'],
@@ -106,13 +112,21 @@ export default class FunctionRun extends BaseCommand {
106
112
  const body = { input, name: functionName };
107
113
  if (branch)
108
114
  body.branch = branch;
115
+ const headers = {
116
+ 'accept': 'application/json',
117
+ 'Authorization': `Bearer ${profile.access_token}`,
118
+ 'Content-Type': 'application/json',
119
+ };
120
+ // The Metadata API resolves the workspace's tables against the data source
121
+ // named by X-Data-Source (defaulting to `live`), so the run reads and writes
122
+ // the same tables a request carrying that header would. An unknown label is
123
+ // rejected server-side with "Invalid data source."
124
+ const dataSource = flags.datasource?.trim();
125
+ if (dataSource)
126
+ headers['X-Data-Source'] = dataSource;
109
127
  const response = await this.verboseFetch(apiUrl, {
110
128
  body: JSON.stringify(body),
111
- headers: {
112
- 'accept': 'application/json',
113
- 'Authorization': `Bearer ${profile.access_token}`,
114
- 'Content-Type': 'application/json',
115
- },
129
+ headers,
116
130
  method: 'POST',
117
131
  }, flags.verbose, profile.access_token);
118
132
  if (!response.ok) {