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

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 (163) hide show
  1. package/dist/bundleEventRow.cjs +42 -0
  2. package/dist/bundleEventRow.mjs +41 -0
  3. package/dist/bundleStorageLayout.cjs +7 -0
  4. package/dist/bundleStorageLayout.d.cts +5 -1
  5. package/dist/bundleStorageLayout.d.mts +5 -1
  6. package/dist/bundleStorageLayout.mjs +7 -1
  7. package/dist/contentType.cjs +9 -0
  8. package/dist/contentType.d.cts +4 -0
  9. package/dist/contentType.d.mts +4 -0
  10. package/dist/contentType.mjs +7 -0
  11. package/dist/coreApi.d.cts +131 -0
  12. package/dist/coreApi.d.mts +131 -0
  13. package/dist/database/adapter.cjs +37 -0
  14. package/dist/database/adapter.d.cts +150 -0
  15. package/dist/database/adapter.d.mts +150 -0
  16. package/dist/database/adapter.mjs +30 -0
  17. package/dist/database/memoryAdapter.cjs +102 -0
  18. package/dist/database/memoryAdapter.d.cts +16 -0
  19. package/dist/database/memoryAdapter.d.mts +16 -0
  20. package/dist/database/memoryAdapter.mjs +102 -0
  21. package/dist/database/values.cjs +110 -0
  22. package/dist/database/values.d.cts +30 -0
  23. package/dist/database/values.d.mts +30 -0
  24. package/dist/database/values.mjs +100 -0
  25. package/dist/database/verifyAdapter.cjs +129 -0
  26. package/dist/database/verifyAdapter.d.cts +29 -0
  27. package/dist/database/verifyAdapter.d.mts +29 -0
  28. package/dist/database/verifyAdapter.mjs +128 -0
  29. package/dist/databaseErrors.cjs +30 -0
  30. package/dist/databaseErrors.d.cts +21 -0
  31. package/dist/databaseErrors.d.mts +21 -0
  32. package/dist/databaseErrors.mjs +28 -0
  33. package/dist/databaseMetadata.cjs +2 -2
  34. package/dist/databaseMetadata.mjs +1 -1
  35. package/dist/databaseRows.cjs +0 -6
  36. package/dist/databaseRows.mjs +0 -6
  37. package/dist/index.cjs +14 -41
  38. package/dist/index.d.cts +15 -19
  39. package/dist/index.d.mts +15 -19
  40. package/dist/index.mjs +10 -16
  41. package/dist/insightsContract.cjs +65 -17
  42. package/dist/insightsContract.d.cts +6 -1
  43. package/dist/insightsContract.d.mts +6 -1
  44. package/dist/insightsContract.mjs +52 -5
  45. package/dist/insightsDistinctSummary.cjs +73 -0
  46. package/dist/insightsDistinctSummary.d.cts +12 -0
  47. package/dist/insightsDistinctSummary.d.mts +12 -0
  48. package/dist/insightsDistinctSummary.mjs +69 -0
  49. package/dist/insightsOverview.cjs +139 -0
  50. package/dist/insightsOverview.d.cts +42 -0
  51. package/dist/insightsOverview.d.mts +42 -0
  52. package/dist/insightsOverview.mjs +134 -0
  53. package/dist/internal.cjs +44 -8
  54. package/dist/internal.d.cts +12 -9
  55. package/dist/internal.d.mts +12 -9
  56. package/dist/internal.mjs +9 -4
  57. package/dist/releaseCatalogCompiler.cjs +1 -1
  58. package/dist/releaseCatalogCompiler.mjs +2 -2
  59. package/dist/releaseCatalogMutation.cjs +0 -292
  60. package/dist/releaseCatalogMutation.d.cts +4 -45
  61. package/dist/releaseCatalogMutation.d.mts +4 -45
  62. package/dist/releaseCatalogMutation.mjs +1 -288
  63. package/dist/releaseManagement.cjs +0 -221
  64. package/dist/releaseManagement.d.cts +4 -28
  65. package/dist/releaseManagement.d.mts +4 -28
  66. package/dist/releaseManagement.mjs +1 -216
  67. package/dist/types/databaseConfig.cjs +5 -0
  68. package/dist/types/databaseConfig.d.cts +33 -0
  69. package/dist/types/databaseConfig.d.mts +33 -0
  70. package/dist/types/databaseConfig.mjs +5 -0
  71. package/dist/types/databaseOperations.d.cts +5 -172
  72. package/dist/types/databaseOperations.d.mts +5 -172
  73. package/dist/types/databaseRows.d.cts +3 -6
  74. package/dist/types/databaseRows.d.mts +3 -6
  75. package/dist/types/index.cjs +2 -0
  76. package/dist/types/index.d.cts +9 -86
  77. package/dist/types/index.d.mts +9 -86
  78. package/dist/types/index.mjs +2 -1
  79. package/dist/types/insights.d.cts +172 -0
  80. package/dist/types/insights.d.mts +172 -0
  81. package/dist/types/internal.d.cts +4 -7
  82. package/dist/types/internal.d.mts +4 -7
  83. package/dist/types/models.d.cts +24 -0
  84. package/dist/types/models.d.mts +24 -0
  85. package/dist/types/public.d.cts +4 -2
  86. package/dist/types/public.d.mts +4 -2
  87. package/package.json +2 -2
  88. package/dist/calculatePagination.cjs +0 -25
  89. package/dist/calculatePagination.d.cts +0 -12
  90. package/dist/calculatePagination.d.mts +0 -12
  91. package/dist/calculatePagination.mjs +0 -25
  92. package/dist/compressionFormat.cjs +0 -62
  93. package/dist/compressionFormat.d.cts +0 -33
  94. package/dist/compressionFormat.d.mts +0 -33
  95. package/dist/compressionFormat.mjs +0 -58
  96. package/dist/createDatabasePlugin.cjs +0 -873
  97. package/dist/createDatabasePlugin.d.cts +0 -28
  98. package/dist/createDatabasePlugin.d.mts +0 -28
  99. package/dist/createDatabasePlugin.mjs +0 -869
  100. package/dist/databaseClient.cjs +0 -117
  101. package/dist/databaseClient.d.cts +0 -32
  102. package/dist/databaseClient.d.mts +0 -32
  103. package/dist/databaseClient.mjs +0 -114
  104. package/dist/databaseClientReads.cjs +0 -115
  105. package/dist/databaseClientReads.mjs +0 -113
  106. package/dist/databaseClientUpdates.cjs +0 -40
  107. package/dist/databaseClientUpdates.d.cts +0 -11
  108. package/dist/databaseClientUpdates.d.mts +0 -11
  109. package/dist/databaseClientUpdates.mjs +0 -38
  110. package/dist/databasePluginCrud.cjs +0 -87
  111. package/dist/databasePluginCrud.d.cts +0 -4
  112. package/dist/databasePluginCrud.d.mts +0 -4
  113. package/dist/databasePluginCrud.mjs +0 -86
  114. package/dist/databasePluginCrudValidation.d.cts +0 -6
  115. package/dist/databasePluginCrudValidation.d.mts +0 -6
  116. package/dist/databasePluginCrudValidationErrors.cjs +0 -11
  117. package/dist/databasePluginCrudValidationErrors.d.cts +0 -9
  118. package/dist/databasePluginCrudValidationErrors.d.mts +0 -9
  119. package/dist/databasePluginCrudValidationErrors.mjs +0 -11
  120. package/dist/databasePluginCrudValidationFields.cjs +0 -293
  121. package/dist/databasePluginCrudValidationFields.d.cts +0 -1
  122. package/dist/databasePluginCrudValidationFields.d.mts +0 -1
  123. package/dist/databasePluginCrudValidationFields.mjs +0 -281
  124. package/dist/databasePluginCrudValidationMutations.cjs +0 -88
  125. package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
  126. package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
  127. package/dist/databasePluginCrudValidationMutations.mjs +0 -82
  128. package/dist/databasePluginCrudValidationQueries.cjs +0 -103
  129. package/dist/databasePluginCrudValidationQueries.d.cts +0 -2
  130. package/dist/databasePluginCrudValidationQueries.d.mts +0 -2
  131. package/dist/databasePluginCrudValidationQueries.mjs +0 -97
  132. package/dist/databasePluginCrudValidationRows.cjs +0 -55
  133. package/dist/databasePluginCrudValidationRows.d.cts +0 -1
  134. package/dist/databasePluginCrudValidationRows.d.mts +0 -1
  135. package/dist/databasePluginCrudValidationRows.mjs +0 -53
  136. package/dist/databasePluginTransaction.cjs +0 -7
  137. package/dist/databasePluginTransaction.mjs +0 -7
  138. package/dist/insightsLatestQueries.cjs +0 -53
  139. package/dist/insightsLatestQueries.d.cts +0 -13
  140. package/dist/insightsLatestQueries.d.mts +0 -13
  141. package/dist/insightsLatestQueries.mjs +0 -52
  142. package/dist/paginateBundles.cjs +0 -53
  143. package/dist/paginateBundles.d.cts +0 -13
  144. package/dist/paginateBundles.d.mts +0 -13
  145. package/dist/paginateBundles.mjs +0 -53
  146. package/dist/queryBundles.cjs +0 -34
  147. package/dist/queryBundles.d.cts +0 -9
  148. package/dist/queryBundles.d.mts +0 -9
  149. package/dist/queryBundles.mjs +0 -32
  150. package/dist/requestBundleCache.cjs +0 -22
  151. package/dist/requestBundleCache.d.cts +0 -8
  152. package/dist/requestBundleCache.d.mts +0 -8
  153. package/dist/requestBundleCache.mjs +0 -22
  154. package/dist/types/database.d.cts +0 -5
  155. package/dist/types/database.d.mts +0 -5
  156. package/dist/types/databaseFields.cjs +0 -88
  157. package/dist/types/databaseFields.d.cts +0 -12
  158. package/dist/types/databaseFields.d.mts +0 -12
  159. package/dist/types/databaseFields.mjs +0 -88
  160. package/dist/types/databasePlugin.d.cts +0 -304
  161. package/dist/types/databasePlugin.d.mts +0 -304
  162. package/dist/types/databaseQuery.d.cts +0 -46
  163. package/dist/types/databaseQuery.d.mts +0 -46
@@ -1,7 +1,6 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
1
+ import { DatabasePluginInputError } from "./databaseErrors.mjs";
2
+ import { isRecord, validateBundleEventFields } from "./bundleEventRow.mjs";
2
3
  import { isUUIDv7 } from "./uuidv7.mjs";
3
- import { isRecord } from "./databasePluginCrudValidationFields.mjs";
4
- import { validateCreateData } from "./databasePluginCrudValidationRows.mjs";
5
4
  //#region src/insightsContract.ts
6
5
  const encoder = new TextEncoder();
7
6
  /** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
@@ -42,13 +41,15 @@ const isEventFilter = (value) => {
42
41
  };
43
42
  const validateRow = (model, row, result = false) => {
44
43
  try {
45
- validateCreateData(model, row);
44
+ validateBundleEventFields(row);
46
45
  if (!isRecord(row) || typeof row.id !== "string" || !isUUIDv7(row.id) || [...Object.values(row), ...isRecord(row.metadata) ? Object.values(row.metadata) : []].some((value) => typeof value === "string" && !isWellFormedText(value))) throw new DatabasePluginInputError("invalid-data");
47
46
  } catch (error) {
48
47
  if (result) throw new DatabasePluginInputError("invalid-result");
49
48
  throw error;
50
49
  }
51
50
  };
51
+ /** Throws `invalid-data` unless `row` is a complete, well-formed bundle event row. */
52
+ const assertBundleEventRow = (row) => validateRow("bundle_events", row);
52
53
  /** Downloads and applied transitions belong in installation history. */
53
54
  const isInsightsMovementEvent = (event) => event.type === "UPDATE_DOWNLOADED" || event.type === "UPDATE_APPLIED" || event.type === "RECOVERED";
54
55
  const matchesInsightsEventFilter = (event, filter) => {
@@ -63,6 +64,18 @@ const invalidResult = () => {
63
64
  throw new DatabasePluginInputError("invalid-result");
64
65
  };
65
66
  const validateCount = (count) => isTimestamp(count) ? count : invalidResult();
67
+ const isTimeRange = (value) => isRecord(value) && hasOnlyKeys(value, ["start", "end"]) && isTimestamp(value.start) && isTimestamp(value.end) && value.start < value.end;
68
+ const isReleaseReference = (value) => isRecord(value) && hasOnlyKeys(value, [
69
+ "releaseId",
70
+ "platform",
71
+ "channel"
72
+ ]) && isIdentity(value.releaseId) && hasScope(value);
73
+ const validateAggregateResult = (value) => {
74
+ const result = isRecord(value) ? value : invalidResult();
75
+ if (!isTimestamp(result.measuredAtMs)) invalidResult();
76
+ const coverage = result.coverage;
77
+ if (!isRecord(coverage) || coverage.kind !== "complete" && coverage.kind !== "partial" || coverage.sinceMs !== null && !isTimestamp(coverage.sinceMs)) invalidResult();
78
+ };
66
79
  /** Validate custom and bundled providers at the same public boundary. */
67
80
  const createValidatedInsightsModel = (model) => ({
68
81
  async recordEvent(input) {
@@ -137,7 +150,41 @@ const createValidatedInsightsModel = (model) => ({
137
150
  "beforeReceivedAtMs"
138
151
  ]) || !isBundleFilter(input.filter) || !isTimestamp(input.sinceMs) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs > input.beforeReceivedAtMs) invalidQuery();
139
152
  return validateCount(await model.countEvents(input));
153
+ },
154
+ async getReleaseActivity(input) {
155
+ if (!isRecord(input) || !hasOnlyKeys(input, [
156
+ "releases",
157
+ "scope",
158
+ "timeRange"
159
+ ])) invalidQuery();
160
+ const releases = input.releases;
161
+ const scope = input.scope;
162
+ const timeRange = input.timeRange;
163
+ const releaseQuery = Array.isArray(releases) && releases.length > 0 && releases.length <= 100 && releases.every(isReleaseReference) && scope === void 0 && (timeRange === void 0 || isTimeRange(timeRange));
164
+ const scopeQuery = releases === void 0 && isRecord(scope) && hasOnlyKeys(scope, ["platform", "channel"]) && hasScope(scope) && isTimeRange(timeRange);
165
+ if (!releaseQuery && !scopeQuery) invalidQuery();
166
+ const result = await model.getReleaseActivity(input);
167
+ validateAggregateResult(result);
168
+ if (!Array.isArray(result.data)) invalidResult();
169
+ return result;
170
+ },
171
+ async getAppUsage(input) {
172
+ if (!isRecord(input) || !hasOnlyKeys(input, [
173
+ "channel",
174
+ "platform",
175
+ "appVersion",
176
+ "timeRange",
177
+ "intervalMs"
178
+ ]) || !isText(input.channel) || ![
179
+ "all",
180
+ "ios",
181
+ "android"
182
+ ].includes(input.platform) || input.appVersion !== void 0 && !isText(input.appVersion) || !isTimeRange(input.timeRange) || !isTimestamp(input.intervalMs) || input.intervalMs < 36e5) invalidQuery();
183
+ const result = await model.getAppUsage(input);
184
+ validateAggregateResult(result);
185
+ if (!isTimestamp(result.activeInstallations) || !Array.isArray(result.points) || !Array.isArray(result.appVersions) || !Array.isArray(result.versions) || !Array.isArray(result.platforms) || !Array.isArray(result.bundleDistribution)) invalidResult();
186
+ return result;
140
187
  }
141
188
  });
142
189
  //#endregion
143
- export { compareInsightsText, createValidatedInsightsModel, isInsightsMovementEvent, matchesInsightsEventFilter };
190
+ export { assertBundleEventRow, compareInsightsText, createValidatedInsightsModel, isInsightsMovementEvent, matchesInsightsEventFilter };
@@ -0,0 +1,73 @@
1
+ //#region src/insightsDistinctSummary.ts
2
+ const PRECISION = 10;
3
+ const REGISTER_COUNT = 1024;
4
+ const MAX_RANK = 55;
5
+ const hash = (value) => {
6
+ let result = 14695981039346656037n;
7
+ for (const byte of new TextEncoder().encode(value)) {
8
+ result ^= BigInt(byte);
9
+ result = BigInt.asUintN(64, result * 1099511628211n);
10
+ }
11
+ return result;
12
+ };
13
+ const OFFSET = 33;
14
+ const decode = (summary) => {
15
+ if (!summary) return new Uint8Array(REGISTER_COUNT);
16
+ if (summary.length !== REGISTER_COUNT) throw new Error("Invalid Insights distinct summary");
17
+ const registers = new Uint8Array(REGISTER_COUNT);
18
+ for (let index = 0; index < REGISTER_COUNT; index += 1) {
19
+ const value = summary.charCodeAt(index) - OFFSET;
20
+ if (!Number.isInteger(value) || value < 0 || value > MAX_RANK) throw new Error("Invalid Insights distinct summary");
21
+ registers[index] = value;
22
+ }
23
+ return registers;
24
+ };
25
+ const encode = (registers) => Array.from(registers, (value) => String.fromCharCode(value + OFFSET)).join("");
26
+ const getInsightsDistinctRegister = (identity) => {
27
+ const value = hash(identity);
28
+ const index = Number(value & BigInt(1023));
29
+ let remainder = value >> BigInt(PRECISION);
30
+ let rank = 1;
31
+ while ((remainder & 1n) === 0n && rank < MAX_RANK) {
32
+ rank += 1;
33
+ remainder >>= 1n;
34
+ }
35
+ return {
36
+ index,
37
+ rank,
38
+ character: String.fromCharCode(rank + OFFSET)
39
+ };
40
+ };
41
+ const addInsightsDistinct = (summary, identity) => {
42
+ const registers = decode(summary);
43
+ const { index, rank } = getInsightsDistinctRegister(identity);
44
+ registers[index] = Math.max(registers[index], rank);
45
+ return encode(registers);
46
+ };
47
+ const mergeInsightsDistinct = (summaries) => {
48
+ const merged = new Uint8Array(REGISTER_COUNT);
49
+ for (const summary of summaries) {
50
+ const registers = decode(summary);
51
+ for (let index = 0; index < REGISTER_COUNT; index += 1) merged[index] = Math.max(merged[index], registers[index]);
52
+ }
53
+ return encode(merged);
54
+ };
55
+ const countInsightsDistinct = (summary) => {
56
+ const registers = decode(summary);
57
+ let inverseSum = 0;
58
+ let empty = 0;
59
+ for (const register of registers) {
60
+ inverseSum += 2 ** -register;
61
+ if (register === 0) empty += 1;
62
+ }
63
+ const raw = .7213 / 1.0010537109375 * REGISTER_COUNT ** 2 / inverseSum;
64
+ const estimate = raw <= 2.5 * REGISTER_COUNT && empty > 0 ? REGISTER_COUNT * Math.log(REGISTER_COUNT / empty) : raw;
65
+ return Math.max(0, Math.round(estimate));
66
+ };
67
+ const emptyInsightsDistinct = () => encode(new Uint8Array(REGISTER_COUNT));
68
+ //#endregion
69
+ exports.addInsightsDistinct = addInsightsDistinct;
70
+ exports.countInsightsDistinct = countInsightsDistinct;
71
+ exports.emptyInsightsDistinct = emptyInsightsDistinct;
72
+ exports.getInsightsDistinctRegister = getInsightsDistinctRegister;
73
+ exports.mergeInsightsDistinct = mergeInsightsDistinct;
@@ -0,0 +1,12 @@
1
+ //#region src/insightsDistinctSummary.d.ts
2
+ declare const getInsightsDistinctRegister: (identity: string) => {
3
+ index: number;
4
+ rank: number;
5
+ character: string;
6
+ };
7
+ declare const addInsightsDistinct: (summary: string | null | undefined, identity: string) => string;
8
+ declare const mergeInsightsDistinct: (summaries: readonly (string | null | undefined)[]) => string;
9
+ declare const countInsightsDistinct: (summary: string | null | undefined) => number;
10
+ declare const emptyInsightsDistinct: () => string;
11
+ //#endregion
12
+ export { addInsightsDistinct, countInsightsDistinct, emptyInsightsDistinct, getInsightsDistinctRegister, mergeInsightsDistinct };
@@ -0,0 +1,12 @@
1
+ //#region src/insightsDistinctSummary.d.ts
2
+ declare const getInsightsDistinctRegister: (identity: string) => {
3
+ index: number;
4
+ rank: number;
5
+ character: string;
6
+ };
7
+ declare const addInsightsDistinct: (summary: string | null | undefined, identity: string) => string;
8
+ declare const mergeInsightsDistinct: (summaries: readonly (string | null | undefined)[]) => string;
9
+ declare const countInsightsDistinct: (summary: string | null | undefined) => number;
10
+ declare const emptyInsightsDistinct: () => string;
11
+ //#endregion
12
+ export { addInsightsDistinct, countInsightsDistinct, emptyInsightsDistinct, getInsightsDistinctRegister, mergeInsightsDistinct };
@@ -0,0 +1,69 @@
1
+ //#region src/insightsDistinctSummary.ts
2
+ const PRECISION = 10;
3
+ const REGISTER_COUNT = 1024;
4
+ const MAX_RANK = 55;
5
+ const hash = (value) => {
6
+ let result = 14695981039346656037n;
7
+ for (const byte of new TextEncoder().encode(value)) {
8
+ result ^= BigInt(byte);
9
+ result = BigInt.asUintN(64, result * 1099511628211n);
10
+ }
11
+ return result;
12
+ };
13
+ const OFFSET = 33;
14
+ const decode = (summary) => {
15
+ if (!summary) return new Uint8Array(REGISTER_COUNT);
16
+ if (summary.length !== REGISTER_COUNT) throw new Error("Invalid Insights distinct summary");
17
+ const registers = new Uint8Array(REGISTER_COUNT);
18
+ for (let index = 0; index < REGISTER_COUNT; index += 1) {
19
+ const value = summary.charCodeAt(index) - OFFSET;
20
+ if (!Number.isInteger(value) || value < 0 || value > MAX_RANK) throw new Error("Invalid Insights distinct summary");
21
+ registers[index] = value;
22
+ }
23
+ return registers;
24
+ };
25
+ const encode = (registers) => Array.from(registers, (value) => String.fromCharCode(value + OFFSET)).join("");
26
+ const getInsightsDistinctRegister = (identity) => {
27
+ const value = hash(identity);
28
+ const index = Number(value & BigInt(1023));
29
+ let remainder = value >> BigInt(PRECISION);
30
+ let rank = 1;
31
+ while ((remainder & 1n) === 0n && rank < MAX_RANK) {
32
+ rank += 1;
33
+ remainder >>= 1n;
34
+ }
35
+ return {
36
+ index,
37
+ rank,
38
+ character: String.fromCharCode(rank + OFFSET)
39
+ };
40
+ };
41
+ const addInsightsDistinct = (summary, identity) => {
42
+ const registers = decode(summary);
43
+ const { index, rank } = getInsightsDistinctRegister(identity);
44
+ registers[index] = Math.max(registers[index], rank);
45
+ return encode(registers);
46
+ };
47
+ const mergeInsightsDistinct = (summaries) => {
48
+ const merged = new Uint8Array(REGISTER_COUNT);
49
+ for (const summary of summaries) {
50
+ const registers = decode(summary);
51
+ for (let index = 0; index < REGISTER_COUNT; index += 1) merged[index] = Math.max(merged[index], registers[index]);
52
+ }
53
+ return encode(merged);
54
+ };
55
+ const countInsightsDistinct = (summary) => {
56
+ const registers = decode(summary);
57
+ let inverseSum = 0;
58
+ let empty = 0;
59
+ for (const register of registers) {
60
+ inverseSum += 2 ** -register;
61
+ if (register === 0) empty += 1;
62
+ }
63
+ const raw = .7213 / 1.0010537109375 * REGISTER_COUNT ** 2 / inverseSum;
64
+ const estimate = raw <= 2.5 * REGISTER_COUNT && empty > 0 ? REGISTER_COUNT * Math.log(REGISTER_COUNT / empty) : raw;
65
+ return Math.max(0, Math.round(estimate));
66
+ };
67
+ const emptyInsightsDistinct = () => encode(new Uint8Array(REGISTER_COUNT));
68
+ //#endregion
69
+ export { addInsightsDistinct, countInsightsDistinct, emptyInsightsDistinct, getInsightsDistinctRegister, mergeInsightsDistinct };
@@ -0,0 +1,139 @@
1
+ //#region src/insightsOverview.ts
2
+ const encodeIdentity = (identity) => [
3
+ identity.scopeKind,
4
+ identity.releaseKind,
5
+ identity.releaseId,
6
+ identity.channel,
7
+ identity.platform,
8
+ identity.appVersionKind,
9
+ identity.appVersion,
10
+ identity.periodKind,
11
+ String(identity.bucketStartMs)
12
+ ].map((value) => `${new TextEncoder().encode(value).length}:${value}`).join("");
13
+ const fnv = (value, seed) => {
14
+ let result = seed;
15
+ for (const byte of new TextEncoder().encode(value)) {
16
+ result ^= BigInt(byte);
17
+ result = BigInt.asUintN(64, result * 1099511628211n);
18
+ }
19
+ return result.toString(16).padStart(16, "0");
20
+ };
21
+ /** A 128-bit hex key for a string: two FNV-1a 64 hashes with different seeds. */
22
+ const insightsKey = (value) => `${fnv(value, 14695981039346656037n)}${fnv(value, 9521211207457086692n)}`;
23
+ const insightsOverviewId = (identity) => insightsKey(encodeIdentity(identity));
24
+ const insightsOverviewValues = (identity) => ({
25
+ id: insightsOverviewId(identity),
26
+ scope_kind: identity.scopeKind,
27
+ release_kind: identity.releaseKind,
28
+ release_id: identity.releaseId,
29
+ channel: identity.channel,
30
+ platform: identity.platform,
31
+ app_version_kind: identity.appVersionKind,
32
+ app_version: identity.appVersion,
33
+ period_kind: identity.periodKind,
34
+ bucket_start_ms: identity.bucketStartMs
35
+ });
36
+ const hour = (value) => Math.floor(value / 36e5) * 36e5;
37
+ const currentInsightsReleaseId = (event) => event.type === "UPDATE_DOWNLOADED" ? event.from_release_id : event.to_release_id;
38
+ const insightsDistributionIdentity = (event) => {
39
+ const releaseId = currentInsightsReleaseId(event);
40
+ return {
41
+ scopeKind: "distribution",
42
+ releaseKind: releaseId === null ? "embedded" : "specific",
43
+ releaseId: releaseId ?? "",
44
+ channel: event.channel,
45
+ platform: event.platform,
46
+ appVersionKind: "specific",
47
+ appVersion: event.app_version,
48
+ periodKind: "latest",
49
+ bucketStartMs: hour(event.received_at_ms)
50
+ };
51
+ };
52
+ const insightsOverviewDeltas = (event) => {
53
+ const bucketStartMs = hour(event.received_at_ms);
54
+ const counters = /* @__PURE__ */ new Map();
55
+ const append = (identity, values) => {
56
+ const key = encodeIdentity(identity);
57
+ const previous = counters.get(key);
58
+ counters.set(key, {
59
+ identity,
60
+ downloads: (previous?.downloads ?? 0) + values.downloads,
61
+ launches: (previous?.launches ?? 0) + values.launches,
62
+ failedLaunches: (previous?.failedLaunches ?? 0) + values.failedLaunches,
63
+ launchIdentity: previous?.launchIdentity ?? values.launchIdentity,
64
+ activityIdentity: previous?.activityIdentity ?? values.activityIdentity
65
+ });
66
+ };
67
+ const metric = (releaseId, values) => {
68
+ const launchIdentity = values.launches > 0 ? event.install_id : void 0;
69
+ if (releaseId !== null) for (const [periodKind, start] of [["lifetime", 0], ["hour", bucketStartMs]]) append({
70
+ scopeKind: "release",
71
+ releaseKind: "specific",
72
+ releaseId,
73
+ channel: event.channel,
74
+ platform: event.platform,
75
+ appVersionKind: "all",
76
+ appVersion: "",
77
+ periodKind,
78
+ bucketStartMs: start
79
+ }, {
80
+ ...values,
81
+ ...periodKind === "hour" ? { launchIdentity } : {}
82
+ });
83
+ append({
84
+ scopeKind: "channel",
85
+ releaseKind: "all",
86
+ releaseId: "",
87
+ channel: event.channel,
88
+ platform: event.platform,
89
+ appVersionKind: "all",
90
+ appVersion: "",
91
+ periodKind: "hour",
92
+ bucketStartMs
93
+ }, {
94
+ ...values,
95
+ launchIdentity
96
+ });
97
+ };
98
+ if (event.type === "UPDATE_DOWNLOADED") metric(event.to_release_id, {
99
+ downloads: 1,
100
+ launches: 0,
101
+ failedLaunches: 0
102
+ });
103
+ else {
104
+ metric(event.to_release_id, {
105
+ downloads: 0,
106
+ launches: 1,
107
+ failedLaunches: 0
108
+ });
109
+ if (event.type === "RECOVERED") metric(event.from_release_id, {
110
+ downloads: 0,
111
+ launches: 0,
112
+ failedLaunches: 1
113
+ });
114
+ }
115
+ for (const platform of [event.platform, "all"]) for (const appVersionKind of ["specific", "all"]) append({
116
+ scopeKind: "usage",
117
+ releaseKind: "all",
118
+ releaseId: "",
119
+ channel: event.channel,
120
+ platform,
121
+ appVersionKind,
122
+ appVersion: appVersionKind === "specific" ? event.app_version : "",
123
+ periodKind: "hour",
124
+ bucketStartMs
125
+ }, {
126
+ downloads: 0,
127
+ launches: 0,
128
+ failedLaunches: 0,
129
+ activityIdentity: event.install_id
130
+ });
131
+ return [...counters.values()];
132
+ };
133
+ //#endregion
134
+ exports.currentInsightsReleaseId = currentInsightsReleaseId;
135
+ exports.insightsDistributionIdentity = insightsDistributionIdentity;
136
+ exports.insightsKey = insightsKey;
137
+ exports.insightsOverviewDeltas = insightsOverviewDeltas;
138
+ exports.insightsOverviewId = insightsOverviewId;
139
+ exports.insightsOverviewValues = insightsOverviewValues;
@@ -0,0 +1,42 @@
1
+ import { BundleEventRow } from "./types/databaseRows.cjs";
2
+ import "./types/internal.cjs";
3
+ //#region src/insightsOverview.d.ts
4
+ type InsightsOverviewIdentity = {
5
+ readonly scopeKind: "release" | "channel" | "usage" | "distribution";
6
+ readonly releaseKind: "all" | "specific" | "embedded";
7
+ readonly releaseId: string;
8
+ readonly channel: string;
9
+ readonly platform: "all" | "ios" | "android";
10
+ readonly appVersionKind: "all" | "specific";
11
+ readonly appVersion: string;
12
+ readonly periodKind: "lifetime" | "hour" | "latest";
13
+ readonly bucketStartMs: number;
14
+ };
15
+ type InsightsOverviewDelta = {
16
+ readonly identity: InsightsOverviewIdentity;
17
+ readonly downloads: number;
18
+ readonly launches: number;
19
+ readonly failedLaunches: number;
20
+ readonly launchIdentity?: string;
21
+ readonly activityIdentity?: string;
22
+ };
23
+ /** A 128-bit hex key for a string: two FNV-1a 64 hashes with different seeds. */
24
+ declare const insightsKey: (value: string) => string;
25
+ declare const insightsOverviewId: (identity: InsightsOverviewIdentity) => string;
26
+ declare const insightsOverviewValues: (identity: InsightsOverviewIdentity) => {
27
+ id: string;
28
+ scope_kind: "release" | "channel" | "usage" | "distribution";
29
+ release_kind: "all" | "specific" | "embedded";
30
+ release_id: string;
31
+ channel: string;
32
+ platform: "all" | "ios" | "android";
33
+ app_version_kind: "all" | "specific";
34
+ app_version: string;
35
+ period_kind: "lifetime" | "hour" | "latest";
36
+ bucket_start_ms: number;
37
+ };
38
+ declare const currentInsightsReleaseId: (event: BundleEventRow) => string | null;
39
+ declare const insightsDistributionIdentity: (event: BundleEventRow) => InsightsOverviewIdentity;
40
+ declare const insightsOverviewDeltas: (event: BundleEventRow) => readonly InsightsOverviewDelta[];
41
+ //#endregion
42
+ export { InsightsOverviewDelta, InsightsOverviewIdentity, currentInsightsReleaseId, insightsDistributionIdentity, insightsKey, insightsOverviewDeltas, insightsOverviewId, insightsOverviewValues };
@@ -0,0 +1,42 @@
1
+ import { BundleEventRow } from "./types/databaseRows.mjs";
2
+ import "./types/internal.mjs";
3
+ //#region src/insightsOverview.d.ts
4
+ type InsightsOverviewIdentity = {
5
+ readonly scopeKind: "release" | "channel" | "usage" | "distribution";
6
+ readonly releaseKind: "all" | "specific" | "embedded";
7
+ readonly releaseId: string;
8
+ readonly channel: string;
9
+ readonly platform: "all" | "ios" | "android";
10
+ readonly appVersionKind: "all" | "specific";
11
+ readonly appVersion: string;
12
+ readonly periodKind: "lifetime" | "hour" | "latest";
13
+ readonly bucketStartMs: number;
14
+ };
15
+ type InsightsOverviewDelta = {
16
+ readonly identity: InsightsOverviewIdentity;
17
+ readonly downloads: number;
18
+ readonly launches: number;
19
+ readonly failedLaunches: number;
20
+ readonly launchIdentity?: string;
21
+ readonly activityIdentity?: string;
22
+ };
23
+ /** A 128-bit hex key for a string: two FNV-1a 64 hashes with different seeds. */
24
+ declare const insightsKey: (value: string) => string;
25
+ declare const insightsOverviewId: (identity: InsightsOverviewIdentity) => string;
26
+ declare const insightsOverviewValues: (identity: InsightsOverviewIdentity) => {
27
+ id: string;
28
+ scope_kind: "release" | "channel" | "usage" | "distribution";
29
+ release_kind: "all" | "specific" | "embedded";
30
+ release_id: string;
31
+ channel: string;
32
+ platform: "all" | "ios" | "android";
33
+ app_version_kind: "all" | "specific";
34
+ app_version: string;
35
+ period_kind: "lifetime" | "hour" | "latest";
36
+ bucket_start_ms: number;
37
+ };
38
+ declare const currentInsightsReleaseId: (event: BundleEventRow) => string | null;
39
+ declare const insightsDistributionIdentity: (event: BundleEventRow) => InsightsOverviewIdentity;
40
+ declare const insightsOverviewDeltas: (event: BundleEventRow) => readonly InsightsOverviewDelta[];
41
+ //#endregion
42
+ export { InsightsOverviewDelta, InsightsOverviewIdentity, currentInsightsReleaseId, insightsDistributionIdentity, insightsKey, insightsOverviewDeltas, insightsOverviewId, insightsOverviewValues };
@@ -0,0 +1,134 @@
1
+ //#region src/insightsOverview.ts
2
+ const encodeIdentity = (identity) => [
3
+ identity.scopeKind,
4
+ identity.releaseKind,
5
+ identity.releaseId,
6
+ identity.channel,
7
+ identity.platform,
8
+ identity.appVersionKind,
9
+ identity.appVersion,
10
+ identity.periodKind,
11
+ String(identity.bucketStartMs)
12
+ ].map((value) => `${new TextEncoder().encode(value).length}:${value}`).join("");
13
+ const fnv = (value, seed) => {
14
+ let result = seed;
15
+ for (const byte of new TextEncoder().encode(value)) {
16
+ result ^= BigInt(byte);
17
+ result = BigInt.asUintN(64, result * 1099511628211n);
18
+ }
19
+ return result.toString(16).padStart(16, "0");
20
+ };
21
+ /** A 128-bit hex key for a string: two FNV-1a 64 hashes with different seeds. */
22
+ const insightsKey = (value) => `${fnv(value, 14695981039346656037n)}${fnv(value, 9521211207457086692n)}`;
23
+ const insightsOverviewId = (identity) => insightsKey(encodeIdentity(identity));
24
+ const insightsOverviewValues = (identity) => ({
25
+ id: insightsOverviewId(identity),
26
+ scope_kind: identity.scopeKind,
27
+ release_kind: identity.releaseKind,
28
+ release_id: identity.releaseId,
29
+ channel: identity.channel,
30
+ platform: identity.platform,
31
+ app_version_kind: identity.appVersionKind,
32
+ app_version: identity.appVersion,
33
+ period_kind: identity.periodKind,
34
+ bucket_start_ms: identity.bucketStartMs
35
+ });
36
+ const hour = (value) => Math.floor(value / 36e5) * 36e5;
37
+ const currentInsightsReleaseId = (event) => event.type === "UPDATE_DOWNLOADED" ? event.from_release_id : event.to_release_id;
38
+ const insightsDistributionIdentity = (event) => {
39
+ const releaseId = currentInsightsReleaseId(event);
40
+ return {
41
+ scopeKind: "distribution",
42
+ releaseKind: releaseId === null ? "embedded" : "specific",
43
+ releaseId: releaseId ?? "",
44
+ channel: event.channel,
45
+ platform: event.platform,
46
+ appVersionKind: "specific",
47
+ appVersion: event.app_version,
48
+ periodKind: "latest",
49
+ bucketStartMs: hour(event.received_at_ms)
50
+ };
51
+ };
52
+ const insightsOverviewDeltas = (event) => {
53
+ const bucketStartMs = hour(event.received_at_ms);
54
+ const counters = /* @__PURE__ */ new Map();
55
+ const append = (identity, values) => {
56
+ const key = encodeIdentity(identity);
57
+ const previous = counters.get(key);
58
+ counters.set(key, {
59
+ identity,
60
+ downloads: (previous?.downloads ?? 0) + values.downloads,
61
+ launches: (previous?.launches ?? 0) + values.launches,
62
+ failedLaunches: (previous?.failedLaunches ?? 0) + values.failedLaunches,
63
+ launchIdentity: previous?.launchIdentity ?? values.launchIdentity,
64
+ activityIdentity: previous?.activityIdentity ?? values.activityIdentity
65
+ });
66
+ };
67
+ const metric = (releaseId, values) => {
68
+ const launchIdentity = values.launches > 0 ? event.install_id : void 0;
69
+ if (releaseId !== null) for (const [periodKind, start] of [["lifetime", 0], ["hour", bucketStartMs]]) append({
70
+ scopeKind: "release",
71
+ releaseKind: "specific",
72
+ releaseId,
73
+ channel: event.channel,
74
+ platform: event.platform,
75
+ appVersionKind: "all",
76
+ appVersion: "",
77
+ periodKind,
78
+ bucketStartMs: start
79
+ }, {
80
+ ...values,
81
+ ...periodKind === "hour" ? { launchIdentity } : {}
82
+ });
83
+ append({
84
+ scopeKind: "channel",
85
+ releaseKind: "all",
86
+ releaseId: "",
87
+ channel: event.channel,
88
+ platform: event.platform,
89
+ appVersionKind: "all",
90
+ appVersion: "",
91
+ periodKind: "hour",
92
+ bucketStartMs
93
+ }, {
94
+ ...values,
95
+ launchIdentity
96
+ });
97
+ };
98
+ if (event.type === "UPDATE_DOWNLOADED") metric(event.to_release_id, {
99
+ downloads: 1,
100
+ launches: 0,
101
+ failedLaunches: 0
102
+ });
103
+ else {
104
+ metric(event.to_release_id, {
105
+ downloads: 0,
106
+ launches: 1,
107
+ failedLaunches: 0
108
+ });
109
+ if (event.type === "RECOVERED") metric(event.from_release_id, {
110
+ downloads: 0,
111
+ launches: 0,
112
+ failedLaunches: 1
113
+ });
114
+ }
115
+ for (const platform of [event.platform, "all"]) for (const appVersionKind of ["specific", "all"]) append({
116
+ scopeKind: "usage",
117
+ releaseKind: "all",
118
+ releaseId: "",
119
+ channel: event.channel,
120
+ platform,
121
+ appVersionKind,
122
+ appVersion: appVersionKind === "specific" ? event.app_version : "",
123
+ periodKind: "hour",
124
+ bucketStartMs
125
+ }, {
126
+ downloads: 0,
127
+ launches: 0,
128
+ failedLaunches: 0,
129
+ activityIdentity: event.install_id
130
+ });
131
+ return [...counters.values()];
132
+ };
133
+ //#endregion
134
+ export { currentInsightsReleaseId, insightsDistributionIdentity, insightsKey, insightsOverviewDeltas, insightsOverviewId, insightsOverviewValues };
package/dist/internal.cjs CHANGED
@@ -1,9 +1,45 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_databaseFields = require("./types/databaseFields.cjs");
3
- const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
4
- const require_insightsLatestQueries = require("./insightsLatestQueries.cjs");
5
- exports.DatabaseRowReferencedError = require_createDatabasePlugin.DatabaseRowReferencedError;
6
- exports.createDatabasePluginAdapter = require_createDatabasePlugin.createDatabasePluginAdapter;
7
- exports.databaseFields = require_databaseFields.databaseFields;
8
- exports.latestInsightsCountGroups = require_insightsLatestQueries.latestInsightsCountGroups;
9
- exports.latestInsightsWhere = require_insightsLatestQueries.latestInsightsWhere;
2
+ const require_databaseErrors = require("./databaseErrors.cjs");
3
+ const require_insightsContract = require("./insightsContract.cjs");
4
+ const require_insightsDistinctSummary = require("./insightsDistinctSummary.cjs");
5
+ const require_insightsOverview = require("./insightsOverview.cjs");
6
+ const require_adapter = require("./database/adapter.cjs");
7
+ const require_values = require("./database/values.cjs");
8
+ const require_memoryAdapter = require("./database/memoryAdapter.cjs");
9
+ const require_verifyAdapter = require("./database/verifyAdapter.cjs");
10
+ exports.DATABASE_MAX_MULTI_VALUES = require_adapter.DATABASE_MAX_MULTI_VALUES;
11
+ exports.DATABASE_MAX_QUERY_LIMIT = require_adapter.DATABASE_MAX_QUERY_LIMIT;
12
+ exports.DATABASE_VERSION_COLUMN = require_adapter.DATABASE_VERSION_COLUMN;
13
+ exports.DatabaseAdapterContractError = require_verifyAdapter.DatabaseAdapterContractError;
14
+ exports.DatabaseRowReferencedError = require_databaseErrors.DatabaseRowReferencedError;
15
+ exports.DatabaseSchemaError = require_adapter.DatabaseSchemaError;
16
+ exports.DatabaseValueError = require_values.DatabaseValueError;
17
+ exports.addInsightsDistinct = require_insightsDistinctSummary.addInsightsDistinct;
18
+ exports.assertBundleEventRow = require_insightsContract.assertBundleEventRow;
19
+ exports.canonicalJson = require_values.canonicalJson;
20
+ exports.compareKeyValues = require_values.compareKeyValues;
21
+ exports.compareTuples = require_values.compareTuples;
22
+ exports.compareUtf8 = require_values.compareUtf8;
23
+ exports.countInsightsDistinct = require_insightsDistinctSummary.countInsightsDistinct;
24
+ exports.createMemoryAdapter = require_memoryAdapter.createMemoryAdapter;
25
+ exports.createValidatedInsightsModel = require_insightsContract.createValidatedInsightsModel;
26
+ exports.currentInsightsReleaseId = require_insightsOverview.currentInsightsReleaseId;
27
+ exports.emptyInsightsDistinct = require_insightsDistinctSummary.emptyInsightsDistinct;
28
+ exports.findPhysicalColumn = require_adapter.findPhysicalColumn;
29
+ exports.findPhysicalIndex = require_adapter.findPhysicalIndex;
30
+ exports.getInsightsDistinctRegister = require_insightsDistinctSummary.getInsightsDistinctRegister;
31
+ exports.indexEntries = require_values.indexEntries;
32
+ exports.indexOrderColumns = require_adapter.indexOrderColumns;
33
+ exports.indexOrderTuple = require_values.indexOrderTuple;
34
+ exports.insightsDistributionIdentity = require_insightsOverview.insightsDistributionIdentity;
35
+ exports.insightsKey = require_insightsOverview.insightsKey;
36
+ exports.insightsOverviewDeltas = require_insightsOverview.insightsOverviewDeltas;
37
+ exports.insightsOverviewId = require_insightsOverview.insightsOverviewId;
38
+ exports.insightsOverviewValues = require_insightsOverview.insightsOverviewValues;
39
+ exports.isKeyValue = require_values.isKeyValue;
40
+ exports.matchesQuery = require_values.matchesQuery;
41
+ exports.mergeInsightsDistinct = require_insightsDistinctSummary.mergeInsightsDistinct;
42
+ exports.normalizeStoredRow = require_values.normalizeStoredRow;
43
+ exports.normalizeStoredValue = require_values.normalizeStoredValue;
44
+ exports.rowKey = require_adapter.rowKey;
45
+ exports.verifyAdapter = require_verifyAdapter.verifyAdapter;