@hot-updater/server 0.31.4 → 0.33.0

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.
Files changed (45) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/_virtual/_rolldown/runtime.mjs +1 -1
  3. package/dist/db/createBundleDiff.cjs +19 -13
  4. package/dist/db/createBundleDiff.mjs +15 -9
  5. package/dist/db/index.cjs +7 -10
  6. package/dist/db/index.mjs +7 -10
  7. package/dist/db/pluginCore.cjs +136 -96
  8. package/dist/db/pluginCore.mjs +137 -97
  9. package/dist/db/requestBundleIdentityMap.cjs +29 -0
  10. package/dist/db/requestBundleIdentityMap.mjs +29 -0
  11. package/dist/db/schemaEnhancements.cjs +1 -1
  12. package/dist/db/types.d.cts +2 -1
  13. package/dist/db/types.d.mts +2 -1
  14. package/dist/db/updateArtifacts.cjs +6 -6
  15. package/dist/db/updateArtifacts.mjs +6 -6
  16. package/dist/handler.cjs +18 -8
  17. package/dist/handler.d.cts +9 -10
  18. package/dist/handler.d.mts +9 -10
  19. package/dist/handler.mjs +17 -7
  20. package/dist/index.d.cts +1 -1
  21. package/dist/index.d.mts +1 -1
  22. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.cts +1 -1
  23. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.mts +1 -1
  24. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.cts +1 -1
  25. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.mts +1 -1
  26. package/dist/packages/server/package.cjs +1 -1
  27. package/dist/packages/server/package.mjs +1 -1
  28. package/dist/runtime.cjs +10 -12
  29. package/dist/runtime.mjs +10 -12
  30. package/package.json +7 -7
  31. package/src/db/createBundleDiff.spec.ts +3 -0
  32. package/src/db/createBundleDiff.ts +27 -21
  33. package/src/db/index.spec.ts +36 -0
  34. package/src/db/index.ts +6 -10
  35. package/src/db/pluginCore.spec.ts +443 -0
  36. package/src/db/pluginCore.ts +63 -7
  37. package/src/db/requestBundleIdentityMap.spec.ts +56 -0
  38. package/src/db/requestBundleIdentityMap.ts +61 -0
  39. package/src/db/types.ts +2 -0
  40. package/src/db/updateArtifacts.ts +8 -19
  41. package/src/handler-standalone.integration.spec.ts +12 -0
  42. package/src/handler.spec.ts +117 -19
  43. package/src/handler.ts +47 -21
  44. package/src/runtime.spec.ts +46 -4
  45. package/src/runtime.ts +10 -12
@@ -5,7 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
8
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
9
  var __copyProps = (to, from, except, desc) => {
10
10
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
11
  key = keys[i];
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  //#region \0rolldown/runtime.js
3
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
3
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
4
4
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
5
  //#endregion
6
6
  export { __commonJSMin, __require };
@@ -1,12 +1,13 @@
1
1
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
2
3
  let node_crypto = require("node:crypto");
3
- node_crypto = require_runtime.__toESM(node_crypto, 1);
4
+ node_crypto = require_runtime.__toESM(node_crypto);
4
5
  let node_fs_promises = require("node:fs/promises");
5
- node_fs_promises = require_runtime.__toESM(node_fs_promises, 1);
6
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
6
7
  let node_os = require("node:os");
7
- node_os = require_runtime.__toESM(node_os, 1);
8
+ node_os = require_runtime.__toESM(node_os);
8
9
  let node_path = require("node:path");
9
- node_path = require_runtime.__toESM(node_path, 1);
10
+ node_path = require_runtime.__toESM(node_path);
10
11
  let node_util = require("node:util");
11
12
  let node_zlib = require("node:zlib");
12
13
  let _hot_updater_bsdiff = require("@hot-updater/bsdiff");
@@ -27,11 +28,6 @@ const isBundleManifest = (value) => {
27
28
  return typeof manifestAsset.fileHash === "string" && (manifestAsset.signature === void 0 || typeof manifestAsset.signature === "string");
28
29
  });
29
30
  };
30
- const createChildStorageUri = (baseStorageUri, relativePath) => {
31
- const baseUrl = new URL(baseStorageUri);
32
- baseUrl.pathname = `${baseUrl.pathname.replace(/\/+$/, "")}/${relativePath.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/")}`;
33
- return baseUrl.toString();
34
- };
35
31
  const getRelativeStorageDir = (relativePath) => {
36
32
  const normalized = relativePath.replace(/\\/g, "/");
37
33
  const dirname = node_path.default.posix.dirname(normalized);
@@ -76,18 +72,28 @@ function resolveHbcAssetPath(manifest) {
76
72
  if (candidates.length > 1) throw new Error(`Expected exactly one Hermes bundle asset in manifest, found ${candidates.length}: ${candidates.join(", ")}`);
77
73
  return candidates[0];
78
74
  }
79
- async function fetchAssetBytes(bundle, assetPath, storagePlugin) {
75
+ async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
80
76
  const assetBaseStorageUri = (0, _hot_updater_core.getAssetBaseStorageUri)(bundle);
81
77
  if (!assetBaseStorageUri) throw new Error(`Bundle ${bundle.id} does not have asset storage metadata`);
78
+ const asset = manifest.assets[assetPath];
79
+ if (!asset) throw new Error(`Asset ${assetPath} is missing from manifest`);
82
80
  if (BR_COMPRESSED_ASSET_PATH_RE.test(assetPath)) {
83
- const compressedAssetStorageUri = createChildStorageUri(assetBaseStorageUri, `${assetPath}.br`);
81
+ const compressedAssetStorageUri = (0, _hot_updater_plugin_core.resolveManifestAssetStorageUri)({
82
+ assetBaseStorageUri,
83
+ assetPath: `${assetPath}.br`,
84
+ fileHash: asset.fileHash
85
+ });
84
86
  let compressedBytes = null;
85
87
  try {
86
88
  compressedBytes = await downloadStorageBytes(compressedAssetStorageUri, storagePlugin);
87
89
  } catch {}
88
90
  if (compressedBytes) return new Uint8Array(await decompressBrotli(compressedBytes));
89
91
  }
90
- return downloadStorageBytes(createChildStorageUri(assetBaseStorageUri, assetPath), storagePlugin);
92
+ return downloadStorageBytes((0, _hot_updater_plugin_core.resolveManifestAssetStorageUri)({
93
+ assetBaseStorageUri,
94
+ assetPath,
95
+ fileHash: asset.fileHash
96
+ }), storagePlugin);
91
97
  }
92
98
  async function getFileHash(filePath) {
93
99
  const file = await node_fs_promises.default.readFile(filePath);
@@ -117,7 +123,7 @@ async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {})
117
123
  const targetAssetHash = targetManifest.assets[targetAssetPath]?.fileHash;
118
124
  if (!baseAssetHash || !targetAssetHash) throw new Error("Hermes asset hash is missing from manifest");
119
125
  if (baseAssetHash === targetAssetHash) throw new Error("Hermes bundle is unchanged; no diff patch is required");
120
- const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, deps.storagePlugin)]);
126
+ const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, baseManifest, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, targetManifest, deps.storagePlugin)]);
121
127
  const patchBytes = await (0, _hot_updater_bsdiff.hdiff)(baseBytes, targetBytes);
122
128
  const workDir = await node_fs_promises.default.mkdtemp(node_path.default.join(node_os.default.tmpdir(), "hot-updater-console-bsdiff-"));
123
129
  const patchFilename = `${node_path.default.posix.basename(targetAssetPath)}.bsdiff`;
@@ -1,3 +1,4 @@
1
+ import { resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
1
2
  import crypto, { randomUUID } from "node:crypto";
2
3
  import fs from "node:fs/promises";
3
4
  import os from "node:os";
@@ -22,11 +23,6 @@ const isBundleManifest = (value) => {
22
23
  return typeof manifestAsset.fileHash === "string" && (manifestAsset.signature === void 0 || typeof manifestAsset.signature === "string");
23
24
  });
24
25
  };
25
- const createChildStorageUri = (baseStorageUri, relativePath) => {
26
- const baseUrl = new URL(baseStorageUri);
27
- baseUrl.pathname = `${baseUrl.pathname.replace(/\/+$/, "")}/${relativePath.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/")}`;
28
- return baseUrl.toString();
29
- };
30
26
  const getRelativeStorageDir = (relativePath) => {
31
27
  const normalized = relativePath.replace(/\\/g, "/");
32
28
  const dirname = path.posix.dirname(normalized);
@@ -71,18 +67,28 @@ function resolveHbcAssetPath(manifest) {
71
67
  if (candidates.length > 1) throw new Error(`Expected exactly one Hermes bundle asset in manifest, found ${candidates.length}: ${candidates.join(", ")}`);
72
68
  return candidates[0];
73
69
  }
74
- async function fetchAssetBytes(bundle, assetPath, storagePlugin) {
70
+ async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
75
71
  const assetBaseStorageUri = getAssetBaseStorageUri(bundle);
76
72
  if (!assetBaseStorageUri) throw new Error(`Bundle ${bundle.id} does not have asset storage metadata`);
73
+ const asset = manifest.assets[assetPath];
74
+ if (!asset) throw new Error(`Asset ${assetPath} is missing from manifest`);
77
75
  if (BR_COMPRESSED_ASSET_PATH_RE.test(assetPath)) {
78
- const compressedAssetStorageUri = createChildStorageUri(assetBaseStorageUri, `${assetPath}.br`);
76
+ const compressedAssetStorageUri = resolveManifestAssetStorageUri({
77
+ assetBaseStorageUri,
78
+ assetPath: `${assetPath}.br`,
79
+ fileHash: asset.fileHash
80
+ });
79
81
  let compressedBytes = null;
80
82
  try {
81
83
  compressedBytes = await downloadStorageBytes(compressedAssetStorageUri, storagePlugin);
82
84
  } catch {}
83
85
  if (compressedBytes) return new Uint8Array(await decompressBrotli(compressedBytes));
84
86
  }
85
- return downloadStorageBytes(createChildStorageUri(assetBaseStorageUri, assetPath), storagePlugin);
87
+ return downloadStorageBytes(resolveManifestAssetStorageUri({
88
+ assetBaseStorageUri,
89
+ assetPath,
90
+ fileHash: asset.fileHash
91
+ }), storagePlugin);
86
92
  }
87
93
  async function getFileHash(filePath) {
88
94
  const file = await fs.readFile(filePath);
@@ -112,7 +118,7 @@ async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {})
112
118
  const targetAssetHash = targetManifest.assets[targetAssetPath]?.fileHash;
113
119
  if (!baseAssetHash || !targetAssetHash) throw new Error("Hermes asset hash is missing from manifest");
114
120
  if (baseAssetHash === targetAssetHash) throw new Error("Hermes bundle is unchanged; no diff patch is required");
115
- const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, deps.storagePlugin)]);
121
+ const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, baseManifest, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, targetManifest, deps.storagePlugin)]);
116
122
  const patchBytes = await hdiff(baseBytes, targetBytes);
117
123
  const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "hot-updater-console-bsdiff-"));
118
124
  const patchFilename = `${path.posix.basename(targetAssetPath)}.bsdiff`;
package/dist/db/index.cjs CHANGED
@@ -29,20 +29,17 @@ function createHotUpdater(options) {
29
29
  resolveFileUrl
30
30
  });
31
31
  const api = {
32
- ...core.api,
32
+ basePath,
33
+ adapterName: core.adapterName,
34
+ createMigrator: core.createMigrator,
35
+ generateSchema: core.generateSchema,
33
36
  handler: require_handler.createHandler(core.api, {
34
37
  basePath,
35
38
  routes: options.routes
36
- }),
37
- adapterName: core.adapterName,
38
- createMigrator: core.createMigrator,
39
- generateSchema: core.generateSchema
40
- };
41
- return {
42
- ...api,
43
- basePath,
44
- handler: api.handler
39
+ })
45
40
  };
41
+ Object.defineProperties(api, Object.getOwnPropertyDescriptors(core.api));
42
+ return api;
46
43
  }
47
44
  //#endregion
48
45
  exports.createHotUpdater = createHotUpdater;
package/dist/db/index.mjs CHANGED
@@ -28,20 +28,17 @@ function createHotUpdater(options) {
28
28
  resolveFileUrl
29
29
  });
30
30
  const api = {
31
- ...core.api,
31
+ basePath,
32
+ adapterName: core.adapterName,
33
+ createMigrator: core.createMigrator,
34
+ generateSchema: core.generateSchema,
32
35
  handler: createHandler(core.api, {
33
36
  basePath,
34
37
  routes: options.routes
35
- }),
36
- adapterName: core.adapterName,
37
- createMigrator: core.createMigrator,
38
- generateSchema: core.generateSchema
39
- };
40
- return {
41
- ...api,
42
- basePath,
43
- handler: api.handler
38
+ })
44
39
  };
40
+ Object.defineProperties(api, Object.getOwnPropertyDescriptors(core.api));
41
+ return api;
45
42
  }
46
43
  //#endregion
47
44
  export { createHotUpdater };
@@ -1,6 +1,7 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
2
  const require_schemaEnhancements = require("./schemaEnhancements.cjs");
3
3
  const require_updateArtifacts = require("./updateArtifacts.cjs");
4
+ const require_requestBundleIdentityMap = require("./requestBundleIdentityMap.cjs");
4
5
  let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
5
6
  let _hot_updater_core = require("@hot-updater/core");
6
7
  //#region src/db/pluginCore.ts
@@ -111,109 +112,148 @@ function createPluginDatabaseCore(getPlugin, resolveFileUrl, options) {
111
112
  enabled: true,
112
113
  id: { gte: minBundleId }
113
114
  });
114
- return {
115
- api: {
116
- async getBundleById(id, context) {
117
- return getPlugin().getBundleById(id, context);
118
- },
119
- async getUpdateInfo(args, context) {
120
- const directGetUpdateInfo = getPlugin().getUpdateInfo;
121
- if (directGetUpdateInfo) return context === void 0 ? await directGetUpdateInfo(args) : await directGetUpdateInfo(args, context);
122
- const channel = args.channel ?? "production";
123
- const minBundleId = args.minBundleId ?? _hot_updater_core.NIL_UUID;
124
- const baseWhere = getBaseWhere({
125
- platform: args.platform,
126
- channel,
127
- minBundleId
128
- });
129
- if (args._updateStrategy === "fingerprint") return findUpdateInfoByScanning({
130
- args,
131
- queryWhere: {
132
- ...baseWhere,
133
- fingerprintHash: args.fingerprintHash
134
- },
135
- context,
136
- isCandidate: (bundle) => {
137
- return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && bundle.fingerprintHash === args.fingerprintHash;
138
- }
139
- });
140
- return findUpdateInfoByScanning({
141
- args,
142
- queryWhere: { ...baseWhere },
143
- context,
144
- isCandidate: (bundle) => {
145
- return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && !!bundle.targetAppVersion && (0, _hot_updater_plugin_core.semverSatisfies)(bundle.targetAppVersion, args.appVersion);
146
- }
147
- });
148
- },
149
- async getAppUpdateInfo(args, context) {
150
- const info = await this.getUpdateInfo(args, context);
151
- if (!info) return null;
152
- const { storageUri, ...rest } = info;
153
- const readStorageText = options?.readStorageText;
154
- if (info.id === _hot_updater_core.NIL_UUID || !readStorageText) {
155
- const fileUrl = await resolveFileUrl(storageUri ?? null, context);
156
- return {
157
- ...rest,
158
- fileUrl
159
- };
115
+ const api = {
116
+ async getBundleById(id, context) {
117
+ return getPlugin().getBundleById(id, context);
118
+ },
119
+ async getUpdateInfo(args, context) {
120
+ const directGetUpdateInfo = getPlugin().getUpdateInfo;
121
+ if (directGetUpdateInfo) return context === void 0 ? await directGetUpdateInfo(args) : await directGetUpdateInfo(args, context);
122
+ const channel = args.channel ?? "production";
123
+ const minBundleId = args.minBundleId ?? _hot_updater_core.NIL_UUID;
124
+ const baseWhere = getBaseWhere({
125
+ platform: args.platform,
126
+ channel,
127
+ minBundleId
128
+ });
129
+ if (args._updateStrategy === "fingerprint") return findUpdateInfoByScanning({
130
+ args,
131
+ queryWhere: {
132
+ ...baseWhere,
133
+ fingerprintHash: args.fingerprintHash
134
+ },
135
+ context,
136
+ isCandidate: (bundle) => {
137
+ return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && bundle.fingerprintHash === args.fingerprintHash;
138
+ }
139
+ });
140
+ return findUpdateInfoByScanning({
141
+ args,
142
+ queryWhere: { ...baseWhere },
143
+ context,
144
+ isCandidate: (bundle) => {
145
+ return bundle.enabled && bundle.platform === args.platform && bundle.channel === channel && bundle.id.localeCompare(minBundleId) >= 0 && !!bundle.targetAppVersion && (0, _hot_updater_plugin_core.semverSatisfies)(bundle.targetAppVersion, args.appVersion);
160
146
  }
161
- const [fileUrl, targetBundle, currentBundle] = await Promise.all([
162
- resolveFileUrl(storageUri ?? null, context),
163
- getPlugin().getBundleById(info.id, context),
164
- args.bundleId !== _hot_updater_core.NIL_UUID ? getPlugin().getBundleById(args.bundleId, context) : null
165
- ]);
166
- const baseResponse = {
147
+ });
148
+ },
149
+ async getAppUpdateInfo(args, context) {
150
+ const info = await this.getUpdateInfo(args, context);
151
+ if (!info) return null;
152
+ const { storageUri, ...rest } = info;
153
+ const readStorageText = options?.readStorageText;
154
+ if (info.id === _hot_updater_core.NIL_UUID || !readStorageText) {
155
+ const fileUrl = await resolveFileUrl(storageUri ?? null, context);
156
+ return {
167
157
  ...rest,
168
158
  fileUrl
169
159
  };
170
- const manifestArtifacts = await require_updateArtifacts.resolveManifestArtifacts({
171
- currentBundle,
172
- resolveFileUrl,
173
- readStorageText,
174
- targetBundle,
175
- context
176
- });
177
- if (!manifestArtifacts) return baseResponse;
178
- return {
179
- ...baseResponse,
180
- ...manifestArtifacts
181
- };
182
- },
183
- async getChannels(context) {
184
- return getPlugin().getChannels(context);
185
- },
186
- async getBundles(options, context) {
187
- return getPlugin().getBundles(options, context);
188
- },
189
- async insertBundle(bundle, context) {
190
- require_schemaEnhancements.assertBundlePersistenceConstraints(bundle);
191
- await runWithMutationPlugin(async (plugin) => {
192
- await plugin.appendBundle(bundle, context);
193
- await plugin.commitBundle(context);
194
- });
195
- },
196
- async updateBundleById(bundleId, newBundle, context) {
197
- await runWithMutationPlugin(async (plugin) => {
198
- const current = await plugin.getBundleById(bundleId, context);
199
- if (!current) throw new Error("targetBundleId not found");
200
- require_schemaEnhancements.assertBundlePersistenceConstraints({
201
- ...current,
202
- ...newBundle
203
- });
204
- await plugin.updateBundle(bundleId, newBundle, context);
205
- await plugin.commitBundle(context);
160
+ }
161
+ const requestBundleSeeds = (0, _hot_updater_plugin_core.getRequestUpdateBundleSeeds)(context);
162
+ const requestBundles = require_requestBundleIdentityMap.createRequestBundleIdentityMap({
163
+ context,
164
+ loadBundleById: (bundleId, requestContext) => getPlugin().getBundleById(bundleId, requestContext),
165
+ seeds: requestBundleSeeds
166
+ });
167
+ const getCurrentBundle = () => {
168
+ if (args.bundleId === _hot_updater_core.NIL_UUID) return null;
169
+ const seededCurrentBundle = requestBundles.peek(args.bundleId);
170
+ if (seededCurrentBundle || requestBundleSeeds.length > 0) return seededCurrentBundle;
171
+ return requestBundles.get(args.bundleId);
172
+ };
173
+ const [fileUrl, targetBundle, currentBundle] = await Promise.all([
174
+ resolveFileUrl(storageUri ?? null, context),
175
+ requestBundles.get(info.id),
176
+ getCurrentBundle()
177
+ ]);
178
+ const baseResponse = {
179
+ ...rest,
180
+ fileUrl
181
+ };
182
+ const manifestArtifacts = await require_updateArtifacts.resolveManifestArtifacts({
183
+ currentBundle,
184
+ resolveFileUrl,
185
+ readStorageText,
186
+ targetBundle,
187
+ context
188
+ });
189
+ if (!manifestArtifacts) return baseResponse;
190
+ return {
191
+ ...baseResponse,
192
+ ...manifestArtifacts
193
+ };
194
+ },
195
+ async getChannels(context) {
196
+ return getPlugin().getChannels(context);
197
+ },
198
+ async getBundles(options, context) {
199
+ return getPlugin().getBundles(options, context);
200
+ },
201
+ async insertBundle(bundle, context) {
202
+ require_schemaEnhancements.assertBundlePersistenceConstraints(bundle);
203
+ await runWithMutationPlugin(async (plugin) => {
204
+ await plugin.appendBundle(bundle, context);
205
+ await plugin.commitBundle(context);
206
+ });
207
+ },
208
+ async updateBundleById(bundleId, newBundle, context) {
209
+ await runWithMutationPlugin(async (plugin) => {
210
+ const current = await plugin.getBundleById(bundleId, context);
211
+ if (!current) throw new Error("targetBundleId not found");
212
+ require_schemaEnhancements.assertBundlePersistenceConstraints({
213
+ ...current,
214
+ ...newBundle
206
215
  });
207
- },
208
- async deleteBundleById(bundleId, context) {
209
- await runWithMutationPlugin(async (plugin) => {
210
- const bundle = await plugin.getBundleById(bundleId, context);
211
- if (!bundle) return;
212
- await plugin.deleteBundle(bundle, context);
213
- await plugin.commitBundle(context);
216
+ await plugin.updateBundle(bundleId, newBundle, context);
217
+ await plugin.commitBundle(context);
218
+ });
219
+ },
220
+ async deleteBundleById(bundleId, context) {
221
+ await runWithMutationPlugin(async (plugin) => {
222
+ const bundle = await plugin.getBundleById(bundleId, context);
223
+ if (!bundle) return;
224
+ await plugin.deleteBundle(bundle, context);
225
+ await plugin.commitBundle(context);
226
+ });
227
+ }
228
+ };
229
+ Object.defineProperty(api, "diagnostics", {
230
+ configurable: true,
231
+ enumerable: true,
232
+ get() {
233
+ const diagnostics = getPlugin().diagnostics;
234
+ if (!diagnostics) {
235
+ Object.defineProperty(this, "diagnostics", {
236
+ configurable: true,
237
+ enumerable: true,
238
+ value: void 0
214
239
  });
240
+ return;
215
241
  }
216
- },
242
+ const wrappedDiagnostics = {};
243
+ if (diagnostics.bundleIndex) wrappedDiagnostics.bundleIndex = {
244
+ check: (context) => getPlugin().diagnostics.bundleIndex.check(context),
245
+ ...diagnostics.bundleIndex.repair ? { repair: (context) => getPlugin().diagnostics.bundleIndex.repair(context) } : {}
246
+ };
247
+ Object.defineProperty(this, "diagnostics", {
248
+ configurable: true,
249
+ enumerable: true,
250
+ value: wrappedDiagnostics
251
+ });
252
+ return wrappedDiagnostics;
253
+ }
254
+ });
255
+ return {
256
+ api,
217
257
  adapterName: getPlugin().name,
218
258
  createMigrator: () => {
219
259
  throw new Error("createMigrator is only available for Kysely/Prisma/Drizzle database adapters.");