@ductape/cli 0.4.1 → 0.4.2

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.
@@ -1,5 +1,6 @@
1
1
  export type ComponentActionKind = 'graph' | 'vector';
2
2
  export type ComponentActionVerb = 'create' | 'update' | 'get' | 'list' | 'delete' | 'execute';
3
+ export declare function assertComponentActionResult(kind: ComponentActionKind, verb: ComponentActionVerb, result: unknown): void;
3
4
  export declare function runComponentActions(kind: ComponentActionKind, verb: ComponentActionVerb, opts: {
4
5
  resource?: string;
5
6
  action?: string;
@@ -1,6 +1,15 @@
1
1
  import { readJsonBody } from '../lib/read-body.js';
2
2
  import { getSdkProxy, requireSession } from '../lib/proxy/context.js';
3
3
  import { printJson } from '../lib/output.js';
4
+ export function assertComponentActionResult(kind, verb, result) {
5
+ if (verb === 'get' && (result === null || result === undefined)) {
6
+ throw new Error(`${kind} action was not found in the canonical product catalogue`);
7
+ }
8
+ if (verb === 'execute' && result && typeof result === 'object' && result.success === false) {
9
+ const message = result.error ?? result.message;
10
+ throw new Error(`${kind} action execution failed${message ? `: ${String(message)}` : ''}`);
11
+ }
12
+ }
4
13
  export async function runComponentActions(kind, verb, opts) {
5
14
  const session = requireSession();
6
15
  const body = readJsonBody(opts.file) ?? {};
@@ -41,5 +50,6 @@ export async function runComponentActions(kind, verb, opts) {
41
50
  params = [{ product: session.project.product_tag, env: session.project.env_slug, ...body }];
42
51
  }
43
52
  const result = await getSdkProxy(session).execute(kind, method, params);
53
+ assertComponentActionResult(kind, verb, result);
44
54
  printJson(result, Boolean(opts.json));
45
55
  }
@@ -357,6 +357,10 @@ function adaptColumn(col) {
357
357
  }
358
358
  export async function runDbSchemaPush(opts) {
359
359
  const session = requireSession();
360
+ const project = findProjectConfig();
361
+ const localEntry = project && fs.existsSync(getSchemaPath(project.dir))
362
+ ? loadSchemaFile(project.dir).find((entry) => entry.db === opts.db)
363
+ : undefined;
360
364
  const proxy = getDbProxy(session);
361
365
  const envSlug = opts.env;
362
366
  const productTag = session.project.product_tag;
@@ -382,12 +386,17 @@ export async function runDbSchemaPush(opts) {
382
386
  for (const tableName of tableNames) {
383
387
  try {
384
388
  const tableSchema = await proxy.execute('schema.describe', [tableName], dbContext);
385
- const cols = Array.isArray(tableSchema?.columns)
389
+ let cols = Array.isArray(tableSchema?.columns)
386
390
  ? tableSchema.columns
387
391
  : Array.isArray(tableSchema) ? tableSchema : [];
388
392
  if (cols.length === 0) {
389
- console.warn(` [skip] ${tableName}: no columns returned`);
390
- continue;
393
+ const localDefinition = localEntry?.tables?.[tableName];
394
+ if (!localDefinition) {
395
+ console.warn(` [skip] ${tableName}: no live columns or code-first definition returned`);
396
+ continue;
397
+ }
398
+ cols = parseTableDef(tableName, localDefinition).fields;
399
+ console.log(` ${tableName}: using code-first schema because the collection is empty`);
391
400
  }
392
401
  const columns = cols
393
402
  .filter((c) => c.name)
@@ -115,7 +115,7 @@ export async function runDbActions(verb, opts, extraArgs) {
115
115
  if (!databaseTag) {
116
116
  throw new Error('list requires --database <product_tag:database_tag>');
117
117
  }
118
- method = 'action.fetchAll';
118
+ method = 'action.list';
119
119
  params = [databaseTag];
120
120
  break;
121
121
  }
@@ -1,5 +1,6 @@
1
1
  import type { IMigration } from './db-types.js';
2
2
  export declare function validateEquivalentMigrationIndexes(migrations: IMigration[]): void;
3
+ export declare function validateCanonicalMigrationOperations(migrations: IMigration[]): void;
3
4
  export declare function getMigrationsDir(projectDir: string, dbTag: string): string;
4
5
  export declare function loadMigrationFiles(projectDir: string, dbTag: string): IMigration[];
5
6
  export declare function writeMigrationFile(projectDir: string, dbTag: string, migration: IMigration, counter: number): string;
@@ -22,6 +22,19 @@ export function validateEquivalentMigrationIndexes(migrations) {
22
22
  seen.set(fingerprint, { migration: migration.tag, operation: operationIndex, name: operation.name });
23
23
  });
24
24
  }
25
+ export function validateCanonicalMigrationOperations(migrations) {
26
+ for (const migration of migrations) {
27
+ for (const [direction, operations] of [['up', migration.up], ['down', migration.down]]) {
28
+ operations.forEach((operation, index) => {
29
+ if (operation.type === 'createCollection' && !operation.name) {
30
+ const legacy = operation.collection;
31
+ throw new Error(`Migration "${migration.tag}" ${direction} operation ${index + 1} createCollection requires "name"` +
32
+ (typeof legacy === 'string' ? '; "collection" is not valid for createCollection' : ''));
33
+ }
34
+ });
35
+ }
36
+ }
37
+ }
25
38
  export function getMigrationsDir(projectDir, dbTag) {
26
39
  return path.join(projectDir, PROJECT_CONFIG_DIR, 'database', 'migrations', dbTag);
27
40
  }
@@ -37,6 +50,7 @@ export function loadMigrationFiles(projectDir, dbTag) {
37
50
  const raw = JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8'));
38
51
  return raw;
39
52
  });
53
+ validateCanonicalMigrationOperations(migrations);
40
54
  validateEquivalentMigrationIndexes(migrations);
41
55
  return migrations;
42
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ductape/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",