@hot-updater/supabase 0.29.5 → 0.29.7

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 CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_supabaseEdgeFunctionStorage = require("./supabaseEdgeFunctionStorage-B-gM2rZx.cjs");
2
+ const require_supabaseEdgeFunctionStorage = require("./supabaseEdgeFunctionStorage-Dd8ytWP1.cjs");
3
3
  exports.supabaseEdgeFunctionDatabase = require_supabaseEdgeFunctionStorage.supabaseEdgeFunctionDatabase;
4
4
  exports.supabaseEdgeFunctionStorage = require_supabaseEdgeFunctionStorage.supabaseEdgeFunctionStorage;
package/dist/edge.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as supabaseEdgeFunctionDatabase, t as supabaseEdgeFunctionStorage } from "./supabaseEdgeFunctionStorage-CVEY5QJO.mjs";
1
+ import { n as supabaseEdgeFunctionDatabase, t as supabaseEdgeFunctionStorage } from "./supabaseEdgeFunctionStorage-DnnViEfo.mjs";
2
2
  export { supabaseEdgeFunctionDatabase, supabaseEdgeFunctionStorage };
@@ -6259,8 +6259,8 @@ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__
6259
6259
  const EDGE_VENDOR_DIR = "_hot-updater";
6260
6260
  const WORKSPACE_PACKAGE_PREFIX = "@hot-updater/";
6261
6261
  const IMPORT_SPECIFIER_PATTERN = /from\s+["']([^"']+)["']|import\s*\(\s*["']([^"']+)["']\s*\)/g;
6262
- const getConfigTemplate = (build) => {
6263
- return new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage({
6262
+ const getConfigScaffold = (build) => {
6263
+ return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage({
6264
6264
  imports: [{
6265
6265
  pkg: "@hot-updater/supabase",
6266
6266
  named: ["supabaseStorage"]
@@ -6279,7 +6279,7 @@ const getConfigTemplate = (build) => {
6279
6279
  supabaseUrl: process.env.HOT_UPDATER_SUPABASE_URL!,
6280
6280
  supabaseAnonKey: process.env.HOT_UPDATER_SUPABASE_ANON_KEY!,
6281
6281
  })`
6282
- }).getResult();
6282
+ }));
6283
6283
  };
6284
6284
  const SOURCE_TEMPLATE = `// add this to your App.tsx
6285
6285
  import { HotUpdater } from "@hot-updater/react-native";
@@ -6661,14 +6661,16 @@ const runInit = async ({ build }) => {
6661
6661
  await pushDB(tmpDir, { dbPassword });
6662
6662
  await deployEdgeFunction(tmpDir, project.id);
6663
6663
  await removeTmpDir();
6664
- await fs_promises.default.writeFile("hot-updater.config.ts", getConfigTemplate(build));
6664
+ const configWriteResult = await (0, _hot_updater_cli_tools.writeHotUpdaterConfig)(getConfigScaffold(build));
6665
6665
  await (0, _hot_updater_cli_tools.makeEnv)({
6666
6666
  HOT_UPDATER_SUPABASE_ANON_KEY: serviceRoleKey.api_key,
6667
6667
  HOT_UPDATER_SUPABASE_BUCKET_NAME: bucket.name,
6668
6668
  HOT_UPDATER_SUPABASE_URL: `https://${project.id}.supabase.co`
6669
6669
  });
6670
6670
  _hot_updater_cli_tools.p.log.success("Generated '.env.hotupdater' file with Supabase settings.");
6671
- _hot_updater_cli_tools.p.log.success("Generated 'hot-updater.config.ts' file with Supabase settings.");
6671
+ if (configWriteResult.status === "created") _hot_updater_cli_tools.p.log.success("Generated 'hot-updater.config.ts' file with Supabase settings.");
6672
+ else if (configWriteResult.status === "merged") _hot_updater_cli_tools.p.log.success("Updated 'hot-updater.config.ts' file with Supabase settings.");
6673
+ else _hot_updater_cli_tools.p.log.warn(`Kept existing 'hot-updater.config.ts' unchanged: ${configWriteResult.reason}`);
6672
6674
  _hot_updater_cli_tools.p.note((0, _hot_updater_cli_tools.transformTemplate)(SOURCE_TEMPLATE, { source: `https://${project.id}.supabase.co/functions/v1/update-server` }));
6673
6675
  _hot_updater_cli_tools.p.log.message(`Next step: ${(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/supabase#step-4-add-hotupdater-to-your-project")}`);
6674
6676
  _hot_updater_cli_tools.p.log.success("Done! 🎉");
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import fs from "fs/promises";
3
3
  import path from "path";
4
- import { ConfigBuilder, copyDirToTmp, link, makeEnv, p, resolvePackageVersion, transformEnv, transformTemplate } from "@hot-updater/cli-tools";
4
+ import { ConfigBuilder, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, link, makeEnv, p, resolvePackageVersion, transformEnv, transformTemplate, writeHotUpdaterConfig } from "@hot-updater/cli-tools";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
7
7
  import { StringDecoder } from "node:string_decoder";
@@ -6254,8 +6254,8 @@ const require$1 = createRequire(import.meta.url);
6254
6254
  const EDGE_VENDOR_DIR = "_hot-updater";
6255
6255
  const WORKSPACE_PACKAGE_PREFIX = "@hot-updater/";
6256
6256
  const IMPORT_SPECIFIER_PATTERN = /from\s+["']([^"']+)["']|import\s*\(\s*["']([^"']+)["']\s*\)/g;
6257
- const getConfigTemplate = (build) => {
6258
- return new ConfigBuilder().setBuildType(build).setStorage({
6257
+ const getConfigScaffold = (build) => {
6258
+ return createHotUpdaterConfigScaffoldFromBuilder(new ConfigBuilder().setBuildType(build).setStorage({
6259
6259
  imports: [{
6260
6260
  pkg: "@hot-updater/supabase",
6261
6261
  named: ["supabaseStorage"]
@@ -6274,7 +6274,7 @@ const getConfigTemplate = (build) => {
6274
6274
  supabaseUrl: process.env.HOT_UPDATER_SUPABASE_URL!,
6275
6275
  supabaseAnonKey: process.env.HOT_UPDATER_SUPABASE_ANON_KEY!,
6276
6276
  })`
6277
- }).getResult();
6277
+ }));
6278
6278
  };
6279
6279
  const SOURCE_TEMPLATE = `// add this to your App.tsx
6280
6280
  import { HotUpdater } from "@hot-updater/react-native";
@@ -6656,14 +6656,16 @@ const runInit = async ({ build }) => {
6656
6656
  await pushDB(tmpDir, { dbPassword });
6657
6657
  await deployEdgeFunction(tmpDir, project.id);
6658
6658
  await removeTmpDir();
6659
- await fs.writeFile("hot-updater.config.ts", getConfigTemplate(build));
6659
+ const configWriteResult = await writeHotUpdaterConfig(getConfigScaffold(build));
6660
6660
  await makeEnv({
6661
6661
  HOT_UPDATER_SUPABASE_ANON_KEY: serviceRoleKey.api_key,
6662
6662
  HOT_UPDATER_SUPABASE_BUCKET_NAME: bucket.name,
6663
6663
  HOT_UPDATER_SUPABASE_URL: `https://${project.id}.supabase.co`
6664
6664
  });
6665
6665
  p.log.success("Generated '.env.hotupdater' file with Supabase settings.");
6666
- p.log.success("Generated 'hot-updater.config.ts' file with Supabase settings.");
6666
+ if (configWriteResult.status === "created") p.log.success("Generated 'hot-updater.config.ts' file with Supabase settings.");
6667
+ else if (configWriteResult.status === "merged") p.log.success("Updated 'hot-updater.config.ts' file with Supabase settings.");
6668
+ else p.log.warn(`Kept existing 'hot-updater.config.ts' unchanged: ${configWriteResult.reason}`);
6667
6669
  p.note(transformTemplate(SOURCE_TEMPLATE, { source: `https://${project.id}.supabase.co/functions/v1/update-server` }));
6668
6670
  p.log.message(`Next step: ${link("https://hot-updater.dev/docs/managed/supabase#step-4-add-hotupdater-to-your-project")}`);
6669
6671
  p.log.success("Done! 🎉");
package/dist/index.cjs CHANGED
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
- const require_supabaseEdgeFunctionStorage = require("./supabaseEdgeFunctionStorage-B-gM2rZx.cjs");
24
+ const require_supabaseEdgeFunctionStorage = require("./supabaseEdgeFunctionStorage-Dd8ytWP1.cjs");
25
25
  let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
26
26
  let _supabase_supabase_js = require("@supabase/supabase-js");
27
27
  let fs_promises = require("fs/promises");
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as supabaseEdgeFunctionDatabase, r as supabaseDatabase, t as supabaseEdgeFunctionStorage } from "./supabaseEdgeFunctionStorage-CVEY5QJO.mjs";
1
+ import { n as supabaseEdgeFunctionDatabase, r as supabaseDatabase, t as supabaseEdgeFunctionStorage } from "./supabaseEdgeFunctionStorage-DnnViEfo.mjs";
2
2
  import { createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
3
3
  import { createClient } from "@supabase/supabase-js";
4
4
  import fs from "fs/promises";
@@ -0,0 +1,545 @@
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 ../../node_modules/.pnpm/map-obj@5.0.0/node_modules/map-obj/index.js
6
+ const isObject$1 = (value) => typeof value === "object" && value !== null;
7
+ const isObjectCustom = (value) => isObject$1(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
8
+ const mapObjectSkip = Symbol("mapObjectSkip");
9
+ const _mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => {
10
+ options = {
11
+ deep: false,
12
+ target: {},
13
+ ...options
14
+ };
15
+ if (isSeen.has(object)) return isSeen.get(object);
16
+ isSeen.set(object, options.target);
17
+ const { target } = options;
18
+ delete options.target;
19
+ const mapArray = (array) => array.map((element) => isObjectCustom(element) ? _mapObject(element, mapper, options, isSeen) : element);
20
+ if (Array.isArray(object)) return mapArray(object);
21
+ for (const [key, value] of Object.entries(object)) {
22
+ const mapResult = mapper(key, value, object);
23
+ if (mapResult === mapObjectSkip) continue;
24
+ let [newKey, newValue, { shouldRecurse = true } = {}] = mapResult;
25
+ if (newKey === "__proto__") continue;
26
+ if (options.deep && shouldRecurse && isObjectCustom(newValue)) newValue = Array.isArray(newValue) ? mapArray(newValue) : _mapObject(newValue, mapper, options, isSeen);
27
+ target[newKey] = newValue;
28
+ }
29
+ return target;
30
+ };
31
+ function mapObject(object, mapper, options) {
32
+ if (!isObject$1(object)) throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
33
+ return _mapObject(object, mapper, options);
34
+ }
35
+ //#endregion
36
+ //#region ../../node_modules/.pnpm/camelcase@8.0.0/node_modules/camelcase/index.js
37
+ const UPPERCASE = /[\p{Lu}]/u;
38
+ const LOWERCASE = /[\p{Ll}]/u;
39
+ const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
40
+ const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
41
+ const SEPARATORS = /[_.\- ]+/;
42
+ const LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source);
43
+ const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
44
+ const NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
45
+ const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase) => {
46
+ let isLastCharLower = false;
47
+ let isLastCharUpper = false;
48
+ let isLastLastCharUpper = false;
49
+ let isLastLastCharPreserved = false;
50
+ for (let index = 0; index < string.length; index++) {
51
+ const character = string[index];
52
+ isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
53
+ if (isLastCharLower && UPPERCASE.test(character)) {
54
+ string = string.slice(0, index) + "-" + string.slice(index);
55
+ isLastCharLower = false;
56
+ isLastLastCharUpper = isLastCharUpper;
57
+ isLastCharUpper = true;
58
+ index++;
59
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase)) {
60
+ string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
61
+ isLastLastCharUpper = isLastCharUpper;
62
+ isLastCharUpper = false;
63
+ isLastCharLower = true;
64
+ } else {
65
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
66
+ isLastLastCharUpper = isLastCharUpper;
67
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
68
+ }
69
+ }
70
+ return string;
71
+ };
72
+ const preserveConsecutiveUppercase = (input, toLowerCase) => {
73
+ LEADING_CAPITAL.lastIndex = 0;
74
+ return input.replaceAll(LEADING_CAPITAL, (match) => toLowerCase(match));
75
+ };
76
+ const postProcess = (input, toUpperCase) => {
77
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
78
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
79
+ return input.replaceAll(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ["_", "-"].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match)).replaceAll(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));
80
+ };
81
+ function camelCase(input, options) {
82
+ if (!(typeof input === "string" || Array.isArray(input))) throw new TypeError("Expected the input to be `string | string[]`");
83
+ options = {
84
+ pascalCase: false,
85
+ preserveConsecutiveUppercase: false,
86
+ ...options
87
+ };
88
+ if (Array.isArray(input)) input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
89
+ else input = input.trim();
90
+ if (input.length === 0) return "";
91
+ const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
92
+ const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
93
+ if (input.length === 1) {
94
+ if (SEPARATORS.test(input)) return "";
95
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
96
+ }
97
+ if (input !== toLowerCase(input)) input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
98
+ input = input.replace(LEADING_SEPARATORS, "");
99
+ input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
100
+ if (options.pascalCase) input = toUpperCase(input.charAt(0)) + input.slice(1);
101
+ return postProcess(input, toUpperCase);
102
+ }
103
+ //#endregion
104
+ //#region ../../node_modules/.pnpm/quick-lru@6.1.2/node_modules/quick-lru/index.js
105
+ var QuickLRU = class extends Map {
106
+ constructor(options = {}) {
107
+ super();
108
+ if (!(options.maxSize && options.maxSize > 0)) throw new TypeError("`maxSize` must be a number greater than 0");
109
+ if (typeof options.maxAge === "number" && options.maxAge === 0) throw new TypeError("`maxAge` must be a number greater than 0");
110
+ this.maxSize = options.maxSize;
111
+ this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
112
+ this.onEviction = options.onEviction;
113
+ this.cache = /* @__PURE__ */ new Map();
114
+ this.oldCache = /* @__PURE__ */ new Map();
115
+ this._size = 0;
116
+ }
117
+ _emitEvictions(cache) {
118
+ if (typeof this.onEviction !== "function") return;
119
+ for (const [key, item] of cache) this.onEviction(key, item.value);
120
+ }
121
+ _deleteIfExpired(key, item) {
122
+ if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
123
+ if (typeof this.onEviction === "function") this.onEviction(key, item.value);
124
+ return this.delete(key);
125
+ }
126
+ return false;
127
+ }
128
+ _getOrDeleteIfExpired(key, item) {
129
+ if (this._deleteIfExpired(key, item) === false) return item.value;
130
+ }
131
+ _getItemValue(key, item) {
132
+ return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
133
+ }
134
+ _peek(key, cache) {
135
+ const item = cache.get(key);
136
+ return this._getItemValue(key, item);
137
+ }
138
+ _set(key, value) {
139
+ this.cache.set(key, value);
140
+ this._size++;
141
+ if (this._size >= this.maxSize) {
142
+ this._size = 0;
143
+ this._emitEvictions(this.oldCache);
144
+ this.oldCache = this.cache;
145
+ this.cache = /* @__PURE__ */ new Map();
146
+ }
147
+ }
148
+ _moveToRecent(key, item) {
149
+ this.oldCache.delete(key);
150
+ this._set(key, item);
151
+ }
152
+ *_entriesAscending() {
153
+ for (const item of this.oldCache) {
154
+ const [key, value] = item;
155
+ if (!this.cache.has(key)) {
156
+ if (this._deleteIfExpired(key, value) === false) yield item;
157
+ }
158
+ }
159
+ for (const item of this.cache) {
160
+ const [key, value] = item;
161
+ if (this._deleteIfExpired(key, value) === false) yield item;
162
+ }
163
+ }
164
+ get(key) {
165
+ if (this.cache.has(key)) {
166
+ const item = this.cache.get(key);
167
+ return this._getItemValue(key, item);
168
+ }
169
+ if (this.oldCache.has(key)) {
170
+ const item = this.oldCache.get(key);
171
+ if (this._deleteIfExpired(key, item) === false) {
172
+ this._moveToRecent(key, item);
173
+ return item.value;
174
+ }
175
+ }
176
+ }
177
+ set(key, value, { maxAge = this.maxAge } = {}) {
178
+ const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : void 0;
179
+ if (this.cache.has(key)) this.cache.set(key, {
180
+ value,
181
+ expiry
182
+ });
183
+ else this._set(key, {
184
+ value,
185
+ expiry
186
+ });
187
+ return this;
188
+ }
189
+ has(key) {
190
+ if (this.cache.has(key)) return !this._deleteIfExpired(key, this.cache.get(key));
191
+ if (this.oldCache.has(key)) return !this._deleteIfExpired(key, this.oldCache.get(key));
192
+ return false;
193
+ }
194
+ peek(key) {
195
+ if (this.cache.has(key)) return this._peek(key, this.cache);
196
+ if (this.oldCache.has(key)) return this._peek(key, this.oldCache);
197
+ }
198
+ delete(key) {
199
+ const deleted = this.cache.delete(key);
200
+ if (deleted) this._size--;
201
+ return this.oldCache.delete(key) || deleted;
202
+ }
203
+ clear() {
204
+ this.cache.clear();
205
+ this.oldCache.clear();
206
+ this._size = 0;
207
+ }
208
+ resize(newSize) {
209
+ if (!(newSize && newSize > 0)) throw new TypeError("`maxSize` must be a number greater than 0");
210
+ const items = [...this._entriesAscending()];
211
+ const removeCount = items.length - newSize;
212
+ if (removeCount < 0) {
213
+ this.cache = new Map(items);
214
+ this.oldCache = /* @__PURE__ */ new Map();
215
+ this._size = items.length;
216
+ } else {
217
+ if (removeCount > 0) this._emitEvictions(items.slice(0, removeCount));
218
+ this.oldCache = new Map(items.slice(removeCount));
219
+ this.cache = /* @__PURE__ */ new Map();
220
+ this._size = 0;
221
+ }
222
+ this.maxSize = newSize;
223
+ }
224
+ *keys() {
225
+ for (const [key] of this) yield key;
226
+ }
227
+ *values() {
228
+ for (const [, value] of this) yield value;
229
+ }
230
+ *[Symbol.iterator]() {
231
+ for (const item of this.cache) {
232
+ const [key, value] = item;
233
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
234
+ }
235
+ for (const item of this.oldCache) {
236
+ const [key, value] = item;
237
+ if (!this.cache.has(key)) {
238
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
239
+ }
240
+ }
241
+ }
242
+ *entriesDescending() {
243
+ let items = [...this.cache];
244
+ for (let i = items.length - 1; i >= 0; --i) {
245
+ const [key, value] = items[i];
246
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
247
+ }
248
+ items = [...this.oldCache];
249
+ for (let i = items.length - 1; i >= 0; --i) {
250
+ const [key, value] = items[i];
251
+ if (!this.cache.has(key)) {
252
+ if (this._deleteIfExpired(key, value) === false) yield [key, value.value];
253
+ }
254
+ }
255
+ }
256
+ *entriesAscending() {
257
+ for (const [key, value] of this._entriesAscending()) yield [key, value.value];
258
+ }
259
+ get size() {
260
+ if (!this._size) return this.oldCache.size;
261
+ let oldCacheSize = 0;
262
+ for (const key of this.oldCache.keys()) if (!this.cache.has(key)) oldCacheSize++;
263
+ return Math.min(this._size + oldCacheSize, this.maxSize);
264
+ }
265
+ entries() {
266
+ return this.entriesAscending();
267
+ }
268
+ forEach(callbackFunction, thisArgument = this) {
269
+ for (const [key, value] of this.entriesAscending()) callbackFunction.call(thisArgument, value, key, this);
270
+ }
271
+ get [Symbol.toStringTag]() {
272
+ return JSON.stringify([...this.entriesAscending()]);
273
+ }
274
+ };
275
+ //#endregion
276
+ //#region ../../node_modules/.pnpm/camelcase-keys@9.1.3/node_modules/camelcase-keys/index.js
277
+ const has = (array, key) => array.some((element) => {
278
+ if (typeof element === "string") return element === key;
279
+ element.lastIndex = 0;
280
+ return element.test(key);
281
+ });
282
+ const cache = new QuickLRU({ maxSize: 1e5 });
283
+ const isObject = (value) => typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date);
284
+ const transform = (input, options = {}) => {
285
+ if (!isObject(input)) return input;
286
+ const { exclude, pascalCase = false, stopPaths, deep = false, preserveConsecutiveUppercase = false } = options;
287
+ const stopPathsSet = new Set(stopPaths);
288
+ const makeMapper = (parentPath) => (key, value) => {
289
+ if (deep && isObject(value)) {
290
+ const path = parentPath === void 0 ? key : `${parentPath}.${key}`;
291
+ if (!stopPathsSet.has(path)) value = mapObject(value, makeMapper(path));
292
+ }
293
+ if (!(exclude && has(exclude, key))) {
294
+ const cacheKey = pascalCase ? `${key}_` : key;
295
+ if (cache.has(cacheKey)) key = cache.get(cacheKey);
296
+ else {
297
+ const returnValue = camelCase(key, {
298
+ pascalCase,
299
+ locale: false,
300
+ preserveConsecutiveUppercase
301
+ });
302
+ if (key.length < 100) cache.set(cacheKey, returnValue);
303
+ key = returnValue;
304
+ }
305
+ }
306
+ return [key, value];
307
+ };
308
+ return mapObject(input, makeMapper(void 0));
309
+ };
310
+ function camelcaseKeys(input, options) {
311
+ if (Array.isArray(input)) return Object.keys(input).map((key) => transform(input[key], options));
312
+ return transform(input, options);
313
+ }
314
+ //#endregion
315
+ //#region src/getUpdateInfo.ts
316
+ const appVersionStrategy = async (supabase, { platform, appVersion, bundleId, minBundleId = _hot_updater_core.NIL_UUID, channel = "production", cohort }) => {
317
+ const { data: appVersionList, error: appVersionListError } = await supabase.rpc("get_target_app_version_list", {
318
+ app_platform: platform,
319
+ min_bundle_id: minBundleId
320
+ });
321
+ if (appVersionListError) throw appVersionListError;
322
+ const targetAppVersionList = (0, _hot_updater_plugin_core.filterCompatibleAppVersions)((appVersionList ?? []).map((group) => group.target_app_version), appVersion);
323
+ const { data, error } = await supabase.rpc("get_update_info_by_app_version", {
324
+ app_platform: platform,
325
+ app_version: appVersion,
326
+ bundle_id: bundleId,
327
+ min_bundle_id: minBundleId,
328
+ target_channel: channel,
329
+ target_app_version_list: targetAppVersionList,
330
+ cohort: cohort ?? null
331
+ });
332
+ if (error) throw error;
333
+ const row = data?.[0];
334
+ return row ? camelcaseKeys(row) : null;
335
+ };
336
+ const fingerprintStrategy = async (supabase, { platform, fingerprintHash, bundleId, minBundleId = _hot_updater_core.NIL_UUID, channel = "production", cohort }) => {
337
+ const { data, error } = await supabase.rpc("get_update_info_by_fingerprint_hash", {
338
+ app_platform: platform,
339
+ bundle_id: bundleId,
340
+ min_bundle_id: minBundleId,
341
+ target_channel: channel,
342
+ target_fingerprint_hash: fingerprintHash,
343
+ cohort: cohort ?? null
344
+ });
345
+ if (error) throw error;
346
+ const row = data?.[0];
347
+ return row ? camelcaseKeys(row) : null;
348
+ };
349
+ const getUpdateInfo = (supabase, args) => {
350
+ if (args._updateStrategy === "appVersion") return appVersionStrategy(supabase, args);
351
+ return fingerprintStrategy(supabase, args);
352
+ };
353
+ //#endregion
354
+ //#region src/supabaseDatabase.ts
355
+ const supabaseDatabase = (0, _hot_updater_plugin_core.createDatabasePlugin)({
356
+ name: "supabaseDatabase",
357
+ factory: (config) => {
358
+ const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseAnonKey);
359
+ return {
360
+ async getUpdateInfo(args) {
361
+ return getUpdateInfo(supabase, args);
362
+ },
363
+ async getBundleById(bundleId) {
364
+ 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();
365
+ if (!data || error) return null;
366
+ return {
367
+ channel: data.channel,
368
+ enabled: data.enabled,
369
+ shouldForceUpdate: data.should_force_update,
370
+ fileHash: data.file_hash,
371
+ gitCommitHash: data.git_commit_hash,
372
+ id: data.id,
373
+ message: data.message,
374
+ platform: data.platform,
375
+ targetAppVersion: data.target_app_version,
376
+ fingerprintHash: data.fingerprint_hash,
377
+ storageUri: data.storage_uri,
378
+ metadata: data.metadata ?? {},
379
+ rolloutCohortCount: data.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
380
+ targetCohorts: data.target_cohorts ?? null
381
+ };
382
+ },
383
+ async getBundles(options) {
384
+ const { where, limit, orderBy } = options ?? {};
385
+ const offset = (options && "offset" in options ? options.offset : void 0) ?? 0;
386
+ if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0 || where?.id?.in && where.id.in.length === 0) return {
387
+ data: [],
388
+ pagination: (0, _hot_updater_plugin_core.calculatePagination)(0, {
389
+ limit,
390
+ offset
391
+ })
392
+ };
393
+ let countQuery = supabase.from("bundles").select("*", {
394
+ count: "exact",
395
+ head: true
396
+ });
397
+ if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
398
+ if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
399
+ if (where?.enabled !== void 0) countQuery = countQuery.eq("enabled", where.enabled);
400
+ if (where?.fingerprintHash !== void 0) countQuery = where.fingerprintHash === null ? countQuery.is("fingerprint_hash", null) : countQuery.eq("fingerprint_hash", where.fingerprintHash);
401
+ if (where?.targetAppVersion !== void 0) countQuery = where.targetAppVersion === null ? countQuery.is("target_app_version", null) : countQuery.eq("target_app_version", where.targetAppVersion);
402
+ if (where?.targetAppVersionIn) countQuery = countQuery.in("target_app_version", where.targetAppVersionIn);
403
+ if (where?.targetAppVersionNotNull) countQuery = countQuery.not("target_app_version", "is", null);
404
+ if (where?.id?.eq) countQuery = countQuery.eq("id", where.id.eq);
405
+ if (where?.id?.gt) countQuery = countQuery.gt("id", where.id.gt);
406
+ if (where?.id?.gte) countQuery = countQuery.gte("id", where.id.gte);
407
+ if (where?.id?.lt) countQuery = countQuery.lt("id", where.id.lt);
408
+ if (where?.id?.lte) countQuery = countQuery.lte("id", where.id.lte);
409
+ if (where?.id?.in) countQuery = countQuery.in("id", where.id.in);
410
+ const { count: total = 0 } = await countQuery;
411
+ 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" });
412
+ if (where?.channel) query = query.eq("channel", where.channel);
413
+ if (where?.platform) query = query.eq("platform", where.platform);
414
+ if (where?.enabled !== void 0) query = query.eq("enabled", where.enabled);
415
+ if (where?.fingerprintHash !== void 0) query = where.fingerprintHash === null ? query.is("fingerprint_hash", null) : query.eq("fingerprint_hash", where.fingerprintHash);
416
+ if (where?.targetAppVersion !== void 0) query = where.targetAppVersion === null ? query.is("target_app_version", null) : query.eq("target_app_version", where.targetAppVersion);
417
+ if (where?.targetAppVersionIn) query = query.in("target_app_version", where.targetAppVersionIn);
418
+ if (where?.targetAppVersionNotNull) query = query.not("target_app_version", "is", null);
419
+ if (where?.id?.eq) query = query.eq("id", where.id.eq);
420
+ if (where?.id?.gt) query = query.gt("id", where.id.gt);
421
+ if (where?.id?.gte) query = query.gte("id", where.id.gte);
422
+ if (where?.id?.lt) query = query.lt("id", where.id.lt);
423
+ if (where?.id?.lte) query = query.lte("id", where.id.lte);
424
+ if (where?.id?.in) query = query.in("id", where.id.in);
425
+ if (limit) query = query.limit(limit);
426
+ if (offset) query = query.range(offset, offset + (limit || 20) - 1);
427
+ const { data } = await query;
428
+ return {
429
+ data: data ? data.map((bundle) => ({
430
+ channel: bundle.channel,
431
+ enabled: bundle.enabled,
432
+ shouldForceUpdate: bundle.should_force_update,
433
+ fileHash: bundle.file_hash,
434
+ gitCommitHash: bundle.git_commit_hash,
435
+ id: bundle.id,
436
+ message: bundle.message,
437
+ platform: bundle.platform,
438
+ targetAppVersion: bundle.target_app_version,
439
+ fingerprintHash: bundle.fingerprint_hash,
440
+ storageUri: bundle.storage_uri,
441
+ metadata: bundle.metadata ?? {},
442
+ rolloutCohortCount: bundle.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
443
+ targetCohorts: bundle.target_cohorts ?? null
444
+ })) : [],
445
+ pagination: (0, _hot_updater_plugin_core.calculatePagination)(total ?? 0, {
446
+ limit,
447
+ offset
448
+ })
449
+ };
450
+ },
451
+ async getChannels() {
452
+ const { data, error } = await supabase.rpc("get_channels");
453
+ if (error) throw error;
454
+ return data.map((bundle) => bundle.channel);
455
+ },
456
+ async commitBundle({ changedSets }) {
457
+ if (changedSets.length === 0) return;
458
+ for (const op of changedSets) if (op.operation === "delete") {
459
+ const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
460
+ if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
461
+ } else if (op.operation === "insert" || op.operation === "update") {
462
+ const bundle = op.data;
463
+ const { error } = await supabase.from("bundles").upsert({
464
+ id: bundle.id,
465
+ channel: bundle.channel,
466
+ enabled: bundle.enabled,
467
+ should_force_update: bundle.shouldForceUpdate,
468
+ file_hash: bundle.fileHash,
469
+ git_commit_hash: bundle.gitCommitHash,
470
+ message: bundle.message,
471
+ platform: bundle.platform,
472
+ target_app_version: bundle.targetAppVersion,
473
+ fingerprint_hash: bundle.fingerprintHash,
474
+ storage_uri: bundle.storageUri,
475
+ metadata: bundle.metadata,
476
+ rollout_cohort_count: bundle.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
477
+ target_cohorts: bundle.targetCohorts ?? null
478
+ }, { onConflict: "id" });
479
+ if (error) throw error;
480
+ }
481
+ }
482
+ };
483
+ }
484
+ });
485
+ //#endregion
486
+ //#region src/supabaseEdgeFunctionDatabase.ts
487
+ const supabaseEdgeFunctionDatabase = (config, hooks) => {
488
+ return supabaseDatabase({
489
+ supabaseUrl: config.supabaseUrl,
490
+ supabaseAnonKey: config.supabaseServiceRoleKey
491
+ }, hooks);
492
+ };
493
+ //#endregion
494
+ //#region src/supabaseEdgeFunctionStorage.ts
495
+ const supabaseEdgeFunctionStorage = (config) => {
496
+ const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseServiceRoleKey);
497
+ return () => {
498
+ return {
499
+ name: "supabaseEdgeFunctionStorage",
500
+ supportedProtocol: "supabase-storage",
501
+ async upload() {
502
+ throw new Error("supabaseEdgeFunctionStorage does not support upload() in the edge runtime.");
503
+ },
504
+ async delete(storageUri) {
505
+ const storageUrl = new URL(storageUri);
506
+ if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
507
+ const bucketName = storageUrl.host;
508
+ const key = storageUrl.pathname.replace(/^\/+/, "");
509
+ if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
510
+ const { error } = await supabase.storage.from(bucketName).remove([key]);
511
+ if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
512
+ },
513
+ async getDownloadUrl(storageUri) {
514
+ const storageUrl = new URL(storageUri);
515
+ if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
516
+ const bucketName = storageUrl.host;
517
+ const key = storageUrl.pathname.replace(/^\/+/, "");
518
+ if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
519
+ const { data, error } = await supabase.storage.from(bucketName).createSignedUrl(key, config.signedUrlExpiresIn ?? 3600);
520
+ if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
521
+ if (!data?.signedUrl) throw new Error("Failed to generate download URL");
522
+ return { fileUrl: data.signedUrl };
523
+ }
524
+ };
525
+ };
526
+ };
527
+ //#endregion
528
+ Object.defineProperty(exports, "supabaseDatabase", {
529
+ enumerable: true,
530
+ get: function() {
531
+ return supabaseDatabase;
532
+ }
533
+ });
534
+ Object.defineProperty(exports, "supabaseEdgeFunctionDatabase", {
535
+ enumerable: true,
536
+ get: function() {
537
+ return supabaseEdgeFunctionDatabase;
538
+ }
539
+ });
540
+ Object.defineProperty(exports, "supabaseEdgeFunctionStorage", {
541
+ enumerable: true,
542
+ get: function() {
543
+ return supabaseEdgeFunctionStorage;
544
+ }
545
+ });