@supawatch/target-factories 0.7.1 → 0.8.0

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/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { Rendered, Snapshot, Table, Target, TargetCapabilities, TargetOptions } from "@supawatch/core";
2
2
  export type FactoriesTargetOptions = TargetOptions;
3
- export declare function exportNameFor(table: Table): string;
3
+ export declare function exportNameFor(table: Table, snapshot: Snapshot): string;
4
4
  export declare class FactoriesTarget implements Target<FactoriesTargetOptions> {
5
5
  readonly name = "factories";
6
6
  readonly fileExtension = ".mjs";
7
7
  readonly capabilities: TargetCapabilities;
8
- renderTable(table: Table, _snapshot: Snapshot, _opts: FactoriesTargetOptions): Rendered;
9
- renderTypes(table: Table, _snapshot: Snapshot, _opts: FactoriesTargetOptions): string;
8
+ renderTable(table: Table, snapshot: Snapshot, _opts: FactoriesTargetOptions): Rendered;
9
+ renderTypes(table: Table, snapshot: Snapshot, _opts: FactoriesTargetOptions): string;
10
10
  }
11
11
  export default FactoriesTarget;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { exportBaseName, fileBaseName } from "@supawatch/core";
1
2
  function defaultExpr(runtime, seedPath) {
2
3
  switch (runtime.kind) {
3
4
  case "number":
@@ -31,11 +32,11 @@ function defaultExpr(runtime, seedPath) {
31
32
  return JSON.stringify(runtime.labels[0] ?? "");
32
33
  }
33
34
  }
34
- function baseNameFor(table) {
35
- return table.name.replace(/[^a-zA-Z0-9_]/g, "_");
35
+ function baseNameFor(table, snapshot) {
36
+ return exportBaseName(table, snapshot);
36
37
  }
37
- export function exportNameFor(table) {
38
- const base = baseNameFor(table);
38
+ export function exportNameFor(table, snapshot) {
39
+ const base = baseNameFor(table, snapshot);
39
40
  return "make" + base.charAt(0).toUpperCase() + base.slice(1);
40
41
  }
41
42
  function fieldDefault(table, col) {
@@ -51,23 +52,23 @@ export class FactoriesTarget {
51
52
  brandedTypes: false,
52
53
  dateInstances: true,
53
54
  };
54
- renderTable(table, _snapshot, _opts) {
55
+ renderTable(table, snapshot, _opts) {
55
56
  const fields = table.columns
56
57
  .map((col) => ` ${JSON.stringify(col.name)}: ${fieldDefault(table, col)},`)
57
58
  .join("\n");
58
59
  const body = [
59
- `export function ${exportNameFor(table)}(overrides = {}) {`,
60
+ `export function ${exportNameFor(table, snapshot)}(overrides = {}) {`,
60
61
  " return {",
61
62
  fields,
62
63
  " ...overrides,",
63
64
  " };",
64
65
  "}",
65
66
  ].join("\n");
66
- return { imports: [], body, exportName: exportNameFor(table) };
67
+ return { imports: [], body, exportName: exportNameFor(table, snapshot) };
67
68
  }
68
- renderTypes(table, _snapshot, _opts) {
69
- const name = exportNameFor(table);
70
- const base = baseNameFor(table);
69
+ renderTypes(table, snapshot, _opts) {
70
+ const name = exportNameFor(table, snapshot);
71
+ const base = baseNameFor(table, snapshot);
71
72
  const rowType = `${base}FactoryRow`;
72
73
  const tsType = (runtime) => {
73
74
  switch (runtime.kind) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supawatch/target-factories",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Typed fixture factories generated from live Postgres by supawatch, guaranteed to satisfy the generated Zod schemas.",
5
5
  "keywords": [
6
6
  "supabase",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@supawatch/core": "0.7.1"
36
+ "@supawatch/core": "0.8.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^22.20.1",