@hot-updater/plugin-core 1.0.0-rc.0 → 1.0.0-rc.14

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 (142) 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 +116 -42
  15. package/dist/createDatabasePlugin.d.cts +3 -1
  16. package/dist/createDatabasePlugin.d.mts +3 -1
  17. package/dist/createDatabasePlugin.mjs +116 -43
  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 +4 -0
  31. package/dist/databaseJsonValue.d.cts +4 -2
  32. package/dist/databaseJsonValue.d.mts +4 -2
  33. package/dist/databaseJsonValue.mjs +2 -1
  34. package/dist/databaseMetadata.cjs +0 -1
  35. package/dist/databasePluginCrud.cjs +1 -0
  36. package/dist/databasePluginCrud.d.cts +4 -1
  37. package/dist/databasePluginCrud.d.mts +4 -1
  38. package/dist/databasePluginCrud.mjs +1 -1
  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 +21 -19
  44. package/dist/databasePluginCrudValidationFields.d.cts +1 -1
  45. package/dist/databasePluginCrudValidationFields.d.mts +1 -1
  46. package/dist/databasePluginCrudValidationFields.mjs +20 -20
  47. package/dist/databasePluginCrudValidationMutations.cjs +1 -1
  48. package/dist/databasePluginCrudValidationMutations.d.cts +1 -1
  49. package/dist/databasePluginCrudValidationMutations.d.mts +1 -1
  50. package/dist/databasePluginCrudValidationMutations.mjs +1 -1
  51. package/dist/databasePluginCrudValidationQueries.d.cts +2 -1
  52. package/dist/databasePluginCrudValidationQueries.d.mts +2 -1
  53. package/dist/databasePluginCrudValidationRows.cjs +2 -2
  54. package/dist/databasePluginCrudValidationRows.d.cts +1 -1
  55. package/dist/databasePluginCrudValidationRows.d.mts +1 -1
  56. package/dist/databasePluginCrudValidationRows.mjs +2 -2
  57. package/dist/databaseRows.cjs +0 -1
  58. package/dist/databaseRows.d.cts +2 -6
  59. package/dist/databaseRows.d.mts +2 -6
  60. package/dist/index.cjs +4 -1
  61. package/dist/index.d.cts +5 -4
  62. package/dist/index.d.mts +5 -4
  63. package/dist/index.mjs +3 -2
  64. package/dist/insightsContract.cjs +146 -0
  65. package/dist/insightsContract.d.cts +9 -0
  66. package/dist/insightsContract.d.mts +9 -0
  67. package/dist/insightsContract.mjs +143 -0
  68. package/dist/insightsLatestQueries.cjs +53 -0
  69. package/dist/insightsLatestQueries.d.cts +13 -0
  70. package/dist/insightsLatestQueries.d.mts +13 -0
  71. package/dist/insightsLatestQueries.mjs +52 -0
  72. package/dist/internal.cjs +3 -0
  73. package/dist/internal.d.cts +5 -3
  74. package/dist/internal.d.mts +5 -3
  75. package/dist/internal.mjs +2 -1
  76. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.cjs +136 -0
  77. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.mjs +116 -0
  78. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.cjs +167 -0
  79. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/range-DvX-Y6iv.mjs +165 -0
  80. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.cjs +42 -0
  81. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/set-CC5YeoYX.mjs +39 -0
  82. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.cjs +39 -0
  83. package/dist/node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.mjs +37 -0
  84. package/dist/paginateBundles.d.cts +1 -8
  85. package/dist/paginateBundles.d.mts +1 -8
  86. package/dist/parseStorageUri.d.cts +1 -5
  87. package/dist/parseStorageUri.d.mts +1 -5
  88. package/dist/queryBundles.d.cts +0 -1
  89. package/dist/queryBundles.d.mts +0 -1
  90. package/dist/releaseCatalogCompiler.cjs +15 -12
  91. package/dist/releaseCatalogCompiler.d.cts +0 -1
  92. package/dist/releaseCatalogCompiler.d.mts +0 -1
  93. package/dist/releaseCatalogCompiler.mjs +11 -7
  94. package/dist/releaseCatalogMutation.cjs +1 -1
  95. package/dist/releaseCatalogMutation.d.cts +1 -1
  96. package/dist/releaseCatalogMutation.d.mts +1 -1
  97. package/dist/releaseCatalogMutation.mjs +1 -0
  98. package/dist/releaseManagement.cjs +3 -2
  99. package/dist/releaseManagement.d.cts +1 -1
  100. package/dist/releaseManagement.d.mts +1 -1
  101. package/dist/releaseManagement.mjs +3 -1
  102. package/dist/remoteBundleSigning.cjs +5 -7
  103. package/dist/remoteBundleSigning.d.cts +2 -15
  104. package/dist/remoteBundleSigning.d.mts +2 -15
  105. package/dist/remoteBundleSigning.mjs +5 -7
  106. package/dist/requestBundleCache.d.cts +1 -2
  107. package/dist/requestBundleCache.d.mts +1 -2
  108. package/dist/semverSatisfies.cjs +4 -3
  109. package/dist/semverSatisfies.mjs +2 -1
  110. package/dist/storageDownloadPath.cjs +2 -1
  111. package/dist/storageDownloadPath.d.cts +1 -3
  112. package/dist/storageDownloadPath.d.mts +1 -3
  113. package/dist/storageDownloadPath.mjs +2 -1
  114. package/dist/types/database.d.cts +4 -3
  115. package/dist/types/database.d.mts +4 -3
  116. package/dist/types/databaseFields.cjs +1 -5
  117. package/dist/types/databaseFields.d.cts +1 -1
  118. package/dist/types/databaseFields.d.mts +1 -1
  119. package/dist/types/databaseFields.mjs +1 -5
  120. package/dist/types/databaseOperations.d.cts +15 -12
  121. package/dist/types/databaseOperations.d.mts +15 -12
  122. package/dist/types/databasePlugin.d.cts +77 -13
  123. package/dist/types/databasePlugin.d.mts +77 -13
  124. package/dist/types/databaseQuery.d.cts +2 -3
  125. package/dist/types/databaseQuery.d.mts +2 -3
  126. package/dist/types/databaseRows.d.cts +16 -11
  127. package/dist/types/databaseRows.d.mts +16 -11
  128. package/dist/types/index.d.cts +15 -11
  129. package/dist/types/index.d.mts +15 -11
  130. package/dist/types/internal.d.cts +4 -3
  131. package/dist/types/internal.d.mts +4 -3
  132. package/dist/types/public.d.cts +4 -3
  133. package/dist/types/public.d.mts +4 -3
  134. package/dist/types/utils.d.cts +1 -1
  135. package/dist/types/utils.d.mts +1 -1
  136. package/dist/uuidv7.cjs +7 -2
  137. package/dist/uuidv7.d.cts +0 -1
  138. package/dist/uuidv7.d.mts +0 -1
  139. package/dist/uuidv7.mjs +1 -1
  140. package/package.json +4 -4
  141. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.cjs +0 -345
  142. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.mjs +0 -341
@@ -15,7 +15,7 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
@@ -5,7 +5,8 @@ const require_parseStorageUri = require("./parseStorageUri.cjs");
5
5
  const isBrotliManifestAssetPath = (assetPath) => /(^|\/)index\.[^/]+\.bundle$/.test(assetPath.replace(/\\/g, "/"));
6
6
  const getManifestAssetDownloadPath = (assetPath) => isBrotliManifestAssetPath(assetPath) ? `${assetPath}.br` : assetPath;
7
7
  const createStorageUriWithRelativePath = ({ baseStorageUri, relativePath }) => {
8
- const parsed = require_parseStorageUri.parseStorageUri(baseStorageUri, new URL(baseStorageUri).protocol.replace(":", ""));
8
+ const protocol = new URL(baseStorageUri).protocol.replace(":", "");
9
+ const parsed = require_parseStorageUri.parseStorageUri(baseStorageUri, protocol);
9
10
  const childKey = require_createStorageKeyBuilder.createStorageKeyBuilder(void 0)(relativePath);
10
11
  if (!childKey) throw new Error("Relative storage key must not be empty.");
11
12
  return require_parseStorageUri.createStorageUri({
@@ -15,7 +16,8 @@ const createStorageUriWithRelativePath = ({ baseStorageUri, relativePath }) => {
15
16
  });
16
17
  };
17
18
  const replaceStorageUriKeySuffix = ({ storageUri, keySuffix, replacement }) => {
18
- const parsed = require_parseStorageUri.parseStorageUri(storageUri, new URL(storageUri).protocol.replace(":", ""));
19
+ const protocol = new URL(storageUri).protocol.replace(":", "");
20
+ const parsed = require_parseStorageUri.parseStorageUri(storageUri, protocol);
19
21
  const normalizedSuffix = require_createStorageKeyBuilder.createStorageKeyBuilder(void 0)(keySuffix);
20
22
  const normalizedReplacement = require_createStorageKeyBuilder.createStorageKeyBuilder(void 0)(replacement);
21
23
  if (!normalizedSuffix || !normalizedReplacement) throw new Error("Storage URI key suffix and replacement must not be empty.");
@@ -1,44 +1,25 @@
1
1
  //#region src/assetStorageLayout.d.ts
2
2
  declare const isBrotliManifestAssetPath: (assetPath: string) => boolean;
3
3
  declare const getManifestAssetDownloadPath: (assetPath: string) => string;
4
- declare const createStorageUriWithRelativePath: ({
5
- baseStorageUri,
6
- relativePath
7
- }: {
4
+ declare const createStorageUriWithRelativePath: ({ baseStorageUri, relativePath }: {
8
5
  baseStorageUri: string;
9
6
  relativePath: string;
10
7
  }) => string;
11
- declare const replaceStorageUriKeySuffix: ({
12
- storageUri,
13
- keySuffix,
14
- replacement
15
- }: {
8
+ declare const replaceStorageUriKeySuffix: ({ storageUri, keySuffix, replacement }: {
16
9
  storageUri: string;
17
10
  keySuffix: string;
18
11
  replacement: string;
19
12
  }) => string;
20
- declare const resolveManifestAssetStorageFileHash: ({
21
- downloadFileHash,
22
- fileHash
23
- }: {
13
+ declare const resolveManifestAssetStorageFileHash: ({ downloadFileHash, fileHash }: {
24
14
  downloadFileHash?: unknown;
25
15
  fileHash: string;
26
16
  }) => string;
27
- declare const getManifestAssetStoragePath: ({
28
- assetPath,
29
- downloadFileHash,
30
- fileHash
31
- }: {
17
+ declare const getManifestAssetStoragePath: ({ assetPath, downloadFileHash, fileHash }: {
32
18
  assetPath: string;
33
19
  downloadFileHash?: unknown;
34
20
  fileHash: string;
35
21
  }) => string;
36
- declare const resolveManifestAssetStorageUri: ({
37
- assetBaseStorageUri,
38
- assetPath,
39
- downloadFileHash,
40
- fileHash
41
- }: {
22
+ declare const resolveManifestAssetStorageUri: ({ assetBaseStorageUri, assetPath, downloadFileHash, fileHash }: {
42
23
  assetBaseStorageUri: string;
43
24
  assetPath: string;
44
25
  downloadFileHash?: unknown;
@@ -1,44 +1,25 @@
1
1
  //#region src/assetStorageLayout.d.ts
2
2
  declare const isBrotliManifestAssetPath: (assetPath: string) => boolean;
3
3
  declare const getManifestAssetDownloadPath: (assetPath: string) => string;
4
- declare const createStorageUriWithRelativePath: ({
5
- baseStorageUri,
6
- relativePath
7
- }: {
4
+ declare const createStorageUriWithRelativePath: ({ baseStorageUri, relativePath }: {
8
5
  baseStorageUri: string;
9
6
  relativePath: string;
10
7
  }) => string;
11
- declare const replaceStorageUriKeySuffix: ({
12
- storageUri,
13
- keySuffix,
14
- replacement
15
- }: {
8
+ declare const replaceStorageUriKeySuffix: ({ storageUri, keySuffix, replacement }: {
16
9
  storageUri: string;
17
10
  keySuffix: string;
18
11
  replacement: string;
19
12
  }) => string;
20
- declare const resolveManifestAssetStorageFileHash: ({
21
- downloadFileHash,
22
- fileHash
23
- }: {
13
+ declare const resolveManifestAssetStorageFileHash: ({ downloadFileHash, fileHash }: {
24
14
  downloadFileHash?: unknown;
25
15
  fileHash: string;
26
16
  }) => string;
27
- declare const getManifestAssetStoragePath: ({
28
- assetPath,
29
- downloadFileHash,
30
- fileHash
31
- }: {
17
+ declare const getManifestAssetStoragePath: ({ assetPath, downloadFileHash, fileHash }: {
32
18
  assetPath: string;
33
19
  downloadFileHash?: unknown;
34
20
  fileHash: string;
35
21
  }) => string;
36
- declare const resolveManifestAssetStorageUri: ({
37
- assetBaseStorageUri,
38
- assetPath,
39
- downloadFileHash,
40
- fileHash
41
- }: {
22
+ declare const resolveManifestAssetStorageUri: ({ assetBaseStorageUri, assetPath, downloadFileHash, fileHash }: {
42
23
  assetBaseStorageUri: string;
43
24
  assetPath: string;
44
25
  downloadFileHash?: unknown;
@@ -5,7 +5,8 @@ import { createStorageUri, parseStorageUri } from "./parseStorageUri.mjs";
5
5
  const isBrotliManifestAssetPath = (assetPath) => /(^|\/)index\.[^/]+\.bundle$/.test(assetPath.replace(/\\/g, "/"));
6
6
  const getManifestAssetDownloadPath = (assetPath) => isBrotliManifestAssetPath(assetPath) ? `${assetPath}.br` : assetPath;
7
7
  const createStorageUriWithRelativePath = ({ baseStorageUri, relativePath }) => {
8
- const parsed = parseStorageUri(baseStorageUri, new URL(baseStorageUri).protocol.replace(":", ""));
8
+ const protocol = new URL(baseStorageUri).protocol.replace(":", "");
9
+ const parsed = parseStorageUri(baseStorageUri, protocol);
9
10
  const childKey = createStorageKeyBuilder(void 0)(relativePath);
10
11
  if (!childKey) throw new Error("Relative storage key must not be empty.");
11
12
  return createStorageUri({
@@ -15,7 +16,8 @@ const createStorageUriWithRelativePath = ({ baseStorageUri, relativePath }) => {
15
16
  });
16
17
  };
17
18
  const replaceStorageUriKeySuffix = ({ storageUri, keySuffix, replacement }) => {
18
- const parsed = parseStorageUri(storageUri, new URL(storageUri).protocol.replace(":", ""));
19
+ const protocol = new URL(storageUri).protocol.replace(":", "");
20
+ const parsed = parseStorageUri(storageUri, protocol);
19
21
  const normalizedSuffix = createStorageKeyBuilder(void 0)(keySuffix);
20
22
  const normalizedReplacement = createStorageKeyBuilder(void 0)(replacement);
21
23
  if (!normalizedSuffix || !normalizedReplacement) throw new Error("Storage URI key suffix and replacement must not be empty.");
@@ -1,5 +1,4 @@
1
1
  import { PaginationInfo } from "./types/index.cjs";
2
-
3
2
  //#region src/calculatePagination.d.ts
4
3
  interface PaginationOptions {
5
4
  limit: number;
@@ -1,5 +1,4 @@
1
1
  import { PaginationInfo } from "./types/index.mjs";
2
-
3
2
  //#region src/calculatePagination.d.ts
4
3
  interface PaginationOptions {
5
4
  limit: number;
@@ -1,6 +1,6 @@
1
1
  const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
2
  let mime = require("mime");
3
- mime = require_runtime.__toESM(mime);
3
+ mime = require_runtime.__toESM(mime, 1);
4
4
  //#region src/compressionFormat.ts
5
5
  /**
6
6
  * Compression formats registry
@@ -24,21 +24,28 @@ const COMPRESSION_FORMATS = {
24
24
  }
25
25
  };
26
26
  /**
27
+ * Finds the compression format matching a filename extension
28
+ * @param filename The filename to match
29
+ * @returns Compression format information, or undefined when nothing matches
30
+ */
31
+ function findCompressionFormat(filename) {
32
+ return Object.values(COMPRESSION_FORMATS).find((info) => filename.endsWith(info.fileExtension));
33
+ }
34
+ /**
27
35
  * Detects compression format from filename
28
36
  * @param filename The filename to detect format from
29
37
  * @returns Compression format information
30
38
  */
31
39
  function detectCompressionFormat(filename) {
32
- for (const info of Object.values(COMPRESSION_FORMATS)) if (filename.endsWith(info.fileExtension)) return info;
33
- return COMPRESSION_FORMATS.zip;
40
+ return findCompressionFormat(filename) ?? COMPRESSION_FORMATS.zip;
34
41
  }
35
42
  /**
36
43
  * Gets MIME type for a filename
37
44
  * @param filename The filename to get MIME type for
38
- * @returns MIME type string
45
+ * @returns MIME type string, or undefined when the filename is not an archive
39
46
  */
40
47
  function getCompressionMimeType(filename) {
41
- return detectCompressionFormat(filename).mimeType;
48
+ return findCompressionFormat(filename)?.mimeType;
42
49
  }
43
50
  /**
44
51
  * Gets Content-Type for a bundle file with 3-tier fallback
@@ -20,7 +20,7 @@ declare function detectCompressionFormat(filename: string): CompressionFormatInf
20
20
  /**
21
21
  * Gets MIME type for a filename
22
22
  * @param filename The filename to get MIME type for
23
- * @returns MIME type string
23
+ * @returns MIME type string, or undefined when the filename is not an archive
24
24
  */
25
25
  declare function getCompressionMimeType(filename: string): string | undefined;
26
26
  /**
@@ -20,7 +20,7 @@ declare function detectCompressionFormat(filename: string): CompressionFormatInf
20
20
  /**
21
21
  * Gets MIME type for a filename
22
22
  * @param filename The filename to get MIME type for
23
- * @returns MIME type string
23
+ * @returns MIME type string, or undefined when the filename is not an archive
24
24
  */
25
25
  declare function getCompressionMimeType(filename: string): string | undefined;
26
26
  /**
@@ -22,21 +22,28 @@ const COMPRESSION_FORMATS = {
22
22
  }
23
23
  };
24
24
  /**
25
+ * Finds the compression format matching a filename extension
26
+ * @param filename The filename to match
27
+ * @returns Compression format information, or undefined when nothing matches
28
+ */
29
+ function findCompressionFormat(filename) {
30
+ return Object.values(COMPRESSION_FORMATS).find((info) => filename.endsWith(info.fileExtension));
31
+ }
32
+ /**
25
33
  * Detects compression format from filename
26
34
  * @param filename The filename to detect format from
27
35
  * @returns Compression format information
28
36
  */
29
37
  function detectCompressionFormat(filename) {
30
- for (const info of Object.values(COMPRESSION_FORMATS)) if (filename.endsWith(info.fileExtension)) return info;
31
- return COMPRESSION_FORMATS.zip;
38
+ return findCompressionFormat(filename) ?? COMPRESSION_FORMATS.zip;
32
39
  }
33
40
  /**
34
41
  * Gets MIME type for a filename
35
42
  * @param filename The filename to get MIME type for
36
- * @returns MIME type string
43
+ * @returns MIME type string, or undefined when the filename is not an archive
37
44
  */
38
45
  function getCompressionMimeType(filename) {
39
- return detectCompressionFormat(filename).mimeType;
46
+ return findCompressionFormat(filename)?.mimeType;
40
47
  }
41
48
  /**
42
49
  * Gets Content-Type for a bundle file with 3-tier fallback
@@ -1,10 +1,7 @@
1
1
  //#region src/contentAddressedAssets.d.ts
2
2
  declare const CONTENT_ADDRESSED_ASSET_PREFIX = "assets";
3
3
  declare const isContentAddressedAssetFileHash: (value: unknown) => value is string;
4
- declare const getContentAddressedAssetStoragePath: ({
5
- assetPath,
6
- fileHash
7
- }: {
4
+ declare const getContentAddressedAssetStoragePath: ({ assetPath, fileHash }: {
8
5
  assetPath: string;
9
6
  fileHash: string;
10
7
  }) => string;
@@ -1,10 +1,7 @@
1
1
  //#region src/contentAddressedAssets.d.ts
2
2
  declare const CONTENT_ADDRESSED_ASSET_PREFIX = "assets";
3
3
  declare const isContentAddressedAssetFileHash: (value: unknown) => value is string;
4
- declare const getContentAddressedAssetStoragePath: ({
5
- assetPath,
6
- fileHash
7
- }: {
4
+ declare const getContentAddressedAssetStoragePath: ({ assetPath, fileHash }: {
8
5
  assetPath: string;
9
6
  fileHash: string;
10
7
  }) => string;
@@ -4,10 +4,95 @@ const require_databasePluginCrudValidationRows = require("./databasePluginCrudVa
4
4
  const require_databasePluginCrudValidationMutations = require("./databasePluginCrudValidationMutations.cjs");
5
5
  const require_databasePluginCrud = require("./databasePluginCrud.cjs");
6
6
  const require_databasePluginTransaction = require("./databasePluginTransaction.cjs");
7
+ const require_insightsContract = require("./insightsContract.cjs");
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 [
36
+ "UPDATE_DOWNLOADED",
37
+ "UPDATE_APPLIED",
38
+ "RECOVERED"
39
+ ].map((type) => [{
40
+ field: "install_id",
41
+ value: filter.installId
42
+ }, {
43
+ field: "type",
44
+ value: type
45
+ }]);
46
+ };
47
+ const listInsightsEventRange = async (crud, input, filterWhere) => {
48
+ const where = [...filterWhere, {
49
+ field: "received_at_ms",
50
+ operator: "gte",
51
+ value: input.sinceMs ?? 0
52
+ }];
53
+ const sameTimestamp = input.after === void 0 ? [] : await crud.findMany({
54
+ model: "bundle_events",
55
+ where: [
56
+ ...filterWhere,
57
+ {
58
+ field: "received_at_ms",
59
+ value: input.after.receivedAtMs
60
+ },
61
+ {
62
+ field: "id",
63
+ operator: "lt",
64
+ value: input.after.id
65
+ }
66
+ ],
67
+ orderBy: [{
68
+ field: "id",
69
+ direction: "desc"
70
+ }],
71
+ limit: input.limit,
72
+ offset: 0
73
+ });
74
+ if (sameTimestamp.length === input.limit) return sameTimestamp;
75
+ const older = await crud.findMany({
76
+ model: "bundle_events",
77
+ where: [...where, {
78
+ field: "received_at_ms",
79
+ operator: "lt",
80
+ value: input.after?.receivedAtMs ?? input.beforeReceivedAtMs
81
+ }],
82
+ orderBy: [{
83
+ field: "received_at_ms",
84
+ direction: "desc"
85
+ }, {
86
+ field: "id",
87
+ direction: "desc"
88
+ }],
89
+ limit: input.limit - sameTimestamp.length,
90
+ offset: 0
91
+ });
92
+ return [...sameTimestamp, ...older];
93
+ };
10
94
  var DatabaseAtomicCommitUnsupportedError = class extends Error {
95
+ pluginName;
11
96
  name = "DatabaseAtomicCommitUnsupportedError";
12
97
  constructor(pluginName) {
13
98
  super(`Database plugin "${pluginName}" cannot atomically commit changes across models.`);
@@ -28,6 +113,7 @@ var DatabaseRowReferencedError = class extends Error {
28
113
  }
29
114
  };
30
115
  var DatabaseCommitConflictError = class extends Error {
116
+ result;
31
117
  name = "DatabaseCommitConflictError";
32
118
  constructor(result) {
33
119
  super("Database commit precondition failed.");
@@ -255,12 +341,6 @@ const applyChange = async (database, change, changeIndex) => {
255
341
  }
256
342
  return;
257
343
  }
258
- case "analytics":
259
- await database.create({
260
- model: "bundle_events",
261
- data: change.row
262
- });
263
- return;
264
344
  case "apiKeys": switch (change.operation) {
265
345
  case "insert":
266
346
  await database.create({
@@ -442,14 +522,6 @@ const validateDatabaseChange = (change) => {
442
522
  return;
443
523
  default: throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-operation");
444
524
  }
445
- case "analytics":
446
- if (change.operation !== "insert" || !hasOnlyKeys(change, [
447
- "model",
448
- "operation",
449
- "row"
450
- ])) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-operation");
451
- require_databasePluginCrudValidationRows.validateCreateData("bundle_events", change.row);
452
- return;
453
525
  case "apiKeys": switch (change.operation) {
454
526
  case "insert":
455
527
  if (!hasOnlyKeys(change, [
@@ -717,37 +789,32 @@ const createDatabasePluginAdapter = (name, implementation) => {
717
789
  return result;
718
790
  }
719
791
  },
720
- analytics: {
721
- async append(row) {
722
- await crud.create({
723
- model: "bundle_events",
724
- data: row
725
- });
792
+ insights: {
793
+ recordEvent: (input) => implementation.recordInsights(input),
794
+ async listEvents(input) {
795
+ const ranges = await Promise.all(toInsightsEventRanges(input.filter).map((where) => listInsightsEventRange(crud, input, where)));
796
+ if (ranges.length === 1) return ranges[0];
797
+ return ranges.flat().sort((left, right) => right.received_at_ms - left.received_at_ms || require_insightsContract.compareInsightsText(right.id, left.id)).slice(0, input.limit);
726
798
  },
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",
732
- where: [{
799
+ findLatestEvents: (input) => implementation.findLatestInsightsEvents(input),
800
+ countLatestEvents: (input) => implementation.countLatestInsightsEvents(input),
801
+ countEvents(input) {
802
+ return crud.count({
803
+ model: "bundle_events",
804
+ where: [
805
+ ...toInsightsBundleWhere(input.filter),
806
+ {
807
+ field: "received_at_ms",
808
+ operator: "gte",
809
+ value: input.sinceMs
810
+ },
811
+ {
733
812
  field: "received_at_ms",
734
813
  operator: "lt",
735
814
  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);
815
+ }
816
+ ]
817
+ });
751
818
  }
752
819
  },
753
820
  apiKeys: {
@@ -791,9 +858,16 @@ const createDatabasePluginAdapter = (name, implementation) => {
791
858
  ...implementation.dispose ? { dispose: implementation.dispose } : {}
792
859
  };
793
860
  };
794
- const createDatabasePlugin = (options) => ({ ...options });
861
+ const createDatabasePlugin = (options) => ({
862
+ ...options,
863
+ models: {
864
+ ...options.models,
865
+ insights: require_insightsContract.createValidatedInsightsModel(options.models.insights)
866
+ }
867
+ });
795
868
  //#endregion
796
869
  exports.DatabaseAtomicCommitUnsupportedError = DatabaseAtomicCommitUnsupportedError;
870
+ exports.DatabasePluginInputError = require_databasePluginCrudValidationErrors.DatabasePluginInputError;
797
871
  exports.DatabaseRowReferencedError = DatabaseRowReferencedError;
798
872
  exports.createDatabasePlugin = createDatabasePlugin;
799
873
  exports.createDatabasePluginAdapter = createDatabasePluginAdapter;
@@ -1,6 +1,8 @@
1
1
  import { DatabasePlugin } from "./types/databasePlugin.cjs";
2
2
  import { DatabasePluginImplementation } from "./types/databaseOperations.cjs";
3
+ import "./types/internal.cjs";
3
4
  import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.cjs";
5
+ import "./databasePluginCrud.cjs";
4
6
  //#region src/createDatabasePlugin.d.ts
5
7
  declare class DatabaseAtomicCommitUnsupportedError extends Error {
6
8
  readonly pluginName: string;
@@ -23,4 +25,4 @@ type DatabasePluginAdapter = Omit<DatabasePlugin, "name">;
23
25
  declare const createDatabasePluginAdapter: (name: string, implementation: DatabasePluginImplementation) => DatabasePluginAdapter;
24
26
  declare const createDatabasePlugin: (options: CreateDatabasePluginOptions) => DatabasePlugin;
25
27
  //#endregion
26
- export { CreateDatabasePluginOptions, DatabaseAtomicCommitUnsupportedError, DatabasePluginAdapter, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };
28
+ export { CreateDatabasePluginOptions, DatabaseAtomicCommitUnsupportedError, DatabasePluginAdapter, DatabasePluginInputError, type DatabasePluginInputErrorCode, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };
@@ -1,6 +1,8 @@
1
1
  import { DatabasePlugin } from "./types/databasePlugin.mjs";
2
2
  import { DatabasePluginImplementation } from "./types/databaseOperations.mjs";
3
+ import "./types/internal.mjs";
3
4
  import { DatabasePluginInputError, DatabasePluginInputErrorCode } from "./databasePluginCrudValidationErrors.mjs";
5
+ import "./databasePluginCrud.mjs";
4
6
  //#region src/createDatabasePlugin.d.ts
5
7
  declare class DatabaseAtomicCommitUnsupportedError extends Error {
6
8
  readonly pluginName: string;
@@ -23,4 +25,4 @@ type DatabasePluginAdapter = Omit<DatabasePlugin, "name">;
23
25
  declare const createDatabasePluginAdapter: (name: string, implementation: DatabasePluginImplementation) => DatabasePluginAdapter;
24
26
  declare const createDatabasePlugin: (options: CreateDatabasePluginOptions) => DatabasePlugin;
25
27
  //#endregion
26
- export { CreateDatabasePluginOptions, DatabaseAtomicCommitUnsupportedError, DatabasePluginAdapter, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };
28
+ export { CreateDatabasePluginOptions, DatabaseAtomicCommitUnsupportedError, DatabasePluginAdapter, DatabasePluginInputError, type DatabasePluginInputErrorCode, DatabaseRowReferencedError, createDatabasePlugin, createDatabasePluginAdapter };