@supawatch/target-json-schema 0.7.0 → 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 +2 -2
- package/dist/index.js +5 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Rendered, Snapshot, Table, Target, TargetCapabilities, TargetOptions, Verifier } from "@supawatch/core";
|
|
2
2
|
export type JsonSchemaTargetOptions = TargetOptions;
|
|
3
|
-
export declare function exportNameFor(table: Table): string;
|
|
3
|
+
export declare function exportNameFor(table: Table, snapshot: Snapshot): string;
|
|
4
4
|
export declare class JsonSchemaTarget implements Target<JsonSchemaTargetOptions> {
|
|
5
5
|
readonly name = "json-schema";
|
|
6
6
|
readonly fileExtension = ".schema.json";
|
|
7
7
|
readonly barrel = false;
|
|
8
8
|
readonly capabilities: TargetCapabilities;
|
|
9
|
-
renderTable(table: Table,
|
|
9
|
+
renderTable(table: Table, snapshot: Snapshot, opts: JsonSchemaTargetOptions): Rendered;
|
|
10
10
|
assembleFile(rendered: Rendered): string;
|
|
11
11
|
verifier(): Verifier;
|
|
12
12
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { Ajv } from "ajv";
|
|
3
|
+
import { exportBaseName, fileBaseName } from "@supawatch/core";
|
|
3
4
|
// JSON Schema has no type for JS Date instances or Uint8Array; those
|
|
4
5
|
// columns get an accept-anything schema with a $comment saying why. The
|
|
5
6
|
// honest alternative would be claiming "string", which would reject every
|
|
@@ -34,8 +35,8 @@ function fieldSchema(col) {
|
|
|
34
35
|
}
|
|
35
36
|
return { anyOf: [base, { type: "null" }] };
|
|
36
37
|
}
|
|
37
|
-
export function exportNameFor(table) {
|
|
38
|
-
return table
|
|
38
|
+
export function exportNameFor(table, snapshot) {
|
|
39
|
+
return exportBaseName(table, snapshot) + "Row";
|
|
39
40
|
}
|
|
40
41
|
export class JsonSchemaTarget {
|
|
41
42
|
name = "json-schema";
|
|
@@ -46,7 +47,7 @@ export class JsonSchemaTarget {
|
|
|
46
47
|
brandedTypes: false,
|
|
47
48
|
dateInstances: false,
|
|
48
49
|
};
|
|
49
|
-
renderTable(table,
|
|
50
|
+
renderTable(table, snapshot, opts) {
|
|
50
51
|
const strict = opts.strict !== false;
|
|
51
52
|
const properties = {};
|
|
52
53
|
for (const col of table.columns) {
|
|
@@ -64,7 +65,7 @@ export class JsonSchemaTarget {
|
|
|
64
65
|
return {
|
|
65
66
|
imports: [],
|
|
66
67
|
body: JSON.stringify(schema, null, 2) + "\n",
|
|
67
|
-
exportName: exportNameFor(table),
|
|
68
|
+
exportName: exportNameFor(table, snapshot),
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
assembleFile(rendered) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supawatch/target-json-schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Draft-07 JSON Schemas generated from live Postgres by supawatch, Ajv-verified against real rows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"supabase",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"ajv": "^8.17.0",
|
|
38
|
-
"@supawatch/core": "0.
|
|
38
|
+
"@supawatch/core": "0.8.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22.20.1",
|