@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.
- package/CHANGELOG.md +88 -0
- package/LICENSE +21 -0
- package/README.md +525 -2
- package/bin/platform.js +28 -0
- package/dist/baseline/deps.d.ts +32 -0
- package/dist/baseline/deps.d.ts.map +1 -0
- package/dist/baseline/deps.js +66 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +36 -0
- package/dist/baseline/errors.d.ts.map +1 -0
- package/dist/baseline/errors.js +23 -0
- package/dist/baseline/errors.js.map +1 -0
- package/dist/baseline/fs.d.ts +9 -0
- package/dist/baseline/fs.d.ts.map +1 -0
- package/dist/baseline/fs.js +39 -0
- package/dist/baseline/fs.js.map +1 -0
- package/dist/baseline/index.d.ts +8 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +24 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/mapping.d.ts +43 -0
- package/dist/baseline/mapping.d.ts.map +1 -0
- package/dist/baseline/mapping.js +80 -0
- package/dist/baseline/mapping.js.map +1 -0
- package/dist/baseline/normalise.d.ts +42 -0
- package/dist/baseline/normalise.d.ts.map +1 -0
- package/dist/baseline/normalise.js +133 -0
- package/dist/baseline/normalise.js.map +1 -0
- package/dist/baseline/plan.d.ts +66 -0
- package/dist/baseline/plan.d.ts.map +1 -0
- package/dist/baseline/plan.js +105 -0
- package/dist/baseline/plan.js.map +1 -0
- package/dist/baseline/report.d.ts +127 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +89 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +117 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +358 -0
- package/dist/baseline/run.js.map +1 -0
- package/dist/bin/db-commands.d.ts +31 -0
- package/dist/bin/db-commands.d.ts.map +1 -0
- package/dist/bin/db-commands.js +311 -0
- package/dist/bin/db-commands.js.map +1 -0
- package/dist/bin/fs-io.d.ts +7 -0
- package/dist/bin/fs-io.d.ts.map +1 -0
- package/dist/bin/fs-io.js +45 -0
- package/dist/bin/fs-io.js.map +1 -0
- package/dist/bin/platform.d.ts +21 -0
- package/dist/bin/platform.d.ts.map +1 -0
- package/dist/bin/platform.js +99 -0
- package/dist/bin/platform.js.map +1 -0
- package/dist/compose/api.d.ts +84 -0
- package/dist/compose/api.d.ts.map +1 -0
- package/dist/compose/api.js +101 -0
- package/dist/compose/api.js.map +1 -0
- package/dist/compose/compose.d.ts +51 -0
- package/dist/compose/compose.d.ts.map +1 -0
- package/dist/compose/compose.js +177 -0
- package/dist/compose/compose.js.map +1 -0
- package/dist/compose/diff.d.ts +7 -0
- package/dist/compose/diff.d.ts.map +1 -0
- package/dist/compose/diff.js +68 -0
- package/dist/compose/diff.js.map +1 -0
- package/dist/compose/errors.d.ts +31 -0
- package/dist/compose/errors.d.ts.map +1 -0
- package/dist/compose/errors.js +35 -0
- package/dist/compose/errors.js.map +1 -0
- package/dist/compose/index.d.ts +3 -0
- package/dist/compose/index.d.ts.map +1 -0
- package/dist/compose/index.js +11 -0
- package/dist/compose/index.js.map +1 -0
- package/dist/compose/parse.d.ts +65 -0
- package/dist/compose/parse.d.ts.map +1 -0
- package/dist/compose/parse.js +122 -0
- package/dist/compose/parse.js.map +1 -0
- package/dist/drift/app-objects.d.ts +107 -0
- package/dist/drift/app-objects.d.ts.map +1 -0
- package/dist/drift/app-objects.js +193 -0
- package/dist/drift/app-objects.js.map +1 -0
- package/dist/drift/db-conformance.d.ts +52 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +89 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +8 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +43 -0
- package/dist/drift/index.js.map +1 -0
- package/dist/drift/raw-sql-indexes.d.ts +106 -0
- package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
- package/dist/drift/raw-sql-indexes.js +113 -0
- package/dist/drift/raw-sql-indexes.js.map +1 -0
- package/dist/drift/raw-sql-tripwire.d.ts +191 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +422 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- package/dist/drift/rls-policies.d.ts +226 -0
- package/dist/drift/rls-policies.d.ts.map +1 -0
- package/dist/drift/rls-policies.js +317 -0
- package/dist/drift/rls-policies.js.map +1 -0
- package/dist/drift/run.d.ts +152 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +252 -0
- package/dist/drift/run.js.map +1 -0
- package/dist/drift/sql-expression.d.ts +27 -0
- package/dist/drift/sql-expression.d.ts.map +1 -0
- package/dist/drift/sql-expression.js +64 -0
- package/dist/drift/sql-expression.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/hash.d.ts +13 -0
- package/dist/lock/hash.d.ts.map +1 -0
- package/dist/lock/hash.js +19 -0
- package/dist/lock/hash.js.map +1 -0
- package/dist/lock/index.d.ts +5 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js +20 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/lock/lock.d.ts +154 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +151 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +68 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +96 -0
- package/dist/lock/manifest.js.map +1 -0
- package/dist/lock/semver.d.ts +10 -0
- package/dist/lock/semver.d.ts.map +1 -0
- package/dist/lock/semver.js +13 -0
- package/dist/lock/semver.js.map +1 -0
- package/dist/seed/index.d.ts +5 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +16 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/seed/input.d.ts +52 -0
- package/dist/seed/input.d.ts.map +1 -0
- package/dist/seed/input.js +77 -0
- package/dist/seed/input.js.map +1 -0
- package/dist/seed/seed-platform.d.ts +41 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +165 -0
- package/dist/seed/seed-platform.js.map +1 -0
- package/dist/seed/steps.d.ts +172 -0
- package/dist/seed/steps.d.ts.map +1 -0
- package/dist/seed/steps.js +136 -0
- package/dist/seed/steps.js.map +1 -0
- package/dist/seed/types.d.ts +287 -0
- package/dist/seed/types.d.ts.map +1 -0
- package/dist/seed/types.js +5 -0
- package/dist/seed/types.js.map +1 -0
- package/dist/sync/app-migrations.d.ts +52 -0
- package/dist/sync/app-migrations.d.ts.map +1 -0
- package/dist/sync/app-migrations.js +62 -0
- package/dist/sync/app-migrations.js.map +1 -0
- package/dist/sync/apply.d.ts +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +38 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +59 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +115 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +32 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +23 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +10 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +27 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/ledger.d.ts +65 -0
- package/dist/sync/ledger.d.ts.map +1 -0
- package/dist/sync/ledger.js +49 -0
- package/dist/sync/ledger.js.map +1 -0
- package/dist/sync/plan.d.ts +63 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +86 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +62 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +95 -0
- package/dist/sync/promote.js.map +1 -0
- package/dist/sync/timestamps.d.ts +41 -0
- package/dist/sync/timestamps.d.ts.map +1 -0
- package/dist/sync/timestamps.js +68 -0
- package/dist/sync/timestamps.js.map +1 -0
- package/dist/sync/version.d.ts +28 -0
- package/dist/sync/version.d.ts.map +1 -0
- package/dist/sync/version.js +66 -0
- package/dist/sync/version.js.map +1 -0
- package/migrations/0001_initial/migration.sql +297 -0
- package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
- package/migrations/0003_add_credentials/migration.sql +20 -0
- package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
- package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
- package/migrations/0006_add_notifications/migration.sql +22 -0
- package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
- package/migrations/0008_add_jobs/migration.sql +110 -0
- package/migrations/0009_add_worker_nodes/migration.sql +90 -0
- package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
- package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
- package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
- package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
- package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
- package/migrations/0015_add_job_claim_token/migration.sql +92 -0
- package/migrations/0016_add_ai_platform/migration.sql +108 -0
- package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
- package/migrations/0018_add_user_credentials/migration.sql +29 -0
- package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
- package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
- package/migrations/0021_add_job_trace_context/migration.sql +6 -0
- package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
- package/migrations/0023_add_organizations/migration.sql +142 -0
- package/migrations/0024_split_system_org_roles/migration.sql +131 -0
- package/migrations/0025_org_scoped_rls/migration.sql +215 -0
- package/migrations/0026_add_groups/migration.sql +165 -0
- package/migrations/0027_add_grants/migration.sql +117 -0
- package/migrations/0028_add_org_settings/migration.sql +49 -0
- package/migrations/0029_add_org_credentials/migration.sql +54 -0
- package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
- package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
- package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
- package/migrations/0033_add_android_app/migration.sql +60 -0
- package/migrations/0034_open_job_reason/migration.sql +16 -0
- package/migrations/0035_ai_usage_feature/migration.sql +37 -0
- package/migrations/0036_add_app_metadata/migration.sql +49 -0
- package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
- package/migrations/manifest.json +379 -0
- package/package.json +78 -4
- package/raw-sql-indexes.json +94 -0
- package/rls-policies.json +74 -0
- package/schema/ai.prisma +444 -0
- package/schema/android-app.prisma +47 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +170 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +439 -0
- package/schema/jobs.prisma +760 -0
- package/schema/notifications.prisma +649 -0
- package/schema/settings.prisma +60 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../src/lock/lock.ts"],"names":[],"mappings":"AAqDA;;;;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,CAA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,YAAY,CAEjE;AAcD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
rlsPolicies: zod_1.z
|
|
43
|
+
.array(zod_1.z
|
|
44
|
+
.object({
|
|
45
|
+
name: zod_1.z.string().min(1),
|
|
46
|
+
table: zod_1.z.string().min(1),
|
|
47
|
+
usingSha256: sha256Schema.optional(),
|
|
48
|
+
checkSha256: sha256Schema.optional(),
|
|
49
|
+
})
|
|
50
|
+
.strict())
|
|
51
|
+
.optional(),
|
|
52
|
+
appMigrations: zod_1.z.array(zod_1.z.string().min(1).refine((v) => !/[\\/]/.test(v), 'must be a bare directory name')).optional(),
|
|
53
|
+
})
|
|
54
|
+
.strict();
|
|
55
|
+
/**
|
|
56
|
+
* A lock file that failed validation, with the offending path.
|
|
57
|
+
*
|
|
58
|
+
* @stability experimental
|
|
59
|
+
*/
|
|
60
|
+
class LockFormatError extends Error {
|
|
61
|
+
/** @param message - What is wrong with the file. */
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = 'LockFormatError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.LockFormatError = LockFormatError;
|
|
68
|
+
function describeIssues(error) {
|
|
69
|
+
return error.issues.map((i) => `${i.path.length ? i.path.join('.') : '(root)'}: ${i.message}`).join('; ');
|
|
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
|
+
function parseLock(text, source = 'platform.lock') {
|
|
81
|
+
let raw;
|
|
82
|
+
try {
|
|
83
|
+
raw = JSON.parse(text);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new LockFormatError(`${source} is not valid JSON: ${error.message}`);
|
|
87
|
+
}
|
|
88
|
+
const version = raw?.lockVersion;
|
|
89
|
+
if (typeof version === 'number' && version > LOCK_VERSION) {
|
|
90
|
+
throw new LockFormatError(`${source} has lockVersion ${version}; this release reads ${LOCK_VERSION}. Upgrade @marinoscar/platform-db.`);
|
|
91
|
+
}
|
|
92
|
+
const parsed = lockSchema.safeParse(raw);
|
|
93
|
+
if (!parsed.success)
|
|
94
|
+
throw new LockFormatError(`${source} is invalid: ${describeIssues(parsed.error)}`);
|
|
95
|
+
return parsed.data;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reads and validates a `platform.lock`.
|
|
99
|
+
*
|
|
100
|
+
* @param file - Path of the lock file.
|
|
101
|
+
* @returns The validated lock.
|
|
102
|
+
* @throws LockFormatError when the file is invalid (see {@link parseLock}).
|
|
103
|
+
* @stability experimental
|
|
104
|
+
*/
|
|
105
|
+
function readLock(file) {
|
|
106
|
+
return parseLock((0, node_fs_1.readFileSync)(file, 'utf8'), file);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An empty lock for an app that has installed nothing.
|
|
110
|
+
*
|
|
111
|
+
* @param platformVersion - The package version, default `0.0.0`.
|
|
112
|
+
* @returns A lock with no migrations.
|
|
113
|
+
* @stability experimental
|
|
114
|
+
*/
|
|
115
|
+
function emptyLock(platformVersion = '0.0.0') {
|
|
116
|
+
return { lockVersion: LOCK_VERSION, platformVersion, migrations: [] };
|
|
117
|
+
}
|
|
118
|
+
function sortKeys(value) {
|
|
119
|
+
if (Array.isArray(value))
|
|
120
|
+
return value.map(sortKeys);
|
|
121
|
+
if (value !== null && typeof value === 'object') {
|
|
122
|
+
return Object.fromEntries(Object.keys(value)
|
|
123
|
+
.sort()
|
|
124
|
+
.map((k) => [k, sortKeys(value[k])]));
|
|
125
|
+
}
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serialises a lock (or any manifest-shaped JSON) deterministically: keys
|
|
130
|
+
* sorted at every level, arrays in their given order, two-space indent, one
|
|
131
|
+
* trailing newline. The same input always produces the same bytes, so diffs
|
|
132
|
+
* stay stable.
|
|
133
|
+
*
|
|
134
|
+
* @param value - The lock, or any JSON value.
|
|
135
|
+
* @returns The file contents.
|
|
136
|
+
* @stability experimental
|
|
137
|
+
*/
|
|
138
|
+
function serializeJson(value) {
|
|
139
|
+
return `${JSON.stringify(sortKeys(value), null, 2)}\n`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Serialises a lock for writing to `platform.lock`.
|
|
143
|
+
*
|
|
144
|
+
* @param lock - The lock.
|
|
145
|
+
* @returns The file contents (see {@link serializeJson}).
|
|
146
|
+
* @stability experimental
|
|
147
|
+
*/
|
|
148
|
+
function serializeLock(lock) {
|
|
149
|
+
return serializeJson(lock);
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/lock/lock.ts"],"names":[],"mappings":";;;AAsLA,8BAgBC;AAUD,4BAEC;AASD,8BAEC;AAwBD,sCAEC;AASD,sCAEC;A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
|
+
* (`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
|
+
* `true` when the migration enables row-level security on a table. An app
|
|
24
|
+
* adopting the history in partial mode stops before such a migration until
|
|
25
|
+
* it opts in (`platform db baseline --allow-rls`): RLS is inert for a
|
|
26
|
+
* superuser role, and the application role must be an ordinary one first.
|
|
27
|
+
* Omitted when the migration enables none.
|
|
28
|
+
*/
|
|
29
|
+
rls?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A manifest file that failed validation.
|
|
33
|
+
*
|
|
34
|
+
* @stability experimental
|
|
35
|
+
*/
|
|
36
|
+
export declare class ManifestFormatError extends Error {
|
|
37
|
+
/** @param message - What is wrong with the manifest. */
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parses and validates the text of `manifest.json`: a JSON array of entries
|
|
42
|
+
* with unique ids and a strictly ascending four-digit sequence.
|
|
43
|
+
*
|
|
44
|
+
* @param text - The file contents.
|
|
45
|
+
* @param source - A label for error messages (usually the path).
|
|
46
|
+
* @returns The validated entries, in file order.
|
|
47
|
+
* @throws ManifestFormatError when the JSON or an entry is invalid, an id repeats or the sequence is not strictly ascending.
|
|
48
|
+
* @stability experimental
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseManifest(text: string, source?: string): ManifestEntry[];
|
|
51
|
+
/**
|
|
52
|
+
* Reads and validates a package `manifest.json`.
|
|
53
|
+
*
|
|
54
|
+
* @param file - Path of the manifest.
|
|
55
|
+
* @returns The validated entries.
|
|
56
|
+
* @throws ManifestFormatError when the manifest is invalid (see {@link parseManifest}).
|
|
57
|
+
* @stability experimental
|
|
58
|
+
*/
|
|
59
|
+
export declare function readManifest(file: string): ManifestEntry[];
|
|
60
|
+
/**
|
|
61
|
+
* The origin id of a package migration: `platform:` plus its id.
|
|
62
|
+
*
|
|
63
|
+
* @param entry - A manifest entry (or anything with its `id`).
|
|
64
|
+
* @returns For example `platform:0001_initial`.
|
|
65
|
+
* @stability experimental
|
|
66
|
+
*/
|
|
67
|
+
export declare function originIdOf(entry: Pick<ManifestEntry, 'id'>): string;
|
|
68
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/lock/manifest.ts"],"names":[],"mappings":"AAmBA;;;;;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;IACnB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;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,96 @@
|
|
|
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
|
+
rls: zod_1.z.boolean().optional(),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const manifestSchema = zod_1.z.array(manifestEntrySchema);
|
|
23
|
+
/**
|
|
24
|
+
* A manifest file that failed validation.
|
|
25
|
+
*
|
|
26
|
+
* @stability experimental
|
|
27
|
+
*/
|
|
28
|
+
class ManifestFormatError extends Error {
|
|
29
|
+
/** @param message - What is wrong with the manifest. */
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'ManifestFormatError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ManifestFormatError = ManifestFormatError;
|
|
36
|
+
/**
|
|
37
|
+
* Parses and validates the text of `manifest.json`: a JSON array of entries
|
|
38
|
+
* with unique ids and a strictly ascending four-digit sequence.
|
|
39
|
+
*
|
|
40
|
+
* @param text - The file contents.
|
|
41
|
+
* @param source - A label for error messages (usually the path).
|
|
42
|
+
* @returns The validated entries, in file order.
|
|
43
|
+
* @throws ManifestFormatError when the JSON or an entry is invalid, an id repeats or the sequence is not strictly ascending.
|
|
44
|
+
* @stability experimental
|
|
45
|
+
*/
|
|
46
|
+
function parseManifest(text, source = 'manifest.json') {
|
|
47
|
+
let raw;
|
|
48
|
+
try {
|
|
49
|
+
raw = JSON.parse(text);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new ManifestFormatError(`${source} is not valid JSON: ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
const parsed = manifestSchema.safeParse(raw);
|
|
55
|
+
if (!parsed.success) {
|
|
56
|
+
const detail = parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ');
|
|
57
|
+
throw new ManifestFormatError(`${source} is invalid: ${detail}`);
|
|
58
|
+
}
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
let previous = 0;
|
|
61
|
+
for (const entry of parsed.data) {
|
|
62
|
+
if (entry.dir !== entry.id)
|
|
63
|
+
throw new ManifestFormatError(`${source}: entry ${entry.id} has dir ${entry.dir}; they must match`);
|
|
64
|
+
if (seen.has(entry.id))
|
|
65
|
+
throw new ManifestFormatError(`${source}: duplicate migration id ${entry.id}`);
|
|
66
|
+
seen.add(entry.id);
|
|
67
|
+
const sequence = Number(entry.id.slice(0, 4));
|
|
68
|
+
if (sequence <= previous) {
|
|
69
|
+
throw new ManifestFormatError(`${source}: ${entry.id} is out of sequence (the history is linear and strictly ascending)`);
|
|
70
|
+
}
|
|
71
|
+
previous = sequence;
|
|
72
|
+
}
|
|
73
|
+
return parsed.data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Reads and validates a package `manifest.json`.
|
|
77
|
+
*
|
|
78
|
+
* @param file - Path of the manifest.
|
|
79
|
+
* @returns The validated entries.
|
|
80
|
+
* @throws ManifestFormatError when the manifest is invalid (see {@link parseManifest}).
|
|
81
|
+
* @stability experimental
|
|
82
|
+
*/
|
|
83
|
+
function readManifest(file) {
|
|
84
|
+
return parseManifest((0, node_fs_1.readFileSync)(file, 'utf8'), file);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The origin id of a package migration: `platform:` plus its id.
|
|
88
|
+
*
|
|
89
|
+
* @param entry - A manifest entry (or anything with its `id`).
|
|
90
|
+
* @returns For example `platform:0001_initial`.
|
|
91
|
+
* @stability experimental
|
|
92
|
+
*/
|
|
93
|
+
function originIdOf(entry) {
|
|
94
|
+
return `platform:${entry.id}`;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/lock/manifest.ts"],"names":[],"mappings":";;;AAyEA,sCAyBC;AAUD,oCAEC;AASD,gCAEC;AAzHD,qCAAuC;AACvC,6BAAwB;AACxB,2CAA6C;AAE7C,MAAM,mBAAmB,GAAG,OAAC;KAC1B,MAAM,CAAC;IACN,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,4BAA4B,EAAE,oBAAoB,CAAC;IACxE,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,C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AAC;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,5 @@
|
|
|
1
|
+
export { seedPlatform } from './seed-platform.js';
|
|
2
|
+
export { PLATFORM_SEED_STEP_IDS, SeedStepError, assertSeedIdempotent, assertSeedSteps, readSeedStepResult, type SeedIdempotenceResult, type SeedPlatformOptions, type SeedStep, type SeedStepContext, type SeedStepResult, type SeedStepSummary, } from './steps.js';
|
|
3
|
+
export { platformSeedInputFrom, readSeedSnapshot, type PermissionCatalogSnapshot, type SeedRegistrySnapshot } from './input.js';
|
|
4
|
+
export type { PlatformSeedInput, SeedAllowedEmailDelegate, SeedDefaultOrganization, SeedJsonValue, SeedLogger, SeedNamedDelegate, SeedNamedEntry, SeedOrganizationDelegate, SeedPrisma, SeedRowId, SeedRolePermissionDelegate, SeedScope, SeedSummary, SeedSystemSettingsDelegate, SeedUpsertArgs, } from './types.js';
|
|
5
|
+
//# 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,EACL,sBAAsB,EACtB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readSeedSnapshot = exports.platformSeedInputFrom = exports.readSeedStepResult = exports.assertSeedSteps = exports.assertSeedIdempotent = exports.SeedStepError = exports.PLATFORM_SEED_STEP_IDS = 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 steps_js_1 = require("./steps.js");
|
|
8
|
+
Object.defineProperty(exports, "PLATFORM_SEED_STEP_IDS", { enumerable: true, get: function () { return steps_js_1.PLATFORM_SEED_STEP_IDS; } });
|
|
9
|
+
Object.defineProperty(exports, "SeedStepError", { enumerable: true, get: function () { return steps_js_1.SeedStepError; } });
|
|
10
|
+
Object.defineProperty(exports, "assertSeedIdempotent", { enumerable: true, get: function () { return steps_js_1.assertSeedIdempotent; } });
|
|
11
|
+
Object.defineProperty(exports, "assertSeedSteps", { enumerable: true, get: function () { return steps_js_1.assertSeedSteps; } });
|
|
12
|
+
Object.defineProperty(exports, "readSeedStepResult", { enumerable: true, get: function () { return steps_js_1.readSeedStepResult; } });
|
|
13
|
+
var input_js_1 = require("./input.js");
|
|
14
|
+
Object.defineProperty(exports, "platformSeedInputFrom", { enumerable: true, get: function () { return input_js_1.platformSeedInputFrom; } });
|
|
15
|
+
Object.defineProperty(exports, "readSeedSnapshot", { enumerable: true, get: function () { return input_js_1.readSeedSnapshot; } });
|
|
16
|
+
//# 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,uCAYoB;AAXlB,kHAAA,sBAAsB,OAAA;AACtB,yGAAA,aAAa,OAAA;AACb,gHAAA,oBAAoB,OAAA;AACpB,2GAAA,eAAe,OAAA;AACf,8GAAA,kBAAkB,OAAA;AAQpB,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,QAA8B,EAAE,GAAsB;IAC1F,MAAM,KAAK,GAAsB;QAC/B,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK;QACjC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,WAAW;QAC7C,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,eAAe;QAChD,sBA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AO,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,41 @@
|
|
|
1
|
+
import { type SeedPlatformOptions } from './steps.js';
|
|
2
|
+
import type { PlatformSeedInput, SeedLogger, SeedPrisma, SeedSummary } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Seed the platform's roles and permissions (each with its `system` or `org`
|
|
5
|
+
* scope, refreshed on every run like the description), default grants, the `global` system
|
|
6
|
+
* settings row, the initial administrator's allowlist entry and the default
|
|
7
|
+
* organization.
|
|
8
|
+
*
|
|
9
|
+
* Idempotent: every write is an upsert keyed on a natural unique (`name`,
|
|
10
|
+
* `roleId_permissionId`, `key`, `email`), so a second run updates the same
|
|
11
|
+
* rows. It **never deletes**: a permission that left the registry stays as a
|
|
12
|
+
* row until an explicit migration removes it (expand/contract). It never
|
|
13
|
+
* overwrites an admin-edited value either: the settings row and the allowlist
|
|
14
|
+
* row are created with `update: {}`. Writes are sequential, in a fixed order
|
|
15
|
+
* (roles, permissions, grants, settings, allowlist, default organization), so
|
|
16
|
+
* the log reads the same on every run. The default organization is created only
|
|
17
|
+
* when no organization is flagged default (found by `isDefault`, not by slug),
|
|
18
|
+
* so a renamed default is left alone and the one-default index is never hit.
|
|
19
|
+
*
|
|
20
|
+
* App steps (`extras`, see {@link SeedStep}) run after the default organization,
|
|
21
|
+
* in array order, each in its own transaction when the client has
|
|
22
|
+
* `$transaction`, under the same logger: `Seeding <id>...` then
|
|
23
|
+
* `✓ <id>: <created> created, <updated> updated`. They are validated before
|
|
24
|
+
* anything is written, and each must be idempotent ({@link assertSeedIdempotent}
|
|
25
|
+
* proves it).
|
|
26
|
+
*
|
|
27
|
+
* @param prisma - The app's Prisma client, or any object with the delegates of {@link SeedPrisma}.
|
|
28
|
+
* @param input - What to write; see {@link PlatformSeedInput}.
|
|
29
|
+
* @param options - Receives one line per step; default: silent. A bare {@link SeedLogger} (the previous third argument) is still accepted. Or {@link SeedPlatformOptions}: `{ log, extras }`.
|
|
30
|
+
* @returns What the run did.
|
|
31
|
+
* @throws SeedStepError for an invalid extra step, before any write; SeedStepError wrapping what a step threw; whatever the client throws otherwise. Nothing else is caught, so a failed seed fails loudly.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* await seedPlatform(prisma, input, { log: { info: console.log }, extras: [seedCoachDefaults] });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @stability experimental
|
|
39
|
+
*/
|
|
40
|
+
export declare function seedPlatform<Tx = SeedPrisma>(prisma: SeedPrisma, input: PlatformSeedInput, options?: SeedLogger | SeedPlatformOptions<Tx>): Promise<SeedSummary>;
|
|
41
|
+
//# 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,EAAgC,KAAK,mBAAmB,EAAiE,MAAM,YAAY,CAAC;AACnJ,OAAO,KAAK,EAAE,iBAAiB,EAAiB,UAAU,EAAkB,UAAU,EAAa,WAAW,EAAE,MAAM,YAAY,CAAC;AAkBnI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,YAAY,CAAC,EAAE,GAAG,UAAU,EAChD,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE,UAAU,GAAG,mBAAmB,CAAC,EAAE,CAAU,GACrD,OAAO,CAAC,WAAW,CAAC,CAiHtB"}
|