@supawatch/target-schema-lock 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Omar Dulaimi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @supawatch/target-schema-lock
2
+
3
+ The schema lockfile target for
4
+ [supawatch](https://github.com/omar-dulaimi/supawatch). Emits
5
+ `schema.lock.json`: a canonical, byte-stable snapshot of your schema meant
6
+ to be committed.
7
+
8
+ Configure it in `supawatch.config.ts` (the CLI loads this package by name):
9
+
10
+ ```ts
11
+ targets: [{ kind: "schema-lock" }]
12
+ ```
13
+
14
+ Why commit it: `supawatch check` then catches schema drift the same way it
15
+ catches stale generated files, and the lockfile's diff in a pull request IS
16
+ the schema changelog reviewers read. Ordering is canonicalized (sorted keys
17
+ and collections), so an unchanged schema produces identical bytes.
18
+
19
+ MIT.
@@ -0,0 +1,11 @@
1
+ import type { Snapshot, SnapshotFile, Target, TargetCapabilities, TargetOptions } from "@supawatch/core";
2
+ export type SchemaLockTargetOptions = TargetOptions;
3
+ export declare class SchemaLockTarget implements Target<SchemaLockTargetOptions> {
4
+ readonly name = "schema-lock";
5
+ readonly fileExtension = ".json";
6
+ readonly barrel = false;
7
+ readonly capabilities: TargetCapabilities;
8
+ renderTable(): never;
9
+ renderSnapshot(snapshot: Snapshot, _opts: SchemaLockTargetOptions): SnapshotFile[];
10
+ }
11
+ export default SchemaLockTarget;
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ const FORMAT = 1;
2
+ // Canonicalize: sort every object's keys and every named collection, so
3
+ // the file is byte-stable for an unchanged schema regardless of catalog
4
+ // ordering.
5
+ function canonical(value) {
6
+ if (Array.isArray(value))
7
+ return value.map(canonical);
8
+ if (value && typeof value === "object") {
9
+ const out = {};
10
+ for (const key of Object.keys(value).sort()) {
11
+ out[key] = canonical(value[key]);
12
+ }
13
+ return out;
14
+ }
15
+ return value;
16
+ }
17
+ function sortByName(xs) {
18
+ return [...xs].sort((a, b) => `${a.schema ?? ""}.${a.name}`.localeCompare(`${b.schema ?? ""}.${b.name}`));
19
+ }
20
+ export class SchemaLockTarget {
21
+ name = "schema-lock";
22
+ fileExtension = ".json";
23
+ barrel = false;
24
+ capabilities = {
25
+ strictObjects: false,
26
+ brandedTypes: false,
27
+ dateInstances: false,
28
+ };
29
+ renderTable() {
30
+ throw new Error("schema-lock is a snapshot-level target");
31
+ }
32
+ renderSnapshot(snapshot, _opts) {
33
+ const body = canonical({
34
+ format: FORMAT,
35
+ tables: sortByName(snapshot.tables),
36
+ enums: sortByName(snapshot.enums),
37
+ domains: sortByName(snapshot.domains),
38
+ composites: sortByName(snapshot.composites),
39
+ });
40
+ return [
41
+ { file: "schema.lock.json", content: JSON.stringify(body, null, 2) + "\n" },
42
+ ];
43
+ }
44
+ }
45
+ export default SchemaLockTarget;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@supawatch/target-schema-lock",
3
+ "version": "0.2.0",
4
+ "description": "A canonical committed schema lockfile from supawatch, turning pull-request diffs into schema changelogs.",
5
+ "keywords": [
6
+ "supabase",
7
+ "postgres",
8
+ "postgresql",
9
+ "codegen",
10
+ "schema",
11
+ "typescript",
12
+ "lockfile",
13
+ "drift",
14
+ "ci"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Omar Dulaimi",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/omar-dulaimi/supawatch.git",
21
+ "directory": "packages/target-schema-lock"
22
+ },
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "@supawatch/core": "0.2.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.20.1",
40
+ "typescript": "^5.9.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json"
44
+ }
45
+ }