@webstudio-is/postgrest 0.252.1
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/LICENSE +661 -0
- package/README.md +51 -0
- package/package.json +29 -0
- package/playground/domains.ts +54 -0
- package/playground/pnpm-playground +8 -0
- package/src/__generated__/db-types.ts +1176 -0
- package/src/index.server.ts +16 -0
- package/supabase/SQL-TESTS-AI.md +161 -0
- package/supabase/tests/cleanup-builds.sql +227 -0
- package/supabase/tests/latest-builds-domains.sql +516 -0
- package/supabase/tests/latest-builds-projects.sql +808 -0
- package/supabase/tests/project-domains.sql +77 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
BEGIN;
|
|
2
|
+
|
|
3
|
+
SET
|
|
4
|
+
LOCAL search_path = pgtap,
|
|
5
|
+
public;
|
|
6
|
+
|
|
7
|
+
-- SET LOCAL search_path = pgtap,public;
|
|
8
|
+
-- Initialize the testing environment without planning any specific number of tests
|
|
9
|
+
SELECT
|
|
10
|
+
no_plan();
|
|
11
|
+
|
|
12
|
+
-- Insert a new user into the User table
|
|
13
|
+
INSERT INTO
|
|
14
|
+
"public"."User" ("id", "createdAt", "email", "username")
|
|
15
|
+
VALUES
|
|
16
|
+
(
|
|
17
|
+
'user1',
|
|
18
|
+
'2023-01-01 00:00:00+00',
|
|
19
|
+
'user1@517cce32-9af3-example.com',
|
|
20
|
+
'user1'
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- Insert projects associated with the user
|
|
24
|
+
INSERT INTO
|
|
25
|
+
"public"."Project" (
|
|
26
|
+
"id",
|
|
27
|
+
"title",
|
|
28
|
+
"domain",
|
|
29
|
+
"userId",
|
|
30
|
+
"isDeleted",
|
|
31
|
+
"createdAt"
|
|
32
|
+
)
|
|
33
|
+
VALUES
|
|
34
|
+
(
|
|
35
|
+
'project1',
|
|
36
|
+
'Project One',
|
|
37
|
+
'517cce32-9af3-project1-domain1',
|
|
38
|
+
'user1',
|
|
39
|
+
false,
|
|
40
|
+
'2023-01-01 00:00:00+00'
|
|
41
|
+
),
|
|
42
|
+
(
|
|
43
|
+
'project2',
|
|
44
|
+
'Project Two',
|
|
45
|
+
'517cce32-9af3-project2-domain1',
|
|
46
|
+
'user1',
|
|
47
|
+
false,
|
|
48
|
+
'2023-01-01 00:00:00+00'
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
-- Insert custom domains into the Domain table
|
|
52
|
+
INSERT INTO
|
|
53
|
+
"public"."Domain" (
|
|
54
|
+
"id",
|
|
55
|
+
"domain",
|
|
56
|
+
"createdAt",
|
|
57
|
+
"status",
|
|
58
|
+
"updatedAt"
|
|
59
|
+
)
|
|
60
|
+
VALUES
|
|
61
|
+
(
|
|
62
|
+
'project-1-custom-domain-1',
|
|
63
|
+
'517cce32-9af3-project-1-custom-domain-1.com',
|
|
64
|
+
'2023-01-01 00:00:00+00',
|
|
65
|
+
'INITIALIZING',
|
|
66
|
+
'2023-01-01 00:00:00+00'
|
|
67
|
+
),
|
|
68
|
+
(
|
|
69
|
+
'project-1-custom-domain-2',
|
|
70
|
+
'517cce32-9af3-project-1-custom-domain-2.com',
|
|
71
|
+
'2023-01-01 00:00:00+00',
|
|
72
|
+
'INITIALIZING',
|
|
73
|
+
'2023-01-01 00:00:00+00'
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
-- Establish relationships between projects and custom domains
|
|
77
|
+
INSERT INTO
|
|
78
|
+
"public"."ProjectDomain" (
|
|
79
|
+
"projectId",
|
|
80
|
+
"domainId",
|
|
81
|
+
"createdAt",
|
|
82
|
+
"txtRecord",
|
|
83
|
+
"cname"
|
|
84
|
+
)
|
|
85
|
+
VALUES
|
|
86
|
+
(
|
|
87
|
+
'project1',
|
|
88
|
+
'project-1-custom-domain-1',
|
|
89
|
+
'2023-01-01 00:00:00+00',
|
|
90
|
+
'txtRecord1',
|
|
91
|
+
'cname1'
|
|
92
|
+
),
|
|
93
|
+
(
|
|
94
|
+
'project1',
|
|
95
|
+
'project-1-custom-domain-2',
|
|
96
|
+
'2023-01-01 00:00:00+00',
|
|
97
|
+
'txtRecord2',
|
|
98
|
+
'cname2'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
-- Create a view to encapsulate the repetitive SELECT query for testing
|
|
102
|
+
CREATE
|
|
103
|
+
OR REPLACE VIEW "public"."TestProjectDomains" AS
|
|
104
|
+
SELECT
|
|
105
|
+
pd."projectId",
|
|
106
|
+
pd."domainId",
|
|
107
|
+
lbv."buildId"
|
|
108
|
+
FROM
|
|
109
|
+
"public"."ProjectDomain" pd
|
|
110
|
+
LEFT JOIN LATERAL (
|
|
111
|
+
SELECT
|
|
112
|
+
*
|
|
113
|
+
FROM
|
|
114
|
+
"latestBuildVirtual"(
|
|
115
|
+
ROW(
|
|
116
|
+
'',
|
|
117
|
+
pd."domainId",
|
|
118
|
+
pd."projectId",
|
|
119
|
+
'',
|
|
120
|
+
'INITIALIZING' :: "DomainStatus",
|
|
121
|
+
NULL,
|
|
122
|
+
'txt',
|
|
123
|
+
'expectedTxt',
|
|
124
|
+
'cname',
|
|
125
|
+
TRUE,
|
|
126
|
+
NOW(),
|
|
127
|
+
NOW()
|
|
128
|
+
) :: "domainsVirtual"
|
|
129
|
+
)
|
|
130
|
+
) lbv ON TRUE
|
|
131
|
+
ORDER BY
|
|
132
|
+
pd."domainId";
|
|
133
|
+
|
|
134
|
+
--------------------------------------------------------------------------------
|
|
135
|
+
-- Test Case 1: Initial State Without Builds
|
|
136
|
+
--------------------------------------------------------------------------------
|
|
137
|
+
SELECT
|
|
138
|
+
results_eq(
|
|
139
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
140
|
+
$$
|
|
141
|
+
SELECT
|
|
142
|
+
*
|
|
143
|
+
FROM
|
|
144
|
+
(
|
|
145
|
+
VALUES
|
|
146
|
+
('project1', 'project-1-custom-domain-1', NULL),
|
|
147
|
+
('project1', 'project-1-custom-domain-2', NULL)
|
|
148
|
+
) AS expected(projectId, domainId, buildId)
|
|
149
|
+
ORDER BY
|
|
150
|
+
domainId $$,
|
|
151
|
+
'Initial state without builds'
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
--------------------------------------------------------------------------------
|
|
155
|
+
-- Test Case 2: After Inserting Build1 Associated with Custom Domain 1
|
|
156
|
+
--------------------------------------------------------------------------------
|
|
157
|
+
-- Insert a build associated with a custom domain
|
|
158
|
+
INSERT INTO
|
|
159
|
+
"public"."Build" (
|
|
160
|
+
"id",
|
|
161
|
+
"createdAt",
|
|
162
|
+
"pages",
|
|
163
|
+
"projectId",
|
|
164
|
+
"deployment",
|
|
165
|
+
"updatedAt",
|
|
166
|
+
"publishStatus"
|
|
167
|
+
)
|
|
168
|
+
VALUES
|
|
169
|
+
(
|
|
170
|
+
'build1-for-custom-domain-1',
|
|
171
|
+
'2023-01-02 00:00:00+00',
|
|
172
|
+
'home',
|
|
173
|
+
'project1',
|
|
174
|
+
'{"domains": ["some-other-domain.com", "517cce32-9af3-project-1-custom-domain-1.com"]}' :: text,
|
|
175
|
+
'2023-01-02 00:00:00+00',
|
|
176
|
+
'PUBLISHED'
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
SELECT
|
|
180
|
+
results_eq(
|
|
181
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
182
|
+
$$
|
|
183
|
+
SELECT
|
|
184
|
+
*
|
|
185
|
+
FROM
|
|
186
|
+
(
|
|
187
|
+
VALUES
|
|
188
|
+
(
|
|
189
|
+
'project1',
|
|
190
|
+
'project-1-custom-domain-1',
|
|
191
|
+
'build1-for-custom-domain-1'
|
|
192
|
+
),
|
|
193
|
+
('project1', 'project-1-custom-domain-2', NULL)
|
|
194
|
+
) AS expected(projectId, domainId, buildId)
|
|
195
|
+
ORDER BY
|
|
196
|
+
domainId $$,
|
|
197
|
+
'After inserting build1 associated with custom domain 1'
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
--------------------------------------------------------------------------------
|
|
201
|
+
-- Test Case 3: After Inserting Build2 Associated with Custom Domain 1
|
|
202
|
+
--------------------------------------------------------------------------------
|
|
203
|
+
-- Insert a new build associated with the same custom domain
|
|
204
|
+
INSERT INTO
|
|
205
|
+
"public"."Build" (
|
|
206
|
+
"id",
|
|
207
|
+
"createdAt",
|
|
208
|
+
"pages",
|
|
209
|
+
"projectId",
|
|
210
|
+
"deployment",
|
|
211
|
+
"updatedAt",
|
|
212
|
+
"publishStatus"
|
|
213
|
+
)
|
|
214
|
+
VALUES
|
|
215
|
+
(
|
|
216
|
+
'build2-for-custom-domain-1',
|
|
217
|
+
'2024-01-02 00:00:00+00',
|
|
218
|
+
'home',
|
|
219
|
+
'project1',
|
|
220
|
+
'{"domains": ["some-other-domain.com", "517cce32-9af3-project-1-custom-domain-1.com"]}' :: text,
|
|
221
|
+
'2024-01-02 00:00:00+00',
|
|
222
|
+
'PUBLISHED'
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
SELECT
|
|
226
|
+
results_eq(
|
|
227
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
228
|
+
$$
|
|
229
|
+
SELECT
|
|
230
|
+
*
|
|
231
|
+
FROM
|
|
232
|
+
(
|
|
233
|
+
VALUES
|
|
234
|
+
(
|
|
235
|
+
'project1',
|
|
236
|
+
'project-1-custom-domain-1',
|
|
237
|
+
'build2-for-custom-domain-1'
|
|
238
|
+
),
|
|
239
|
+
('project1', 'project-1-custom-domain-2', NULL)
|
|
240
|
+
) AS expected(projectId, domainId, buildId)
|
|
241
|
+
ORDER BY
|
|
242
|
+
domainId $$,
|
|
243
|
+
'After inserting build2 associated with custom domain 1'
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
--------------------------------------------------------------------------------
|
|
247
|
+
-- Test Case 4: After Inserting Build3 Associated with Custom Domain 2
|
|
248
|
+
--------------------------------------------------------------------------------
|
|
249
|
+
-- Insert a new build associated with another custom domain
|
|
250
|
+
INSERT INTO
|
|
251
|
+
"public"."Build" (
|
|
252
|
+
"id",
|
|
253
|
+
"createdAt",
|
|
254
|
+
"pages",
|
|
255
|
+
"projectId",
|
|
256
|
+
"deployment",
|
|
257
|
+
"updatedAt",
|
|
258
|
+
"publishStatus"
|
|
259
|
+
)
|
|
260
|
+
VALUES
|
|
261
|
+
(
|
|
262
|
+
'build3-for-custom-domain-2',
|
|
263
|
+
'2024-01-03 00:00:00+00',
|
|
264
|
+
'home',
|
|
265
|
+
'project1',
|
|
266
|
+
'{"domains": ["some-other-domain.com", "517cce32-9af3-project-1-custom-domain-2.com"]}' :: text,
|
|
267
|
+
'2024-01-03 00:00:00+00',
|
|
268
|
+
'PUBLISHED'
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
SELECT
|
|
272
|
+
results_eq(
|
|
273
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
274
|
+
$$
|
|
275
|
+
SELECT
|
|
276
|
+
*
|
|
277
|
+
FROM
|
|
278
|
+
(
|
|
279
|
+
VALUES
|
|
280
|
+
(
|
|
281
|
+
'project1',
|
|
282
|
+
'project-1-custom-domain-1',
|
|
283
|
+
'build2-for-custom-domain-1'
|
|
284
|
+
),
|
|
285
|
+
(
|
|
286
|
+
'project1',
|
|
287
|
+
'project-1-custom-domain-2',
|
|
288
|
+
'build3-for-custom-domain-2'
|
|
289
|
+
)
|
|
290
|
+
) AS expected(projectId, domainId, buildId)
|
|
291
|
+
ORDER BY
|
|
292
|
+
domainId $$,
|
|
293
|
+
'After inserting build3 associated with custom domain 2'
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
--------------------------------------------------------------------------------
|
|
297
|
+
-- Test Case 5: After Inserting Build4 Associated with Both Domains
|
|
298
|
+
--------------------------------------------------------------------------------
|
|
299
|
+
-- Insert a new build associated with both custom domains
|
|
300
|
+
INSERT INTO
|
|
301
|
+
"public"."Build" (
|
|
302
|
+
"id",
|
|
303
|
+
"createdAt",
|
|
304
|
+
"pages",
|
|
305
|
+
"projectId",
|
|
306
|
+
"deployment",
|
|
307
|
+
"updatedAt",
|
|
308
|
+
"publishStatus"
|
|
309
|
+
)
|
|
310
|
+
VALUES
|
|
311
|
+
(
|
|
312
|
+
'build4-for-both-domains',
|
|
313
|
+
'2024-01-04 00:00:00+00',
|
|
314
|
+
'home',
|
|
315
|
+
'project1',
|
|
316
|
+
'{"domains": ["some-other-domain.com", "517cce32-9af3-project-1-custom-domain-2.com", "517cce32-9af3-project-1-custom-domain-1.com"]}' :: text,
|
|
317
|
+
'2024-01-04 00:00:00+00',
|
|
318
|
+
'PUBLISHED'
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
SELECT
|
|
322
|
+
results_eq(
|
|
323
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
324
|
+
$$
|
|
325
|
+
SELECT
|
|
326
|
+
*
|
|
327
|
+
FROM
|
|
328
|
+
(
|
|
329
|
+
VALUES
|
|
330
|
+
(
|
|
331
|
+
'project1',
|
|
332
|
+
'project-1-custom-domain-1',
|
|
333
|
+
'build4-for-both-domains'
|
|
334
|
+
),
|
|
335
|
+
(
|
|
336
|
+
'project1',
|
|
337
|
+
'project-1-custom-domain-2',
|
|
338
|
+
'build4-for-both-domains'
|
|
339
|
+
)
|
|
340
|
+
) AS expected(projectId, domainId, buildId)
|
|
341
|
+
ORDER BY
|
|
342
|
+
domainId $$,
|
|
343
|
+
'After inserting build4 associated with both domains'
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
--------------------------------------------------------------------------------
|
|
347
|
+
-- Test Case 6: Insert Builds and Relationships for Project2
|
|
348
|
+
--------------------------------------------------------------------------------
|
|
349
|
+
-- Establish relationships between project2 and the same custom domains
|
|
350
|
+
INSERT INTO
|
|
351
|
+
"public"."ProjectDomain" (
|
|
352
|
+
"projectId",
|
|
353
|
+
"domainId",
|
|
354
|
+
"createdAt",
|
|
355
|
+
"txtRecord",
|
|
356
|
+
"cname"
|
|
357
|
+
)
|
|
358
|
+
VALUES
|
|
359
|
+
(
|
|
360
|
+
'project2',
|
|
361
|
+
'project-1-custom-domain-1',
|
|
362
|
+
'2023-01-01 00:00:00+00',
|
|
363
|
+
'txtRecord21',
|
|
364
|
+
'cname21'
|
|
365
|
+
),
|
|
366
|
+
(
|
|
367
|
+
'project2',
|
|
368
|
+
'project-1-custom-domain-2',
|
|
369
|
+
'2023-01-01 00:00:00+00',
|
|
370
|
+
'txtRecord22',
|
|
371
|
+
'cname22'
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
-- Insert a new build for project2 associated with both domains
|
|
375
|
+
INSERT INTO
|
|
376
|
+
"public"."Build" (
|
|
377
|
+
"id",
|
|
378
|
+
"createdAt",
|
|
379
|
+
"pages",
|
|
380
|
+
"projectId",
|
|
381
|
+
"deployment",
|
|
382
|
+
"updatedAt",
|
|
383
|
+
"publishStatus"
|
|
384
|
+
)
|
|
385
|
+
VALUES
|
|
386
|
+
(
|
|
387
|
+
'build5-project2-for-both-domains',
|
|
388
|
+
'2025-01-04 00:00:00+00',
|
|
389
|
+
'home',
|
|
390
|
+
'project2',
|
|
391
|
+
'{"domains": ["some-other-domain.com", "517cce32-9af3-project-1-custom-domain-2.com", "517cce32-9af3-project-1-custom-domain-1.com"]}' :: text,
|
|
392
|
+
'2025-01-04 00:00:00+00',
|
|
393
|
+
'PUBLISHED'
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
--------------------------------------------------------------------------------
|
|
397
|
+
-- Test Case 7: Verify Results for Project1 Remain Unchanged After Project2 Updates
|
|
398
|
+
--------------------------------------------------------------------------------
|
|
399
|
+
SELECT
|
|
400
|
+
results_eq(
|
|
401
|
+
'SELECT * FROM "public"."TestProjectDomains" WHERE "projectId" = ''project1''',
|
|
402
|
+
$$
|
|
403
|
+
SELECT
|
|
404
|
+
*
|
|
405
|
+
FROM
|
|
406
|
+
(
|
|
407
|
+
VALUES
|
|
408
|
+
(
|
|
409
|
+
'project1',
|
|
410
|
+
'project-1-custom-domain-1',
|
|
411
|
+
'build4-for-both-domains'
|
|
412
|
+
),
|
|
413
|
+
(
|
|
414
|
+
'project1',
|
|
415
|
+
'project-1-custom-domain-2',
|
|
416
|
+
'build4-for-both-domains'
|
|
417
|
+
)
|
|
418
|
+
) AS expected(projectId, domainId, buildId)
|
|
419
|
+
ORDER BY
|
|
420
|
+
domainId $$,
|
|
421
|
+
'Verify Project1 results remain unchanged after Project2 updates'
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
--------------------------------------------------------------------------------
|
|
425
|
+
-- Test Case 8: Verify Results for Project2 Reflect Latest Build
|
|
426
|
+
--------------------------------------------------------------------------------
|
|
427
|
+
SELECT
|
|
428
|
+
results_eq(
|
|
429
|
+
$$
|
|
430
|
+
SELECT
|
|
431
|
+
*
|
|
432
|
+
FROM
|
|
433
|
+
"public"."TestProjectDomains"
|
|
434
|
+
WHERE
|
|
435
|
+
"projectId" = 'project2' $$,
|
|
436
|
+
$$
|
|
437
|
+
SELECT
|
|
438
|
+
*
|
|
439
|
+
FROM
|
|
440
|
+
(
|
|
441
|
+
VALUES
|
|
442
|
+
(
|
|
443
|
+
'project2',
|
|
444
|
+
'project-1-custom-domain-1',
|
|
445
|
+
'build5-project2-for-both-domains'
|
|
446
|
+
),
|
|
447
|
+
(
|
|
448
|
+
'project2',
|
|
449
|
+
'project-1-custom-domain-2',
|
|
450
|
+
'build5-project2-for-both-domains'
|
|
451
|
+
)
|
|
452
|
+
) AS expected(projectId, domainId, buildId)
|
|
453
|
+
ORDER BY
|
|
454
|
+
domainId $$,
|
|
455
|
+
'Verify Project2 results reflect the latest build'
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
--------------------------------------------------------------------------------
|
|
459
|
+
-- Test Case 9: Verify updatedAt Field for domainsVirtual Function
|
|
460
|
+
--------------------------------------------------------------------------------
|
|
461
|
+
-- Insert a build with specific updatedAt value for project1 custom domain 1
|
|
462
|
+
-- This build should be selected as latest because it has the newest createdAt
|
|
463
|
+
INSERT INTO
|
|
464
|
+
"public"."Build" (
|
|
465
|
+
"id",
|
|
466
|
+
"createdAt",
|
|
467
|
+
"pages",
|
|
468
|
+
"projectId",
|
|
469
|
+
"deployment",
|
|
470
|
+
"updatedAt",
|
|
471
|
+
"publishStatus"
|
|
472
|
+
)
|
|
473
|
+
VALUES
|
|
474
|
+
(
|
|
475
|
+
'build-with-updatedAt-test',
|
|
476
|
+
'2025-01-10 00:00:00+00',
|
|
477
|
+
'home',
|
|
478
|
+
'project1',
|
|
479
|
+
'{"domains": ["517cce32-9af3-project-1-custom-domain-1.com"]}' :: text,
|
|
480
|
+
'2024-06-15 12:30:00+00',
|
|
481
|
+
'PUBLISHED'
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
-- Verify updatedAt is returned correctly from the latest build
|
|
485
|
+
SELECT
|
|
486
|
+
is (
|
|
487
|
+
(
|
|
488
|
+
SELECT
|
|
489
|
+
"updatedAt"
|
|
490
|
+
FROM
|
|
491
|
+
"public"."latestBuildVirtual"(
|
|
492
|
+
ROW(
|
|
493
|
+
'',
|
|
494
|
+
'project-1-custom-domain-1',
|
|
495
|
+
'project1',
|
|
496
|
+
'',
|
|
497
|
+
'INITIALIZING' :: "DomainStatus",
|
|
498
|
+
NULL,
|
|
499
|
+
'txt',
|
|
500
|
+
'expectedTxt',
|
|
501
|
+
'cname',
|
|
502
|
+
TRUE,
|
|
503
|
+
NOW(),
|
|
504
|
+
NOW()
|
|
505
|
+
) :: "domainsVirtual"
|
|
506
|
+
)
|
|
507
|
+
),
|
|
508
|
+
'2024-06-15 12:30:00+00' :: timestamp with time zone,
|
|
509
|
+
'Test Case 9: updatedAt field should be returned correctly from latestBuildVirtual(domainsVirtual).'
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
-- Finalize the tests
|
|
513
|
+
SELECT
|
|
514
|
+
finish();
|
|
515
|
+
|
|
516
|
+
ROLLBACK;
|