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

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 (244) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/LICENSE +21 -0
  3. package/README.md +525 -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 +66 -0
  8. package/dist/baseline/deps.js.map +1 -0
  9. package/dist/baseline/errors.d.ts +36 -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 +127 -0
  34. package/dist/baseline/report.d.ts.map +1 -0
  35. package/dist/baseline/report.js +89 -0
  36. package/dist/baseline/report.js.map +1 -0
  37. package/dist/baseline/run.d.ts +117 -0
  38. package/dist/baseline/run.d.ts.map +1 -0
  39. package/dist/baseline/run.js +358 -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 +311 -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/app-objects.d.ts +107 -0
  78. package/dist/drift/app-objects.d.ts.map +1 -0
  79. package/dist/drift/app-objects.js +193 -0
  80. package/dist/drift/app-objects.js.map +1 -0
  81. package/dist/drift/db-conformance.d.ts +52 -0
  82. package/dist/drift/db-conformance.d.ts.map +1 -0
  83. package/dist/drift/db-conformance.js +89 -0
  84. package/dist/drift/db-conformance.js.map +1 -0
  85. package/dist/drift/index.d.ts +8 -0
  86. package/dist/drift/index.d.ts.map +1 -0
  87. package/dist/drift/index.js +43 -0
  88. package/dist/drift/index.js.map +1 -0
  89. package/dist/drift/raw-sql-indexes.d.ts +106 -0
  90. package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
  91. package/dist/drift/raw-sql-indexes.js +113 -0
  92. package/dist/drift/raw-sql-indexes.js.map +1 -0
  93. package/dist/drift/raw-sql-tripwire.d.ts +191 -0
  94. package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
  95. package/dist/drift/raw-sql-tripwire.js +422 -0
  96. package/dist/drift/raw-sql-tripwire.js.map +1 -0
  97. package/dist/drift/rls-policies.d.ts +226 -0
  98. package/dist/drift/rls-policies.d.ts.map +1 -0
  99. package/dist/drift/rls-policies.js +317 -0
  100. package/dist/drift/rls-policies.js.map +1 -0
  101. package/dist/drift/run.d.ts +152 -0
  102. package/dist/drift/run.d.ts.map +1 -0
  103. package/dist/drift/run.js +252 -0
  104. package/dist/drift/run.js.map +1 -0
  105. package/dist/drift/sql-expression.d.ts +27 -0
  106. package/dist/drift/sql-expression.d.ts.map +1 -0
  107. package/dist/drift/sql-expression.js +64 -0
  108. package/dist/drift/sql-expression.js.map +1 -0
  109. package/dist/index.d.ts +16 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +33 -0
  112. package/dist/index.js.map +1 -0
  113. package/dist/lock/hash.d.ts +13 -0
  114. package/dist/lock/hash.d.ts.map +1 -0
  115. package/dist/lock/hash.js +19 -0
  116. package/dist/lock/hash.js.map +1 -0
  117. package/dist/lock/index.d.ts +5 -0
  118. package/dist/lock/index.d.ts.map +1 -0
  119. package/dist/lock/index.js +20 -0
  120. package/dist/lock/index.js.map +1 -0
  121. package/dist/lock/lock.d.ts +154 -0
  122. package/dist/lock/lock.d.ts.map +1 -0
  123. package/dist/lock/lock.js +151 -0
  124. package/dist/lock/lock.js.map +1 -0
  125. package/dist/lock/manifest.d.ts +68 -0
  126. package/dist/lock/manifest.d.ts.map +1 -0
  127. package/dist/lock/manifest.js +96 -0
  128. package/dist/lock/manifest.js.map +1 -0
  129. package/dist/lock/semver.d.ts +10 -0
  130. package/dist/lock/semver.d.ts.map +1 -0
  131. package/dist/lock/semver.js +13 -0
  132. package/dist/lock/semver.js.map +1 -0
  133. package/dist/seed/index.d.ts +5 -0
  134. package/dist/seed/index.d.ts.map +1 -0
  135. package/dist/seed/index.js +16 -0
  136. package/dist/seed/index.js.map +1 -0
  137. package/dist/seed/input.d.ts +52 -0
  138. package/dist/seed/input.d.ts.map +1 -0
  139. package/dist/seed/input.js +77 -0
  140. package/dist/seed/input.js.map +1 -0
  141. package/dist/seed/seed-platform.d.ts +41 -0
  142. package/dist/seed/seed-platform.d.ts.map +1 -0
  143. package/dist/seed/seed-platform.js +165 -0
  144. package/dist/seed/seed-platform.js.map +1 -0
  145. package/dist/seed/steps.d.ts +172 -0
  146. package/dist/seed/steps.d.ts.map +1 -0
  147. package/dist/seed/steps.js +136 -0
  148. package/dist/seed/steps.js.map +1 -0
  149. package/dist/seed/types.d.ts +287 -0
  150. package/dist/seed/types.d.ts.map +1 -0
  151. package/dist/seed/types.js +5 -0
  152. package/dist/seed/types.js.map +1 -0
  153. package/dist/sync/app-migrations.d.ts +52 -0
  154. package/dist/sync/app-migrations.d.ts.map +1 -0
  155. package/dist/sync/app-migrations.js +62 -0
  156. package/dist/sync/app-migrations.js.map +1 -0
  157. package/dist/sync/apply.d.ts +29 -0
  158. package/dist/sync/apply.d.ts.map +1 -0
  159. package/dist/sync/apply.js +38 -0
  160. package/dist/sync/apply.js.map +1 -0
  161. package/dist/sync/check.d.ts +59 -0
  162. package/dist/sync/check.d.ts.map +1 -0
  163. package/dist/sync/check.js +115 -0
  164. package/dist/sync/check.js.map +1 -0
  165. package/dist/sync/errors.d.ts +32 -0
  166. package/dist/sync/errors.d.ts.map +1 -0
  167. package/dist/sync/errors.js +23 -0
  168. package/dist/sync/errors.js.map +1 -0
  169. package/dist/sync/index.d.ts +10 -0
  170. package/dist/sync/index.d.ts.map +1 -0
  171. package/dist/sync/index.js +27 -0
  172. package/dist/sync/index.js.map +1 -0
  173. package/dist/sync/ledger.d.ts +65 -0
  174. package/dist/sync/ledger.d.ts.map +1 -0
  175. package/dist/sync/ledger.js +49 -0
  176. package/dist/sync/ledger.js.map +1 -0
  177. package/dist/sync/plan.d.ts +63 -0
  178. package/dist/sync/plan.d.ts.map +1 -0
  179. package/dist/sync/plan.js +86 -0
  180. package/dist/sync/plan.js.map +1 -0
  181. package/dist/sync/promote.d.ts +62 -0
  182. package/dist/sync/promote.d.ts.map +1 -0
  183. package/dist/sync/promote.js +95 -0
  184. package/dist/sync/promote.js.map +1 -0
  185. package/dist/sync/timestamps.d.ts +41 -0
  186. package/dist/sync/timestamps.d.ts.map +1 -0
  187. package/dist/sync/timestamps.js +68 -0
  188. package/dist/sync/timestamps.js.map +1 -0
  189. package/dist/sync/version.d.ts +28 -0
  190. package/dist/sync/version.d.ts.map +1 -0
  191. package/dist/sync/version.js +66 -0
  192. package/dist/sync/version.js.map +1 -0
  193. package/migrations/0001_initial/migration.sql +297 -0
  194. package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
  195. package/migrations/0003_add_credentials/migration.sql +20 -0
  196. package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
  197. package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
  198. package/migrations/0006_add_notifications/migration.sql +22 -0
  199. package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
  200. package/migrations/0008_add_jobs/migration.sql +110 -0
  201. package/migrations/0009_add_worker_nodes/migration.sql +90 -0
  202. package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
  203. package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
  204. package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
  205. package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
  206. package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
  207. package/migrations/0015_add_job_claim_token/migration.sql +92 -0
  208. package/migrations/0016_add_ai_platform/migration.sql +108 -0
  209. package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
  210. package/migrations/0018_add_user_credentials/migration.sql +29 -0
  211. package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
  212. package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
  213. package/migrations/0021_add_job_trace_context/migration.sql +6 -0
  214. package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
  215. package/migrations/0023_add_organizations/migration.sql +142 -0
  216. package/migrations/0024_split_system_org_roles/migration.sql +131 -0
  217. package/migrations/0025_org_scoped_rls/migration.sql +215 -0
  218. package/migrations/0026_add_groups/migration.sql +165 -0
  219. package/migrations/0027_add_grants/migration.sql +117 -0
  220. package/migrations/0028_add_org_settings/migration.sql +49 -0
  221. package/migrations/0029_add_org_credentials/migration.sql +54 -0
  222. package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
  223. package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
  224. package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
  225. package/migrations/0033_add_android_app/migration.sql +60 -0
  226. package/migrations/0034_open_job_reason/migration.sql +16 -0
  227. package/migrations/0035_ai_usage_feature/migration.sql +37 -0
  228. package/migrations/0036_add_app_metadata/migration.sql +49 -0
  229. package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
  230. package/migrations/manifest.json +379 -0
  231. package/package.json +78 -4
  232. package/raw-sql-indexes.json +94 -0
  233. package/rls-policies.json +74 -0
  234. package/schema/ai.prisma +444 -0
  235. package/schema/android-app.prisma +47 -0
  236. package/schema/base.prisma +11 -0
  237. package/schema/credentials.prisma +170 -0
  238. package/schema/db-backup.prisma +376 -0
  239. package/schema/identity.prisma +439 -0
  240. package/schema/jobs.prisma +760 -0
  241. package/schema/notifications.prisma +649 -0
  242. package/schema/settings.prisma +60 -0
  243. package/schema/sharing.prisma +223 -0
  244. package/schema/storage.prisma +84 -0
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ // The filesystem-facing API of the composer: load fragments, write or check
3
+ // the generated folder. The pure composition is in ./compose.ts.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.composeSchema = composeSchema;
6
+ exports.writeComposedSchema = writeComposedSchema;
7
+ exports.checkComposedSchema = checkComposedSchema;
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = require("node:path");
10
+ const compose_js_1 = require("./compose.js");
11
+ const diff_js_1 = require("./diff.js");
12
+ /** The `schema/` folder shipped in this package (`src/compose` and `dist/compose` are both two levels below the package root). */
13
+ const PACKAGE_SCHEMA_DIR = (0, node_path_1.resolve)(__dirname, '..', '..', 'schema');
14
+ function load(dir, origin) {
15
+ if (!(0, node_fs_1.existsSync)(dir)) {
16
+ if (origin === 'package')
17
+ throw new Error(`platform schema folder not found: ${dir}`);
18
+ return [];
19
+ }
20
+ return (0, node_fs_1.readdirSync)(dir, { withFileTypes: true })
21
+ .filter((e) => e.isFile() && e.name.endsWith('.prisma'))
22
+ .map((e) => ({ origin, name: e.name, path: (0, node_path_1.join)(dir, e.name), text: (0, node_fs_1.readFileSync)((0, node_path_1.join)(dir, e.name), 'utf8') }));
23
+ }
24
+ /**
25
+ * Composes the platform fragments and the app's fragments into the generated
26
+ * schema files. Reads the fragment folders; writes nothing.
27
+ *
28
+ * @param opts - Folders to read and the output folder to name.
29
+ * @returns The files that belong in `outDir` and any warnings.
30
+ * @throws `ComposeError` when a fragment breaks a rule (see the rule table in the database ADR).
31
+ * @stability experimental
32
+ */
33
+ function composeSchema(opts) {
34
+ const inputs = [
35
+ ...load(opts.platformSchemaDir ?? PACKAGE_SCHEMA_DIR, 'package'),
36
+ ...load(opts.appFragmentsDir, 'app'),
37
+ ];
38
+ const { files, warnings } = (0, compose_js_1.composeFragments)(inputs);
39
+ return {
40
+ files: [...files].map(([name, contents]) => ({ path: (0, node_path_1.join)(opts.outDir, name), contents })),
41
+ warnings,
42
+ };
43
+ }
44
+ /**
45
+ * Composes and writes the generated folder: creates it if missing, replaces
46
+ * changed files and deletes `*.prisma` files that no fragment produces any
47
+ * more. Other files in the folder are left alone.
48
+ *
49
+ * @param opts - Folders to read and the folder to write.
50
+ * @returns What was written.
51
+ * @throws `ComposeError` when a fragment breaks a rule; nothing is written then.
52
+ * @stability experimental
53
+ */
54
+ function writeComposedSchema(opts) {
55
+ const result = composeSchema(opts);
56
+ (0, node_fs_1.mkdirSync)(opts.outDir, { recursive: true });
57
+ const keep = new Set(result.files.map((f) => f.path));
58
+ for (const name of (0, node_fs_1.readdirSync)(opts.outDir)) {
59
+ const path = (0, node_path_1.join)(opts.outDir, name);
60
+ if (name.endsWith('.prisma') && !keep.has(path))
61
+ (0, node_fs_1.rmSync)(path);
62
+ }
63
+ for (const f of result.files) {
64
+ if (!(0, node_fs_1.existsSync)(f.path) || (0, node_fs_1.readFileSync)(f.path, 'utf8') !== f.contents)
65
+ (0, node_fs_1.writeFileSync)(f.path, f.contents);
66
+ }
67
+ return result;
68
+ }
69
+ /**
70
+ * Compares the generated folder with a fresh composition without writing
71
+ * anything (the `--check` mode CI runs, like `openapi:dump` plus a diff).
72
+ * Line endings are ignored so a Windows checkout with CRLF still passes.
73
+ *
74
+ * @param opts - Folders to read and the generated folder to compare.
75
+ * @returns Whether the folder is current, and what differs when it is not.
76
+ * @throws `ComposeError` when a fragment breaks a rule.
77
+ * @stability experimental
78
+ */
79
+ function checkComposedSchema(opts) {
80
+ const { files } = composeSchema(opts);
81
+ const parts = [];
82
+ const expected = new Set(files.map((f) => f.path));
83
+ for (const f of files) {
84
+ if (!(0, node_fs_1.existsSync)(f.path)) {
85
+ parts.push(`missing: ${f.path}`);
86
+ continue;
87
+ }
88
+ const onDisk = (0, node_fs_1.readFileSync)(f.path, 'utf8').replace(/\r\n/g, '\n');
89
+ if (onDisk !== f.contents)
90
+ parts.push(`changed: ${f.path}\n${(0, diff_js_1.lineDiff)(onDisk, f.contents)}`);
91
+ }
92
+ if ((0, node_fs_1.existsSync)(opts.outDir)) {
93
+ for (const name of (0, node_fs_1.readdirSync)(opts.outDir).sort()) {
94
+ const path = (0, node_path_1.join)(opts.outDir, name);
95
+ if (name.endsWith('.prisma') && !expected.has(path))
96
+ parts.push(`stale (no fragment produces it): ${path}`);
97
+ }
98
+ }
99
+ return { upToDate: parts.length === 0, diff: parts.join('\n') };
100
+ }
101
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/compose/api.ts"],"names":[],"mappings":";AAAA,4EAA4E;AAC5E,iEAAiE;;AAqFjE,sCAUC;AAYD,kDAYC;AAYD,kDAmBC;AApJD,qCAAkG;AAClG,yCAA0C;AAE1C,6CAAoE;AACpE,uCAAqC;AAyDrC,kIAAkI;AAClI,MAAM,kBAAkB,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AAEpE,SAAS,IAAI,CAAC,GAAW,EAAE,MAAyB;IAClD,IAAI,CAAC,IAAA,oBAAU,EAAC,GAAG,CAAC,EAAE,CAAC;QACrB,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;QACtF,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,IAAA,qBAAW,EAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAC7C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;SACvD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC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AM,KAAK,CAAC,CAAC,QAAQ;YAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,KAAK,IAAA,kBAAQ,EAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,IAAA,oBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,IAAA,qBAAW,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACnD,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC;QAC9G,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,51 @@
1
+ /** First line of every generated file. */
2
+ export declare const GENERATED_HEADER = "// GENERATED by platform db compose \u2014 do not edit";
3
+ /**
4
+ * One fragment handed to {@link composeFragments}.
5
+ *
6
+ * @internal
7
+ */
8
+ export interface FragmentInput {
9
+ /** Origin: the package ships it, or the app owns it. */
10
+ origin: 'package' | 'app';
11
+ /** File name inside its directory, for example `identity.prisma`. */
12
+ name: string;
13
+ /** File contents. */
14
+ text: string;
15
+ /** Path to name in errors (default: `<origin>:<name>`). */
16
+ path?: string;
17
+ }
18
+ /**
19
+ * What a pure composition produced.
20
+ *
21
+ * @internal
22
+ */
23
+ export interface FragmentComposition {
24
+ /** Generated files by name (`platform.identity.prisma`, `app.workouts.prisma`). */
25
+ files: Map<string, string>;
26
+ /** Models the package owners marked `// @extensible`, sorted. */
27
+ extensible: string[];
28
+ /** One entry per merged back-relation field. */
29
+ extensions: Array<{
30
+ model: string;
31
+ field: string;
32
+ from: string;
33
+ }>;
34
+ /** Non-fatal observations. */
35
+ warnings: string[];
36
+ }
37
+ /**
38
+ * Composes fragments held in memory. Package fragments load first, then app
39
+ * fragments, each alphabetically; an app fragment named `base.prisma`
40
+ * replaces the package's. `extend model` blocks are merged into their target
41
+ * before its first `@@` line, under a `// composed from <origin>:<file>`
42
+ * comment. The composer generates nothing of its own: a back-relation is
43
+ * always written by the slice that owns the foreign key.
44
+ *
45
+ * @param inputs - The fragments, in any order.
46
+ * @returns The generated files and what was merged.
47
+ * @throws {@link ComposeError} for every rule of the ADR's rejection table.
48
+ * @internal
49
+ */
50
+ export declare function composeFragments(inputs: readonly FragmentInput[]): FragmentComposition;
51
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/compose/compose.ts"],"names":[],"mappings":"AAOA,0CAA0C;AAC1C,eAAO,MAAM,gBAAgB,2DAAsD,CAAC;AAEpF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,iEAAiE;IACjE,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gDAAgD;IAChD,UAAU,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,mBAAmB,CA6KtF"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ // The composer behind `platform db compose` (docs/adr/0002 D2). Plain TypeScript,
3
+ // no Prisma dependency: it must run in CI and in a Docker build stage before
4
+ // `prisma generate` exists.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GENERATED_HEADER = void 0;
7
+ exports.composeFragments = composeFragments;
8
+ const errors_js_1 = require("./errors.js");
9
+ const parse_js_1 = require("./parse.js");
10
+ /** First line of every generated file. */
11
+ exports.GENERATED_HEADER = '// GENERATED by platform db compose — do not edit';
12
+ const SCALARS = new Set(['String', 'Int', 'BigInt', 'Float', 'Decimal', 'Boolean', 'DateTime', 'Json', 'Bytes', 'Unsupported']);
13
+ /** Code-unit order: identical on every machine and locale. */
14
+ function byName(a, b) {
15
+ return a < b ? -1 : a > b ? 1 : 0;
16
+ }
17
+ const labelOf = (i) => `${i.origin}:${i.name}`;
18
+ const pathOf = (i) => i.path ?? labelOf(i);
19
+ /**
20
+ * Composes fragments held in memory. Package fragments load first, then app
21
+ * fragments, each alphabetically; an app fragment named `base.prisma`
22
+ * replaces the package's. `extend model` blocks are merged into their target
23
+ * before its first `@@` line, under a `// composed from <origin>:<file>`
24
+ * comment. The composer generates nothing of its own: a back-relation is
25
+ * always written by the slice that owns the foreign key.
26
+ *
27
+ * @param inputs - The fragments, in any order.
28
+ * @returns The generated files and what was merged.
29
+ * @throws {@link ComposeError} for every rule of the ADR's rejection table.
30
+ * @internal
31
+ */
32
+ function composeFragments(inputs) {
33
+ const warnings = [];
34
+ const sorted = [...inputs].sort((a, b) => a.origin === b.origin ? byName(a.name, b.name) : a.origin === 'package' ? -1 : 1);
35
+ const parsed = sorted.map((input) => ({ input, ...(0, parse_js_1.parseBlocks)(input.text, pathOf(input)) }));
36
+ const appBase = parsed.find((p) => p.input.origin === 'app' && p.input.name === 'base.prisma');
37
+ if (appBase && parsed.some((p) => p.input.origin === 'package' && p.input.name === 'base.prisma')) {
38
+ warnings.push(`${pathOf(appBase.input)} replaces the package's base.prisma: the generator and datasource blocks are now yours to keep current`);
39
+ }
40
+ const live = appBase
41
+ ? parsed.filter((p) => !(p.input.origin === 'package' && p.input.name === 'base.prisma'))
42
+ : parsed;
43
+ // 1. Declarations.
44
+ const declared = new Map();
45
+ for (const { input, blocks } of live) {
46
+ for (const b of blocks) {
47
+ if (b.extend)
48
+ continue;
49
+ // Prisma allows one datasource and many uniquely named generators.
50
+ const key = b.kind === 'datasource' ? 'datasource' : b.kind === 'generator' ? `generator:${b.name}` : b.name;
51
+ const prev = declared.get(key);
52
+ if (prev) {
53
+ const here = `${pathOf(input)}:${b.line}`;
54
+ const there = `${prev.file}:${prev.block.line}`;
55
+ if (b.kind === 'generator' || b.kind === 'datasource') {
56
+ throw new errors_js_1.ComposeError('DUPLICATE_BASE', pathOf(input), b.line, `${b.kind} "${b.name}" is already declared at ${there}; an app replaces the package's generator and datasource by providing its own base.prisma, never a second block`);
57
+ }
58
+ throw new errors_js_1.ComposeError('DUPLICATE_MODEL', pathOf(input), b.line, `${b.kind} "${b.name}" is already declared at ${there} (again at ${here}); to add back-relations to a model another fragment owns, write "extend model ${b.name} { ... }"`);
59
+ }
60
+ declared.set(key, { block: b, file: pathOf(input) });
61
+ }
62
+ }
63
+ if (![...declared.keys()].some((k) => k === 'datasource')) {
64
+ warnings.push('no datasource block is declared by any fragment; prisma will refuse the composed schema');
65
+ }
66
+ // 2. Extensions.
67
+ const modelNames = new Set();
68
+ const enumNames = new Set();
69
+ for (const { block } of declared.values()) {
70
+ if (block.kind === 'model')
71
+ modelNames.add(block.name);
72
+ if (block.kind === 'enum')
73
+ enumNames.add(block.name);
74
+ }
75
+ const fieldOwner = new Map();
76
+ for (const { block, file } of declared.values()) {
77
+ if (block.kind !== 'model')
78
+ continue;
79
+ for (const f of (0, parse_js_1.parseBody)(block, file).fields)
80
+ fieldOwner.set(`${block.name}.${f.name}`, `declared at ${file}:${f.line}`);
81
+ }
82
+ const added = new Map();
83
+ const extensions = [];
84
+ for (const { input, blocks } of live) {
85
+ const file = pathOf(input);
86
+ for (const b of blocks) {
87
+ if (!b.extend)
88
+ continue;
89
+ if (b.kind !== 'model') {
90
+ throw new errors_js_1.ComposeError('MALFORMED', file, b.line, `only "extend model" is supported, got "extend ${b.kind} ${b.name}"`);
91
+ }
92
+ const target = declared.get(b.name);
93
+ if (!target || target.block.kind !== 'model') {
94
+ throw new errors_js_1.ComposeError('UNKNOWN_MODEL', file, b.line, `extend model ${b.name}: no fragment declares a model named ${b.name}`);
95
+ }
96
+ if (!(0, parse_js_1.isExtensible)(target.block)) {
97
+ throw new errors_js_1.ComposeError('NOT_EXTENSIBLE', file, b.line, `extend model ${b.name}: ${b.name} (declared at ${target.file}:${target.block.line}) is not marked "// @extensible" by its owner; request a seam from the package instead of editing it`);
98
+ }
99
+ const { fields, attrs } = (0, parse_js_1.parseBody)(b, file);
100
+ const attr = attrs[0];
101
+ if (attr) {
102
+ throw new errors_js_1.ComposeError('EXTEND_BLOCK_ATTRIBUTE', file, attr.line, `extend model ${b.name} may not carry block attributes (${attr.raw.trim()}); they would alter the package's table`);
103
+ }
104
+ for (const f of fields) {
105
+ if (!modelNames.has(f.type)) {
106
+ const scalar = SCALARS.has(f.type) || enumNames.has(f.type);
107
+ throw new errors_js_1.ComposeError(scalar ? 'EXTEND_SCALAR_FIELD' : 'EXTEND_UNKNOWN_TYPE', file, f.line, scalar
108
+ ? `extend model ${b.name}: field "${f.name}" has type ${f.type}; an extend block may only add back-relation fields (a new column is a declared deviation in platform.lock, not an extension)`
109
+ : `extend model ${b.name}: field "${f.name}" has type ${f.type}, which no fragment declares as a model`);
110
+ }
111
+ if (/fields:\s*\[/.test(f.attrs)) {
112
+ throw new errors_js_1.ComposeError('EXTEND_OWNING_RELATION', file, f.line, `extend model ${b.name}: field "${f.name}" is the owning side of a relation (fields: [...]); it would add a foreign key column to the package's table`);
113
+ }
114
+ const key = `${b.name}.${f.name}`;
115
+ const prior = fieldOwner.get(key);
116
+ if (prior) {
117
+ throw new errors_js_1.ComposeError('FIELD_COLLISION', file, f.line, `extend model ${b.name}: field "${f.name}" already exists on ${b.name} (${prior})`);
118
+ }
119
+ fieldOwner.set(key, `added at ${file}:${f.line}`);
120
+ extensions.push({ model: b.name, field: f.name, from: labelOf(input) });
121
+ }
122
+ // The block's own comment and field lines travel verbatim, together with
123
+ // the comment run directly above the block.
124
+ const above = [];
125
+ const leading = b.leading.split('\n');
126
+ for (let i = leading.length - 1; i >= 0; i--) {
127
+ const t = leading[i].trim();
128
+ if (t === '' || !t.startsWith('//'))
129
+ break;
130
+ above.unshift(` ${t}`);
131
+ }
132
+ const body = b.lines.slice(1, -1);
133
+ while (body.length && body[0].trim() === '')
134
+ body.shift();
135
+ while (body.length && body[body.length - 1].trim() === '')
136
+ body.pop();
137
+ const list = added.get(b.name) ?? [];
138
+ list.push({ source: labelOf(input), lines: [...above, ...body] });
139
+ added.set(b.name, list);
140
+ }
141
+ }
142
+ // 3. Output: one file per fragment that declares anything.
143
+ const files = new Map();
144
+ for (const { input, blocks, trailing } of live) {
145
+ const out = [];
146
+ for (const b of blocks) {
147
+ if (b.extend)
148
+ continue;
149
+ const copy = { leading: b.leading, lines: [...b.lines] };
150
+ const ext = b.kind === 'model' ? added.get(b.name) : undefined;
151
+ if (ext) {
152
+ const attrIdx = copy.lines.findIndex((l, i) => i > 0 && l.trim().startsWith('@@'));
153
+ const at = attrIdx === -1 ? copy.lines.length - 1 : attrIdx;
154
+ const insert = [];
155
+ for (const e of ext)
156
+ insert.push('', ` // composed from ${e.source}`, ...e.lines);
157
+ if (attrIdx !== -1)
158
+ insert.push('');
159
+ copy.lines.splice(at, 0, ...insert);
160
+ copy.lines = copy.lines.filter((l, i, a) => !(l.trim() === '' && i > 0 && a[i - 1].trim() === ''));
161
+ }
162
+ out.push((0, parse_js_1.renderBlock)(copy));
163
+ }
164
+ if (!out.length)
165
+ continue; // a fragment of pure `extend` blocks has no output file of its own
166
+ if (trailing.trim() !== '')
167
+ out.push(trailing.replace(/^\n+|\n+$/g, ''));
168
+ const body = out.join('\n\n').replace(/\n{3,}/g, '\n\n').replace(/^\n+/, '');
169
+ files.set(`${input.origin === 'package' ? 'platform' : 'app'}.${input.name}`, `${exports.GENERATED_HEADER}\n// source: ${labelOf(input)}\n\n${body}\n`);
170
+ }
171
+ const extensible = [...declared.values()]
172
+ .filter((d) => d.block.kind === 'model' && (0, parse_js_1.isExtensible)(d.block))
173
+ .map((d) => d.block.name)
174
+ .sort(byName);
175
+ return { files, extensible, extensions, warnings };
176
+ }
177
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/compose/compose.ts"],"names":[],"mappings":";AAAA,kFAAkF;AAClF,6EAA6E;AAC7E,4BAA4B;;;AAqE5B,4CA6KC;AAhPD,2CAA2C;AAC3C,yCAA2F;AAE3F,0CAA0C;AAC7B,QAAA,gBAAgB,GAAG,mDAAmD,CAAC;AAkCpF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;AAEhI,8DAA8D;AAC9D,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,OAAO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*/
6
+ export declare function lineDiff(actual: string, expected: string, context?: number): string;
7
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/compose/diff.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CA8C9E"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // A tiny line diff for the `--check` report: shared prefix and suffix are
3
+ // trimmed, the middle is compared with a longest-common-subsequence table.
4
+ // Generated files are a few hundred lines and a stale file differs in one
5
+ // place, so this never gets large.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.lineDiff = lineDiff;
8
+ /**
9
+ * Unified-style listing (`-` on disk, `+` expected) with up to two lines of context.
10
+ *
11
+ * @internal
12
+ */
13
+ function lineDiff(actual, expected, context = 2) {
14
+ const a = actual.split('\n');
15
+ const b = expected.split('\n');
16
+ let start = 0;
17
+ while (start < a.length && start < b.length && a[start] === b[start])
18
+ start++;
19
+ let endA = a.length;
20
+ let endB = b.length;
21
+ while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
22
+ endA--;
23
+ endB--;
24
+ }
25
+ const midA = a.slice(start, endA);
26
+ const midB = b.slice(start, endB);
27
+ const out = [];
28
+ for (const line of a.slice(Math.max(0, start - context), start))
29
+ out.push(` ${line}`);
30
+ if (midA.length * midB.length > 4_000_000) {
31
+ for (const line of midA)
32
+ out.push(`- ${line}`);
33
+ for (const line of midB)
34
+ out.push(`+ ${line}`);
35
+ }
36
+ else {
37
+ const lcs = Array.from({ length: midA.length + 1 }, () => new Array(midB.length + 1).fill(0));
38
+ for (let i = midA.length - 1; i >= 0; i--) {
39
+ for (let j = midB.length - 1; j >= 0; j--) {
40
+ lcs[i][j] =
41
+ midA[i] === midB[j]
42
+ ? lcs[i + 1][j + 1] + 1
43
+ : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
44
+ }
45
+ }
46
+ let i = 0;
47
+ let j = 0;
48
+ while (i < midA.length || j < midB.length) {
49
+ if (i < midA.length && j < midB.length && midA[i] === midB[j]) {
50
+ out.push(` ${midA[i]}`);
51
+ i++;
52
+ j++;
53
+ }
54
+ else if (j < midB.length && (i === midA.length || lcs[i][j + 1] >= lcs[i + 1][j])) {
55
+ out.push(`+ ${midB[j]}`);
56
+ j++;
57
+ }
58
+ else {
59
+ out.push(`- ${midA[i]}`);
60
+ i++;
61
+ }
62
+ }
63
+ }
64
+ for (const line of a.slice(endA, endA + context))
65
+ out.push(` ${line}`);
66
+ return out.join('\n');
67
+ }
68
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/compose/diff.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,mCAAmC;;AAOnC,4BA8CC;AAnDD;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAO,GAAG,CAAC;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,CAAC,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,CAAC;IAC9E,IAAI,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACpB,IAAI,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACpB,OAAO,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KA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C,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACzB,CAAC,EAAE,CAAC;YACN,CAAC;QACH,CAAC;IACH,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;QAAE,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Stable code of a composer rejection. Every code is listed in the rule table
3
+ * of the database ADR (docs/adr/0002-database-packaging-and-rls.md, D2).
4
+ *
5
+ * @stability experimental
6
+ */
7
+ export type ComposeErrorCode = 'NOT_EXTENSIBLE' | 'UNKNOWN_MODEL' | 'FIELD_COLLISION' | 'EXTEND_SCALAR_FIELD' | 'EXTEND_OWNING_RELATION' | 'EXTEND_BLOCK_ATTRIBUTE' | 'EXTEND_UNKNOWN_TYPE' | 'DUPLICATE_MODEL' | 'DUPLICATE_BASE' | 'MALFORMED';
8
+ /**
9
+ * A rejected fragment. The message always starts with `file:line: CODE:` so an
10
+ * editor or a CI annotation can jump to the offending line.
11
+ *
12
+ * @stability experimental
13
+ */
14
+ export declare class ComposeError extends Error {
15
+ /** The stable rule code (for example `NOT_EXTENSIBLE`). */
16
+ readonly code: ComposeErrorCode;
17
+ /** The fragment file the problem is in, as the caller supplied its path. */
18
+ readonly file: string;
19
+ /** 1-based line of the offending block header or field. */
20
+ readonly line: number;
21
+ /** The explanation without the `file:line: CODE:` prefix. */
22
+ readonly detail: string;
23
+ /**
24
+ * @param code - The rule that was broken.
25
+ * @param file - The fragment file.
26
+ * @param line - 1-based line in that file.
27
+ * @param detail - What is wrong and how to fix it.
28
+ */
29
+ constructor(code: ComposeErrorCode, file: string, line: number, detail: string);
30
+ }
31
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/compose/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,eAAe,GACf,iBAAiB,GACjB,qBAAqB,GACrB,wBAAwB,GACxB,wBAAwB,GACxB,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,WAAW,CAAC;AAEhB;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;OAKG;gBACS,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ/E"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComposeError = void 0;
4
+ /**
5
+ * A rejected fragment. The message always starts with `file:line: CODE:` so an
6
+ * editor or a CI annotation can jump to the offending line.
7
+ *
8
+ * @stability experimental
9
+ */
10
+ class ComposeError extends Error {
11
+ /** The stable rule code (for example `NOT_EXTENSIBLE`). */
12
+ code;
13
+ /** The fragment file the problem is in, as the caller supplied its path. */
14
+ file;
15
+ /** 1-based line of the offending block header or field. */
16
+ line;
17
+ /** The explanation without the `file:line: CODE:` prefix. */
18
+ detail;
19
+ /**
20
+ * @param code - The rule that was broken.
21
+ * @param file - The fragment file.
22
+ * @param line - 1-based line in that file.
23
+ * @param detail - What is wrong and how to fix it.
24
+ */
25
+ constructor(code, file, line, detail) {
26
+ super(`${file}:${line}: ${code}: ${detail}`);
27
+ this.name = 'ComposeError';
28
+ this.code = code;
29
+ this.file = file;
30
+ this.line = line;
31
+ this.detail = detail;
32
+ }
33
+ }
34
+ exports.ComposeError = ComposeError;
35
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/compose/errors.ts"],"names":[],"mappings":";;;AAkBA;;;;;GAKG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,2DAA2D;IAClD,IAAI,CAAmB;IAChC,4EAA4E;IACnE,IAAI,CAAS;IACtB,2DAA2D;IAClD,IAAI,CAAS;IACtB,6DAA6D;IACpD,MAAM,CAAS;IAExB;;;;;OAKG;IACH,YAAY,IAAsB,EAAE,IAAY,EAAE,IAAY,EAAE,MAAc;QAC5E,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI,KAAK,MAAM,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAxBD,oCAwBC"}
@@ -0,0 +1,3 @@
1
+ export { ComposeError, type ComposeErrorCode } from './errors.js';
2
+ export { checkComposedSchema, composeSchema, writeComposedSchema, type ComposeCheck, type ComposedFile, type ComposeOptions, type ComposeResult, } from './api.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeComposedSchema = exports.composeSchema = exports.checkComposedSchema = exports.ComposeError = void 0;
4
+ // The schema composer: `platform db compose` and its programmatic API.
5
+ var errors_js_1 = require("./errors.js");
6
+ Object.defineProperty(exports, "ComposeError", { enumerable: true, get: function () { return errors_js_1.ComposeError; } });
7
+ var api_js_1 = require("./api.js");
8
+ Object.defineProperty(exports, "checkComposedSchema", { enumerable: true, get: function () { return api_js_1.checkComposedSchema; } });
9
+ Object.defineProperty(exports, "composeSchema", { enumerable: true, get: function () { return api_js_1.composeSchema; } });
10
+ Object.defineProperty(exports, "writeComposedSchema", { enumerable: true, get: function () { return api_js_1.writeComposedSchema; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,yCAAkE;AAAzD,yGAAA,YAAY,OAAA;AACrB,mCAQkB;AAPhB,6GAAA,mBAAmB,OAAA;AACnB,uGAAA,aAAa,OAAA;AACb,6GAAA,mBAAmB,OAAA"}
@@ -0,0 +1,65 @@
1
+ /** @internal */
2
+ export type BlockKind = 'model' | 'enum' | 'type' | 'view' | 'generator' | 'datasource';
3
+ /** @internal */
4
+ export interface Block {
5
+ /** `extend model X { ... }` rather than a declaration. */
6
+ extend: boolean;
7
+ kind: BlockKind;
8
+ name: string;
9
+ /** Comments and blank lines between the previous block and this one. */
10
+ leading: string;
11
+ /** Header line, body lines and the closing `}`. */
12
+ lines: string[];
13
+ /** 1-based line of the header. */
14
+ line: number;
15
+ }
16
+ /** @internal */
17
+ export interface Field {
18
+ name: string;
19
+ /** The type name without `[]`, `?` or arguments. */
20
+ type: string;
21
+ /** Everything after the type (attributes and trailing comment). */
22
+ attrs: string;
23
+ /** The line exactly as written. */
24
+ raw: string;
25
+ /** 1-based line in the file. */
26
+ line: number;
27
+ }
28
+ /**
29
+ * Splits one fragment into top-level blocks.
30
+ *
31
+ * @param src - File contents.
32
+ * @param file - Path to name in errors.
33
+ * @returns The blocks in file order and the text after the last block.
34
+ * @throws {@link ComposeError} `MALFORMED` for a header or footer that is not `prisma format` shaped.
35
+ * @internal
36
+ */
37
+ export declare function parseBlocks(src: string, file: string): {
38
+ blocks: Block[];
39
+ trailing: string;
40
+ };
41
+ /**
42
+ * Is the block marked `// @extensible` in the comment run directly above it?
43
+ *
44
+ * @internal
45
+ */
46
+ export declare function isExtensible(block: Block): boolean;
47
+ /**
48
+ * The fields and block attributes of a model body.
49
+ *
50
+ * @internal
51
+ */
52
+ export declare function parseBody(block: Block, file: string): {
53
+ fields: Field[];
54
+ attrs: Array<{
55
+ raw: string;
56
+ line: number;
57
+ }>;
58
+ };
59
+ /**
60
+ * The block as text, with its leading comments.
61
+ *
62
+ * @internal
63
+ */
64
+ export declare function renderBlock(block: Pick<Block, 'leading' | 'lines'>): string;
65
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/compose/parse.ts"],"names":[],"mappings":"AAWA,gBAAgB;AAChB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,YAAY,CAAC;AAExF,gBAAgB;AAChB,MAAM,WAAW,KAAK;IACpB,0DAA0D;IAC1D,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,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