postgresdk 0.18.26 → 0.18.27

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/dist/cli.js CHANGED
@@ -515,6 +515,19 @@ async function ensureDirs(dirs) {
515
515
  for (const d of dirs)
516
516
  await mkdir(d, { recursive: true });
517
517
  }
518
+ async function collectDirsRecursively(root) {
519
+ if (!existsSync(root))
520
+ return [];
521
+ const dirs = [root];
522
+ const entries = await readdir(root, { withFileTypes: true });
523
+ for (const entry of entries) {
524
+ if (!entry.isDirectory())
525
+ continue;
526
+ const sub = join(root, entry.name);
527
+ dirs.push(...await collectDirsRecursively(sub));
528
+ }
529
+ return dirs;
530
+ }
518
531
  async function deleteStaleFiles(generatedPaths, dirsToScan) {
519
532
  let deleted = 0;
520
533
  const filesDeleted = [];
@@ -2328,8 +2341,9 @@ Options:`);
2328
2341
  let filesWritten = 0;
2329
2342
  let filesUnchanged = 0;
2330
2343
  const changedFiles = [];
2344
+ const resolvedOutput = resolve2(config.output);
2331
2345
  for (const [path, content] of Object.entries(sdk.files)) {
2332
- const fullPath = join3(config.output, path);
2346
+ const fullPath = join3(resolvedOutput, path);
2333
2347
  await mkdir2(dirname3(fullPath), { recursive: true });
2334
2348
  let shouldWrite = true;
2335
2349
  if (existsSync4(fullPath)) {
@@ -2346,7 +2360,13 @@ Options:`);
2346
2360
  console.log(` ✓ ${path}`);
2347
2361
  }
2348
2362
  }
2349
- const metadataPath = join3(config.output, ".postgresdk.json");
2363
+ const generatedPaths = new Set(Object.keys(sdk.files).map((p) => join3(resolvedOutput, p)));
2364
+ const dirsToScan = await collectDirsRecursively(resolvedOutput);
2365
+ const deleteResult = await deleteStaleFiles(generatedPaths, dirsToScan);
2366
+ for (const f of deleteResult.filesDeleted) {
2367
+ console.log(` ✗ ${f}`);
2368
+ }
2369
+ const metadataPath = join3(resolvedOutput, ".postgresdk.json");
2350
2370
  const metadata = {
2351
2371
  version: sdk.version,
2352
2372
  pulledFrom: config.from
@@ -2361,18 +2381,27 @@ Options:`);
2361
2381
  if (metadataChanged) {
2362
2382
  await writeFile2(metadataPath, JSON.stringify(metadata, null, 2));
2363
2383
  }
2364
- if (filesWritten === 0 && !metadataChanged) {
2384
+ if (filesWritten === 0 && !metadataChanged && deleteResult.deleted === 0) {
2365
2385
  console.log(`✅ SDK up-to-date (${filesUnchanged} files unchanged)`);
2366
2386
  } else {
2387
+ const parts = [];
2388
+ if (filesWritten > 0)
2389
+ parts.push(`updated ${filesWritten} files`);
2390
+ if (deleteResult.deleted > 0)
2391
+ parts.push(`deleted ${deleteResult.deleted} stale files`);
2392
+ if (filesUnchanged > 0)
2393
+ parts.push(`${filesUnchanged} unchanged`);
2367
2394
  console.log(`✅ SDK pulled successfully to ${config.output}`);
2368
- console.log(` Updated: ${filesWritten} files, Unchanged: ${filesUnchanged} files`);
2395
+ console.log(` ${parts.join(", ")}`);
2369
2396
  }
2370
2397
  } catch (err) {
2371
2398
  console.error(`❌ Pull failed:`, err);
2372
2399
  process.exit(1);
2373
2400
  }
2374
2401
  }
2375
- var init_cli_pull = () => {};
2402
+ var init_cli_pull = __esm(() => {
2403
+ init_utils();
2404
+ });
2376
2405
 
2377
2406
  // src/index.ts
2378
2407
  var import_config = __toESM(require_config(), 1);
package/dist/index.js CHANGED
@@ -514,6 +514,19 @@ async function ensureDirs(dirs) {
514
514
  for (const d of dirs)
515
515
  await mkdir(d, { recursive: true });
516
516
  }
517
+ async function collectDirsRecursively(root) {
518
+ if (!existsSync(root))
519
+ return [];
520
+ const dirs = [root];
521
+ const entries = await readdir(root, { withFileTypes: true });
522
+ for (const entry of entries) {
523
+ if (!entry.isDirectory())
524
+ continue;
525
+ const sub = join(root, entry.name);
526
+ dirs.push(...await collectDirsRecursively(sub));
527
+ }
528
+ return dirs;
529
+ }
517
530
  async function deleteStaleFiles(generatedPaths, dirsToScan) {
518
531
  let deleted = 0;
519
532
  const filesDeleted = [];
package/dist/utils.d.ts CHANGED
@@ -20,6 +20,11 @@ export declare function writeFilesIfChanged(files: Array<{
20
20
  */
21
21
  export declare function hashContent(content: string): string;
22
22
  export declare function ensureDirs(dirs: string[]): Promise<void>;
23
+ /**
24
+ * Recursively collect all subdirectory paths under `root`, including root itself.
25
+ * Returns an empty array if `root` does not exist.
26
+ */
27
+ export declare function collectDirsRecursively(root: string): Promise<string[]>;
23
28
  /**
24
29
  * Delete files in the given directories that are not in the set of generated paths.
25
30
  * Used to remove stale files for tables that no longer exist in the schema.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.18.26",
3
+ "version": "0.18.27",
4
4
  "description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
5
5
  "type": "module",
6
6
  "bin": {