@betterinternship/schema 1.30.0 → 2.0.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/README.md +33 -36
- package/dist/db.d.ts +4 -12
- package/dist/db.js +1 -5
- package/dist/db.js.map +1 -1
- package/dist/db.types.d.ts +658 -0
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -5
- package/dist/index.js.map +1 -1
- package/dist/repository/factories.d.ts +2 -11
- package/dist/repository/factories.js +10 -35
- package/dist/repository/factories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -6
- package/dist/db.doc.types.d.ts +0 -110
- package/dist/db.doc.types.js +0 -3
- package/dist/db.doc.types.js.map +0 -1
- package/dist/db.internal.types.d.ts +0 -185
- package/dist/db.internal.types.js +0 -3
- package/dist/db.internal.types.js.map +0 -1
- package/dist/db.internship.types.d.ts +0 -96
- package/dist/db.internship.types.js +0 -3
- package/dist/db.internship.types.js.map +0 -1
- package/dist/db.iom.types.d.ts +0 -315
- package/dist/db.iom.types.js +0 -3
- package/dist/db.iom.types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
# @betterinternship/schema
|
|
2
|
-
|
|
3
|
-
Consolidated database schema package for BetterInternship. Replaces the previous `@betterinternship/schema.base` and `@betterinternship/schema.moa` packages.
|
|
4
|
-
|
|
5
|
-
## Exports
|
|
6
|
-
|
|
7
|
-
- `db` — Kysely client over
|
|
8
|
-
- `
|
|
9
|
-
- `
|
|
10
|
-
- `
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
npm run build
|
|
36
|
-
```
|
|
1
|
+
# @betterinternship/schema
|
|
2
|
+
|
|
3
|
+
Consolidated database schema package for BetterInternship. Replaces the previous `@betterinternship/schema.base` and `@betterinternship/schema.moa` packages.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
- `db` — the one Kysely client, typed over every schema (`career`, `documents`, `forms`, `internal`, `iom`). Table names are schema-qualified (`"career.users"`, `"iom.moas"`), so one query or transaction can span schemas.
|
|
8
|
+
- `createRepository(table)` — base class for a repository bound to one table, e.g. `class MoaRepository extends createRepository('iom.moas') {}`. Optional generics refine the read, insert and update shapes.
|
|
9
|
+
- `handleDBError` — shared Postgres error translator
|
|
10
|
+
- Types: `DB`, every table interface (`CareerUsers`, `IomMoas`, …), `Json`, `Generated`, `Timestamp`, `DBTable`, `Schema`, and `SchemaDB<S>` (`DB` narrowed to some schemas, for handles that must not reach the rest, such as a second connection to prod).
|
|
11
|
+
|
|
12
|
+
2.0 removed the 1.x per-schema clients (`internshipDb`, `documentDb`, `internalDb`, `iomDb`), their types (`InternshipDB`, …), the per-schema repository factories (`createInternalRepository`, …) and the `Internship` / `Document` / `Internal` / `IOM` namespaces. Use `db`, `DB`, `createRepository` and root imports instead.
|
|
13
|
+
|
|
14
|
+
## Environment
|
|
15
|
+
|
|
16
|
+
Codegen reads `DATABASE_URL` from `dev.env`. Create `dev.env` with your dev database URL:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
DATABASE_URL="postgres://..."
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Codegen
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm run generate # every schema -> lib/db.types.ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
To add a schema, add it to the pattern in package.json's `generate` script (and `scripts/db.types.sh`), and to `Schema` in lib/db.ts.
|
|
29
|
+
|
|
30
|
+
After that, don't forget to run:
|
|
31
|
+
```
|
|
32
|
+
npm run build
|
|
33
|
+
```
|
package/dist/db.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
2
|
import { DB } from "./db.types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type InternshipDB = _InternshipDB;
|
|
8
|
-
export type DocumentDB = _DocumentDB;
|
|
9
|
-
export type InternalDB = _InternalDB;
|
|
10
|
-
export type IomDB = _IomDB;
|
|
3
|
+
export type Schema = "career" | "documents" | "forms" | "internal" | "iom";
|
|
4
|
+
export type SchemaDB<S extends Schema> = {
|
|
5
|
+
[K in keyof DB as K extends `${S}.${string}` ? K : never]: DB[K];
|
|
6
|
+
};
|
|
11
7
|
export declare const db: Kysely<DB>;
|
|
12
|
-
export declare const internshipDb: Kysely<_InternshipDB>;
|
|
13
|
-
export declare const documentDb: Kysely<_DocumentDB>;
|
|
14
|
-
export declare const internalDb: Kysely<_InternalDB>;
|
|
15
|
-
export declare const iomDb: Kysely<_IomDB>;
|
|
16
8
|
export declare const handleDBError: (error: any, description?: string) => never;
|
package/dist/db.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleDBError = exports.
|
|
3
|
+
exports.handleDBError = exports.db = void 0;
|
|
4
4
|
const kysely_1 = require("kysely");
|
|
5
5
|
const pg_1 = require("pg");
|
|
6
6
|
const env_1 = require("./env");
|
|
@@ -51,10 +51,6 @@ const lazyKysely = () => {
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
exports.db = lazyKysely();
|
|
54
|
-
exports.internshipDb = lazyKysely();
|
|
55
|
-
exports.documentDb = lazyKysely();
|
|
56
|
-
exports.internalDb = lazyKysely();
|
|
57
|
-
exports.iomDb = lazyKysely();
|
|
58
54
|
const handleDBError = (error, description = "") => {
|
|
59
55
|
switch (error.code) {
|
|
60
56
|
case "PGRST116":
|
package/dist/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../lib/db.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../lib/db.ts"],"names":[],"mappings":";;;AASA,mCAAiD;AACjD,2BAA0B;AAC1B,+BAA4B;AAe5B,IAAI,IAAsB,CAAC;AAC3B,MAAM,OAAO,GAAG,GAAS,EAAE;IACzB,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAEtB,MAAM,YAAY,GAAG,SAAG,CAAC,YAAY,CAAC;IACtC,MAAM,gBAAgB,GAAG,SAAG,CAAC,gBAAgB,CAAC;IAC9C,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAGxE,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAC9D,IAAI,CAAC,gBAAgB,IAAI,CAAC,UAAU;QAClC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAG3D,MAAM,OAAO,GAAG,MAAM,CAAC,SAAG,CAAC,iBAAiB,CAAC,CAAC;IAC9C,IAAI,SAAG,CAAC,iBAAiB,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAE/E,IAAI,GAAG,IAAI,SAAI,CAAC;QACd,gBAAgB,EAAE,YAAY;QAC9B,GAAG,CAAC,SAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,GAAG,EAAE,UAAU;YACb,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE;YAC/B,CAAC,CAAC;gBACE,k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