@supawatch/target-valibot 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
@@ -2,13 +2,13 @@ import type { Rendered, Snapshot, Table, Target, TargetCapabilities, TargetOptio
2
2
  export interface ValibotTargetOptions extends TargetOptions {
3
3
  strict?: boolean;
4
4
  }
5
- export declare function exportNameFor(table: Table): string;
5
+ export declare function exportNameFor(table: Table, snapshot: Snapshot): string;
6
6
  export declare class ValibotTarget implements Target<ValibotTargetOptions> {
7
7
  readonly name = "valibot";
8
8
  readonly fileExtension = ".mjs";
9
9
  readonly capabilities: TargetCapabilities;
10
- renderTable(table: Table, _snapshot: Snapshot, opts: ValibotTargetOptions): Rendered;
11
- renderTypes(table: Table, _snapshot: Snapshot, opts: ValibotTargetOptions): string;
10
+ renderTable(table: Table, snapshot: Snapshot, opts: ValibotTargetOptions): Rendered;
11
+ renderTypes(table: Table, snapshot: Snapshot, opts: ValibotTargetOptions): string;
12
12
  verifier(): Verifier;
13
13
  }
14
14
  export default ValibotTarget;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { pathToFileURL } from "node:url";
2
2
  import * as v from "valibot";
3
+ import { exportBaseName, fileBaseName } from "@supawatch/core";
3
4
  function valibotExpr(runtime) {
4
5
  switch (runtime.kind) {
5
6
  case "number":
@@ -50,11 +51,11 @@ function tsType(runtime) {
50
51
  return runtime.labels.map((l) => JSON.stringify(l)).join(" | ");
51
52
  }
52
53
  }
53
- export function exportNameFor(table) {
54
- return table.name.replace(/[^a-zA-Z0-9_]/g, "_") + "Row";
54
+ export function exportNameFor(table, snapshot) {
55
+ return exportBaseName(table, snapshot) + "Row";
55
56
  }
56
- function baseNameFor(table) {
57
- return table.name.replace(/[^a-zA-Z0-9_]/g, "_");
57
+ function baseNameFor(table, snapshot) {
58
+ return exportBaseName(table, snapshot);
58
59
  }
59
60
  function fieldSchema(col) {
60
61
  const base = valibotExpr(col.runtime);
@@ -91,30 +92,30 @@ export class ValibotTarget {
91
92
  brandedTypes: true,
92
93
  dateInstances: true,
93
94
  };
94
- renderTable(table, _snapshot, opts) {
95
+ renderTable(table, snapshot, opts) {
95
96
  const strict = opts.strict !== false;
96
97
  const ctor = strict ? "v.strictObject" : "v.object";
97
98
  const fields = table.columns
98
99
  .map((col) => ` ${JSON.stringify(col.name)}: ${fieldSchema(col)},`)
99
100
  .join("\n");
100
101
  const parts = [
101
- `export const ${exportNameFor(table)} = ${ctor}({\n${fields}\n});`,
102
+ `export const ${exportNameFor(table, snapshot)} = ${ctor}({\n${fields}\n});`,
102
103
  ];
103
104
  if (opts.emit?.insert && table.kind === "table") {
104
- parts.push(variantBody(table, ctor, `${baseNameFor(table)}Insert`, insertOptional));
105
+ parts.push(variantBody(table, ctor, `${baseNameFor(table, snapshot)}Insert`, insertOptional));
105
106
  }
106
107
  if (opts.emit?.update && table.kind === "table") {
107
- parts.push(variantBody(table, ctor, `${baseNameFor(table)}Update`, () => true));
108
+ parts.push(variantBody(table, ctor, `${baseNameFor(table, snapshot)}Update`, () => true));
108
109
  }
109
110
  return {
110
111
  imports: [{ from: "valibot", namespace: "v" }],
111
112
  body: parts.join("\n\n"),
112
- exportName: exportNameFor(table),
113
+ exportName: exportNameFor(table, snapshot),
113
114
  };
114
115
  }
115
- renderTypes(table, _snapshot, opts) {
116
- const name = exportNameFor(table);
117
- const base = baseNameFor(table);
116
+ renderTypes(table, snapshot, opts) {
117
+ const name = exportNameFor(table, snapshot);
118
+ const base = baseNameFor(table, snapshot);
118
119
  const rowType = `${base}RowType`;
119
120
  const typeOf = (col) => {
120
121
  const override = jsonOverrideFor(table, col, opts.jsonTypes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supawatch/target-valibot",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Valibot schemas generated from live Postgres by supawatch, mapped to what the driver actually returns.",
5
5
  "keywords": [
6
6
  "supabase",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "valibot": "^1.1.0",
36
- "@supawatch/core": "0.7.1"
36
+ "@supawatch/core": "0.8.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "valibot": "^1.0.0"