@hot-updater/plugin-core 1.0.0-rc.1 → 1.0.0-rc.2

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 (134) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/assetStorageLayout.cjs +4 -2
  3. package/dist/assetStorageLayout.d.cts +5 -24
  4. package/dist/assetStorageLayout.d.mts +5 -24
  5. package/dist/assetStorageLayout.mjs +4 -2
  6. package/dist/calculatePagination.d.cts +0 -1
  7. package/dist/calculatePagination.d.mts +0 -1
  8. package/dist/compressionFormat.cjs +12 -5
  9. package/dist/compressionFormat.d.cts +1 -1
  10. package/dist/compressionFormat.d.mts +1 -1
  11. package/dist/compressionFormat.mjs +11 -4
  12. package/dist/contentAddressedAssets.d.cts +1 -4
  13. package/dist/contentAddressedAssets.d.mts +1 -4
  14. package/dist/createDatabasePlugin.cjs +161 -40
  15. package/dist/createDatabasePlugin.d.cts +3 -1
  16. package/dist/createDatabasePlugin.d.mts +3 -1
  17. package/dist/createDatabasePlugin.mjs +161 -41
  18. package/dist/createStoragePlugin.d.cts +0 -1
  19. package/dist/createStoragePlugin.d.mts +0 -1
  20. package/dist/databaseClient.cjs +6 -1
  21. package/dist/databaseClient.d.cts +1 -2
  22. package/dist/databaseClient.d.mts +1 -2
  23. package/dist/databaseClient.mjs +6 -2
  24. package/dist/databaseClientReads.cjs +3 -1
  25. package/dist/databaseClientReads.mjs +3 -2
  26. package/dist/databaseClientUpdates.cjs +2 -1
  27. package/dist/databaseClientUpdates.d.cts +1 -1
  28. package/dist/databaseClientUpdates.d.mts +1 -1
  29. package/dist/databaseClientUpdates.mjs +2 -0
  30. package/dist/databaseJsonValue.cjs +2 -0
  31. package/dist/databaseJsonValue.d.cts +1 -0
  32. package/dist/databaseJsonValue.d.mts +1 -0
  33. package/dist/databaseJsonValue.mjs +1 -1
  34. package/dist/databaseMetadata.cjs +0 -1
  35. package/dist/databasePluginCrud.cjs +3 -1
  36. package/dist/databasePluginCrud.d.cts +4 -1
  37. package/dist/databasePluginCrud.d.mts +4 -1
  38. package/dist/databasePluginCrud.mjs +4 -3
  39. package/dist/databasePluginCrudValidation.d.cts +6 -1
  40. package/dist/databasePluginCrudValidation.d.mts +6 -1
  41. package/dist/databasePluginCrudValidationErrors.cjs +1 -0
  42. package/dist/databasePluginCrudValidationErrors.mjs +1 -0
  43. package/dist/databasePluginCrudValidationFields.cjs +43 -13
  44. package/dist/databasePluginCrudValidationFields.d.cts +1 -1
  45. package/dist/databasePluginCrudValidationFields.d.mts +1 -1
  46. package/dist/databasePluginCrudValidationFields.mjs +41 -13
  47. package/dist/databasePluginCrudValidationMutations.cjs +20 -1
  48. package/dist/databasePluginCrudValidationMutations.d.cts +1 -1
  49. package/dist/databasePluginCrudValidationMutations.d.mts +1 -1
  50. package/dist/databasePluginCrudValidationMutations.mjs +20 -2
  51. package/dist/databasePluginCrudValidationQueries.d.cts +2 -1
  52. package/dist/databasePluginCrudValidationQueries.d.mts +2 -1
  53. package/dist/databasePluginCrudValidationRows.d.cts +1 -1
  54. package/dist/databasePluginCrudValidationRows.d.mts +1 -1
  55. package/dist/databaseRows.cjs +0 -1
  56. package/dist/databaseRows.d.cts +2 -6
  57. package/dist/databaseRows.d.mts +2 -6
  58. package/dist/index.cjs +4 -1
  59. package/dist/index.d.cts +4 -3
  60. package/dist/index.d.mts +4 -3
  61. package/dist/index.mjs +2 -1
  62. package/dist/insightsContract.cjs +157 -0
  63. package/dist/insightsContract.d.cts +11 -0
  64. package/dist/insightsContract.d.mts +11 -0
  65. package/dist/insightsContract.mjs +153 -0
  66. package/dist/internal.d.cts +5 -4
  67. package/dist/internal.d.mts +5 -4
  68. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.cjs +136 -0
  69. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.mjs +116 -0
  70. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.cjs +167 -0
  71. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.mjs +165 -0
  72. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.cjs +42 -0
  73. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.mjs +39 -0
  74. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.cjs +39 -0
  75. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.mjs +37 -0
  76. package/dist/paginateBundles.d.cts +1 -8
  77. package/dist/paginateBundles.d.mts +1 -8
  78. package/dist/parseStorageUri.d.cts +1 -5
  79. package/dist/parseStorageUri.d.mts +1 -5
  80. package/dist/queryBundles.d.cts +0 -1
  81. package/dist/queryBundles.d.mts +0 -1
  82. package/dist/releaseCatalogCompiler.cjs +15 -12
  83. package/dist/releaseCatalogCompiler.d.cts +0 -1
  84. package/dist/releaseCatalogCompiler.d.mts +0 -1
  85. package/dist/releaseCatalogCompiler.mjs +11 -7
  86. package/dist/releaseCatalogMutation.cjs +1 -1
  87. package/dist/releaseCatalogMutation.d.cts +1 -1
  88. package/dist/releaseCatalogMutation.d.mts +1 -1
  89. package/dist/releaseCatalogMutation.mjs +1 -0
  90. package/dist/releaseManagement.cjs +3 -2
  91. package/dist/releaseManagement.d.cts +1 -1
  92. package/dist/releaseManagement.d.mts +1 -1
  93. package/dist/releaseManagement.mjs +3 -1
  94. package/dist/remoteBundleSigning.cjs +4 -4
  95. package/dist/remoteBundleSigning.d.cts +2 -13
  96. package/dist/remoteBundleSigning.d.mts +2 -13
  97. package/dist/remoteBundleSigning.mjs +4 -4
  98. package/dist/requestBundleCache.d.cts +1 -2
  99. package/dist/requestBundleCache.d.mts +1 -2
  100. package/dist/semverSatisfies.cjs +4 -3
  101. package/dist/semverSatisfies.mjs +2 -1
  102. package/dist/storageDownloadPath.cjs +2 -1
  103. package/dist/storageDownloadPath.d.cts +1 -3
  104. package/dist/storageDownloadPath.d.mts +1 -3
  105. package/dist/storageDownloadPath.mjs +2 -1
  106. package/dist/types/database.d.cts +4 -3
  107. package/dist/types/database.d.mts +4 -3
  108. package/dist/types/databaseFields.cjs +13 -0
  109. package/dist/types/databaseFields.d.cts +1 -0
  110. package/dist/types/databaseFields.d.mts +1 -0
  111. package/dist/types/databaseFields.mjs +13 -0
  112. package/dist/types/databaseOperations.d.cts +26 -15
  113. package/dist/types/databaseOperations.d.mts +26 -15
  114. package/dist/types/databasePlugin.d.cts +70 -12
  115. package/dist/types/databasePlugin.d.mts +70 -12
  116. package/dist/types/databaseQuery.d.cts +2 -3
  117. package/dist/types/databaseQuery.d.mts +2 -3
  118. package/dist/types/databaseRows.d.cts +3 -2
  119. package/dist/types/databaseRows.d.mts +3 -2
  120. package/dist/types/index.d.cts +11 -7
  121. package/dist/types/index.d.mts +11 -7
  122. package/dist/types/internal.d.cts +5 -4
  123. package/dist/types/internal.d.mts +5 -4
  124. package/dist/types/public.d.cts +4 -3
  125. package/dist/types/public.d.mts +4 -3
  126. package/dist/types/utils.d.cts +1 -1
  127. package/dist/types/utils.d.mts +1 -1
  128. package/dist/uuidv7.cjs +7 -2
  129. package/dist/uuidv7.d.cts +0 -1
  130. package/dist/uuidv7.d.mts +0 -1
  131. package/dist/uuidv7.mjs +1 -1
  132. package/package.json +3 -3
  133. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.cjs +0 -345
  134. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.mjs +0 -341
@@ -4,10 +4,91 @@ import { validateCreateData, validateResult } from "./databasePluginCrudValidati
4
4
  import { validateApiKeyUpdateData, validateBundleUpdateData, validateReleaseUpdateData } from "./databasePluginCrudValidationMutations.mjs";
5
5
  import { createDatabasePluginCrud } from "./databasePluginCrud.mjs";
6
6
  import { createTransactionDatabasePlugin } from "./databasePluginTransaction.mjs";
7
+ import { compareInsightsText, createValidatedInsightsModel } from "./insightsContract.mjs";
7
8
  //#region src/createDatabasePlugin.ts
8
9
  const PAGE_SIZE = 100;
9
10
  const compareChannelRows = (left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
11
+ const toInsightsBundleWhere = (filter) => [
12
+ {
13
+ field: "platform",
14
+ value: filter.platform
15
+ },
16
+ {
17
+ field: "channel",
18
+ value: filter.channel
19
+ },
20
+ {
21
+ field: "type",
22
+ value: filter.type
23
+ },
24
+ filter.type === "RECOVERED" ? {
25
+ field: "from_bundle_id",
26
+ value: filter.fromBundleId
27
+ } : {
28
+ field: "to_bundle_id",
29
+ value: filter.toBundleId
30
+ }
31
+ ];
32
+ const toInsightsEventRanges = (filter) => {
33
+ if (filter.kind === "all") return [[]];
34
+ if (filter.kind === "bundle") return [toInsightsBundleWhere(filter)];
35
+ return ["UPDATE_APPLIED", "RECOVERED"].map((type) => [{
36
+ field: "install_id",
37
+ value: filter.installId
38
+ }, {
39
+ field: "type",
40
+ value: type
41
+ }]);
42
+ };
43
+ const listInsightsEventRange = async (crud, input, filterWhere) => {
44
+ const where = [...filterWhere, {
45
+ field: "received_at_ms",
46
+ operator: "gte",
47
+ value: input.sinceMs ?? 0
48
+ }];
49
+ const sameTimestamp = input.after === void 0 ? [] : await crud.findMany({
50
+ model: "bundle_events",
51
+ where: [
52
+ ...filterWhere,
53
+ {
54
+ field: "received_at_ms",
55
+ value: input.after.receivedAtMs
56
+ },
57
+ {
58
+ field: "id",
59
+ operator: "lt",
60
+ value: input.after.id
61
+ }
62
+ ],
63
+ orderBy: [{
64
+ field: "id",
65
+ direction: "desc"
66
+ }],
67
+ limit: input.limit,
68
+ offset: 0
69
+ });
70
+ if (sameTimestamp.length === input.limit) return sameTimestamp;
71
+ const older = await crud.findMany({
72
+ model: "bundle_events",
73
+ where: [...where, {
74
+ field: "received_at_ms",
75
+ operator: "lt",
76
+ value: input.after?.receivedAtMs ?? input.beforeReceivedAtMs
77
+ }],
78
+ orderBy: [{
79
+ field: "received_at_ms",
80
+ direction: "desc"
81
+ }, {
82
+ field: "id",
83
+ direction: "desc"
84
+ }],
85
+ limit: input.limit - sameTimestamp.length,
86
+ offset: 0
87
+ });
88
+ return [...sameTimestamp, ...older];
89
+ };
10
90
  var DatabaseAtomicCommitUnsupportedError = class extends Error {
91
+ pluginName;
11
92
  name = "DatabaseAtomicCommitUnsupportedError";
12
93
  constructor(pluginName) {
13
94
  super(`Database plugin "${pluginName}" cannot atomically commit changes across models.`);
@@ -28,6 +109,7 @@ var DatabaseRowReferencedError = class extends Error {
28
109
  }
29
110
  };
30
111
  var DatabaseCommitConflictError = class extends Error {
112
+ result;
31
113
  name = "DatabaseCommitConflictError";
32
114
  constructor(result) {
33
115
  super("Database commit precondition failed.");
@@ -255,12 +337,6 @@ const applyChange = async (database, change, changeIndex) => {
255
337
  }
256
338
  return;
257
339
  }
258
- case "insights":
259
- await database.create({
260
- model: "bundle_events",
261
- data: change.row
262
- });
263
- return;
264
340
  case "apiKeys": switch (change.operation) {
265
341
  case "insert":
266
342
  await database.create({
@@ -442,14 +518,6 @@ const validateDatabaseChange = (change) => {
442
518
  return;
443
519
  default: throw new DatabasePluginInputError("invalid-operation");
444
520
  }
445
- case "insights":
446
- if (change.operation !== "insert" || !hasOnlyKeys(change, [
447
- "model",
448
- "operation",
449
- "row"
450
- ])) throw new DatabasePluginInputError("invalid-operation");
451
- validateCreateData("bundle_events", change.row);
452
- return;
453
521
  case "apiKeys": switch (change.operation) {
454
522
  case "insert":
455
523
  if (!hasOnlyKeys(change, [
@@ -718,36 +786,82 @@ const createDatabasePluginAdapter = (name, implementation) => {
718
786
  }
719
787
  },
720
788
  insights: {
721
- async append(row) {
722
- await crud.create({
723
- model: "bundle_events",
724
- data: row
725
- });
789
+ record: (input) => implementation.recordInsights(input),
790
+ async listEvents(input) {
791
+ const ranges = await Promise.all(toInsightsEventRanges(input.filter).map((where) => listInsightsEventRange(crud, input, where)));
792
+ if (ranges.length === 1) return ranges[0];
793
+ return ranges.flat().sort((left, right) => right.received_at_ms - left.received_at_ms || compareInsightsText(right.id, left.id)).slice(0, input.limit);
726
794
  },
727
- async scan(input) {
728
- const rows = [];
729
- for (let offset = 0; rows.length < input.limit; offset += PAGE_SIZE) {
730
- const page = await crud.findMany({
731
- model: "bundle_events",
795
+ async findInstallations(input) {
796
+ if ("installId" in input) {
797
+ const row = await crud.findOne({
798
+ model: "bundle_installations",
732
799
  where: [{
800
+ field: "install_id",
801
+ value: input.installId
802
+ }]
803
+ });
804
+ return row === null ? [] : [row];
805
+ }
806
+ return crud.findMany({
807
+ model: "bundle_installations",
808
+ where: [{
809
+ field: "user_id",
810
+ value: input.userId
811
+ }, ...input.afterInstallId === void 0 ? [] : [{
812
+ field: "install_id",
813
+ operator: "gt",
814
+ value: input.afterInstallId
815
+ }]],
816
+ orderBy: [{
817
+ field: "install_id",
818
+ direction: "asc"
819
+ }],
820
+ limit: input.limit,
821
+ offset: 0
822
+ });
823
+ },
824
+ countInstallations(input) {
825
+ return crud.count({
826
+ model: "bundle_installations",
827
+ where: [
828
+ {
829
+ field: "platform",
830
+ value: input.platform
831
+ },
832
+ {
833
+ field: "channel",
834
+ value: input.channel
835
+ },
836
+ {
837
+ field: "received_at_ms",
838
+ operator: "gte",
839
+ value: input.sinceMs
840
+ },
841
+ ...input.bundleId === void 0 ? [] : [{
842
+ field: "to_bundle_id",
843
+ value: input.bundleId
844
+ }]
845
+ ]
846
+ });
847
+ },
848
+ countEvents(input) {
849
+ return crud.count({
850
+ model: "bundle_events",
851
+ where: [
852
+ ...toInsightsBundleWhere(input.filter),
853
+ {
854
+ field: "received_at_ms",
855
+ operator: "gte",
856
+ value: input.sinceMs
857
+ },
858
+ {
733
859
  field: "received_at_ms",
734
860
  operator: "lt",
735
861
  value: input.beforeReceivedAtMs
736
- }],
737
- orderBy: [{
738
- field: "received_at_ms",
739
- direction: "asc"
740
- }, {
741
- field: "id",
742
- direction: "asc"
743
- }],
744
- limit: PAGE_SIZE,
745
- offset
746
- });
747
- rows.push(...page.filter((row) => input.after === void 0 || row.received_at_ms > input.after.receivedAtMs || row.received_at_ms === input.after.receivedAtMs && row.id > input.after.id));
748
- if (page.length < PAGE_SIZE) break;
749
- }
750
- return rows.slice(0, input.limit);
862
+ }
863
+ ]
864
+ });
751
865
  }
752
866
  },
753
867
  apiKeys: {
@@ -791,6 +905,12 @@ const createDatabasePluginAdapter = (name, implementation) => {
791
905
  ...implementation.dispose ? { dispose: implementation.dispose } : {}
792
906
  };
793
907
  };
794
- const createDatabasePlugin = (options) => ({ ...options });
908
+ const createDatabasePlugin = (options) => ({
909
+ ...options,
910
+ models: {
911
+ ...options.models,
912
+ insights: createValidatedInsightsModel(options.models.insights)
913
+ }
914
+ });
795
915
  //#endregion
796
- export { DatabaseAtomicCommitUnsupportedError, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };
916
+ export { DatabaseAtomicCommitUnsupportedError, DatabasePluginInputError, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };
@@ -1,5 +1,4 @@
1
1
  import { StoragePlugin } from "./types/index.cjs";
2
-
3
2
  //#region src/createStoragePlugin.d.ts
4
3
  type CreateStoragePluginOptions = StoragePlugin;
5
4
  type StorageOperation = Exclude<keyof StoragePlugin, "name" | "protocol">;
@@ -1,5 +1,4 @@
1
1
  import { StoragePlugin } from "./types/index.mjs";
2
-
3
2
  //#region src/createStoragePlugin.d.ts
4
3
  type CreateStoragePluginOptions = StoragePlugin;
5
4
  type StorageOperation = Exclude<keyof StoragePlugin, "name" | "protocol">;
@@ -4,6 +4,7 @@ const require_databaseClientReads = require("./databaseClientReads.cjs");
4
4
  const require_databaseClientUpdates = require("./databaseClientUpdates.cjs");
5
5
  //#region src/databaseClient.ts
6
6
  var DatabaseBundleNotFoundError = class extends Error {
7
+ bundleId;
7
8
  name = "DatabaseBundleNotFoundError";
8
9
  constructor(bundleId) {
9
10
  super(`Bundle "${bundleId}" was not found.`);
@@ -11,6 +12,8 @@ var DatabaseBundleNotFoundError = class extends Error {
11
12
  }
12
13
  };
13
14
  var DatabasePatchInsertUnsupportedError = class extends Error {
15
+ bundleId;
16
+ pluginName;
14
17
  name = "DatabasePatchInsertUnsupportedError";
15
18
  constructor(bundleId, pluginName) {
16
19
  super(`Database plugin "${pluginName}" cannot atomically insert patches for bundle "${bundleId}".`);
@@ -29,12 +32,13 @@ const insertChanges = (bundle) => [{
29
32
  }))];
30
33
  const updateChanges = (bundleId, update) => {
31
34
  const rowUpdate = require_databaseClientUpdates.bundleUpdateToRow(update);
35
+ const patchesPresent = Object.hasOwn(update, "patches");
32
36
  return [{
33
37
  model: "bundles",
34
38
  operation: "update",
35
39
  where: { id: bundleId },
36
40
  update: rowUpdate
37
- }, ...Object.hasOwn(update, "patches") ? [{
41
+ }, ...patchesPresent ? [{
38
42
  model: "bundlePatches",
39
43
  operation: "delete",
40
44
  where: { bundleId }
@@ -109,4 +113,5 @@ const createDatabaseClient = (plugin) => {
109
113
  //#endregion
110
114
  exports.DatabaseBundleNotFoundError = DatabaseBundleNotFoundError;
111
115
  exports.DatabasePatchInsertUnsupportedError = DatabasePatchInsertUnsupportedError;
116
+ exports.DatabasePatchUpdateUnsupportedError = require_databaseClientUpdates.DatabasePatchUpdateUnsupportedError;
112
117
  exports.createDatabaseClient = createDatabaseClient;
@@ -3,7 +3,6 @@ import { BundleRepository, ChannelDeleteInput, ChannelDeleteResult, ChannelInser
3
3
  import { DatabaseBundleQueryOptions, PaginatedResult } from "./types/index.cjs";
4
4
  import { DatabasePatchUpdateUnsupportedError } from "./databaseClientUpdates.cjs";
5
5
  import { Bundle } from "@hot-updater/core";
6
-
7
6
  //#region src/databaseClient.d.ts
8
7
  interface DatabaseClient {
9
8
  getBundleById(id: string): Promise<Bundle | null>;
@@ -30,4 +29,4 @@ declare class DatabasePatchInsertUnsupportedError extends Error {
30
29
  }
31
30
  declare const createDatabaseClient: (plugin: BundleRepository) => DatabaseClient;
32
31
  //#endregion
33
- export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, createDatabaseClient };
32
+ export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -3,7 +3,6 @@ import { BundleRepository, ChannelDeleteInput, ChannelDeleteResult, ChannelInser
3
3
  import { DatabaseBundleQueryOptions, PaginatedResult } from "./types/index.mjs";
4
4
  import { DatabasePatchUpdateUnsupportedError } from "./databaseClientUpdates.mjs";
5
5
  import { Bundle } from "@hot-updater/core";
6
-
7
6
  //#region src/databaseClient.d.ts
8
7
  interface DatabaseClient {
9
8
  getBundleById(id: string): Promise<Bundle | null>;
@@ -30,4 +29,4 @@ declare class DatabasePatchInsertUnsupportedError extends Error {
30
29
  }
31
30
  declare const createDatabaseClient: (plugin: BundleRepository) => DatabaseClient;
32
31
  //#endregion
33
- export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, createDatabaseClient };
32
+ export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -4,6 +4,7 @@ import { hydrateRows, responsePage } from "./databaseClientReads.mjs";
4
4
  import { DatabasePatchUpdateUnsupportedError, bundleUpdateToPatchRows, bundleUpdateToRow } from "./databaseClientUpdates.mjs";
5
5
  //#region src/databaseClient.ts
6
6
  var DatabaseBundleNotFoundError = class extends Error {
7
+ bundleId;
7
8
  name = "DatabaseBundleNotFoundError";
8
9
  constructor(bundleId) {
9
10
  super(`Bundle "${bundleId}" was not found.`);
@@ -11,6 +12,8 @@ var DatabaseBundleNotFoundError = class extends Error {
11
12
  }
12
13
  };
13
14
  var DatabasePatchInsertUnsupportedError = class extends Error {
15
+ bundleId;
16
+ pluginName;
14
17
  name = "DatabasePatchInsertUnsupportedError";
15
18
  constructor(bundleId, pluginName) {
16
19
  super(`Database plugin "${pluginName}" cannot atomically insert patches for bundle "${bundleId}".`);
@@ -29,12 +32,13 @@ const insertChanges = (bundle) => [{
29
32
  }))];
30
33
  const updateChanges = (bundleId, update) => {
31
34
  const rowUpdate = bundleUpdateToRow(update);
35
+ const patchesPresent = Object.hasOwn(update, "patches");
32
36
  return [{
33
37
  model: "bundles",
34
38
  operation: "update",
35
39
  where: { id: bundleId },
36
40
  update: rowUpdate
37
- }, ...Object.hasOwn(update, "patches") ? [{
41
+ }, ...patchesPresent ? [{
38
42
  model: "bundlePatches",
39
43
  operation: "delete",
40
44
  where: { bundleId }
@@ -107,4 +111,4 @@ const createDatabaseClient = (plugin) => {
107
111
  };
108
112
  };
109
113
  //#endregion
110
- export { DatabaseBundleNotFoundError, DatabasePatchInsertUnsupportedError, createDatabaseClient };
114
+ export { DatabaseBundleNotFoundError, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -59,7 +59,8 @@ const hydrateRows = async (database, ownerRows) => {
59
59
  const patchRows = await database.models.bundlePatches.findByBundleIds(ownerRows.map(({ id }) => id));
60
60
  const ownerIds = new Set(ownerRows.map(({ id }) => id));
61
61
  const referencedIds = [...new Set(patchRows.map(({ base_bundle_id }) => base_bundle_id).filter((id) => !ownerIds.has(id)))];
62
- return require_databaseRows.rowsToBundles(ownerRows, patchRows, referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } }));
62
+ const referencedRows = referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } });
63
+ return require_databaseRows.rowsToBundles(ownerRows, patchRows, referencedRows);
63
64
  };
64
65
  const cursorIdFilter = (cursor, direction) => {
65
66
  if (cursor?.after) return { [direction === "desc" ? "lt" : "gt"]: cursor.after };
@@ -110,4 +111,5 @@ const responsePage = async (database, options) => {
110
111
  };
111
112
  //#endregion
112
113
  exports.hydrateRows = hydrateRows;
114
+ exports.loadBundleRows = loadBundleRows;
113
115
  exports.responsePage = responsePage;
@@ -59,7 +59,8 @@ const hydrateRows = async (database, ownerRows) => {
59
59
  const patchRows = await database.models.bundlePatches.findByBundleIds(ownerRows.map(({ id }) => id));
60
60
  const ownerIds = new Set(ownerRows.map(({ id }) => id));
61
61
  const referencedIds = [...new Set(patchRows.map(({ base_bundle_id }) => base_bundle_id).filter((id) => !ownerIds.has(id)))];
62
- return rowsToBundles(ownerRows, patchRows, referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } }));
62
+ const referencedRows = referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } });
63
+ return rowsToBundles(ownerRows, patchRows, referencedRows);
63
64
  };
64
65
  const cursorIdFilter = (cursor, direction) => {
65
66
  if (cursor?.after) return { [direction === "desc" ? "lt" : "gt"]: cursor.after };
@@ -109,4 +110,4 @@ const responsePage = async (database, options) => {
109
110
  };
110
111
  };
111
112
  //#endregion
112
- export { hydrateRows, responsePage };
113
+ export { hydrateRows, loadBundleRows, responsePage };
@@ -1,8 +1,9 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
1
  const require_databaseMetadata = require("./databaseMetadata.cjs");
3
2
  let _hot_updater_core = require("@hot-updater/core");
4
3
  //#region src/databaseClientUpdates.ts
5
4
  var DatabasePatchUpdateUnsupportedError = class extends Error {
5
+ bundleId;
6
+ pluginName;
6
7
  name = "DatabasePatchUpdateUnsupportedError";
7
8
  constructor(bundleId, pluginName) {
8
9
  super(`Database plugin "${pluginName}" cannot atomically replace patches for bundle "${bundleId}".`);
@@ -1,5 +1,5 @@
1
+ import "./types/index.cjs";
1
2
  import { Bundle } from "@hot-updater/core";
2
-
3
3
  //#region src/databaseClientUpdates.d.ts
4
4
  declare class DatabasePatchUpdateUnsupportedError extends Error {
5
5
  readonly bundleId: string;
@@ -1,5 +1,5 @@
1
+ import "./types/index.mjs";
1
2
  import { Bundle } from "@hot-updater/core";
2
-
3
3
  //#region src/databaseClientUpdates.d.ts
4
4
  declare class DatabasePatchUpdateUnsupportedError extends Error {
5
5
  readonly bundleId: string;
@@ -2,6 +2,8 @@ import { bundleMetadataToRow } from "./databaseMetadata.mjs";
2
2
  import { getBundlePatches } from "@hot-updater/core";
3
3
  //#region src/databaseClientUpdates.ts
4
4
  var DatabasePatchUpdateUnsupportedError = class extends Error {
5
+ bundleId;
6
+ pluginName;
5
7
  name = "DatabasePatchUpdateUnsupportedError";
6
8
  constructor(bundleId, pluginName) {
7
9
  super(`Database plugin "${pluginName}" cannot atomically replace patches for bundle "${bundleId}".`);
@@ -34,4 +34,6 @@ const isDatabaseJsonValue = (value) => {
34
34
  const isDatabaseJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && isDatabaseJsonValue(value);
35
35
  const isDatabaseMetadataObject = (value) => isDatabaseJsonObject(value) && (!Object.hasOwn(value, "app_version") || typeof value["app_version"] === "string");
36
36
  //#endregion
37
+ exports.isDatabaseJsonObject = isDatabaseJsonObject;
38
+ exports.isDatabaseJsonValue = isDatabaseJsonValue;
37
39
  exports.isDatabaseMetadataObject = isDatabaseMetadataObject;
@@ -1,4 +1,5 @@
1
1
  import { DatabaseBundleMetadata } from "./types/databaseRows.cjs";
2
+ import "./types/index.cjs";
2
3
  //#region src/databaseJsonValue.d.ts
3
4
  declare const isDatabaseMetadataObject: (value: unknown) => value is DatabaseBundleMetadata;
4
5
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { DatabaseBundleMetadata } from "./types/databaseRows.mjs";
2
+ import "./types/index.mjs";
2
3
  //#region src/databaseJsonValue.d.ts
3
4
  declare const isDatabaseMetadataObject: (value: unknown) => value is DatabaseBundleMetadata;
4
5
  //#endregion
@@ -34,4 +34,4 @@ const isDatabaseJsonValue = (value) => {
34
34
  const isDatabaseJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && isDatabaseJsonValue(value);
35
35
  const isDatabaseMetadataObject = (value) => isDatabaseJsonObject(value) && (!Object.hasOwn(value, "app_version") || typeof value["app_version"] === "string");
36
36
  //#endregion
37
- export { isDatabaseMetadataObject };
37
+ export { isDatabaseJsonObject, isDatabaseJsonValue, isDatabaseMetadataObject };
@@ -1,4 +1,3 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
1
  const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
3
2
  const require_databaseJsonValue = require("./databaseJsonValue.cjs");
4
3
  let _hot_updater_core = require("@hot-updater/core");
@@ -8,7 +8,7 @@ const createDatabasePluginCrud = (implementation) => {
8
8
  async function create(input) {
9
9
  require_databasePluginCrudValidationFields.validateModel(input.model);
10
10
  require_databasePluginCrudValidationRows.validateCreateData(input.model, input.data);
11
- if (input.onConflict !== void 0 && !(input.onConflict === "ignore" && (input.model === "channels" || input.model === "api_keys"))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-operation");
11
+ if (input.onConflict !== void 0 && !(input.onConflict === "ignore" && (input.model === "channels" || input.model === "api_keys" || input.model === "bundle_installations"))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-operation");
12
12
  require_databasePluginCrudValidationQueries.validateSelect(input.model, input.select);
13
13
  const row = await implementation.create(input);
14
14
  require_databasePluginCrudValidationRows.validateResult(input.model, row, input.select);
@@ -22,6 +22,7 @@ const createDatabasePluginCrud = (implementation) => {
22
22
  if (input.model === "bundles") require_databasePluginCrudValidationMutations.validateBundleUpdateData(input.update);
23
23
  else if (input.model === "releases") require_databasePluginCrudValidationMutations.validateReleaseUpdateData(input.update);
24
24
  else if (input.model === "release_catalogs") require_databasePluginCrudValidationMutations.validateReleaseCatalogUpdateData(input.update);
25
+ else if (input.model === "bundle_installations") require_databasePluginCrudValidationMutations.validateInsightsInstallationUpdateData(input.update);
25
26
  else if (input.model === "api_keys") require_databasePluginCrudValidationMutations.validateApiKeyUpdateData(input.update);
26
27
  else throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-operation");
27
28
  require_databasePluginCrudValidationQueries.validateSelect(input.model, input.select);
@@ -83,4 +84,5 @@ const createDatabasePluginCrud = (implementation) => {
83
84
  };
84
85
  };
85
86
  //#endregion
87
+ exports.DatabasePluginInputError = require_databasePluginCrudValidationErrors.DatabasePluginInputError;
86
88
  exports.createDatabasePluginCrud = createDatabasePluginCrud;
@@ -1 +1,4 @@
1
- import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.cjs";
1
+ import "./types/internal.cjs";
2
+ import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.cjs";
3
+ import "./databasePluginCrudValidation.cjs";
4
+ export { DatabasePluginInputError, type DatabasePluginInputErrorCode };
@@ -1 +1,4 @@
1
- import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.mjs";
1
+ import "./types/internal.mjs";
2
+ import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.mjs";
3
+ import "./databasePluginCrudValidation.mjs";
4
+ export { DatabasePluginInputError, type DatabasePluginInputErrorCode };
@@ -1,14 +1,14 @@
1
1
  import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
2
  import { validateModel } from "./databasePluginCrudValidationFields.mjs";
3
3
  import { selectRow, validateCreateData, validateResult } from "./databasePluginCrudValidationRows.mjs";
4
- import { validateApiKeyUpdateData, validateBundleUpdateData, validateMutationWhere, validateReleaseCatalogUpdateData, validateReleaseTargetUpdate, validateReleaseUpdateData, validateUpdateWhere } from "./databasePluginCrudValidationMutations.mjs";
4
+ import { validateApiKeyUpdateData, validateBundleUpdateData, validateInsightsInstallationUpdateData, validateMutationWhere, validateReleaseCatalogUpdateData, validateReleaseTargetUpdate, validateReleaseUpdateData, validateUpdateWhere } from "./databasePluginCrudValidationMutations.mjs";
5
5
  import { validateDistinctFields, validateDistinctOn, validateOrderBy, validatePagination, validateSelect, validateWhere } from "./databasePluginCrudValidationQueries.mjs";
6
6
  //#region src/databasePluginCrud.ts
7
7
  const createDatabasePluginCrud = (implementation) => {
8
8
  async function create(input) {
9
9
  validateModel(input.model);
10
10
  validateCreateData(input.model, input.data);
11
- if (input.onConflict !== void 0 && !(input.onConflict === "ignore" && (input.model === "channels" || input.model === "api_keys"))) throw new DatabasePluginInputError("invalid-operation");
11
+ if (input.onConflict !== void 0 && !(input.onConflict === "ignore" && (input.model === "channels" || input.model === "api_keys" || input.model === "bundle_installations"))) throw new DatabasePluginInputError("invalid-operation");
12
12
  validateSelect(input.model, input.select);
13
13
  const row = await implementation.create(input);
14
14
  validateResult(input.model, row, input.select);
@@ -22,6 +22,7 @@ const createDatabasePluginCrud = (implementation) => {
22
22
  if (input.model === "bundles") validateBundleUpdateData(input.update);
23
23
  else if (input.model === "releases") validateReleaseUpdateData(input.update);
24
24
  else if (input.model === "release_catalogs") validateReleaseCatalogUpdateData(input.update);
25
+ else if (input.model === "bundle_installations") validateInsightsInstallationUpdateData(input.update);
25
26
  else if (input.model === "api_keys") validateApiKeyUpdateData(input.update);
26
27
  else throw new DatabasePluginInputError("invalid-operation");
27
28
  validateSelect(input.model, input.select);
@@ -83,4 +84,4 @@ const createDatabasePluginCrud = (implementation) => {
83
84
  };
84
85
  };
85
86
  //#endregion
86
- export { createDatabasePluginCrud };
87
+ export { DatabasePluginInputError, createDatabasePluginCrud };
@@ -1 +1,6 @@
1
- import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.cjs";
1
+ import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.cjs";
2
+ import "./databasePluginCrudValidationFields.cjs";
3
+ import "./databasePluginCrudValidationMutations.cjs";
4
+ import "./databasePluginCrudValidationQueries.cjs";
5
+ import "./databasePluginCrudValidationRows.cjs";
6
+ export { DatabasePluginInputError, type DatabasePluginInputErrorCode };
@@ -1 +1,6 @@
1
- import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.mjs";
1
+ import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.mjs";
2
+ import "./databasePluginCrudValidationFields.mjs";
3
+ import "./databasePluginCrudValidationMutations.mjs";
4
+ import "./databasePluginCrudValidationQueries.mjs";
5
+ import "./databasePluginCrudValidationRows.mjs";
6
+ export { DatabasePluginInputError, type DatabasePluginInputErrorCode };
@@ -1,5 +1,6 @@
1
1
  //#region src/databasePluginCrudValidationErrors.ts
2
2
  var DatabasePluginInputError = class extends Error {
3
+ code;
3
4
  name = "DatabasePluginInputError";
4
5
  constructor(code) {
5
6
  super(`Invalid database plugin input: ${code}`);
@@ -1,5 +1,6 @@
1
1
  //#region src/databasePluginCrudValidationErrors.ts
2
2
  var DatabasePluginInputError = class extends Error {
3
+ code;
3
4
  name = "DatabasePluginInputError";
4
5
  constructor(code) {
5
6
  super(`Invalid database plugin input: ${code}`);