@supawatch/target-orpc 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,12 +2,12 @@ import type { Rendered, Snapshot, Table, Target, TargetCapabilities, TargetOptio
2
2
  export interface OrpcTargetOptions extends TargetOptions {
3
3
  schemasImportPath?: string;
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 OrpcTarget implements Target<OrpcTargetOptions> {
7
7
  readonly name = "orpc";
8
8
  readonly fileExtension = ".mjs";
9
9
  readonly capabilities: TargetCapabilities;
10
- renderTable(table: Table, _snapshot: Snapshot, opts: OrpcTargetOptions): Rendered;
11
- renderTypes(table: Table, _snapshot: Snapshot, _opts: OrpcTargetOptions): string;
10
+ renderTable(table: Table, snapshot: Snapshot, opts: OrpcTargetOptions): Rendered;
11
+ renderTypes(table: Table, snapshot: Snapshot, _opts: OrpcTargetOptions): string;
12
12
  }
13
13
  export default OrpcTarget;
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
- function baseNameFor(table) {
2
- return table.name.replace(/[^a-zA-Z0-9_]/g, "_");
1
+ import { exportBaseName, fileBaseName } from "@supawatch/core";
2
+ function baseNameFor(table, snapshot) {
3
+ return exportBaseName(table, snapshot);
3
4
  }
4
- export function exportNameFor(table) {
5
- const base = baseNameFor(table);
5
+ export function exportNameFor(table, snapshot) {
6
+ const base = baseNameFor(table, snapshot);
6
7
  return `create${base.charAt(0).toUpperCase() + base.slice(1)}Orpc`;
7
8
  }
8
9
  function quotedIdent(table) {
@@ -17,15 +18,15 @@ export class OrpcTarget {
17
18
  brandedTypes: false,
18
19
  dateInstances: true,
19
20
  };
20
- renderTable(table, _snapshot, opts) {
21
- const base = baseNameFor(table);
21
+ renderTable(table, snapshot, opts) {
22
+ const base = baseNameFor(table, snapshot);
22
23
  const importPath = opts.schemasImportPath ?? "../zod";
23
24
  const rowName = `${base}Row`;
24
25
  const insertName = `${base}Insert`;
25
26
  const ident = quotedIdent(table);
26
27
  const singlePk = table.primaryKey.length === 1 ? table.primaryKey[0] : null;
27
28
  const lines = [
28
- `export function ${exportNameFor(table)}(sql) {`,
29
+ `export function ${exportNameFor(table, snapshot)}(sql) {`,
29
30
  " const procedures = {",
30
31
  " list: os.handler(async () => {",
31
32
  ` const rows = await sql.unsafe('select * from ${ident} limit 100');`,
@@ -44,14 +45,14 @@ export class OrpcTarget {
44
45
  return {
45
46
  imports: [
46
47
  { from: "@orpc/server", names: ["os"] },
47
- { from: `${importPath}/${table.name}.mjs`, names: [names] },
48
+ { from: `${importPath}/${fileBaseName(table, snapshot)}.mjs`, names: [names] },
48
49
  ],
49
50
  body: lines.join("\n"),
50
- exportName: exportNameFor(table),
51
+ exportName: exportNameFor(table, snapshot),
51
52
  };
52
53
  }
53
- renderTypes(table, _snapshot, _opts) {
54
- const name = exportNameFor(table);
54
+ renderTypes(table, snapshot, _opts) {
55
+ const name = exportNameFor(table, snapshot);
55
56
  return [
56
57
  "// Generated by supawatch. Do not edit.",
57
58
  `export declare function ${name}(sql: { unsafe(text: string, params?: unknown[]): Promise<any[]> }): any;`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supawatch/target-orpc",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "oRPC routers generated from live Postgres by supawatch, input-validated by 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",