@hot-updater/supabase 1.2.0-rc.6 → 1.2.0-rc.60
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.d.cts +1 -1
- package/dist/edge.d.mts +1 -1
- package/dist/edge.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/init/index.cjs +57 -31
- package/dist/init/index.d.cts +2 -2
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +58 -32
- package/dist/{supabaseStorage-8VAuNYHy.mjs → supabaseStorage-BoMZ6ay3.mjs} +115 -2
- package/dist/{supabaseStorage-B131_auF.d.cts → supabaseStorage-C9W-69OP.d.cts} +5 -5
- package/dist/{supabaseStorage-B131_auF.d.mts → supabaseStorage-C9W-69OP.d.mts} +5 -5
- package/dist/{supabaseStorage-BV6GuUz_.cjs → supabaseStorage-CkMp_r4q.cjs} +115 -2
- package/package.json +9 -9
- package/supabase/migrations/0002_hot-updater_1.2.0.sql +30 -2
package/dist/edge.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_supabaseStorage = require("./supabaseStorage-
|
|
2
|
+
const require_supabaseStorage = require("./supabaseStorage-CkMp_r4q.cjs");
|
|
3
3
|
exports.supabaseDatabase = require_supabaseStorage.supabaseDatabase;
|
|
4
4
|
exports.supabaseStorage = require_supabaseStorage.supabaseStorage;
|
package/dist/edge.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-
|
|
1
|
+
import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.cjs";
|
|
2
2
|
export { type SupabaseDatabaseConfig, type SupabaseStorageConfig, supabaseDatabase, supabaseStorage };
|
package/dist/edge.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-
|
|
1
|
+
import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.mjs";
|
|
2
2
|
export { type SupabaseDatabaseConfig, type SupabaseStorageConfig, supabaseDatabase, supabaseStorage };
|
package/dist/edge.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as supabaseDatabase, t as supabaseStorage } from "./supabaseStorage-
|
|
1
|
+
import { n as supabaseDatabase, t as supabaseStorage } from "./supabaseStorage-BoMZ6ay3.mjs";
|
|
2
2
|
export { supabaseDatabase, supabaseStorage };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_supabaseStorage = require("./supabaseStorage-
|
|
2
|
+
const require_supabaseStorage = require("./supabaseStorage-CkMp_r4q.cjs");
|
|
3
3
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
4
4
|
//#region src/supabaseSchema.ts
|
|
5
5
|
/** Every table the apply RPC may name: models, index tables, settings, and the write guard. */
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-
|
|
1
|
+
import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.cjs";
|
|
2
2
|
import { ToolingDatabase } from "@hot-updater/plugin-core";
|
|
3
3
|
//#region src/supabaseMigration.d.ts
|
|
4
4
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-
|
|
1
|
+
import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.mjs";
|
|
2
2
|
import { ToolingDatabase } from "@hot-updater/plugin-core";
|
|
3
3
|
//#region src/supabaseMigration.d.ts
|
|
4
4
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as SUPABASE_TABLE_PREFIX, n as supabaseDatabase$1, r as SUPABASE_APPLY_FUNCTION, t as supabaseStorage } from "./supabaseStorage-
|
|
1
|
+
import { i as SUPABASE_TABLE_PREFIX, n as supabaseDatabase$1, r as SUPABASE_APPLY_FUNCTION, t as supabaseStorage } from "./supabaseStorage-BoMZ6ay3.mjs";
|
|
2
2
|
import { SETTINGS_TABLE, WRITE_GUARD_TABLE, coreSettings, coreTarget, createTableStatements, generateEngineSql, isMultiIndex } from "@hot-updater/plugin-core";
|
|
3
3
|
//#region src/supabaseSchema.ts
|
|
4
4
|
/** Every table the apply RPC may name: models, index tables, settings, and the write guard. */
|
package/dist/init/index.cjs
CHANGED
|
@@ -6421,14 +6421,15 @@ const supabaseDatabase = (config) => {
|
|
|
6421
6421
|
//#region iac/configTemplate.ts
|
|
6422
6422
|
/**
|
|
6423
6423
|
* The config init writes. With the `resources` init set up, it names them,
|
|
6424
|
-
* and reads the service role key with `
|
|
6424
|
+
* and reads the service role key with `secret()`, from the environment and
|
|
6425
6425
|
* `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
|
|
6426
|
-
* the agent scaffold writes it
|
|
6426
|
+
* the agent scaffold writes it before the agent creates the project, it
|
|
6427
|
+
* reads the URL and bucket from the environment, where the agent records
|
|
6428
|
+
* them, and the key with `secret()` alike.
|
|
6427
6429
|
*/
|
|
6428
6430
|
const getConfigScaffold = (build, resources) => {
|
|
6429
6431
|
const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
|
|
6430
|
-
const serviceRoleKey =
|
|
6431
|
-
(await deploySecrets()).HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY`;
|
|
6432
|
+
const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
|
|
6432
6433
|
const storageConfig = {
|
|
6433
6434
|
imports: [{
|
|
6434
6435
|
pkg: "@hot-updater/supabase",
|
|
@@ -6450,7 +6451,6 @@ const getConfigScaffold = (build, resources) => {
|
|
|
6450
6451
|
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6451
6452
|
})`
|
|
6452
6453
|
};
|
|
6453
|
-
const helperStatements = resources === void 0 ? [] : [(0, _hot_updater_cli_tools.secretEnvHelper)("deploySecrets", ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"])];
|
|
6454
6454
|
const builder = new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
6455
6455
|
imports: [{
|
|
6456
6456
|
pkg: "hot-updater/plugins",
|
|
@@ -6462,11 +6462,11 @@ const getConfigScaffold = (build, resources) => {
|
|
|
6462
6462
|
}],
|
|
6463
6463
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6464
6464
|
});
|
|
6465
|
-
|
|
6465
|
+
builder.addImport({
|
|
6466
6466
|
pkg: "hot-updater",
|
|
6467
|
-
named: ["
|
|
6468
|
-
})
|
|
6469
|
-
return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder
|
|
6467
|
+
named: ["secret"]
|
|
6468
|
+
});
|
|
6469
|
+
return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder);
|
|
6470
6470
|
};
|
|
6471
6471
|
//#endregion
|
|
6472
6472
|
//#region iac/init/index.ts
|
|
@@ -6605,6 +6605,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
|
|
|
6605
6605
|
};
|
|
6606
6606
|
};
|
|
6607
6607
|
//#endregion
|
|
6608
|
+
//#region iac/supabaseCliPackage.ts
|
|
6609
|
+
/**
|
|
6610
|
+
* The Supabase CLI init runs, as `npx -y <SUPABASE_CLI>`, so whichever CLI
|
|
6611
|
+
* the project installs or npx resolves can't change what its commands do.
|
|
6612
|
+
* Its commands use Supabase CLI 3's forms: `--remote` targets the linked
|
|
6613
|
+
* project or `--remote=<ref>` another one, and every hosted change passes
|
|
6614
|
+
* `--yes`, because CLI 3 fails one without a terminal unless it does. Move
|
|
6615
|
+
* to a new major only after checking each command against its release notes.
|
|
6616
|
+
*/
|
|
6617
|
+
const SUPABASE_CLI = "supabase@3.0.0";
|
|
6618
|
+
//#endregion
|
|
6608
6619
|
//#region iac/supabaseAuthentication.ts
|
|
6609
6620
|
const SUPABASE_AUTH_METHOD = {
|
|
6610
6621
|
accessToken: "access-token",
|
|
@@ -6625,7 +6636,7 @@ const openBrowser = async (url) => {
|
|
|
6625
6636
|
const hasValidSupabaseCliLogin = async () => {
|
|
6626
6637
|
return (await execa("npx", [
|
|
6627
6638
|
"-y",
|
|
6628
|
-
|
|
6639
|
+
SUPABASE_CLI,
|
|
6629
6640
|
"projects",
|
|
6630
6641
|
"list",
|
|
6631
6642
|
"--output",
|
|
@@ -6652,7 +6663,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
|
|
|
6652
6663
|
if (await hasValidSupabaseCliLogin()) return;
|
|
6653
6664
|
const loginProcess = execa("npx", [
|
|
6654
6665
|
"-y",
|
|
6655
|
-
|
|
6666
|
+
SUPABASE_CLI,
|
|
6656
6667
|
"login",
|
|
6657
6668
|
"--no-browser",
|
|
6658
6669
|
"--agent",
|
|
@@ -6724,7 +6735,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
|
|
|
6724
6735
|
};
|
|
6725
6736
|
const handleSupabaseDatabaseCommandError = (err, options) => {
|
|
6726
6737
|
if (err instanceof ExecaError) _hot_updater_cli_tools.p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
|
|
6727
|
-
else
|
|
6738
|
+
else _hot_updater_cli_tools.p.log.error(err instanceof Error ? err.message : String(err));
|
|
6728
6739
|
process.exit(1);
|
|
6729
6740
|
};
|
|
6730
6741
|
const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
@@ -6737,9 +6748,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
|
6737
6748
|
const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
|
|
6738
6749
|
await fs_promises.default.writeFile(path.default.join(workdir, "supabase", "config.toml"), (0, _hot_updater_cli_tools.transformTemplate)(SUPABASE_CONFIG_TEMPLATE, { projectId }));
|
|
6739
6750
|
await execa("npx", [
|
|
6740
|
-
"
|
|
6751
|
+
"-y",
|
|
6752
|
+
SUPABASE_CLI,
|
|
6741
6753
|
"link",
|
|
6742
|
-
"--project-ref",
|
|
6743
6754
|
projectId,
|
|
6744
6755
|
"--workdir",
|
|
6745
6756
|
workdir
|
|
@@ -6768,10 +6779,11 @@ const linkSupabase = async (workdir, options) => {
|
|
|
6768
6779
|
/** Pushes the workdir's migrations the linked project has not run, after its own history. */
|
|
6769
6780
|
const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
|
|
6770
6781
|
await execa("npx", [
|
|
6771
|
-
"
|
|
6782
|
+
"-y",
|
|
6783
|
+
SUPABASE_CLI,
|
|
6772
6784
|
"migration",
|
|
6773
6785
|
"fetch",
|
|
6774
|
-
"--
|
|
6786
|
+
"--remote",
|
|
6775
6787
|
"--yes",
|
|
6776
6788
|
"--workdir",
|
|
6777
6789
|
workdir
|
|
@@ -6783,10 +6795,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
|
|
|
6783
6795
|
throw error;
|
|
6784
6796
|
});
|
|
6785
6797
|
return execa("npx", [
|
|
6786
|
-
"
|
|
6798
|
+
"-y",
|
|
6799
|
+
SUPABASE_CLI,
|
|
6787
6800
|
"db",
|
|
6788
6801
|
"push",
|
|
6789
6802
|
"--include-all",
|
|
6803
|
+
"--remote",
|
|
6790
6804
|
"--yes",
|
|
6791
6805
|
"--workdir",
|
|
6792
6806
|
workdir
|
|
@@ -6949,7 +6963,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
|
6949
6963
|
const runSupabaseCli = async (args) => {
|
|
6950
6964
|
const result = await execa("npx", [
|
|
6951
6965
|
"-y",
|
|
6952
|
-
|
|
6966
|
+
SUPABASE_CLI,
|
|
6953
6967
|
...args
|
|
6954
6968
|
], { env: void 0 });
|
|
6955
6969
|
return JSON.parse(result.stdout);
|
|
@@ -6972,15 +6986,14 @@ const supabaseCliManagementApi = () => ({
|
|
|
6972
6986
|
listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
|
|
6973
6987
|
"functions",
|
|
6974
6988
|
"list",
|
|
6975
|
-
|
|
6976
|
-
projectId,
|
|
6989
|
+
`--remote=${projectId}`,
|
|
6977
6990
|
"--output",
|
|
6978
6991
|
"json"
|
|
6979
6992
|
])),
|
|
6980
6993
|
createProject: async ({ name, organizationSlug, region }) => {
|
|
6981
6994
|
await execa("npx", [
|
|
6982
6995
|
"-y",
|
|
6983
|
-
|
|
6996
|
+
SUPABASE_CLI,
|
|
6984
6997
|
"projects",
|
|
6985
6998
|
"create",
|
|
6986
6999
|
name,
|
|
@@ -6988,6 +7001,7 @@ const supabaseCliManagementApi = () => ({
|
|
|
6988
7001
|
organizationSlug,
|
|
6989
7002
|
"--region",
|
|
6990
7003
|
region,
|
|
7004
|
+
"--yes",
|
|
6991
7005
|
"--agent",
|
|
6992
7006
|
"no"
|
|
6993
7007
|
], { stdio: "inherit" });
|
|
@@ -7276,7 +7290,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7276
7290
|
try {
|
|
7277
7291
|
const listProjects = await execa("npx", [
|
|
7278
7292
|
"-y",
|
|
7279
|
-
|
|
7293
|
+
SUPABASE_CLI,
|
|
7280
7294
|
"projects",
|
|
7281
7295
|
"list",
|
|
7282
7296
|
"--output",
|
|
@@ -7286,7 +7300,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7286
7300
|
} catch (err) {
|
|
7287
7301
|
spinner.stop();
|
|
7288
7302
|
const message = err instanceof Error ? err.message : String(err);
|
|
7289
|
-
|
|
7303
|
+
_hot_updater_cli_tools.p.log.error(`Failed to fetch Supabase projects: ${message}`);
|
|
7290
7304
|
process.exit(1);
|
|
7291
7305
|
}
|
|
7292
7306
|
spinner.stop();
|
|
@@ -7437,13 +7451,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
|
|
|
7437
7451
|
task: async () => {
|
|
7438
7452
|
try {
|
|
7439
7453
|
return (await execa("npx", [
|
|
7440
|
-
"
|
|
7454
|
+
"-y",
|
|
7455
|
+
SUPABASE_CLI,
|
|
7441
7456
|
"functions",
|
|
7442
7457
|
"deploy",
|
|
7443
7458
|
functionName,
|
|
7444
|
-
|
|
7445
|
-
projectId,
|
|
7459
|
+
`--remote=${projectId}`,
|
|
7446
7460
|
"--no-verify-jwt",
|
|
7461
|
+
"--yes",
|
|
7447
7462
|
"--workdir",
|
|
7448
7463
|
workdir
|
|
7449
7464
|
], {
|
|
@@ -7482,11 +7497,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
|
|
|
7482
7497
|
const getServiceRoleApiKey = async () => {
|
|
7483
7498
|
const keysProcess = await execa("npx", [
|
|
7484
7499
|
"-y",
|
|
7485
|
-
|
|
7500
|
+
SUPABASE_CLI,
|
|
7486
7501
|
"projects",
|
|
7487
7502
|
"api-keys",
|
|
7488
|
-
|
|
7489
|
-
project.id,
|
|
7503
|
+
`--remote=${project.id}`,
|
|
7490
7504
|
"--output",
|
|
7491
7505
|
"json"
|
|
7492
7506
|
], { env: getSupabaseCliEnv(accessToken) });
|
|
@@ -7693,6 +7707,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7693
7707
|
});
|
|
7694
7708
|
({clientPlugins} = managedServer);
|
|
7695
7709
|
try {
|
|
7710
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(managedServer);
|
|
7696
7711
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(managedServer, {
|
|
7697
7712
|
env: initInputEnv,
|
|
7698
7713
|
name: "Supabase init"
|
|
@@ -7702,6 +7717,18 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7702
7717
|
await database.dispose?.();
|
|
7703
7718
|
}
|
|
7704
7719
|
await deployEdgeFunction(accessToken, tmpDir, project.id, functionName);
|
|
7720
|
+
const backfillDatabase = supabaseDatabase({
|
|
7721
|
+
supabaseServiceRoleKey: projectAccess.serviceRoleApiKey,
|
|
7722
|
+
supabaseUrl: `https://${project.id}.supabase.co`
|
|
7723
|
+
});
|
|
7724
|
+
try {
|
|
7725
|
+
await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)((0, _hot_updater_cli_tools.assembleServer)({
|
|
7726
|
+
database: backfillDatabase,
|
|
7727
|
+
plugins: managedServer.plugins
|
|
7728
|
+
}));
|
|
7729
|
+
} finally {
|
|
7730
|
+
await backfillDatabase.dispose?.();
|
|
7731
|
+
}
|
|
7705
7732
|
} finally {
|
|
7706
7733
|
await removeTmpDir();
|
|
7707
7734
|
}
|
|
@@ -7719,8 +7746,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7719
7746
|
clientPlugins
|
|
7720
7747
|
});
|
|
7721
7748
|
reportSupabaseOriginCatalogReady();
|
|
7722
|
-
|
|
7723
|
-
_hot_updater_cli_tools.p.log.success("Done! 🎉");
|
|
7749
|
+
return { nextSteps: [(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
|
|
7724
7750
|
};
|
|
7725
7751
|
const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
|
|
7726
7752
|
//#endregion
|
package/dist/init/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunInitOptions } from "@hot-updater/cli-tools";
|
|
1
|
+
import { RunInitOptions, RunInitResult } from "@hot-updater/cli-tools";
|
|
2
2
|
//#region iac/supabaseApi.d.ts
|
|
3
3
|
type SupabaseInfrastructureState = "fresh" | "incompatible" | "v1";
|
|
4
4
|
interface SupabaseApi {
|
|
@@ -177,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
|
|
|
177
177
|
readonly serviceRoleApiKey: string;
|
|
178
178
|
}>;
|
|
179
179
|
declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
|
|
180
|
-
declare const runInit: (options: RunInitOptions) => Promise<
|
|
180
|
+
declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
|
|
181
181
|
//#endregion
|
|
182
182
|
export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
|
package/dist/init/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunInitOptions } from "@hot-updater/cli-tools";
|
|
1
|
+
import { RunInitOptions, RunInitResult } from "@hot-updater/cli-tools";
|
|
2
2
|
//#region iac/supabaseApi.d.ts
|
|
3
3
|
type SupabaseInfrastructureState = "fresh" | "incompatible" | "v1";
|
|
4
4
|
interface SupabaseApi {
|
|
@@ -177,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
|
|
|
177
177
|
readonly serviceRoleApiKey: string;
|
|
178
178
|
}>;
|
|
179
179
|
declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
|
|
180
|
-
declare const runInit: (options: RunInitOptions) => Promise<
|
|
180
|
+
declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
|
|
181
181
|
//#endregion
|
|
182
182
|
export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
|
package/dist/init/index.mjs
CHANGED
|
@@ -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, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitInputs, assertInitProviderInputs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, getHotUpdaterEnvValue, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, moduleSpecifiersOf, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, resolvePackageVersion,
|
|
4
|
+
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitInputs, assertInitProviderInputs, backfillInsightsReleaseRefs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, fillReleaseLabels, getHotUpdaterEnvValue, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, moduleSpecifiersOf, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, resolvePackageVersion, transformEnv, transformTemplate, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
5
5
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -6416,14 +6416,15 @@ const supabaseDatabase = (config) => {
|
|
|
6416
6416
|
//#region iac/configTemplate.ts
|
|
6417
6417
|
/**
|
|
6418
6418
|
* The config init writes. With the `resources` init set up, it names them,
|
|
6419
|
-
* and reads the service role key with `
|
|
6419
|
+
* and reads the service role key with `secret()`, from the environment and
|
|
6420
6420
|
* `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
|
|
6421
|
-
* the agent scaffold writes it
|
|
6421
|
+
* the agent scaffold writes it before the agent creates the project, it
|
|
6422
|
+
* reads the URL and bucket from the environment, where the agent records
|
|
6423
|
+
* them, and the key with `secret()` alike.
|
|
6422
6424
|
*/
|
|
6423
6425
|
const getConfigScaffold = (build, resources) => {
|
|
6424
6426
|
const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
|
|
6425
|
-
const serviceRoleKey =
|
|
6426
|
-
(await deploySecrets()).HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY`;
|
|
6427
|
+
const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
|
|
6427
6428
|
const storageConfig = {
|
|
6428
6429
|
imports: [{
|
|
6429
6430
|
pkg: "@hot-updater/supabase",
|
|
@@ -6445,7 +6446,6 @@ const getConfigScaffold = (build, resources) => {
|
|
|
6445
6446
|
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6446
6447
|
})`
|
|
6447
6448
|
};
|
|
6448
|
-
const helperStatements = resources === void 0 ? [] : [secretEnvHelper("deploySecrets", ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"])];
|
|
6449
6449
|
const builder = new ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
6450
6450
|
imports: [{
|
|
6451
6451
|
pkg: "hot-updater/plugins",
|
|
@@ -6457,11 +6457,11 @@ const getConfigScaffold = (build, resources) => {
|
|
|
6457
6457
|
}],
|
|
6458
6458
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6459
6459
|
});
|
|
6460
|
-
|
|
6460
|
+
builder.addImport({
|
|
6461
6461
|
pkg: "hot-updater",
|
|
6462
|
-
named: ["
|
|
6463
|
-
})
|
|
6464
|
-
return createHotUpdaterConfigScaffoldFromBuilder(builder
|
|
6462
|
+
named: ["secret"]
|
|
6463
|
+
});
|
|
6464
|
+
return createHotUpdaterConfigScaffoldFromBuilder(builder);
|
|
6465
6465
|
};
|
|
6466
6466
|
//#endregion
|
|
6467
6467
|
//#region iac/init/index.ts
|
|
@@ -6600,6 +6600,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
|
|
|
6600
6600
|
};
|
|
6601
6601
|
};
|
|
6602
6602
|
//#endregion
|
|
6603
|
+
//#region iac/supabaseCliPackage.ts
|
|
6604
|
+
/**
|
|
6605
|
+
* The Supabase CLI init runs, as `npx -y <SUPABASE_CLI>`, so whichever CLI
|
|
6606
|
+
* the project installs or npx resolves can't change what its commands do.
|
|
6607
|
+
* Its commands use Supabase CLI 3's forms: `--remote` targets the linked
|
|
6608
|
+
* project or `--remote=<ref>` another one, and every hosted change passes
|
|
6609
|
+
* `--yes`, because CLI 3 fails one without a terminal unless it does. Move
|
|
6610
|
+
* to a new major only after checking each command against its release notes.
|
|
6611
|
+
*/
|
|
6612
|
+
const SUPABASE_CLI = "supabase@3.0.0";
|
|
6613
|
+
//#endregion
|
|
6603
6614
|
//#region iac/supabaseAuthentication.ts
|
|
6604
6615
|
const SUPABASE_AUTH_METHOD = {
|
|
6605
6616
|
accessToken: "access-token",
|
|
@@ -6620,7 +6631,7 @@ const openBrowser = async (url) => {
|
|
|
6620
6631
|
const hasValidSupabaseCliLogin = async () => {
|
|
6621
6632
|
return (await execa("npx", [
|
|
6622
6633
|
"-y",
|
|
6623
|
-
|
|
6634
|
+
SUPABASE_CLI,
|
|
6624
6635
|
"projects",
|
|
6625
6636
|
"list",
|
|
6626
6637
|
"--output",
|
|
@@ -6647,7 +6658,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
|
|
|
6647
6658
|
if (await hasValidSupabaseCliLogin()) return;
|
|
6648
6659
|
const loginProcess = execa("npx", [
|
|
6649
6660
|
"-y",
|
|
6650
|
-
|
|
6661
|
+
SUPABASE_CLI,
|
|
6651
6662
|
"login",
|
|
6652
6663
|
"--no-browser",
|
|
6653
6664
|
"--agent",
|
|
@@ -6719,7 +6730,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
|
|
|
6719
6730
|
};
|
|
6720
6731
|
const handleSupabaseDatabaseCommandError = (err, options) => {
|
|
6721
6732
|
if (err instanceof ExecaError) p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
|
|
6722
|
-
else
|
|
6733
|
+
else p.log.error(err instanceof Error ? err.message : String(err));
|
|
6723
6734
|
process.exit(1);
|
|
6724
6735
|
};
|
|
6725
6736
|
const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
@@ -6732,9 +6743,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
|
6732
6743
|
const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
|
|
6733
6744
|
await fs.writeFile(path.join(workdir, "supabase", "config.toml"), transformTemplate(SUPABASE_CONFIG_TEMPLATE, { projectId }));
|
|
6734
6745
|
await execa("npx", [
|
|
6735
|
-
"
|
|
6746
|
+
"-y",
|
|
6747
|
+
SUPABASE_CLI,
|
|
6736
6748
|
"link",
|
|
6737
|
-
"--project-ref",
|
|
6738
6749
|
projectId,
|
|
6739
6750
|
"--workdir",
|
|
6740
6751
|
workdir
|
|
@@ -6763,10 +6774,11 @@ const linkSupabase = async (workdir, options) => {
|
|
|
6763
6774
|
/** Pushes the workdir's migrations the linked project has not run, after its own history. */
|
|
6764
6775
|
const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
|
|
6765
6776
|
await execa("npx", [
|
|
6766
|
-
"
|
|
6777
|
+
"-y",
|
|
6778
|
+
SUPABASE_CLI,
|
|
6767
6779
|
"migration",
|
|
6768
6780
|
"fetch",
|
|
6769
|
-
"--
|
|
6781
|
+
"--remote",
|
|
6770
6782
|
"--yes",
|
|
6771
6783
|
"--workdir",
|
|
6772
6784
|
workdir
|
|
@@ -6778,10 +6790,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
|
|
|
6778
6790
|
throw error;
|
|
6779
6791
|
});
|
|
6780
6792
|
return execa("npx", [
|
|
6781
|
-
"
|
|
6793
|
+
"-y",
|
|
6794
|
+
SUPABASE_CLI,
|
|
6782
6795
|
"db",
|
|
6783
6796
|
"push",
|
|
6784
6797
|
"--include-all",
|
|
6798
|
+
"--remote",
|
|
6785
6799
|
"--yes",
|
|
6786
6800
|
"--workdir",
|
|
6787
6801
|
workdir
|
|
@@ -6944,7 +6958,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
|
6944
6958
|
const runSupabaseCli = async (args) => {
|
|
6945
6959
|
const result = await execa("npx", [
|
|
6946
6960
|
"-y",
|
|
6947
|
-
|
|
6961
|
+
SUPABASE_CLI,
|
|
6948
6962
|
...args
|
|
6949
6963
|
], { env: void 0 });
|
|
6950
6964
|
return JSON.parse(result.stdout);
|
|
@@ -6967,15 +6981,14 @@ const supabaseCliManagementApi = () => ({
|
|
|
6967
6981
|
listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
|
|
6968
6982
|
"functions",
|
|
6969
6983
|
"list",
|
|
6970
|
-
|
|
6971
|
-
projectId,
|
|
6984
|
+
`--remote=${projectId}`,
|
|
6972
6985
|
"--output",
|
|
6973
6986
|
"json"
|
|
6974
6987
|
])),
|
|
6975
6988
|
createProject: async ({ name, organizationSlug, region }) => {
|
|
6976
6989
|
await execa("npx", [
|
|
6977
6990
|
"-y",
|
|
6978
|
-
|
|
6991
|
+
SUPABASE_CLI,
|
|
6979
6992
|
"projects",
|
|
6980
6993
|
"create",
|
|
6981
6994
|
name,
|
|
@@ -6983,6 +6996,7 @@ const supabaseCliManagementApi = () => ({
|
|
|
6983
6996
|
organizationSlug,
|
|
6984
6997
|
"--region",
|
|
6985
6998
|
region,
|
|
6999
|
+
"--yes",
|
|
6986
7000
|
"--agent",
|
|
6987
7001
|
"no"
|
|
6988
7002
|
], { stdio: "inherit" });
|
|
@@ -7271,7 +7285,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7271
7285
|
try {
|
|
7272
7286
|
const listProjects = await execa("npx", [
|
|
7273
7287
|
"-y",
|
|
7274
|
-
|
|
7288
|
+
SUPABASE_CLI,
|
|
7275
7289
|
"projects",
|
|
7276
7290
|
"list",
|
|
7277
7291
|
"--output",
|
|
@@ -7281,7 +7295,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7281
7295
|
} catch (err) {
|
|
7282
7296
|
spinner.stop();
|
|
7283
7297
|
const message = err instanceof Error ? err.message : String(err);
|
|
7284
|
-
|
|
7298
|
+
p.log.error(`Failed to fetch Supabase projects: ${message}`);
|
|
7285
7299
|
process.exit(1);
|
|
7286
7300
|
}
|
|
7287
7301
|
spinner.stop();
|
|
@@ -7432,13 +7446,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
|
|
|
7432
7446
|
task: async () => {
|
|
7433
7447
|
try {
|
|
7434
7448
|
return (await execa("npx", [
|
|
7435
|
-
"
|
|
7449
|
+
"-y",
|
|
7450
|
+
SUPABASE_CLI,
|
|
7436
7451
|
"functions",
|
|
7437
7452
|
"deploy",
|
|
7438
7453
|
functionName,
|
|
7439
|
-
|
|
7440
|
-
projectId,
|
|
7454
|
+
`--remote=${projectId}`,
|
|
7441
7455
|
"--no-verify-jwt",
|
|
7456
|
+
"--yes",
|
|
7442
7457
|
"--workdir",
|
|
7443
7458
|
workdir
|
|
7444
7459
|
], {
|
|
@@ -7477,11 +7492,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
|
|
|
7477
7492
|
const getServiceRoleApiKey = async () => {
|
|
7478
7493
|
const keysProcess = await execa("npx", [
|
|
7479
7494
|
"-y",
|
|
7480
|
-
|
|
7495
|
+
SUPABASE_CLI,
|
|
7481
7496
|
"projects",
|
|
7482
7497
|
"api-keys",
|
|
7483
|
-
|
|
7484
|
-
project.id,
|
|
7498
|
+
`--remote=${project.id}`,
|
|
7485
7499
|
"--output",
|
|
7486
7500
|
"json"
|
|
7487
7501
|
], { env: getSupabaseCliEnv(accessToken) });
|
|
@@ -7688,6 +7702,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7688
7702
|
});
|
|
7689
7703
|
({clientPlugins} = managedServer);
|
|
7690
7704
|
try {
|
|
7705
|
+
await fillReleaseLabels(managedServer);
|
|
7691
7706
|
credential = await provisionClientCredential(managedServer, {
|
|
7692
7707
|
env: initInputEnv,
|
|
7693
7708
|
name: "Supabase init"
|
|
@@ -7697,6 +7712,18 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7697
7712
|
await database.dispose?.();
|
|
7698
7713
|
}
|
|
7699
7714
|
await deployEdgeFunction(accessToken, tmpDir, project.id, functionName);
|
|
7715
|
+
const backfillDatabase = supabaseDatabase({
|
|
7716
|
+
supabaseServiceRoleKey: projectAccess.serviceRoleApiKey,
|
|
7717
|
+
supabaseUrl: `https://${project.id}.supabase.co`
|
|
7718
|
+
});
|
|
7719
|
+
try {
|
|
7720
|
+
await backfillInsightsReleaseRefs(assembleServer({
|
|
7721
|
+
database: backfillDatabase,
|
|
7722
|
+
plugins: managedServer.plugins
|
|
7723
|
+
}));
|
|
7724
|
+
} finally {
|
|
7725
|
+
await backfillDatabase.dispose?.();
|
|
7726
|
+
}
|
|
7700
7727
|
} finally {
|
|
7701
7728
|
await removeTmpDir();
|
|
7702
7729
|
}
|
|
@@ -7714,8 +7741,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
|
7714
7741
|
clientPlugins
|
|
7715
7742
|
});
|
|
7716
7743
|
reportSupabaseOriginCatalogReady();
|
|
7717
|
-
|
|
7718
|
-
p.log.success("Done! 🎉");
|
|
7744
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
|
|
7719
7745
|
};
|
|
7720
7746
|
const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
|
|
7721
7747
|
//#endregion
|
|
@@ -164,9 +164,43 @@ const isMissingObjectError = async (error) => {
|
|
|
164
164
|
const body = await response.json().catch(() => void 0);
|
|
165
165
|
return typeof body === "object" && body !== null && Reflect.get(body, "error") === "not_found";
|
|
166
166
|
};
|
|
167
|
+
/** The one-line description of a request Storage failed with `status`. */
|
|
168
|
+
const answeredHttp = (status) => `Supabase Storage answered HTTP ${status}`;
|
|
169
|
+
/**
|
|
170
|
+
* fetch for supabase-js, which reads the body of a failed request as JSON. A
|
|
171
|
+
* gateway in front of Storage answers some failures, such as a 502, with an
|
|
172
|
+
* HTML page, which would fail as a JSON parse error without its status. Such
|
|
173
|
+
* a response becomes a JSON error that names the status. A HEAD response
|
|
174
|
+
* has no body, and supabase-js reads it unparsed.
|
|
175
|
+
*/
|
|
176
|
+
const storageFetch = async (input, init) => {
|
|
177
|
+
const response = await fetch(input, init);
|
|
178
|
+
if (response.ok || init?.method === "HEAD") return response;
|
|
179
|
+
try {
|
|
180
|
+
JSON.parse(await response.clone().text());
|
|
181
|
+
return response;
|
|
182
|
+
} catch {
|
|
183
|
+
return Response.json({
|
|
184
|
+
statusCode: String(response.status),
|
|
185
|
+
error: response.statusText,
|
|
186
|
+
message: answeredHttp(response.status)
|
|
187
|
+
}, {
|
|
188
|
+
status: response.status,
|
|
189
|
+
statusText: response.statusText
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
167
193
|
/** A character Storage rejects in an object name, `?`, or `!`. */
|
|
168
194
|
const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
|
|
195
|
+
const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
|
|
169
196
|
const utf8 = new TextEncoder();
|
|
197
|
+
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
198
|
+
/** Objects Storage lists a page at a time. */
|
|
199
|
+
const LIST_PAGE_SIZE = 1e3;
|
|
200
|
+
/** Names Storage removes in one request. */
|
|
201
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
202
|
+
/** The object the Supabase dashboard keeps in a folder it creates. */
|
|
203
|
+
const EMPTY_FOLDER_PLACEHOLDER = ".emptyFolderPlaceholder";
|
|
170
204
|
/**
|
|
171
205
|
* The object name Storage keeps a key under. Storage accepts names of ASCII
|
|
172
206
|
* letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
|
|
@@ -177,13 +211,42 @@ const utf8 = new TextEncoder();
|
|
|
177
211
|
* Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
|
|
178
212
|
*/
|
|
179
213
|
const toObjectName = (key) => key.replace(ESCAPED_CHARACTER, (character) => Array.from(utf8.encode(character), (byte) => `!${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""));
|
|
214
|
+
/** The key `toObjectName` stored under `name`, or null for a name it never makes. */
|
|
215
|
+
const fromObjectName = (name) => {
|
|
216
|
+
const bytes = [];
|
|
217
|
+
const parts = [];
|
|
218
|
+
const flush = () => {
|
|
219
|
+
if (bytes.length === 0) return true;
|
|
220
|
+
try {
|
|
221
|
+
parts.push(utf8Decoder.decode(new Uint8Array(bytes)));
|
|
222
|
+
} catch {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
bytes.length = 0;
|
|
226
|
+
return true;
|
|
227
|
+
};
|
|
228
|
+
let index = 0;
|
|
229
|
+
for (const match of name.matchAll(ESCAPE_SEQUENCE)) {
|
|
230
|
+
if (match.index !== index) {
|
|
231
|
+
if (!flush()) return null;
|
|
232
|
+
parts.push(name.slice(index, match.index));
|
|
233
|
+
}
|
|
234
|
+
bytes.push(Number.parseInt(match[1], 16));
|
|
235
|
+
index = match.index + match[0].length;
|
|
236
|
+
}
|
|
237
|
+
if (!flush()) return null;
|
|
238
|
+
parts.push(name.slice(index));
|
|
239
|
+
const key = parts.join("");
|
|
240
|
+
return toObjectName(key) === name ? key : null;
|
|
241
|
+
};
|
|
180
242
|
const supabaseStorage = (config) => {
|
|
181
243
|
let client;
|
|
182
|
-
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => createClient(config.supabaseUrl, key), (error) => {
|
|
244
|
+
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => createClient(config.supabaseUrl, key, { global: { fetch: storageFetch } }), (error) => {
|
|
183
245
|
client = void 0;
|
|
184
246
|
throw error;
|
|
185
247
|
}))).storage.from(config.bucketName);
|
|
186
248
|
const getStorageKey = createStorageKeyBuilder(config.basePath);
|
|
249
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
187
250
|
const resolveSignedUrl = createSupabaseSignedUrlBatcher({
|
|
188
251
|
createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
|
|
189
252
|
expiresIn: config.signedUrlExpiresIn ?? 3600,
|
|
@@ -206,7 +269,12 @@ const supabaseStorage = (config) => {
|
|
|
206
269
|
duplex: "half",
|
|
207
270
|
...contentLength === void 0 ? {} : { headers: { "content-length": String(contentLength) } }
|
|
208
271
|
});
|
|
209
|
-
if (error)
|
|
272
|
+
if (error) {
|
|
273
|
+
const status = Reflect.get(error, "status");
|
|
274
|
+
if (typeof status !== "number") throw error;
|
|
275
|
+
const detail = error.message === answeredHttp(status) ? "" : `: ${error.message}`;
|
|
276
|
+
throw new Error(`${answeredHttp(status)} while uploading ${storageKey}${detail}`, { cause: error });
|
|
277
|
+
}
|
|
210
278
|
return { storageUri: createStorageUri({
|
|
211
279
|
protocol: "supabase-storage",
|
|
212
280
|
bucket: config.bucketName,
|
|
@@ -240,6 +308,51 @@ const supabaseStorage = (config) => {
|
|
|
240
308
|
const { error } = await (await bucket()).remove([toObjectName(key)]);
|
|
241
309
|
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
|
|
242
310
|
return { deleted: true };
|
|
311
|
+
},
|
|
312
|
+
async listObjects(prefix) {
|
|
313
|
+
const objects = [];
|
|
314
|
+
const folder = toObjectName(getStorageKey(prefix ?? ""));
|
|
315
|
+
let cursor;
|
|
316
|
+
do {
|
|
317
|
+
const { data, error } = await (await bucket()).listV2({
|
|
318
|
+
prefix: folder ? `${folder}/` : "",
|
|
319
|
+
limit: LIST_PAGE_SIZE,
|
|
320
|
+
...cursor === void 0 ? {} : { cursor }
|
|
321
|
+
});
|
|
322
|
+
if (error) throw new Error(`Failed to list storage objects: ${error.message}`);
|
|
323
|
+
for (const entry of data.objects) {
|
|
324
|
+
const name = entry.key ?? entry.name;
|
|
325
|
+
if (name.split("/").at(-1) === EMPTY_FOLDER_PLACEHOLDER) continue;
|
|
326
|
+
const key = fromObjectName(name);
|
|
327
|
+
if (key === null || !key.startsWith(basePrefix)) continue;
|
|
328
|
+
let storageUri;
|
|
329
|
+
try {
|
|
330
|
+
storageUri = createStorageUri({
|
|
331
|
+
protocol: "supabase-storage",
|
|
332
|
+
bucket: config.bucketName,
|
|
333
|
+
key
|
|
334
|
+
});
|
|
335
|
+
} catch {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const updatedAt = entry.updated_at ?? entry.created_at;
|
|
339
|
+
objects.push({
|
|
340
|
+
key: key.slice(basePrefix.length),
|
|
341
|
+
...updatedAt ? { lastModifiedAt: new Date(updatedAt) } : {},
|
|
342
|
+
size: Number(entry.metadata?.size ?? 0),
|
|
343
|
+
storageUri
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
cursor = data.hasNext ? data.nextCursor : void 0;
|
|
347
|
+
} while (cursor !== void 0);
|
|
348
|
+
return objects;
|
|
349
|
+
},
|
|
350
|
+
async deleteObjects(relativeKeys) {
|
|
351
|
+
const names = relativeKeys.map((key) => toObjectName(getStorageKey(key)));
|
|
352
|
+
for (let offset = 0; offset < names.length; offset += DELETE_BATCH_SIZE) {
|
|
353
|
+
const { error } = await (await bucket()).remove(names.slice(offset, offset + DELETE_BATCH_SIZE));
|
|
354
|
+
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage objects: ${error.message}`);
|
|
355
|
+
}
|
|
243
356
|
}
|
|
244
357
|
});
|
|
245
358
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EngineDatabase, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
1
|
+
import { EngineDatabase, Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
2
2
|
//#region src/supabaseConfig.d.ts
|
|
3
3
|
type SupabaseServiceRoleConfig = {
|
|
4
4
|
supabaseUrl: string;
|
|
5
5
|
/**
|
|
6
6
|
* The project's service role key, or a function that returns it, such as
|
|
7
|
-
*
|
|
8
|
-
* config loads without the key.
|
|
7
|
+
* `secret("<name>")` in `hot-updater.config.ts`: called on the first
|
|
8
|
+
* request, so a config loads without the key.
|
|
9
9
|
*/
|
|
10
|
-
supabaseServiceRoleKey:
|
|
10
|
+
supabaseServiceRoleKey: Lazy<string>;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/supabaseDatabase.d.ts
|
|
@@ -28,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
|
|
|
28
28
|
/** Signed download URL lifetime in seconds. @default 3600 */
|
|
29
29
|
signedUrlExpiresIn?: number;
|
|
30
30
|
};
|
|
31
|
-
declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
|
|
31
|
+
declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
|
|
32
32
|
//#endregion
|
|
33
33
|
export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EngineDatabase, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
1
|
+
import { EngineDatabase, Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
2
2
|
//#region src/supabaseConfig.d.ts
|
|
3
3
|
type SupabaseServiceRoleConfig = {
|
|
4
4
|
supabaseUrl: string;
|
|
5
5
|
/**
|
|
6
6
|
* The project's service role key, or a function that returns it, such as
|
|
7
|
-
*
|
|
8
|
-
* config loads without the key.
|
|
7
|
+
* `secret("<name>")` in `hot-updater.config.ts`: called on the first
|
|
8
|
+
* request, so a config loads without the key.
|
|
9
9
|
*/
|
|
10
|
-
supabaseServiceRoleKey:
|
|
10
|
+
supabaseServiceRoleKey: Lazy<string>;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/supabaseDatabase.d.ts
|
|
@@ -28,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
|
|
|
28
28
|
/** Signed download URL lifetime in seconds. @default 3600 */
|
|
29
29
|
signedUrlExpiresIn?: number;
|
|
30
30
|
};
|
|
31
|
-
declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
|
|
31
|
+
declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
|
|
32
32
|
//#endregion
|
|
33
33
|
export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
|
|
@@ -164,9 +164,43 @@ const isMissingObjectError = async (error) => {
|
|
|
164
164
|
const body = await response.json().catch(() => void 0);
|
|
165
165
|
return typeof body === "object" && body !== null && Reflect.get(body, "error") === "not_found";
|
|
166
166
|
};
|
|
167
|
+
/** The one-line description of a request Storage failed with `status`. */
|
|
168
|
+
const answeredHttp = (status) => `Supabase Storage answered HTTP ${status}`;
|
|
169
|
+
/**
|
|
170
|
+
* fetch for supabase-js, which reads the body of a failed request as JSON. A
|
|
171
|
+
* gateway in front of Storage answers some failures, such as a 502, with an
|
|
172
|
+
* HTML page, which would fail as a JSON parse error without its status. Such
|
|
173
|
+
* a response becomes a JSON error that names the status. A HEAD response
|
|
174
|
+
* has no body, and supabase-js reads it unparsed.
|
|
175
|
+
*/
|
|
176
|
+
const storageFetch = async (input, init) => {
|
|
177
|
+
const response = await fetch(input, init);
|
|
178
|
+
if (response.ok || init?.method === "HEAD") return response;
|
|
179
|
+
try {
|
|
180
|
+
JSON.parse(await response.clone().text());
|
|
181
|
+
return response;
|
|
182
|
+
} catch {
|
|
183
|
+
return Response.json({
|
|
184
|
+
statusCode: String(response.status),
|
|
185
|
+
error: response.statusText,
|
|
186
|
+
message: answeredHttp(response.status)
|
|
187
|
+
}, {
|
|
188
|
+
status: response.status,
|
|
189
|
+
statusText: response.statusText
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
167
193
|
/** A character Storage rejects in an object name, `?`, or `!`. */
|
|
168
194
|
const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
|
|
195
|
+
const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
|
|
169
196
|
const utf8 = new TextEncoder();
|
|
197
|
+
const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
198
|
+
/** Objects Storage lists a page at a time. */
|
|
199
|
+
const LIST_PAGE_SIZE = 1e3;
|
|
200
|
+
/** Names Storage removes in one request. */
|
|
201
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
202
|
+
/** The object the Supabase dashboard keeps in a folder it creates. */
|
|
203
|
+
const EMPTY_FOLDER_PLACEHOLDER = ".emptyFolderPlaceholder";
|
|
170
204
|
/**
|
|
171
205
|
* The object name Storage keeps a key under. Storage accepts names of ASCII
|
|
172
206
|
* letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
|
|
@@ -177,13 +211,42 @@ const utf8 = new TextEncoder();
|
|
|
177
211
|
* Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
|
|
178
212
|
*/
|
|
179
213
|
const toObjectName = (key) => key.replace(ESCAPED_CHARACTER, (character) => Array.from(utf8.encode(character), (byte) => `!${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""));
|
|
214
|
+
/** The key `toObjectName` stored under `name`, or null for a name it never makes. */
|
|
215
|
+
const fromObjectName = (name) => {
|
|
216
|
+
const bytes = [];
|
|
217
|
+
const parts = [];
|
|
218
|
+
const flush = () => {
|
|
219
|
+
if (bytes.length === 0) return true;
|
|
220
|
+
try {
|
|
221
|
+
parts.push(utf8Decoder.decode(new Uint8Array(bytes)));
|
|
222
|
+
} catch {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
bytes.length = 0;
|
|
226
|
+
return true;
|
|
227
|
+
};
|
|
228
|
+
let index = 0;
|
|
229
|
+
for (const match of name.matchAll(ESCAPE_SEQUENCE)) {
|
|
230
|
+
if (match.index !== index) {
|
|
231
|
+
if (!flush()) return null;
|
|
232
|
+
parts.push(name.slice(index, match.index));
|
|
233
|
+
}
|
|
234
|
+
bytes.push(Number.parseInt(match[1], 16));
|
|
235
|
+
index = match.index + match[0].length;
|
|
236
|
+
}
|
|
237
|
+
if (!flush()) return null;
|
|
238
|
+
parts.push(name.slice(index));
|
|
239
|
+
const key = parts.join("");
|
|
240
|
+
return toObjectName(key) === name ? key : null;
|
|
241
|
+
};
|
|
180
242
|
const supabaseStorage = (config) => {
|
|
181
243
|
let client;
|
|
182
|
-
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, key), (error) => {
|
|
244
|
+
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, key, { global: { fetch: storageFetch } }), (error) => {
|
|
183
245
|
client = void 0;
|
|
184
246
|
throw error;
|
|
185
247
|
}))).storage.from(config.bucketName);
|
|
186
248
|
const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
|
|
249
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
187
250
|
const resolveSignedUrl = createSupabaseSignedUrlBatcher({
|
|
188
251
|
createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
|
|
189
252
|
expiresIn: config.signedUrlExpiresIn ?? 3600,
|
|
@@ -206,7 +269,12 @@ const supabaseStorage = (config) => {
|
|
|
206
269
|
duplex: "half",
|
|
207
270
|
...contentLength === void 0 ? {} : { headers: { "content-length": String(contentLength) } }
|
|
208
271
|
});
|
|
209
|
-
if (error)
|
|
272
|
+
if (error) {
|
|
273
|
+
const status = Reflect.get(error, "status");
|
|
274
|
+
if (typeof status !== "number") throw error;
|
|
275
|
+
const detail = error.message === answeredHttp(status) ? "" : `: ${error.message}`;
|
|
276
|
+
throw new Error(`${answeredHttp(status)} while uploading ${storageKey}${detail}`, { cause: error });
|
|
277
|
+
}
|
|
210
278
|
return { storageUri: (0, _hot_updater_plugin_core.createStorageUri)({
|
|
211
279
|
protocol: "supabase-storage",
|
|
212
280
|
bucket: config.bucketName,
|
|
@@ -240,6 +308,51 @@ const supabaseStorage = (config) => {
|
|
|
240
308
|
const { error } = await (await bucket()).remove([toObjectName(key)]);
|
|
241
309
|
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
|
|
242
310
|
return { deleted: true };
|
|
311
|
+
},
|
|
312
|
+
async listObjects(prefix) {
|
|
313
|
+
const objects = [];
|
|
314
|
+
const folder = toObjectName(getStorageKey(prefix ?? ""));
|
|
315
|
+
let cursor;
|
|
316
|
+
do {
|
|
317
|
+
const { data, error } = await (await bucket()).listV2({
|
|
318
|
+
prefix: folder ? `${folder}/` : "",
|
|
319
|
+
limit: LIST_PAGE_SIZE,
|
|
320
|
+
...cursor === void 0 ? {} : { cursor }
|
|
321
|
+
});
|
|
322
|
+
if (error) throw new Error(`Failed to list storage objects: ${error.message}`);
|
|
323
|
+
for (const entry of data.objects) {
|
|
324
|
+
const name = entry.key ?? entry.name;
|
|
325
|
+
if (name.split("/").at(-1) === EMPTY_FOLDER_PLACEHOLDER) continue;
|
|
326
|
+
const key = fromObjectName(name);
|
|
327
|
+
if (key === null || !key.startsWith(basePrefix)) continue;
|
|
328
|
+
let storageUri;
|
|
329
|
+
try {
|
|
330
|
+
storageUri = (0, _hot_updater_plugin_core.createStorageUri)({
|
|
331
|
+
protocol: "supabase-storage",
|
|
332
|
+
bucket: config.bucketName,
|
|
333
|
+
key
|
|
334
|
+
});
|
|
335
|
+
} catch {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const updatedAt = entry.updated_at ?? entry.created_at;
|
|
339
|
+
objects.push({
|
|
340
|
+
key: key.slice(basePrefix.length),
|
|
341
|
+
...updatedAt ? { lastModifiedAt: new Date(updatedAt) } : {},
|
|
342
|
+
size: Number(entry.metadata?.size ?? 0),
|
|
343
|
+
storageUri
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
cursor = data.hasNext ? data.nextCursor : void 0;
|
|
347
|
+
} while (cursor !== void 0);
|
|
348
|
+
return objects;
|
|
349
|
+
},
|
|
350
|
+
async deleteObjects(relativeKeys) {
|
|
351
|
+
const names = relativeKeys.map((key) => toObjectName(getStorageKey(key)));
|
|
352
|
+
for (let offset = 0; offset < names.length; offset += DELETE_BATCH_SIZE) {
|
|
353
|
+
const { error } = await (await bucket()).remove(names.slice(offset, offset + DELETE_BATCH_SIZE));
|
|
354
|
+
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage objects: ${error.message}`);
|
|
355
|
+
}
|
|
243
356
|
}
|
|
244
357
|
});
|
|
245
358
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/supabase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.60",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@supabase/supabase-js": "2.76.1",
|
|
52
|
-
"hono": "4.
|
|
52
|
+
"hono": "4.13.21",
|
|
53
53
|
"uuidv7": "^1.0.2",
|
|
54
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
55
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
56
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
57
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
54
|
+
"@hot-updater/protocol": "1.2.0-rc.60",
|
|
55
|
+
"@hot-updater/plugin-core": "1.2.0-rc.60",
|
|
56
|
+
"@hot-updater/cli-tools": "1.2.0-rc.60",
|
|
57
|
+
"@hot-updater/server": "1.2.0-rc.60"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@electric-sql/pglite": "0.4.1",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"execa": "9.5.2",
|
|
65
65
|
"@types/node": "^20",
|
|
66
66
|
"mime": "^4.0.4",
|
|
67
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
68
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
69
|
-
"@hot-updater/postgres": "1.2.0-rc.
|
|
67
|
+
"@hot-updater/mock": "1.2.0-rc.60",
|
|
68
|
+
"@hot-updater/test-utils": "1.2.0-rc.60",
|
|
69
|
+
"@hot-updater/postgres": "1.2.0-rc.60"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsdown",
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
-- HotUpdater.schema
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ALTER TABLE "hot_updater_v1_releases" ADD COLUMN IF NOT EXISTS "label" bigint;
|
|
4
|
+
|
|
5
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_releases_byLabel" ON "hot_updater_v1_releases" ("channel_id", "platform", "label");
|
|
6
|
+
|
|
7
|
+
CREATE TABLE IF NOT EXISTS "hot_updater_v1_native_builds" ("id" varchar(36) COLLATE "C" NOT NULL, "scope_key" varchar(2048) COLLATE "C" NOT NULL, "platform" varchar(16) COLLATE "C" NOT NULL, "channel_id" varchar(1408) COLLATE "C" NOT NULL, "fingerprint_hash" varchar(255) COLLATE "C", "app_version" text COLLATE "C", "min_bundle_id" varchar(36) COLLATE "C" NOT NULL, "artifact_kind" varchar(16) COLLATE "C" NOT NULL, "artifact_storage_uri" text COLLATE "C" NOT NULL, "byte_size" bigint NOT NULL, "git_commit_hash" varchar(255) COLLATE "C", "created_at_ms" bigint NOT NULL, "build_key" varchar(69) COLLATE "C", "build_number" varchar(64) COLLATE "C", "submitted_to" varchar(16) COLLATE "C", "submitted_at_ms" bigint, "submitted_version" varchar(255) COLLATE "C", "is_store_build" boolean NOT NULL, "is_sandbox" boolean NOT NULL, "sandbox_url_scheme" varchar(255) COLLATE "C", "export_method" varchar(16) COLLATE "C", "native_app_version" text COLLATE "C", "store_build_scope_key" varchar(2048) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
4
8
|
|
|
5
9
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byScope" ON "hot_updater_v1_native_builds" ("scope_key", "id");
|
|
6
10
|
|
|
7
11
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byBuildKey" ON "hot_updater_v1_native_builds" ("scope_key", "build_key", "id");
|
|
8
12
|
|
|
13
|
+
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byScopeKind" ON "hot_updater_v1_native_builds" ("scope_key", "artifact_kind", "id");
|
|
14
|
+
|
|
15
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byStoreBuild" ON "hot_updater_v1_native_builds" ("store_build_scope_key");
|
|
16
|
+
|
|
9
17
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byChannel" ON "hot_updater_v1_native_builds" ("channel_id", "id");
|
|
10
18
|
|
|
11
19
|
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_min_bundle_id" ON "hot_updater_v1_native_builds" ("min_bundle_id");
|
|
12
20
|
|
|
21
|
+
CREATE TABLE IF NOT EXISTS "hot_updater_v1_ios_devices" ("id" varchar(36) COLLATE "C" NOT NULL, "udid" varchar(40) COLLATE "C" NOT NULL, "name" varchar(100) COLLATE "C" NOT NULL, "status" varchar(16) COLLATE "C" NOT NULL, "requested_by" varchar(320) COLLATE "C", "created_at_ms" bigint NOT NULL, "approved_by" varchar(320) COLLATE "C", "approved_at_ms" bigint, "registered_at_ms" bigint, "apple_issuer_id" varchar(64) COLLATE "C", "apple_error" varchar(512) COLLATE "C", "build_id" varchar(36) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
22
|
+
|
|
23
|
+
CREATE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_byStatus" ON "hot_updater_v1_ios_devices" ("status", "id");
|
|
24
|
+
|
|
25
|
+
CREATE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_byRegistration" ON "hot_updater_v1_ios_devices" ("registered_at_ms", "id");
|
|
26
|
+
|
|
27
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_udid" ON "hot_updater_v1_ios_devices" ("udid");
|
|
28
|
+
|
|
29
|
+
CREATE TABLE IF NOT EXISTS "hot_updater_v1_ios_device_account" ("id" varchar(16) COLLATE "C" NOT NULL, "apple_issuer_id" varchar(64) COLLATE "C" NOT NULL, "claimed_at_ms" bigint NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
30
|
+
|
|
31
|
+
CREATE TABLE IF NOT EXISTS "hot_updater_v1_label_sequences" ("id" varchar(1440) COLLATE "C" NOT NULL, "last_label" bigint NOT NULL, "is_filled" boolean NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
32
|
+
|
|
33
|
+
CREATE INDEX IF NOT EXISTS "hot_updater_v1_bundle_events__byBundle__key" ON "hot_updater_v1_bundle_events__byBundle" ("id");
|
|
34
|
+
|
|
13
35
|
ALTER TABLE "hot_updater_v1_native_builds" ENABLE ROW LEVEL SECURITY;
|
|
14
36
|
|
|
37
|
+
ALTER TABLE "hot_updater_v1_ios_devices" ENABLE ROW LEVEL SECURITY;
|
|
38
|
+
|
|
39
|
+
ALTER TABLE "hot_updater_v1_ios_device_account" ENABLE ROW LEVEL SECURITY;
|
|
40
|
+
|
|
41
|
+
ALTER TABLE "hot_updater_v1_label_sequences" ENABLE ROW LEVEL SECURITY;
|
|
42
|
+
|
|
15
43
|
CREATE OR REPLACE FUNCTION public.hot_updater_v1_apply(p_statements jsonb)
|
|
16
44
|
RETURNS jsonb
|
|
17
45
|
LANGUAGE plpgsql
|
|
@@ -31,7 +59,7 @@ BEGIN
|
|
|
31
59
|
FOR item IN SELECT value FROM jsonb_array_elements(p_statements) LOOP
|
|
32
60
|
statement := item->>'sql';
|
|
33
61
|
FOR target IN SELECT (regexp_matches(statement, '(?:FROM|INTO|UPDATE|JOIN) "([^"]+)"', 'g'))[1] LOOP
|
|
34
|
-
IF NOT target = ANY (ARRAY['hot_updater_v1_bundles', 'hot_updater_v1_bundle_patches', 'hot_updater_v1_releases', 'hot_updater_v1_release_catalogs', 'hot_updater_v1_channels', 'hot_updater_v1_bundle_totals', 'hot_updater_v1_native_builds', 'hot_updater_v1_bundle_events', 'hot_updater_v1_bundle_events__byBundle', 'hot_updater_v1_bundle_event_heads', 'hot_updater_v1_insights_overview', 'hot_updater_v1_insights_sketches', 'hot_updater_v1_insights_overview_daily', 'hot_updater_v1_insights_sketches_daily', 'hot_updater_v1_insights_overview_lifetime', 'hot_updater_v1_insights_sketches_lifetime', 'hot_updater_v1_insights_distribution', 'hot_updater_v1_insights_builtin_distribution', 'hot_updater_v1_insights_latest_by_bundle', 'hot_updater_v1_insights_outcomes', 'hot_updater_v1_insights_failures', 'hot_updater_v1_api_keys', 'hot_updater_v1_remote_config_active', 'hot_updater_v1_remote_config_versions', 'hot_updater_v1_private_hot_updater_settings', 'hot_updater_v1__hu_write']) THEN
|
|
62
|
+
IF NOT target = ANY (ARRAY['hot_updater_v1_bundles', 'hot_updater_v1_bundle_patches', 'hot_updater_v1_releases', 'hot_updater_v1_release_catalogs', 'hot_updater_v1_channels', 'hot_updater_v1_bundle_totals', 'hot_updater_v1_native_builds', 'hot_updater_v1_ios_devices', 'hot_updater_v1_ios_device_account', 'hot_updater_v1_label_sequences', 'hot_updater_v1_bundle_events', 'hot_updater_v1_bundle_events__byBundle', 'hot_updater_v1_bundle_event_heads', 'hot_updater_v1_insights_overview', 'hot_updater_v1_insights_sketches', 'hot_updater_v1_insights_overview_daily', 'hot_updater_v1_insights_sketches_daily', 'hot_updater_v1_insights_overview_lifetime', 'hot_updater_v1_insights_sketches_lifetime', 'hot_updater_v1_insights_distribution', 'hot_updater_v1_insights_builtin_distribution', 'hot_updater_v1_insights_latest_by_bundle', 'hot_updater_v1_insights_outcomes', 'hot_updater_v1_insights_failures', 'hot_updater_v1_api_keys', 'hot_updater_v1_remote_config_active', 'hot_updater_v1_remote_config_versions', 'hot_updater_v1_private_hot_updater_settings', 'hot_updater_v1__hu_write']) THEN
|
|
35
63
|
RAISE EXCEPTION 'hot_updater_v1_apply: % is not a Hot Updater table', target USING ERRCODE = '42501';
|
|
36
64
|
END IF;
|
|
37
65
|
END LOOP;
|