@oneuptime/common 14.0.102 → 14.0.103

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 (208) hide show
  1. package/Models/DatabaseModels/Index.js +6 -0
  2. package/Models/DatabaseModels/LogSavedView.d.mts +1 -0
  3. package/Models/DatabaseModels/LogSavedView.d.ts +1 -0
  4. package/Models/DatabaseModels/LogSavedView.js +43 -1
  5. package/Models/DatabaseModels/NetworkControllerConnection.d.mts +1 -0
  6. package/Models/DatabaseModels/NetworkControllerConnection.d.ts +1 -0
  7. package/Models/DatabaseModels/NetworkControllerConnection.js +21 -0
  8. package/Models/DatabaseModels/Project.d.mts +3 -0
  9. package/Models/DatabaseModels/Project.d.ts +3 -0
  10. package/Models/DatabaseModels/Project.js +124 -0
  11. package/Models/DatabaseModels/Runner.d.mts +1 -0
  12. package/Models/DatabaseModels/Runner.d.ts +1 -0
  13. package/Models/DatabaseModels/Runner.js +40 -0
  14. package/Models/DatabaseModels/SecurityCase.d.mts +2 -1
  15. package/Models/DatabaseModels/SecurityCase.d.ts +2 -1
  16. package/Models/DatabaseModels/SecurityCase.js +27 -0
  17. package/Models/DatabaseModels/SecurityCaseCustomField.d.mts +20 -0
  18. package/Models/DatabaseModels/SecurityCaseCustomField.d.ts +20 -0
  19. package/Models/DatabaseModels/SecurityCaseCustomField.js +387 -0
  20. package/Models/DatabaseModels/SecurityCaseCustomField.mjs +2 -0
  21. package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.mts +15 -0
  22. package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.ts +15 -0
  23. package/Models/DatabaseModels/SecurityCaseNoteTemplate.js +309 -0
  24. package/Models/DatabaseModels/SecurityCaseNoteTemplate.mjs +2 -0
  25. package/Models/DatabaseModels/WorkspaceHomeChoice.d.mts +11 -0
  26. package/Models/DatabaseModels/WorkspaceHomeChoice.d.ts +11 -0
  27. package/Models/DatabaseModels/WorkspaceHomeChoice.js +186 -0
  28. package/Models/DatabaseModels/WorkspaceHomeChoice.mjs +2 -0
  29. package/Types/AI/AIFixReadiness.d.mts +2 -0
  30. package/Types/AI/AIFixReadiness.d.ts +2 -0
  31. package/Types/AI/AIFixReadiness.js +0 -6
  32. package/Types/AI/CodeTask.d.mts +3 -1
  33. package/Types/AI/CodeTask.d.ts +3 -1
  34. package/Types/AI/CodeTask.js +12 -0
  35. package/Types/CustomField/CustomFieldRecordKinds.js +5 -0
  36. package/Types/CustomField/CustomFieldSavedViews.js +2 -0
  37. package/Types/DateLanguage.js +3 -2
  38. package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.mts +1 -0
  39. package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.ts +1 -0
  40. package/Types/DockerSwarm/DockerSwarmInventoryExtractor.js +84 -6
  41. package/Types/DockerSwarm/DockerSwarmInventoryExtractor.mjs +1 -0
  42. package/Types/InstallScripts/InstallScripts.d.mts +1 -0
  43. package/Types/InstallScripts/InstallScripts.d.ts +1 -0
  44. package/Types/InstallScripts/InstallScripts.js +14 -0
  45. package/Types/Monitor/DockerSwarmAlertTemplates.d.mts +15 -0
  46. package/Types/Monitor/DockerSwarmAlertTemplates.d.ts +15 -0
  47. package/Types/Monitor/DockerSwarmAlertTemplates.js +168 -0
  48. package/Types/Monitor/DockerSwarmAlertTemplates.mjs +1 -0
  49. package/Types/Monitor/DockerSwarmMetricCatalog.d.mts +1 -1
  50. package/Types/Monitor/DockerSwarmMetricCatalog.d.ts +1 -1
  51. package/Types/Monitor/DockerSwarmMetricCatalog.js +43 -11
  52. package/Types/Monitor/SeriesContext/SeriesDebugHints.js +19 -0
  53. package/Types/NetworkController/NetworkControllerDeviceAdd.d.mts +70 -0
  54. package/Types/NetworkController/NetworkControllerDeviceAdd.d.ts +70 -0
  55. package/Types/NetworkController/NetworkControllerDeviceAdd.js +389 -0
  56. package/Types/NetworkController/NetworkControllerDeviceAdd.mjs +26 -0
  57. package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
  58. package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
  59. package/Types/NetworkController/NetworkControllerReadSummary.js +6 -1
  60. package/Types/NetworkDevice/NetworkTopologyLayout.d.mts +8 -0
  61. package/Types/NetworkDevice/NetworkTopologyLayout.d.ts +8 -0
  62. package/Types/NetworkDevice/NetworkTopologyLayout.js +49 -0
  63. package/Types/NetworkDevice/NetworkTopologyLayout.mjs +3 -0
  64. package/Types/Permission.d.mts +8 -0
  65. package/Types/Permission.d.ts +8 -0
  66. package/Types/Permission.js +87 -3
  67. package/Types/PushNotification/PushNotificationCategory.d.mts +3 -0
  68. package/Types/PushNotification/PushNotificationCategory.d.ts +3 -0
  69. package/Types/PushNotification/PushNotificationCategory.js +38 -0
  70. package/Types/PushNotification/PushNotificationCategory.mjs +4 -0
  71. package/Types/PushNotification/PushNotificationMessage.d.mts +1 -0
  72. package/Types/PushNotification/PushNotificationMessage.d.ts +1 -0
  73. package/Types/Runner/RunnerCodeFixes.d.mts +22 -0
  74. package/Types/Runner/RunnerCodeFixes.d.ts +22 -0
  75. package/Types/Runner/RunnerCodeFixes.js +129 -0
  76. package/Types/Runner/RunnerCodeFixes.mjs +9 -0
  77. package/Types/SecurityCase/SecurityCaseNumber.js +8 -4
  78. package/Types/SecurityEvent/MitreAttack.d.mts +2 -0
  79. package/Types/SecurityEvent/MitreAttack.d.ts +2 -0
  80. package/Types/SecurityEvent/MitreAttack.js +26 -0
  81. package/Types/SecurityEvent/MitreAttack.mjs +2 -0
  82. package/Types/SecurityEvent/OcsfSeverity.js +10 -1
  83. package/Types/Telemetry/TelemetrySearchQuery.js +14 -2
  84. package/Types/Workspace/WorkspaceMessagePayload.d.mts +7 -0
  85. package/Types/Workspace/WorkspaceMessagePayload.d.ts +7 -0
  86. package/Utils/CronScheduleText.d.mts +3 -0
  87. package/Utils/CronScheduleText.d.ts +3 -0
  88. package/Utils/CronScheduleText.js +307 -0
  89. package/Utils/CronScheduleText.mjs +3 -0
  90. package/Utils/Dashboard/DashboardBoardLayout.d.mts +2 -0
  91. package/Utils/Dashboard/DashboardBoardLayout.d.ts +2 -0
  92. package/Utils/Dashboard/DashboardBoardLayout.js +17 -4
  93. package/Utils/Dashboard/DashboardBoardLayout.mjs +1 -0
  94. package/Utils/DeveloperDocs/CliCommands.d.mts +114 -0
  95. package/Utils/DeveloperDocs/CliCommands.d.ts +114 -0
  96. package/Utils/DeveloperDocs/CliCommands.js +750 -0
  97. package/Utils/DeveloperDocs/CliCommands.mjs +37 -0
  98. package/Utils/DeveloperDocs/CliExamples.d.mts +59 -0
  99. package/Utils/DeveloperDocs/CliExamples.d.ts +59 -0
  100. package/Utils/DeveloperDocs/CliExamples.js +348 -0
  101. package/Utils/DeveloperDocs/CliExamples.mjs +17 -0
  102. package/Utils/DeveloperDocs/CliResources.d.mts +18 -0
  103. package/Utils/DeveloperDocs/CliResources.d.ts +18 -0
  104. package/Utils/DeveloperDocs/CliResources.js +129 -0
  105. package/Utils/DeveloperDocs/CliResources.mjs +6 -0
  106. package/Utils/DeveloperDocs/ExampleBuilder.d.mts +6 -0
  107. package/Utils/DeveloperDocs/ExampleBuilder.d.ts +6 -0
  108. package/Utils/DeveloperDocs/ExampleBuilder.js +27 -2
  109. package/Utils/DeveloperDocs/ExampleBuilder.mjs +1 -0
  110. package/Utils/DeveloperDocs/PageLookups.d.mts +1 -1
  111. package/Utils/DeveloperDocs/PageLookups.d.ts +1 -1
  112. package/Utils/DeveloperDocs/PageLookups.js +9 -2
  113. package/Utils/DeveloperDocs/TerraformSchema.d.mts +1 -0
  114. package/Utils/DeveloperDocs/TerraformSchema.d.ts +1 -0
  115. package/Utils/DeveloperDocs/TerraformSchema.js +3 -1
  116. package/Utils/DeveloperDocs/TerraformSchema.mjs +1 -0
  117. package/Utils/LookupTable.d.mts +3 -0
  118. package/Utils/LookupTable.d.ts +3 -0
  119. package/Utils/LookupTable.js +44 -0
  120. package/Utils/LookupTable.mjs +4 -0
  121. package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +62 -0
  122. package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +62 -0
  123. package/Utils/Monitor/MonitorCheckScheduleUtil.js +484 -0
  124. package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +3 -0
  125. package/Utils/Monitor/MonitorOverviewFamily.d.mts +39 -0
  126. package/Utils/Monitor/MonitorOverviewFamily.d.ts +39 -0
  127. package/Utils/Monitor/MonitorOverviewFamily.js +207 -0
  128. package/Utils/Monitor/MonitorOverviewFamily.mjs +4 -0
  129. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +192 -0
  130. package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +192 -0
  131. package/Utils/Monitor/MonitorOverviewPresentationUtil.js +1659 -0
  132. package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +5 -0
  133. package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +112 -0
  134. package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +112 -0
  135. package/Utils/Monitor/MonitorOverviewProbeUtil.js +640 -0
  136. package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +3 -0
  137. package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +1 -1
  138. package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +1 -1
  139. package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +27 -0
  140. package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +27 -0
  141. package/Utils/Monitor/MonitorStatusHistoryUtil.js +132 -0
  142. package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +2 -0
  143. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +44 -0
  144. package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +44 -0
  145. package/Utils/Monitor/MonitorUptimeSummaryUtil.js +487 -0
  146. package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +2 -0
  147. package/Utils/OldestKeyMap.d.mts +10 -0
  148. package/Utils/OldestKeyMap.d.ts +10 -0
  149. package/Utils/OldestKeyMap.js +91 -0
  150. package/Utils/OldestKeyMap.mjs +2 -0
  151. package/Utils/Project/NextNumber.d.mts +4 -3
  152. package/Utils/Project/NextNumber.d.ts +4 -3
  153. package/Utils/Project/NextNumber.js +11 -2
  154. package/Utils/Project/NumberPrefix.d.mts +1 -1
  155. package/Utils/Project/NumberPrefix.d.ts +1 -1
  156. package/Utils/Project/NumberPrefix.js +12 -0
  157. package/Utils/Schema/AnalyticsModelSchema.d.mts +48 -0
  158. package/Utils/Schema/AnalyticsModelSchema.d.ts +48 -0
  159. package/Utils/Schema/AnalyticsModelSchema.js +767 -0
  160. package/Utils/Schema/AnalyticsModelSchema.mjs +2 -0
  161. package/Utils/Schema/BaseSchema.d.mts +117 -0
  162. package/Utils/Schema/BaseSchema.d.ts +117 -0
  163. package/Utils/Schema/BaseSchema.js +257 -0
  164. package/Utils/Schema/BaseSchema.mjs +3 -0
  165. package/Utils/Schema/ModelSchema.d.mts +80 -0
  166. package/Utils/Schema/ModelSchema.d.ts +80 -0
  167. package/Utils/Schema/ModelSchema.js +1727 -0
  168. package/Utils/Schema/ModelSchema.mjs +2 -0
  169. package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.mts +0 -1
  170. package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.ts +0 -1
  171. package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.js +9 -25
  172. package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.mjs +0 -1
  173. package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.mts +1 -1
  174. package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.ts +1 -1
  175. package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.js +7 -6
  176. package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.mts +1 -1
  177. package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.ts +1 -1
  178. package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.js +10 -9
  179. package/Utils/SecurityEvent/Connectors/Microsoft365AuditNormalizer.js +4 -3
  180. package/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.js +12 -28
  181. package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.mts +1 -1
  182. package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.ts +1 -1
  183. package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.js +13 -24
  184. package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.mjs +1 -1
  185. package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.mts +2 -2
  186. package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.ts +2 -2
  187. package/Utils/SecurityEvent/Connectors/OktaNormalizer.js +7 -6
  188. package/Utils/SecurityEvent/Connectors/SplunkNormalizer.js +7 -26
  189. package/Utils/SecurityEvent/LogParsers/AzureActivityLogParser.js +4 -3
  190. package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.mts +2 -2
  191. package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.ts +2 -2
  192. package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.js +26 -16
  193. package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.mts +1 -1
  194. package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.ts +1 -1
  195. package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.js +10 -6
  196. package/Utils/SecurityEvent/SecurityEventNormalizer.js +17 -11
  197. package/Utils/SecurityEvent/SecurityEventSearch.js +8 -1
  198. package/Utils/SecurityEvent/Sigma/SigmaRuleSetParser.js +4 -5
  199. package/Utils/SecurityEvent/ThreatIntel/StixPatternParser.js +7 -3
  200. package/Utils/SecurityEvent/UdmNormalizer.js +10 -6
  201. package/Utils/Telemetry/SavedViewDefault.js +4 -3
  202. package/Utils/Telemetry/SavedViewScope.d.mts +33 -0
  203. package/Utils/Telemetry/SavedViewScope.d.ts +33 -0
  204. package/Utils/Telemetry/SavedViewScope.js +105 -0
  205. package/Utils/Telemetry/SavedViewScope.mjs +7 -0
  206. package/package.json +1 -11
  207. package/UI/Utils/TranslateTemplate.d.mts +0 -8
  208. package/UI/Utils/TranslateTemplate.d.ts +0 -8
@@ -0,0 +1,767 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AnalyticsModelSchema = void 0;
7
+ const Zod_1 = __importDefault(require("./Zod"));
8
+ const TableColumnType_1 = __importDefault(require("../../Types/AnalyticsDatabase/TableColumnType"));
9
+ const SortOrder_1 = __importDefault(require("../../Types/BaseDatabase/SortOrder"));
10
+ const BaseSchema_1 = require("./BaseSchema");
11
+ const TypeSchemas_1 = require("./TypeSchemas");
12
+ /*
13
+ * WHAT A TELEMETRY QUERY CAN DO WITH A COLUMN OF EACH TYPE, as
14
+ * StatementGenerator compiles it: Tests/Utils/Schema/AnalyticsModelSchema runs
15
+ * every operator listed here through it, on every column of every telemetry
16
+ * table. The OpenAPI spec and the MCP server's oneuptime_describe_resource
17
+ * both read these lists.
18
+ */
19
+ const PRESENCE_OPERATORS = ["IsNull", "NotNull"];
20
+ const EQUALITY_OPERATORS = [
21
+ "EqualTo",
22
+ "NotEqual",
23
+ ...PRESENCE_OPERATORS,
24
+ ];
25
+ // IN (...) on a column of one value, hasAny on an Array(String).
26
+ const ID_OPERATORS = [...EQUALITY_OPERATORS, "Includes"];
27
+ const RANGE_OPERATORS = [
28
+ ...EQUALITY_OPERATORS,
29
+ "GreaterThan",
30
+ "GreaterThanOrEqual",
31
+ "LessThan",
32
+ "LessThanOrEqual",
33
+ "InBetween",
34
+ ];
35
+ const OPERATORS_BY_COLUMN_TYPE = {
36
+ [TableColumnType_1.default.Text]: [...ID_OPERATORS, "EqualToOrNull", "Search"],
37
+ [TableColumnType_1.default.ObjectID]: ID_OPERATORS,
38
+ [TableColumnType_1.default.IP]: ID_OPERATORS,
39
+ [TableColumnType_1.default.ArrayText]: [...ID_OPERATORS, "Search"],
40
+ [TableColumnType_1.default.Boolean]: EQUALITY_OPERATORS,
41
+ /*
42
+ * A telemetry table's time column (time, startTime, windowStart,
43
+ * validFrom) is a DateTime64. An ISO-8601 time binds as either type.
44
+ */
45
+ [TableColumnType_1.default.Date]: RANGE_OPERATORS,
46
+ [TableColumnType_1.default.DateTime64]: RANGE_OPERATORS,
47
+ [TableColumnType_1.default.Number]: RANGE_OPERATORS,
48
+ [TableColumnType_1.default.LongNumber]: RANGE_OPERATORS,
49
+ [TableColumnType_1.default.BigNumber]: RANGE_OPERATORS,
50
+ [TableColumnType_1.default.Decimal]: RANGE_OPERATORS,
51
+ [TableColumnType_1.default.UInt8]: RANGE_OPERATORS,
52
+ [TableColumnType_1.default.UInt64]: RANGE_OPERATORS,
53
+ [TableColumnType_1.default.Port]: RANGE_OPERATORS,
54
+ // On each key: {"attributes": {"<key>": <value or operator>}}.
55
+ [TableColumnType_1.default.MapStringString]: [...EQUALITY_OPERATORS, "Search"],
56
+ [TableColumnType_1.default.ArrayNumber]: PRESENCE_OPERATORS,
57
+ [TableColumnType_1.default.ArrayBigNumber]: PRESENCE_OPERATORS,
58
+ [TableColumnType_1.default.ArrayDecimal]: PRESENCE_OPERATORS,
59
+ [TableColumnType_1.default.JSON]: PRESENCE_OPERATORS,
60
+ [TableColumnType_1.default.JSONArray]: PRESENCE_OPERATORS,
61
+ // A pre-aggregate's state, which nothing compares with.
62
+ [TableColumnType_1.default.AggregateFunction]: [],
63
+ };
64
+ const TIME_COLUMN_TYPES = [
65
+ TableColumnType_1.default.Date,
66
+ TableColumnType_1.default.DateTime64,
67
+ ];
68
+ /*
69
+ * 64 bits and wider: a JSON number past 2^53 loses digits, so a value can
70
+ * also be sent as a string of digits.
71
+ */
72
+ const WIDE_INTEGER_COLUMN_TYPES = [
73
+ TableColumnType_1.default.LongNumber,
74
+ TableColumnType_1.default.BigNumber,
75
+ TableColumnType_1.default.UInt64,
76
+ ];
77
+ const EXAMPLE_TIME = "2026-01-01T00:00:00.000Z";
78
+ // EXAMPLE_TIME in nanoseconds, as a 64-bit column takes it.
79
+ const EXAMPLE_UNIX_NANO = "1767225600000000000";
80
+ const EXAMPLE_ID = "123e4567-e89b-12d3-a456-426614174000";
81
+ const DIGITS = /^[0-9]+$/;
82
+ /*
83
+ * The columns the API writes itself: a record's ID and creation time
84
+ * (AnalyticsDatabaseService.sanitizeCreate). An update leaves them out of
85
+ * what it changes (BaseAnalyticsAPI.updateItem).
86
+ */
87
+ const API_WRITTEN_COLUMNS = ["_id", "createdAt", "updatedAt"];
88
+ class AnalyticsModelSchema extends BaseSchema_1.BaseSchema {
89
+ // Helper function to add default value to openapi schema if it exists
90
+ static addDefaultToOpenApi(openApiConfig, column) {
91
+ if (column.defaultValue !== undefined && column.defaultValue !== null) {
92
+ return Object.assign(Object.assign({}, openApiConfig), { default: column.defaultValue });
93
+ }
94
+ return openApiConfig;
95
+ }
96
+ static getModelSchema(data) {
97
+ const modelType = data.modelType;
98
+ const model = new modelType();
99
+ const columns = model.getTableColumns();
100
+ // Filter out columns with no read permissions
101
+ const filteredColumns = columns.filter((column) => {
102
+ const accessControl = model.getColumnAccessControlFor(column.key);
103
+ if (!accessControl) {
104
+ return false;
105
+ }
106
+ const readPermissions = accessControl.read;
107
+ return readPermissions && readPermissions.length > 0;
108
+ });
109
+ const shape = {};
110
+ for (const column of filteredColumns) {
111
+ const key = column.key;
112
+ let zodType;
113
+ if (column.type === TableColumnType_1.default.ObjectID) {
114
+ zodType = Zod_1.default.string().openapi(this.addDefaultToOpenApi({
115
+ type: "string",
116
+ example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
117
+ }, column));
118
+ }
119
+ else if (column.type === TableColumnType_1.default.Date) {
120
+ zodType = Zod_1.default.date().openapi(this.addDefaultToOpenApi({
121
+ type: "string",
122
+ format: "date-time",
123
+ example: "2023-01-15T12:30:00.000Z",
124
+ }, column));
125
+ }
126
+ else if (column.type === TableColumnType_1.default.Text) {
127
+ zodType = Zod_1.default.string().openapi(this.addDefaultToOpenApi({
128
+ type: "string",
129
+ example: "Example text value",
130
+ }, column));
131
+ }
132
+ else if (column.type === TableColumnType_1.default.Number) {
133
+ zodType = Zod_1.default
134
+ .number()
135
+ .openapi(this.addDefaultToOpenApi({ type: "number", example: 42 }, column));
136
+ }
137
+ else if (column.type === TableColumnType_1.default.LongNumber) {
138
+ zodType = Zod_1.default.number().openapi(this.addDefaultToOpenApi({
139
+ type: "number",
140
+ example: 1000000,
141
+ }, column));
142
+ }
143
+ else if (column.type === TableColumnType_1.default.Boolean) {
144
+ zodType = Zod_1.default
145
+ .boolean()
146
+ .openapi(this.addDefaultToOpenApi({ type: "boolean", example: true }, column));
147
+ }
148
+ else if (column.type === TableColumnType_1.default.JSON) {
149
+ zodType = Zod_1.default.any().openapi(this.addDefaultToOpenApi({
150
+ type: "object",
151
+ example: { key: "value", nested: { data: 123 } },
152
+ }, column));
153
+ }
154
+ else if (column.type === TableColumnType_1.default.JSONArray) {
155
+ zodType = Zod_1.default.array(Zod_1.default.any()).openapi(this.addDefaultToOpenApi({
156
+ type: "array",
157
+ items: {
158
+ type: "object",
159
+ },
160
+ example: [{ key: "value" }, { key2: "value2" }],
161
+ }, column));
162
+ }
163
+ else if (column.type === TableColumnType_1.default.Decimal) {
164
+ zodType = Zod_1.default.number().openapi(this.addDefaultToOpenApi({
165
+ type: "number",
166
+ example: 123.45,
167
+ }, column));
168
+ }
169
+ else if (column.type === TableColumnType_1.default.ArrayNumber) {
170
+ zodType = Zod_1.default.array(Zod_1.default.number()).openapi(this.addDefaultToOpenApi({
171
+ type: "array",
172
+ items: {
173
+ type: "number",
174
+ },
175
+ example: [1, 2, 3, 4, 5],
176
+ }, column));
177
+ }
178
+ else if (column.type === TableColumnType_1.default.ArrayText) {
179
+ zodType = Zod_1.default.array(Zod_1.default.string()).openapi(this.addDefaultToOpenApi({
180
+ type: "array",
181
+ items: {
182
+ type: "string",
183
+ },
184
+ example: ["item1", "item2", "item3"],
185
+ }, column));
186
+ }
187
+ else if (column.type === TableColumnType_1.default.IP) {
188
+ zodType = (0, TypeSchemas_1.getIPSchema)();
189
+ }
190
+ else if (column.type === TableColumnType_1.default.Port) {
191
+ zodType = (0, TypeSchemas_1.getPortSchema)();
192
+ }
193
+ else {
194
+ // Default fallback
195
+ zodType = Zod_1.default.any().openapi(this.addDefaultToOpenApi({
196
+ type: "string",
197
+ example: "example_value",
198
+ }, column));
199
+ }
200
+ // Apply default value if it exists
201
+ zodType = this.applyDefaultValue(zodType, column);
202
+ if (column.required) {
203
+ // leave as is
204
+ }
205
+ else {
206
+ zodType = zodType.optional();
207
+ }
208
+ // Add title and description to the schema
209
+ if (column.title) {
210
+ zodType = zodType.describe(column.title);
211
+ }
212
+ shape[key] = zodType;
213
+ }
214
+ const schema = Zod_1.default.object(shape);
215
+ return schema;
216
+ }
217
+ /*
218
+ * A column's value as a create or update sends it: what
219
+ * CommonModel.setColumnValue reads, and StatementGenerator writes into
220
+ * the INSERT. Plain JSON - the request body is not deserialized, so a
221
+ * {_type, value} wrapper is not read.
222
+ */
223
+ static getWriteValueSchema(column, disableOpenApiSchema = false) {
224
+ switch (column.type) {
225
+ case TableColumnType_1.default.ObjectID:
226
+ return (0, TypeSchemas_1.getObjectIDSchema)();
227
+ // ISO-8601, which setColumnValue reads as a date.
228
+ case TableColumnType_1.default.Date:
229
+ case TableColumnType_1.default.DateTime64:
230
+ return this.applyOpenApi(Zod_1.default.string(), this.addDefaultToOpenApi({ type: "string", format: "date-time", example: EXAMPLE_TIME }, column), disableOpenApiSchema);
231
+ /*
232
+ * A JSON number past 2^53 loses digits: a UInt64 (a time in
233
+ * nanoseconds, a byte count) is also taken as a string of digits,
234
+ * which the INSERT casts whole.
235
+ */
236
+ case TableColumnType_1.default.UInt64:
237
+ return this.applyOpenApi(Zod_1.default.union([Zod_1.default.number(), Zod_1.default.string().regex(DIGITS)]), this.addDefaultToOpenApi({ example: EXAMPLE_UNIX_NANO }, column), disableOpenApiSchema);
238
+ case TableColumnType_1.default.Text:
239
+ return this.applyOpenApi(Zod_1.default.string(), this.addDefaultToOpenApi({
240
+ type: "string",
241
+ example: "Example text",
242
+ }, column), disableOpenApiSchema);
243
+ case TableColumnType_1.default.Number:
244
+ return this.applyOpenApi(Zod_1.default.number(), this.addDefaultToOpenApi({ type: "number", example: 42 }, column), disableOpenApiSchema);
245
+ // Also read from a string, as a number: past 2^53 digits are lost.
246
+ case TableColumnType_1.default.LongNumber:
247
+ case TableColumnType_1.default.BigNumber:
248
+ return this.applyOpenApi(Zod_1.default.number(), this.addDefaultToOpenApi({
249
+ type: "number",
250
+ example: 1000000,
251
+ }, column), disableOpenApiSchema);
252
+ case TableColumnType_1.default.Boolean:
253
+ return this.applyOpenApi(Zod_1.default.boolean(), this.addDefaultToOpenApi({ type: "boolean", example: true }, column), disableOpenApiSchema);
254
+ // Any JSON value: an object, or an array, as a span's links are.
255
+ case TableColumnType_1.default.JSON:
256
+ return this.applyOpenApi(Zod_1.default.any(), this.addDefaultToOpenApi({ example: { key: "value" } }, column), disableOpenApiSchema);
257
+ // Strings by key, as a log's or a span's attributes.
258
+ case TableColumnType_1.default.MapStringString:
259
+ return this.applyOpenApi(Zod_1.default.object({}).catchall(Zod_1.default.string()), this.addDefaultToOpenApi({ example: { "http.method": "GET" } }, column), disableOpenApiSchema);
260
+ case TableColumnType_1.default.JSONArray:
261
+ return this.applyOpenApi(Zod_1.default.array(Zod_1.default.any()), this.addDefaultToOpenApi({
262
+ type: "array",
263
+ items: { type: "object" },
264
+ example: [{ key: "value" }],
265
+ }, column), disableOpenApiSchema);
266
+ case TableColumnType_1.default.Decimal:
267
+ return this.applyOpenApi(Zod_1.default.number(), this.addDefaultToOpenApi({
268
+ type: "number",
269
+ example: 123.45,
270
+ }, column), disableOpenApiSchema);
271
+ case TableColumnType_1.default.ArrayNumber:
272
+ case TableColumnType_1.default.ArrayDecimal:
273
+ case TableColumnType_1.default.ArrayBigNumber:
274
+ return this.applyOpenApi(Zod_1.default.array(Zod_1.default.number()), this.addDefaultToOpenApi({
275
+ type: "array",
276
+ items: { type: "number" },
277
+ example: [1, 2, 3],
278
+ }, column), disableOpenApiSchema);
279
+ case TableColumnType_1.default.ArrayText:
280
+ return this.applyOpenApi(Zod_1.default.array(Zod_1.default.string()), this.addDefaultToOpenApi({
281
+ type: "array",
282
+ items: { type: "string" },
283
+ example: ["item1", "item2"],
284
+ }, column), disableOpenApiSchema);
285
+ case TableColumnType_1.default.IP:
286
+ return (0, TypeSchemas_1.getIPSchema)();
287
+ case TableColumnType_1.default.Port:
288
+ return (0, TypeSchemas_1.getPortSchema)();
289
+ default:
290
+ return this.applyOpenApi(Zod_1.default.any(), this.addDefaultToOpenApi({
291
+ type: "string",
292
+ example: "unknown",
293
+ }, column), disableOpenApiSchema);
294
+ }
295
+ }
296
+ static applyDefaultValue(zodType, column) {
297
+ // Apply default value if it exists in the column metadata
298
+ if (column.defaultValue !== undefined && column.defaultValue !== null) {
299
+ zodType = zodType.default(column.defaultValue);
300
+ }
301
+ return zodType;
302
+ }
303
+ /*
304
+ * The fields a create may send: the columns somebody may create. One with
305
+ * a default is optional - the API writes the default
306
+ * (AnalyticsDatabaseService.checkRequiredFields) - and so is the project,
307
+ * which the API takes from the request. Its example sends the fields it
308
+ * requires.
309
+ *
310
+ * Its .openapi() names no `type`: zod-to-openapi takes a `type` there for
311
+ * the whole schema and leaves out the properties it would have generated,
312
+ * so the spec listed no field of a telemetry create or update.
313
+ */
314
+ static getCreateModelSchema(data) {
315
+ var _a;
316
+ const model = new data.modelType();
317
+ const disableOpenApiSchema = data.disableOpenApiSchema || false;
318
+ // The API writes the request's project there - the API key's.
319
+ const tenantColumn = (_a = model.getTenantColumn()) === null || _a === void 0 ? void 0 : _a.key;
320
+ const shape = {};
321
+ const example = {};
322
+ for (const column of this.getWritableColumns(model, "create")) {
323
+ const value = this.getWriteValueSchema(column, disableOpenApiSchema);
324
+ const isRequired = column.required &&
325
+ !column.isDefaultValueColumn &&
326
+ column.key !== tenantColumn;
327
+ shape[column.key] = this.applyOpenApi(isRequired ? value : value.optional(), { description: column.description || column.title }, disableOpenApiSchema);
328
+ if (isRequired) {
329
+ example[column.key] = this.getExampleValueForColumn(column.type);
330
+ }
331
+ }
332
+ return this.applyOpenApi(Zod_1.default.object(shape), {
333
+ description: `Create schema for ${model.tableName || "analytics model"}`,
334
+ example: example,
335
+ additionalProperties: false,
336
+ }, disableOpenApiSchema);
337
+ }
338
+ /*
339
+ * The fields an update may change: the columns somebody may update - on
340
+ * a telemetry table today, none - each optional, as an update changes
341
+ * what it sends.
342
+ */
343
+ static getUpdateModelSchema(data) {
344
+ const model = new data.modelType();
345
+ const disableOpenApiSchema = data.disableOpenApiSchema || false;
346
+ const tableName = model.tableName || "analytics model";
347
+ const shape = {};
348
+ const example = {};
349
+ for (const column of this.getWritableColumns(model, "update")) {
350
+ shape[column.key] = this.applyOpenApi(this.getWriteValueSchema(column, disableOpenApiSchema).optional(), { description: column.description || column.title }, disableOpenApiSchema);
351
+ if (Object.keys(example).length === 0) {
352
+ example[column.key] = this.getExampleValueForColumn(column.type);
353
+ }
354
+ }
355
+ return this.applyOpenApi(Zod_1.default.object(shape), {
356
+ description: Object.keys(shape).length > 0
357
+ ? `Update schema for ${tableName}. An update changes the fields it sends.`
358
+ : `Update schema for ${tableName}. No field can be updated: the API refuses an update of any field.`,
359
+ example: example,
360
+ additionalProperties: false,
361
+ }, disableOpenApiSchema);
362
+ }
363
+ /*
364
+ * The columns a create or update may name: those somebody may write (the
365
+ * API refuses the others: ModelPermission.checkCreatePermissions and
366
+ * checkUpdatePermissions), less those it writes itself.
367
+ */
368
+ static getWritableColumns(model, operation) {
369
+ return model
370
+ .getTableColumns()
371
+ .filter((column) => {
372
+ const accessControl = model.getColumnAccessControlFor(column.key);
373
+ return (!API_WRITTEN_COLUMNS.includes(column.key) &&
374
+ ((accessControl === null || accessControl === void 0 ? void 0 : accessControl[operation]) || []).length > 0);
375
+ });
376
+ }
377
+ /*
378
+ * The columns a query may name, each with what it can be compared with.
379
+ *
380
+ * Neither this object's .openapi() nor a column's names a `type`:
381
+ * zod-to-openapi takes a `type` there for the whole schema and leaves out
382
+ * the properties and operators it would have generated, so the spec listed
383
+ * no field of a telemetry query at all.
384
+ */
385
+ static getQueryModelSchema(data) {
386
+ const model = new data.modelType();
387
+ const disableOpenApiSchema = data.disableOpenApiSchema || false;
388
+ const shape = {};
389
+ for (const column of this.getQueryableColumns(model)) {
390
+ const operators = this.getValidOperatorsForColumnType(column.type);
391
+ shape[column.key] = this.applyOpenApi(this.getColumnQuerySchema(column.type, operators).optional(), {
392
+ description: this.getColumnQueryDescription(column, operators),
393
+ example: this.getColumnQueryExample(column.type),
394
+ }, disableOpenApiSchema);
395
+ }
396
+ // A telemetry table is sorted by its time, which every query should bound.
397
+ const sortColumn = model.getTableColumn(model.defaultSortColumn);
398
+ const timeColumn = sortColumn &&
399
+ shape[sortColumn.key] &&
400
+ TIME_COLUMN_TYPES.includes(sortColumn.type)
401
+ ? sortColumn
402
+ : null;
403
+ return this.applyOpenApi(Zod_1.default.object(shape), {
404
+ description: `Query schema for ${model.tableName || "analytics_model"}. A field takes a plain value, which it matches exactly, or an operator its type allows.${timeColumn
405
+ ? ` Telemetry tables are large: bound every query by ${timeColumn.key}.`
406
+ : ""}`,
407
+ example: timeColumn
408
+ ? {
409
+ [timeColumn.key]: this.getColumnQueryExample(timeColumn.type),
410
+ }
411
+ : {},
412
+ additionalProperties: false,
413
+ }, disableOpenApiSchema);
414
+ }
415
+ static getSelectModelSchema(data) {
416
+ const modelType = data.modelType;
417
+ const model = new modelType();
418
+ return this.generateSelectSchema({
419
+ model,
420
+ tableName: model.tableName || "analytics_model",
421
+ getColumns: (model) => {
422
+ return this.getReadableColumns(model).map((column) => {
423
+ return { key: column.key, type: column.type };
424
+ });
425
+ },
426
+ getSelectSchemaExample: () => {
427
+ return this.getSelectSchemaExample(modelType);
428
+ },
429
+ });
430
+ }
431
+ // No `type` in .openapi() here either, so the spec lists the fields.
432
+ static getSortModelSchema(data) {
433
+ const model = new data.modelType();
434
+ const disableOpenApiSchema = data.disableOpenApiSchema || false;
435
+ const sortableTypes = this.getSortableTypes();
436
+ const shape = {};
437
+ for (const column of model.getTableColumns()) {
438
+ if (!sortableTypes.includes(column.type)) {
439
+ continue;
440
+ }
441
+ shape[column.key] = this.applyOpenApi(Zod_1.default.enum([SortOrder_1.default.Ascending, SortOrder_1.default.Descending]).optional(), {
442
+ description: `Sort order for ${column.key} field`,
443
+ example: SortOrder_1.default.Descending,
444
+ }, disableOpenApiSchema);
445
+ }
446
+ return this.applyOpenApi(Zod_1.default.object(shape), {
447
+ description: `Sort schema for ${model.tableName || "analytics_model"}. Only sortable fields are included.`,
448
+ example: shape[model.defaultSortColumn]
449
+ ? { [model.defaultSortColumn]: SortOrder_1.default.Descending }
450
+ : {},
451
+ additionalProperties: false,
452
+ }, disableOpenApiSchema);
453
+ }
454
+ static getGroupByModelSchema(data) {
455
+ const modelType = data.modelType;
456
+ const model = new modelType();
457
+ return this.generateGroupBySchema({
458
+ model,
459
+ tableName: model.tableName || "analytics_model",
460
+ getColumns: (model) => {
461
+ return this.getReadableColumns(model).map((column) => {
462
+ return { key: column.key, type: column.type };
463
+ });
464
+ },
465
+ getGroupableTypes: () => {
466
+ return [
467
+ TableColumnType_1.default.Text,
468
+ TableColumnType_1.default.ObjectID,
469
+ TableColumnType_1.default.Boolean,
470
+ TableColumnType_1.default.Date,
471
+ TableColumnType_1.default.Number,
472
+ TableColumnType_1.default.IP,
473
+ TableColumnType_1.default.Port,
474
+ ];
475
+ },
476
+ getGroupBySchemaExample: () => {
477
+ return this.getGroupBySchemaExample(modelType);
478
+ },
479
+ });
480
+ }
481
+ /*
482
+ * The column types a telemetry query can be sorted on. StatementGenerator
483
+ * orders by any column; arrays, JSON, maps and aggregate states have no
484
+ * order worth asking for.
485
+ */
486
+ static getSortableTypes() {
487
+ return [
488
+ TableColumnType_1.default.Text,
489
+ TableColumnType_1.default.Number,
490
+ TableColumnType_1.default.LongNumber,
491
+ TableColumnType_1.default.BigNumber,
492
+ TableColumnType_1.default.UInt8,
493
+ TableColumnType_1.default.UInt64,
494
+ TableColumnType_1.default.Date,
495
+ TableColumnType_1.default.DateTime64,
496
+ TableColumnType_1.default.Boolean,
497
+ TableColumnType_1.default.ObjectID,
498
+ TableColumnType_1.default.Decimal,
499
+ TableColumnType_1.default.IP,
500
+ TableColumnType_1.default.Port,
501
+ ];
502
+ }
503
+ /*
504
+ * The operators a query can use on a column of this type - on a
505
+ * Map(String, String) column, on each of its keys. None: the column cannot
506
+ * be filtered.
507
+ */
508
+ static getValidOperatorsForColumnType(columnType) {
509
+ return OPERATORS_BY_COLUMN_TYPE[columnType] || [];
510
+ }
511
+ // Those of the columns a query may name that it can compare with something.
512
+ static getQueryableColumns(model) {
513
+ return this.getReadableColumns(model).filter((column) => {
514
+ return this.getValidOperatorsForColumnType(column.type).length > 0;
515
+ });
516
+ }
517
+ /*
518
+ * The columns a query, select or group by may name: those somebody may
519
+ * read, and those the API lets through all the same. It refuses any other
520
+ * column nobody may read, such as a table's retentionDate.
521
+ */
522
+ static getReadableColumns(model) {
523
+ return model
524
+ .getTableColumns()
525
+ .filter((column) => {
526
+ const accessControl = model.getColumnAccessControlFor(column.key);
527
+ return (BaseSchema_1.ALWAYS_READABLE_COLUMNS.includes(column.key) ||
528
+ ((accessControl === null || accessControl === void 0 ? void 0 : accessControl.read) || []).length > 0);
529
+ });
530
+ }
531
+ /*
532
+ * A plain value, or an object of one of the operators - on a map, under
533
+ * each key.
534
+ */
535
+ static getColumnQuerySchema(columnType, operators) {
536
+ const operatorSchemas = operators.map((operator) => {
537
+ return this.getOperatorSchema(operator, columnType);
538
+ });
539
+ const valueOrOperator = operatorSchemas.length === 1
540
+ ? operatorSchemas[0]
541
+ : Zod_1.default.union(operatorSchemas);
542
+ /*
543
+ * A map is filtered by key. A `_type` among the keys would be read as an
544
+ * operator on the whole map, which StatementGenerator compiles none of.
545
+ */
546
+ if (columnType === TableColumnType_1.default.MapStringString) {
547
+ return Zod_1.default
548
+ .object({})
549
+ .catchall(valueOrOperator)
550
+ .refine((keys) => {
551
+ return !("_type" in keys);
552
+ }, 'A map is filtered by key: {"<key>": <value or operator>}.');
553
+ }
554
+ return valueOrOperator;
555
+ }
556
+ static getColumnQueryDescription(column, operators) {
557
+ let description = `Query operators for ${column.key} field of type ${column.type}. Supported operators: ${operators.join(", ")}.`;
558
+ if (column.type === TableColumnType_1.default.MapStringString) {
559
+ description += ` Filtered by key, each key with these operators: {"${column.key}": {"<key>": <value or operator>}}.`;
560
+ }
561
+ else if (column.type === TableColumnType_1.default.ArrayText) {
562
+ description += ` EqualTo, NotEqual and Search match one element; Includes matches any of several.`;
563
+ }
564
+ else if (TIME_COLUMN_TYPES.includes(column.type)) {
565
+ description += ` Times are ISO-8601, such as ${EXAMPLE_TIME}.`;
566
+ }
567
+ else if (WIDE_INTEGER_COLUMN_TYPES.includes(column.type)) {
568
+ description += ` A value past 2^53 is sent as a string of digits.`;
569
+ }
570
+ return description;
571
+ }
572
+ static getColumnQueryExample(columnType) {
573
+ if (TIME_COLUMN_TYPES.includes(columnType)) {
574
+ return { _type: "GreaterThan", value: EXAMPLE_TIME };
575
+ }
576
+ if (WIDE_INTEGER_COLUMN_TYPES.includes(columnType)) {
577
+ return { _type: "GreaterThan", value: "1767225600000000000" };
578
+ }
579
+ switch (columnType) {
580
+ case TableColumnType_1.default.Number:
581
+ case TableColumnType_1.default.Decimal:
582
+ case TableColumnType_1.default.UInt8:
583
+ case TableColumnType_1.default.Port:
584
+ return { _type: "GreaterThan", value: 42 };
585
+ case TableColumnType_1.default.ObjectID:
586
+ return "123e4567-e89b-12d3-a456-426614174000";
587
+ case TableColumnType_1.default.IP:
588
+ return "192.168.1.1";
589
+ case TableColumnType_1.default.Boolean:
590
+ return true;
591
+ case TableColumnType_1.default.ArrayText:
592
+ return { _type: "EqualTo", value: "item1" };
593
+ case TableColumnType_1.default.MapStringString:
594
+ return { key: "value" };
595
+ case TableColumnType_1.default.Text:
596
+ return "example text";
597
+ default:
598
+ return { _type: "NotNull" };
599
+ }
600
+ }
601
+ // A value of a column of this type, as a create or update sends it.
602
+ static getExampleValueForColumn(columnType) {
603
+ switch (columnType) {
604
+ case TableColumnType_1.default.ObjectID:
605
+ return EXAMPLE_ID;
606
+ case TableColumnType_1.default.Text:
607
+ return "example text";
608
+ case TableColumnType_1.default.Number:
609
+ case TableColumnType_1.default.LongNumber:
610
+ case TableColumnType_1.default.BigNumber:
611
+ return 42;
612
+ case TableColumnType_1.default.UInt64:
613
+ return EXAMPLE_UNIX_NANO;
614
+ case TableColumnType_1.default.Decimal:
615
+ return 123.45;
616
+ case TableColumnType_1.default.Date:
617
+ case TableColumnType_1.default.DateTime64:
618
+ return EXAMPLE_TIME;
619
+ case TableColumnType_1.default.Boolean:
620
+ return true;
621
+ case TableColumnType_1.default.JSON:
622
+ return { key: "value" };
623
+ case TableColumnType_1.default.JSONArray:
624
+ return [{ key: "value" }];
625
+ case TableColumnType_1.default.ArrayText:
626
+ return ["item1", "item2"];
627
+ case TableColumnType_1.default.ArrayNumber:
628
+ return [1, 2, 3];
629
+ case TableColumnType_1.default.IP:
630
+ return "192.168.1.1";
631
+ case TableColumnType_1.default.Port:
632
+ return 8080;
633
+ default:
634
+ return "example_value";
635
+ }
636
+ }
637
+ static getSelectSchemaExample(modelType) {
638
+ const model = new modelType();
639
+ const columns = model.getTableColumns();
640
+ // Add common fields (only if they have read permissions)
641
+ const example = {};
642
+ // Check if _id has read permissions
643
+ const idAccessControl = model.getColumnAccessControlFor("_id");
644
+ if (idAccessControl &&
645
+ idAccessControl.read &&
646
+ idAccessControl.read.length > 0) {
647
+ example["_id"] = true;
648
+ }
649
+ // Check if createdAt has read permissions
650
+ const createdAtAccessControl = model.getColumnAccessControlFor("createdAt");
651
+ if (createdAtAccessControl &&
652
+ createdAtAccessControl.read &&
653
+ createdAtAccessControl.read.length > 0) {
654
+ example["createdAt"] = true;
655
+ }
656
+ // Add first few non-system fields with read permissions
657
+ let fieldCount = 0;
658
+ const maxFields = 3;
659
+ for (const column of columns) {
660
+ if (fieldCount >= maxFields) {
661
+ break;
662
+ }
663
+ if (!["_id", "createdAt", "updatedAt"].includes(column.key)) {
664
+ // Check read permissions
665
+ const accessControl = model.getColumnAccessControlFor(column.key);
666
+ if (accessControl &&
667
+ accessControl.read &&
668
+ accessControl.read.length > 0) {
669
+ example[column.key] = true;
670
+ fieldCount++;
671
+ }
672
+ }
673
+ }
674
+ return example;
675
+ }
676
+ static getGroupBySchemaExample(modelType) {
677
+ const model = new modelType();
678
+ const columns = model.getTableColumns();
679
+ // Find first suitable field for grouping with read permissions
680
+ for (const column of columns) {
681
+ const isGroupable = [
682
+ TableColumnType_1.default.Text,
683
+ TableColumnType_1.default.ObjectID,
684
+ TableColumnType_1.default.Boolean,
685
+ TableColumnType_1.default.Date,
686
+ TableColumnType_1.default.Number,
687
+ TableColumnType_1.default.IP,
688
+ TableColumnType_1.default.Port,
689
+ ].includes(column.type);
690
+ if (isGroupable &&
691
+ !["_id", "createdAt", "updatedAt"].includes(column.key)) {
692
+ // Check read permissions
693
+ const accessControl = model.getColumnAccessControlFor(column.key);
694
+ if (accessControl &&
695
+ accessControl.read &&
696
+ accessControl.read.length > 0) {
697
+ return { [column.key]: true };
698
+ }
699
+ }
700
+ }
701
+ // Fallback to createdAt if it has read permissions
702
+ const createdAtAccessControl = model.getColumnAccessControlFor("createdAt");
703
+ if (createdAtAccessControl &&
704
+ createdAtAccessControl.read &&
705
+ createdAtAccessControl.read.length > 0) {
706
+ return { ["createdAt"]: true };
707
+ }
708
+ // Final fallback - return empty object if no columns have read permissions
709
+ return {};
710
+ }
711
+ // An operator as JSONFunctions.deserialize reads it on the API.
712
+ static getOperatorSchema(operatorType, columnType) {
713
+ const value = this.getQueryValueSchema(columnType);
714
+ switch (operatorType) {
715
+ /*
716
+ * A plain value matches exactly. An Array(String) column's plain value
717
+ * is the whole array, so one element is asked for with EqualTo itself.
718
+ */
719
+ case "EqualTo":
720
+ return columnType === TableColumnType_1.default.ArrayText
721
+ ? Zod_1.default.object({ _type: Zod_1.default.literal(operatorType), value: value })
722
+ : value;
723
+ case "IsNull":
724
+ case "NotNull":
725
+ return Zod_1.default.object({ _type: Zod_1.default.literal(operatorType) });
726
+ case "InBetween":
727
+ return Zod_1.default.object({
728
+ _type: Zod_1.default.literal(operatorType),
729
+ startValue: value,
730
+ endValue: value,
731
+ });
732
+ case "Includes":
733
+ return Zod_1.default.object({
734
+ _type: Zod_1.default.literal(operatorType),
735
+ value: Zod_1.default.array(value),
736
+ });
737
+ case "Search":
738
+ return Zod_1.default.object({ _type: Zod_1.default.literal(operatorType), value: Zod_1.default.string() });
739
+ default:
740
+ return Zod_1.default.object({ _type: Zod_1.default.literal(operatorType), value: value });
741
+ }
742
+ }
743
+ /*
744
+ * What a query compares a column of this type with, as JSON carries it: on
745
+ * an Array(String), one element; on a map, a key's value.
746
+ */
747
+ static getQueryValueSchema(columnType) {
748
+ if (TIME_COLUMN_TYPES.includes(columnType)) {
749
+ return Zod_1.default.string().openapi({ format: "date-time" });
750
+ }
751
+ if (WIDE_INTEGER_COLUMN_TYPES.includes(columnType)) {
752
+ return Zod_1.default.union([Zod_1.default.number(), Zod_1.default.string()]);
753
+ }
754
+ switch (columnType) {
755
+ case TableColumnType_1.default.Number:
756
+ case TableColumnType_1.default.Decimal:
757
+ case TableColumnType_1.default.UInt8:
758
+ case TableColumnType_1.default.Port:
759
+ return Zod_1.default.number();
760
+ case TableColumnType_1.default.Boolean:
761
+ return Zod_1.default.boolean();
762
+ default:
763
+ return Zod_1.default.string();
764
+ }
765
+ }
766
+ }
767
+ exports.AnalyticsModelSchema = AnalyticsModelSchema;