@marinoscar/platform-db 0.1.0-next.3 → 0.1.0-next.4
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 +34 -0
- package/README.md +156 -13
- package/dist/baseline/deps.d.ts.map +1 -1
- package/dist/baseline/deps.js +2 -0
- package/dist/baseline/deps.js.map +1 -1
- package/dist/baseline/errors.d.ts +3 -1
- package/dist/baseline/errors.d.ts.map +1 -1
- package/dist/baseline/errors.js.map +1 -1
- package/dist/baseline/report.d.ts +3 -1
- package/dist/baseline/report.d.ts.map +1 -1
- package/dist/baseline/report.js +4 -0
- package/dist/baseline/report.js.map +1 -1
- package/dist/baseline/run.d.ts +12 -1
- package/dist/baseline/run.d.ts.map +1 -1
- package/dist/baseline/run.js +19 -0
- package/dist/baseline/run.js.map +1 -1
- package/dist/bin/db-commands.d.ts +1 -1
- package/dist/bin/db-commands.d.ts.map +1 -1
- package/dist/bin/db-commands.js +40 -5
- package/dist/bin/db-commands.js.map +1 -1
- 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 +3 -0
- package/dist/drift/db-conformance.d.ts.map +1 -1
- package/dist/drift/db-conformance.js +24 -0
- package/dist/drift/db-conformance.js.map +1 -1
- package/dist/drift/index.d.ts +5 -2
- package/dist/drift/index.d.ts.map +1 -1
- package/dist/drift/index.js +18 -1
- package/dist/drift/index.js.map +1 -1
- package/dist/drift/raw-sql-tripwire.d.ts +44 -3
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -1
- package/dist/drift/raw-sql-tripwire.js +39 -11
- package/dist/drift/raw-sql-tripwire.js.map +1 -1
- 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 +24 -0
- package/dist/drift/run.d.ts.map +1 -1
- package/dist/drift/run.js +52 -1
- package/dist/drift/run.js.map +1 -1
- 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/lock/index.d.ts +1 -1
- package/dist/lock/index.d.ts.map +1 -1
- package/dist/lock/index.js.map +1 -1
- package/dist/lock/lock.d.ts +37 -0
- package/dist/lock/lock.d.ts.map +1 -1
- package/dist/lock/lock.js +11 -0
- package/dist/lock/lock.js.map +1 -1
- package/dist/lock/manifest.d.ts +8 -0
- package/dist/lock/manifest.d.ts.map +1 -1
- package/dist/lock/manifest.js +1 -0
- package/dist/lock/manifest.js.map +1 -1
- package/dist/seed/index.d.ts +1 -0
- package/dist/seed/index.d.ts.map +1 -1
- package/dist/seed/index.js +7 -1
- package/dist/seed/index.js.map +1 -1
- package/dist/seed/seed-platform.d.ts +16 -3
- package/dist/seed/seed-platform.d.ts.map +1 -1
- package/dist/seed/seed-platform.js +37 -5
- package/dist/seed/seed-platform.js.map +1 -1
- 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 +12 -2
- package/dist/seed/types.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/sync/apply.js +1 -0
- package/dist/sync/apply.js.map +1 -1
- package/dist/sync/check.d.ts +5 -2
- package/dist/sync/check.d.ts.map +1 -1
- package/dist/sync/check.js +8 -1
- package/dist/sync/check.js.map +1 -1
- package/dist/sync/errors.d.ts +2 -1
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/index.d.ts +1 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +3 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/plan.d.ts +3 -1
- package/dist/sync/plan.d.ts.map +1 -1
- package/dist/sync/plan.js +9 -2
- package/dist/sync/plan.js.map +1 -1
- package/dist/sync/promote.d.ts +4 -0
- package/dist/sync/promote.d.ts.map +1 -1
- package/dist/sync/promote.js +2 -0
- package/dist/sync/promote.js.map +1 -1
- 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 +139 -0
- package/package.json +5 -2
- package/raw-sql-indexes.json +45 -0
- package/rls-policies.json +74 -0
- package/schema/ai.prisma +59 -2
- package/schema/android-app.prisma +47 -0
- package/schema/credentials.prisma +62 -0
- package/schema/identity.prisma +33 -1
- package/schema/jobs.prisma +36 -7
- package/schema/notifications.prisma +40 -1
- package/schema/settings.prisma +25 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +28 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { ManifestEntry } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A row-level-security policy the package ships, with why it exists. Prisma's
|
|
4
|
+
* schema language cannot express a policy and `prisma migrate diff` ignores it
|
|
5
|
+
* in both directions, so the list is an intentional-drift allow-list like
|
|
6
|
+
* {@link RAW_SQL_INDEXES}: the drift test asserts each policy exists (and that
|
|
7
|
+
* its table has row-level security enabled and forced) and that no other
|
|
8
|
+
* policy does.
|
|
9
|
+
*
|
|
10
|
+
* @stability experimental
|
|
11
|
+
*/
|
|
12
|
+
export interface PackageRlsPolicy {
|
|
13
|
+
/** The policy name (`<table>_org_isolation`). */
|
|
14
|
+
name: string;
|
|
15
|
+
/** The table it protects (the database name, not the Prisma model). */
|
|
16
|
+
table: string;
|
|
17
|
+
/** One line: what the policy enforces. */
|
|
18
|
+
reason: string;
|
|
19
|
+
/** The repository document that explains the invariant, relative to the repository root. */
|
|
20
|
+
doc: string;
|
|
21
|
+
/** The platform migration id (`NNNN_slug`) that first creates it. */
|
|
22
|
+
createdIn: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads the package's `rls-policies.json`.
|
|
26
|
+
*
|
|
27
|
+
* @param file - Path of the JSON file.
|
|
28
|
+
* @returns The policies, in file order.
|
|
29
|
+
* @throws Error when the file is not valid.
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
export declare function readPackageRlsPolicies(file: string): PackageRlsPolicy[];
|
|
33
|
+
/**
|
|
34
|
+
* The package's row-level-security policies: the allow-list of intentional
|
|
35
|
+
* drift that `platform db drift` asserts against `pg_policies` and that
|
|
36
|
+
* {@link assertRlsPolicies} checks against the migrations. Read from the
|
|
37
|
+
* shipped `rls-policies.json`.
|
|
38
|
+
*
|
|
39
|
+
* @stability experimental
|
|
40
|
+
*/
|
|
41
|
+
export declare const RLS_POLICIES: ReadonlyArray<PackageRlsPolicy>;
|
|
42
|
+
/**
|
|
43
|
+
* A policy an app lists in its own `platform.lock` (`rlsPolicies`).
|
|
44
|
+
*
|
|
45
|
+
* @stability experimental
|
|
46
|
+
*/
|
|
47
|
+
export interface RlsPolicyRef {
|
|
48
|
+
/** The policy name. */
|
|
49
|
+
name: string;
|
|
50
|
+
/** The table it protects. */
|
|
51
|
+
table: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A row of `pg_policies`.
|
|
55
|
+
*
|
|
56
|
+
* @stability experimental
|
|
57
|
+
*/
|
|
58
|
+
export interface PolicyRow {
|
|
59
|
+
/** `tablename`. */
|
|
60
|
+
table: string;
|
|
61
|
+
/** `policyname`. */
|
|
62
|
+
name: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The row-level-security flags of one table (`pg_class.relrowsecurity` and `relforcerowsecurity`).
|
|
66
|
+
*
|
|
67
|
+
* @stability experimental
|
|
68
|
+
*/
|
|
69
|
+
export interface TableRlsRow {
|
|
70
|
+
/** The table name. */
|
|
71
|
+
table: string;
|
|
72
|
+
/** `relrowsecurity`. */
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
/** `relforcerowsecurity`. */
|
|
75
|
+
forced: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The class of a policy failure.
|
|
79
|
+
*
|
|
80
|
+
* - `POLICY_MISSING`: a listed policy is not in `pg_policies`.
|
|
81
|
+
* - `POLICY_UNLISTED`: `pg_policies` holds a policy no list names.
|
|
82
|
+
* - `RLS_NOT_ENABLED`: a listed policy's table does not have row-level security enabled.
|
|
83
|
+
* - `RLS_NOT_FORCED`: a listed policy's table does not FORCE it, so the owner (the application role) bypasses the policy.
|
|
84
|
+
* - `RLS_FORCED_WITHOUT_POLICY`: a table forces row-level security but no listed policy protects it (everything would be denied).
|
|
85
|
+
*
|
|
86
|
+
* @stability experimental
|
|
87
|
+
*/
|
|
88
|
+
export type RlsProblemCode = 'POLICY_MISSING' | 'POLICY_UNLISTED' | 'RLS_NOT_ENABLED' | 'RLS_NOT_FORCED' | 'RLS_FORCED_WITHOUT_POLICY';
|
|
89
|
+
/**
|
|
90
|
+
* One row-level-security problem.
|
|
91
|
+
*
|
|
92
|
+
* @stability experimental
|
|
93
|
+
*/
|
|
94
|
+
export interface RlsProblem {
|
|
95
|
+
/** The class of failure. */
|
|
96
|
+
code: RlsProblemCode;
|
|
97
|
+
/** The policy name, or the table for a table-level problem. */
|
|
98
|
+
name: string;
|
|
99
|
+
/** A one-line explanation. */
|
|
100
|
+
message: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The positive assertion of the drift test for policies: every expected policy
|
|
104
|
+
* exists, its table has row-level security enabled AND forced, and nothing else
|
|
105
|
+
* exists (`migrate diff` ignores policies, so a dropped, weakened-by-hand or
|
|
106
|
+
* extra one is invisible to it).
|
|
107
|
+
*
|
|
108
|
+
* @param expected - The package's list plus the app's (`platform.lock` `rlsPolicies`).
|
|
109
|
+
* @param livePolicies - Rows of `pg_policies` for the `public` schema.
|
|
110
|
+
* @param liveTables - Row-level-security flags of every table in the `public` schema.
|
|
111
|
+
* @returns Every problem found.
|
|
112
|
+
* @stability experimental
|
|
113
|
+
*/
|
|
114
|
+
export declare function checkRlsPolicies(expected: ReadonlyArray<RlsPolicyRef>, livePolicies: readonly PolicyRow[], liveTables: readonly TableRlsRow[]): RlsProblem[];
|
|
115
|
+
/**
|
|
116
|
+
* A policy found by reading migration SQL.
|
|
117
|
+
*
|
|
118
|
+
* @stability experimental
|
|
119
|
+
*/
|
|
120
|
+
export interface ScannedPolicy {
|
|
121
|
+
/** The policy name. */
|
|
122
|
+
name: string;
|
|
123
|
+
/** The table, unquoted and without a schema. */
|
|
124
|
+
table: string;
|
|
125
|
+
/** The migration id that first creates a policy of this name on the table. */
|
|
126
|
+
createdIn: string;
|
|
127
|
+
/** The `USING` expression the history leaves (after any `ALTER POLICY`), normalised by {@link normaliseSqlExpression}; absent when the policy has none. */
|
|
128
|
+
using?: string;
|
|
129
|
+
/** The `WITH CHECK` expression the history leaves, normalised the same way; absent when the policy has none. */
|
|
130
|
+
check?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* What a migration history leaves behind for row-level security.
|
|
134
|
+
*
|
|
135
|
+
* @stability experimental
|
|
136
|
+
*/
|
|
137
|
+
export interface ScannedRls {
|
|
138
|
+
/** Policies that survive the whole history, in creation order. */
|
|
139
|
+
policies: ScannedPolicy[];
|
|
140
|
+
/** Tables whose row-level security is enabled at the end of the history. */
|
|
141
|
+
enabled: string[];
|
|
142
|
+
/** Tables whose row-level security is forced at the end of the history. */
|
|
143
|
+
forced: string[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Reads the row-level security a migration history leaves behind, in
|
|
147
|
+
* statement order: `CREATE POLICY` adds a policy, `DROP POLICY` removes it,
|
|
148
|
+
* `ALTER TABLE ... ENABLE|DISABLE|FORCE|NO FORCE ROW LEVEL SECURITY` sets the
|
|
149
|
+
* flags and `DROP TABLE` forgets everything about the table. Comments are
|
|
150
|
+
* ignored.
|
|
151
|
+
*
|
|
152
|
+
* @param migrations - `[id, sql]` pairs in history order.
|
|
153
|
+
* @returns The policies and the enabled and forced tables at the end.
|
|
154
|
+
* @stability experimental
|
|
155
|
+
*/
|
|
156
|
+
export declare function scanRlsPolicies(migrations: ReadonlyArray<readonly [string, string]>): ScannedRls;
|
|
157
|
+
/**
|
|
158
|
+
* The class of a policy tripwire failure.
|
|
159
|
+
*
|
|
160
|
+
* - `UNLISTED_POLICY`: a migration leaves a policy `RLS_POLICIES` does not list.
|
|
161
|
+
* - `LISTED_POLICY_NOT_FOUND`: a listed policy is not left by the migrations.
|
|
162
|
+
* - `LISTED_POLICY_MISMATCH`: the listed `createdIn` disagrees with the migrations.
|
|
163
|
+
* - `POLICY_TABLE_NOT_ENABLED` / `POLICY_TABLE_NOT_FORCED`: a policy's table does not `ENABLE` / `FORCE ROW LEVEL SECURITY` in the migrations.
|
|
164
|
+
*
|
|
165
|
+
* @stability experimental
|
|
166
|
+
*/
|
|
167
|
+
export type RlsTripwireCode = 'UNLISTED_POLICY' | 'LISTED_POLICY_NOT_FOUND' | 'LISTED_POLICY_MISMATCH' | 'POLICY_TABLE_NOT_ENABLED' | 'POLICY_TABLE_NOT_FORCED';
|
|
168
|
+
/**
|
|
169
|
+
* One policy tripwire failure.
|
|
170
|
+
*
|
|
171
|
+
* @stability experimental
|
|
172
|
+
*/
|
|
173
|
+
export interface RlsTripwireProblem {
|
|
174
|
+
/** The class of failure. */
|
|
175
|
+
code: RlsTripwireCode;
|
|
176
|
+
/** The policy name. */
|
|
177
|
+
name: string;
|
|
178
|
+
/** A one-line explanation naming the migration and the fix. */
|
|
179
|
+
message: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* What {@link checkRlsPolicySources} reads.
|
|
183
|
+
*
|
|
184
|
+
* @stability experimental
|
|
185
|
+
*/
|
|
186
|
+
export interface RlsTripwireInput {
|
|
187
|
+
/** The package history, in order. */
|
|
188
|
+
manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[];
|
|
189
|
+
/** Reads a package migration's SQL by directory; `undefined` when it does not exist. */
|
|
190
|
+
readMigration: (dir: string) => string | undefined;
|
|
191
|
+
/** The list to hold the migrations to; default {@link RLS_POLICIES}. */
|
|
192
|
+
listed?: ReadonlyArray<PackageRlsPolicy>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The offline policy tripwire, as a pure function: every policy a migration
|
|
196
|
+
* leaves behind is listed in `RLS_POLICIES`, every listed one is created, and
|
|
197
|
+
* each listed policy's table both enables and forces row-level security.
|
|
198
|
+
*
|
|
199
|
+
* @param input - See {@link RlsTripwireInput}.
|
|
200
|
+
* @returns Every problem found; empty when the tripwire holds.
|
|
201
|
+
* @stability experimental
|
|
202
|
+
*/
|
|
203
|
+
export declare function checkRlsPolicySources(input: RlsTripwireInput): RlsTripwireProblem[];
|
|
204
|
+
/**
|
|
205
|
+
* What {@link assertRlsPolicies} reads from disk.
|
|
206
|
+
*
|
|
207
|
+
* @stability experimental
|
|
208
|
+
*/
|
|
209
|
+
export interface AssertRlsPoliciesOptions {
|
|
210
|
+
/** The package history (`migrations/manifest.json`, parsed). */
|
|
211
|
+
manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[];
|
|
212
|
+
/** The package's `migrations/` directory. */
|
|
213
|
+
migrationsDir: string;
|
|
214
|
+
/** The list to hold the migrations to; default {@link RLS_POLICIES}. */
|
|
215
|
+
listed?: ReadonlyArray<PackageRlsPolicy>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Runs the policy tripwire against the migrations on disk and throws, listing
|
|
219
|
+
* every problem, when it does not hold.
|
|
220
|
+
*
|
|
221
|
+
* @param options - See {@link AssertRlsPoliciesOptions}.
|
|
222
|
+
* @throws Error naming each problem.
|
|
223
|
+
* @stability experimental
|
|
224
|
+
*/
|
|
225
|
+
export declare function assertRlsPolicies(options: AssertRlsPoliciesOptions): void;
|
|
226
|
+
//# sourceMappingURL=rls-policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rls-policies.d.ts","sourceRoot":"","sources":["../../src/drift/rls-policies.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAgBtD;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,GAAG,EAAE,MAAM,CAAC;IACZ,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAYvE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,gBAAgB,CAGxD,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAA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,wBAAwB,GAAG,IAAI,CAezE"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RLS_POLICIES = void 0;
|
|
4
|
+
exports.readPackageRlsPolicies = readPackageRlsPolicies;
|
|
5
|
+
exports.checkRlsPolicies = checkRlsPolicies;
|
|
6
|
+
exports.scanRlsPolicies = scanRlsPolicies;
|
|
7
|
+
exports.checkRlsPolicySources = checkRlsPolicySources;
|
|
8
|
+
exports.assertRlsPolicies = assertRlsPolicies;
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const raw_sql_tripwire_js_1 = require("./raw-sql-tripwire.js");
|
|
13
|
+
const sql_expression_js_1 = require("./sql-expression.js");
|
|
14
|
+
const policySchema = zod_1.z
|
|
15
|
+
.object({
|
|
16
|
+
name: zod_1.z.string().min(1),
|
|
17
|
+
table: zod_1.z.string().min(1),
|
|
18
|
+
reason: zod_1.z.string().min(1),
|
|
19
|
+
doc: zod_1.z.string().min(1),
|
|
20
|
+
createdIn: zod_1.z.string().regex(/^\d{4}_[a-z0-9][a-z0-9_]*$/, 'expected a platform migration id, NNNN_slug'),
|
|
21
|
+
})
|
|
22
|
+
.strict();
|
|
23
|
+
const listSchema = zod_1.z.object({ policies: zod_1.z.array(policySchema) }).strict();
|
|
24
|
+
/**
|
|
25
|
+
* Reads the package's `rls-policies.json`.
|
|
26
|
+
*
|
|
27
|
+
* @param file - Path of the JSON file.
|
|
28
|
+
* @returns The policies, in file order.
|
|
29
|
+
* @throws Error when the file is not valid.
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
function readPackageRlsPolicies(file) {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new Error(`${file} is not valid JSON: ${error.message}`);
|
|
39
|
+
}
|
|
40
|
+
const parsed = listSchema.safeParse(raw);
|
|
41
|
+
if (!parsed.success) {
|
|
42
|
+
throw new Error(`${file} is invalid: ${parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ')}`);
|
|
43
|
+
}
|
|
44
|
+
return parsed.data.policies;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The package's row-level-security policies: the allow-list of intentional
|
|
48
|
+
* drift that `platform db drift` asserts against `pg_policies` and that
|
|
49
|
+
* {@link assertRlsPolicies} checks against the migrations. Read from the
|
|
50
|
+
* shipped `rls-policies.json`.
|
|
51
|
+
*
|
|
52
|
+
* @stability experimental
|
|
53
|
+
*/
|
|
54
|
+
exports.RLS_POLICIES = Object.freeze(
|
|
55
|
+
// `src/drift` and `dist/drift` are both two levels below the package root.
|
|
56
|
+
readPackageRlsPolicies((0, node_path_1.join)(__dirname, '..', '..', 'rls-policies.json')).map((policy) => Object.freeze(policy)));
|
|
57
|
+
/**
|
|
58
|
+
* The positive assertion of the drift test for policies: every expected policy
|
|
59
|
+
* exists, its table has row-level security enabled AND forced, and nothing else
|
|
60
|
+
* exists (`migrate diff` ignores policies, so a dropped, weakened-by-hand or
|
|
61
|
+
* extra one is invisible to it).
|
|
62
|
+
*
|
|
63
|
+
* @param expected - The package's list plus the app's (`platform.lock` `rlsPolicies`).
|
|
64
|
+
* @param livePolicies - Rows of `pg_policies` for the `public` schema.
|
|
65
|
+
* @param liveTables - Row-level-security flags of every table in the `public` schema.
|
|
66
|
+
* @returns Every problem found.
|
|
67
|
+
* @stability experimental
|
|
68
|
+
*/
|
|
69
|
+
function checkRlsPolicies(expected, livePolicies, liveTables) {
|
|
70
|
+
const problems = [];
|
|
71
|
+
const liveKey = new Set(livePolicies.map((row) => `${row.table}\u0000${row.name}`));
|
|
72
|
+
const expectedKey = new Set(expected.map((policy) => `${policy.table}\u0000${policy.name}`));
|
|
73
|
+
const tables = new Map(liveTables.map((row) => [row.table, row]));
|
|
74
|
+
for (const policy of expected) {
|
|
75
|
+
if (!liveKey.has(`${policy.table}\u0000${policy.name}`)) {
|
|
76
|
+
problems.push({ code: 'POLICY_MISSING', name: policy.name, message: `${policy.name}: not in pg_policies on ${policy.table}` });
|
|
77
|
+
}
|
|
78
|
+
const table = tables.get(policy.table);
|
|
79
|
+
if (!table?.enabled) {
|
|
80
|
+
problems.push({ code: 'RLS_NOT_ENABLED', name: policy.table, message: `${policy.table}: row-level security is not enabled, so ${policy.name} does nothing` });
|
|
81
|
+
}
|
|
82
|
+
else if (!table.forced) {
|
|
83
|
+
problems.push({
|
|
84
|
+
code: 'RLS_NOT_FORCED',
|
|
85
|
+
name: policy.table,
|
|
86
|
+
message: `${policy.table}: row-level security is enabled but not FORCED, so the table owner (the application role) ignores ${policy.name}`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const row of livePolicies) {
|
|
91
|
+
if (!expectedKey.has(`${row.table}\u0000${row.name}`)) {
|
|
92
|
+
problems.push({
|
|
93
|
+
code: 'POLICY_UNLISTED',
|
|
94
|
+
name: row.name,
|
|
95
|
+
message: `${row.name}: a policy on ${row.table} that RLS_POLICIES (or platform.lock rlsPolicies) does not list; add it with its reason or drop it`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const protectedTables = new Set(expected.map((policy) => policy.table));
|
|
100
|
+
for (const table of liveTables) {
|
|
101
|
+
if (table.forced && !protectedTables.has(table.table)) {
|
|
102
|
+
problems.push({
|
|
103
|
+
code: 'RLS_FORCED_WITHOUT_POLICY',
|
|
104
|
+
name: table.table,
|
|
105
|
+
message: `${table.table}: row-level security is forced but no listed policy protects it`,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return problems;
|
|
110
|
+
}
|
|
111
|
+
const IDENT = '(?:"[^"]+"|[A-Za-z_][\\w$]*)';
|
|
112
|
+
const QUALIFIED = `${IDENT}(?:\\.${IDENT})?`;
|
|
113
|
+
const CREATE_POLICY = new RegExp(`^CREATE\\s+POLICY\\s+(${IDENT})\\s+ON\\s+(${QUALIFIED})`, 'i');
|
|
114
|
+
const ALTER_POLICY = new RegExp(`^ALTER\\s+POLICY\\s+(${IDENT})\\s+ON\\s+(${QUALIFIED})`, 'i');
|
|
115
|
+
const DROP_POLICY = new RegExp(`^DROP\\s+POLICY\\s+(?:IF\\s+EXISTS\\s+)?(${IDENT})\\s+ON\\s+(${QUALIFIED})`, 'i');
|
|
116
|
+
const ALTER_RLS = new RegExp(`^ALTER\\s+TABLE\\s+(?:IF\\s+EXISTS\\s+)?(?:ONLY\\s+)?(${QUALIFIED})\\s+(ENABLE|DISABLE|FORCE|NO\\s+FORCE)\\s+ROW\\s+LEVEL\\s+SECURITY`, 'i');
|
|
117
|
+
const DROP_TABLE = new RegExp(`^DROP\\s+TABLE\\s+(?:IF\\s+EXISTS\\s+)?(${QUALIFIED})`, 'i');
|
|
118
|
+
const unquote = (ident) => (ident.startsWith('"') ? ident.slice(1, -1) : ident.toLowerCase());
|
|
119
|
+
const unqualify = (qualified) => {
|
|
120
|
+
const parts = qualified.match(new RegExp(IDENT, 'g')) ?? [qualified];
|
|
121
|
+
return unquote(parts[parts.length - 1]);
|
|
122
|
+
};
|
|
123
|
+
/** The `USING (...)` and `WITH CHECK (...)` expressions of a `CREATE POLICY` or `ALTER POLICY` statement, normalised. */
|
|
124
|
+
function policyExpressions(statement) {
|
|
125
|
+
const found = {};
|
|
126
|
+
let depth = 0;
|
|
127
|
+
let quote = '';
|
|
128
|
+
for (let i = 0; i < statement.length; i += 1) {
|
|
129
|
+
const c = statement[i];
|
|
130
|
+
if (quote) {
|
|
131
|
+
if (c === quote)
|
|
132
|
+
quote = '';
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (c === "'" || c === '"') {
|
|
136
|
+
quote = c;
|
|
137
|
+
}
|
|
138
|
+
else if (c === '(') {
|
|
139
|
+
depth += 1;
|
|
140
|
+
}
|
|
141
|
+
else if (c === ')') {
|
|
142
|
+
depth -= 1;
|
|
143
|
+
}
|
|
144
|
+
else if (depth === 0 && !/[\w$]/.test(statement[i - 1] ?? ' ')) {
|
|
145
|
+
const rest = statement.slice(i);
|
|
146
|
+
const keyword = /^(WITH\s+CHECK|USING)\s*\(/i.exec(rest);
|
|
147
|
+
if (keyword) {
|
|
148
|
+
const open = i + keyword[0].length - 1;
|
|
149
|
+
const group = (0, raw_sql_tripwire_js_1.balanced)(statement, open);
|
|
150
|
+
if (!group)
|
|
151
|
+
break;
|
|
152
|
+
const expression = (0, sql_expression_js_1.normaliseSqlExpression)(group.inner);
|
|
153
|
+
if (keyword[1].toUpperCase() === 'USING')
|
|
154
|
+
found.using = expression;
|
|
155
|
+
else
|
|
156
|
+
found.check = expression;
|
|
157
|
+
i = statement.length - group.rest.length - 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return found;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Reads the row-level security a migration history leaves behind, in
|
|
165
|
+
* statement order: `CREATE POLICY` adds a policy, `DROP POLICY` removes it,
|
|
166
|
+
* `ALTER TABLE ... ENABLE|DISABLE|FORCE|NO FORCE ROW LEVEL SECURITY` sets the
|
|
167
|
+
* flags and `DROP TABLE` forgets everything about the table. Comments are
|
|
168
|
+
* ignored.
|
|
169
|
+
*
|
|
170
|
+
* @param migrations - `[id, sql]` pairs in history order.
|
|
171
|
+
* @returns The policies and the enabled and forced tables at the end.
|
|
172
|
+
* @stability experimental
|
|
173
|
+
*/
|
|
174
|
+
function scanRlsPolicies(migrations) {
|
|
175
|
+
const live = new Map();
|
|
176
|
+
const firstCreated = new Map();
|
|
177
|
+
const enabled = new Set();
|
|
178
|
+
const forced = new Set();
|
|
179
|
+
for (const [id, sql] of migrations) {
|
|
180
|
+
for (const statement of (0, raw_sql_tripwire_js_1.splitSqlStatements)(sql)) {
|
|
181
|
+
const create = CREATE_POLICY.exec(statement);
|
|
182
|
+
if (create) {
|
|
183
|
+
const name = unquote(create[1]);
|
|
184
|
+
const table = unqualify(create[2]);
|
|
185
|
+
const key = `${table}\u0000${name}`;
|
|
186
|
+
if (!firstCreated.has(key))
|
|
187
|
+
firstCreated.set(key, id);
|
|
188
|
+
live.set(key, { name, table, createdIn: firstCreated.get(key), ...policyExpressions(statement) });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const alterPolicy = ALTER_POLICY.exec(statement);
|
|
192
|
+
if (alterPolicy) {
|
|
193
|
+
const key = `${unqualify(alterPolicy[2])}\u0000${unquote(alterPolicy[1])}`;
|
|
194
|
+
const existing = live.get(key);
|
|
195
|
+
if (existing) {
|
|
196
|
+
const rename = new RegExp(`^ALTER\\s+POLICY\\s+${IDENT}\\s+ON\\s+${QUALIFIED}\\s+RENAME\\s+TO\\s+(${IDENT})\\s*$`, 'i').exec(statement);
|
|
197
|
+
if (rename) {
|
|
198
|
+
const renamed = unquote(rename[1]);
|
|
199
|
+
live.delete(key);
|
|
200
|
+
firstCreated.set(`${existing.table}\u0000${renamed}`, firstCreated.get(key));
|
|
201
|
+
live.set(`${existing.table}\u0000${renamed}`, { ...existing, name: renamed });
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
live.set(key, { ...existing, ...policyExpressions(statement) });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const drop = DROP_POLICY.exec(statement);
|
|
210
|
+
if (drop) {
|
|
211
|
+
live.delete(`${unqualify(drop[2])}\u0000${unquote(drop[1])}`);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const alter = ALTER_RLS.exec(statement);
|
|
215
|
+
if (alter) {
|
|
216
|
+
const table = unqualify(alter[1]);
|
|
217
|
+
const verb = alter[2].toUpperCase().replace(/\s+/g, ' ');
|
|
218
|
+
if (verb === 'ENABLE')
|
|
219
|
+
enabled.add(table);
|
|
220
|
+
else if (verb === 'DISABLE')
|
|
221
|
+
enabled.delete(table);
|
|
222
|
+
else if (verb === 'FORCE')
|
|
223
|
+
forced.add(table);
|
|
224
|
+
else
|
|
225
|
+
forced.delete(table);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const dropTable = DROP_TABLE.exec(statement);
|
|
229
|
+
if (dropTable) {
|
|
230
|
+
const table = unqualify(dropTable[1]);
|
|
231
|
+
enabled.delete(table);
|
|
232
|
+
forced.delete(table);
|
|
233
|
+
for (const key of [...live.keys()])
|
|
234
|
+
if (key.startsWith(`${table}\u0000`))
|
|
235
|
+
live.delete(key);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { policies: [...live.values()], enabled: [...enabled], forced: [...forced] };
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The offline policy tripwire, as a pure function: every policy a migration
|
|
243
|
+
* leaves behind is listed in `RLS_POLICIES`, every listed one is created, and
|
|
244
|
+
* each listed policy's table both enables and forces row-level security.
|
|
245
|
+
*
|
|
246
|
+
* @param input - See {@link RlsTripwireInput}.
|
|
247
|
+
* @returns Every problem found; empty when the tripwire holds.
|
|
248
|
+
* @stability experimental
|
|
249
|
+
*/
|
|
250
|
+
function checkRlsPolicySources(input) {
|
|
251
|
+
const listed = input.listed ?? exports.RLS_POLICIES;
|
|
252
|
+
const problems = [];
|
|
253
|
+
const migrations = [];
|
|
254
|
+
for (const entry of input.manifest) {
|
|
255
|
+
const sql = input.readMigration(entry.dir);
|
|
256
|
+
if (sql === undefined) {
|
|
257
|
+
problems.push({ code: 'LISTED_POLICY_NOT_FOUND', name: entry.id, message: `${entry.id}: migrations/${entry.dir}/migration.sql does not exist, so it cannot be scanned` });
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
migrations.push([entry.id, sql]);
|
|
261
|
+
}
|
|
262
|
+
const found = scanRlsPolicies(migrations);
|
|
263
|
+
const byKey = new Map(found.policies.map((policy) => [`${policy.table}\u0000${policy.name}`, policy]));
|
|
264
|
+
const listedKeys = new Set(listed.map((policy) => `${policy.table}\u0000${policy.name}`));
|
|
265
|
+
for (const policy of found.policies) {
|
|
266
|
+
if (!listedKeys.has(`${policy.table}\u0000${policy.name}`)) {
|
|
267
|
+
problems.push({
|
|
268
|
+
code: 'UNLISTED_POLICY',
|
|
269
|
+
name: policy.name,
|
|
270
|
+
message: `${policy.name}: ${policy.createdIn} creates a policy on ${policy.table} that RLS_POLICIES does not list; add it to rls-policies.json with its reason`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (const policy of listed) {
|
|
275
|
+
const actual = byKey.get(`${policy.table}\u0000${policy.name}`);
|
|
276
|
+
if (!actual) {
|
|
277
|
+
problems.push({ code: 'LISTED_POLICY_NOT_FOUND', name: policy.name, message: `${policy.name}: listed in RLS_POLICIES but no migration leaves a policy of that name on ${policy.table}` });
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (actual.createdIn !== policy.createdIn) {
|
|
281
|
+
problems.push({ code: 'LISTED_POLICY_MISMATCH', name: policy.name, message: `${policy.name}: the migrations say it is created in ${actual.createdIn} (listed ${policy.createdIn})` });
|
|
282
|
+
}
|
|
283
|
+
if (!found.enabled.includes(policy.table)) {
|
|
284
|
+
problems.push({ code: 'POLICY_TABLE_NOT_ENABLED', name: policy.name, message: `${policy.name}: no migration leaves ${policy.table} with ENABLE ROW LEVEL SECURITY` });
|
|
285
|
+
}
|
|
286
|
+
if (!found.forced.includes(policy.table)) {
|
|
287
|
+
problems.push({ code: 'POLICY_TABLE_NOT_FORCED', name: policy.name, message: `${policy.name}: no migration leaves ${policy.table} with FORCE ROW LEVEL SECURITY, so the application role would bypass the policy` });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return problems;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Runs the policy tripwire against the migrations on disk and throws, listing
|
|
294
|
+
* every problem, when it does not hold.
|
|
295
|
+
*
|
|
296
|
+
* @param options - See {@link AssertRlsPoliciesOptions}.
|
|
297
|
+
* @throws Error naming each problem.
|
|
298
|
+
* @stability experimental
|
|
299
|
+
*/
|
|
300
|
+
function assertRlsPolicies(options) {
|
|
301
|
+
const problems = checkRlsPolicySources({
|
|
302
|
+
manifest: options.manifest,
|
|
303
|
+
readMigration: (dir) => {
|
|
304
|
+
try {
|
|
305
|
+
return (0, node_fs_1.readFileSync)((0, node_path_1.join)(options.migrationsDir, dir, 'migration.sql'), 'utf8');
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
...(options.listed ? { listed: options.listed } : {}),
|
|
312
|
+
});
|
|
313
|
+
if (problems.length > 0) {
|
|
314
|
+
throw new Error(`rls-policies tripwire failed:\n${problems.map((p) => ` ${p.code} ${p.message}`).join('\n')}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=rls-policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rls-policies.js","sourceRoot":"","sources":["../../src/drift/rls-policies.ts"],"names":[],"mappings":";;;AAkDA,wDAYC;AAiGD,4CA6CC;AA6FD,0CA0DC;AAwDD,sDA0CC;AAwBD,8CAeC;AA5eD,qCAAuC;AACvC,yCAAiC;AACjC,6BAAwB;AAExB,+DAAqE;AACrE,2DAA6D;AAE7D,MAAM,YAAY,GAAG,OAAC;KACnB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,GAAG,EAAE,OA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D,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnH,CAAC;AACH,CAAC"}
|
package/dist/drift/run.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RawSqlIndex } from '../lock/index.js';
|
|
2
2
|
import type { LedgerRow } from '../sync/index.js';
|
|
3
3
|
import { type IndexRow, type RawIndexProblem } from './raw-sql-indexes.js';
|
|
4
|
+
import { type PolicyRow, type RlsPolicyRef, type RlsProblem, type TableRlsRow } from './rls-policies.js';
|
|
4
5
|
/**
|
|
5
6
|
* The slice of the `pg` client the platform tools use.
|
|
6
7
|
*
|
|
@@ -34,6 +35,8 @@ export interface DriftOptions {
|
|
|
34
35
|
shadowDatabaseUrl?: string;
|
|
35
36
|
/** Every raw-SQL index to assert (package list plus the app's). */
|
|
36
37
|
rawSqlIndexes: readonly RawSqlIndex[];
|
|
38
|
+
/** Every row-level-security policy to assert (package list plus the app's); omitted: policies are not checked. */
|
|
39
|
+
rlsPolicies?: readonly RlsPolicyRef[];
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* The outcome of {@link runDrift}.
|
|
@@ -47,6 +50,8 @@ export interface DriftResult {
|
|
|
47
50
|
schemaDiff: string;
|
|
48
51
|
/** Missing or changed raw-SQL indexes. */
|
|
49
52
|
indexProblems: RawIndexProblem[];
|
|
53
|
+
/** Missing, extra or unforced row-level-security policies. Empty when policies are not checked. */
|
|
54
|
+
policyProblems: RlsProblem[];
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Resolves the `pg` client constructor from the app, falling back to this package's own copy.
|
|
@@ -124,5 +129,24 @@ export declare function readLedgerRows(databaseUrl: string, cwd: string): Promis
|
|
|
124
129
|
* @stability experimental
|
|
125
130
|
*/
|
|
126
131
|
export declare function runDrift(options: DriftOptions): Promise<DriftResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Reads every policy of the `public` schema (`pg_policies`).
|
|
134
|
+
*
|
|
135
|
+
* @param databaseUrl - Connection string.
|
|
136
|
+
* @param cwd - Where to resolve `pg` from.
|
|
137
|
+
* @returns The table and name of each policy.
|
|
138
|
+
* @stability experimental
|
|
139
|
+
*/
|
|
140
|
+
export declare function readPolicyRows(databaseUrl: string, cwd: string): Promise<PolicyRow[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Reads the row-level-security flags of every ordinary table of the `public`
|
|
143
|
+
* schema (`pg_class.relrowsecurity`, `relforcerowsecurity`).
|
|
144
|
+
*
|
|
145
|
+
* @param databaseUrl - Connection string.
|
|
146
|
+
* @param cwd - Where to resolve `pg` from.
|
|
147
|
+
* @returns One row per table.
|
|
148
|
+
* @stability experimental
|
|
149
|
+
*/
|
|
150
|
+
export declare function readTableRlsRows(databaseUrl: string, cwd: string): Promise<TableRlsRow[]>;
|
|
127
151
|
export {};
|
|
128
152
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/drift/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/drift/run.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/drift/run.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO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