|
1 | 1 | import { codeBlock } from 'common-tags'; |
2 | | -import { fileURLToPath } from 'node:url'; |
3 | | -import { extractFiles } from './eszip.js'; |
4 | | -import { |
5 | | - assertSuccess, |
6 | | - type ManagementApiClient, |
7 | | -} from './management-api/index.js'; |
8 | 2 |
|
9 | 3 | /** |
10 | 4 | * Gets the deployment ID for an Edge Function. |
@@ -40,96 +34,3 @@ export const edgeFunctionExample = codeBlock` |
40 | 34 | }); |
41 | 35 | }); |
42 | 36 | `; |
43 | | - |
44 | | -/** |
45 | | - * Fetches a full Edge Function from the Supabase Management API. |
46 | | -
|
47 | | - * - Includes both function metadata and the contents of each file. |
48 | | - * - Normalizes file paths to be relative to the project root. |
49 | | - */ |
50 | | -export async function getFullEdgeFunction( |
51 | | - managementApiClient: ManagementApiClient, |
52 | | - projectId: string, |
53 | | - functionSlug: string |
54 | | -) { |
55 | | - const functionResponse = await managementApiClient.GET( |
56 | | - '/v1/projects/{ref}/functions/{function_slug}', |
57 | | - { |
58 | | - params: { |
59 | | - path: { |
60 | | - ref: projectId, |
61 | | - function_slug: functionSlug, |
62 | | - }, |
63 | | - }, |
64 | | - } |
65 | | - ); |
66 | | - |
67 | | - if (functionResponse.error) { |
68 | | - return { |
69 | | - data: undefined, |
70 | | - error: functionResponse.error as { message: string }, |
71 | | - }; |
72 | | - } |
73 | | - |
74 | | - assertSuccess(functionResponse, 'Failed to fetch Edge Function'); |
75 | | - |
76 | | - const edgeFunction = functionResponse.data; |
77 | | - |
78 | | - const deploymentId = getDeploymentId( |
79 | | - projectId, |
80 | | - edgeFunction.id, |
81 | | - edgeFunction.version |
82 | | - ); |
83 | | - |
84 | | - const pathPrefix = getPathPrefix(deploymentId); |
85 | | - |
86 | | - const entrypoint_path = edgeFunction.entrypoint_path |
87 | | - ? fileURLToPath(edgeFunction.entrypoint_path, { windows: false }).replace( |
88 | | - pathPrefix, |
89 | | - '' |
90 | | - ) |
91 | | - : undefined; |
92 | | - |
93 | | - const import_map_path = edgeFunction.import_map_path |
94 | | - ? fileURLToPath(edgeFunction.import_map_path, { windows: false }).replace( |
95 | | - pathPrefix, |
96 | | - '' |
97 | | - ) |
98 | | - : undefined; |
99 | | - |
100 | | - const eszipResponse = await managementApiClient.GET( |
101 | | - '/v1/projects/{ref}/functions/{function_slug}/body', |
102 | | - { |
103 | | - params: { |
104 | | - path: { |
105 | | - ref: projectId, |
106 | | - function_slug: functionSlug, |
107 | | - }, |
108 | | - }, |
109 | | - parseAs: 'arrayBuffer', |
110 | | - } |
111 | | - ); |
112 | | - |
113 | | - assertSuccess(eszipResponse, 'Failed to fetch Edge Function eszip bundle'); |
114 | | - |
115 | | - const extractedFiles = await extractFiles( |
116 | | - new Uint8Array(eszipResponse.data), |
117 | | - pathPrefix |
118 | | - ); |
119 | | - |
120 | | - const files = await Promise.all( |
121 | | - extractedFiles.map(async (file) => ({ |
122 | | - name: file.name, |
123 | | - content: await file.text(), |
124 | | - })) |
125 | | - ); |
126 | | - |
127 | | - const normalizedFunction = { |
128 | | - ...edgeFunction, |
129 | | - entrypoint_path, |
130 | | - import_map_path, |
131 | | - files, |
132 | | - }; |
133 | | - |
134 | | - return { data: normalizedFunction, error: undefined }; |
135 | | -} |
0 commit comments