@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,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LockFormatError = void 0;
4
+ exports.parseLock = parseLock;
5
+ exports.readLock = readLock;
6
+ exports.emptyLock = emptyLock;
7
+ exports.serializeJson = serializeJson;
8
+ exports.serializeLock = serializeLock;
9
+ const node_fs_1 = require("node:fs");
10
+ const zod_1 = require("zod");
11
+ const semver_js_1 = require("./semver.js");
12
+ /** The lock file format version this release reads and writes. */
13
+ const LOCK_VERSION = 1;
14
+ const sha256Schema = zod_1.z.string().regex(/^[0-9a-f]{64}$/, 'expected 64 lower-case hex characters');
15
+ // Semver, prerelease allowed: a prerelease package (0.1.0-next.1) writes its own version into the lock.
16
+ const versionSchema = zod_1.z.string().regex(semver_js_1.SEMVER_PATTERN, 'expected a version such as 1.2.3 or 1.2.3-next.1');
17
+ const lockEntrySchema = zod_1.z
18
+ .object({
19
+ originId: zod_1.z.string().regex(/^platform:\d{4}_[a-z0-9][a-z0-9_]*$/, 'expected platform:NNNN_slug'),
20
+ localDir: zod_1.z
21
+ .string()
22
+ .min(1)
23
+ .refine((v) => !/[\\/]/.test(v) && v !== '.' && v !== '..', 'must be a bare directory name'),
24
+ sha256: sha256Schema,
25
+ since: versionSchema,
26
+ localSha256: sha256Schema.optional(),
27
+ note: zod_1.z.string().min(1).optional(),
28
+ })
29
+ .strict()
30
+ .refine((e) => (e.localSha256 === undefined) === (e.note === undefined), {
31
+ message: 'localSha256 and note are recorded together (a comment-only divergence must say why)',
32
+ });
33
+ const lockSchema = zod_1.z
34
+ .object({
35
+ lockVersion: zod_1.z.literal(LOCK_VERSION),
36
+ platformVersion: versionSchema,
37
+ migrations: zod_1.z.array(lockEntrySchema),
38
+ deviations: zod_1.z
39
+ .array(zod_1.z.object({ id: zod_1.z.string().min(1), reason: zod_1.z.string().min(1), expectDiff: zod_1.z.array(zod_1.z.string()) }).strict())
40
+ .optional(),
41
+ rawSqlIndexes: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string().min(1), definition: zod_1.z.string().min(1) }).strict()).optional(),
42
+ })
43
+ .strict();
44
+ /**
45
+ * A lock file that failed validation, with the offending path.
46
+ *
47
+ * @stability experimental
48
+ */
49
+ class LockFormatError extends Error {
50
+ /** @param message - What is wrong with the file. */
51
+ constructor(message) {
52
+ super(message);
53
+ this.name = 'LockFormatError';
54
+ }
55
+ }
56
+ exports.LockFormatError = LockFormatError;
57
+ function describeIssues(error) {
58
+ return error.issues.map((i) => `${i.path.length ? i.path.join('.') : '(root)'}: ${i.message}`).join('; ');
59
+ }
60
+ /**
61
+ * Parses and validates the text of a `platform.lock`.
62
+ *
63
+ * @param text - The file contents.
64
+ * @param source - A label for error messages (usually the path).
65
+ * @returns The validated lock.
66
+ * @throws LockFormatError when the JSON is invalid or does not match the schema, or the lock version is newer than this release reads.
67
+ * @stability experimental
68
+ */
69
+ function parseLock(text, source = 'platform.lock') {
70
+ let raw;
71
+ try {
72
+ raw = JSON.parse(text);
73
+ }
74
+ catch (error) {
75
+ throw new LockFormatError(`${source} is not valid JSON: ${error.message}`);
76
+ }
77
+ const version = raw?.lockVersion;
78
+ if (typeof version === 'number' && version > LOCK_VERSION) {
79
+ throw new LockFormatError(`${source} has lockVersion ${version}; this release reads ${LOCK_VERSION}. Upgrade @marinoscar/platform-db.`);
80
+ }
81
+ const parsed = lockSchema.safeParse(raw);
82
+ if (!parsed.success)
83
+ throw new LockFormatError(`${source} is invalid: ${describeIssues(parsed.error)}`);
84
+ return parsed.data;
85
+ }
86
+ /**
87
+ * Reads and validates a `platform.lock`.
88
+ *
89
+ * @param file - Path of the lock file.
90
+ * @returns The validated lock.
91
+ * @throws LockFormatError when the file is invalid (see {@link parseLock}).
92
+ * @stability experimental
93
+ */
94
+ function readLock(file) {
95
+ return parseLock((0, node_fs_1.readFileSync)(file, 'utf8'), file);
96
+ }
97
+ /**
98
+ * An empty lock for an app that has installed nothing.
99
+ *
100
+ * @param platformVersion - The package version, default `0.0.0`.
101
+ * @returns A lock with no migrations.
102
+ * @stability experimental
103
+ */
104
+ function emptyLock(platformVersion = '0.0.0') {
105
+ return { lockVersion: LOCK_VERSION, platformVersion, migrations: [] };
106
+ }
107
+ function sortKeys(value) {
108
+ if (Array.isArray(value))
109
+ return value.map(sortKeys);
110
+ if (value !== null && typeof value === 'object') {
111
+ return Object.fromEntries(Object.keys(value)
112
+ .sort()
113
+ .map((k) => [k, sortKeys(value[k])]));
114
+ }
115
+ return value;
116
+ }
117
+ /**
118
+ * Serialises a lock (or any manifest-shaped JSON) deterministically: keys
119
+ * sorted at every level, arrays in their given order, two-space indent, one
120
+ * trailing newline. The same input always produces the same bytes, so diffs
121
+ * stay stable.
122
+ *
123
+ * @param value - The lock, or any JSON value.
124
+ * @returns The file contents.
125
+ * @stability experimental
126
+ */
127
+ function serializeJson(value) {
128
+ return `${JSON.stringify(sortKeys(value), null, 2)}\n`;
129
+ }
130
+ /**
131
+ * Serialises a lock for writing to `platform.lock`.
132
+ *
133
+ * @param lock - The lock.
134
+ * @returns The file contents (see {@link serializeJson}).
135
+ * @stability experimental
136
+ */
137
+ function serializeLock(lock) {
138
+ return serializeJson(lock);
139
+ }
140
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/lock/lock.ts"],"names":[],"mappings":";;;AAmIA,8BAgBC;AAUD,4BAEC;AASD,8BAEC;AAwBD,sCAEC;AASD,sCAEC;AA/MD,qCAAuC;AACvC,6BAAwB;AACxB,2CAA6C;AAE7C,kEAAkE;AAClE,MAAM,YAAY,GAAG,CAAU,CAAC;AAEhC,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,uCAAuC,C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,CAAE,KAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,IAAkB;IAC9C,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * One migration of the package's linear, immutable history
3
+ * (`migrations/manifest.json`).
4
+ *
5
+ * @stability experimental
6
+ */
7
+ export interface ManifestEntry {
8
+ /** `NNNN_slug`; the origin id of the migration is `platform:` plus this. */
9
+ id: string;
10
+ /** The directory under the package's `migrations/` folder holding `migration.sql`. */
11
+ dir: string;
12
+ /** SHA-256 of the package's `migration.sql` bytes. */
13
+ sha256: string;
14
+ /** The platform version that introduced the migration. */
15
+ since: string;
16
+ /** The slice that owns the migration. */
17
+ slice: string;
18
+ /** Slice ids that must appear in earlier entries. */
19
+ requires: string[];
20
+ /** Other slices whose tables the migration also changes; omitted when it touches none. */
21
+ touches?: string[];
22
+ }
23
+ /**
24
+ * A manifest file that failed validation.
25
+ *
26
+ * @stability experimental
27
+ */
28
+ export declare class ManifestFormatError extends Error {
29
+ /** @param message - What is wrong with the manifest. */
30
+ constructor(message: string);
31
+ }
32
+ /**
33
+ * Parses and validates the text of `manifest.json`: a JSON array of entries
34
+ * with unique ids and a strictly ascending four-digit sequence.
35
+ *
36
+ * @param text - The file contents.
37
+ * @param source - A label for error messages (usually the path).
38
+ * @returns The validated entries, in file order.
39
+ * @throws ManifestFormatError when the JSON or an entry is invalid, an id repeats or the sequence is not strictly ascending.
40
+ * @stability experimental
41
+ */
42
+ export declare function parseManifest(text: string, source?: string): ManifestEntry[];
43
+ /**
44
+ * Reads and validates a package `manifest.json`.
45
+ *
46
+ * @param file - Path of the manifest.
47
+ * @returns The validated entries.
48
+ * @throws ManifestFormatError when the manifest is invalid (see {@link parseManifest}).
49
+ * @stability experimental
50
+ */
51
+ export declare function readManifest(file: string): ManifestEntry[];
52
+ /**
53
+ * The origin id of a package migration: `platform:` plus its id.
54
+ *
55
+ * @param entry - A manifest entry (or anything with its `id`).
56
+ * @returns For example `platform:0001_initial`.
57
+ * @stability experimental
58
+ */
59
+ export declare function originIdOf(entry: Pick<ManifestEntry, 'id'>): string;
60
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/lock/manifest.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,EAAE,EAAE,MAAM,CAAC;IACX,sFAAsF;IACtF,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,wDAAwD;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAkB,GAAG,aAAa,EAAE,CAyBrF;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ManifestFormatError = void 0;
4
+ exports.parseManifest = parseManifest;
5
+ exports.readManifest = readManifest;
6
+ exports.originIdOf = originIdOf;
7
+ const node_fs_1 = require("node:fs");
8
+ const zod_1 = require("zod");
9
+ const semver_js_1 = require("./semver.js");
10
+ const manifestEntrySchema = zod_1.z
11
+ .object({
12
+ id: zod_1.z.string().regex(/^\d{4}_[a-z0-9][a-z0-9_]*$/, 'expected NNNN_slug'),
13
+ dir: zod_1.z.string().regex(/^\d{4}_[a-z0-9][a-z0-9_]*$/, 'expected NNNN_slug'),
14
+ sha256: zod_1.z.string().regex(/^[0-9a-f]{64}$/, 'expected 64 lower-case hex characters'),
15
+ since: zod_1.z.string().regex(semver_js_1.SEMVER_PATTERN, 'expected a version such as 1.2.3 or 1.2.3-next.1'),
16
+ slice: zod_1.z.string().min(1),
17
+ requires: zod_1.z.array(zod_1.z.string().min(1)),
18
+ touches: zod_1.z.array(zod_1.z.string().min(1)).optional(),
19
+ })
20
+ .strict();
21
+ const manifestSchema = zod_1.z.array(manifestEntrySchema);
22
+ /**
23
+ * A manifest file that failed validation.
24
+ *
25
+ * @stability experimental
26
+ */
27
+ class ManifestFormatError extends Error {
28
+ /** @param message - What is wrong with the manifest. */
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = 'ManifestFormatError';
32
+ }
33
+ }
34
+ exports.ManifestFormatError = ManifestFormatError;
35
+ /**
36
+ * Parses and validates the text of `manifest.json`: a JSON array of entries
37
+ * with unique ids and a strictly ascending four-digit sequence.
38
+ *
39
+ * @param text - The file contents.
40
+ * @param source - A label for error messages (usually the path).
41
+ * @returns The validated entries, in file order.
42
+ * @throws ManifestFormatError when the JSON or an entry is invalid, an id repeats or the sequence is not strictly ascending.
43
+ * @stability experimental
44
+ */
45
+ function parseManifest(text, source = 'manifest.json') {
46
+ let raw;
47
+ try {
48
+ raw = JSON.parse(text);
49
+ }
50
+ catch (error) {
51
+ throw new ManifestFormatError(`${source} is not valid JSON: ${error.message}`);
52
+ }
53
+ const parsed = manifestSchema.safeParse(raw);
54
+ if (!parsed.success) {
55
+ const detail = parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ');
56
+ throw new ManifestFormatError(`${source} is invalid: ${detail}`);
57
+ }
58
+ const seen = new Set();
59
+ let previous = 0;
60
+ for (const entry of parsed.data) {
61
+ if (entry.dir !== entry.id)
62
+ throw new ManifestFormatError(`${source}: entry ${entry.id} has dir ${entry.dir}; they must match`);
63
+ if (seen.has(entry.id))
64
+ throw new ManifestFormatError(`${source}: duplicate migration id ${entry.id}`);
65
+ seen.add(entry.id);
66
+ const sequence = Number(entry.id.slice(0, 4));
67
+ if (sequence <= previous) {
68
+ throw new ManifestFormatError(`${source}: ${entry.id} is out of sequence (the history is linear and strictly ascending)`);
69
+ }
70
+ previous = sequence;
71
+ }
72
+ return parsed.data;
73
+ }
74
+ /**
75
+ * Reads and validates a package `manifest.json`.
76
+ *
77
+ * @param file - Path of the manifest.
78
+ * @returns The validated entries.
79
+ * @throws ManifestFormatError when the manifest is invalid (see {@link parseManifest}).
80
+ * @stability experimental
81
+ */
82
+ function readManifest(file) {
83
+ return parseManifest((0, node_fs_1.readFileSync)(file, 'utf8'), file);
84
+ }
85
+ /**
86
+ * The origin id of a package migration: `platform:` plus its id.
87
+ *
88
+ * @param entry - A manifest entry (or anything with its `id`).
89
+ * @returns For example `platform:0001_initial`.
90
+ * @stability experimental
91
+ */
92
+ function originIdOf(entry) {
93
+ return `platform:${entry.id}`;
94
+ }
95
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/lock/manifest.ts"],"names":[],"mappings":";;;AAgEA,sCAyBC;AAUD,oCAEC;AASD,gCAEC;AAhHD,qCAAuC;AACvC,6BAAwB;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,MAAM,IAAI,mBAAmB,CAAC,GAAG,MAAM,KAAK,KAAK,CAAC,EAAE,oEAAoE,CAAC,CAAC;QAC5H,CAAC;QACD,QAAQ,GAAG,QAAQ,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,IAAY;IACvC,OAAO,aAAa,CAAC,IAAA,sBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,KAAgC;IACzD,OAAO,YAAY,KAAK,CAAC,EAAE,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A semantic version as the platform writes it: `x.y.z`, optionally followed by
3
+ * a prerelease (`-next.1`) and build metadata (`+sha`). Prerelease packages
4
+ * (`0.1.0-next.1`) are published, so the lock, the manifest and the version
5
+ * comparisons all accept them.
6
+ *
7
+ * @stability experimental
8
+ */
9
+ export declare const SEMVER_PATTERN: RegExp;
10
+ //# sourceMappingURL=semver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../src/lock/semver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,QAC+E,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SEMVER_PATTERN = void 0;
4
+ /**
5
+ * A semantic version as the platform writes it: `x.y.z`, optionally followed by
6
+ * a prerelease (`-next.1`) and build metadata (`+sha`). Prerelease packages
7
+ * (`0.1.0-next.1`) are published, so the lock, the manifest and the version
8
+ * comparisons all accept them.
9
+ *
10
+ * @stability experimental
11
+ */
12
+ exports.SEMVER_PATTERN = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
13
+ //# sourceMappingURL=semver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semver.js","sourceRoot":"","sources":["../../src/lock/semver.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACU,QAAA,cAAc,GACzB,wGAAwG,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { seedPlatform } from './seed-platform.js';
2
+ export { platformSeedInputFrom, readSeedSnapshot, type PermissionCatalogSnapshot, type SeedRegistrySnapshot } from './input.js';
3
+ export type { PlatformSeedInput, SeedAllowedEmailDelegate, SeedDefaultOrganization, SeedJsonValue, SeedLogger, SeedNamedDelegate, SeedNamedEntry, SeedOrganizationDelegate, SeedPrisma, SeedRowId, SeedRolePermissionDelegate, SeedScope, SeedSummary, SeedSystemSettingsDelegate, SeedUpsertArgs, } from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seed/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,KAAK,yBAAyB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAChI,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,wBAAwB,EACxB,UAAU,EACV,SAAS,EACT,0BAA0B,EAC1B,SAAS,EACT,WAAW,EACX,0BAA0B,EAC1B,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readSeedSnapshot = exports.platformSeedInputFrom = exports.seedPlatform = void 0;
4
+ // The platform seed slice: `@marinoscar/platform-db/seed`.
5
+ var seed_platform_js_1 = require("./seed-platform.js");
6
+ Object.defineProperty(exports, "seedPlatform", { enumerable: true, get: function () { return seed_platform_js_1.seedPlatform; } });
7
+ var input_js_1 = require("./input.js");
8
+ Object.defineProperty(exports, "platformSeedInputFrom", { enumerable: true, get: function () { return input_js_1.platformSeedInputFrom; } });
9
+ Object.defineProperty(exports, "readSeedSnapshot", { enumerable: true, get: function () { return input_js_1.readSeedSnapshot; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seed/index.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,uDAAkD;AAAzC,gHAAA,YAAY,OAAA;AACrB,uCAAgI;AAAvH,iHAAA,qBAAqB,OAAA;AAAE,4GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,52 @@
1
+ import type { PlatformSeedInput, SeedNamedEntry } from './types.js';
2
+ /**
3
+ * The permission registries as plain data: the shape of
4
+ * `prisma/catalog/permissions.json`.
5
+ *
6
+ * @stability experimental
7
+ */
8
+ export interface PermissionCatalogSnapshot {
9
+ /** Every role, in registration order. */
10
+ roles: ReadonlyArray<SeedNamedEntry>;
11
+ /** Every permission, in registration order. */
12
+ permissions: ReadonlyArray<SeedNamedEntry>;
13
+ /** Default grants: role name to permission names. */
14
+ rolePermissions: Readonly<Record<string, readonly string[]>>;
15
+ }
16
+ /**
17
+ * The registries' plain-data snapshots, as {@link platformSeedInputFrom} takes them.
18
+ *
19
+ * @stability experimental
20
+ */
21
+ export interface SeedRegistrySnapshot {
22
+ /** The roles, permissions and default grants. */
23
+ permissions: PermissionCatalogSnapshot;
24
+ /** The `global` system settings value: every namespace's defaults, in registration order. */
25
+ settings: Readonly<Record<string, unknown>>;
26
+ }
27
+ /**
28
+ * Build the seed input from the registries' snapshots and the process
29
+ * environment.
30
+ *
31
+ * Pure: it reads nothing but its arguments. The initial administrator is the
32
+ * `INITIAL_ADMIN_EMAIL` entry of `env`; an unset or empty value means none.
33
+ *
34
+ * @param snapshot - The permission and settings snapshots (see {@link readSeedSnapshot}).
35
+ * @param env - The environment to read `INITIAL_ADMIN_EMAIL` from, normally `process.env`.
36
+ * @returns The input for `seedPlatform`.
37
+ *
38
+ * @stability experimental
39
+ */
40
+ export declare function platformSeedInputFrom(snapshot: SeedRegistrySnapshot, env: NodeJS.ProcessEnv): PlatformSeedInput;
41
+ /**
42
+ * Read the two committed catalogs of an app's `prisma/catalog/` folder:
43
+ * `permissions.json` and `system-settings-defaults.json`.
44
+ *
45
+ * @param catalogDir - The folder holding both files (the reference app passes `join(__dirname, 'catalog')` from `prisma/`).
46
+ * @returns The snapshots for {@link platformSeedInputFrom}.
47
+ * @throws When a file is missing, is not JSON, or lacks the expected shape; the message names the file.
48
+ *
49
+ * @stability experimental
50
+ */
51
+ export declare function readSeedSnapshot(catalogDir: string): SeedRegistrySnapshot;
52
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/seed/input.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,yCAAyC;IACzC,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACrC,+CAA+C;IAC/C,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,qDAAqD;IACrD,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,WAAW,EAAE,yBAAyB,CAAC;IACvC,6FAA6F;IAC7F,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC7C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,iBAAiB,CAS/G;AAsBD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,oBAAoB,CAYzE"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ // Building a PlatformSeedInput from the registries' plain-data snapshots
3
+ // (issue #712). The snapshots are the committed JSON catalogs an app renders
4
+ // from its permission and settings registries (`prisma/catalog/`), because the
5
+ // seed runs in a production image that carries `prisma/` but not `src/`.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.platformSeedInputFrom = platformSeedInputFrom;
8
+ exports.readSeedSnapshot = readSeedSnapshot;
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = require("node:path");
11
+ /**
12
+ * Build the seed input from the registries' snapshots and the process
13
+ * environment.
14
+ *
15
+ * Pure: it reads nothing but its arguments. The initial administrator is the
16
+ * `INITIAL_ADMIN_EMAIL` entry of `env`; an unset or empty value means none.
17
+ *
18
+ * @param snapshot - The permission and settings snapshots (see {@link readSeedSnapshot}).
19
+ * @param env - The environment to read `INITIAL_ADMIN_EMAIL` from, normally `process.env`.
20
+ * @returns The input for `seedPlatform`.
21
+ *
22
+ * @stability experimental
23
+ */
24
+ function platformSeedInputFrom(snapshot, env) {
25
+ const input = {
26
+ roles: snapshot.permissions.roles,
27
+ permissions: snapshot.permissions.permissions,
28
+ roleGrants: snapshot.permissions.rolePermissions,
29
+ systemSettingsDefaults: snapshot.settings,
30
+ };
31
+ const initialAdminEmail = env.INITIAL_ADMIN_EMAIL;
32
+ return initialAdminEmail ? { ...input, initialAdminEmail } : input;
33
+ }
34
+ /** True for a non-null, non-array object. */
35
+ function isRecord(value) {
36
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
37
+ }
38
+ /** Read and parse one catalog file, naming it in every failure. */
39
+ function readJson(path) {
40
+ let text;
41
+ try {
42
+ text = (0, node_fs_1.readFileSync)(path, 'utf8');
43
+ }
44
+ catch (error) {
45
+ throw new Error(`Seed catalog ${path} cannot be read (${error.message}). Regenerate it with the app's catalog scripts.`);
46
+ }
47
+ try {
48
+ return JSON.parse(text);
49
+ }
50
+ catch (error) {
51
+ throw new Error(`Seed catalog ${path} is not valid JSON (${error.message}). Regenerate it with the app's catalog scripts.`);
52
+ }
53
+ }
54
+ /**
55
+ * Read the two committed catalogs of an app's `prisma/catalog/` folder:
56
+ * `permissions.json` and `system-settings-defaults.json`.
57
+ *
58
+ * @param catalogDir - The folder holding both files (the reference app passes `join(__dirname, 'catalog')` from `prisma/`).
59
+ * @returns The snapshots for {@link platformSeedInputFrom}.
60
+ * @throws When a file is missing, is not JSON, or lacks the expected shape; the message names the file.
61
+ *
62
+ * @stability experimental
63
+ */
64
+ function readSeedSnapshot(catalogDir) {
65
+ const permissionsPath = (0, node_path_1.join)(catalogDir, 'permissions.json');
66
+ const permissions = readJson(permissionsPath);
67
+ if (!isRecord(permissions) || !Array.isArray(permissions.roles) || !Array.isArray(permissions.permissions) || !isRecord(permissions.rolePermissions)) {
68
+ throw new Error(`Seed catalog ${permissionsPath} must hold "roles", "permissions" (arrays) and "rolePermissions" (an object).`);
69
+ }
70
+ const settingsPath = (0, node_path_1.join)(catalogDir, 'system-settings-defaults.json');
71
+ const settings = readJson(settingsPath);
72
+ if (!isRecord(settings)) {
73
+ throw new Error(`Seed catalog ${settingsPath} must hold one object of settings namespaces.`);
74
+ }
75
+ return { permissions: permissions, settings };
76
+ }
77
+ //# sourceMappingURL=input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/seed/input.ts"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,+EAA+E;AAC/E,yEAAyE;;AA+CzE,sDASC;AAgCD,4CAYC;AAlGD,qCAAuC;AACvC,yCAAiC;AA+BjC;;;;;;;;;;;;GAYG;AACH,SAAgB,qBAAqB,CAAC,QAA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kB,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;QACrJ,MAAM,IAAI,KAAK,CAAC,gBAAgB,eAAe,+EAA+E,CAAC,CAAC;IAClI,CAAC;IACD,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,UAAU,EAAE,+BAA+B,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,gBAAgB,YAAY,+CAA+C,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,WAAmD,EAAE,QAAQ,EAAE,CAAC;AACxF,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { PlatformSeedInput, SeedLogger, SeedPrisma, SeedSummary } from './types.js';
2
+ /**
3
+ * Seed the platform's roles and permissions (each with its `system` or `org`
4
+ * scope, refreshed on every run like the description), default grants, the `global` system
5
+ * settings row, the initial administrator's allowlist entry and the default
6
+ * organization.
7
+ *
8
+ * Idempotent: every write is an upsert keyed on a natural unique (`name`,
9
+ * `roleId_permissionId`, `key`, `email`), so a second run updates the same
10
+ * rows. It **never deletes**: a permission that left the registry stays as a
11
+ * row until an explicit migration removes it (expand/contract). It never
12
+ * overwrites an admin-edited value either: the settings row and the allowlist
13
+ * row are created with `update: {}`. Writes are sequential, in a fixed order
14
+ * (roles, permissions, grants, settings, allowlist, default organization), so
15
+ * the log reads the same on every run. The default organization is created only
16
+ * when no organization is flagged default (found by `isDefault`, not by slug),
17
+ * so a renamed default is left alone and the one-default index is never hit.
18
+ *
19
+ * @param prisma - The app's Prisma client, or any object with the delegates of {@link SeedPrisma}.
20
+ * @param input - What to write; see {@link PlatformSeedInput}.
21
+ * @param log - Receives one line per step. Default: silent.
22
+ * @returns What the run did.
23
+ * @throws Whatever the client throws; nothing is caught, so a failed seed fails loudly.
24
+ *
25
+ * @stability experimental
26
+ */
27
+ export declare function seedPlatform(prisma: SeedPrisma, input: PlatformSeedInput, log?: SeedLogger): Promise<SeedSummary>;
28
+ //# sourceMappingURL=seed-platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed-platform.d.ts","sourceRoot":"","sources":["../../src/seed/seed-platform.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,UAAU,EAAkB,UAAU,EAAa,WAAW,EAAE,MAAM,YAAY,CAAC;AAkBnI;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,GAAE,UAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CA4F/H"}