@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.
- package/CHANGELOG.md +40 -0
- package/LICENSE +21 -0
- package/README.md +382 -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 +64 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +34 -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 +125 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +85 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +106 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +339 -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 +276 -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/db-conformance.d.ts +49 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +65 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +5 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +26 -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 +150 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +394 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- package/dist/drift/run.d.ts +128 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +201 -0
- package/dist/drift/run.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 +117 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +140 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +60 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +95 -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 +4 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +10 -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 +28 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +133 -0
- package/dist/seed/seed-platform.js.map +1 -0
- package/dist/seed/types.d.ts +277 -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/apply.d.ts +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +37 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +56 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +108 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +31 -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 +9 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +25 -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 +61 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +79 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +58 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +93 -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/manifest.json +240 -0
- package/package.json +75 -4
- package/raw-sql-indexes.json +49 -0
- package/schema/ai.prisma +387 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +108 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +407 -0
- package/schema/jobs.prisma +731 -0
- package/schema/notifications.prisma +610 -0
- package/schema/settings.prisma +35 -0
- package/schema/storage.prisma +57 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// seedPlatform (issue #712): the platform's idempotent seed, extracted from
|
|
3
|
+
// the reference app's prisma/seed.ts with the same writes, in the same order,
|
|
4
|
+
// under the same console lines.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.seedPlatform = seedPlatform;
|
|
7
|
+
/** The `global` row's key: the one `system_settings` row the platform owns. */
|
|
8
|
+
const GLOBAL_SETTINGS_KEY = 'global';
|
|
9
|
+
/** The default organization when the input names none. Mirrors the migration's backfill row. */
|
|
10
|
+
const DEFAULT_ORGANIZATION = { name: 'Default organization', slug: 'default' };
|
|
11
|
+
/** The note on the initial administrator's allowlist row. */
|
|
12
|
+
const INITIAL_ADMIN_NOTE = 'Initial admin (auto-seeded)';
|
|
13
|
+
const SILENT = { info: () => undefined };
|
|
14
|
+
/** `{ scope }` when the entry declares one, `{}` otherwise (a catalog from before scopes). */
|
|
15
|
+
function scopeOf(entry) {
|
|
16
|
+
return entry.scope ? { scope: entry.scope } : {};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Seed the platform's roles and permissions (each with its `system` or `org`
|
|
20
|
+
* scope, refreshed on every run like the description), default grants, the `global` system
|
|
21
|
+
* settings row, the initial administrator's allowlist entry and the default
|
|
22
|
+
* organization.
|
|
23
|
+
*
|
|
24
|
+
* Idempotent: every write is an upsert keyed on a natural unique (`name`,
|
|
25
|
+
* `roleId_permissionId`, `key`, `email`), so a second run updates the same
|
|
26
|
+
* rows. It **never deletes**: a permission that left the registry stays as a
|
|
27
|
+
* row until an explicit migration removes it (expand/contract). It never
|
|
28
|
+
* overwrites an admin-edited value either: the settings row and the allowlist
|
|
29
|
+
* row are created with `update: {}`. Writes are sequential, in a fixed order
|
|
30
|
+
* (roles, permissions, grants, settings, allowlist, default organization), so
|
|
31
|
+
* the log reads the same on every run. The default organization is created only
|
|
32
|
+
* when no organization is flagged default (found by `isDefault`, not by slug),
|
|
33
|
+
* so a renamed default is left alone and the one-default index is never hit.
|
|
34
|
+
*
|
|
35
|
+
* @param prisma - The app's Prisma client, or any object with the delegates of {@link SeedPrisma}.
|
|
36
|
+
* @param input - What to write; see {@link PlatformSeedInput}.
|
|
37
|
+
* @param log - Receives one line per step. Default: silent.
|
|
38
|
+
* @returns What the run did.
|
|
39
|
+
* @throws Whatever the client throws; nothing is caught, so a failed seed fails loudly.
|
|
40
|
+
*
|
|
41
|
+
* @stability experimental
|
|
42
|
+
*/
|
|
43
|
+
async function seedPlatform(prisma, input, log = SILENT) {
|
|
44
|
+
log.info('Seeding roles...');
|
|
45
|
+
for (const role of input.roles) {
|
|
46
|
+
await prisma.role.upsert({
|
|
47
|
+
where: { name: role.name },
|
|
48
|
+
update: { description: role.description, ...scopeOf(role) },
|
|
49
|
+
create: { name: role.name, description: role.description, ...scopeOf(role) },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
log.info(`✓ Seeded ${input.roles.length} roles`);
|
|
53
|
+
log.info('Seeding permissions...');
|
|
54
|
+
for (const permission of input.permissions) {
|
|
55
|
+
await prisma.permission.upsert({
|
|
56
|
+
where: { name: permission.name },
|
|
57
|
+
update: { description: permission.description, ...scopeOf(permission) },
|
|
58
|
+
create: { name: permission.name, description: permission.description, ...scopeOf(permission) },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
log.info(`✓ Seeded ${input.permissions.length} permissions`);
|
|
62
|
+
log.info('Seeding role-permission mappings...');
|
|
63
|
+
let rolePermissions = 0;
|
|
64
|
+
const skippedGrants = [];
|
|
65
|
+
for (const [roleName, permissionNames] of Object.entries(input.roleGrants)) {
|
|
66
|
+
const role = await prisma.role.findUnique({ where: { name: roleName } });
|
|
67
|
+
if (!role) {
|
|
68
|
+
skippedGrants.push(roleName);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
for (const permissionName of permissionNames) {
|
|
72
|
+
const permission = await prisma.permission.findUnique({ where: { name: permissionName } });
|
|
73
|
+
if (!permission) {
|
|
74
|
+
skippedGrants.push(`${roleName}: ${permissionName}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
await prisma.rolePermission.upsert({
|
|
78
|
+
where: { roleId_permissionId: { roleId: role.id, permissionId: permission.id } },
|
|
79
|
+
update: {},
|
|
80
|
+
create: { roleId: role.id, permissionId: permission.id },
|
|
81
|
+
});
|
|
82
|
+
rolePermissions++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
log.info(`✓ Seeded ${rolePermissions} role-permission mappings`);
|
|
86
|
+
for (const skipped of skippedGrants)
|
|
87
|
+
log.info(`⊘ Skipped grant with no matching row: ${skipped}`);
|
|
88
|
+
log.info('Seeding system settings...');
|
|
89
|
+
await prisma.systemSettings.upsert({
|
|
90
|
+
where: { key: GLOBAL_SETTINGS_KEY },
|
|
91
|
+
update: {}, // Don't overwrite existing settings
|
|
92
|
+
create: { key: GLOBAL_SETTINGS_KEY, value: input.systemSettingsDefaults, version: 1 },
|
|
93
|
+
});
|
|
94
|
+
log.info('✓ Seeded default system settings');
|
|
95
|
+
log.info('Seeding initial admin allowlist...');
|
|
96
|
+
let allowlistedEmail = null;
|
|
97
|
+
if (input.initialAdminEmail) {
|
|
98
|
+
allowlistedEmail = input.initialAdminEmail.toLowerCase();
|
|
99
|
+
await prisma.allowedEmail.upsert({
|
|
100
|
+
where: { email: allowlistedEmail },
|
|
101
|
+
update: {},
|
|
102
|
+
create: { email: allowlistedEmail, notes: INITIAL_ADMIN_NOTE },
|
|
103
|
+
});
|
|
104
|
+
log.info(`✓ Added ${input.initialAdminEmail} to allowlist`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
log.info('⊘ INITIAL_ADMIN_EMAIL not set, skipping allowlist seed');
|
|
108
|
+
}
|
|
109
|
+
log.info('Seeding default organization...');
|
|
110
|
+
const defaultOrganization = input.defaultOrganization ?? DEFAULT_ORGANIZATION;
|
|
111
|
+
const existingDefault = await prisma.organization.findFirst({ where: { isDefault: true } });
|
|
112
|
+
const defaultOrganizationCreated = existingDefault === null;
|
|
113
|
+
if (defaultOrganizationCreated) {
|
|
114
|
+
await prisma.organization.upsert({
|
|
115
|
+
where: { slug: defaultOrganization.slug },
|
|
116
|
+
update: {}, // Don't overwrite an administrator's edits
|
|
117
|
+
create: { name: defaultOrganization.name, slug: defaultOrganization.slug, isDefault: true },
|
|
118
|
+
});
|
|
119
|
+
log.info(`✓ Created default organization "${defaultOrganization.slug}"`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
log.info('✓ Default organization already exists');
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
roles: input.roles.length,
|
|
126
|
+
permissions: input.permissions.length,
|
|
127
|
+
rolePermissions,
|
|
128
|
+
skippedGrants,
|
|
129
|
+
allowlistedEmail,
|
|
130
|
+
defaultOrganizationCreated,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=seed-platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-platform.js","sourceRoot":"","sources":["../../src/seed/seed-platform.ts"],"names":[],"mappings":";AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,gCAAgC;;AA6ChC,oCA4FC;AArID,+EAA+E;AAC/E,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAErC,gGAAgG;AAChG,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,SAAS,EAAW,CAAC;AAExF,6DAA6D;AAC7D,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AAEzD,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;AAErD,8FAA8F;AAC9F,SAAS,OAAO,CAAC,KAAqB;IACpC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACI,KAAK,UAAU,YAAY,CAAC,MAAkB,EAAE,KAAwB,EAAE,MAAkB,MAAM;IACvG,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACvB,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YAC1B,MAAM,EA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AAC,IAAI,EAAE,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;SAC5F,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,mCAAmC,mBAAmB,CAAC,IAAI,GAAG,CAAC,CAAC;IAC3E,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACpD,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM;QACzB,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM;QACrC,eAAe;QACf,aAAa;QACb,gBAAgB;QAChB,0BAA0B;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSON value, the shape of a `SystemSettings.value` column.
|
|
3
|
+
*
|
|
4
|
+
* @stability experimental
|
|
5
|
+
*/
|
|
6
|
+
export type SeedJsonValue = string | number | boolean | null | SeedJsonValue[] | {
|
|
7
|
+
[key: string]: SeedJsonValue;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* What a role or a permission operates: the deployment (`'system'`) or one
|
|
11
|
+
* organization (`'org'`). The values of the `RoleScope` database enum.
|
|
12
|
+
*
|
|
13
|
+
* @stability experimental
|
|
14
|
+
*/
|
|
15
|
+
export type SeedScope = 'system' | 'org';
|
|
16
|
+
/**
|
|
17
|
+
* A role or a permission as the seed writes it.
|
|
18
|
+
*
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
export interface SeedNamedEntry {
|
|
22
|
+
/** The unique name (`admin`, `jobs:read`). */
|
|
23
|
+
name: string;
|
|
24
|
+
/** What it is for; refreshed on every run. */
|
|
25
|
+
description: string;
|
|
26
|
+
/**
|
|
27
|
+
* The scope, refreshed on every run like the description. Optional so a
|
|
28
|
+
* catalog written before scopes existed keeps working: an entry without one
|
|
29
|
+
* is written without one (the column default, `'system'`, applies on create
|
|
30
|
+
* and an existing row keeps its scope).
|
|
31
|
+
*/
|
|
32
|
+
scope?: SeedScope;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Everything `seedPlatform` writes. Every field a later slice adds (org-scoped
|
|
36
|
+
* roles, a default organization) is added as an **optional** field, so a
|
|
37
|
+
* caller written today keeps compiling.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const input = platformSeedInputFrom({ permissions, settings }, process.env);
|
|
42
|
+
* await seedPlatform(prisma, input, { info: console.log });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @extensionPoint option
|
|
46
|
+
* @stability experimental
|
|
47
|
+
*/
|
|
48
|
+
export interface PlatformSeedInput {
|
|
49
|
+
/** Roles, upserted by `name`; the description is updated on every run. */
|
|
50
|
+
roles: ReadonlyArray<SeedNamedEntry>;
|
|
51
|
+
/** Permissions, upserted by `name`; the description is updated on every run. */
|
|
52
|
+
permissions: ReadonlyArray<SeedNamedEntry>;
|
|
53
|
+
/** Default grants: role name to permission names. A name that no row carries is skipped, never created. */
|
|
54
|
+
roleGrants: Readonly<Record<string, readonly string[]>>;
|
|
55
|
+
/** The value of the `global` system settings row, composed from the namespaces. Written once, never overwritten. */
|
|
56
|
+
systemSettingsDefaults: Readonly<Record<string, unknown>>;
|
|
57
|
+
/** The email of the initial administrator. When set, it is added to the allowlist (lower-cased, never updated). */
|
|
58
|
+
initialAdminEmail?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The default organization created when the database has none (default:
|
|
61
|
+
* `Default organization`, slug `default`). Never updated afterwards: an
|
|
62
|
+
* administrator may rename it.
|
|
63
|
+
*/
|
|
64
|
+
defaultOrganization?: SeedDefaultOrganization;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The default organization as the seed creates it.
|
|
68
|
+
*
|
|
69
|
+
* @stability experimental
|
|
70
|
+
*/
|
|
71
|
+
export interface SeedDefaultOrganization {
|
|
72
|
+
/** Display name. */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Unique slug, lower-case `[a-z0-9-]`, 2 to 63 characters. */
|
|
75
|
+
slug: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Where `seedPlatform` reports progress. The package logs nothing by itself.
|
|
79
|
+
*
|
|
80
|
+
* @stability experimental
|
|
81
|
+
*/
|
|
82
|
+
export interface SeedLogger {
|
|
83
|
+
/**
|
|
84
|
+
* Report one line of progress.
|
|
85
|
+
*
|
|
86
|
+
* @param msg - The line, without a trailing newline.
|
|
87
|
+
*/
|
|
88
|
+
info(msg: string): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* What one `seedPlatform` run did.
|
|
92
|
+
*
|
|
93
|
+
* @stability experimental
|
|
94
|
+
*/
|
|
95
|
+
export interface SeedSummary {
|
|
96
|
+
/** Roles upserted. */
|
|
97
|
+
roles: number;
|
|
98
|
+
/** Permissions upserted. */
|
|
99
|
+
permissions: number;
|
|
100
|
+
/** Role-permission grants upserted (a grant naming an unknown role or permission is not counted). */
|
|
101
|
+
rolePermissions: number;
|
|
102
|
+
/** Grants skipped because the role or the permission has no row, as `role: permission` (`role` alone for an unknown role). */
|
|
103
|
+
skippedGrants: string[];
|
|
104
|
+
/** The allowlisted initial administrator (lower-cased), or `null` when none was given. */
|
|
105
|
+
allowlistedEmail: string | null;
|
|
106
|
+
/** True when this run created the default organization; false when one already existed. */
|
|
107
|
+
defaultOrganizationCreated: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The arguments of an upsert, as the seed writes them.
|
|
111
|
+
*
|
|
112
|
+
* @stability experimental
|
|
113
|
+
*/
|
|
114
|
+
export interface SeedUpsertArgs<Where, Update, Create> {
|
|
115
|
+
/** The natural unique the row is found by. */
|
|
116
|
+
where: Where;
|
|
117
|
+
/** What an existing row is updated with (`{}` never overwrites). */
|
|
118
|
+
update: Update;
|
|
119
|
+
/** What a missing row is created with. */
|
|
120
|
+
create: Create;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The delegate of a table the seed upserts by `name` and looks up by `name`
|
|
124
|
+
* (`role`, `permission`).
|
|
125
|
+
*
|
|
126
|
+
* @stability experimental
|
|
127
|
+
*/
|
|
128
|
+
export interface SeedNamedDelegate {
|
|
129
|
+
/**
|
|
130
|
+
* Create the row, or refresh its description.
|
|
131
|
+
*
|
|
132
|
+
* @param args - Keyed on `name`.
|
|
133
|
+
* @returns Anything awaitable.
|
|
134
|
+
*/
|
|
135
|
+
upsert(args: SeedUpsertArgs<{
|
|
136
|
+
name: string;
|
|
137
|
+
}, {
|
|
138
|
+
description: string;
|
|
139
|
+
scope?: SeedScope;
|
|
140
|
+
}, SeedNamedEntry>): PromiseLike<unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* Find the row id by name.
|
|
143
|
+
*
|
|
144
|
+
* @param args - Keyed on `name`.
|
|
145
|
+
* @returns The row, or `null` when none exists.
|
|
146
|
+
*/
|
|
147
|
+
findUnique(args: {
|
|
148
|
+
where: {
|
|
149
|
+
name: string;
|
|
150
|
+
};
|
|
151
|
+
}): PromiseLike<SeedRowId | null>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The only column of a looked-up row the seed reads.
|
|
155
|
+
*
|
|
156
|
+
* @stability experimental
|
|
157
|
+
*/
|
|
158
|
+
export interface SeedRowId {
|
|
159
|
+
/** The row's primary key. */
|
|
160
|
+
id: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The delegate of `role_permissions`.
|
|
164
|
+
*
|
|
165
|
+
* @stability experimental
|
|
166
|
+
*/
|
|
167
|
+
export interface SeedRolePermissionDelegate {
|
|
168
|
+
/**
|
|
169
|
+
* Create the grant when it is missing; an existing grant is left as it is.
|
|
170
|
+
*
|
|
171
|
+
* @param args - Keyed on `roleId_permissionId`.
|
|
172
|
+
* @returns Anything awaitable.
|
|
173
|
+
*/
|
|
174
|
+
upsert(args: SeedUpsertArgs<{
|
|
175
|
+
roleId_permissionId: {
|
|
176
|
+
roleId: string;
|
|
177
|
+
permissionId: string;
|
|
178
|
+
};
|
|
179
|
+
}, Record<string, never>, {
|
|
180
|
+
roleId: string;
|
|
181
|
+
permissionId: string;
|
|
182
|
+
}>): PromiseLike<unknown>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The delegate of `system_settings`.
|
|
186
|
+
*
|
|
187
|
+
* @stability experimental
|
|
188
|
+
*/
|
|
189
|
+
export interface SeedSystemSettingsDelegate {
|
|
190
|
+
/**
|
|
191
|
+
* Create the `global` row when it is missing; an existing row is left as it is.
|
|
192
|
+
*
|
|
193
|
+
* @param args - Keyed on `key`.
|
|
194
|
+
* @returns Anything awaitable.
|
|
195
|
+
*/
|
|
196
|
+
upsert(args: SeedUpsertArgs<{
|
|
197
|
+
key: string;
|
|
198
|
+
}, Record<string, never>, {
|
|
199
|
+
key: string;
|
|
200
|
+
value: {
|
|
201
|
+
[key: string]: SeedJsonValue;
|
|
202
|
+
};
|
|
203
|
+
version: number;
|
|
204
|
+
}>): PromiseLike<unknown>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The delegate of `allowed_emails`.
|
|
208
|
+
*
|
|
209
|
+
* @stability experimental
|
|
210
|
+
*/
|
|
211
|
+
export interface SeedAllowedEmailDelegate {
|
|
212
|
+
/**
|
|
213
|
+
* Create the allowlist entry when it is missing; an existing entry is left as it is.
|
|
214
|
+
*
|
|
215
|
+
* @param args - Keyed on `email`.
|
|
216
|
+
* @returns Anything awaitable.
|
|
217
|
+
*/
|
|
218
|
+
upsert(args: SeedUpsertArgs<{
|
|
219
|
+
email: string;
|
|
220
|
+
}, Record<string, never>, {
|
|
221
|
+
email: string;
|
|
222
|
+
notes: string;
|
|
223
|
+
}>): PromiseLike<unknown>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The delegate of `organizations`.
|
|
227
|
+
*
|
|
228
|
+
* @stability experimental
|
|
229
|
+
*/
|
|
230
|
+
export interface SeedOrganizationDelegate {
|
|
231
|
+
/**
|
|
232
|
+
* Find the default organization, whatever its slug has become.
|
|
233
|
+
*
|
|
234
|
+
* @param args - Filters on `isDefault`.
|
|
235
|
+
* @returns The row, or `null` when none is flagged default.
|
|
236
|
+
*/
|
|
237
|
+
findFirst(args: {
|
|
238
|
+
where: {
|
|
239
|
+
isDefault: true;
|
|
240
|
+
};
|
|
241
|
+
}): PromiseLike<SeedRowId | null>;
|
|
242
|
+
/**
|
|
243
|
+
* Create the default organization when its slug is free; an existing row is left as it is.
|
|
244
|
+
*
|
|
245
|
+
* @param args - Keyed on `slug`.
|
|
246
|
+
* @returns Anything awaitable.
|
|
247
|
+
*/
|
|
248
|
+
upsert(args: SeedUpsertArgs<{
|
|
249
|
+
slug: string;
|
|
250
|
+
}, Record<string, never>, {
|
|
251
|
+
name: string;
|
|
252
|
+
slug: string;
|
|
253
|
+
isDefault: true;
|
|
254
|
+
}>): PromiseLike<unknown>;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The part of a generated Prisma client the seed uses, as a structural type.
|
|
258
|
+
* The package compiles against these types and never imports or bundles a
|
|
259
|
+
* client: pass the app's `PrismaClient` (or a fake in a test).
|
|
260
|
+
*
|
|
261
|
+
* @stability experimental
|
|
262
|
+
*/
|
|
263
|
+
export interface SeedPrisma {
|
|
264
|
+
/** The `roles` table. */
|
|
265
|
+
role: SeedNamedDelegate;
|
|
266
|
+
/** The `permissions` table. */
|
|
267
|
+
permission: SeedNamedDelegate;
|
|
268
|
+
/** The `role_permissions` table. */
|
|
269
|
+
rolePermission: SeedRolePermissionDelegate;
|
|
270
|
+
/** The `system_settings` table. */
|
|
271
|
+
systemSettings: SeedSystemSettingsDelegate;
|
|
272
|
+
/** The `allowed_emails` table. */
|
|
273
|
+
allowedEmail: SeedAllowedEmailDelegate;
|
|
274
|
+
/** The `organizations` table. */
|
|
275
|
+
organization: SeedOrganizationDelegate;
|
|
276
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E,MAAM,CAAA;KAAE,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,IAAI,CAAA;KAAE,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9I;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,IAAI,EAAE,iBAAiB,CAAC;IACxB,+BAA+B;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,oCAAoC;IACpC,cAAc,EAAE,0BAA0B,CAAC;IAC3C,mCAAmC;IACnC,cAAc,EAAE,0BAA0B,CAAC;IAC3C,kCAAkC;IAClC,YAAY,EAAE,wBAAwB,CAAC;IACvC,iCAAiC;IACjC,YAAY,EAAE,wBAAwB,CAAC;CACxC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Types of the platform seed (issue #712). Kept apart from the functions so the
|
|
3
|
+
// structural `SeedPrisma` can be read, and mocked, without importing a client.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/seed/types.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+EAA+E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PlatformLock } from '../lock/index.js';
|
|
2
|
+
import { type SyncPlan } from './plan.js';
|
|
3
|
+
/**
|
|
4
|
+
* The file-system side of {@link applySync}, injectable so the logic is testable.
|
|
5
|
+
*
|
|
6
|
+
* @stability experimental
|
|
7
|
+
*/
|
|
8
|
+
export interface SyncIo {
|
|
9
|
+
/** Reads `<package>/migrations/<packageDir>/migration.sql`. */
|
|
10
|
+
readPackageFile(packageDir: string): Uint8Array;
|
|
11
|
+
/** Creates `prisma/migrations/<localDir>/migration.sql` with exactly these bytes; must throw when the directory already exists. */
|
|
12
|
+
writeLocalMigration(localDir: string, bytes: Uint8Array): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Executes a plan: byte-copies every planned migration into the app and
|
|
16
|
+
* returns the lock to write.
|
|
17
|
+
*
|
|
18
|
+
* Every package file is verified against its manifest hash before the first
|
|
19
|
+
* copy, so a stale or tampered package fails without leaving half an install.
|
|
20
|
+
* Bytes are copied verbatim: never re-encoded, never given a header.
|
|
21
|
+
*
|
|
22
|
+
* @param plan - The result of {@link planSync}.
|
|
23
|
+
* @param io - File access.
|
|
24
|
+
* @returns The new lock (the caller writes it with `serializeLock`).
|
|
25
|
+
* @throws SyncError `PACKAGE_FILE_MISMATCH` before any copy, or `LOCAL_DIR_EXISTS` from the io.
|
|
26
|
+
* @stability experimental
|
|
27
|
+
*/
|
|
28
|
+
export declare function applySync(plan: SyncPlan, io: SyncIo): PlatformLock;
|
|
29
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,+DAA+D;IAC/D,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;IAChD,mIAAmI;IACnI,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAChE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,CAkBlE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySync = applySync;
|
|
4
|
+
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const plan_js_1 = require("./plan.js");
|
|
7
|
+
/**
|
|
8
|
+
* Executes a plan: byte-copies every planned migration into the app and
|
|
9
|
+
* returns the lock to write.
|
|
10
|
+
*
|
|
11
|
+
* Every package file is verified against its manifest hash before the first
|
|
12
|
+
* copy, so a stale or tampered package fails without leaving half an install.
|
|
13
|
+
* Bytes are copied verbatim: never re-encoded, never given a header.
|
|
14
|
+
*
|
|
15
|
+
* @param plan - The result of {@link planSync}.
|
|
16
|
+
* @param io - File access.
|
|
17
|
+
* @returns The new lock (the caller writes it with `serializeLock`).
|
|
18
|
+
* @throws SyncError `PACKAGE_FILE_MISMATCH` before any copy, or `LOCAL_DIR_EXISTS` from the io.
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
function applySync(plan, io) {
|
|
22
|
+
const files = plan.installs.map((install) => {
|
|
23
|
+
const bytes = io.readPackageFile(install.packageDir);
|
|
24
|
+
const actual = (0, index_js_1.sha256Hex)(bytes);
|
|
25
|
+
if (actual !== install.sha256) {
|
|
26
|
+
throw new errors_js_1.SyncError('PACKAGE_FILE_MISMATCH', `${install.originId}: package file hashes to ${actual}, the manifest says ${install.sha256}; the package is corrupt or a released migration was edited`);
|
|
27
|
+
}
|
|
28
|
+
return bytes;
|
|
29
|
+
});
|
|
30
|
+
plan.installs.forEach((install, i) => io.writeLocalMigration(install.localDir, files[i]));
|
|
31
|
+
return {
|
|
32
|
+
...plan.baseLock,
|
|
33
|
+
platformVersion: plan.installs.length ? plan.platformVersion : plan.baseLock.platformVersion,
|
|
34
|
+
migrations: [...plan.baseLock.migrations, ...plan.installs.map(plan_js_1.lockEntryOf)],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=apply.js.map
|
|
@@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@
|
|
|
1
|
+
import { type ManifestEntry, type PlatformLock } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The class of a lock failure; each is named in the command's output.
|
|
4
|
+
*
|
|
5
|
+
* - `LOCAL_MODIFIED`: an installed file's bytes differ from the lock (`localSha256 ?? sha256`).
|
|
6
|
+
* - `PACKAGE_MODIFIED`: the lock's hash differs from the manifest's for the same origin id (a released migration was rewritten).
|
|
7
|
+
* - `PACKAGE_FILE_MODIFIED`: the package's `migration.sql` differs from its manifest hash (or is missing).
|
|
8
|
+
* - `NOT_INSTALLED`: a package migration is not in the lock; run `platform db sync`.
|
|
9
|
+
* - `LOCAL_DIR_MISSING`: a locked `localDir` does not exist.
|
|
10
|
+
* - `NOT_IN_PACKAGE`: the lock names a migration the manifest does not have.
|
|
11
|
+
* - `LOCAL_OUT_OF_ORDER`: installed directories do not sort in package order.
|
|
12
|
+
*
|
|
13
|
+
* @stability experimental
|
|
14
|
+
*/
|
|
15
|
+
export type CheckProblemCode = 'LOCAL_MODIFIED' | 'PACKAGE_MODIFIED' | 'PACKAGE_FILE_MODIFIED' | 'NOT_INSTALLED' | 'LOCAL_DIR_MISSING' | 'NOT_IN_PACKAGE' | 'LOCAL_OUT_OF_ORDER';
|
|
16
|
+
/**
|
|
17
|
+
* One offending migration.
|
|
18
|
+
*
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
export interface CheckProblem {
|
|
22
|
+
/** The class of failure. */
|
|
23
|
+
code: CheckProblemCode;
|
|
24
|
+
/** The origin id of the offending migration. */
|
|
25
|
+
originId: string;
|
|
26
|
+
/** The app-local directory, when there is one. */
|
|
27
|
+
localDir?: string;
|
|
28
|
+
/** A one-line explanation naming the migration and the fix. */
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The outcome of {@link checkLock}.
|
|
33
|
+
*
|
|
34
|
+
* @stability experimental
|
|
35
|
+
*/
|
|
36
|
+
export interface CheckResult {
|
|
37
|
+
/** True when `problems` is empty. */
|
|
38
|
+
ok: boolean;
|
|
39
|
+
/** Every offending migration, locked ones first (lock order), then uninstalled ones. */
|
|
40
|
+
problems: CheckProblem[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `platform db check`, offline half. Read-only and pure apart from the two
|
|
44
|
+
* readers. Fails when a locked migration's local bytes differ from the lock,
|
|
45
|
+
* the lock differs from the manifest, a package migration is not installed, or
|
|
46
|
+
* a locked directory is missing.
|
|
47
|
+
*
|
|
48
|
+
* @param manifest - The package history.
|
|
49
|
+
* @param lock - The app's `platform.lock`.
|
|
50
|
+
* @param readLocal - Reads `prisma/migrations/<localDir>/migration.sql`; returns `undefined` when the directory or file does not exist.
|
|
51
|
+
* @param readPackage - Optional: reads the package's actual `migration.sql` so a file edited without its manifest hash is also caught; `undefined` means missing.
|
|
52
|
+
* @returns Every problem found; `ok` when there is none.
|
|
53
|
+
* @stability experimental
|
|
54
|
+
*/
|
|
55
|
+
export declare function checkLock(manifest: readonly ManifestEntry[], lock: PlatformLock, readLocal: (localDir: string) => Uint8Array | undefined, readPackage?: (packageDir: string) => Uint8Array | undefined): CheckResult;
|
|
56
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhG;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,oBAAoB,CAAC;AAEzB;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,gBAAgB,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,wFAAwF;IACxF,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EACvD,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,GAC3D,WAAW,CA0Fb"}
|