@softure-ai/db 0.1.5 → 0.1.6

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +215 -21
  3. package/dist/cli/run.d.ts +8 -1
  4. package/dist/cli/run.d.ts.map +1 -1
  5. package/dist/cli/run.js +71 -21
  6. package/dist/cli/run.js.map +1 -1
  7. package/dist/client.d.ts +39 -8
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +64 -8
  10. package/dist/client.js.map +1 -1
  11. package/dist/configured.d.ts +31 -0
  12. package/dist/configured.d.ts.map +1 -0
  13. package/dist/configured.js +74 -0
  14. package/dist/configured.js.map +1 -0
  15. package/dist/index.d.ts +3 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/migrations/adopt.d.ts +8 -1
  20. package/dist/migrations/adopt.d.ts.map +1 -1
  21. package/dist/migrations/adopt.js +53 -87
  22. package/dist/migrations/adopt.js.map +1 -1
  23. package/dist/migrations/apply.d.ts +35 -0
  24. package/dist/migrations/apply.d.ts.map +1 -0
  25. package/dist/migrations/apply.js +115 -0
  26. package/dist/migrations/apply.js.map +1 -0
  27. package/dist/migrations/migrator.d.ts +55 -27
  28. package/dist/migrations/migrator.d.ts.map +1 -1
  29. package/dist/migrations/migrator.js +187 -103
  30. package/dist/migrations/migrator.js.map +1 -1
  31. package/dist/migrations/problems.d.ts +9 -0
  32. package/dist/migrations/problems.d.ts.map +1 -1
  33. package/dist/migrations/problems.js +9 -3
  34. package/dist/migrations/problems.js.map +1 -1
  35. package/dist/migrations/reference.d.ts +23 -0
  36. package/dist/migrations/reference.d.ts.map +1 -0
  37. package/dist/migrations/reference.js +64 -0
  38. package/dist/migrations/reference.js.map +1 -0
  39. package/dist/migrations/session.d.ts +2 -1
  40. package/dist/migrations/session.d.ts.map +1 -1
  41. package/dist/migrations/session.js +19 -2
  42. package/dist/migrations/session.js.map +1 -1
  43. package/dist/migrations/stubs.d.ts +23 -0
  44. package/dist/migrations/stubs.d.ts.map +1 -0
  45. package/dist/migrations/stubs.js +99 -0
  46. package/dist/migrations/stubs.js.map +1 -0
  47. package/dist/testing.d.ts +11 -2
  48. package/dist/testing.d.ts.map +1 -1
  49. package/dist/testing.js +28 -9
  50. package/dist/testing.js.map +1 -1
  51. package/package.json +22 -5
  52. package/src/cli/run.ts +84 -23
  53. package/src/client.ts +88 -16
  54. package/src/configured.ts +109 -0
  55. package/src/index.ts +9 -0
  56. package/src/migrations/adopt.ts +65 -100
  57. package/src/migrations/apply.ts +135 -0
  58. package/src/migrations/migrator.ts +246 -128
  59. package/src/migrations/problems.ts +13 -5
  60. package/src/migrations/reference.ts +78 -0
  61. package/src/migrations/session.ts +28 -2
  62. package/src/migrations/stubs.ts +139 -0
  63. package/src/testing.ts +38 -10
package/dist/client.d.ts CHANGED
@@ -2,19 +2,30 @@ import type { PGlite } from "@electric-sql/pglite";
2
2
  import type { NodePgDatabase } from "drizzle-orm/node-postgres";
3
3
  import type { PgliteDatabase } from "drizzle-orm/pglite";
4
4
  import type { Pool } from "pg";
5
- export type PostgresDatabase = NodePgDatabase & {
5
+ /** The optional peer a URL scheme needs, named in the error when it is not installed. */
6
+ export interface DriverRequirement {
7
+ readonly packageName: string;
8
+ readonly scheme: string;
9
+ }
10
+ /**
11
+ * The drizzle schema a database is typed with. The default accepts any schema, so an app database made with
12
+ * `drizzle({ client, schema })` (and its transactions) can be passed wherever a module takes `Database` or
13
+ * `Queryable`; pass the app's schema to keep its relational `db.query` API typed.
14
+ */
15
+ export type DatabaseSchema = Record<string, unknown>;
16
+ export type PostgresDatabase<TSchema extends DatabaseSchema = DatabaseSchema> = NodePgDatabase<TSchema> & {
6
17
  $client: Pool;
7
18
  };
8
- export type PgliteClientDatabase = PgliteDatabase & {
19
+ export type PgliteClientDatabase<TSchema extends DatabaseSchema = DatabaseSchema> = PgliteDatabase<TSchema> & {
9
20
  $client: PGlite;
10
21
  };
11
22
  /** The drizzle database modules and the app query through. */
12
- export type Database = PostgresDatabase | PgliteClientDatabase;
23
+ export type Database<TSchema extends DatabaseSchema = DatabaseSchema> = PostgresDatabase<TSchema> | PgliteClientDatabase<TSchema>;
13
24
  /**
14
25
  * A connection *or* an open transaction. Query helpers take this, so one function serves a
15
- * plain read and a step inside `db.transaction()` (FIRE `client.ts`).
26
+ * plain read and a step inside `db.transaction()`.
16
27
  */
17
- export type Queryable = Database | Parameters<Parameters<Database["transaction"]>[0]>[0];
28
+ export type Queryable<TSchema extends DatabaseSchema = DatabaseSchema> = Database<TSchema> | Parameters<Parameters<Database<TSchema>["transaction"]>[0]>[0];
18
29
  export type DatabaseHandle = {
19
30
  readonly kind: "postgres";
20
31
  readonly db: PostgresDatabase;
@@ -31,12 +42,32 @@ export interface CreateDatabaseOptions {
31
42
  readonly max?: number;
32
43
  }
33
44
  /**
34
- * Opens the database a URL points at. Throws when the scheme is not supported: that is a
35
- * deployment bug. The message names the scheme only, never the URL, which holds a password.
45
+ * Opens the database a URL points at. Throws when the URL is empty or its scheme is not supported:
46
+ * that is a deployment bug. The message names the scheme only, never the URL, which holds a password.
47
+ * The config accepts an empty URL (a build has no DATABASE_URL), so this is where it is refused.
36
48
  */
37
49
  export declare function createDatabase(url: string, options?: CreateDatabaseOptions): Promise<DatabaseHandle>;
38
- /** Wraps an open PGlite instance (used by `createTestDatabase`). */
50
+ /**
51
+ * Wraps an open PGlite instance, e.g. the app's own, for `database.handle` in softure.config. `close` closes the
52
+ * instance, which writes a `pglite://<dir>` database back to its directory.
53
+ */
39
54
  export declare function createPgliteHandle(client: PGlite): Promise<DatabaseHandle & {
40
55
  kind: "pglite";
41
56
  }>;
57
+ /**
58
+ * Wraps an open node-postgres pool, e.g. the app's own, for `database.handle` in softure.config. `close` ends
59
+ * the pool. The pool's `error` listener stays the app's: add one, or an idle client's lost connection crashes
60
+ * the process.
61
+ */
62
+ export declare function createPostgresHandle(pool: Pool): Promise<DatabaseHandle & {
63
+ kind: "postgres";
64
+ }>;
65
+ /** Whether `value` has the shape of a `DatabaseHandle` (what `database.handle` must return). */
66
+ export declare function isDatabaseHandle(value: unknown): value is DatabaseHandle;
67
+ /**
68
+ * Turns Node's "Cannot find package" for a driver (from the driver import or from drizzle's adapter, which imports
69
+ * it statically) into an error that says what to install. Anything else, including a missing package other than
70
+ * the driver, is returned unchanged.
71
+ */
72
+ export declare function explainMissingDriver(error: unknown, driver: DriverRequirement): unknown;
42
73
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK/B,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,8DAA8D;AAC9D,MAAM,MAAM,QAAQ,GAAG,gBAAgB,GAAG,oBAAoB,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzF,MAAM,MAAM,cAAc,GACtB;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,gBAAgB,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,IAAI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AA0B,GAAG,OAAO,CAAC,cAAc,CAAC,CAqB9G;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAGrG;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,cAAc,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAGrG;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAOxE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAWvF"}
package/dist/client.js CHANGED
@@ -1,32 +1,88 @@
1
1
  const PGLITE_PREFIX = "pglite://";
2
2
  const POSTGRES_PREFIXES = ["postgres://", "postgresql://"];
3
+ const MODULE_NOT_FOUND_CODES = new Set(["ERR_MODULE_NOT_FOUND", "MODULE_NOT_FOUND"]);
4
+ const POSTGRES_DRIVER = { packageName: "pg", scheme: "postgres://" };
5
+ const PGLITE_DRIVER = { packageName: "@electric-sql/pglite", scheme: "pglite://" };
3
6
  /**
4
- * Opens the database a URL points at. Throws when the scheme is not supported: that is a
5
- * deployment bug. The message names the scheme only, never the URL, which holds a password.
7
+ * Opens the database a URL points at. Throws when the URL is empty or its scheme is not supported:
8
+ * that is a deployment bug. The message names the scheme only, never the URL, which holds a password.
9
+ * The config accepts an empty URL (a build has no DATABASE_URL), so this is where it is refused.
6
10
  */
7
11
  export async function createDatabase(url, options = {}) {
12
+ if (url === "") {
13
+ throw new Error("createDatabase: the database URL is empty; set database.url in softure.config (usually from DATABASE_URL)");
14
+ }
8
15
  if (url.startsWith(PGLITE_PREFIX)) {
9
16
  const dataDir = url.slice(PGLITE_PREFIX.length);
10
- const { PGlite } = await import("@electric-sql/pglite");
17
+ const { PGlite } = await importDriver(PGLITE_DRIVER, () => import("@electric-sql/pglite"));
11
18
  const client = dataDir === "" ? new PGlite() : new PGlite(dataDir);
12
19
  return createPgliteHandle(client);
13
20
  }
14
21
  if (POSTGRES_PREFIXES.some((prefix) => url.startsWith(prefix))) {
15
- const { default: pg } = await import("pg");
16
- const { drizzle } = await import("drizzle-orm/node-postgres");
22
+ const { default: pg } = await importDriver(POSTGRES_DRIVER, () => import("pg"));
17
23
  const pool = new pg.Pool({ connectionString: url, max: options.max ?? 10 });
18
24
  // An idle client that loses its connection emits 'error' on the pool; unhandled, it would
19
25
  // crash the process. The pool drops that client and the next query opens a new one.
20
26
  pool.on("error", () => undefined);
21
- return { kind: "postgres", db: drizzle({ client: pool }), pool, close: () => pool.end() };
27
+ return createPostgresHandle(pool);
22
28
  }
23
29
  throw new Error(`createDatabase: unsupported database URL scheme ${describeScheme(url)}; use postgres://, postgresql:// or pglite://<dir>`);
24
30
  }
25
- /** Wraps an open PGlite instance (used by `createTestDatabase`). */
31
+ /**
32
+ * Wraps an open PGlite instance, e.g. the app's own, for `database.handle` in softure.config. `close` closes the
33
+ * instance, which writes a `pglite://<dir>` database back to its directory.
34
+ */
26
35
  export async function createPgliteHandle(client) {
27
- const { drizzle } = await import("drizzle-orm/pglite");
36
+ const { drizzle } = await importDriver(PGLITE_DRIVER, () => import("drizzle-orm/pglite"));
28
37
  return { kind: "pglite", db: drizzle({ client }), client, close: () => client.close() };
29
38
  }
39
+ /**
40
+ * Wraps an open node-postgres pool, e.g. the app's own, for `database.handle` in softure.config. `close` ends
41
+ * the pool. The pool's `error` listener stays the app's: add one, or an idle client's lost connection crashes
42
+ * the process.
43
+ */
44
+ export async function createPostgresHandle(pool) {
45
+ const { drizzle } = await importDriver(POSTGRES_DRIVER, () => import("drizzle-orm/node-postgres"));
46
+ return { kind: "postgres", db: drizzle({ client: pool }), pool, close: () => pool.end() };
47
+ }
48
+ /** Whether `value` has the shape of a `DatabaseHandle` (what `database.handle` must return). */
49
+ export function isDatabaseHandle(value) {
50
+ if (typeof value !== "object" || value === null)
51
+ return false;
52
+ const candidate = value;
53
+ if (typeof candidate.db !== "object" || candidate.db === null || typeof candidate.close !== "function")
54
+ return false;
55
+ if (candidate.kind === "postgres")
56
+ return typeof candidate.pool === "object" && candidate.pool !== null;
57
+ if (candidate.kind === "pglite")
58
+ return typeof candidate.client === "object" && candidate.client !== null;
59
+ return false;
60
+ }
61
+ /**
62
+ * Turns Node's "Cannot find package" for a driver (from the driver import or from drizzle's adapter, which imports
63
+ * it statically) into an error that says what to install. Anything else, including a missing package other than
64
+ * the driver, is returned unchanged.
65
+ */
66
+ export function explainMissingDriver(error, driver) {
67
+ if (!(error instanceof Error))
68
+ return error;
69
+ const code = error.code;
70
+ if (typeof code !== "string" || !MODULE_NOT_FOUND_CODES.has(code))
71
+ return error;
72
+ if (!error.message.includes(`'${driver.packageName}'`))
73
+ return error;
74
+ return new Error(`createDatabase: ${driver.scheme} URLs need the "${driver.packageName}" package, which is not installed; run ` +
75
+ `\`npm install ${driver.packageName}\` and, in a Next.js app, list "@softure-ai/db" and "${driver.packageName}" ` +
76
+ "in serverExternalPackages (db README §2)", { cause: error });
77
+ }
78
+ async function importDriver(driver, load) {
79
+ try {
80
+ return await load();
81
+ }
82
+ catch (error) {
83
+ throw explainMissingDriver(error, driver);
84
+ }
85
+ }
30
86
  function describeScheme(url) {
31
87
  const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(url)?.[1];
32
88
  return scheme === undefined ? "(none)" : `"${scheme}:"`;
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,iBAAiB,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAiC3D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW,EAAE,UAAiC,EAAE;I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AIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc,EAAE,MAAyB;IAC5E,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,IAAI,GAAI,KAAoC,CAAC,IAAI,CAAC;IACxD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,WAAW,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACrE,OAAO,IAAI,KAAK,CACd,mBAAmB,MAAM,CAAC,MAAM,mBAAmB,MAAM,CAAC,WAAW,yCAAyC;QAC5G,iBAAiB,MAAM,CAAC,WAAW,wDAAwD,MAAM,CAAC,WAAW,IAAI;QACjH,0CAA0C,EAC5C,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,YAAY,CAAI,MAAyB,EAAE,IAAsB;IAC9E,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,MAAM,GAAG,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,IAAI,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { SoftureDatabaseConfig } from "@softure-ai/core";
2
+ import { type CreateDatabaseOptions, type DatabaseHandle } from "./client.js";
3
+ declare module "@softure-ai/core" {
4
+ interface SoftureDatabaseHandleTypes {
5
+ readonly handle: DatabaseHandle;
6
+ }
7
+ }
8
+ /**
9
+ * The handle for the config's database: the app's `database.handle`, called once per function and checked, or
10
+ * else `getSharedDatabase(database.url)`. Never closes anything; for a server's whole life. A failed or invalid
11
+ * `handle` call is not kept, so the next call tries again.
12
+ */
13
+ export declare function getConfiguredDatabase(database: SoftureDatabaseConfig): Promise<DatabaseHandle>;
14
+ export interface CommandDatabase {
15
+ readonly handle: DatabaseHandle;
16
+ /** Closes what the command opened: its own handle, or the app's configured one (and forgets it). */
17
+ readonly close: () => Promise<void>;
18
+ }
19
+ /**
20
+ * The database for a command's own process (`softure migrate`, a module CLI, an ops script): the app's
21
+ * configured handle when `database.handle` is set, so the app's hooks and the command share one instance,
22
+ * otherwise a new handle on `database.url` with `options`. `close` closes either one; a `pglite://` directory is
23
+ * written back only then. Not for a running server: closing would close the app's handle under it.
24
+ */
25
+ export declare function openCommandDatabase(database: SoftureDatabaseConfig, options?: CreateDatabaseOptions): Promise<CommandDatabase>;
26
+ /**
27
+ * Closes and forgets every configured handle this process resolved. For tests; at shutdown the app closes its own
28
+ * handle, which it owns (`closeSharedDatabases` leaves configured handles alone for that reason).
29
+ */
30
+ export declare function closeConfiguredDatabases(): Promise<void>;
31
+ //# sourceMappingURL=configured.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configured.d.ts","sourceRoot":"","sources":["../src/configured.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAoC,KAAK,qBAAqB,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAGhH,OAAO,QAAQ,kBAAkB,CAAC;IAChC,UAAU,0BAA0B;QAClC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;KACjC;CACF;AAqBD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiB9F;AAYD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,oGAAoG;IACpG,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBxI;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAM9D"}
@@ -0,0 +1,74 @@
1
+ import { createDatabase, isDatabaseHandle } from "./client.js";
2
+ import { getSharedDatabase } from "./shared.js";
3
+ const CONFIGURED_KEY = Symbol.for("@softure-ai/db/configured-handles");
4
+ const host = globalThis;
5
+ function getConfiguredHandles() {
6
+ return (host[CONFIGURED_KEY] ??= { byFunction: new WeakMap(), open: new Set() });
7
+ }
8
+ /**
9
+ * The handle for the config's database: the app's `database.handle`, called once per function and checked, or
10
+ * else `getSharedDatabase(database.url)`. Never closes anything; for a server's whole life. A failed or invalid
11
+ * `handle` call is not kept, so the next call tries again.
12
+ */
13
+ export function getConfiguredDatabase(database) {
14
+ const source = database.handle;
15
+ if (source === undefined)
16
+ return getSharedDatabase(database.url);
17
+ const handles = getConfiguredHandles();
18
+ let handle = handles.byFunction.get(source);
19
+ if (handle === undefined) {
20
+ handle = resolveHandle(source);
21
+ const opened = handle;
22
+ handles.byFunction.set(source, opened);
23
+ handles.open.add(opened);
24
+ opened.catch(() => {
25
+ handles.byFunction.delete(source);
26
+ handles.open.delete(opened);
27
+ });
28
+ }
29
+ return handle;
30
+ }
31
+ async function resolveHandle(source) {
32
+ const value = await source();
33
+ if (!isDatabaseHandle(value)) {
34
+ throw new Error("database.handle: the function must return a database handle; wrap the app's client with createPostgresHandle(pool) or createPgliteHandle(client) from @softure-ai/db");
35
+ }
36
+ return value;
37
+ }
38
+ /**
39
+ * The database for a command's own process (`softure migrate`, a module CLI, an ops script): the app's
40
+ * configured handle when `database.handle` is set, so the app's hooks and the command share one instance,
41
+ * otherwise a new handle on `database.url` with `options`. `close` closes either one; a `pglite://` directory is
42
+ * written back only then. Not for a running server: closing would close the app's handle under it.
43
+ */
44
+ export async function openCommandDatabase(database, options = {}) {
45
+ const source = database.handle;
46
+ if (source === undefined) {
47
+ const handle = await createDatabase(database.url, options);
48
+ return { handle, close: handle.close };
49
+ }
50
+ const opened = getConfiguredDatabase(database);
51
+ const handle = await opened;
52
+ return {
53
+ handle,
54
+ close: async () => {
55
+ const handles = getConfiguredHandles();
56
+ handles.byFunction.delete(source);
57
+ handles.open.delete(opened);
58
+ await handle.close();
59
+ },
60
+ };
61
+ }
62
+ /**
63
+ * Closes and forgets every configured handle this process resolved. For tests; at shutdown the app closes its own
64
+ * handle, which it owns (`closeSharedDatabases` leaves configured handles alone for that reason).
65
+ */
66
+ export async function closeConfiguredDatabases() {
67
+ const handles = host[CONFIGURED_KEY];
68
+ if (handles === undefined)
69
+ return;
70
+ host[CONFIGURED_KEY] = undefined;
71
+ const results = await Promise.allSettled([...handles.open]);
72
+ await Promise.all(results.flatMap((result) => (result.status === "fulfilled" ? [result.value.close()] : [])));
73
+ }
74
+ //# sourceMappingURL=configured.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configured.js","sourceRoot":"","sources":["../src/configured.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAmD,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAUhD,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAWvE,MAAM,IAAI,GAAG,UAAmC,CAAC;AAEjD,SAAS,oBAAoB;IAC3B,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,OAAO,EAAE,EAAE,IAAI,EAA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DatabaseOptions, type Database, type DatabaseHandle, type PgliteClientDatabase, type PostgresDatabase, type Queryable, } from "./client.js";
1
+ export { createDatabase, createPgliteHandle, createPostgresHandle, isDatabaseHandle, type CreateDatabaseOptions, type Database, type DatabaseHandle, type DatabaseSchema, type PgliteClientDatabase, type PostgresDatabase, type Queryable, } from "./client.js";
2
2
  export { closeSharedDatabases, getSharedDatabase } from "./shared.js";
3
+ export { closeConfiguredDatabases, getConfiguredDatabase, openCommandDatabase, type CommandDatabase } from "./configured.js";
3
4
  export { computeChecksum, readMigrationFiles, type MigrationFile } from "./migrations/files.js";
4
5
  export { describeProblem, type MigrationErrorCode, type MigrationFailure, type MigrationProblem, type MigrationResult, } from "./migrations/problems.js";
5
- export { migrate, planMigrations, type MigrateOptions, type MigrationPlan, type MigrationReport, type MigrationStep, } from "./migrations/migrator.js";
6
+ export { migrate, planMigrations, runAppMigrations, type AppMigrationHook, type AppMigrationPhase, type AppMigrations, type MigrateOptions, type MigrationPlan, type MigrationReport, type MigrationStep, } from "./migrations/migrator.js";
6
7
  export { adoptModule, type AdoptionReport, type AdoptOptions } from "./migrations/adopt.js";
7
8
  export { exportMigrations } from "./migrations/export.js";
8
9
  export { checkExportedMigrations, type ExportedMigration, type ExportedMigrationsCheck, } from "./migrations/exported.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,EACvB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B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC5F,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  // Public API of @softure-ai/db: the database client and the module migrator
2
2
  // (docs/02-module-standard.md §4). Test databases: `@softure-ai/db/testing`; CLI: `@softure-ai/db/cli`.
3
- export { createDatabase, } from "./client.js";
3
+ export { createDatabase, createPgliteHandle, createPostgresHandle, isDatabaseHandle, } from "./client.js";
4
4
  export { closeSharedDatabases, getSharedDatabase } from "./shared.js";
5
+ export { closeConfiguredDatabases, getConfiguredDatabase, openCommandDatabase } from "./configured.js";
5
6
  export { computeChecksum, readMigrationFiles } from "./migrations/files.js";
6
7
  export { describeProblem, } from "./migrations/problems.js";
7
- export { migrate, planMigrations, } from "./migrations/migrator.js";
8
+ export { migrate, planMigrations, runAppMigrations, } from "./migrations/migrator.js";
8
9
  export { adoptModule } from "./migrations/adopt.js";
9
10
  export { exportMigrations } from "./migrations/export.js";
10
11
  export { checkExportedMigrations, } from "./migrations/exported.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wGAAwG;AACxG,OAAO,EACL,cAAc,GAOf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAsB,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACL,eAAe,GAKhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,cAAc,GAKf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAA0C,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,uBAAuB,GAGxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAyC,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wGAAwG;AACxG,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GAQjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,mBAAmB,EAAwB,MAAM,iBAAiB,CAAC;AAC7H,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAsB,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACL,eAAe,GAKhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,cAAc,EACd,gBAAgB,GAQjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAA0C,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,uBAAuB,GAGxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAyC,MAAM,wBAAwB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { type AnySoftureModule } from "@softure-ai/core";
2
- import { type DatabaseHandle } from "../client.js";
2
+ import type { DatabaseHandle } from "../client.js";
3
3
  import { type MigrationStep } from "./migrator.js";
4
4
  import { type MigrationResult } from "./problems.js";
5
5
  export interface AdoptOptions {
@@ -9,6 +9,11 @@ export interface AdoptOptions {
9
9
  readonly module: string;
10
10
  /** Its version; must equal the enabled module's manifest version. */
11
11
  readonly version: string;
12
+ /**
13
+ * The last file to adopt (1..n); default every file. The later files stay pending and the next
14
+ * `migrate` applies them.
15
+ */
16
+ readonly through?: number;
12
17
  /** Compare and report only; write nothing (also no ledger). */
13
18
  readonly dryRun?: boolean;
14
19
  readonly migrationsDir?: URL;
@@ -19,6 +24,8 @@ export interface AdoptionReport {
19
24
  readonly dryRun: boolean;
20
25
  /** Ledger migrations applied first (or that would be, on a dry run). */
21
26
  readonly ledger: readonly MigrationStep[];
27
+ /** Pending files of the modules it depends on, applied before the comparison (or that would be). */
28
+ readonly dependencies: readonly MigrationStep[];
22
29
  /** The module's migrations recorded as adopted (or that would be). */
23
30
  readonly adopted: readonly MigrationStep[];
24
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"adopt.d.ts","sourceRoot":"","sources":["../../src/migrations/adopt.ts"],"names":[],"mappings":"AAKA,OAAO,EAAM,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnE,OAAO,EAOL,KAAK,aAAa,EAEnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAmC,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAGtF,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,qCA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AAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,oGAAoG;IACpG,QAAQ,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,CAAC;IAChD,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAkEzH"}
@@ -1,15 +1,18 @@
1
1
  // Adoption (docs/02-module-standard.md §4, docs/05-adoption-playbook.md step 3): an existing app
2
2
  // has moved its own tables into a module's schema with its own migration. `adoptModule` checks
3
- // that the schema now equals what the module's migrations would create, then records those
4
- // migrations as `adopted` without running them. Any difference refuses: marking a schema as
5
- // migrated when it is not is the one mistake a later migration cannot recover from.
3
+ // that the schema now equals what the module's files 1..through would create, then records those
4
+ // files as `adopted` without running them; the later files stay pending for `migrate`. Any
5
+ // difference refuses: marking a schema as migrated when it is not is the one mistake a later
6
+ // migration cannot recover from. The pending files of the modules it depends on run first.
6
7
  import { ok } from "@softure-ai/core";
7
- import { createDatabase } from "../client.js";
8
+ import { applyFile, recordAdoption, withMigrationLock } from "./apply.js";
8
9
  import { describeSchema, diffSchemas } from "./introspect.js";
9
- import { LEDGER_MODULE_ID, readJournal, recordMigration } from "./ledger.js";
10
- import { applyFile, compareJournal, migrate, prepareUnits, rollBack, withMigrationLock, } from "./migrator.js";
10
+ import { LEDGER_MODULE_ID, readJournal } from "./ledger.js";
11
+ import { checkThrough, compareJournal, prepareUnits, toStep } from "./migrator.js";
11
12
  import { failWith } from "./problems.js";
13
+ import { buildReferenceSchema, collectWithDependencies, listOwnedSchemas } from "./reference.js";
12
14
  import { withSession } from "./session.js";
15
+ import { readAppTables } from "./stubs.js";
13
16
  export async function adoptModule(handle, options) {
14
17
  const target = options.modules.find((module) => module.id === options.module);
15
18
  if (target === undefined) {
@@ -26,106 +29,69 @@ export async function adoptModule(handle, options) {
26
29
  if (unit === undefined) {
27
30
  return failWith([{ code: "db.adopt_no_schema", module: target.id }]);
28
31
  }
29
- const reference = await describeReference(options, target);
30
- if (!reference.ok) {
31
- return reference;
32
+ const through = options.through ?? unit.files.length;
33
+ const throughProblems = checkThrough(unit, through);
34
+ if (throughProblems.length > 0) {
35
+ return failWith(throughProblems);
32
36
  }
33
37
  return withSession(handle, (session) => withMigrationLock(session, async () => {
34
38
  const journal = await readJournal(session);
35
39
  const comparison = compareJournal(units.value, journal);
36
- const problems = [...comparison.problems, ...checkAdoptable(target, unit, journal, comparison.pending)];
40
+ const problems = [...comparison.problems, ...checkAdoptable(unit, journal)];
37
41
  if (problems.length > 0) {
38
42
  return failWith(problems);
39
43
  }
44
+ const dependencyIds = collectWithDependencies(options.modules, target.id);
45
+ dependencyIds.delete(target.id);
46
+ const ledger = comparison.pending.filter((step) => step.module === LEDGER_MODULE_ID);
47
+ const dependencies = comparison.pending.filter((step) => dependencyIds.has(step.module));
48
+ const files = unit.files.filter((file) => file.version <= through);
49
+ const adopted = files.map((file) => toStep(unit, file));
50
+ const report = { module: unit.module, version: options.version, dryRun: options.dryRun === true, ledger, dependencies, adopted };
51
+ // Built from the live database's app tables (module SQL may reference them, issue #170), so
52
+ // inside the lock and only once the checks above passed.
53
+ const appTables = await readAppTables(session, listOwnedSchemas(units.value));
54
+ const reference = await buildReferenceSchema({ modules: options.modules, units: units.value, target: unit, through, appTables });
55
+ if (!reference.ok) {
56
+ return reference;
57
+ }
58
+ // The target's own schema only, compared before anything is written: applying a dependency
59
+ // never changes it.
40
60
  const differences = diffSchemas(reference.value, await describeSchema(session, unit.schema));
41
61
  if (differences.length > 0) {
42
62
  return failWith([{ code: "db.schema_mismatch", module: unit.module, schema: unit.schema, differences }]);
43
63
  }
44
- const ledger = comparison.pending.filter((step) => step.module === LEDGER_MODULE_ID);
45
- const adopted = unit.files.map((file) => ({ module: unit.module, schema: unit.schema, version: file.version, name: file.name, checksum: file.checksum }));
46
- const report = { module: unit.module, version: options.version, dryRun: options.dryRun === true, ledger, adopted };
47
64
  if (options.dryRun === true) {
48
65
  return ok(report);
49
66
  }
50
- const failure = await writeAdoption(session, units.value, unit);
67
+ const ledgerFailure = await applyPending(session, units.value, ledger);
68
+ if (ledgerFailure !== null) {
69
+ return failWith([ledgerFailure.problem]);
70
+ }
71
+ const dependencyFailure = await applyPending(session, units.value, dependencies);
72
+ if (dependencyFailure !== null) {
73
+ return failWith([dependencyFailure.problem, { code: "db.adopt_dependency_pending", module: unit.module, dependency: dependencyFailure.step.module }]);
74
+ }
75
+ const failure = await recordAdoption(session, unit, files);
51
76
  return failure === null ? ok(report) : failWith([failure]);
52
77
  }));
53
78
  }
54
- /** The adopted module must be new to the ledger, and everything it depends on fully migrated. */
55
- function checkAdoptable(target, unit, journal, pending) {
56
- if (journal.some((row) => row.module === unit.module)) {
57
- return [{ code: "db.adopt_already_applied", module: unit.module }];
58
- }
59
- return Object.keys(target.manifest.dependsOn)
60
- .filter((dependency) => pending.some((step) => step.module === dependency))
61
- .map((dependency) => ({ code: "db.adopt_dependency_pending", module: unit.module, dependency }));
79
+ /** The adopted module must be new to the ledger. */
80
+ function checkAdoptable(unit, journal) {
81
+ return journal.some((row) => row.module === unit.module) ? [{ code: "db.adopt_already_applied", module: unit.module }] : [];
62
82
  }
63
- /**
64
- * The schema the module's migrations create: they run on a scratch PGlite together with the
65
- * enabled modules the target depends on (directly or not), because its SQL may reference them.
66
- */
67
- async function describeReference(options, target) {
68
- const modules = collectWithDependencies(options.modules, target);
69
- const scratch = await createDatabase("pglite://");
70
- try {
71
- const result = await migrate(scratch, { modules, ...(options.migrationsDir ? { migrationsDir: options.migrationsDir } : {}) });
72
- if (!result.ok) {
73
- const reason = result.problems.map((problem) => problem.code === "db.migration_failed" ? `${problem.module} ${problem.name}: ${problem.reason}` : problem.code).join("; ");
74
- return failWith([{ code: "db.adopt_reference_failed", module: target.id, reason }]);
83
+ /** Applies the steps in order, each file in its own transaction; stops at the first failure. */
84
+ async function applyPending(session, units, steps) {
85
+ for (const step of steps) {
86
+ const unit = units.find((candidate) => candidate.module === step.module);
87
+ const file = unit?.files.find((candidate) => candidate.version === step.version);
88
+ if (unit === undefined || file === undefined) {
89
+ throw new Error(`adoptModule: step ${step.module} ${step.version} has no file; compareJournal is broken`);
75
90
  }
76
- const schema = target.manifest.dbSchema ?? "";
77
- return ok(await withSession(scratch, (session) => describeSchema(session, schema)));
78
- }
79
- finally {
80
- await scratch.close();
81
- }
82
- }
83
- function collectWithDependencies(modules, target) {
84
- const byId = new Map(modules.map((module) => [module.id, module]));
85
- const collected = new Map();
86
- const visit = (module) => {
87
- if (collected.has(module.id))
88
- return;
89
- collected.set(module.id, module);
90
- for (const dependency of Object.keys(module.manifest.dependsOn)) {
91
- const listed = byId.get(dependency);
92
- if (listed !== undefined)
93
- visit(listed);
94
- }
95
- };
96
- visit(target);
97
- return [...collected.values()];
98
- }
99
- /** Applies a pending ledger migration, then records every module file as adopted in one transaction. */
100
- async function writeAdoption(session, units, unit) {
101
- const ledger = units.find((candidate) => candidate.module === LEDGER_MODULE_ID);
102
- const journal = await readJournal(session);
103
- for (const file of ledger?.files ?? []) {
104
- if (ledger !== undefined && !journal.some((row) => row.module === LEDGER_MODULE_ID && row.version === file.version)) {
105
- const failure = await applyFile(session, { unit: ledger, file, method: "applied" });
106
- if (failure !== null)
107
- return failure;
108
- }
109
- }
110
- try {
111
- await session.exec("BEGIN");
112
- for (const file of unit.files) {
113
- await recordMigration(session, {
114
- module: unit.module,
115
- version: file.version,
116
- name: file.name,
117
- checksum: file.checksum,
118
- moduleVersion: unit.moduleVersion,
119
- method: "adopted",
120
- });
121
- }
122
- await session.exec("COMMIT");
123
- return null;
124
- }
125
- catch (error) {
126
- const reason = await rollBack(session, error);
127
- const first = unit.files[0];
128
- return { code: "db.migration_failed", module: unit.module, version: first?.version ?? 0, name: first?.name ?? "", reason };
91
+ const failure = await applyFile(session, { unit, file, method: "applied" });
92
+ if (failure !== null)
93
+ return { problem: failure, step };
129
94
  }
95
+ return null;
130
96
  }
131
97
  //# sourceMappingURL=adopt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adopt.js","sourceRoot":"","sources":["../../src/migrations/adopt.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,+FAA+F;AAC/F,2FAA2F;AAC3F,4FAA4F;AAC5F,oFAAoF;AACpF,OAAO,EAAE,EAAE,EAAyB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,cAAc,EACd,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAA+C,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,WAAW,EAAyB,MAAM,cAAc,CAAC;AAwBlE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAsB,EAAE,OAAqB;IAC7E,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,IAAI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