@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.3

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 (208) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +21 -0
  3. package/README.md +382 -2
  4. package/bin/platform.js +28 -0
  5. package/dist/baseline/deps.d.ts +32 -0
  6. package/dist/baseline/deps.d.ts.map +1 -0
  7. package/dist/baseline/deps.js +64 -0
  8. package/dist/baseline/deps.js.map +1 -0
  9. package/dist/baseline/errors.d.ts +34 -0
  10. package/dist/baseline/errors.d.ts.map +1 -0
  11. package/dist/baseline/errors.js +23 -0
  12. package/dist/baseline/errors.js.map +1 -0
  13. package/dist/baseline/fs.d.ts +9 -0
  14. package/dist/baseline/fs.d.ts.map +1 -0
  15. package/dist/baseline/fs.js +39 -0
  16. package/dist/baseline/fs.js.map +1 -0
  17. package/dist/baseline/index.d.ts +8 -0
  18. package/dist/baseline/index.d.ts.map +1 -0
  19. package/dist/baseline/index.js +24 -0
  20. package/dist/baseline/index.js.map +1 -0
  21. package/dist/baseline/mapping.d.ts +43 -0
  22. package/dist/baseline/mapping.d.ts.map +1 -0
  23. package/dist/baseline/mapping.js +80 -0
  24. package/dist/baseline/mapping.js.map +1 -0
  25. package/dist/baseline/normalise.d.ts +42 -0
  26. package/dist/baseline/normalise.d.ts.map +1 -0
  27. package/dist/baseline/normalise.js +133 -0
  28. package/dist/baseline/normalise.js.map +1 -0
  29. package/dist/baseline/plan.d.ts +66 -0
  30. package/dist/baseline/plan.d.ts.map +1 -0
  31. package/dist/baseline/plan.js +105 -0
  32. package/dist/baseline/plan.js.map +1 -0
  33. package/dist/baseline/report.d.ts +125 -0
  34. package/dist/baseline/report.d.ts.map +1 -0
  35. package/dist/baseline/report.js +85 -0
  36. package/dist/baseline/report.js.map +1 -0
  37. package/dist/baseline/run.d.ts +106 -0
  38. package/dist/baseline/run.d.ts.map +1 -0
  39. package/dist/baseline/run.js +339 -0
  40. package/dist/baseline/run.js.map +1 -0
  41. package/dist/bin/db-commands.d.ts +31 -0
  42. package/dist/bin/db-commands.d.ts.map +1 -0
  43. package/dist/bin/db-commands.js +276 -0
  44. package/dist/bin/db-commands.js.map +1 -0
  45. package/dist/bin/fs-io.d.ts +7 -0
  46. package/dist/bin/fs-io.d.ts.map +1 -0
  47. package/dist/bin/fs-io.js +45 -0
  48. package/dist/bin/fs-io.js.map +1 -0
  49. package/dist/bin/platform.d.ts +21 -0
  50. package/dist/bin/platform.d.ts.map +1 -0
  51. package/dist/bin/platform.js +99 -0
  52. package/dist/bin/platform.js.map +1 -0
  53. package/dist/compose/api.d.ts +84 -0
  54. package/dist/compose/api.d.ts.map +1 -0
  55. package/dist/compose/api.js +101 -0
  56. package/dist/compose/api.js.map +1 -0
  57. package/dist/compose/compose.d.ts +51 -0
  58. package/dist/compose/compose.d.ts.map +1 -0
  59. package/dist/compose/compose.js +177 -0
  60. package/dist/compose/compose.js.map +1 -0
  61. package/dist/compose/diff.d.ts +7 -0
  62. package/dist/compose/diff.d.ts.map +1 -0
  63. package/dist/compose/diff.js +68 -0
  64. package/dist/compose/diff.js.map +1 -0
  65. package/dist/compose/errors.d.ts +31 -0
  66. package/dist/compose/errors.d.ts.map +1 -0
  67. package/dist/compose/errors.js +35 -0
  68. package/dist/compose/errors.js.map +1 -0
  69. package/dist/compose/index.d.ts +3 -0
  70. package/dist/compose/index.d.ts.map +1 -0
  71. package/dist/compose/index.js +11 -0
  72. package/dist/compose/index.js.map +1 -0
  73. package/dist/compose/parse.d.ts +65 -0
  74. package/dist/compose/parse.d.ts.map +1 -0
  75. package/dist/compose/parse.js +122 -0
  76. package/dist/compose/parse.js.map +1 -0
  77. package/dist/drift/db-conformance.d.ts +49 -0
  78. package/dist/drift/db-conformance.d.ts.map +1 -0
  79. package/dist/drift/db-conformance.js +65 -0
  80. package/dist/drift/db-conformance.js.map +1 -0
  81. package/dist/drift/index.d.ts +5 -0
  82. package/dist/drift/index.d.ts.map +1 -0
  83. package/dist/drift/index.js +26 -0
  84. package/dist/drift/index.js.map +1 -0
  85. package/dist/drift/raw-sql-indexes.d.ts +106 -0
  86. package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
  87. package/dist/drift/raw-sql-indexes.js +113 -0
  88. package/dist/drift/raw-sql-indexes.js.map +1 -0
  89. package/dist/drift/raw-sql-tripwire.d.ts +150 -0
  90. package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
  91. package/dist/drift/raw-sql-tripwire.js +394 -0
  92. package/dist/drift/raw-sql-tripwire.js.map +1 -0
  93. package/dist/drift/run.d.ts +128 -0
  94. package/dist/drift/run.d.ts.map +1 -0
  95. package/dist/drift/run.js +201 -0
  96. package/dist/drift/run.js.map +1 -0
  97. package/dist/index.d.ts +16 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +33 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/lock/hash.d.ts +13 -0
  102. package/dist/lock/hash.d.ts.map +1 -0
  103. package/dist/lock/hash.js +19 -0
  104. package/dist/lock/hash.js.map +1 -0
  105. package/dist/lock/index.d.ts +5 -0
  106. package/dist/lock/index.d.ts.map +1 -0
  107. package/dist/lock/index.js +20 -0
  108. package/dist/lock/index.js.map +1 -0
  109. package/dist/lock/lock.d.ts +117 -0
  110. package/dist/lock/lock.d.ts.map +1 -0
  111. package/dist/lock/lock.js +140 -0
  112. package/dist/lock/lock.js.map +1 -0
  113. package/dist/lock/manifest.d.ts +60 -0
  114. package/dist/lock/manifest.d.ts.map +1 -0
  115. package/dist/lock/manifest.js +95 -0
  116. package/dist/lock/manifest.js.map +1 -0
  117. package/dist/lock/semver.d.ts +10 -0
  118. package/dist/lock/semver.d.ts.map +1 -0
  119. package/dist/lock/semver.js +13 -0
  120. package/dist/lock/semver.js.map +1 -0
  121. package/dist/seed/index.d.ts +4 -0
  122. package/dist/seed/index.d.ts.map +1 -0
  123. package/dist/seed/index.js +10 -0
  124. package/dist/seed/index.js.map +1 -0
  125. package/dist/seed/input.d.ts +52 -0
  126. package/dist/seed/input.d.ts.map +1 -0
  127. package/dist/seed/input.js +77 -0
  128. package/dist/seed/input.js.map +1 -0
  129. package/dist/seed/seed-platform.d.ts +28 -0
  130. package/dist/seed/seed-platform.d.ts.map +1 -0
  131. package/dist/seed/seed-platform.js +133 -0
  132. package/dist/seed/seed-platform.js.map +1 -0
  133. package/dist/seed/types.d.ts +277 -0
  134. package/dist/seed/types.d.ts.map +1 -0
  135. package/dist/seed/types.js +5 -0
  136. package/dist/seed/types.js.map +1 -0
  137. package/dist/sync/apply.d.ts +29 -0
  138. package/dist/sync/apply.d.ts.map +1 -0
  139. package/dist/sync/apply.js +37 -0
  140. package/dist/sync/apply.js.map +1 -0
  141. package/dist/sync/check.d.ts +56 -0
  142. package/dist/sync/check.d.ts.map +1 -0
  143. package/dist/sync/check.js +108 -0
  144. package/dist/sync/check.js.map +1 -0
  145. package/dist/sync/errors.d.ts +31 -0
  146. package/dist/sync/errors.d.ts.map +1 -0
  147. package/dist/sync/errors.js +23 -0
  148. package/dist/sync/errors.js.map +1 -0
  149. package/dist/sync/index.d.ts +9 -0
  150. package/dist/sync/index.d.ts.map +1 -0
  151. package/dist/sync/index.js +25 -0
  152. package/dist/sync/index.js.map +1 -0
  153. package/dist/sync/ledger.d.ts +65 -0
  154. package/dist/sync/ledger.d.ts.map +1 -0
  155. package/dist/sync/ledger.js +49 -0
  156. package/dist/sync/ledger.js.map +1 -0
  157. package/dist/sync/plan.d.ts +61 -0
  158. package/dist/sync/plan.d.ts.map +1 -0
  159. package/dist/sync/plan.js +79 -0
  160. package/dist/sync/plan.js.map +1 -0
  161. package/dist/sync/promote.d.ts +58 -0
  162. package/dist/sync/promote.d.ts.map +1 -0
  163. package/dist/sync/promote.js +93 -0
  164. package/dist/sync/promote.js.map +1 -0
  165. package/dist/sync/timestamps.d.ts +41 -0
  166. package/dist/sync/timestamps.d.ts.map +1 -0
  167. package/dist/sync/timestamps.js +68 -0
  168. package/dist/sync/timestamps.js.map +1 -0
  169. package/dist/sync/version.d.ts +28 -0
  170. package/dist/sync/version.d.ts.map +1 -0
  171. package/dist/sync/version.js +66 -0
  172. package/dist/sync/version.js.map +1 -0
  173. package/migrations/0001_initial/migration.sql +297 -0
  174. package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
  175. package/migrations/0003_add_credentials/migration.sql +20 -0
  176. package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
  177. package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
  178. package/migrations/0006_add_notifications/migration.sql +22 -0
  179. package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
  180. package/migrations/0008_add_jobs/migration.sql +110 -0
  181. package/migrations/0009_add_worker_nodes/migration.sql +90 -0
  182. package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
  183. package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
  184. package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
  185. package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
  186. package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
  187. package/migrations/0015_add_job_claim_token/migration.sql +92 -0
  188. package/migrations/0016_add_ai_platform/migration.sql +108 -0
  189. package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
  190. package/migrations/0018_add_user_credentials/migration.sql +29 -0
  191. package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
  192. package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
  193. package/migrations/0021_add_job_trace_context/migration.sql +6 -0
  194. package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
  195. package/migrations/0023_add_organizations/migration.sql +142 -0
  196. package/migrations/0024_split_system_org_roles/migration.sql +131 -0
  197. package/migrations/manifest.json +240 -0
  198. package/package.json +75 -4
  199. package/raw-sql-indexes.json +49 -0
  200. package/schema/ai.prisma +387 -0
  201. package/schema/base.prisma +11 -0
  202. package/schema/credentials.prisma +108 -0
  203. package/schema/db-backup.prisma +376 -0
  204. package/schema/identity.prisma +407 -0
  205. package/schema/jobs.prisma +731 -0
  206. package/schema/notifications.prisma +610 -0
  207. package/schema/settings.prisma +35 -0
  208. package/schema/storage.prisma +57 -0
@@ -0,0 +1,128 @@
1
+ import type { RawSqlIndex } from '../lock/index.js';
2
+ import type { LedgerRow } from '../sync/index.js';
3
+ import { type IndexRow, type RawIndexProblem } from './raw-sql-indexes.js';
4
+ /**
5
+ * The slice of the `pg` client the platform tools use.
6
+ *
7
+ * @internal
8
+ */
9
+ export interface PgClient {
10
+ connect(): Promise<void>;
11
+ query(sql: string, values?: unknown[]): Promise<{
12
+ rows: Record<string, string | Date | null>[];
13
+ }>;
14
+ end(): Promise<void>;
15
+ }
16
+ type PgClientCtor = new (config: {
17
+ connectionString: string;
18
+ }) => PgClient;
19
+ /**
20
+ * What the drift test needs.
21
+ *
22
+ * @stability experimental
23
+ */
24
+ export interface DriftOptions {
25
+ /** Directory holding `prisma.config.ts`; the Prisma CLI runs here. */
26
+ cwd: string;
27
+ /** The app's `prisma/migrations` directory. */
28
+ migrations: string;
29
+ /** The composed schema: a folder or a single `.prisma` file. */
30
+ schema: string;
31
+ /** Connection string of the migrated database (the app's `DATABASE_URL`). */
32
+ databaseUrl: string;
33
+ /** A pre-created, empty shadow database; when omitted one is created and dropped. */
34
+ shadowDatabaseUrl?: string;
35
+ /** Every raw-SQL index to assert (package list plus the app's). */
36
+ rawSqlIndexes: readonly RawSqlIndex[];
37
+ }
38
+ /**
39
+ * The outcome of {@link runDrift}.
40
+ *
41
+ * @stability experimental
42
+ */
43
+ export interface DriftResult {
44
+ /** True when both the diff and the index assertion are clean. */
45
+ ok: boolean;
46
+ /** The SQL `prisma migrate diff` printed: statements that are in the schema but in no migration. Empty when clean. */
47
+ schemaDiff: string;
48
+ /** Missing or changed raw-SQL indexes. */
49
+ indexProblems: RawIndexProblem[];
50
+ }
51
+ /**
52
+ * Resolves the `pg` client constructor from the app, falling back to this package's own copy.
53
+ *
54
+ * @internal
55
+ */
56
+ export declare function loadPg(cwd: string): PgClientCtor;
57
+ /**
58
+ * The path of the `prisma` CLI entry point resolved from the app.
59
+ *
60
+ * @internal
61
+ */
62
+ export declare function prismaCli(cwd: string): string;
63
+ /**
64
+ * Runs `prisma migrate diff` from the migration history to the composed
65
+ * schema, with `--exit-code` and `--script`. The diff replays the history in a
66
+ * shadow database, so it needs one: a supplied URL, or a throwaway database next to the live
67
+ * one that is dropped afterwards.
68
+ *
69
+ * @param options - See {@link DriftOptions}.
70
+ * @returns The SQL of the difference; empty when the history equals the schema.
71
+ * @throws Error when Prisma fails for a reason other than a difference.
72
+ * @stability experimental
73
+ */
74
+ export declare function schemaDiff(options: DriftOptions): Promise<string>;
75
+ /**
76
+ * Runs `body` with a shadow database URL: the supplied one, or a throwaway
77
+ * database created next to the live one (through the `postgres` maintenance
78
+ * database) and dropped afterwards. The live database is never touched.
79
+ *
80
+ * @param options - `cwd` (where `pg` resolves from), the live `databaseUrl` and an optional `shadowDatabaseUrl`.
81
+ * @param body - Receives the shadow database URL.
82
+ * @returns What `body` returns.
83
+ * @internal
84
+ */
85
+ export declare function withShadowDatabase<T>(options: {
86
+ cwd: string;
87
+ databaseUrl: string;
88
+ shadowDatabaseUrl?: string | undefined;
89
+ }, body: (shadowUrl: string) => Promise<T>): Promise<T>;
90
+ /**
91
+ * Removes the Prisma CLI's banner and environment-loader lines from its output.
92
+ *
93
+ * @internal
94
+ */
95
+ export declare function stripBanner(stdout: string): string;
96
+ /**
97
+ * Reads every index of the `public` schema as `name` and `indexdef`.
98
+ *
99
+ * @param databaseUrl - Connection string.
100
+ * @param cwd - Where to resolve `pg` from.
101
+ * @returns The rows of `pg_indexes`.
102
+ * @stability experimental
103
+ */
104
+ export declare function readIndexRows(databaseUrl: string, cwd: string): Promise<IndexRow[]>;
105
+ /**
106
+ * Reads Prisma's `_prisma_migrations` ledger, oldest first. A database Prisma
107
+ * never migrated has no such table and yields no rows.
108
+ *
109
+ * @param databaseUrl - Connection string.
110
+ * @param cwd - Where to resolve `pg` from.
111
+ * @returns The ledger rows.
112
+ * @stability experimental
113
+ */
114
+ export declare function readLedgerRows(databaseUrl: string, cwd: string): Promise<LedgerRow[]>;
115
+ /**
116
+ * The CI drift test: the migration history replayed in a shadow database must
117
+ * equal the composed schema (`prisma migrate diff --exit-code`), and every
118
+ * raw-SQL index must exist with its recorded definition. There is no
119
+ * allow-list over the diff output: Prisma ignores partial and expression
120
+ * indexes in both directions, so the indexes are asserted positively instead.
121
+ *
122
+ * @param options - See {@link DriftOptions}.
123
+ * @returns The diff SQL and the index problems; `ok` when both are empty.
124
+ * @stability experimental
125
+ */
126
+ export declare function runDrift(options: DriftOptions): Promise<DriftResult>;
127
+ export {};
128
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/drift/run.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE/F;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;IAClG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB;AACD,KAAK,YAAY,GAAG,KAAK,MAAM,EAAE;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,KAAK,QAAQ,CAAC;AAE3E;;;;GAIG;AACH,MAAM,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QAAQ,EAAE,CAAC,CAUzF;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAoB3F;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAK1E"}
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadPg = loadPg;
4
+ exports.prismaCli = prismaCli;
5
+ exports.schemaDiff = schemaDiff;
6
+ exports.withShadowDatabase = withShadowDatabase;
7
+ exports.stripBanner = stripBanner;
8
+ exports.readIndexRows = readIndexRows;
9
+ exports.readLedgerRows = readLedgerRows;
10
+ exports.runDrift = runDrift;
11
+ const node_child_process_1 = require("node:child_process");
12
+ const node_fs_1 = require("node:fs");
13
+ const node_module_1 = require("node:module");
14
+ const node_path_1 = require("node:path");
15
+ const raw_sql_indexes_js_1 = require("./raw-sql-indexes.js");
16
+ /**
17
+ * Resolves the `pg` client constructor from the app, falling back to this package's own copy.
18
+ *
19
+ * @internal
20
+ */
21
+ function loadPg(cwd) {
22
+ const req = (0, node_module_1.createRequire)((0, node_path_1.join)((0, node_path_1.resolve)(cwd), 'noop.js'));
23
+ try {
24
+ return req('pg').Client;
25
+ }
26
+ catch {
27
+ // Fall back to this package's own resolution (a workspace hoists it).
28
+ return (0, node_module_1.createRequire)(__filename)('pg').Client;
29
+ }
30
+ }
31
+ function withDatabase(url, database) {
32
+ const parsed = new URL(url);
33
+ parsed.pathname = `/${database}`;
34
+ return parsed.toString();
35
+ }
36
+ const databaseOf = (url) => decodeURIComponent(new URL(url).pathname.replace(/^\//, ''));
37
+ const quoteIdent = (name) => `"${name.replace(/"/g, '""')}"`;
38
+ /**
39
+ * The path of the `prisma` CLI entry point resolved from the app.
40
+ *
41
+ * @internal
42
+ */
43
+ function prismaCli(cwd) {
44
+ const req = (0, node_module_1.createRequire)((0, node_path_1.join)((0, node_path_1.resolve)(cwd), 'noop.js'));
45
+ const found = req.resolve('prisma/build/index.js');
46
+ if (!(0, node_fs_1.existsSync)(found))
47
+ throw new Error('the prisma CLI was not found; install `prisma` in the app');
48
+ return found;
49
+ }
50
+ /**
51
+ * Runs `prisma migrate diff` from the migration history to the composed
52
+ * schema, with `--exit-code` and `--script`. The diff replays the history in a
53
+ * shadow database, so it needs one: a supplied URL, or a throwaway database next to the live
54
+ * one that is dropped afterwards.
55
+ *
56
+ * @param options - See {@link DriftOptions}.
57
+ * @returns The SQL of the difference; empty when the history equals the schema.
58
+ * @throws Error when Prisma fails for a reason other than a difference.
59
+ * @stability experimental
60
+ */
61
+ async function schemaDiff(options) {
62
+ return withShadowDatabase(options, async (shadowUrl) => {
63
+ const result = (0, node_child_process_1.spawnSync)(process.execPath, [
64
+ prismaCli(options.cwd),
65
+ 'migrate',
66
+ 'diff',
67
+ '--from-migrations',
68
+ options.migrations,
69
+ '--to-schema',
70
+ options.schema,
71
+ '--exit-code',
72
+ '--script',
73
+ ], {
74
+ cwd: options.cwd,
75
+ env: { ...process.env, DATABASE_URL: options.databaseUrl, SHADOW_DATABASE_URL: shadowUrl },
76
+ encoding: 'utf8',
77
+ maxBuffer: 64 * 1024 * 1024,
78
+ });
79
+ if (result.error)
80
+ throw result.error;
81
+ if (result.status === 0)
82
+ return '';
83
+ if (result.status === 2)
84
+ return stripBanner(result.stdout);
85
+ throw new Error(`prisma migrate diff failed (exit ${result.status}): ${(result.stderr || result.stdout).trim()}`);
86
+ });
87
+ }
88
+ /**
89
+ * Runs `body` with a shadow database URL: the supplied one, or a throwaway
90
+ * database created next to the live one (through the `postgres` maintenance
91
+ * database) and dropped afterwards. The live database is never touched.
92
+ *
93
+ * @param options - `cwd` (where `pg` resolves from), the live `databaseUrl` and an optional `shadowDatabaseUrl`.
94
+ * @param body - Receives the shadow database URL.
95
+ * @returns What `body` returns.
96
+ * @internal
97
+ */
98
+ async function withShadowDatabase(options, body) {
99
+ const Client = loadPg(options.cwd);
100
+ let shadowUrl = options.shadowDatabaseUrl;
101
+ let created;
102
+ if (!shadowUrl) {
103
+ const name = `${databaseOf(options.databaseUrl)}_drift_shadow_${process.pid}`;
104
+ const admin = new Client({ connectionString: withDatabase(options.databaseUrl, 'postgres') });
105
+ await admin.connect();
106
+ await admin.query(`DROP DATABASE IF EXISTS ${quoteIdent(name)} WITH (FORCE)`);
107
+ await admin.query(`CREATE DATABASE ${quoteIdent(name)}`);
108
+ created = { admin, name };
109
+ shadowUrl = withDatabase(options.databaseUrl, name);
110
+ }
111
+ try {
112
+ return await body(shadowUrl);
113
+ }
114
+ finally {
115
+ if (created) {
116
+ await created.admin.query(`DROP DATABASE IF EXISTS ${quoteIdent(created.name)} WITH (FORCE)`);
117
+ await created.admin.end();
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ * Removes the Prisma CLI's banner and environment-loader lines from its output.
123
+ *
124
+ * @internal
125
+ */
126
+ function stripBanner(stdout) {
127
+ return stdout
128
+ .split('\n')
129
+ .filter((line) => !/^(Loaded Prisma config|Prisma schema loaded|Datasource |◇ injected env|\[dotenv)/.test(line))
130
+ .join('\n')
131
+ .trim();
132
+ }
133
+ /**
134
+ * Reads every index of the `public` schema as `name` and `indexdef`.
135
+ *
136
+ * @param databaseUrl - Connection string.
137
+ * @param cwd - Where to resolve `pg` from.
138
+ * @returns The rows of `pg_indexes`.
139
+ * @stability experimental
140
+ */
141
+ async function readIndexRows(databaseUrl, cwd) {
142
+ const Client = loadPg(cwd);
143
+ const client = new Client({ connectionString: databaseUrl });
144
+ await client.connect();
145
+ try {
146
+ const { rows } = await client.query("SELECT indexname AS name, indexdef AS definition FROM pg_indexes WHERE schemaname = 'public' ORDER BY indexname");
147
+ return rows.map((row) => ({ name: String(row.name), definition: String(row.definition) }));
148
+ }
149
+ finally {
150
+ await client.end();
151
+ }
152
+ }
153
+ /**
154
+ * Reads Prisma's `_prisma_migrations` ledger, oldest first. A database Prisma
155
+ * never migrated has no such table and yields no rows.
156
+ *
157
+ * @param databaseUrl - Connection string.
158
+ * @param cwd - Where to resolve `pg` from.
159
+ * @returns The ledger rows.
160
+ * @stability experimental
161
+ */
162
+ async function readLedgerRows(databaseUrl, cwd) {
163
+ const Client = loadPg(cwd);
164
+ const client = new Client({ connectionString: databaseUrl });
165
+ await client.connect();
166
+ try {
167
+ const { rows } = await client.query('SELECT migration_name, checksum, finished_at, rolled_back_at FROM _prisma_migrations ORDER BY started_at, migration_name');
168
+ return rows.map((row) => ({
169
+ migrationName: String(row.migration_name),
170
+ checksum: String(row.checksum),
171
+ finishedAt: row.finished_at ? new Date(row.finished_at) : null,
172
+ rolledBackAt: row.rolled_back_at ? new Date(row.rolled_back_at) : null,
173
+ }));
174
+ }
175
+ catch (error) {
176
+ if (error.code === '42P01')
177
+ return [];
178
+ throw error;
179
+ }
180
+ finally {
181
+ await client.end();
182
+ }
183
+ }
184
+ /**
185
+ * The CI drift test: the migration history replayed in a shadow database must
186
+ * equal the composed schema (`prisma migrate diff --exit-code`), and every
187
+ * raw-SQL index must exist with its recorded definition. There is no
188
+ * allow-list over the diff output: Prisma ignores partial and expression
189
+ * indexes in both directions, so the indexes are asserted positively instead.
190
+ *
191
+ * @param options - See {@link DriftOptions}.
192
+ * @returns The diff SQL and the index problems; `ok` when both are empty.
193
+ * @stability experimental
194
+ */
195
+ async function runDrift(options) {
196
+ const diff = await schemaDiff(options);
197
+ const live = await readIndexRows(options.databaseUrl, options.cwd);
198
+ const indexProblems = (0, raw_sql_indexes_js_1.checkRawSqlIndexes)(options.rawSqlIndexes, live);
199
+ return { ok: diff === '' && indexProblems.length === 0, schemaDiff: diff, indexProblems };
200
+ }
201
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/drift/run.ts"],"names":[],"mappings":";;AA2DA,wBAQC;AAgBD,8BAKC;AAaD,gCA2BC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CAAC;YACxB,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC;YACzC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YAC9B,UAAU,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI;YAC9D,YAAY,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI;SACvE,CAAC,CAAC,CAAC;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA2B,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,CAAC;QAC7D,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,QAAQ,CAAC,OAAqB;IAClD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACnE,MAAM,aAAa,GAAG,IAAA,uCAAkB,EAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACtE,OAAO,EAAE,EAAE,EAAE,IAAI,KAAK,EAAE,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The npm name of this package, which holds Prisma schema fragments, SQL migrations and seed functions of the platform.
3
+ *
4
+ * A placeholder export so the build, the pack check and the smoke imports in
5
+ * CI have something to load end to end. Real slices arrive as subpath
6
+ * exports (`@marinoscar/platform-db/<slice>`).
7
+ *
8
+ * @stability experimental
9
+ */
10
+ export declare const PLATFORM_PACKAGE: "@marinoscar/platform-db";
11
+ export * from './compose/index.js';
12
+ export * from './lock/index.js';
13
+ export * from './sync/index.js';
14
+ export * from './drift/index.js';
15
+ export * from './baseline/index.js';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAG,yBAAkC,CAAC;AAEnE,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PLATFORM_PACKAGE = void 0;
18
+ /**
19
+ * The npm name of this package, which holds Prisma schema fragments, SQL migrations and seed functions of the platform.
20
+ *
21
+ * A placeholder export so the build, the pack check and the smoke imports in
22
+ * CI have something to load end to end. Real slices arrive as subpath
23
+ * exports (`@marinoscar/platform-db/<slice>`).
24
+ *
25
+ * @stability experimental
26
+ */
27
+ exports.PLATFORM_PACKAGE = '@marinoscar/platform-db';
28
+ __exportStar(require("./compose/index.js"), exports);
29
+ __exportStar(require("./lock/index.js"), exports);
30
+ __exportStar(require("./sync/index.js"), exports);
31
+ __exportStar(require("./drift/index.js"), exports);
32
+ __exportStar(require("./baseline/index.js"), exports);
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG,yBAAkC,CAAC;AAEnE,qDAAmC;AACnC,kDAAgC;AAChC,kDAAgC;AAChC,mDAAiC;AACjC,sDAAoC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Lower-case hex SHA-256 of raw bytes.
3
+ *
4
+ * Migration files are hashed as bytes and never normalised: Prisma checksums
5
+ * the raw file, so a changed comment, a trailing newline or a line ending is a
6
+ * different migration.
7
+ *
8
+ * @param bytes - The file contents, exactly as stored.
9
+ * @returns 64 lower-case hex characters.
10
+ * @stability experimental
11
+ */
12
+ export declare function sha256Hex(bytes: Uint8Array | string): string;
13
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/lock/hash.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAE5D"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sha256Hex = sha256Hex;
4
+ const node_crypto_1 = require("node:crypto");
5
+ /**
6
+ * Lower-case hex SHA-256 of raw bytes.
7
+ *
8
+ * Migration files are hashed as bytes and never normalised: Prisma checksums
9
+ * the raw file, so a changed comment, a trailing newline or a line ending is a
10
+ * different migration.
11
+ *
12
+ * @param bytes - The file contents, exactly as stored.
13
+ * @returns 64 lower-case hex characters.
14
+ * @stability experimental
15
+ */
16
+ function sha256Hex(bytes) {
17
+ return (0, node_crypto_1.createHash)('sha256').update(bytes).digest('hex');
18
+ }
19
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/lock/hash.ts"],"names":[],"mappings":";;AAaA,8BAEC;AAfD,6CAAyC;AAEzC;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAAC,KAA0B;IAClD,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { sha256Hex } from './hash.js';
2
+ export { SEMVER_PATTERN } from './semver.js';
3
+ export { LockFormatError, emptyLock, parseLock, readLock, serializeJson, serializeLock, type LockDeviation, type LockEntry, type PlatformLock, type RawSqlIndex, } from './lock.js';
4
+ export { ManifestFormatError, originIdOf, parseManifest, readManifest, type ManifestEntry } from './manifest.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lock/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,EACT,QAAQ,EACR,aAAa,EACb,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readManifest = exports.parseManifest = exports.originIdOf = exports.ManifestFormatError = exports.serializeLock = exports.serializeJson = exports.readLock = exports.parseLock = exports.emptyLock = exports.LockFormatError = exports.SEMVER_PATTERN = exports.sha256Hex = void 0;
4
+ var hash_js_1 = require("./hash.js");
5
+ Object.defineProperty(exports, "sha256Hex", { enumerable: true, get: function () { return hash_js_1.sha256Hex; } });
6
+ var semver_js_1 = require("./semver.js");
7
+ Object.defineProperty(exports, "SEMVER_PATTERN", { enumerable: true, get: function () { return semver_js_1.SEMVER_PATTERN; } });
8
+ var lock_js_1 = require("./lock.js");
9
+ Object.defineProperty(exports, "LockFormatError", { enumerable: true, get: function () { return lock_js_1.LockFormatError; } });
10
+ Object.defineProperty(exports, "emptyLock", { enumerable: true, get: function () { return lock_js_1.emptyLock; } });
11
+ Object.defineProperty(exports, "parseLock", { enumerable: true, get: function () { return lock_js_1.parseLock; } });
12
+ Object.defineProperty(exports, "readLock", { enumerable: true, get: function () { return lock_js_1.readLock; } });
13
+ Object.defineProperty(exports, "serializeJson", { enumerable: true, get: function () { return lock_js_1.serializeJson; } });
14
+ Object.defineProperty(exports, "serializeLock", { enumerable: true, get: function () { return lock_js_1.serializeLock; } });
15
+ var manifest_js_1 = require("./manifest.js");
16
+ Object.defineProperty(exports, "ManifestFormatError", { enumerable: true, get: function () { return manifest_js_1.ManifestFormatError; } });
17
+ Object.defineProperty(exports, "originIdOf", { enumerable: true, get: function () { return manifest_js_1.originIdOf; } });
18
+ Object.defineProperty(exports, "parseManifest", { enumerable: true, get: function () { return manifest_js_1.parseManifest; } });
19
+ Object.defineProperty(exports, "readManifest", { enumerable: true, get: function () { return manifest_js_1.readManifest; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lock/index.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAA7B,oGAAA,SAAS,OAAA;AAClB,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,qCAWmB;AAVjB,0GAAA,eAAe,OAAA;AACf,oGAAA,SAAS,OAAA;AACT,oGAAA,SAAS,OAAA;AACT,mGAAA,QAAQ,OAAA;AACR,wGAAA,aAAa,OAAA;AACb,wGAAA,aAAa,OAAA;AAMf,6CAAiH;AAAxG,kHAAA,mBAAmB,OAAA;AAAE,yGAAA,UAAU,OAAA;AAAE,4GAAA,aAAa,OAAA;AAAE,2GAAA,YAAY,OAAA"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * One installed (or mapped) platform migration in the app's `platform.lock`.
3
+ *
4
+ * @stability experimental
5
+ */
6
+ export interface LockEntry {
7
+ /** `platform:` plus the package directory, for example `platform:0001_initial`. */
8
+ originId: string;
9
+ /** The app's directory name under `prisma/migrations`; it may differ from the package slug. */
10
+ localDir: string;
11
+ /** SHA-256 of the package file's bytes; equals Prisma's `_prisma_migrations.checksum` for a byte copy. */
12
+ sha256: string;
13
+ /** The platform version that introduced the migration for this app. */
14
+ since: string;
15
+ /** SHA-256 of the app's file, present only for a recorded comment-only divergence. */
16
+ localSha256?: string;
17
+ /** Why the app's file differs from the package's; present with `localSha256`. */
18
+ note?: string;
19
+ }
20
+ /**
21
+ * The app's declared alteration of a package-owned table (read by the baseline tooling).
22
+ *
23
+ * @stability experimental
24
+ */
25
+ export interface LockDeviation {
26
+ /** Stable id, `<app>:<name>`. */
27
+ id: string;
28
+ /** Why the app alters a package-owned table. */
29
+ reason: string;
30
+ /** The normalised statements `prisma migrate diff` is expected to print for it. */
31
+ expectDiff: string[];
32
+ }
33
+ /**
34
+ * A raw-SQL index the app owns, asserted by the drift test against `pg_indexes`.
35
+ *
36
+ * @stability experimental
37
+ */
38
+ export interface RawSqlIndex {
39
+ /** The index name. */
40
+ name: string;
41
+ /** `pg_indexes.indexdef` of the index. */
42
+ definition: string;
43
+ }
44
+ /**
45
+ * The contents of `prisma/platform.lock`: proof that the app's installed
46
+ * migrations are byte-identical to the package's.
47
+ *
48
+ * @stability experimental
49
+ */
50
+ export interface PlatformLock {
51
+ /** The lock format version; a reader refuses a higher value. */
52
+ lockVersion: 1;
53
+ /** The package version the history was last synced to. */
54
+ platformVersion: string;
55
+ /** One entry per installed or mapped package migration, in package order. */
56
+ migrations: LockEntry[];
57
+ /** Declared alterations of package-owned tables. */
58
+ deviations?: LockDeviation[];
59
+ /** The app's own raw-SQL indexes. */
60
+ rawSqlIndexes?: RawSqlIndex[];
61
+ }
62
+ /**
63
+ * A lock file that failed validation, with the offending path.
64
+ *
65
+ * @stability experimental
66
+ */
67
+ export declare class LockFormatError extends Error {
68
+ /** @param message - What is wrong with the file. */
69
+ constructor(message: string);
70
+ }
71
+ /**
72
+ * Parses and validates the text of a `platform.lock`.
73
+ *
74
+ * @param text - The file contents.
75
+ * @param source - A label for error messages (usually the path).
76
+ * @returns The validated lock.
77
+ * @throws LockFormatError when the JSON is invalid or does not match the schema, or the lock version is newer than this release reads.
78
+ * @stability experimental
79
+ */
80
+ export declare function parseLock(text: string, source?: string): PlatformLock;
81
+ /**
82
+ * Reads and validates a `platform.lock`.
83
+ *
84
+ * @param file - Path of the lock file.
85
+ * @returns The validated lock.
86
+ * @throws LockFormatError when the file is invalid (see {@link parseLock}).
87
+ * @stability experimental
88
+ */
89
+ export declare function readLock(file: string): PlatformLock;
90
+ /**
91
+ * An empty lock for an app that has installed nothing.
92
+ *
93
+ * @param platformVersion - The package version, default `0.0.0`.
94
+ * @returns A lock with no migrations.
95
+ * @stability experimental
96
+ */
97
+ export declare function emptyLock(platformVersion?: string): PlatformLock;
98
+ /**
99
+ * Serialises a lock (or any manifest-shaped JSON) deterministically: keys
100
+ * sorted at every level, arrays in their given order, two-space indent, one
101
+ * trailing newline. The same input always produces the same bytes, so diffs
102
+ * stay stable.
103
+ *
104
+ * @param value - The lock, or any JSON value.
105
+ * @returns The file contents.
106
+ * @stability experimental
107
+ */
108
+ export declare function serializeJson(value: unknown): string;
109
+ /**
110
+ * Serialises a lock for writing to `platform.lock`.
111
+ *
112
+ * @param lock - The lock.
113
+ * @returns The file contents (see {@link serializeJson}).
114
+ * @stability experimental
115
+ */
116
+ export declare function serializeLock(lock: PlatformLock): string;
117
+ //# sourceMappingURL=lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../src/lock/lock.ts"],"names":[],"mappings":"AAwCA;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,WAAW,EAAE,CAAC,CAAC;IACf,0DAA0D;IAC1D,eAAe,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,oDAAoD;IACpD,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,qCAAqC;IACrC,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC;CAC/B;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,oDAAoD;gBACxC,OA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