-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy path+page.ts
More file actions
69 lines (60 loc) · 2.29 KB
/
Copy path+page.ts
File metadata and controls
69 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { sdk } from '$lib/stores/sdk';
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { Query } from '@appwrite.io/console';
const VARIABLES_LIMIT = 100;
export const load = async ({ params, depends, parent }) => {
depends(Dependencies.VARIABLES);
depends(Dependencies.FUNCTION);
const limit = PAGE_LIMIT;
const variablesOffset = 0;
const {
runtimesList,
specificationsList,
runtimeSpecificationsList,
function: fn
} = await parent();
const buildEnabledSpecs = specificationsList?.specifications?.filter((s) => s.enabled) ?? [];
const runtimeEnabledSpecs =
runtimeSpecificationsList?.specifications?.filter((s) => s.enabled) ?? [];
if (!buildEnabledSpecs.some((s) => s.slug === fn.buildSpecification)) {
fn.buildSpecification = buildEnabledSpecs[0]?.slug;
}
if (!runtimeEnabledSpecs.some((s) => s.slug === fn.runtimeSpecification)) {
fn.runtimeSpecification = runtimeEnabledSpecs[0]?.slug;
}
const [globalVariables, variables] = await Promise.all([
sdk.forProject(params.region, params.project).projectApi.listVariables({
queries: [Query.limit(VARIABLES_LIMIT)]
}),
sdk.forProject(params.region, params.project).functions.listVariables({
functionId: params.function,
queries: [Query.limit(limit), Query.offset(variablesOffset)]
})
]);
// Conflicting variables first
variables.variables = variables.variables.sort((var1, var2) => {
const isVar1Global =
globalVariables.variables.find((variable) => variable.key === var1.key) !== undefined;
const isVar2Global =
globalVariables.variables.find((variable) => variable.key === var2.key) !== undefined;
if (isVar1Global && isVar2Global) {
return -var1.$createdAt.localeCompare(var2.$createdAt);
} else if (isVar1Global) {
return -1;
} else if (isVar2Global) {
return 1;
} else {
return -var1.$createdAt.localeCompare(var2.$createdAt);
}
});
return {
variables,
globalVariables,
limit,
variablesOffset,
runtimesList,
specificationsList,
runtimeSpecificationsList,
function: fn
};
};