@vrplatform/kysely 1.3.45-6301 → 1.3.45-6332
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/build/main/control-plane/index.d.ts +106 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/local/index.js +1 -0
- package/build/main/local/index.js.map +1 -1
- package/build/main/v1.generated.d.ts +26 -0
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
- package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
- package/build/module/control-plane/index.d.ts +106 -0
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/local/index.js +1 -0
- package/build/module/local/index.js.map +1 -1
- package/build/module/v1.generated.d.ts +26 -0
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create table public.line_classification_usage (
|
|
7
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
8
|
+
kind text not null,
|
|
9
|
+
name text not null,
|
|
10
|
+
app_id text,
|
|
11
|
+
mapping_status text,
|
|
12
|
+
first_seen_at timestamptz not null default now(),
|
|
13
|
+
last_seen_at timestamptz not null default now(),
|
|
14
|
+
revision integer not null default 1,
|
|
15
|
+
reported_revision integer not null default 0,
|
|
16
|
+
report_attempts integer not null default 0,
|
|
17
|
+
last_error text,
|
|
18
|
+
created_at timestamptz not null default now(),
|
|
19
|
+
updated_at timestamptz not null default now(),
|
|
20
|
+
primary key (tenant_id, kind, name),
|
|
21
|
+
constraint line_classification_usage_kind_check
|
|
22
|
+
check (kind in ('paymentLine', 'reservationLine')),
|
|
23
|
+
constraint line_classification_usage_mapping_status_check
|
|
24
|
+
check (
|
|
25
|
+
mapping_status is null or
|
|
26
|
+
mapping_status in ('excluded', 'mapped', 'unmapped')
|
|
27
|
+
),
|
|
28
|
+
constraint line_classification_usage_revision_check check (revision > 0),
|
|
29
|
+
constraint line_classification_usage_reported_revision_check
|
|
30
|
+
check (reported_revision >= 0 and reported_revision <= revision),
|
|
31
|
+
constraint line_classification_usage_report_attempts_check
|
|
32
|
+
check (report_attempts >= 0)
|
|
33
|
+
);
|
|
34
|
+
`.execute(db);
|
|
35
|
+
|
|
36
|
+
await sql`
|
|
37
|
+
create index line_classification_usage_pending_idx
|
|
38
|
+
on public.line_classification_usage (updated_at, tenant_id, kind, name)
|
|
39
|
+
where reported_revision < revision;
|
|
40
|
+
`.execute(db);
|
|
41
|
+
|
|
42
|
+
await sql`
|
|
43
|
+
create table public.line_classification_usage_backfill (
|
|
44
|
+
source text primary key,
|
|
45
|
+
cursor_id uuid,
|
|
46
|
+
completed_at timestamptz,
|
|
47
|
+
updated_at timestamptz not null default now(),
|
|
48
|
+
constraint line_classification_usage_backfill_source_check
|
|
49
|
+
check (source in ('paymentLine', 'transactionLine'))
|
|
50
|
+
);
|
|
51
|
+
`.execute(db);
|
|
52
|
+
|
|
53
|
+
await sql`
|
|
54
|
+
insert into public.line_classification_usage_backfill (source)
|
|
55
|
+
values ('paymentLine'), ('transactionLine');
|
|
56
|
+
`.execute(db);
|
|
57
|
+
|
|
58
|
+
await sql`
|
|
59
|
+
create or replace function public.capture_line_classification_usage()
|
|
60
|
+
returns trigger
|
|
61
|
+
language plpgsql
|
|
62
|
+
as $$
|
|
63
|
+
begin
|
|
64
|
+
insert into public.line_classification_usage (
|
|
65
|
+
tenant_id,
|
|
66
|
+
kind,
|
|
67
|
+
name,
|
|
68
|
+
app_id,
|
|
69
|
+
mapping_status,
|
|
70
|
+
first_seen_at,
|
|
71
|
+
last_seen_at
|
|
72
|
+
)
|
|
73
|
+
select distinct
|
|
74
|
+
line.tenant_id,
|
|
75
|
+
case
|
|
76
|
+
when line.reservation_id is not null and line.payment_id is null
|
|
77
|
+
then 'reservationLine'
|
|
78
|
+
when line.payment_id is not null then 'paymentLine'
|
|
79
|
+
when classification.type in ('paymentLine', 'reservationLine')
|
|
80
|
+
then classification.type
|
|
81
|
+
end,
|
|
82
|
+
coalesce(line.effective_type, line.type),
|
|
83
|
+
coalesce(
|
|
84
|
+
classification.app_id,
|
|
85
|
+
app.id
|
|
86
|
+
),
|
|
87
|
+
case
|
|
88
|
+
when (
|
|
89
|
+
line.reservation_id is not null and line.payment_id is null
|
|
90
|
+
) or classification.type = 'reservationLine' then
|
|
91
|
+
case
|
|
92
|
+
when mapping.id is null then 'unmapped'
|
|
93
|
+
when mapping.account_id is null then 'excluded'
|
|
94
|
+
else 'mapped'
|
|
95
|
+
end
|
|
96
|
+
else null
|
|
97
|
+
end,
|
|
98
|
+
now(),
|
|
99
|
+
now()
|
|
100
|
+
from new_payment_lines as line
|
|
101
|
+
left join public.payment_line_classification as classification
|
|
102
|
+
on classification.name = coalesce(line.effective_type, line.type)
|
|
103
|
+
left join public.app as app
|
|
104
|
+
on lower(app.id) = lower(
|
|
105
|
+
split_part(coalesce(line.effective_type, line.type), '_', 1)
|
|
106
|
+
)
|
|
107
|
+
and app.category = 'propertyManagementSystem'
|
|
108
|
+
left join accounting.account_reservation_line_type as mapping
|
|
109
|
+
on mapping.tenant_id = line.tenant_id
|
|
110
|
+
and mapping.line_type = coalesce(line.effective_type, line.type)
|
|
111
|
+
and mapping.booking_channel is null
|
|
112
|
+
where line.tenant_id is not null
|
|
113
|
+
and coalesce(line.effective_type, line.type) is not null
|
|
114
|
+
and coalesce(line.effective_type, line.type) != ''
|
|
115
|
+
and (
|
|
116
|
+
(line.reservation_id is not null and line.payment_id is null) or
|
|
117
|
+
line.payment_id is not null or
|
|
118
|
+
classification.type in ('paymentLine', 'reservationLine')
|
|
119
|
+
)
|
|
120
|
+
on conflict (tenant_id, kind, name) do update
|
|
121
|
+
set
|
|
122
|
+
app_id = coalesce(
|
|
123
|
+
excluded.app_id,
|
|
124
|
+
public.line_classification_usage.app_id
|
|
125
|
+
),
|
|
126
|
+
mapping_status = excluded.mapping_status,
|
|
127
|
+
last_seen_at = case
|
|
128
|
+
when public.line_classification_usage.app_id is distinct from
|
|
129
|
+
coalesce(
|
|
130
|
+
excluded.app_id,
|
|
131
|
+
public.line_classification_usage.app_id
|
|
132
|
+
) or
|
|
133
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
134
|
+
excluded.mapping_status or
|
|
135
|
+
public.line_classification_usage.last_seen_at <
|
|
136
|
+
excluded.last_seen_at - interval '1 hour'
|
|
137
|
+
then greatest(
|
|
138
|
+
public.line_classification_usage.last_seen_at,
|
|
139
|
+
excluded.last_seen_at
|
|
140
|
+
)
|
|
141
|
+
else public.line_classification_usage.last_seen_at
|
|
142
|
+
end,
|
|
143
|
+
revision = case
|
|
144
|
+
when public.line_classification_usage.app_id is distinct from
|
|
145
|
+
coalesce(
|
|
146
|
+
excluded.app_id,
|
|
147
|
+
public.line_classification_usage.app_id
|
|
148
|
+
) or
|
|
149
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
150
|
+
excluded.mapping_status or
|
|
151
|
+
public.line_classification_usage.last_seen_at <
|
|
152
|
+
excluded.last_seen_at - interval '1 hour'
|
|
153
|
+
then public.line_classification_usage.revision + 1
|
|
154
|
+
else public.line_classification_usage.revision
|
|
155
|
+
end,
|
|
156
|
+
updated_at = case
|
|
157
|
+
when public.line_classification_usage.app_id is distinct from
|
|
158
|
+
coalesce(
|
|
159
|
+
excluded.app_id,
|
|
160
|
+
public.line_classification_usage.app_id
|
|
161
|
+
) or
|
|
162
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
163
|
+
excluded.mapping_status or
|
|
164
|
+
public.line_classification_usage.last_seen_at <
|
|
165
|
+
excluded.last_seen_at - interval '1 hour'
|
|
166
|
+
then now()
|
|
167
|
+
else public.line_classification_usage.updated_at
|
|
168
|
+
end;
|
|
169
|
+
return null;
|
|
170
|
+
end;
|
|
171
|
+
$$;
|
|
172
|
+
`.execute(db);
|
|
173
|
+
|
|
174
|
+
await sql`
|
|
175
|
+
create trigger payment_line_classification_usage_insert
|
|
176
|
+
after insert on public.payment_line
|
|
177
|
+
referencing new table as new_payment_lines
|
|
178
|
+
for each statement
|
|
179
|
+
execute function public.capture_line_classification_usage();
|
|
180
|
+
`.execute(db);
|
|
181
|
+
|
|
182
|
+
await sql`
|
|
183
|
+
create trigger payment_line_classification_usage_update
|
|
184
|
+
after update on public.payment_line
|
|
185
|
+
referencing new table as new_payment_lines
|
|
186
|
+
for each statement
|
|
187
|
+
execute function public.capture_line_classification_usage();
|
|
188
|
+
`.execute(db);
|
|
189
|
+
|
|
190
|
+
await sql`
|
|
191
|
+
create or replace function public.capture_transaction_line_classification_usage()
|
|
192
|
+
returns trigger
|
|
193
|
+
language plpgsql
|
|
194
|
+
as $$
|
|
195
|
+
begin
|
|
196
|
+
insert into public.line_classification_usage (
|
|
197
|
+
tenant_id,
|
|
198
|
+
kind,
|
|
199
|
+
name,
|
|
200
|
+
app_id,
|
|
201
|
+
mapping_status,
|
|
202
|
+
first_seen_at,
|
|
203
|
+
last_seen_at
|
|
204
|
+
)
|
|
205
|
+
select
|
|
206
|
+
line.tenant_id,
|
|
207
|
+
'paymentLine',
|
|
208
|
+
line.match_line_type_classification,
|
|
209
|
+
coalesce(classification.app_id, app.id),
|
|
210
|
+
null,
|
|
211
|
+
min(line.created_at),
|
|
212
|
+
max(line.updated_at)
|
|
213
|
+
from new_transaction_lines as line
|
|
214
|
+
left join public.payment_line_classification as classification
|
|
215
|
+
on classification.name = line.match_line_type_classification
|
|
216
|
+
left join public.app as app
|
|
217
|
+
on lower(app.id) = lower(
|
|
218
|
+
split_part(line.match_line_type_classification, '_', 1)
|
|
219
|
+
)
|
|
220
|
+
and app.category = 'propertyManagementSystem'
|
|
221
|
+
where line.match_line_type_classification is not null
|
|
222
|
+
and line.match_line_type_classification != ''
|
|
223
|
+
group by
|
|
224
|
+
line.tenant_id,
|
|
225
|
+
line.match_line_type_classification,
|
|
226
|
+
coalesce(classification.app_id, app.id)
|
|
227
|
+
on conflict (tenant_id, kind, name) do update
|
|
228
|
+
set
|
|
229
|
+
app_id = coalesce(
|
|
230
|
+
excluded.app_id,
|
|
231
|
+
public.line_classification_usage.app_id
|
|
232
|
+
),
|
|
233
|
+
first_seen_at = least(
|
|
234
|
+
public.line_classification_usage.first_seen_at,
|
|
235
|
+
excluded.first_seen_at
|
|
236
|
+
),
|
|
237
|
+
last_seen_at = case
|
|
238
|
+
when public.line_classification_usage.app_id is distinct from
|
|
239
|
+
coalesce(
|
|
240
|
+
excluded.app_id,
|
|
241
|
+
public.line_classification_usage.app_id
|
|
242
|
+
) or
|
|
243
|
+
public.line_classification_usage.last_seen_at <
|
|
244
|
+
excluded.last_seen_at - interval '1 hour'
|
|
245
|
+
then greatest(
|
|
246
|
+
public.line_classification_usage.last_seen_at,
|
|
247
|
+
excluded.last_seen_at
|
|
248
|
+
)
|
|
249
|
+
else public.line_classification_usage.last_seen_at
|
|
250
|
+
end,
|
|
251
|
+
revision = case
|
|
252
|
+
when public.line_classification_usage.app_id is distinct from
|
|
253
|
+
coalesce(
|
|
254
|
+
excluded.app_id,
|
|
255
|
+
public.line_classification_usage.app_id
|
|
256
|
+
) or
|
|
257
|
+
public.line_classification_usage.last_seen_at <
|
|
258
|
+
excluded.last_seen_at - interval '1 hour'
|
|
259
|
+
then public.line_classification_usage.revision + 1
|
|
260
|
+
else public.line_classification_usage.revision
|
|
261
|
+
end,
|
|
262
|
+
updated_at = case
|
|
263
|
+
when public.line_classification_usage.app_id is distinct from
|
|
264
|
+
coalesce(
|
|
265
|
+
excluded.app_id,
|
|
266
|
+
public.line_classification_usage.app_id
|
|
267
|
+
) or
|
|
268
|
+
public.line_classification_usage.last_seen_at <
|
|
269
|
+
excluded.last_seen_at - interval '1 hour'
|
|
270
|
+
then now()
|
|
271
|
+
else public.line_classification_usage.updated_at
|
|
272
|
+
end;
|
|
273
|
+
return null;
|
|
274
|
+
end;
|
|
275
|
+
$$;
|
|
276
|
+
`.execute(db);
|
|
277
|
+
|
|
278
|
+
await sql`
|
|
279
|
+
create trigger transaction_line_classification_usage_insert
|
|
280
|
+
after insert on accounting.transaction_line
|
|
281
|
+
referencing new table as new_transaction_lines
|
|
282
|
+
for each statement
|
|
283
|
+
execute function public.capture_transaction_line_classification_usage();
|
|
284
|
+
`.execute(db);
|
|
285
|
+
|
|
286
|
+
await sql`
|
|
287
|
+
create trigger transaction_line_classification_usage_update
|
|
288
|
+
after update on accounting.transaction_line
|
|
289
|
+
referencing new table as new_transaction_lines
|
|
290
|
+
for each statement
|
|
291
|
+
execute function public.capture_transaction_line_classification_usage();
|
|
292
|
+
`.execute(db);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
296
|
+
await sql`
|
|
297
|
+
drop trigger if exists transaction_line_classification_usage_update
|
|
298
|
+
on accounting.transaction_line;
|
|
299
|
+
`.execute(db);
|
|
300
|
+
await sql`
|
|
301
|
+
drop trigger if exists transaction_line_classification_usage_insert
|
|
302
|
+
on accounting.transaction_line;
|
|
303
|
+
`.execute(db);
|
|
304
|
+
await sql`
|
|
305
|
+
drop function if exists
|
|
306
|
+
public.capture_transaction_line_classification_usage();
|
|
307
|
+
`.execute(db);
|
|
308
|
+
await sql`
|
|
309
|
+
drop trigger if exists payment_line_classification_usage_update
|
|
310
|
+
on public.payment_line;
|
|
311
|
+
`.execute(db);
|
|
312
|
+
await sql`
|
|
313
|
+
drop trigger if exists payment_line_classification_usage_insert
|
|
314
|
+
on public.payment_line;
|
|
315
|
+
`.execute(db);
|
|
316
|
+
await sql`
|
|
317
|
+
drop function if exists public.capture_line_classification_usage();
|
|
318
|
+
`.execute(db);
|
|
319
|
+
await sql`
|
|
320
|
+
drop table if exists public.line_classification_usage_backfill;
|
|
321
|
+
`.execute(db);
|
|
322
|
+
await sql`
|
|
323
|
+
drop table if exists public.line_classification_usage;
|
|
324
|
+
`.execute(db);
|
|
325
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<Record<string, never>>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
alter table public.tenant
|
|
7
|
+
add column migration_status text not null default 'active',
|
|
8
|
+
add column migrated_to_region text null,
|
|
9
|
+
add column migrated_at timestamp with time zone null,
|
|
10
|
+
add constraint tenant_migration_status_check
|
|
11
|
+
check (migration_status in ('active', 'frozen', 'migrated')),
|
|
12
|
+
add constraint tenant_migrated_target_check
|
|
13
|
+
check (
|
|
14
|
+
(migration_status = 'migrated' and migrated_to_region is not null and migrated_at is not null)
|
|
15
|
+
or
|
|
16
|
+
(migration_status <> 'migrated' and migrated_to_region is null and migrated_at is null)
|
|
17
|
+
),
|
|
18
|
+
add constraint tenant_migrated_to_region_check
|
|
19
|
+
check (
|
|
20
|
+
migrated_to_region is null
|
|
21
|
+
or migrated_to_region in ('ap', 'crunchy', 'eu', 'hostaway', 'us')
|
|
22
|
+
);
|
|
23
|
+
`.execute(db);
|
|
24
|
+
|
|
25
|
+
await sql`
|
|
26
|
+
do $$
|
|
27
|
+
declare
|
|
28
|
+
constraint_row record;
|
|
29
|
+
begin
|
|
30
|
+
for constraint_row in
|
|
31
|
+
select
|
|
32
|
+
namespace.nspname as schema_name,
|
|
33
|
+
class.relname as table_name,
|
|
34
|
+
constraint_record.conname as constraint_name
|
|
35
|
+
from pg_constraint constraint_record
|
|
36
|
+
inner join pg_class class on class.oid = constraint_record.conrelid
|
|
37
|
+
inner join pg_namespace namespace on namespace.oid = class.relnamespace
|
|
38
|
+
where constraint_record.contype = 'f'
|
|
39
|
+
and not constraint_record.condeferrable
|
|
40
|
+
and namespace.nspname in (
|
|
41
|
+
'accounting',
|
|
42
|
+
'audit',
|
|
43
|
+
'core',
|
|
44
|
+
'health',
|
|
45
|
+
'public',
|
|
46
|
+
'tracking',
|
|
47
|
+
'webhook'
|
|
48
|
+
)
|
|
49
|
+
loop
|
|
50
|
+
execute format(
|
|
51
|
+
'alter table %I.%I alter constraint %I deferrable initially immediate',
|
|
52
|
+
constraint_row.schema_name,
|
|
53
|
+
constraint_row.table_name,
|
|
54
|
+
constraint_row.constraint_name
|
|
55
|
+
);
|
|
56
|
+
end loop;
|
|
57
|
+
end
|
|
58
|
+
$$;
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function down(db: Kysely<Record<string, never>>): Promise<void> {
|
|
63
|
+
await sql`
|
|
64
|
+
do $$
|
|
65
|
+
declare
|
|
66
|
+
constraint_row record;
|
|
67
|
+
begin
|
|
68
|
+
for constraint_row in
|
|
69
|
+
select
|
|
70
|
+
namespace.nspname as schema_name,
|
|
71
|
+
class.relname as table_name,
|
|
72
|
+
constraint_record.conname as constraint_name
|
|
73
|
+
from pg_constraint constraint_record
|
|
74
|
+
inner join pg_class class on class.oid = constraint_record.conrelid
|
|
75
|
+
inner join pg_namespace namespace on namespace.oid = class.relnamespace
|
|
76
|
+
where constraint_record.contype = 'f'
|
|
77
|
+
and constraint_record.condeferrable
|
|
78
|
+
and namespace.nspname in (
|
|
79
|
+
'accounting',
|
|
80
|
+
'audit',
|
|
81
|
+
'core',
|
|
82
|
+
'health',
|
|
83
|
+
'public',
|
|
84
|
+
'tracking',
|
|
85
|
+
'webhook'
|
|
86
|
+
)
|
|
87
|
+
loop
|
|
88
|
+
execute format(
|
|
89
|
+
'alter table %I.%I alter constraint %I not deferrable',
|
|
90
|
+
constraint_row.schema_name,
|
|
91
|
+
constraint_row.table_name,
|
|
92
|
+
constraint_row.constraint_name
|
|
93
|
+
);
|
|
94
|
+
end loop;
|
|
95
|
+
end
|
|
96
|
+
$$;
|
|
97
|
+
`.execute(db);
|
|
98
|
+
|
|
99
|
+
await sql`
|
|
100
|
+
alter table public.tenant
|
|
101
|
+
drop constraint tenant_migrated_to_region_check,
|
|
102
|
+
drop constraint tenant_migrated_target_check,
|
|
103
|
+
drop constraint tenant_migration_status_check,
|
|
104
|
+
drop column migrated_at,
|
|
105
|
+
drop column migrated_to_region,
|
|
106
|
+
drop column migration_status;
|
|
107
|
+
`.execute(db);
|
|
108
|
+
}
|
|
@@ -119,6 +119,25 @@ export interface ControlPlaneFeatureApproval {
|
|
|
119
119
|
updatedAt: Generated<Timestamp>;
|
|
120
120
|
userId: string;
|
|
121
121
|
}
|
|
122
|
+
export interface ControlPlaneFlow {
|
|
123
|
+
appId: string;
|
|
124
|
+
createdAt: Generated<Timestamp>;
|
|
125
|
+
description: string | null;
|
|
126
|
+
eventListening: Generated<Json>;
|
|
127
|
+
id: Generated<string>;
|
|
128
|
+
isPublic: Generated<boolean>;
|
|
129
|
+
leftType: string | null;
|
|
130
|
+
mappingSchema: Generated<Json>;
|
|
131
|
+
revision: Generated<number>;
|
|
132
|
+
rightType: string | null;
|
|
133
|
+
runSchema: Generated<Json>;
|
|
134
|
+
settingSchema: Generated<Json>;
|
|
135
|
+
title: string;
|
|
136
|
+
type: 'pull' | 'push' | null;
|
|
137
|
+
uniqueRef: string;
|
|
138
|
+
updatedAt: Generated<Timestamp>;
|
|
139
|
+
useGlobalMapping: Generated<boolean>;
|
|
140
|
+
}
|
|
122
141
|
export interface ControlPlaneIssueMessageOverwrite {
|
|
123
142
|
createdAt: Generated<Timestamp>;
|
|
124
143
|
id: Generated<string>;
|
|
@@ -126,6 +145,69 @@ export interface ControlPlaneIssueMessageOverwrite {
|
|
|
126
145
|
pattern: string;
|
|
127
146
|
updatedAt: Generated<Timestamp>;
|
|
128
147
|
}
|
|
148
|
+
export interface ControlPlaneLineClassification {
|
|
149
|
+
appConflict: Generated<boolean>;
|
|
150
|
+
appId: string | null;
|
|
151
|
+
createdAt: Generated<Timestamp>;
|
|
152
|
+
firstSeenAt: Timestamp;
|
|
153
|
+
id: Generated<string>;
|
|
154
|
+
kind: string;
|
|
155
|
+
lastSeenAt: Timestamp;
|
|
156
|
+
name: string;
|
|
157
|
+
updatedAt: Generated<Timestamp>;
|
|
158
|
+
}
|
|
159
|
+
export interface ControlPlaneLineClassificationTeamUsage {
|
|
160
|
+
classificationId: string;
|
|
161
|
+
createdAt: Generated<Timestamp>;
|
|
162
|
+
dataRegion: string;
|
|
163
|
+
firstSeenAt: Timestamp;
|
|
164
|
+
lastSeenAt: Timestamp;
|
|
165
|
+
mappingStatus: string | null;
|
|
166
|
+
revision: number;
|
|
167
|
+
tenantId: string;
|
|
168
|
+
updatedAt: Generated<Timestamp>;
|
|
169
|
+
}
|
|
170
|
+
export interface ControlPlaneReservationLineDefault {
|
|
171
|
+
accountKey: string | null;
|
|
172
|
+
bookingChannel: string | null;
|
|
173
|
+
bookingChannelKey: Generated<string>;
|
|
174
|
+
classificationId: string;
|
|
175
|
+
createdAt: Generated<Timestamp>;
|
|
176
|
+
id: Generated<string>;
|
|
177
|
+
partnerTenantId: string | null;
|
|
178
|
+
revenueRecognition: string | null;
|
|
179
|
+
revision: Generated<number>;
|
|
180
|
+
updatedAt: Generated<Timestamp>;
|
|
181
|
+
}
|
|
182
|
+
export interface ControlPlaneTransactionLineMapping {
|
|
183
|
+
accountAssignmentType: string | null;
|
|
184
|
+
createdAt: Generated<Timestamp>;
|
|
185
|
+
deletedAt: Timestamp | null;
|
|
186
|
+
id: Generated<string>;
|
|
187
|
+
lineType: string;
|
|
188
|
+
revision: Generated<number>;
|
|
189
|
+
updatedAt: Generated<Timestamp>;
|
|
190
|
+
}
|
|
191
|
+
export interface ControlPlaneGeneralLedgerDefaultSet {
|
|
192
|
+
createdAt: Generated<Timestamp>;
|
|
193
|
+
id: Generated<string>;
|
|
194
|
+
partnerTenantId: string | null;
|
|
195
|
+
publishedVersion: number | null;
|
|
196
|
+
sourceDataRegion: string;
|
|
197
|
+
sourceDigest: string | null;
|
|
198
|
+
sourceTenantId: string;
|
|
199
|
+
templateKey: string;
|
|
200
|
+
updatedAt: Generated<Timestamp>;
|
|
201
|
+
}
|
|
202
|
+
export interface ControlPlaneGeneralLedgerDefaultVersion {
|
|
203
|
+
dataJson: Json;
|
|
204
|
+
defaultSetId: string;
|
|
205
|
+
id: Generated<string>;
|
|
206
|
+
publishedAt: Generated<Timestamp>;
|
|
207
|
+
sourceDigest: string;
|
|
208
|
+
sourceTenantId: string;
|
|
209
|
+
version: number;
|
|
210
|
+
}
|
|
129
211
|
export interface ControlPlaneOutbox {
|
|
130
212
|
aggregateId: string;
|
|
131
213
|
aggregateType: string;
|
|
@@ -151,6 +233,7 @@ export interface ControlPlaneTenant {
|
|
|
151
233
|
createdAt: Generated<Timestamp>;
|
|
152
234
|
dataRegion: Generated<string>;
|
|
153
235
|
id: Generated<string>;
|
|
236
|
+
migrationStatus: Generated<string>;
|
|
154
237
|
name: string;
|
|
155
238
|
partnerId: string | null;
|
|
156
239
|
partnerDeniedPermissions: Generated<string[]>;
|
|
@@ -161,6 +244,21 @@ export interface ControlPlaneTenant {
|
|
|
161
244
|
uniqueRef: string | null;
|
|
162
245
|
updatedAt: Generated<Timestamp | null>;
|
|
163
246
|
}
|
|
247
|
+
export interface ControlPlaneTenantRegionMigration {
|
|
248
|
+
actor: string;
|
|
249
|
+
completedAt: Timestamp | null;
|
|
250
|
+
error: Json | null;
|
|
251
|
+
id: string;
|
|
252
|
+
reason: string;
|
|
253
|
+
sourceManifest: Json | null;
|
|
254
|
+
sourceRegion: string;
|
|
255
|
+
startedAt: Generated<Timestamp>;
|
|
256
|
+
status: Generated<string>;
|
|
257
|
+
targetManifest: Json | null;
|
|
258
|
+
targetRegion: string;
|
|
259
|
+
tenantId: string;
|
|
260
|
+
updatedAt: Generated<Timestamp>;
|
|
261
|
+
}
|
|
164
262
|
export interface ControlPlaneTenantUser {
|
|
165
263
|
createdAt: Generated<Timestamp | null>;
|
|
166
264
|
id: Generated<string>;
|
|
@@ -213,11 +311,19 @@ export interface ControlPlaneDB {
|
|
|
213
311
|
'controlPlane.feature': ControlPlaneFeature;
|
|
214
312
|
'controlPlane.featureApproval': ControlPlaneFeatureApproval;
|
|
215
313
|
'controlPlane.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;
|
|
314
|
+
'controlPlane.generalLedgerDefaultSet': ControlPlaneGeneralLedgerDefaultSet;
|
|
315
|
+
'controlPlane.generalLedgerDefaultVersion': ControlPlaneGeneralLedgerDefaultVersion;
|
|
316
|
+
'controlPlane.lineClassification': ControlPlaneLineClassification;
|
|
317
|
+
'controlPlane.lineClassificationTeamUsage': ControlPlaneLineClassificationTeamUsage;
|
|
216
318
|
'controlPlane.partnerManagedTeamAssignment': ControlPlanePartnerManagedTeamAssignment;
|
|
319
|
+
'controlPlane.reservationLineDefault': ControlPlaneReservationLineDefault;
|
|
217
320
|
'controlPlane.tenant': ControlPlaneTenant;
|
|
321
|
+
'controlPlane.tenantRegionMigration': ControlPlaneTenantRegionMigration;
|
|
218
322
|
'controlPlane.tenantUser': ControlPlaneTenantUser;
|
|
219
323
|
'controlPlane.token': ControlPlaneToken;
|
|
324
|
+
'controlPlane.transactionLineMapping': ControlPlaneTransactionLineMapping;
|
|
220
325
|
'controlPlane.user': ControlPlaneUser;
|
|
326
|
+
'controlPlaneCore.flow': ControlPlaneFlow;
|
|
221
327
|
'controlPlaneCore.issueMessageOverwrite': ControlPlaneIssueMessageOverwrite;
|
|
222
328
|
}
|
|
223
329
|
export declare function withControlPlaneSchema(kysely: Kysely<ControlPlaneDB>, schema: string, issueMessageOverwriteSchema?: string): Kysely<ControlPlaneDB>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EAGd,wBAAwB,GAQzB,MAAM,QAAQ,CAAC;AAgQhB,MAAM,6BAA8B,SAAQ,wBAAwB;IAEvD;IACA;IAFX,YACW,MAAc,EACd,2BAAmC;QAE5C,KAAK,EAAE,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QACd,gCAA2B,GAA3B,2BAA2B,CAAQ;IAG9C,CAAC;IAEkB,4BAA4B,CAC7C,IAA6B,EAC7B,OAAgB;QAEhB,MAAM,WAAW,GAAG,KAAK,CAAC,4BAA4B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtE,IACE,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,cAAc;YAC3C,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,eAAe,EAC5C,CAAC;YACD,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACxE,CAAC;QACD,IACE,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,kBAAkB;YAC/C,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,oBAAoB,EACjD,CAAC;YACD,OAAO;gBACL,GAAG,WAAW;gBACd,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC;aAChE,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAEkB,iBAAiB,CAClC,IAAkB,EAClB,OAAgB;QAEhB,MAAM,WAAW,GAAG,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC;YAC1C,CAAC,CAAC;gBACE,GAAG,WAAW;gBACd,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE;aACzE;YACH,CAAC,CAAC,WAAW,CAAC;IAClB,CAAC;CACF;AAED,MAAM,wBAAwB;IACnB,YAAY,CAAgC;IAErD,YAAY,MAAc,EAAE,2BAAmC;QAC7D,IAAI,CAAC,YAAY,GAAG,IAAI,6BAA6B,CACnD,MAAM,EACN,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,IAA8B;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,IAA+B;QAE/B,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB,CACpC,MAA8B,EAC9B,MAAc,EACd,2BAA2B,GAAG,MAAM;IAEpC,OAAO,MAAM,CAAC,UAAU,CACtB,IAAI,wBAAwB,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAClE,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ColumnType,\n type FunctionNode,\n IdentifierNode,\n type Kysely,\n type KyselyPlugin,\n OperationNodeTransformer,\n type PluginTransformQueryArgs,\n type PluginTransformResultArgs,\n type QueryId,\n type QueryResult,\n type RootOperationNode,\n type SchemableIdentifierNode,\n type UnknownRow,\n} from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Int8 = ColumnType<\n string,\n number | string | bigint,\n number | string | bigint\n>;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneAccountingIntegrityEvaluation {\n caseCount: Generated<Int8>;\n completedAt: Timestamp | null;\n completedRunCount: Generated<number>;\n createdAt: Generated<Timestamp>;\n environment: string;\n error: Json | null;\n expectedRunCount: number;\n failedRunCount: Generated<number>;\n findingRowCount: Generated<Int8>;\n gitRevision: string;\n id: string;\n results: Generated<Json>;\n rowsScanned: Generated<Int8>;\n skippedRunCount: Generated<number>;\n source: string;\n startedAt: Timestamp;\n status: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneBookingChannelIconCandidate {\n bookingChannelId: string;\n cloudflareImageId: string | null;\n color: string | null;\n comment: string | null;\n createdAt: Generated<Timestamp>;\n externalIcon: string | null;\n height: number | null;\n id: Generated<string>;\n provider: Generated<string>;\n source: string | null;\n updatedAt: Generated<Timestamp>;\n width: number | null;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneEvent {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n name: string;\n packageName: string;\n props: Json;\n tenantId: string | null;\n timestamp: Generated<Timestamp>;\n trackedAt: Generated<Timestamp | null>;\n userId: string | null;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeatureApproval {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n updatedAt: Generated<Timestamp>;\n userId: string;\n}\n\nexport interface ControlPlaneIssueMessageOverwrite {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n message: string;\n pattern: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlanePartnerManagedTeamAssignment {\n createdAt: Generated<Timestamp>;\n managedTeamId: string;\n partnerTenantId: string;\n userId: string;\n}\n\nexport interface ControlPlaneTenant {\n billingPartnerId: string | null;\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n name: string;\n partnerId: string | null;\n partnerDeniedPermissions: Generated<string[]>;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n managedTeamAccess: Generated<'all' | 'assigned'>;\n permissionBundles: Generated<string[]>;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n lastSeen: Timestamp | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'controlPlane.accountingIntegrityEvaluation': ControlPlaneAccountingIntegrityEvaluation;\n 'controlPlane.app': ControlPlaneApp;\n 'controlPlane.bookingChannel': ControlPlaneBookingChannel;\n 'controlPlane.bookingChannelIconCandidate': ControlPlaneBookingChannelIconCandidate;\n 'controlPlane.connectionRoute': ControlPlaneConnectionRoute;\n 'controlPlane.controlPlaneOutbox': ControlPlaneOutbox;\n 'controlPlane.currency': ControlPlaneCurrency;\n 'controlPlane.events': ControlPlaneEvent;\n 'controlPlane.feature': ControlPlaneFeature;\n 'controlPlane.featureApproval': ControlPlaneFeatureApproval;\n 'controlPlane.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'controlPlane.partnerManagedTeamAssignment': ControlPlanePartnerManagedTeamAssignment;\n 'controlPlane.tenant': ControlPlaneTenant;\n 'controlPlane.tenantUser': ControlPlaneTenantUser;\n 'controlPlane.token': ControlPlaneToken;\n 'controlPlane.user': ControlPlaneUser;\n 'controlPlaneCore.issueMessageOverwrite': ControlPlaneIssueMessageOverwrite;\n}\n\nclass ControlPlaneSchemaTransformer extends OperationNodeTransformer {\n constructor(\n readonly schema: string,\n readonly issueMessageOverwriteSchema: string\n ) {\n super();\n }\n\n protected override transformSchemableIdentifier(\n node: SchemableIdentifierNode,\n queryId: QueryId\n ): SchemableIdentifierNode {\n const transformed = super.transformSchemableIdentifier(node, queryId);\n if (\n transformed.schema?.name === 'controlPlane' ||\n transformed.schema?.name === 'control_plane'\n ) {\n return { ...transformed, schema: IdentifierNode.create(this.schema) };\n }\n if (\n transformed.schema?.name === 'controlPlaneCore' ||\n transformed.schema?.name === 'control_plane_core'\n ) {\n return {\n ...transformed,\n schema: IdentifierNode.create(this.issueMessageOverwriteSchema),\n };\n }\n return transformed;\n }\n\n protected override transformFunction(\n node: FunctionNode,\n queryId: QueryId\n ): FunctionNode {\n const transformed = super.transformFunction(node, queryId);\n return node.func.startsWith('controlPlane.')\n ? {\n ...transformed,\n func: `${this.schema}.${transformed.func.slice('controlPlane.'.length)}`,\n }\n : transformed;\n }\n}\n\nclass ControlPlaneSchemaPlugin implements KyselyPlugin {\n readonly #transformer: ControlPlaneSchemaTransformer;\n\n constructor(schema: string, issueMessageOverwriteSchema: string) {\n this.#transformer = new ControlPlaneSchemaTransformer(\n schema,\n issueMessageOverwriteSchema\n );\n }\n\n transformQuery(args: PluginTransformQueryArgs): RootOperationNode {\n return this.#transformer.transformNode(args.node, args.queryId);\n }\n\n async transformResult(\n args: PluginTransformResultArgs\n ): Promise<QueryResult<UnknownRow>> {\n return args.result;\n }\n}\n\nexport function withControlPlaneSchema(\n kysely: Kysely<ControlPlaneDB>,\n schema: string,\n issueMessageOverwriteSchema = 'core'\n) {\n return kysely.withPlugin(\n new ControlPlaneSchemaPlugin(schema, issueMessageOverwriteSchema)\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["control-plane/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EAGd,wBAAwB,GAQzB,MAAM,QAAQ,CAAC;AAkXhB,MAAM,6BAA8B,SAAQ,wBAAwB;IAEvD;IACA;IAFX,YACW,MAAc,EACd,2BAAmC;QAE5C,KAAK,EAAE,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QACd,gCAA2B,GAA3B,2BAA2B,CAAQ;IAG9C,CAAC;IAEkB,4BAA4B,CAC7C,IAA6B,EAC7B,OAAgB;QAEhB,MAAM,WAAW,GAAG,KAAK,CAAC,4BAA4B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtE,IACE,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,cAAc;YAC3C,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,eAAe,EAC5C,CAAC;YACD,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACxE,CAAC;QACD,IACE,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,kBAAkB;YAC/C,WAAW,CAAC,MAAM,EAAE,IAAI,KAAK,oBAAoB,EACjD,CAAC;YACD,OAAO;gBACL,GAAG,WAAW;gBACd,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC;aAChE,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAEkB,iBAAiB,CAClC,IAAkB,EAClB,OAAgB;QAEhB,MAAM,WAAW,GAAG,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC;YAC1C,CAAC,CAAC;gBACE,GAAG,WAAW;gBACd,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE;aACzE;YACH,CAAC,CAAC,WAAW,CAAC;IAClB,CAAC;CACF;AAED,MAAM,wBAAwB;IACnB,YAAY,CAAgC;IAErD,YAAY,MAAc,EAAE,2BAAmC;QAC7D,IAAI,CAAC,YAAY,GAAG,IAAI,6BAA6B,CACnD,MAAM,EACN,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,IAA8B;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,IAA+B;QAE/B,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,sBAAsB,CACpC,MAA8B,EAC9B,MAAc,EACd,2BAA2B,GAAG,MAAM;IAEpC,OAAO,MAAM,CAAC,UAAU,CACtB,IAAI,wBAAwB,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAClE,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ColumnType,\n type FunctionNode,\n IdentifierNode,\n type Kysely,\n type KyselyPlugin,\n OperationNodeTransformer,\n type PluginTransformQueryArgs,\n type PluginTransformResultArgs,\n type QueryId,\n type QueryResult,\n type RootOperationNode,\n type SchemableIdentifierNode,\n type UnknownRow,\n} from 'kysely';\n\nexport type Generated<T> =\n T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>;\n\nexport type Json = JsonValue;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Int8 = ColumnType<\n string,\n number | string | bigint,\n number | string | bigint\n>;\n\nexport type Timestamp = ColumnType<Date | string, Date | string, Date | string>;\n\nexport interface ControlPlaneApp {\n authentication: Generated<Json>;\n category: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconRound: string | null;\n id: Generated<string>;\n info: Json | null;\n name: string;\n type: string;\n version: Generated<number>;\n}\n\nexport interface ControlPlaneAccountingIntegrityEvaluation {\n caseCount: Generated<Int8>;\n completedAt: Timestamp | null;\n completedRunCount: Generated<number>;\n createdAt: Generated<Timestamp>;\n environment: string;\n error: Json | null;\n expectedRunCount: number;\n failedRunCount: Generated<number>;\n findingRowCount: Generated<Int8>;\n gitRevision: string;\n id: string;\n results: Generated<Json>;\n rowsScanned: Generated<Int8>;\n skippedRunCount: Generated<number>;\n source: string;\n startedAt: Timestamp;\n status: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneBookingChannel {\n channelRef: string | null;\n color: string | null;\n createdAt: Generated<Timestamp>;\n icon: string | null;\n iconProvider: string | null;\n id: Generated<string>;\n lastGenerateRun: Timestamp | null;\n logo: string | null;\n logoProvider: string | null;\n selectedBookingChannelIconCandidateId: string | null;\n selectedBookingChannelLogoCandidateId: string | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneBookingChannelIconCandidate {\n bookingChannelId: string;\n cloudflareImageId: string | null;\n color: string | null;\n comment: string | null;\n createdAt: Generated<Timestamp>;\n externalIcon: string | null;\n height: number | null;\n id: Generated<string>;\n provider: Generated<string>;\n source: string | null;\n updatedAt: Generated<Timestamp>;\n width: number | null;\n}\n\nexport interface ControlPlaneCurrency {\n name: string;\n}\n\nexport interface ControlPlaneEvent {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n name: string;\n packageName: string;\n props: Json;\n tenantId: string | null;\n timestamp: Generated<Timestamp>;\n trackedAt: Generated<Timestamp | null>;\n userId: string | null;\n}\n\nexport interface ControlPlaneConnectionRoute {\n connectionId: string;\n createdAt: Generated<Timestamp>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeature {\n createdAt: Generated<Timestamp>;\n description: string | null;\n id: Generated<string>;\n issueUrl: string | null;\n requiredApprovals: Generated<Json | null>;\n status: Generated<string | null>;\n tenantId: string | null;\n title: string;\n updatedAt: Generated<Timestamp>;\n url: string | null;\n}\n\nexport interface ControlPlaneFeatureEnabledTeam {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneFeatureApproval {\n createdAt: Generated<Timestamp>;\n featureId: string;\n id: Generated<string>;\n status: Generated<string | null>;\n updatedAt: Generated<Timestamp>;\n userId: string;\n}\n\nexport interface ControlPlaneFlow {\n appId: string;\n createdAt: Generated<Timestamp>;\n description: string | null;\n eventListening: Generated<Json>;\n id: Generated<string>;\n isPublic: Generated<boolean>;\n leftType: string | null;\n mappingSchema: Generated<Json>;\n revision: Generated<number>;\n rightType: string | null;\n runSchema: Generated<Json>;\n settingSchema: Generated<Json>;\n title: string;\n type: 'pull' | 'push' | null;\n uniqueRef: string;\n updatedAt: Generated<Timestamp>;\n useGlobalMapping: Generated<boolean>;\n}\n\nexport interface ControlPlaneIssueMessageOverwrite {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n message: string;\n pattern: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneLineClassification {\n appConflict: Generated<boolean>;\n appId: string | null;\n createdAt: Generated<Timestamp>;\n firstSeenAt: Timestamp;\n id: Generated<string>;\n kind: string;\n lastSeenAt: Timestamp;\n name: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneLineClassificationTeamUsage {\n classificationId: string;\n createdAt: Generated<Timestamp>;\n dataRegion: string;\n firstSeenAt: Timestamp;\n lastSeenAt: Timestamp;\n mappingStatus: string | null;\n revision: number;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneReservationLineDefault {\n accountKey: string | null;\n bookingChannel: string | null;\n bookingChannelKey: Generated<string>;\n classificationId: string;\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n partnerTenantId: string | null;\n revenueRecognition: string | null;\n revision: Generated<number>;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneTransactionLineMapping {\n accountAssignmentType: string | null;\n createdAt: Generated<Timestamp>;\n deletedAt: Timestamp | null;\n id: Generated<string>;\n lineType: string;\n revision: Generated<number>;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneGeneralLedgerDefaultSet {\n createdAt: Generated<Timestamp>;\n id: Generated<string>;\n partnerTenantId: string | null;\n publishedVersion: number | null;\n sourceDataRegion: string;\n sourceDigest: string | null;\n sourceTenantId: string;\n templateKey: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneGeneralLedgerDefaultVersion {\n dataJson: Json;\n defaultSetId: string;\n id: Generated<string>;\n publishedAt: Generated<Timestamp>;\n sourceDigest: string;\n sourceTenantId: string;\n version: number;\n}\n\nexport interface ControlPlaneOutbox {\n aggregateId: string;\n aggregateType: string;\n attempts: Generated<number>;\n createdAt: Generated<Timestamp>;\n dataRegion: string | null;\n eventType: string;\n eventVersion: number;\n id: Generated<string>;\n lastError: string | null;\n payload: Generated<Json>;\n publishedAt: Timestamp | null;\n}\n\nexport interface ControlPlanePartnerManagedTeamAssignment {\n createdAt: Generated<Timestamp>;\n managedTeamId: string;\n partnerTenantId: string;\n userId: string;\n}\n\nexport interface ControlPlaneTenant {\n billingPartnerId: string | null;\n billingPlan: string | null;\n createdAt: Generated<Timestamp>;\n dataRegion: Generated<string>;\n id: Generated<string>;\n migrationStatus: Generated<string>;\n name: string;\n partnerId: string | null;\n partnerDeniedPermissions: Generated<string[]>;\n slug: string;\n status: Generated<string | null>;\n storageRealm: Generated<string>;\n type: Generated<string | null>;\n uniqueRef: string | null;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneTenantRegionMigration {\n actor: string;\n completedAt: Timestamp | null;\n error: Json | null;\n id: string;\n reason: string;\n sourceManifest: Json | null;\n sourceRegion: string;\n startedAt: Generated<Timestamp>;\n status: Generated<string>;\n targetManifest: Json | null;\n targetRegion: string;\n tenantId: string;\n updatedAt: Generated<Timestamp>;\n}\n\nexport interface ControlPlaneTenantUser {\n createdAt: Generated<Timestamp | null>;\n id: Generated<string>;\n lastInvitedAt: Timestamp | null;\n managedTeamAccess: Generated<'all' | 'assigned'>;\n permissionBundles: Generated<string[]>;\n role: Generated<string | null>;\n status: Generated<string | null>;\n tenantId: string;\n updatedAt: Generated<Timestamp | null>;\n userId: string;\n}\n\nexport interface ControlPlaneToken {\n createdAt: Generated<Timestamp>;\n expiresAt: Timestamp | null;\n id: Generated<string>;\n nanoId: Generated<string>;\n payload: Generated<Json>;\n tenantId: string | null;\n type: string | null;\n userId: string | null;\n}\n\nexport interface ControlPlaneUser {\n clerkId: string | null;\n createdAt: Generated<Timestamp | null>;\n email: string | null;\n firstName: string | null;\n id: Generated<string>;\n isAdmin: Generated<boolean>;\n lastName: string | null;\n lastSeen: Timestamp | null;\n name: string | null;\n partnerId: string | null;\n phone: string | null;\n secondaryEmails: Generated<Json>;\n status: Generated<string | null>;\n sub: string | null;\n type: Generated<string | null>;\n updatedAt: Generated<Timestamp | null>;\n}\n\nexport interface ControlPlaneDB {\n 'controlPlane.accountingIntegrityEvaluation': ControlPlaneAccountingIntegrityEvaluation;\n 'controlPlane.app': ControlPlaneApp;\n 'controlPlane.bookingChannel': ControlPlaneBookingChannel;\n 'controlPlane.bookingChannelIconCandidate': ControlPlaneBookingChannelIconCandidate;\n 'controlPlane.connectionRoute': ControlPlaneConnectionRoute;\n 'controlPlane.controlPlaneOutbox': ControlPlaneOutbox;\n 'controlPlane.currency': ControlPlaneCurrency;\n 'controlPlane.events': ControlPlaneEvent;\n 'controlPlane.feature': ControlPlaneFeature;\n 'controlPlane.featureApproval': ControlPlaneFeatureApproval;\n 'controlPlane.featureEnabledTeam': ControlPlaneFeatureEnabledTeam;\n 'controlPlane.generalLedgerDefaultSet': ControlPlaneGeneralLedgerDefaultSet;\n 'controlPlane.generalLedgerDefaultVersion': ControlPlaneGeneralLedgerDefaultVersion;\n 'controlPlane.lineClassification': ControlPlaneLineClassification;\n 'controlPlane.lineClassificationTeamUsage': ControlPlaneLineClassificationTeamUsage;\n 'controlPlane.partnerManagedTeamAssignment': ControlPlanePartnerManagedTeamAssignment;\n 'controlPlane.reservationLineDefault': ControlPlaneReservationLineDefault;\n 'controlPlane.tenant': ControlPlaneTenant;\n 'controlPlane.tenantRegionMigration': ControlPlaneTenantRegionMigration;\n 'controlPlane.tenantUser': ControlPlaneTenantUser;\n 'controlPlane.token': ControlPlaneToken;\n 'controlPlane.transactionLineMapping': ControlPlaneTransactionLineMapping;\n 'controlPlane.user': ControlPlaneUser;\n 'controlPlaneCore.flow': ControlPlaneFlow;\n 'controlPlaneCore.issueMessageOverwrite': ControlPlaneIssueMessageOverwrite;\n}\n\nclass ControlPlaneSchemaTransformer extends OperationNodeTransformer {\n constructor(\n readonly schema: string,\n readonly issueMessageOverwriteSchema: string\n ) {\n super();\n }\n\n protected override transformSchemableIdentifier(\n node: SchemableIdentifierNode,\n queryId: QueryId\n ): SchemableIdentifierNode {\n const transformed = super.transformSchemableIdentifier(node, queryId);\n if (\n transformed.schema?.name === 'controlPlane' ||\n transformed.schema?.name === 'control_plane'\n ) {\n return { ...transformed, schema: IdentifierNode.create(this.schema) };\n }\n if (\n transformed.schema?.name === 'controlPlaneCore' ||\n transformed.schema?.name === 'control_plane_core'\n ) {\n return {\n ...transformed,\n schema: IdentifierNode.create(this.issueMessageOverwriteSchema),\n };\n }\n return transformed;\n }\n\n protected override transformFunction(\n node: FunctionNode,\n queryId: QueryId\n ): FunctionNode {\n const transformed = super.transformFunction(node, queryId);\n return node.func.startsWith('controlPlane.')\n ? {\n ...transformed,\n func: `${this.schema}.${transformed.func.slice('controlPlane.'.length)}`,\n }\n : transformed;\n }\n}\n\nclass ControlPlaneSchemaPlugin implements KyselyPlugin {\n readonly #transformer: ControlPlaneSchemaTransformer;\n\n constructor(schema: string, issueMessageOverwriteSchema: string) {\n this.#transformer = new ControlPlaneSchemaTransformer(\n schema,\n issueMessageOverwriteSchema\n );\n }\n\n transformQuery(args: PluginTransformQueryArgs): RootOperationNode {\n return this.#transformer.transformNode(args.node, args.queryId);\n }\n\n async transformResult(\n args: PluginTransformResultArgs\n ): Promise<QueryResult<UnknownRow>> {\n return args.result;\n }\n}\n\nexport function withControlPlaneSchema(\n kysely: Kysely<ControlPlaneDB>,\n schema: string,\n issueMessageOverwriteSchema = 'core'\n) {\n return kysely.withPlugin(\n new ControlPlaneSchemaPlugin(schema, issueMessageOverwriteSchema)\n );\n}\n"]}
|
|
@@ -63,6 +63,7 @@ export async function useLocalKysely(args = {}) {
|
|
|
63
63
|
if (controlPlaneMigrationError) {
|
|
64
64
|
throw controlPlaneMigrationError;
|
|
65
65
|
}
|
|
66
|
+
await sql `alter table core.flow set schema public`.execute(controlPlaneBootstrapKysely);
|
|
66
67
|
await sql `alter table core.issue_message_overwrite set schema public`.execute(controlPlaneBootstrapKysely);
|
|
67
68
|
await sql `drop schema core`.execute(controlPlaneBootstrapKysely);
|
|
68
69
|
await sql `alter schema public rename to control_plane`.execute(controlPlaneBootstrapKysely);
|