@hot-updater/plugin-core 1.0.0-rc.15 → 1.0.0-rc.17
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.
- package/dist/coreApi.d.cts +131 -0
- package/dist/coreApi.d.mts +131 -0
- package/dist/database/adapter.cjs +46 -0
- package/dist/database/adapter.d.cts +183 -0
- package/dist/database/adapter.d.mts +183 -0
- package/dist/database/adapter.mjs +38 -0
- package/dist/{insightsDistinctSummary.mjs → database/distinct.cjs} +25 -11
- package/dist/database/distinct.d.cts +16 -0
- package/dist/database/distinct.d.mts +16 -0
- package/dist/{insightsDistinctSummary.cjs → database/distinct.mjs} +21 -15
- package/dist/database/memoryAdapter.cjs +115 -0
- package/dist/database/memoryAdapter.d.cts +16 -0
- package/dist/database/memoryAdapter.d.mts +16 -0
- package/dist/database/memoryAdapter.mjs +115 -0
- package/dist/database/values.cjs +110 -0
- package/dist/database/values.d.cts +30 -0
- package/dist/database/values.d.mts +30 -0
- package/dist/database/values.mjs +100 -0
- package/dist/database/verifyAdapter.cjs +136 -0
- package/dist/database/verifyAdapter.d.cts +29 -0
- package/dist/database/verifyAdapter.d.mts +29 -0
- package/dist/database/verifyAdapter.mjs +135 -0
- package/dist/databaseErrors.cjs +30 -0
- package/dist/databaseErrors.d.cts +21 -0
- package/dist/databaseErrors.d.mts +21 -0
- package/dist/databaseErrors.mjs +28 -0
- package/dist/databaseJsonValue.cjs +0 -2
- package/dist/databaseJsonValue.d.cts +3 -3
- package/dist/databaseJsonValue.d.mts +3 -3
- package/dist/databaseJsonValue.mjs +1 -2
- package/dist/databaseMetadata.cjs +2 -2
- package/dist/databaseMetadata.mjs +1 -1
- package/dist/index.cjs +9 -39
- package/dist/index.d.cts +13 -19
- package/dist/index.d.mts +13 -19
- package/dist/index.mjs +7 -14
- package/dist/internal.cjs +37 -20
- package/dist/internal.d.cts +11 -12
- package/dist/internal.d.mts +11 -12
- package/dist/internal.mjs +8 -6
- package/dist/releaseCatalogCompiler.cjs +1 -1
- package/dist/releaseCatalogCompiler.mjs +2 -2
- package/dist/releaseCatalogMutation.cjs +0 -292
- package/dist/releaseCatalogMutation.d.cts +4 -45
- package/dist/releaseCatalogMutation.d.mts +4 -45
- package/dist/releaseCatalogMutation.mjs +1 -288
- package/dist/releaseManagement.cjs +0 -221
- package/dist/releaseManagement.d.cts +4 -28
- package/dist/releaseManagement.d.mts +4 -28
- package/dist/releaseManagement.mjs +1 -216
- package/dist/types/databaseConfig.cjs +5 -0
- package/dist/types/databaseConfig.d.cts +61 -0
- package/dist/types/databaseConfig.d.mts +61 -0
- package/dist/types/databaseConfig.mjs +5 -0
- package/dist/types/databaseOperations.d.cts +5 -174
- package/dist/types/databaseOperations.d.mts +5 -174
- package/dist/types/databaseRows.d.cts +1 -53
- package/dist/types/databaseRows.d.mts +1 -53
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +8 -74
- package/dist/types/index.d.mts +8 -74
- package/dist/types/index.mjs +2 -1
- package/dist/types/internal.d.cts +4 -8
- package/dist/types/internal.d.mts +4 -8
- package/dist/types/models.d.cts +14 -0
- package/dist/types/models.d.mts +14 -0
- package/dist/types/public.d.cts +4 -3
- package/dist/types/public.d.mts +4 -3
- package/package.json +1 -1
- package/dist/calculatePagination.cjs +0 -25
- package/dist/calculatePagination.d.cts +0 -12
- package/dist/calculatePagination.d.mts +0 -12
- package/dist/calculatePagination.mjs +0 -25
- package/dist/createDatabasePlugin.cjs +0 -875
- package/dist/createDatabasePlugin.d.cts +0 -28
- package/dist/createDatabasePlugin.d.mts +0 -28
- package/dist/createDatabasePlugin.mjs +0 -871
- package/dist/databaseClient.cjs +0 -117
- package/dist/databaseClient.d.cts +0 -32
- package/dist/databaseClient.d.mts +0 -32
- package/dist/databaseClient.mjs +0 -114
- package/dist/databaseClientReads.cjs +0 -115
- package/dist/databaseClientReads.mjs +0 -113
- package/dist/databaseClientUpdates.cjs +0 -37
- package/dist/databaseClientUpdates.d.cts +0 -11
- package/dist/databaseClientUpdates.d.mts +0 -11
- package/dist/databaseClientUpdates.mjs +0 -35
- package/dist/databasePluginCrud.cjs +0 -87
- package/dist/databasePluginCrud.d.cts +0 -4
- package/dist/databasePluginCrud.d.mts +0 -4
- package/dist/databasePluginCrud.mjs +0 -86
- package/dist/databasePluginCrudValidation.d.cts +0 -6
- package/dist/databasePluginCrudValidation.d.mts +0 -6
- package/dist/databasePluginCrudValidationErrors.cjs +0 -11
- package/dist/databasePluginCrudValidationErrors.d.cts +0 -9
- package/dist/databasePluginCrudValidationErrors.d.mts +0 -9
- package/dist/databasePluginCrudValidationErrors.mjs +0 -11
- package/dist/databasePluginCrudValidationFields.cjs +0 -284
- package/dist/databasePluginCrudValidationFields.d.cts +0 -1
- package/dist/databasePluginCrudValidationFields.d.mts +0 -1
- package/dist/databasePluginCrudValidationFields.mjs +0 -272
- package/dist/databasePluginCrudValidationMutations.cjs +0 -88
- package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
- package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
- package/dist/databasePluginCrudValidationMutations.mjs +0 -82
- package/dist/databasePluginCrudValidationQueries.cjs +0 -103
- package/dist/databasePluginCrudValidationQueries.d.cts +0 -2
- package/dist/databasePluginCrudValidationQueries.d.mts +0 -2
- package/dist/databasePluginCrudValidationQueries.mjs +0 -97
- package/dist/databasePluginCrudValidationRows.cjs +0 -55
- package/dist/databasePluginCrudValidationRows.d.cts +0 -1
- package/dist/databasePluginCrudValidationRows.d.mts +0 -1
- package/dist/databasePluginCrudValidationRows.mjs +0 -53
- package/dist/databasePluginTransaction.cjs +0 -7
- package/dist/databasePluginTransaction.mjs +0 -7
- package/dist/insightsContract.cjs +0 -192
- package/dist/insightsContract.d.cts +0 -9
- package/dist/insightsContract.d.mts +0 -9
- package/dist/insightsContract.mjs +0 -189
- package/dist/insightsDistinctSummary.d.cts +0 -12
- package/dist/insightsDistinctSummary.d.mts +0 -12
- package/dist/insightsLatestQueries.cjs +0 -53
- package/dist/insightsLatestQueries.d.cts +0 -13
- package/dist/insightsLatestQueries.d.mts +0 -13
- package/dist/insightsLatestQueries.mjs +0 -52
- package/dist/insightsOverview.cjs +0 -139
- package/dist/insightsOverview.d.cts +0 -40
- package/dist/insightsOverview.d.mts +0 -40
- package/dist/insightsOverview.mjs +0 -135
- package/dist/paginateBundles.cjs +0 -53
- package/dist/paginateBundles.d.cts +0 -13
- package/dist/paginateBundles.d.mts +0 -13
- package/dist/paginateBundles.mjs +0 -53
- package/dist/queryBundles.cjs +0 -34
- package/dist/queryBundles.d.cts +0 -9
- package/dist/queryBundles.d.mts +0 -9
- package/dist/queryBundles.mjs +0 -32
- package/dist/requestBundleCache.cjs +0 -22
- package/dist/requestBundleCache.d.cts +0 -8
- package/dist/requestBundleCache.d.mts +0 -8
- package/dist/requestBundleCache.mjs +0 -22
- package/dist/types/database.d.cts +0 -5
- package/dist/types/database.d.mts +0 -5
- package/dist/types/databaseFields.cjs +0 -85
- package/dist/types/databaseFields.d.cts +0 -12
- package/dist/types/databaseFields.d.mts +0 -12
- package/dist/types/databaseFields.mjs +0 -85
- package/dist/types/databasePlugin.d.cts +0 -388
- package/dist/types/databasePlugin.d.mts +0 -388
- package/dist/types/databaseQuery.d.cts +0 -46
- 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,192 +0,0 @@
|
|
|
1
|
-
const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
|
|
2
|
-
const require_databasePluginCrudValidationFields = require("./databasePluginCrudValidationFields.cjs");
|
|
3
|
-
const require_databasePluginCrudValidationRows = require("./databasePluginCrudValidationRows.cjs");
|
|
4
|
-
let _hot_updater_core = require("@hot-updater/core");
|
|
5
|
-
//#region src/insightsContract.ts
|
|
6
|
-
const encoder = new TextEncoder();
|
|
7
|
-
/** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
|
|
8
|
-
const compareInsightsText = (left, right) => {
|
|
9
|
-
const a = encoder.encode(left);
|
|
10
|
-
const b = encoder.encode(right);
|
|
11
|
-
for (let index = 0; index < Math.min(a.length, b.length); index += 1) if (a[index] !== b[index]) return a[index] - b[index];
|
|
12
|
-
return a.length - b.length;
|
|
13
|
-
};
|
|
14
|
-
const isWellFormedText = (value) => {
|
|
15
|
-
for (const character of value) {
|
|
16
|
-
const point = character.codePointAt(0);
|
|
17
|
-
if (point >= 55296 && point <= 57343) return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
};
|
|
21
|
-
const isIdentity = (value) => typeof value === "string" && value.length > 0 && value.length <= 255 && isWellFormedText(value);
|
|
22
|
-
const isText = (value) => typeof value === "string" && value.length > 0 && isWellFormedText(value);
|
|
23
|
-
const isTimestamp = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
24
|
-
const isLimit = (value) => isTimestamp(value) && value >= 1 && value <= 101;
|
|
25
|
-
const hasOnlyKeys = (value, keys) => Object.keys(value).every((key) => keys.includes(key));
|
|
26
|
-
const hasScope = (value) => (value.platform === "ios" || value.platform === "android") && isText(value.channel);
|
|
27
|
-
const isBundleFilter = (value, withKind = false) => {
|
|
28
|
-
if (!require_databasePluginCrudValidationFields.isRecord(value) || !hasScope(value)) return false;
|
|
29
|
-
const keys = [
|
|
30
|
-
"platform",
|
|
31
|
-
"channel",
|
|
32
|
-
"type",
|
|
33
|
-
...withKind ? ["kind"] : []
|
|
34
|
-
];
|
|
35
|
-
return value.type === "RECOVERED" ? isText(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UNCHANGED") && isText(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
|
|
36
|
-
};
|
|
37
|
-
const isEventFilter = (value) => {
|
|
38
|
-
if (!require_databasePluginCrudValidationFields.isRecord(value)) return false;
|
|
39
|
-
if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
|
|
40
|
-
if (value.kind === "installationMovement") return isIdentity(value.installId) && hasOnlyKeys(value, ["kind", "installId"]);
|
|
41
|
-
return value.kind === "bundle" && isBundleFilter(value, true);
|
|
42
|
-
};
|
|
43
|
-
const validateRow = (model, row, result = false) => {
|
|
44
|
-
try {
|
|
45
|
-
require_databasePluginCrudValidationRows.validateCreateData(model, row);
|
|
46
|
-
if (!require_databasePluginCrudValidationFields.isRecord(row) || typeof row.id !== "string" || !(0, _hot_updater_core.isUUIDv7)(row.id) || [...Object.values(row), ...require_databasePluginCrudValidationFields.isRecord(row.metadata) ? Object.values(row.metadata) : []].some((value) => typeof value === "string" && !isWellFormedText(value))) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (result) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/** Downloads and applied transitions belong in installation history. */
|
|
53
|
-
const isInsightsMovementEvent = (event) => event.type === "UPDATE_DOWNLOADED" || event.type === "UPDATE_APPLIED" || event.type === "RECOVERED";
|
|
54
|
-
const matchesInsightsEventFilter = (event, filter) => {
|
|
55
|
-
if (filter.kind === "all") return true;
|
|
56
|
-
if (filter.kind === "installationMovement") return event.install_id === filter.installId && isInsightsMovementEvent(event);
|
|
57
|
-
return event.type === filter.type && event.platform === filter.platform && event.channel === filter.channel && (filter.type === "RECOVERED" ? event.from_bundle_id === filter.fromBundleId : event.to_bundle_id === filter.toBundleId);
|
|
58
|
-
};
|
|
59
|
-
const invalidQuery = () => {
|
|
60
|
-
throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-query");
|
|
61
|
-
};
|
|
62
|
-
const invalidResult = () => {
|
|
63
|
-
throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-result");
|
|
64
|
-
};
|
|
65
|
-
const validateCount = (count) => isTimestamp(count) ? count : invalidResult();
|
|
66
|
-
const isTimeRange = (value) => require_databasePluginCrudValidationFields.isRecord(value) && hasOnlyKeys(value, ["start", "end"]) && isTimestamp(value.start) && isTimestamp(value.end) && value.start < value.end;
|
|
67
|
-
const isReleaseReference = (value) => require_databasePluginCrudValidationFields.isRecord(value) && hasOnlyKeys(value, [
|
|
68
|
-
"releaseId",
|
|
69
|
-
"platform",
|
|
70
|
-
"channel"
|
|
71
|
-
]) && isIdentity(value.releaseId) && hasScope(value);
|
|
72
|
-
const validateAggregateResult = (value) => {
|
|
73
|
-
const result = require_databasePluginCrudValidationFields.isRecord(value) ? value : invalidResult();
|
|
74
|
-
if (!isTimestamp(result.measuredAtMs)) invalidResult();
|
|
75
|
-
const coverage = result.coverage;
|
|
76
|
-
if (!require_databasePluginCrudValidationFields.isRecord(coverage) || coverage.kind !== "complete" && coverage.kind !== "partial" || coverage.sinceMs !== null && !isTimestamp(coverage.sinceMs)) invalidResult();
|
|
77
|
-
};
|
|
78
|
-
/** Validate custom and bundled providers at the same public boundary. */
|
|
79
|
-
const createValidatedInsightsModel = (model) => ({
|
|
80
|
-
async recordEvent(input) {
|
|
81
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, ["event"])) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-data");
|
|
82
|
-
validateRow("bundle_events", input.event);
|
|
83
|
-
await model.recordEvent(input);
|
|
84
|
-
},
|
|
85
|
-
async listEvents(input) {
|
|
86
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
|
|
87
|
-
"filter",
|
|
88
|
-
"sinceMs",
|
|
89
|
-
"beforeReceivedAtMs",
|
|
90
|
-
"after",
|
|
91
|
-
"limit"
|
|
92
|
-
]) || !isEventFilter(input.filter) || !isLimit(input.limit) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs !== void 0 && !isTimestamp(input.sinceMs)) invalidQuery();
|
|
93
|
-
const sinceMs = input.sinceMs ?? 0;
|
|
94
|
-
if (sinceMs > input.beforeReceivedAtMs || input.after !== void 0 && (!require_databasePluginCrudValidationFields.isRecord(input.after) || !hasOnlyKeys(input.after, ["receivedAtMs", "id"]) || !isTimestamp(input.after.receivedAtMs) || typeof input.after.id !== "string" || !(0, _hot_updater_core.isUUIDv7)(input.after.id) || input.after.receivedAtMs < sinceMs || input.after.receivedAtMs >= input.beforeReceivedAtMs)) invalidQuery();
|
|
95
|
-
const rows = await model.listEvents(input);
|
|
96
|
-
if (!Array.isArray(rows) || rows.length > input.limit) invalidResult();
|
|
97
|
-
let previous = input.after;
|
|
98
|
-
for (const row of rows) {
|
|
99
|
-
validateRow("bundle_events", row, true);
|
|
100
|
-
if (row.received_at_ms < sinceMs || row.received_at_ms >= input.beforeReceivedAtMs || !matchesInsightsEventFilter(row, input.filter) || previous !== void 0 && (row.received_at_ms > previous.receivedAtMs || row.received_at_ms === previous.receivedAtMs && row.id >= previous.id)) invalidResult();
|
|
101
|
-
previous = {
|
|
102
|
-
receivedAtMs: row.received_at_ms,
|
|
103
|
-
id: row.id
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return rows;
|
|
107
|
-
},
|
|
108
|
-
async findLatestEvents(input) {
|
|
109
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input)) invalidQuery();
|
|
110
|
-
if ("installId" in input) {
|
|
111
|
-
if (!hasOnlyKeys(input, ["installId"]) || !isIdentity(input.installId)) invalidQuery();
|
|
112
|
-
} else if (!hasOnlyKeys(input, [
|
|
113
|
-
"userId",
|
|
114
|
-
"afterInstallId",
|
|
115
|
-
"limit"
|
|
116
|
-
]) || !isIdentity(input.userId) || !isLimit(input.limit) || input.afterInstallId !== void 0 && !isIdentity(input.afterInstallId)) invalidQuery();
|
|
117
|
-
const rows = await model.findLatestEvents(input);
|
|
118
|
-
if (!Array.isArray(rows) || rows.length > ("installId" in input ? 1 : input.limit)) invalidResult();
|
|
119
|
-
let previous = "installId" in input ? void 0 : input.afterInstallId;
|
|
120
|
-
for (const row of rows) {
|
|
121
|
-
validateRow("bundle_events", row, true);
|
|
122
|
-
if ("installId" in input ? row.install_id !== input.installId : row.user_id !== input.userId || previous !== void 0 && compareInsightsText(row.install_id, previous) <= 0) invalidResult();
|
|
123
|
-
previous = row.install_id;
|
|
124
|
-
}
|
|
125
|
-
return rows;
|
|
126
|
-
},
|
|
127
|
-
async countLatestEvents(input) {
|
|
128
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
|
|
129
|
-
"platform",
|
|
130
|
-
"channel",
|
|
131
|
-
"sinceMs",
|
|
132
|
-
"bundle"
|
|
133
|
-
]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundle !== void 0 && (!Array.isArray(input.bundle) || input.bundle.length < 1 || input.bundle.length > 2 || input.bundle.some((bundle) => !require_databasePluginCrudValidationFields.isRecord(bundle) || !hasOnlyKeys(bundle, [
|
|
134
|
-
"field",
|
|
135
|
-
"value",
|
|
136
|
-
"types"
|
|
137
|
-
]) || bundle.field !== "from_bundle_id" && bundle.field !== "to_bundle_id" || !isText(bundle.value) || !Array.isArray(bundle.types) || bundle.types.length === 0 || bundle.types.some((type) => ![
|
|
138
|
-
"UNCHANGED",
|
|
139
|
-
"UPDATE_DOWNLOADED",
|
|
140
|
-
"UPDATE_APPLIED",
|
|
141
|
-
"RECOVERED"
|
|
142
|
-
].includes(type))))) invalidQuery();
|
|
143
|
-
return validateCount(await model.countLatestEvents(input));
|
|
144
|
-
},
|
|
145
|
-
async countEvents(input) {
|
|
146
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
|
|
147
|
-
"filter",
|
|
148
|
-
"sinceMs",
|
|
149
|
-
"beforeReceivedAtMs"
|
|
150
|
-
]) || !isBundleFilter(input.filter) || !isTimestamp(input.sinceMs) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs > input.beforeReceivedAtMs) invalidQuery();
|
|
151
|
-
return validateCount(await model.countEvents(input));
|
|
152
|
-
},
|
|
153
|
-
async getReleaseActivity(input) {
|
|
154
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
|
|
155
|
-
"releases",
|
|
156
|
-
"scope",
|
|
157
|
-
"timeRange"
|
|
158
|
-
])) invalidQuery();
|
|
159
|
-
const releases = input.releases;
|
|
160
|
-
const scope = input.scope;
|
|
161
|
-
const timeRange = input.timeRange;
|
|
162
|
-
const releaseQuery = Array.isArray(releases) && releases.length > 0 && releases.length <= 100 && releases.every(isReleaseReference) && scope === void 0 && (timeRange === void 0 || isTimeRange(timeRange));
|
|
163
|
-
const scopeQuery = releases === void 0 && require_databasePluginCrudValidationFields.isRecord(scope) && hasOnlyKeys(scope, ["platform", "channel"]) && hasScope(scope) && isTimeRange(timeRange);
|
|
164
|
-
if (!releaseQuery && !scopeQuery) invalidQuery();
|
|
165
|
-
const result = await model.getReleaseActivity(input);
|
|
166
|
-
validateAggregateResult(result);
|
|
167
|
-
if (!Array.isArray(result.data)) invalidResult();
|
|
168
|
-
return result;
|
|
169
|
-
},
|
|
170
|
-
async getAppUsage(input) {
|
|
171
|
-
if (!require_databasePluginCrudValidationFields.isRecord(input) || !hasOnlyKeys(input, [
|
|
172
|
-
"channel",
|
|
173
|
-
"platform",
|
|
174
|
-
"appVersion",
|
|
175
|
-
"timeRange",
|
|
176
|
-
"intervalMs"
|
|
177
|
-
]) || !isText(input.channel) || ![
|
|
178
|
-
"all",
|
|
179
|
-
"ios",
|
|
180
|
-
"android"
|
|
181
|
-
].includes(input.platform) || input.appVersion !== void 0 && !isText(input.appVersion) || !isTimeRange(input.timeRange) || !isTimestamp(input.intervalMs) || input.intervalMs < 36e5) invalidQuery();
|
|
182
|
-
const result = await model.getAppUsage(input);
|
|
183
|
-
validateAggregateResult(result);
|
|
184
|
-
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();
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
//#endregion
|
|
189
|
-
exports.compareInsightsText = compareInsightsText;
|
|
190
|
-
exports.createValidatedInsightsModel = createValidatedInsightsModel;
|
|
191
|
-
exports.isInsightsMovementEvent = isInsightsMovementEvent;
|
|
192
|
-
exports.matchesInsightsEventFilter = matchesInsightsEventFilter;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BundleEventRow } from "./types/databaseRows.cjs";
|
|
2
|
-
import "./types/index.cjs";
|
|
3
|
-
//#region src/insightsContract.d.ts
|
|
4
|
-
/** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
|
|
5
|
-
declare const compareInsightsText: (left: string, right: string) => number;
|
|
6
|
-
/** Downloads and applied transitions belong in installation history. */
|
|
7
|
-
declare const isInsightsMovementEvent: (event: Pick<BundleEventRow, "type">) => boolean;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { compareInsightsText, isInsightsMovementEvent };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BundleEventRow } from "./types/databaseRows.mjs";
|
|
2
|
-
import "./types/index.mjs";
|
|
3
|
-
//#region src/insightsContract.d.ts
|
|
4
|
-
/** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
|
|
5
|
-
declare const compareInsightsText: (left: string, right: string) => number;
|
|
6
|
-
/** Downloads and applied transitions belong in installation history. */
|
|
7
|
-
declare const isInsightsMovementEvent: (event: Pick<BundleEventRow, "type">) => boolean;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { compareInsightsText, isInsightsMovementEvent };
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
|
|
2
|
-
import { isUUIDv7 } from "./uuidv7.mjs";
|
|
3
|
-
import { isRecord } from "./databasePluginCrudValidationFields.mjs";
|
|
4
|
-
import { validateCreateData } from "./databasePluginCrudValidationRows.mjs";
|
|
5
|
-
//#region src/insightsContract.ts
|
|
6
|
-
const encoder = new TextEncoder();
|
|
7
|
-
/** Exact UTF-8 byte ordering, without case folding or Unicode normalization. */
|
|
8
|
-
const compareInsightsText = (left, right) => {
|
|
9
|
-
const a = encoder.encode(left);
|
|
10
|
-
const b = encoder.encode(right);
|
|
11
|
-
for (let index = 0; index < Math.min(a.length, b.length); index += 1) if (a[index] !== b[index]) return a[index] - b[index];
|
|
12
|
-
return a.length - b.length;
|
|
13
|
-
};
|
|
14
|
-
const isWellFormedText = (value) => {
|
|
15
|
-
for (const character of value) {
|
|
16
|
-
const point = character.codePointAt(0);
|
|
17
|
-
if (point >= 55296 && point <= 57343) return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
};
|
|
21
|
-
const isIdentity = (value) => typeof value === "string" && value.length > 0 && value.length <= 255 && isWellFormedText(value);
|
|
22
|
-
const isText = (value) => typeof value === "string" && value.length > 0 && isWellFormedText(value);
|
|
23
|
-
const isTimestamp = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
24
|
-
const isLimit = (value) => isTimestamp(value) && value >= 1 && value <= 101;
|
|
25
|
-
const hasOnlyKeys = (value, keys) => Object.keys(value).every((key) => keys.includes(key));
|
|
26
|
-
const hasScope = (value) => (value.platform === "ios" || value.platform === "android") && isText(value.channel);
|
|
27
|
-
const isBundleFilter = (value, withKind = false) => {
|
|
28
|
-
if (!isRecord(value) || !hasScope(value)) return false;
|
|
29
|
-
const keys = [
|
|
30
|
-
"platform",
|
|
31
|
-
"channel",
|
|
32
|
-
"type",
|
|
33
|
-
...withKind ? ["kind"] : []
|
|
34
|
-
];
|
|
35
|
-
return value.type === "RECOVERED" ? isText(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UNCHANGED") && isText(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
|
|
36
|
-
};
|
|
37
|
-
const isEventFilter = (value) => {
|
|
38
|
-
if (!isRecord(value)) return false;
|
|
39
|
-
if (value.kind === "all") return hasOnlyKeys(value, ["kind"]);
|
|
40
|
-
if (value.kind === "installationMovement") return isIdentity(value.installId) && hasOnlyKeys(value, ["kind", "installId"]);
|
|
41
|
-
return value.kind === "bundle" && isBundleFilter(value, true);
|
|
42
|
-
};
|
|
43
|
-
const validateRow = (model, row, result = false) => {
|
|
44
|
-
try {
|
|
45
|
-
validateCreateData(model, row);
|
|
46
|
-
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
|
-
} catch (error) {
|
|
48
|
-
if (result) throw new DatabasePluginInputError("invalid-result");
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/** Downloads and applied transitions belong in installation history. */
|
|
53
|
-
const isInsightsMovementEvent = (event) => event.type === "UPDATE_DOWNLOADED" || event.type === "UPDATE_APPLIED" || event.type === "RECOVERED";
|
|
54
|
-
const matchesInsightsEventFilter = (event, filter) => {
|
|
55
|
-
if (filter.kind === "all") return true;
|
|
56
|
-
if (filter.kind === "installationMovement") return event.install_id === filter.installId && isInsightsMovementEvent(event);
|
|
57
|
-
return event.type === filter.type && event.platform === filter.platform && event.channel === filter.channel && (filter.type === "RECOVERED" ? event.from_bundle_id === filter.fromBundleId : event.to_bundle_id === filter.toBundleId);
|
|
58
|
-
};
|
|
59
|
-
const invalidQuery = () => {
|
|
60
|
-
throw new DatabasePluginInputError("invalid-query");
|
|
61
|
-
};
|
|
62
|
-
const invalidResult = () => {
|
|
63
|
-
throw new DatabasePluginInputError("invalid-result");
|
|
64
|
-
};
|
|
65
|
-
const validateCount = (count) => isTimestamp(count) ? count : invalidResult();
|
|
66
|
-
const isTimeRange = (value) => isRecord(value) && hasOnlyKeys(value, ["start", "end"]) && isTimestamp(value.start) && isTimestamp(value.end) && value.start < value.end;
|
|
67
|
-
const isReleaseReference = (value) => isRecord(value) && hasOnlyKeys(value, [
|
|
68
|
-
"releaseId",
|
|
69
|
-
"platform",
|
|
70
|
-
"channel"
|
|
71
|
-
]) && isIdentity(value.releaseId) && hasScope(value);
|
|
72
|
-
const validateAggregateResult = (value) => {
|
|
73
|
-
const result = isRecord(value) ? value : invalidResult();
|
|
74
|
-
if (!isTimestamp(result.measuredAtMs)) invalidResult();
|
|
75
|
-
const coverage = result.coverage;
|
|
76
|
-
if (!isRecord(coverage) || coverage.kind !== "complete" && coverage.kind !== "partial" || coverage.sinceMs !== null && !isTimestamp(coverage.sinceMs)) invalidResult();
|
|
77
|
-
};
|
|
78
|
-
/** Validate custom and bundled providers at the same public boundary. */
|
|
79
|
-
const createValidatedInsightsModel = (model) => ({
|
|
80
|
-
async recordEvent(input) {
|
|
81
|
-
if (!isRecord(input) || !hasOnlyKeys(input, ["event"])) throw new DatabasePluginInputError("invalid-data");
|
|
82
|
-
validateRow("bundle_events", input.event);
|
|
83
|
-
await model.recordEvent(input);
|
|
84
|
-
},
|
|
85
|
-
async listEvents(input) {
|
|
86
|
-
if (!isRecord(input) || !hasOnlyKeys(input, [
|
|
87
|
-
"filter",
|
|
88
|
-
"sinceMs",
|
|
89
|
-
"beforeReceivedAtMs",
|
|
90
|
-
"after",
|
|
91
|
-
"limit"
|
|
92
|
-
]) || !isEventFilter(input.filter) || !isLimit(input.limit) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs !== void 0 && !isTimestamp(input.sinceMs)) invalidQuery();
|
|
93
|
-
const sinceMs = input.sinceMs ?? 0;
|
|
94
|
-
if (sinceMs > input.beforeReceivedAtMs || input.after !== void 0 && (!isRecord(input.after) || !hasOnlyKeys(input.after, ["receivedAtMs", "id"]) || !isTimestamp(input.after.receivedAtMs) || typeof input.after.id !== "string" || !isUUIDv7(input.after.id) || input.after.receivedAtMs < sinceMs || input.after.receivedAtMs >= input.beforeReceivedAtMs)) invalidQuery();
|
|
95
|
-
const rows = await model.listEvents(input);
|
|
96
|
-
if (!Array.isArray(rows) || rows.length > input.limit) invalidResult();
|
|
97
|
-
let previous = input.after;
|
|
98
|
-
for (const row of rows) {
|
|
99
|
-
validateRow("bundle_events", row, true);
|
|
100
|
-
if (row.received_at_ms < sinceMs || row.received_at_ms >= input.beforeReceivedAtMs || !matchesInsightsEventFilter(row, input.filter) || previous !== void 0 && (row.received_at_ms > previous.receivedAtMs || row.received_at_ms === previous.receivedAtMs && row.id >= previous.id)) invalidResult();
|
|
101
|
-
previous = {
|
|
102
|
-
receivedAtMs: row.received_at_ms,
|
|
103
|
-
id: row.id
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return rows;
|
|
107
|
-
},
|
|
108
|
-
async findLatestEvents(input) {
|
|
109
|
-
if (!isRecord(input)) invalidQuery();
|
|
110
|
-
if ("installId" in input) {
|
|
111
|
-
if (!hasOnlyKeys(input, ["installId"]) || !isIdentity(input.installId)) invalidQuery();
|
|
112
|
-
} else if (!hasOnlyKeys(input, [
|
|
113
|
-
"userId",
|
|
114
|
-
"afterInstallId",
|
|
115
|
-
"limit"
|
|
116
|
-
]) || !isIdentity(input.userId) || !isLimit(input.limit) || input.afterInstallId !== void 0 && !isIdentity(input.afterInstallId)) invalidQuery();
|
|
117
|
-
const rows = await model.findLatestEvents(input);
|
|
118
|
-
if (!Array.isArray(rows) || rows.length > ("installId" in input ? 1 : input.limit)) invalidResult();
|
|
119
|
-
let previous = "installId" in input ? void 0 : input.afterInstallId;
|
|
120
|
-
for (const row of rows) {
|
|
121
|
-
validateRow("bundle_events", row, true);
|
|
122
|
-
if ("installId" in input ? row.install_id !== input.installId : row.user_id !== input.userId || previous !== void 0 && compareInsightsText(row.install_id, previous) <= 0) invalidResult();
|
|
123
|
-
previous = row.install_id;
|
|
124
|
-
}
|
|
125
|
-
return rows;
|
|
126
|
-
},
|
|
127
|
-
async countLatestEvents(input) {
|
|
128
|
-
if (!isRecord(input) || !hasOnlyKeys(input, [
|
|
129
|
-
"platform",
|
|
130
|
-
"channel",
|
|
131
|
-
"sinceMs",
|
|
132
|
-
"bundle"
|
|
133
|
-
]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundle !== void 0 && (!Array.isArray(input.bundle) || input.bundle.length < 1 || input.bundle.length > 2 || input.bundle.some((bundle) => !isRecord(bundle) || !hasOnlyKeys(bundle, [
|
|
134
|
-
"field",
|
|
135
|
-
"value",
|
|
136
|
-
"types"
|
|
137
|
-
]) || bundle.field !== "from_bundle_id" && bundle.field !== "to_bundle_id" || !isText(bundle.value) || !Array.isArray(bundle.types) || bundle.types.length === 0 || bundle.types.some((type) => ![
|
|
138
|
-
"UNCHANGED",
|
|
139
|
-
"UPDATE_DOWNLOADED",
|
|
140
|
-
"UPDATE_APPLIED",
|
|
141
|
-
"RECOVERED"
|
|
142
|
-
].includes(type))))) invalidQuery();
|
|
143
|
-
return validateCount(await model.countLatestEvents(input));
|
|
144
|
-
},
|
|
145
|
-
async countEvents(input) {
|
|
146
|
-
if (!isRecord(input) || !hasOnlyKeys(input, [
|
|
147
|
-
"filter",
|
|
148
|
-
"sinceMs",
|
|
149
|
-
"beforeReceivedAtMs"
|
|
150
|
-
]) || !isBundleFilter(input.filter) || !isTimestamp(input.sinceMs) || !isTimestamp(input.beforeReceivedAtMs) || input.sinceMs > input.beforeReceivedAtMs) invalidQuery();
|
|
151
|
-
return validateCount(await model.countEvents(input));
|
|
152
|
-
},
|
|
153
|
-
async getReleaseActivity(input) {
|
|
154
|
-
if (!isRecord(input) || !hasOnlyKeys(input, [
|
|
155
|
-
"releases",
|
|
156
|
-
"scope",
|
|
157
|
-
"timeRange"
|
|
158
|
-
])) invalidQuery();
|
|
159
|
-
const releases = input.releases;
|
|
160
|
-
const scope = input.scope;
|
|
161
|
-
const timeRange = input.timeRange;
|
|
162
|
-
const releaseQuery = Array.isArray(releases) && releases.length > 0 && releases.length <= 100 && releases.every(isReleaseReference) && scope === void 0 && (timeRange === void 0 || isTimeRange(timeRange));
|
|
163
|
-
const scopeQuery = releases === void 0 && isRecord(scope) && hasOnlyKeys(scope, ["platform", "channel"]) && hasScope(scope) && isTimeRange(timeRange);
|
|
164
|
-
if (!releaseQuery && !scopeQuery) invalidQuery();
|
|
165
|
-
const result = await model.getReleaseActivity(input);
|
|
166
|
-
validateAggregateResult(result);
|
|
167
|
-
if (!Array.isArray(result.data)) invalidResult();
|
|
168
|
-
return result;
|
|
169
|
-
},
|
|
170
|
-
async getAppUsage(input) {
|
|
171
|
-
if (!isRecord(input) || !hasOnlyKeys(input, [
|
|
172
|
-
"channel",
|
|
173
|
-
"platform",
|
|
174
|
-
"appVersion",
|
|
175
|
-
"timeRange",
|
|
176
|
-
"intervalMs"
|
|
177
|
-
]) || !isText(input.channel) || ![
|
|
178
|
-
"all",
|
|
179
|
-
"ios",
|
|
180
|
-
"android"
|
|
181
|
-
].includes(input.platform) || input.appVersion !== void 0 && !isText(input.appVersion) || !isTimeRange(input.timeRange) || !isTimestamp(input.intervalMs) || input.intervalMs < 36e5) invalidQuery();
|
|
182
|
-
const result = await model.getAppUsage(input);
|
|
183
|
-
validateAggregateResult(result);
|
|
184
|
-
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();
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
//#endregion
|
|
189
|
-
export { compareInsightsText, createValidatedInsightsModel, isInsightsMovementEvent, matchesInsightsEventFilter };
|