@ductape/cli 0.3.21 → 0.3.22

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.
@@ -48,6 +48,22 @@ export async function runDb(method, opts) {
48
48
  printJson(result, Boolean(opts.json));
49
49
  }
50
50
  const DB_ACTION_VERBS = ['create', 'update', 'get', 'list', 'delete', 'execute', 'dispatch'];
51
+ const DB_ACTION_OPERATIONS = ['query', 'insert', 'update', 'delete', 'aggregate', 'count'];
52
+ function validateDatabaseActionCreateBody(body) {
53
+ const operation = String(body.operation ?? '');
54
+ if (!DB_ACTION_OPERATIONS.includes(operation)) {
55
+ throw new Error(`Invalid database action operation "${operation}". Use one of: ${DB_ACTION_OPERATIONS.join(', ')}. ` +
56
+ 'For MongoDB find/findOne actions use operation "query".');
57
+ }
58
+ const template = body.template;
59
+ if (!template || (typeof template !== 'object' && typeof template !== 'string')) {
60
+ throw new Error('template is required and must be an object for MongoDB or a SQL string.');
61
+ }
62
+ if (JSON.stringify(template).includes('$Input{')) {
63
+ throw new Error('Database action placeholders use {{name}}, not $Input{name}. ' +
64
+ 'Example MongoDB query template: { "where": { "email": "{{email}}" } }.');
65
+ }
66
+ }
51
67
  /**
52
68
  * Database Actions — reusable, parameterized query/mutation definitions saved against a
53
69
  * database component (databases.action.* in the SDK). Definition management is
@@ -75,6 +91,7 @@ export async function runDbActions(verb, opts, extraArgs) {
75
91
  throw new Error('create requires a body: { tag: "product:database:action", name, tableName, ' +
76
92
  'operation, template, description?, filterTemplate? } (pass -f <file.json>).');
77
93
  }
94
+ validateDatabaseActionCreateBody(body);
78
95
  method = 'action.create';
79
96
  params = [body];
80
97
  break;
package/dist/index.js CHANGED
@@ -814,8 +814,8 @@ const dbActions = db
814
814
  'query/insert/update/delete calls keep their raw table/where/data shape.');
815
815
  dbActions
816
816
  .command('create')
817
- .description('Create a database action from a file: { tag: "product:database:action", name, tableName, operation, template }')
818
- .requiredOption('--action-file <path>', 'JSON file with the action definition')
817
+ .description('Create a saved database action; MongoDB query example uses operation "query" and template { "where": { "email": "{{email}}" } }')
818
+ .requiredOption('--action-file <path>', 'JSON definition with tag, name, description, tableName, operation, and template')
819
819
  .option('--json', 'JSON output')
820
820
  .action(wrap((opts) => runDbActions('create', { file: opts.actionFile, json: opts.json }, [])));
821
821
  dbActions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ductape/cli",
3
- "version": "0.3.21",
3
+ "version": "0.3.22",
4
4
  "description": "Ductape CLI — local platform, login, link projects, and manage resources via the proxy (Workbench-compatible)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",