@hot-updater/supabase 0.29.4 → 0.29.6
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/dist/edge.cjs +1 -1
- package/dist/edge.mjs +1 -1
- package/dist/iac/index.cjs +7 -5
- package/dist/iac/index.mjs +8 -6
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/supabaseEdgeFunctionStorage-Dd8ytWP1.cjs +545 -0
- package/dist/supabaseEdgeFunctionStorage-DnnViEfo.mjs +527 -0
- package/package.json +9 -9
- package/dist/supabaseEdgeFunctionStorage-B-gM2rZx.cjs +0 -192
- package/dist/supabaseEdgeFunctionStorage-CVEY5QJO.mjs +0 -174
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
require("./index.cjs");
|
|
2
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
3
|
-
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
4
|
-
let _supabase_supabase_js = require("@supabase/supabase-js");
|
|
5
|
-
//#region src/supabaseDatabase.ts
|
|
6
|
-
const supabaseDatabase = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
7
|
-
name: "supabaseDatabase",
|
|
8
|
-
factory: (config) => {
|
|
9
|
-
const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseAnonKey);
|
|
10
|
-
return {
|
|
11
|
-
async getBundleById(bundleId) {
|
|
12
|
-
const { data, error } = await supabase.from("bundles").select("channel, enabled, should_force_update, file_hash, git_commit_hash, id, message, platform, target_app_version, fingerprint_hash, storage_uri, metadata, rollout_cohort_count, target_cohorts").eq("id", bundleId).single();
|
|
13
|
-
if (!data || error) return null;
|
|
14
|
-
return {
|
|
15
|
-
channel: data.channel,
|
|
16
|
-
enabled: data.enabled,
|
|
17
|
-
shouldForceUpdate: data.should_force_update,
|
|
18
|
-
fileHash: data.file_hash,
|
|
19
|
-
gitCommitHash: data.git_commit_hash,
|
|
20
|
-
id: data.id,
|
|
21
|
-
message: data.message,
|
|
22
|
-
platform: data.platform,
|
|
23
|
-
targetAppVersion: data.target_app_version,
|
|
24
|
-
fingerprintHash: data.fingerprint_hash,
|
|
25
|
-
storageUri: data.storage_uri,
|
|
26
|
-
metadata: data.metadata ?? {},
|
|
27
|
-
rolloutCohortCount: data.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
28
|
-
targetCohorts: data.target_cohorts ?? null
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
async getBundles(options) {
|
|
32
|
-
const { where, limit, offset, orderBy } = options ?? {};
|
|
33
|
-
if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0 || where?.id?.in && where.id.in.length === 0) return {
|
|
34
|
-
data: [],
|
|
35
|
-
pagination: (0, _hot_updater_plugin_core.calculatePagination)(0, {
|
|
36
|
-
limit,
|
|
37
|
-
offset
|
|
38
|
-
})
|
|
39
|
-
};
|
|
40
|
-
let countQuery = supabase.from("bundles").select("*", {
|
|
41
|
-
count: "exact",
|
|
42
|
-
head: true
|
|
43
|
-
});
|
|
44
|
-
if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
|
|
45
|
-
if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
|
|
46
|
-
if (where?.enabled !== void 0) countQuery = countQuery.eq("enabled", where.enabled);
|
|
47
|
-
if (where?.fingerprintHash !== void 0) countQuery = where.fingerprintHash === null ? countQuery.is("fingerprint_hash", null) : countQuery.eq("fingerprint_hash", where.fingerprintHash);
|
|
48
|
-
if (where?.targetAppVersion !== void 0) countQuery = where.targetAppVersion === null ? countQuery.is("target_app_version", null) : countQuery.eq("target_app_version", where.targetAppVersion);
|
|
49
|
-
if (where?.targetAppVersionIn) countQuery = countQuery.in("target_app_version", where.targetAppVersionIn);
|
|
50
|
-
if (where?.targetAppVersionNotNull) countQuery = countQuery.not("target_app_version", "is", null);
|
|
51
|
-
if (where?.id?.eq) countQuery = countQuery.eq("id", where.id.eq);
|
|
52
|
-
if (where?.id?.gt) countQuery = countQuery.gt("id", where.id.gt);
|
|
53
|
-
if (where?.id?.gte) countQuery = countQuery.gte("id", where.id.gte);
|
|
54
|
-
if (where?.id?.lt) countQuery = countQuery.lt("id", where.id.lt);
|
|
55
|
-
if (where?.id?.lte) countQuery = countQuery.lte("id", where.id.lte);
|
|
56
|
-
if (where?.id?.in) countQuery = countQuery.in("id", where.id.in);
|
|
57
|
-
const { count: total = 0 } = await countQuery;
|
|
58
|
-
let query = supabase.from("bundles").select("id, channel, enabled, platform, should_force_update, file_hash, git_commit_hash, message, fingerprint_hash, target_app_version, storage_uri, metadata, rollout_cohort_count, target_cohorts").order("id", { ascending: orderBy?.direction === "asc" });
|
|
59
|
-
if (where?.channel) query = query.eq("channel", where.channel);
|
|
60
|
-
if (where?.platform) query = query.eq("platform", where.platform);
|
|
61
|
-
if (where?.enabled !== void 0) query = query.eq("enabled", where.enabled);
|
|
62
|
-
if (where?.fingerprintHash !== void 0) query = where.fingerprintHash === null ? query.is("fingerprint_hash", null) : query.eq("fingerprint_hash", where.fingerprintHash);
|
|
63
|
-
if (where?.targetAppVersion !== void 0) query = where.targetAppVersion === null ? query.is("target_app_version", null) : query.eq("target_app_version", where.targetAppVersion);
|
|
64
|
-
if (where?.targetAppVersionIn) query = query.in("target_app_version", where.targetAppVersionIn);
|
|
65
|
-
if (where?.targetAppVersionNotNull) query = query.not("target_app_version", "is", null);
|
|
66
|
-
if (where?.id?.eq) query = query.eq("id", where.id.eq);
|
|
67
|
-
if (where?.id?.gt) query = query.gt("id", where.id.gt);
|
|
68
|
-
if (where?.id?.gte) query = query.gte("id", where.id.gte);
|
|
69
|
-
if (where?.id?.lt) query = query.lt("id", where.id.lt);
|
|
70
|
-
if (where?.id?.lte) query = query.lte("id", where.id.lte);
|
|
71
|
-
if (where?.id?.in) query = query.in("id", where.id.in);
|
|
72
|
-
if (limit) query = query.limit(limit);
|
|
73
|
-
if (offset) query = query.range(offset, offset + (limit || 20) - 1);
|
|
74
|
-
const { data } = await query;
|
|
75
|
-
return {
|
|
76
|
-
data: data ? data.map((bundle) => ({
|
|
77
|
-
channel: bundle.channel,
|
|
78
|
-
enabled: bundle.enabled,
|
|
79
|
-
shouldForceUpdate: bundle.should_force_update,
|
|
80
|
-
fileHash: bundle.file_hash,
|
|
81
|
-
gitCommitHash: bundle.git_commit_hash,
|
|
82
|
-
id: bundle.id,
|
|
83
|
-
message: bundle.message,
|
|
84
|
-
platform: bundle.platform,
|
|
85
|
-
targetAppVersion: bundle.target_app_version,
|
|
86
|
-
fingerprintHash: bundle.fingerprint_hash,
|
|
87
|
-
storageUri: bundle.storage_uri,
|
|
88
|
-
metadata: bundle.metadata ?? {},
|
|
89
|
-
rolloutCohortCount: bundle.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
90
|
-
targetCohorts: bundle.target_cohorts ?? null
|
|
91
|
-
})) : [],
|
|
92
|
-
pagination: (0, _hot_updater_plugin_core.calculatePagination)(total ?? 0, {
|
|
93
|
-
limit,
|
|
94
|
-
offset
|
|
95
|
-
})
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
async getChannels() {
|
|
99
|
-
const { data, error } = await supabase.rpc("get_channels");
|
|
100
|
-
if (error) throw error;
|
|
101
|
-
return data.map((bundle) => bundle.channel);
|
|
102
|
-
},
|
|
103
|
-
async commitBundle({ changedSets }) {
|
|
104
|
-
if (changedSets.length === 0) return;
|
|
105
|
-
for (const op of changedSets) if (op.operation === "delete") {
|
|
106
|
-
const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
|
|
107
|
-
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
108
|
-
} else if (op.operation === "insert" || op.operation === "update") {
|
|
109
|
-
const bundle = op.data;
|
|
110
|
-
const { error } = await supabase.from("bundles").upsert({
|
|
111
|
-
id: bundle.id,
|
|
112
|
-
channel: bundle.channel,
|
|
113
|
-
enabled: bundle.enabled,
|
|
114
|
-
should_force_update: bundle.shouldForceUpdate,
|
|
115
|
-
file_hash: bundle.fileHash,
|
|
116
|
-
git_commit_hash: bundle.gitCommitHash,
|
|
117
|
-
message: bundle.message,
|
|
118
|
-
platform: bundle.platform,
|
|
119
|
-
target_app_version: bundle.targetAppVersion,
|
|
120
|
-
fingerprint_hash: bundle.fingerprintHash,
|
|
121
|
-
storage_uri: bundle.storageUri,
|
|
122
|
-
metadata: bundle.metadata,
|
|
123
|
-
rollout_cohort_count: bundle.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
124
|
-
target_cohorts: bundle.targetCohorts ?? null
|
|
125
|
-
}, { onConflict: "id" });
|
|
126
|
-
if (error) throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/supabaseEdgeFunctionDatabase.ts
|
|
134
|
-
const supabaseEdgeFunctionDatabase = (config, hooks) => {
|
|
135
|
-
return supabaseDatabase({
|
|
136
|
-
supabaseUrl: config.supabaseUrl,
|
|
137
|
-
supabaseAnonKey: config.supabaseServiceRoleKey
|
|
138
|
-
}, hooks);
|
|
139
|
-
};
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/supabaseEdgeFunctionStorage.ts
|
|
142
|
-
const supabaseEdgeFunctionStorage = (config) => {
|
|
143
|
-
const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseServiceRoleKey);
|
|
144
|
-
return () => {
|
|
145
|
-
return {
|
|
146
|
-
name: "supabaseEdgeFunctionStorage",
|
|
147
|
-
supportedProtocol: "supabase-storage",
|
|
148
|
-
async upload() {
|
|
149
|
-
throw new Error("supabaseEdgeFunctionStorage does not support upload() in the edge runtime.");
|
|
150
|
-
},
|
|
151
|
-
async delete(storageUri) {
|
|
152
|
-
const storageUrl = new URL(storageUri);
|
|
153
|
-
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
154
|
-
const bucketName = storageUrl.host;
|
|
155
|
-
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
156
|
-
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
157
|
-
const { error } = await supabase.storage.from(bucketName).remove([key]);
|
|
158
|
-
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
159
|
-
},
|
|
160
|
-
async getDownloadUrl(storageUri) {
|
|
161
|
-
const storageUrl = new URL(storageUri);
|
|
162
|
-
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
163
|
-
const bucketName = storageUrl.host;
|
|
164
|
-
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
165
|
-
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
166
|
-
const { data, error } = await supabase.storage.from(bucketName).createSignedUrl(key, config.signedUrlExpiresIn ?? 3600);
|
|
167
|
-
if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
|
|
168
|
-
if (!data?.signedUrl) throw new Error("Failed to generate download URL");
|
|
169
|
-
return { fileUrl: data.signedUrl };
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
//#endregion
|
|
175
|
-
Object.defineProperty(exports, "supabaseDatabase", {
|
|
176
|
-
enumerable: true,
|
|
177
|
-
get: function() {
|
|
178
|
-
return supabaseDatabase;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
Object.defineProperty(exports, "supabaseEdgeFunctionDatabase", {
|
|
182
|
-
enumerable: true,
|
|
183
|
-
get: function() {
|
|
184
|
-
return supabaseEdgeFunctionDatabase;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
Object.defineProperty(exports, "supabaseEdgeFunctionStorage", {
|
|
188
|
-
enumerable: true,
|
|
189
|
-
get: function() {
|
|
190
|
-
return supabaseEdgeFunctionStorage;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_ROLLOUT_COHORT_COUNT } from "@hot-updater/core";
|
|
2
|
-
import { calculatePagination, createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
3
|
-
import { createClient } from "@supabase/supabase-js";
|
|
4
|
-
//#region src/supabaseDatabase.ts
|
|
5
|
-
const supabaseDatabase = createDatabasePlugin({
|
|
6
|
-
name: "supabaseDatabase",
|
|
7
|
-
factory: (config) => {
|
|
8
|
-
const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey);
|
|
9
|
-
return {
|
|
10
|
-
async getBundleById(bundleId) {
|
|
11
|
-
const { data, error } = await supabase.from("bundles").select("channel, enabled, should_force_update, file_hash, git_commit_hash, id, message, platform, target_app_version, fingerprint_hash, storage_uri, metadata, rollout_cohort_count, target_cohorts").eq("id", bundleId).single();
|
|
12
|
-
if (!data || error) return null;
|
|
13
|
-
return {
|
|
14
|
-
channel: data.channel,
|
|
15
|
-
enabled: data.enabled,
|
|
16
|
-
shouldForceUpdate: data.should_force_update,
|
|
17
|
-
fileHash: data.file_hash,
|
|
18
|
-
gitCommitHash: data.git_commit_hash,
|
|
19
|
-
id: data.id,
|
|
20
|
-
message: data.message,
|
|
21
|
-
platform: data.platform,
|
|
22
|
-
targetAppVersion: data.target_app_version,
|
|
23
|
-
fingerprintHash: data.fingerprint_hash,
|
|
24
|
-
storageUri: data.storage_uri,
|
|
25
|
-
metadata: data.metadata ?? {},
|
|
26
|
-
rolloutCohortCount: data.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
27
|
-
targetCohorts: data.target_cohorts ?? null
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
async getBundles(options) {
|
|
31
|
-
const { where, limit, offset, orderBy } = options ?? {};
|
|
32
|
-
if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0 || where?.id?.in && where.id.in.length === 0) return {
|
|
33
|
-
data: [],
|
|
34
|
-
pagination: calculatePagination(0, {
|
|
35
|
-
limit,
|
|
36
|
-
offset
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
let countQuery = supabase.from("bundles").select("*", {
|
|
40
|
-
count: "exact",
|
|
41
|
-
head: true
|
|
42
|
-
});
|
|
43
|
-
if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
|
|
44
|
-
if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
|
|
45
|
-
if (where?.enabled !== void 0) countQuery = countQuery.eq("enabled", where.enabled);
|
|
46
|
-
if (where?.fingerprintHash !== void 0) countQuery = where.fingerprintHash === null ? countQuery.is("fingerprint_hash", null) : countQuery.eq("fingerprint_hash", where.fingerprintHash);
|
|
47
|
-
if (where?.targetAppVersion !== void 0) countQuery = where.targetAppVersion === null ? countQuery.is("target_app_version", null) : countQuery.eq("target_app_version", where.targetAppVersion);
|
|
48
|
-
if (where?.targetAppVersionIn) countQuery = countQuery.in("target_app_version", where.targetAppVersionIn);
|
|
49
|
-
if (where?.targetAppVersionNotNull) countQuery = countQuery.not("target_app_version", "is", null);
|
|
50
|
-
if (where?.id?.eq) countQuery = countQuery.eq("id", where.id.eq);
|
|
51
|
-
if (where?.id?.gt) countQuery = countQuery.gt("id", where.id.gt);
|
|
52
|
-
if (where?.id?.gte) countQuery = countQuery.gte("id", where.id.gte);
|
|
53
|
-
if (where?.id?.lt) countQuery = countQuery.lt("id", where.id.lt);
|
|
54
|
-
if (where?.id?.lte) countQuery = countQuery.lte("id", where.id.lte);
|
|
55
|
-
if (where?.id?.in) countQuery = countQuery.in("id", where.id.in);
|
|
56
|
-
const { count: total = 0 } = await countQuery;
|
|
57
|
-
let query = supabase.from("bundles").select("id, channel, enabled, platform, should_force_update, file_hash, git_commit_hash, message, fingerprint_hash, target_app_version, storage_uri, metadata, rollout_cohort_count, target_cohorts").order("id", { ascending: orderBy?.direction === "asc" });
|
|
58
|
-
if (where?.channel) query = query.eq("channel", where.channel);
|
|
59
|
-
if (where?.platform) query = query.eq("platform", where.platform);
|
|
60
|
-
if (where?.enabled !== void 0) query = query.eq("enabled", where.enabled);
|
|
61
|
-
if (where?.fingerprintHash !== void 0) query = where.fingerprintHash === null ? query.is("fingerprint_hash", null) : query.eq("fingerprint_hash", where.fingerprintHash);
|
|
62
|
-
if (where?.targetAppVersion !== void 0) query = where.targetAppVersion === null ? query.is("target_app_version", null) : query.eq("target_app_version", where.targetAppVersion);
|
|
63
|
-
if (where?.targetAppVersionIn) query = query.in("target_app_version", where.targetAppVersionIn);
|
|
64
|
-
if (where?.targetAppVersionNotNull) query = query.not("target_app_version", "is", null);
|
|
65
|
-
if (where?.id?.eq) query = query.eq("id", where.id.eq);
|
|
66
|
-
if (where?.id?.gt) query = query.gt("id", where.id.gt);
|
|
67
|
-
if (where?.id?.gte) query = query.gte("id", where.id.gte);
|
|
68
|
-
if (where?.id?.lt) query = query.lt("id", where.id.lt);
|
|
69
|
-
if (where?.id?.lte) query = query.lte("id", where.id.lte);
|
|
70
|
-
if (where?.id?.in) query = query.in("id", where.id.in);
|
|
71
|
-
if (limit) query = query.limit(limit);
|
|
72
|
-
if (offset) query = query.range(offset, offset + (limit || 20) - 1);
|
|
73
|
-
const { data } = await query;
|
|
74
|
-
return {
|
|
75
|
-
data: data ? data.map((bundle) => ({
|
|
76
|
-
channel: bundle.channel,
|
|
77
|
-
enabled: bundle.enabled,
|
|
78
|
-
shouldForceUpdate: bundle.should_force_update,
|
|
79
|
-
fileHash: bundle.file_hash,
|
|
80
|
-
gitCommitHash: bundle.git_commit_hash,
|
|
81
|
-
id: bundle.id,
|
|
82
|
-
message: bundle.message,
|
|
83
|
-
platform: bundle.platform,
|
|
84
|
-
targetAppVersion: bundle.target_app_version,
|
|
85
|
-
fingerprintHash: bundle.fingerprint_hash,
|
|
86
|
-
storageUri: bundle.storage_uri,
|
|
87
|
-
metadata: bundle.metadata ?? {},
|
|
88
|
-
rolloutCohortCount: bundle.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
89
|
-
targetCohorts: bundle.target_cohorts ?? null
|
|
90
|
-
})) : [],
|
|
91
|
-
pagination: calculatePagination(total ?? 0, {
|
|
92
|
-
limit,
|
|
93
|
-
offset
|
|
94
|
-
})
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
async getChannels() {
|
|
98
|
-
const { data, error } = await supabase.rpc("get_channels");
|
|
99
|
-
if (error) throw error;
|
|
100
|
-
return data.map((bundle) => bundle.channel);
|
|
101
|
-
},
|
|
102
|
-
async commitBundle({ changedSets }) {
|
|
103
|
-
if (changedSets.length === 0) return;
|
|
104
|
-
for (const op of changedSets) if (op.operation === "delete") {
|
|
105
|
-
const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
|
|
106
|
-
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
107
|
-
} else if (op.operation === "insert" || op.operation === "update") {
|
|
108
|
-
const bundle = op.data;
|
|
109
|
-
const { error } = await supabase.from("bundles").upsert({
|
|
110
|
-
id: bundle.id,
|
|
111
|
-
channel: bundle.channel,
|
|
112
|
-
enabled: bundle.enabled,
|
|
113
|
-
should_force_update: bundle.shouldForceUpdate,
|
|
114
|
-
file_hash: bundle.fileHash,
|
|
115
|
-
git_commit_hash: bundle.gitCommitHash,
|
|
116
|
-
message: bundle.message,
|
|
117
|
-
platform: bundle.platform,
|
|
118
|
-
target_app_version: bundle.targetAppVersion,
|
|
119
|
-
fingerprint_hash: bundle.fingerprintHash,
|
|
120
|
-
storage_uri: bundle.storageUri,
|
|
121
|
-
metadata: bundle.metadata,
|
|
122
|
-
rollout_cohort_count: bundle.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
123
|
-
target_cohorts: bundle.targetCohorts ?? null
|
|
124
|
-
}, { onConflict: "id" });
|
|
125
|
-
if (error) throw error;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/supabaseEdgeFunctionDatabase.ts
|
|
133
|
-
const supabaseEdgeFunctionDatabase = (config, hooks) => {
|
|
134
|
-
return supabaseDatabase({
|
|
135
|
-
supabaseUrl: config.supabaseUrl,
|
|
136
|
-
supabaseAnonKey: config.supabaseServiceRoleKey
|
|
137
|
-
}, hooks);
|
|
138
|
-
};
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/supabaseEdgeFunctionStorage.ts
|
|
141
|
-
const supabaseEdgeFunctionStorage = (config) => {
|
|
142
|
-
const supabase = createClient(config.supabaseUrl, config.supabaseServiceRoleKey);
|
|
143
|
-
return () => {
|
|
144
|
-
return {
|
|
145
|
-
name: "supabaseEdgeFunctionStorage",
|
|
146
|
-
supportedProtocol: "supabase-storage",
|
|
147
|
-
async upload() {
|
|
148
|
-
throw new Error("supabaseEdgeFunctionStorage does not support upload() in the edge runtime.");
|
|
149
|
-
},
|
|
150
|
-
async delete(storageUri) {
|
|
151
|
-
const storageUrl = new URL(storageUri);
|
|
152
|
-
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
153
|
-
const bucketName = storageUrl.host;
|
|
154
|
-
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
155
|
-
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
156
|
-
const { error } = await supabase.storage.from(bucketName).remove([key]);
|
|
157
|
-
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
158
|
-
},
|
|
159
|
-
async getDownloadUrl(storageUri) {
|
|
160
|
-
const storageUrl = new URL(storageUri);
|
|
161
|
-
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
162
|
-
const bucketName = storageUrl.host;
|
|
163
|
-
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
164
|
-
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
165
|
-
const { data, error } = await supabase.storage.from(bucketName).createSignedUrl(key, config.signedUrlExpiresIn ?? 3600);
|
|
166
|
-
if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
|
|
167
|
-
if (!data?.signedUrl) throw new Error("Failed to generate download URL");
|
|
168
|
-
return { fileUrl: data.signedUrl };
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
//#endregion
|
|
174
|
-
export { supabaseEdgeFunctionDatabase as n, supabaseDatabase as r, supabaseEdgeFunctionStorage as t };
|