@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,97 +0,0 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
- import { isBooleanField, isNumberField, isRecord, isStringField, modelValidators, sortableFields, validateField, validateFields } from "./databasePluginCrudValidationFields.mjs";
3
- //#region src/databasePluginCrudValidationQueries.ts
4
- const validateSelect = (model, select) => {
5
- if (select === void 0) return;
6
- if (!Array.isArray(select) || select.length === 0) throw new DatabasePluginInputError("empty-select");
7
- if (!select.every((field) => typeof field === "string")) throw new DatabasePluginInputError("invalid-query");
8
- validateFields(model, select);
9
- };
10
- const validateWhereValue = (model, condition) => {
11
- const field = condition.field;
12
- if (typeof field !== "string") throw new DatabasePluginInputError("invalid-query");
13
- validateField(model, field);
14
- const operator = condition.operator ?? "eq";
15
- const value = condition.value;
16
- const mode = condition.mode;
17
- if (mode !== void 0 && mode !== "sensitive" && mode !== "insensitive") throw new DatabasePluginInputError("invalid-query");
18
- switch (operator) {
19
- case "eq":
20
- case "ne":
21
- if (!(isStringField(field) || isNumberField(field) || isBooleanField(field)) || !modelValidators[model][field]?.(value) || mode !== void 0 && (!isStringField(field) || typeof value !== "string")) throw new DatabasePluginInputError("invalid-query");
22
- return;
23
- case "gt":
24
- case "gte":
25
- case "lt":
26
- case "lte":
27
- if (mode !== void 0 || !(isStringField(field) || isNumberField(field)) || value === null || !modelValidators[model][field]?.(value)) throw new DatabasePluginInputError("invalid-query");
28
- return;
29
- case "in":
30
- case "not_in":
31
- if (!Array.isArray(value) || mode !== void 0) throw new DatabasePluginInputError("invalid-query");
32
- if (!(isStringField(field) || isNumberField(field) || isBooleanField(field))) throw new DatabasePluginInputError("invalid-query");
33
- if (!value.every((item) => modelValidators[model][field]?.(item))) throw new DatabasePluginInputError("invalid-query");
34
- return;
35
- case "contains":
36
- case "starts_with":
37
- case "ends_with":
38
- if (!isStringField(field) || typeof value !== "string" || !modelValidators[model][field]?.(value)) throw new DatabasePluginInputError("invalid-query");
39
- return;
40
- default: throw new DatabasePluginInputError("invalid-query");
41
- }
42
- };
43
- const validateWhere = (model, where) => {
44
- if (where === void 0) return;
45
- if (!Array.isArray(where)) throw new DatabasePluginInputError("invalid-query");
46
- for (const item of where) {
47
- if (!isRecord(item)) throw new DatabasePluginInputError("invalid-query");
48
- if (item.connector !== void 0 && item.connector !== "AND" && item.connector !== "OR") throw new DatabasePluginInputError("invalid-query");
49
- validateWhereValue(model, item);
50
- }
51
- };
52
- const validateDistinctFields = (model, fields) => {
53
- if (fields === void 0) return void 0;
54
- if (!Array.isArray(fields) || fields.length === 0) throw new DatabasePluginInputError("invalid-distinct");
55
- if (!fields.every((field) => typeof field === "string")) throw new DatabasePluginInputError("invalid-distinct");
56
- validateFields(model, fields);
57
- return fields;
58
- };
59
- const validateOrderBy = (model, orderBy) => {
60
- if (orderBy === void 0) return void 0;
61
- if (!Array.isArray(orderBy) || orderBy.length === 0) throw new DatabasePluginInputError("invalid-query");
62
- const fields = /* @__PURE__ */ new Set();
63
- return orderBy.map((clause) => {
64
- if (!isRecord(clause) || typeof clause.field !== "string") throw new DatabasePluginInputError("invalid-query");
65
- validateField(model, clause.field);
66
- if (!sortableFields[model].has(clause.field)) throw new DatabasePluginInputError("invalid-query");
67
- if (clause.direction !== "asc" && clause.direction !== "desc") throw new DatabasePluginInputError("invalid-query");
68
- if (clause.nulls !== void 0 && clause.nulls !== "first" && clause.nulls !== "last") throw new DatabasePluginInputError("invalid-query");
69
- if (fields.has(clause.field)) throw new DatabasePluginInputError("invalid-operation");
70
- fields.add(clause.field);
71
- return clause;
72
- });
73
- };
74
- const validateDistinctOn = (model, distinctOn, orderBy) => {
75
- if (distinctOn === void 0) return;
76
- if (!isRecord(distinctOn)) throw new DatabasePluginInputError("invalid-distinct");
77
- const fields = validateDistinctFields(model, distinctOn.fields);
78
- if (fields === void 0 || orderBy === void 0) throw new DatabasePluginInputError("invalid-distinct");
79
- for (const [index, field] of fields.entries()) if (orderBy[index]?.field !== field) throw new DatabasePluginInputError("invalid-distinct");
80
- };
81
- const validatePagination = (limit, offset) => {
82
- const effectiveLimit = limit ?? 100;
83
- const effectiveOffset = offset ?? 0;
84
- if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0) || offset !== void 0 && (!Number.isSafeInteger(offset) || offset < 0) || !Number.isSafeInteger(effectiveOffset + effectiveLimit)) throw new DatabasePluginInputError("invalid-pagination");
85
- };
86
- const validateBundlePagination = (options) => {
87
- if (!Number.isSafeInteger(options.limit) || options.limit <= 0 || options.page !== void 0 && (!Number.isSafeInteger(options.page) || options.page <= 0) || options.page !== void 0 && options.cursor !== void 0) throw new DatabasePluginInputError("invalid-pagination");
88
- const cursor = options.cursor;
89
- if (cursor === void 0) return;
90
- if (!isRecord(cursor)) throw new DatabasePluginInputError("invalid-pagination");
91
- const hasAfter = Object.hasOwn(cursor, "after");
92
- if (hasAfter === Object.hasOwn(cursor, "before")) throw new DatabasePluginInputError("invalid-pagination");
93
- const value = hasAfter ? cursor.after : cursor.before;
94
- if (typeof value !== "string" || value.length === 0) throw new DatabasePluginInputError("invalid-pagination");
95
- };
96
- //#endregion
97
- export { validateBundlePagination, validateDistinctFields, validateDistinctOn, validateOrderBy, validatePagination, validateSelect, validateWhere };
@@ -1,55 +0,0 @@
1
- const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
2
- const require_databaseFields = require("./types/databaseFields.cjs");
3
- const require_databasePluginCrudValidationFields = require("./databasePluginCrudValidationFields.cjs");
4
- //#region src/databasePluginCrudValidationRows.ts
5
- const hasValidReleaseInvariants = (data) => {
6
- const kind = data.kind;
7
- const bundleId = data.bundle_id;
8
- const strategy = data.strategy;
9
- const targetAppVersion = data.target_app_version;
10
- const fingerprintHash = data.fingerprint_hash;
11
- return (kind === "BUNDLE" && typeof bundleId === "string" || kind === "EMBEDDED" && bundleId === null) && (strategy === "APP_VERSION" && typeof targetAppVersion === "string" && fingerprintHash === null || strategy === "FINGERPRINT" && targetAppVersion === null && typeof fingerprintHash === "string");
12
- };
13
- const hasValidBundleEventInvariants = (data) => (data.type === "UPDATE_DOWNLOADED" || data.type === "UPDATE_APPLIED" || data.type === "RECOVERED") && typeof data.from_bundle_id === "string" && ((require_databasePluginCrudValidationFields.isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === "fingerprint" || (require_databasePluginCrudValidationFields.isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === "appVersion") || data.type === "UNCHANGED" && data.from_bundle_id === null && (require_databasePluginCrudValidationFields.isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === null;
14
- const validateCreateData = (model, data) => {
15
- if (!require_databasePluginCrudValidationFields.isRecord(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
16
- require_databasePluginCrudValidationFields.validateFields(model, Object.keys(data));
17
- for (const field of require_databaseFields.databaseFields[model]) {
18
- const validator = require_databasePluginCrudValidationFields.modelValidators[model][field];
19
- if (!Object.hasOwn(data, field) || !validator || !validator(Reflect.get(data, field))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
20
- }
21
- if (model === "bundles" && data.target_app_version === null && data.fingerprint_hash === null) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
22
- if (model === "releases" && !hasValidReleaseInvariants(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
23
- if (model === "release_catalogs" && (data.strategy === "APP_VERSION" && data.fingerprint_hash !== null || data.strategy === "FINGERPRINT" && typeof data.fingerprint_hash !== "string")) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
24
- if (model === "bundle_events" && !hasValidBundleEventInvariants(data)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
25
- };
26
- const selectRow = (row, input) => {
27
- const { select } = input;
28
- if (!select) return row;
29
- return Object.fromEntries(select.map((field) => [field, Reflect.get(row, field)]));
30
- };
31
- const validateResult = (model, row, select) => {
32
- if (!require_databasePluginCrudValidationFields.isRecord(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
33
- const fields = select ?? require_databaseFields.databaseFields[model];
34
- for (const field of fields) {
35
- const validator = require_databasePluginCrudValidationFields.modelValidators[model][field];
36
- if (!Object.hasOwn(row, field) || !validator || !validator(Reflect.get(row, field))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
37
- }
38
- if (model === "bundles" && Object.hasOwn(row, "target_app_version") && Object.hasOwn(row, "fingerprint_hash") && Reflect.get(row, "target_app_version") === null && Reflect.get(row, "fingerprint_hash") === null) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
39
- if (model === "releases" && [
40
- "kind",
41
- "bundle_id",
42
- "strategy",
43
- "target_app_version",
44
- "fingerprint_hash"
45
- ].every((field) => Object.hasOwn(row, field)) && !hasValidReleaseInvariants(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
46
- if (model === "bundle_events" && [
47
- "type",
48
- "from_bundle_id",
49
- "metadata"
50
- ].every((field) => Object.hasOwn(row, field)) && !hasValidBundleEventInvariants(row)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
51
- };
52
- //#endregion
53
- exports.selectRow = selectRow;
54
- exports.validateCreateData = validateCreateData;
55
- exports.validateResult = validateResult;
@@ -1 +0,0 @@
1
- import "./types/internal.cjs";
@@ -1 +0,0 @@
1
- import "./types/internal.mjs";
@@ -1,53 +0,0 @@
1
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
2
- import { databaseFields } from "./types/databaseFields.mjs";
3
- import { isRecord, modelValidators, validateFields } from "./databasePluginCrudValidationFields.mjs";
4
- //#region src/databasePluginCrudValidationRows.ts
5
- const hasValidReleaseInvariants = (data) => {
6
- const kind = data.kind;
7
- const bundleId = data.bundle_id;
8
- const strategy = data.strategy;
9
- const targetAppVersion = data.target_app_version;
10
- const fingerprintHash = data.fingerprint_hash;
11
- return (kind === "BUNDLE" && typeof bundleId === "string" || kind === "EMBEDDED" && bundleId === null) && (strategy === "APP_VERSION" && typeof targetAppVersion === "string" && fingerprintHash === null || strategy === "FINGERPRINT" && targetAppVersion === null && typeof fingerprintHash === "string");
12
- };
13
- const hasValidBundleEventInvariants = (data) => (data.type === "UPDATE_DOWNLOADED" || data.type === "UPDATE_APPLIED" || data.type === "RECOVERED") && typeof data.from_bundle_id === "string" && ((isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === "fingerprint" || (isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === "appVersion") || data.type === "UNCHANGED" && data.from_bundle_id === null && (isRecord(data.metadata) ? data.metadata.update_strategy : void 0) === null;
14
- const validateCreateData = (model, data) => {
15
- if (!isRecord(data)) throw new DatabasePluginInputError("invalid-data");
16
- validateFields(model, Object.keys(data));
17
- for (const field of databaseFields[model]) {
18
- const validator = modelValidators[model][field];
19
- if (!Object.hasOwn(data, field) || !validator || !validator(Reflect.get(data, field))) throw new DatabasePluginInputError("invalid-data");
20
- }
21
- if (model === "bundles" && data.target_app_version === null && data.fingerprint_hash === null) throw new DatabasePluginInputError("invalid-data");
22
- if (model === "releases" && !hasValidReleaseInvariants(data)) throw new DatabasePluginInputError("invalid-data");
23
- if (model === "release_catalogs" && (data.strategy === "APP_VERSION" && data.fingerprint_hash !== null || data.strategy === "FINGERPRINT" && typeof data.fingerprint_hash !== "string")) throw new DatabasePluginInputError("invalid-data");
24
- if (model === "bundle_events" && !hasValidBundleEventInvariants(data)) throw new DatabasePluginInputError("invalid-data");
25
- };
26
- const selectRow = (row, input) => {
27
- const { select } = input;
28
- if (!select) return row;
29
- return Object.fromEntries(select.map((field) => [field, Reflect.get(row, field)]));
30
- };
31
- const validateResult = (model, row, select) => {
32
- if (!isRecord(row)) throw new DatabasePluginInputError("invalid-result");
33
- const fields = select ?? databaseFields[model];
34
- for (const field of fields) {
35
- const validator = modelValidators[model][field];
36
- if (!Object.hasOwn(row, field) || !validator || !validator(Reflect.get(row, field))) throw new DatabasePluginInputError("invalid-result");
37
- }
38
- if (model === "bundles" && Object.hasOwn(row, "target_app_version") && Object.hasOwn(row, "fingerprint_hash") && Reflect.get(row, "target_app_version") === null && Reflect.get(row, "fingerprint_hash") === null) throw new DatabasePluginInputError("invalid-result");
39
- if (model === "releases" && [
40
- "kind",
41
- "bundle_id",
42
- "strategy",
43
- "target_app_version",
44
- "fingerprint_hash"
45
- ].every((field) => Object.hasOwn(row, field)) && !hasValidReleaseInvariants(row)) throw new DatabasePluginInputError("invalid-result");
46
- if (model === "bundle_events" && [
47
- "type",
48
- "from_bundle_id",
49
- "metadata"
50
- ].every((field) => Object.hasOwn(row, field)) && !hasValidBundleEventInvariants(row)) throw new DatabasePluginInputError("invalid-result");
51
- };
52
- //#endregion
53
- export { selectRow, validateCreateData, validateResult };
@@ -1,7 +0,0 @@
1
- const require_databasePluginCrud = require("./databasePluginCrud.cjs");
2
- //#region src/databasePluginTransaction.ts
3
- const createTransactionDatabasePlugin = (implementation) => {
4
- return require_databasePluginCrud.createDatabasePluginCrud(implementation);
5
- };
6
- //#endregion
7
- exports.createTransactionDatabasePlugin = createTransactionDatabasePlugin;
@@ -1,7 +0,0 @@
1
- import { createDatabasePluginCrud } from "./databasePluginCrud.mjs";
2
- //#region src/databasePluginTransaction.ts
3
- const createTransactionDatabasePlugin = (implementation) => {
4
- return createDatabasePluginCrud(implementation);
5
- };
6
- //#endregion
7
- export { createTransactionDatabasePlugin };
@@ -1,53 +0,0 @@
1
- //#region src/insightsLatestQueries.ts
2
- /** Internal query translation for the bundled CRUD adapters. */
3
- const latestInsightsWhere = (input) => {
4
- if ("installId" in input) return [{
5
- field: "install_id",
6
- value: input.installId
7
- }];
8
- if ("userId" in input) return [{
9
- field: "user_id",
10
- value: input.userId
11
- }, ...input.afterInstallId === void 0 ? [] : [{
12
- field: "install_id",
13
- operator: "gt",
14
- value: input.afterInstallId
15
- }]];
16
- return [
17
- {
18
- field: "platform",
19
- value: input.platform
20
- },
21
- {
22
- field: "channel",
23
- value: input.channel
24
- },
25
- {
26
- field: "received_at_ms",
27
- operator: "gte",
28
- value: input.sinceMs
29
- },
30
- ...input.bundle === void 0 ? [] : [input.bundle.field === "from_bundle_id" ? {
31
- field: "from_bundle_id",
32
- value: input.bundle.value
33
- } : {
34
- field: "to_bundle_id",
35
- value: input.bundle.value
36
- }, {
37
- field: "type",
38
- operator: "in",
39
- value: input.bundle.types
40
- }]
41
- ];
42
- };
43
- /** OR groups for one latest-event count; an installation is counted once. */
44
- const latestInsightsCountGroups = (input) => input.bundle === void 0 ? [latestInsightsWhere({
45
- ...input,
46
- bundle: void 0
47
- })] : input.bundle.map((bundle) => latestInsightsWhere({
48
- ...input,
49
- bundle
50
- }));
51
- //#endregion
52
- exports.latestInsightsCountGroups = latestInsightsCountGroups;
53
- exports.latestInsightsWhere = latestInsightsWhere;
@@ -1,13 +0,0 @@
1
- import { InsightsCountLatestEventsInput, InsightsFindLatestEventsInput } from "./types/databasePlugin.cjs";
2
- import { DatabaseWhere } from "./types/databaseQuery.cjs";
3
- import "./types/index.cjs";
4
- import "./types/internal.cjs";
5
- //#region src/insightsLatestQueries.d.ts
6
- /** Internal query translation for the bundled CRUD adapters. */
7
- declare const latestInsightsWhere: (input: InsightsFindLatestEventsInput | (Omit<InsightsCountLatestEventsInput, "bundle"> & {
8
- bundle?: NonNullable<InsightsCountLatestEventsInput["bundle"]>[number];
9
- })) => readonly DatabaseWhere<"bundle_events">[];
10
- /** OR groups for one latest-event count; an installation is counted once. */
11
- declare const latestInsightsCountGroups: (input: InsightsCountLatestEventsInput) => readonly (readonly DatabaseWhere<"bundle_events">[])[];
12
- //#endregion
13
- export { latestInsightsCountGroups, latestInsightsWhere };
@@ -1,13 +0,0 @@
1
- import { InsightsCountLatestEventsInput, InsightsFindLatestEventsInput } from "./types/databasePlugin.mjs";
2
- import { DatabaseWhere } from "./types/databaseQuery.mjs";
3
- import "./types/index.mjs";
4
- import "./types/internal.mjs";
5
- //#region src/insightsLatestQueries.d.ts
6
- /** Internal query translation for the bundled CRUD adapters. */
7
- declare const latestInsightsWhere: (input: InsightsFindLatestEventsInput | (Omit<InsightsCountLatestEventsInput, "bundle"> & {
8
- bundle?: NonNullable<InsightsCountLatestEventsInput["bundle"]>[number];
9
- })) => readonly DatabaseWhere<"bundle_events">[];
10
- /** OR groups for one latest-event count; an installation is counted once. */
11
- declare const latestInsightsCountGroups: (input: InsightsCountLatestEventsInput) => readonly (readonly DatabaseWhere<"bundle_events">[])[];
12
- //#endregion
13
- export { latestInsightsCountGroups, latestInsightsWhere };
@@ -1,52 +0,0 @@
1
- //#region src/insightsLatestQueries.ts
2
- /** Internal query translation for the bundled CRUD adapters. */
3
- const latestInsightsWhere = (input) => {
4
- if ("installId" in input) return [{
5
- field: "install_id",
6
- value: input.installId
7
- }];
8
- if ("userId" in input) return [{
9
- field: "user_id",
10
- value: input.userId
11
- }, ...input.afterInstallId === void 0 ? [] : [{
12
- field: "install_id",
13
- operator: "gt",
14
- value: input.afterInstallId
15
- }]];
16
- return [
17
- {
18
- field: "platform",
19
- value: input.platform
20
- },
21
- {
22
- field: "channel",
23
- value: input.channel
24
- },
25
- {
26
- field: "received_at_ms",
27
- operator: "gte",
28
- value: input.sinceMs
29
- },
30
- ...input.bundle === void 0 ? [] : [input.bundle.field === "from_bundle_id" ? {
31
- field: "from_bundle_id",
32
- value: input.bundle.value
33
- } : {
34
- field: "to_bundle_id",
35
- value: input.bundle.value
36
- }, {
37
- field: "type",
38
- operator: "in",
39
- value: input.bundle.types
40
- }]
41
- ];
42
- };
43
- /** OR groups for one latest-event count; an installation is counted once. */
44
- const latestInsightsCountGroups = (input) => input.bundle === void 0 ? [latestInsightsWhere({
45
- ...input,
46
- bundle: void 0
47
- })] : input.bundle.map((bundle) => latestInsightsWhere({
48
- ...input,
49
- bundle
50
- }));
51
- //#endregion
52
- export { latestInsightsCountGroups, latestInsightsWhere };
@@ -1,53 +0,0 @@
1
- const require_calculatePagination = require("./calculatePagination.cjs");
2
- const require_queryBundles = require("./queryBundles.cjs");
3
- //#region src/paginateBundles.ts
4
- function paginateBundles({ bundles, limit, offset, cursor, orderBy }) {
5
- const sortedBundles = require_queryBundles.sortBundles(bundles, orderBy);
6
- const direction = orderBy?.direction ?? "desc";
7
- const total = sortedBundles.length;
8
- if (offset !== void 0) {
9
- const normalizedOffset = Math.max(0, offset);
10
- const data = limit > 0 ? sortedBundles.slice(normalizedOffset, normalizedOffset + limit) : sortedBundles.slice(normalizedOffset);
11
- const pagination = require_calculatePagination.calculatePagination(total, {
12
- limit,
13
- offset: normalizedOffset
14
- });
15
- const nextCursor = data.length > 0 && normalizedOffset + data.length < total ? data.at(-1)?.id : void 0;
16
- const previousCursor = data.length > 0 && normalizedOffset > 0 ? data[0]?.id : void 0;
17
- return {
18
- data,
19
- pagination: {
20
- ...pagination,
21
- ...nextCursor ? { nextCursor } : {},
22
- ...previousCursor ? { previousCursor } : {}
23
- }
24
- };
25
- }
26
- let data;
27
- if (cursor?.after) {
28
- const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.after) < 0 : bundle.id.localeCompare(cursor.after) > 0);
29
- data = limit > 0 ? candidates.slice(0, limit) : candidates;
30
- } else if (cursor?.before) {
31
- const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.before) > 0 : bundle.id.localeCompare(cursor.before) < 0);
32
- data = limit > 0 ? candidates.slice(Math.max(0, candidates.length - limit)) : candidates;
33
- } else data = limit > 0 ? sortedBundles.slice(0, limit) : sortedBundles;
34
- const startIndex = data.length > 0 ? sortedBundles.findIndex((bundle) => bundle.id === data[0].id) : cursor?.after ? total : 0;
35
- const pagination = require_calculatePagination.calculatePagination(total, {
36
- limit,
37
- offset: startIndex
38
- });
39
- const nextCursor = data.length > 0 && startIndex + data.length < total ? data.at(-1)?.id : void 0;
40
- const previousCursor = data.length > 0 && startIndex > 0 ? data[0]?.id : void 0;
41
- return {
42
- data,
43
- pagination: {
44
- ...pagination,
45
- ...nextCursor ? { nextCursor } : {},
46
- ...previousCursor ? { previousCursor } : {},
47
- ...data.length === 0 && cursor?.after ? { previousCursor: cursor.after } : {},
48
- ...data.length === 0 && cursor?.before ? { nextCursor: cursor.before } : {}
49
- }
50
- };
51
- }
52
- //#endregion
53
- exports.paginateBundles = paginateBundles;
@@ -1,13 +0,0 @@
1
- import { DatabaseBundleCursor, DatabaseBundleQueryOrder, Paginated } from "./types/index.cjs";
2
- //#region src/paginateBundles.d.ts
3
- declare function paginateBundles<TBundle extends {
4
- readonly id: string;
5
- }>({ bundles, limit, offset, cursor, orderBy }: {
6
- bundles: readonly TBundle[];
7
- limit: number;
8
- offset?: number;
9
- cursor?: DatabaseBundleCursor;
10
- orderBy?: DatabaseBundleQueryOrder;
11
- }): Paginated<TBundle[]>;
12
- //#endregion
13
- export { paginateBundles };
@@ -1,13 +0,0 @@
1
- import { DatabaseBundleCursor, DatabaseBundleQueryOrder, Paginated } from "./types/index.mjs";
2
- //#region src/paginateBundles.d.ts
3
- declare function paginateBundles<TBundle extends {
4
- readonly id: string;
5
- }>({ bundles, limit, offset, cursor, orderBy }: {
6
- bundles: readonly TBundle[];
7
- limit: number;
8
- offset?: number;
9
- cursor?: DatabaseBundleCursor;
10
- orderBy?: DatabaseBundleQueryOrder;
11
- }): Paginated<TBundle[]>;
12
- //#endregion
13
- export { paginateBundles };
@@ -1,53 +0,0 @@
1
- import { calculatePagination } from "./calculatePagination.mjs";
2
- import { sortBundles } from "./queryBundles.mjs";
3
- //#region src/paginateBundles.ts
4
- function paginateBundles({ bundles, limit, offset, cursor, orderBy }) {
5
- const sortedBundles = sortBundles(bundles, orderBy);
6
- const direction = orderBy?.direction ?? "desc";
7
- const total = sortedBundles.length;
8
- if (offset !== void 0) {
9
- const normalizedOffset = Math.max(0, offset);
10
- const data = limit > 0 ? sortedBundles.slice(normalizedOffset, normalizedOffset + limit) : sortedBundles.slice(normalizedOffset);
11
- const pagination = calculatePagination(total, {
12
- limit,
13
- offset: normalizedOffset
14
- });
15
- const nextCursor = data.length > 0 && normalizedOffset + data.length < total ? data.at(-1)?.id : void 0;
16
- const previousCursor = data.length > 0 && normalizedOffset > 0 ? data[0]?.id : void 0;
17
- return {
18
- data,
19
- pagination: {
20
- ...pagination,
21
- ...nextCursor ? { nextCursor } : {},
22
- ...previousCursor ? { previousCursor } : {}
23
- }
24
- };
25
- }
26
- let data;
27
- if (cursor?.after) {
28
- const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.after) < 0 : bundle.id.localeCompare(cursor.after) > 0);
29
- data = limit > 0 ? candidates.slice(0, limit) : candidates;
30
- } else if (cursor?.before) {
31
- const candidates = sortedBundles.filter((bundle) => direction === "desc" ? bundle.id.localeCompare(cursor.before) > 0 : bundle.id.localeCompare(cursor.before) < 0);
32
- data = limit > 0 ? candidates.slice(Math.max(0, candidates.length - limit)) : candidates;
33
- } else data = limit > 0 ? sortedBundles.slice(0, limit) : sortedBundles;
34
- const startIndex = data.length > 0 ? sortedBundles.findIndex((bundle) => bundle.id === data[0].id) : cursor?.after ? total : 0;
35
- const pagination = calculatePagination(total, {
36
- limit,
37
- offset: startIndex
38
- });
39
- const nextCursor = data.length > 0 && startIndex + data.length < total ? data.at(-1)?.id : void 0;
40
- const previousCursor = data.length > 0 && startIndex > 0 ? data[0]?.id : void 0;
41
- return {
42
- data,
43
- pagination: {
44
- ...pagination,
45
- ...nextCursor ? { nextCursor } : {},
46
- ...previousCursor ? { previousCursor } : {},
47
- ...data.length === 0 && cursor?.after ? { previousCursor: cursor.after } : {},
48
- ...data.length === 0 && cursor?.before ? { nextCursor: cursor.before } : {}
49
- }
50
- };
51
- }
52
- //#endregion
53
- export { paginateBundles };
@@ -1,34 +0,0 @@
1
- //#region src/queryBundles.ts
2
- const compareValue = (value, expected, comparator) => {
3
- if (expected === void 0) return true;
4
- switch (comparator) {
5
- case "eq": return value === expected;
6
- case "gt": return value.localeCompare(expected) > 0;
7
- case "gte": return value.localeCompare(expected) >= 0;
8
- case "lt": return value.localeCompare(expected) < 0;
9
- case "lte": return value.localeCompare(expected) <= 0;
10
- }
11
- };
12
- function bundleIdMatchesFilter(id, filter) {
13
- if (!filter) return true;
14
- if (filter.in && !filter.in.includes(id)) return false;
15
- return compareValue(id, filter.eq, "eq") && compareValue(id, filter.gt, "gt") && compareValue(id, filter.gte, "gte") && compareValue(id, filter.lt, "lt") && compareValue(id, filter.lte, "lte");
16
- }
17
- function bundleMatchesQueryWhere(bundle, where) {
18
- if (!where) return true;
19
- if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
20
- if (!bundleIdMatchesFilter(bundle.id, where.id)) return false;
21
- return true;
22
- }
23
- function sortBundles(bundles, orderBy) {
24
- const direction = orderBy?.direction ?? "desc";
25
- if (orderBy && orderBy.field !== "id") return [...bundles];
26
- return bundles.slice().sort((a, b) => {
27
- const result = a.id.localeCompare(b.id);
28
- return direction === "asc" ? result : -result;
29
- });
30
- }
31
- //#endregion
32
- exports.bundleIdMatchesFilter = bundleIdMatchesFilter;
33
- exports.bundleMatchesQueryWhere = bundleMatchesQueryWhere;
34
- exports.sortBundles = sortBundles;
@@ -1,9 +0,0 @@
1
- import { Bundle, DatabaseBundleIdFilter, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere } from "./types/index.cjs";
2
- //#region src/queryBundles.d.ts
3
- declare function bundleIdMatchesFilter(id: string, filter: DatabaseBundleIdFilter | undefined): boolean;
4
- declare function bundleMatchesQueryWhere(bundle: Bundle, where: DatabaseBundleQueryWhere | undefined): boolean;
5
- declare function sortBundles<TBundle extends {
6
- readonly id: string;
7
- }>(bundles: readonly TBundle[], orderBy: DatabaseBundleQueryOrder | undefined): TBundle[];
8
- //#endregion
9
- export { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles };
@@ -1,9 +0,0 @@
1
- import { Bundle, DatabaseBundleIdFilter, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere } from "./types/index.mjs";
2
- //#region src/queryBundles.d.ts
3
- declare function bundleIdMatchesFilter(id: string, filter: DatabaseBundleIdFilter | undefined): boolean;
4
- declare function bundleMatchesQueryWhere(bundle: Bundle, where: DatabaseBundleQueryWhere | undefined): boolean;
5
- declare function sortBundles<TBundle extends {
6
- readonly id: string;
7
- }>(bundles: readonly TBundle[], orderBy: DatabaseBundleQueryOrder | undefined): TBundle[];
8
- //#endregion
9
- export { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles };
@@ -1,32 +0,0 @@
1
- //#region src/queryBundles.ts
2
- const compareValue = (value, expected, comparator) => {
3
- if (expected === void 0) return true;
4
- switch (comparator) {
5
- case "eq": return value === expected;
6
- case "gt": return value.localeCompare(expected) > 0;
7
- case "gte": return value.localeCompare(expected) >= 0;
8
- case "lt": return value.localeCompare(expected) < 0;
9
- case "lte": return value.localeCompare(expected) <= 0;
10
- }
11
- };
12
- function bundleIdMatchesFilter(id, filter) {
13
- if (!filter) return true;
14
- if (filter.in && !filter.in.includes(id)) return false;
15
- return compareValue(id, filter.eq, "eq") && compareValue(id, filter.gt, "gt") && compareValue(id, filter.gte, "gte") && compareValue(id, filter.lt, "lt") && compareValue(id, filter.lte, "lte");
16
- }
17
- function bundleMatchesQueryWhere(bundle, where) {
18
- if (!where) return true;
19
- if (where.platform !== void 0 && bundle.platform !== where.platform) return false;
20
- if (!bundleIdMatchesFilter(bundle.id, where.id)) return false;
21
- return true;
22
- }
23
- function sortBundles(bundles, orderBy) {
24
- const direction = orderBy?.direction ?? "desc";
25
- if (orderBy && orderBy.field !== "id") return [...bundles];
26
- return bundles.slice().sort((a, b) => {
27
- const result = a.id.localeCompare(b.id);
28
- return direction === "asc" ? result : -result;
29
- });
30
- }
31
- //#endregion
32
- export { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles };
@@ -1,22 +0,0 @@
1
- //#region src/requestBundleCache.ts
2
- const createRequestBundleResolver = () => {
3
- const entries = /* @__PURE__ */ new Map();
4
- const pendingLoads = /* @__PURE__ */ new Map();
5
- return { async getById(bundleId, loadBundleById) {
6
- if (entries.has(bundleId)) return entries.get(bundleId) ?? null;
7
- const pending = pendingLoads.get(bundleId);
8
- if (pending) return pending;
9
- const load = loadBundleById().then((bundle) => {
10
- pendingLoads.delete(bundleId);
11
- if (!entries.has(bundleId)) entries.set(bundleId, bundle);
12
- return entries.get(bundleId) ?? null;
13
- }, (error) => {
14
- pendingLoads.delete(bundleId);
15
- throw error;
16
- });
17
- pendingLoads.set(bundleId, load);
18
- return load;
19
- } };
20
- };
21
- //#endregion
22
- exports.createRequestBundleResolver = createRequestBundleResolver;
@@ -1,8 +0,0 @@
1
- import { Bundle } from "./types/index.cjs";
2
- //#region src/requestBundleCache.d.ts
3
- interface RequestBundleResolver {
4
- readonly getById: (bundleId: string, loadBundleById: () => Promise<Bundle | null>) => Promise<Bundle | null>;
5
- }
6
- declare const createRequestBundleResolver: () => RequestBundleResolver;
7
- //#endregion
8
- export { RequestBundleResolver, createRequestBundleResolver };
@@ -1,8 +0,0 @@
1
- import { Bundle } from "./types/index.mjs";
2
- //#region src/requestBundleCache.d.ts
3
- interface RequestBundleResolver {
4
- readonly getById: (bundleId: string, loadBundleById: () => Promise<Bundle | null>) => Promise<Bundle | null>;
5
- }
6
- declare const createRequestBundleResolver: () => RequestBundleResolver;
7
- //#endregion
8
- export { RequestBundleResolver, createRequestBundleResolver };