@forklaunch/core 4.2.0 → 4.3.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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Serialise schema migrations across processes.
3
+ *
4
+ * Every generated component that owns a database (the service, its
5
+ * scheduled retention task, a worker, a scale-to-zero image build) runs its
6
+ * migrations when it starts. On a brand-new database, several of them can
7
+ * start at once, and two `CREATE TABLE` statements for the same table race
8
+ * inside Postgres: the loser fails with `23505` on
9
+ * `pg_type_typname_nsp_index` ("Key (typname, typnamespace)=(...) already
10
+ * exists") and the process exits, which fails the first deploy.
11
+ *
12
+ * `runMigrationsWithLock` takes a Postgres transaction-level advisory lock
13
+ * keyed on the database name, runs the migrations while holding it, and lets
14
+ * the commit release it. A second starter waits for the first, then finds the
15
+ * migrations already recorded and applies nothing. A crashed holder cannot
16
+ * leave the lock behind: Postgres drops it when the session ends.
17
+ *
18
+ * Databases other than Postgres run the migrations directly (their DDL is not
19
+ * subject to this race, or has no advisory locks).
20
+ */
21
+ type Execute = (sql: string, params?: unknown[], method?: 'all' | 'get' | 'run', ctx?: unknown) => Promise<unknown>;
22
+ /** The slice of a MikroORM instance the lock needs. */
23
+ export interface MigrationLockOrm {
24
+ em: {
25
+ getConnection(): {
26
+ execute: Execute;
27
+ transactional<T>(cb: (trx: unknown) => Promise<T>): Promise<T>;
28
+ };
29
+ getPlatform(): {
30
+ getDefaultSchemaName?(): string | undefined;
31
+ };
32
+ };
33
+ migrator?: {
34
+ up(): Promise<unknown>;
35
+ };
36
+ getMigrator?: () => {
37
+ up(): Promise<unknown>;
38
+ };
39
+ }
40
+ export interface RunMigrationsWithLockOptions {
41
+ /**
42
+ * What to run while holding the lock. Defaults to `migrator.up()`.
43
+ */
44
+ run?: () => Promise<unknown>;
45
+ /**
46
+ * Lock on this name instead of `<database>:migrations`. Two migrators that
47
+ * must not overlap must use the same name.
48
+ */
49
+ lockName?: string;
50
+ log?: (message: string) => void;
51
+ }
52
+ /**
53
+ * Run the migrations, one migrator at a time per database.
54
+ *
55
+ * The lock is held on one pooled connection inside a transaction while the
56
+ * migrator uses its own connections, so the pool needs at least two
57
+ * connections (MikroORM's default is 2 to 10).
58
+ */
59
+ export declare function runMigrationsWithLock(orm: MigrationLockOrm, options?: RunMigrationsWithLockOptions): Promise<void>;
60
+ export {};
61
+ //# sourceMappingURL=migrationLock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrationLock.d.ts","sourceRoot":"","sources":["../../src/persistence/migrationLock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,KAAK,OAAO,GAAG,CACb,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,EAClB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,EAC9B,GAAG,CAAC,EAAE,OAAO,KACV,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,uDAAuD;AACvD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE;QACF,aAAa,IAAI;YACf,OAAO,EAAE,OAAO,CAAC;YACjB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;SAChE,CAAC;QACF,WAAW,IAAI;YAAE,oBAAoB,CAAC,IAAI,MAAM,GAAG,SAAS,CAAA;SAAE,CAAC;KAChE,CAAC;IACF,QAAQ,CAAC,EAAE;QAAE,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM;QAAE,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;CAChD;AAED,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "forklaunch-js core package. Contains useful building blocks.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -114,7 +114,7 @@
114
114
  "cors": "^2.8.6",
115
115
  "dotenv": "^18.0.10",
116
116
  "fastmcp": "^4.30.2",
117
- "jose": "6.2.18",
117
+ "jose": "6.2.19",
118
118
  "openapi3-ts": "^4.6.2",
119
119
  "pino": "^10.4.0",
120
120
  "pino-http": "^11.0.0",
@@ -126,7 +126,9 @@
126
126
  "devDependencies": {
127
127
  "@eslint/js": "^10.0.1",
128
128
  "@mikro-orm/libsql": "7.2.13",
129
- "@scalar/express-api-reference": "^0.10.43",
129
+ "@mikro-orm/migrations": "7.2.13",
130
+ "@mikro-orm/postgresql": "7.2.13",
131
+ "@scalar/express-api-reference": "^0.10.44",
130
132
  "@types/cors": "^2.8.19",
131
133
  "@types/qs": "^6.15.1",
132
134
  "@types/uuid": "^11.0.0",