@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.
- package/Models/DatabaseModels/Index.js +6 -0
- package/Models/DatabaseModels/LogSavedView.d.mts +1 -0
- package/Models/DatabaseModels/LogSavedView.d.ts +1 -0
- package/Models/DatabaseModels/LogSavedView.js +43 -1
- package/Models/DatabaseModels/NetworkControllerConnection.d.mts +1 -0
- package/Models/DatabaseModels/NetworkControllerConnection.d.ts +1 -0
- package/Models/DatabaseModels/NetworkControllerConnection.js +21 -0
- package/Models/DatabaseModels/Project.d.mts +3 -0
- package/Models/DatabaseModels/Project.d.ts +3 -0
- package/Models/DatabaseModels/Project.js +124 -0
- package/Models/DatabaseModels/Runner.d.mts +1 -0
- package/Models/DatabaseModels/Runner.d.ts +1 -0
- package/Models/DatabaseModels/Runner.js +40 -0
- package/Models/DatabaseModels/SecurityCase.d.mts +2 -1
- package/Models/DatabaseModels/SecurityCase.d.ts +2 -1
- package/Models/DatabaseModels/SecurityCase.js +27 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.d.mts +20 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.d.ts +20 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.js +387 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.mjs +2 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.mts +15 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.ts +15 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.js +309 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.mjs +2 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.d.mts +11 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.d.ts +11 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.js +186 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.mjs +2 -0
- package/Types/AI/AIFixReadiness.d.mts +2 -0
- package/Types/AI/AIFixReadiness.d.ts +2 -0
- package/Types/AI/AIFixReadiness.js +0 -6
- package/Types/AI/CodeTask.d.mts +3 -1
- package/Types/AI/CodeTask.d.ts +3 -1
- package/Types/AI/CodeTask.js +12 -0
- package/Types/CustomField/CustomFieldRecordKinds.js +5 -0
- package/Types/CustomField/CustomFieldSavedViews.js +2 -0
- package/Types/DateLanguage.js +3 -2
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.mts +1 -0
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.ts +1 -0
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.js +84 -6
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.mjs +1 -0
- package/Types/InstallScripts/InstallScripts.d.mts +1 -0
- package/Types/InstallScripts/InstallScripts.d.ts +1 -0
- package/Types/InstallScripts/InstallScripts.js +14 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.d.mts +15 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.d.ts +15 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.js +168 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.mjs +1 -0
- package/Types/Monitor/DockerSwarmMetricCatalog.d.mts +1 -1
- package/Types/Monitor/DockerSwarmMetricCatalog.d.ts +1 -1
- package/Types/Monitor/DockerSwarmMetricCatalog.js +43 -11
- package/Types/Monitor/SeriesContext/SeriesDebugHints.js +19 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.d.mts +70 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.d.ts +70 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.js +389 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.mjs +26 -0
- package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
- package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
- package/Types/NetworkController/NetworkControllerReadSummary.js +6 -1
- package/Types/NetworkDevice/NetworkTopologyLayout.d.mts +8 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.d.ts +8 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.js +49 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.mjs +3 -0
- package/Types/Permission.d.mts +8 -0
- package/Types/Permission.d.ts +8 -0
- package/Types/Permission.js +87 -3
- package/Types/PushNotification/PushNotificationCategory.d.mts +3 -0
- package/Types/PushNotification/PushNotificationCategory.d.ts +3 -0
- package/Types/PushNotification/PushNotificationCategory.js +38 -0
- package/Types/PushNotification/PushNotificationCategory.mjs +4 -0
- package/Types/PushNotification/PushNotificationMessage.d.mts +1 -0
- package/Types/PushNotification/PushNotificationMessage.d.ts +1 -0
- package/Types/Runner/RunnerCodeFixes.d.mts +22 -0
- package/Types/Runner/RunnerCodeFixes.d.ts +22 -0
- package/Types/Runner/RunnerCodeFixes.js +129 -0
- package/Types/Runner/RunnerCodeFixes.mjs +9 -0
- package/Types/SecurityCase/SecurityCaseNumber.js +8 -4
- package/Types/SecurityEvent/MitreAttack.d.mts +2 -0
- package/Types/SecurityEvent/MitreAttack.d.ts +2 -0
- package/Types/SecurityEvent/MitreAttack.js +26 -0
- package/Types/SecurityEvent/MitreAttack.mjs +2 -0
- package/Types/SecurityEvent/OcsfSeverity.js +10 -1
- package/Types/Telemetry/TelemetrySearchQuery.js +14 -2
- package/Types/Workspace/WorkspaceMessagePayload.d.mts +7 -0
- package/Types/Workspace/WorkspaceMessagePayload.d.ts +7 -0
- package/Utils/CronScheduleText.d.mts +3 -0
- package/Utils/CronScheduleText.d.ts +3 -0
- package/Utils/CronScheduleText.js +307 -0
- package/Utils/CronScheduleText.mjs +3 -0
- package/Utils/Dashboard/DashboardBoardLayout.d.mts +2 -0
- package/Utils/Dashboard/DashboardBoardLayout.d.ts +2 -0
- package/Utils/Dashboard/DashboardBoardLayout.js +17 -4
- package/Utils/Dashboard/DashboardBoardLayout.mjs +1 -0
- package/Utils/DeveloperDocs/CliCommands.d.mts +114 -0
- package/Utils/DeveloperDocs/CliCommands.d.ts +114 -0
- package/Utils/DeveloperDocs/CliCommands.js +750 -0
- package/Utils/DeveloperDocs/CliCommands.mjs +37 -0
- package/Utils/DeveloperDocs/CliExamples.d.mts +59 -0
- package/Utils/DeveloperDocs/CliExamples.d.ts +59 -0
- package/Utils/DeveloperDocs/CliExamples.js +348 -0
- package/Utils/DeveloperDocs/CliExamples.mjs +17 -0
- package/Utils/DeveloperDocs/CliResources.d.mts +18 -0
- package/Utils/DeveloperDocs/CliResources.d.ts +18 -0
- package/Utils/DeveloperDocs/CliResources.js +129 -0
- package/Utils/DeveloperDocs/CliResources.mjs +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.d.mts +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.d.ts +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.js +27 -2
- package/Utils/DeveloperDocs/ExampleBuilder.mjs +1 -0
- package/Utils/DeveloperDocs/PageLookups.d.mts +1 -1
- package/Utils/DeveloperDocs/PageLookups.d.ts +1 -1
- package/Utils/DeveloperDocs/PageLookups.js +9 -2
- package/Utils/DeveloperDocs/TerraformSchema.d.mts +1 -0
- package/Utils/DeveloperDocs/TerraformSchema.d.ts +1 -0
- package/Utils/DeveloperDocs/TerraformSchema.js +3 -1
- package/Utils/DeveloperDocs/TerraformSchema.mjs +1 -0
- package/Utils/LookupTable.d.mts +3 -0
- package/Utils/LookupTable.d.ts +3 -0
- package/Utils/LookupTable.js +44 -0
- package/Utils/LookupTable.mjs +4 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +62 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +62 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.js +484 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +3 -0
- package/Utils/Monitor/MonitorOverviewFamily.d.mts +39 -0
- package/Utils/Monitor/MonitorOverviewFamily.d.ts +39 -0
- package/Utils/Monitor/MonitorOverviewFamily.js +207 -0
- package/Utils/Monitor/MonitorOverviewFamily.mjs +4 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +192 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +192 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.js +1659 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +5 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +112 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +112 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.js +640 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +3 -0
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +1 -1
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +1 -1
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +27 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +27 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.js +132 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +2 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +44 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +44 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.js +487 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +2 -0
- package/Utils/OldestKeyMap.d.mts +10 -0
- package/Utils/OldestKeyMap.d.ts +10 -0
- package/Utils/OldestKeyMap.js +91 -0
- package/Utils/OldestKeyMap.mjs +2 -0
- package/Utils/Project/NextNumber.d.mts +4 -3
- package/Utils/Project/NextNumber.d.ts +4 -3
- package/Utils/Project/NextNumber.js +11 -2
- package/Utils/Project/NumberPrefix.d.mts +1 -1
- package/Utils/Project/NumberPrefix.d.ts +1 -1
- package/Utils/Project/NumberPrefix.js +12 -0
- package/Utils/Schema/AnalyticsModelSchema.d.mts +48 -0
- package/Utils/Schema/AnalyticsModelSchema.d.ts +48 -0
- package/Utils/Schema/AnalyticsModelSchema.js +767 -0
- package/Utils/Schema/AnalyticsModelSchema.mjs +2 -0
- package/Utils/Schema/BaseSchema.d.mts +117 -0
- package/Utils/Schema/BaseSchema.d.ts +117 -0
- package/Utils/Schema/BaseSchema.js +257 -0
- package/Utils/Schema/BaseSchema.mjs +3 -0
- package/Utils/Schema/ModelSchema.d.mts +80 -0
- package/Utils/Schema/ModelSchema.d.ts +80 -0
- package/Utils/Schema/ModelSchema.js +1727 -0
- package/Utils/Schema/ModelSchema.mjs +2 -0
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.mts +0 -1
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.ts +0 -1
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.js +9 -25
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.mjs +0 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.js +7 -6
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.js +10 -9
- package/Utils/SecurityEvent/Connectors/Microsoft365AuditNormalizer.js +4 -3
- package/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.js +12 -28
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.js +13 -24
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.mjs +1 -1
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.mts +2 -2
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.ts +2 -2
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.js +7 -6
- package/Utils/SecurityEvent/Connectors/SplunkNormalizer.js +7 -26
- package/Utils/SecurityEvent/LogParsers/AzureActivityLogParser.js +4 -3
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.mts +2 -2
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.ts +2 -2
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.js +26 -16
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.mts +1 -1
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.ts +1 -1
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.js +10 -6
- package/Utils/SecurityEvent/SecurityEventNormalizer.js +17 -11
- package/Utils/SecurityEvent/SecurityEventSearch.js +8 -1
- package/Utils/SecurityEvent/Sigma/SigmaRuleSetParser.js +4 -5
- package/Utils/SecurityEvent/ThreatIntel/StixPatternParser.js +7 -3
- package/Utils/SecurityEvent/UdmNormalizer.js +10 -6
- package/Utils/Telemetry/SavedViewDefault.js +4 -3
- package/Utils/Telemetry/SavedViewScope.d.mts +33 -0
- package/Utils/Telemetry/SavedViewScope.d.ts +33 -0
- package/Utils/Telemetry/SavedViewScope.js +105 -0
- package/Utils/Telemetry/SavedViewScope.mjs +7 -0
- package/package.json +1 -11
- package/UI/Utils/TranslateTemplate.d.mts +0 -8
- package/UI/Utils/TranslateTemplate.d.ts +0 -8
|
@@ -0,0 +1,1727 @@
|
|
|
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.ModelSchema = void 0;
|
|
7
|
+
const Zod_1 = __importDefault(require("./Zod"));
|
|
8
|
+
const TableColumnType_1 = __importDefault(require("../../Types/Database/TableColumnType"));
|
|
9
|
+
const TableColumn_1 = require("../../Types/Database/TableColumn");
|
|
10
|
+
const BadDataException_1 = __importDefault(require("../../Types/Exception/BadDataException"));
|
|
11
|
+
const Permission_1 = require("../../Types/Permission");
|
|
12
|
+
const BaseSchema_1 = require("./BaseSchema");
|
|
13
|
+
const TypeSchemas_1 = require("./TypeSchemas");
|
|
14
|
+
const MonitorSchemas_1 = require("./MonitorSchemas");
|
|
15
|
+
const MonitorType_1 = __importDefault(require("../../Types/Monitor/MonitorType"));
|
|
16
|
+
const WorkflowStatus_1 = __importDefault(require("../../Types/Workflow/WorkflowStatus"));
|
|
17
|
+
const CustomFieldType_1 = __importDefault(require("../../Types/CustomField/CustomFieldType"));
|
|
18
|
+
/*
|
|
19
|
+
* The text columns an encrypted secret is stored in. An encrypted JSON
|
|
20
|
+
* column holds a map of them, not one string, so it is left as it is.
|
|
21
|
+
*/
|
|
22
|
+
const ENCRYPTED_SECRET_COLUMN_TYPES = [
|
|
23
|
+
TableColumnType_1.default.ShortText,
|
|
24
|
+
TableColumnType_1.default.LongText,
|
|
25
|
+
TableColumnType_1.default.VeryLongText,
|
|
26
|
+
];
|
|
27
|
+
/*
|
|
28
|
+
* WHAT A QUERY CAN DO WITH A COLUMN OF EACH TYPE, as the API runs it:
|
|
29
|
+
* JSONFunctions.deserialize reads the operator, QueryPermission checks the
|
|
30
|
+
* column and QueryUtil.serializeQuery compiles it.
|
|
31
|
+
* Tests/Utils/Schema/ModelSchemaQuery runs every filter the spec documents,
|
|
32
|
+
* on every column of every documented model, through all three. The OpenAPI
|
|
33
|
+
* spec, the MCP server's oneuptime_describe_resource and the developer docs
|
|
34
|
+
* read these lists.
|
|
35
|
+
*/
|
|
36
|
+
const PRESENCE_OPERATORS = ["IsNull", "NotNull"];
|
|
37
|
+
const COMMON_OPERATORS = [
|
|
38
|
+
"EqualTo",
|
|
39
|
+
"NotEqual",
|
|
40
|
+
...PRESENCE_OPERATORS,
|
|
41
|
+
"EqualToOrNull",
|
|
42
|
+
];
|
|
43
|
+
const ID_OPERATORS = [...COMMON_OPERATORS, "Includes"];
|
|
44
|
+
const TEXT_OPERATORS = [
|
|
45
|
+
...COMMON_OPERATORS,
|
|
46
|
+
"Search",
|
|
47
|
+
"Includes",
|
|
48
|
+
];
|
|
49
|
+
const RANGE_OPERATORS = [
|
|
50
|
+
...COMMON_OPERATORS,
|
|
51
|
+
"GreaterThan",
|
|
52
|
+
"LessThan",
|
|
53
|
+
"GreaterThanOrEqual",
|
|
54
|
+
"LessThanOrEqual",
|
|
55
|
+
"InBetween",
|
|
56
|
+
];
|
|
57
|
+
const OPERATORS_BY_COLUMN_TYPE = {
|
|
58
|
+
[TableColumnType_1.default.ObjectID]: ID_OPERATORS,
|
|
59
|
+
[TableColumnType_1.default.Email]: ID_OPERATORS,
|
|
60
|
+
[TableColumnType_1.default.Phone]: ID_OPERATORS,
|
|
61
|
+
[TableColumnType_1.default.HashedString]: ID_OPERATORS,
|
|
62
|
+
[TableColumnType_1.default.Slug]: ID_OPERATORS,
|
|
63
|
+
[TableColumnType_1.default.ShortText]: TEXT_OPERATORS,
|
|
64
|
+
[TableColumnType_1.default.LongText]: TEXT_OPERATORS,
|
|
65
|
+
[TableColumnType_1.default.VeryLongText]: TEXT_OPERATORS,
|
|
66
|
+
[TableColumnType_1.default.Name]: TEXT_OPERATORS,
|
|
67
|
+
[TableColumnType_1.default.Description]: TEXT_OPERATORS,
|
|
68
|
+
[TableColumnType_1.default.Domain]: TEXT_OPERATORS,
|
|
69
|
+
[TableColumnType_1.default.Markdown]: TEXT_OPERATORS,
|
|
70
|
+
[TableColumnType_1.default.Number]: RANGE_OPERATORS,
|
|
71
|
+
[TableColumnType_1.default.PositiveNumber]: RANGE_OPERATORS,
|
|
72
|
+
[TableColumnType_1.default.SmallNumber]: RANGE_OPERATORS,
|
|
73
|
+
[TableColumnType_1.default.SmallPositiveNumber]: RANGE_OPERATORS,
|
|
74
|
+
[TableColumnType_1.default.BigNumber]: RANGE_OPERATORS,
|
|
75
|
+
[TableColumnType_1.default.BigPositiveNumber]: RANGE_OPERATORS,
|
|
76
|
+
[TableColumnType_1.default.Date]: RANGE_OPERATORS,
|
|
77
|
+
[TableColumnType_1.default.Boolean]: COMMON_OPERATORS,
|
|
78
|
+
/*
|
|
79
|
+
* On each key: {"customFields": {"<key>": <value or operator>}}, as
|
|
80
|
+
* JSONColumnQuery compiles it. NotEqual on the column itself is read as a
|
|
81
|
+
* key named "_value".
|
|
82
|
+
*/
|
|
83
|
+
[TableColumnType_1.default.JSON]: [
|
|
84
|
+
...TEXT_OPERATORS,
|
|
85
|
+
"GreaterThan",
|
|
86
|
+
"LessThan",
|
|
87
|
+
"GreaterThanOrEqual",
|
|
88
|
+
"LessThanOrEqual",
|
|
89
|
+
"InBetween",
|
|
90
|
+
],
|
|
91
|
+
// A relation list. The API refuses NotEqual on one (UUIDColumnFilter).
|
|
92
|
+
[TableColumnType_1.default.EntityArray]: ["EqualTo", ...PRESENCE_OPERATORS, "Includes"],
|
|
93
|
+
// A relation, filtered through its own fields, is no field of a query.
|
|
94
|
+
[TableColumnType_1.default.Entity]: [
|
|
95
|
+
"EqualTo",
|
|
96
|
+
"NotEqual",
|
|
97
|
+
...PRESENCE_OPERATORS,
|
|
98
|
+
"Includes",
|
|
99
|
+
],
|
|
100
|
+
/*
|
|
101
|
+
* A JSON document or a file's bytes: only whether there is one can be
|
|
102
|
+
* asked. Postgres reads text compared with a monitor's steps as JSON, and
|
|
103
|
+
* refuses it.
|
|
104
|
+
*/
|
|
105
|
+
[TableColumnType_1.default.MonitorSteps]: PRESENCE_OPERATORS,
|
|
106
|
+
[TableColumnType_1.default.File]: PRESENCE_OPERATORS,
|
|
107
|
+
[TableColumnType_1.default.Buffer]: PRESENCE_OPERATORS,
|
|
108
|
+
[TableColumnType_1.default.Array]: ["EqualTo", "NotEqual", ...PRESENCE_OPERATORS],
|
|
109
|
+
[TableColumnType_1.default.Color]: COMMON_OPERATORS,
|
|
110
|
+
[TableColumnType_1.default.Version]: COMMON_OPERATORS,
|
|
111
|
+
[TableColumnType_1.default.Password]: COMMON_OPERATORS,
|
|
112
|
+
[TableColumnType_1.default.OTP]: COMMON_OPERATORS,
|
|
113
|
+
[TableColumnType_1.default.ShortURL]: COMMON_OPERATORS,
|
|
114
|
+
[TableColumnType_1.default.LongURL]: COMMON_OPERATORS,
|
|
115
|
+
[TableColumnType_1.default.HTML]: COMMON_OPERATORS,
|
|
116
|
+
[TableColumnType_1.default.JavaScript]: COMMON_OPERATORS,
|
|
117
|
+
[TableColumnType_1.default.CSS]: COMMON_OPERATORS,
|
|
118
|
+
[TableColumnType_1.default.Permission]: COMMON_OPERATORS,
|
|
119
|
+
[TableColumnType_1.default.CustomFieldType]: COMMON_OPERATORS,
|
|
120
|
+
[TableColumnType_1.default.MonitorType]: COMMON_OPERATORS,
|
|
121
|
+
[TableColumnType_1.default.WorkflowStatus]: COMMON_OPERATORS,
|
|
122
|
+
[TableColumnType_1.default.IP]: COMMON_OPERATORS,
|
|
123
|
+
[TableColumnType_1.default.Port]: COMMON_OPERATORS,
|
|
124
|
+
};
|
|
125
|
+
// Each type's filter, built once (ModelSchema.getQueryFilterSchema).
|
|
126
|
+
const QUERY_FILTER_SCHEMAS = new Map();
|
|
127
|
+
// Each model's relation select, built once (getRelationSelectSchema).
|
|
128
|
+
const RELATION_SELECT_SCHEMAS = new Map();
|
|
129
|
+
const EXAMPLE_ID = "123e4567-e89b-12d3-a456-426614174000";
|
|
130
|
+
/*
|
|
131
|
+
* What a text field's example is when its column gives none of its own
|
|
132
|
+
* (TableColumn.example, or the first of its allowedValues): placeholders,
|
|
133
|
+
* which a reader replaces.
|
|
134
|
+
*/
|
|
135
|
+
const SHORT_TEXT_EXAMPLE = "Example short text";
|
|
136
|
+
const LONG_TEXT_EXAMPLE = "This is an example of longer text content that might be stored in this field.";
|
|
137
|
+
const VERY_LONG_TEXT_EXAMPLE = "This is an example of very long text content that might be stored in this field. It can contain a lot of information, such as detailed descriptions, comments, or any other lengthy text data that needs to be stored in the database.";
|
|
138
|
+
// What a column's description may already end its sentence with.
|
|
139
|
+
const SENTENCE_END_PUNCTUATION = [".", "!", "?"];
|
|
140
|
+
const EXAMPLE_TIME = "2026-01-01T00:00:00.000Z";
|
|
141
|
+
class ModelSchema extends BaseSchema_1.BaseSchema {
|
|
142
|
+
/**
|
|
143
|
+
* Format permissions array into a human-readable string for OpenAPI documentation
|
|
144
|
+
*/
|
|
145
|
+
static formatPermissionsForSchema(permissions) {
|
|
146
|
+
if (!permissions || permissions.length === 0) {
|
|
147
|
+
return "No access - you don't have permission for this operation";
|
|
148
|
+
}
|
|
149
|
+
return Permission_1.PermissionHelper.getPermissionTitles(permissions).join(", ");
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get permissions description for a column to add to OpenAPI schema
|
|
153
|
+
*/
|
|
154
|
+
static getColumnPermissionsDescription(model, key) {
|
|
155
|
+
const accessControl = model.getColumnAccessControlForAllColumns()[key];
|
|
156
|
+
if (!accessControl) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
const createPermissions = this.formatPermissionsForSchema(accessControl.create);
|
|
160
|
+
const readPermissions = this.formatPermissionsForSchema(accessControl.read);
|
|
161
|
+
const updatePermissions = this.formatPermissionsForSchema(accessControl.update);
|
|
162
|
+
return `Permissions - Create: [${createPermissions}], Read: [${readPermissions}], Update: [${updatePermissions}]`;
|
|
163
|
+
}
|
|
164
|
+
/*
|
|
165
|
+
* A column's description as the spec writes it: the column's own words as
|
|
166
|
+
* one sentence, then its permissions clause. A full stop is added only to
|
|
167
|
+
* words that end without one - most columns' descriptions end with their
|
|
168
|
+
* own ("Date and Time when the object was created."), and joining them
|
|
169
|
+
* with ". " wrote "created.. Permissions - ..." for more than half the
|
|
170
|
+
* spec's columns, which the API reference and every client reading the
|
|
171
|
+
* spec showed.
|
|
172
|
+
*/
|
|
173
|
+
static describeColumnWithPermissions(description, permissionsDescription) {
|
|
174
|
+
const words = description.trim();
|
|
175
|
+
if (!permissionsDescription) {
|
|
176
|
+
return words;
|
|
177
|
+
}
|
|
178
|
+
if (!words) {
|
|
179
|
+
return permissionsDescription;
|
|
180
|
+
}
|
|
181
|
+
const endsWithItsOwnPunctuation = SENTENCE_END_PUNCTUATION.some((mark) => {
|
|
182
|
+
return words.endsWith(mark);
|
|
183
|
+
});
|
|
184
|
+
return `${words}${endsWithItsOwnPunctuation ? "" : "."} ${permissionsDescription}`;
|
|
185
|
+
}
|
|
186
|
+
/*
|
|
187
|
+
* The values a text column takes, when it takes one of a few
|
|
188
|
+
* (TableColumn.allowedValues): the spec's enum for the field, each value
|
|
189
|
+
* once - an enum can give two names one value (MimeType's jpg and jpeg).
|
|
190
|
+
*/
|
|
191
|
+
static getAllowedValues(column) {
|
|
192
|
+
if (!column.allowedValues || column.allowedValues.length === 0) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
return Array.from(new Set(column.allowedValues));
|
|
196
|
+
}
|
|
197
|
+
/*
|
|
198
|
+
* A text field's example: its column's own (TableColumn.example), else
|
|
199
|
+
* the first value it takes when it takes one of a few - "aws" for a cloud
|
|
200
|
+
* account's provider - else the placeholder for its type. Clients copy
|
|
201
|
+
* it: the Terraform provider's examples, the API reference, MCP's tool
|
|
202
|
+
* schemas, the Dashboard's Developer pages.
|
|
203
|
+
*/
|
|
204
|
+
static getTextExample(column, placeholder) {
|
|
205
|
+
var _a;
|
|
206
|
+
if (typeof column.example === "string" && column.example.trim()) {
|
|
207
|
+
return column.example;
|
|
208
|
+
}
|
|
209
|
+
return ((_a = ModelSchema.getAllowedValues(column)) === null || _a === void 0 ? void 0 : _a[0]) || placeholder;
|
|
210
|
+
}
|
|
211
|
+
/*
|
|
212
|
+
* What the spec says about a text field's value: a string, its example,
|
|
213
|
+
* and the values it takes when it takes one of a few.
|
|
214
|
+
*/
|
|
215
|
+
static getTextOpenApi(column, placeholder) {
|
|
216
|
+
const allowedValues = ModelSchema.getAllowedValues(column);
|
|
217
|
+
return Object.assign({ type: "string", example: ModelSchema.getTextExample(column, placeholder) }, (allowedValues ? { enum: allowedValues } : {}));
|
|
218
|
+
}
|
|
219
|
+
static getModelSchema(data) {
|
|
220
|
+
const modelType = data.modelType;
|
|
221
|
+
const model = new modelType();
|
|
222
|
+
const columns = (0, TableColumn_1.getTableColumns)(model);
|
|
223
|
+
const shape = {};
|
|
224
|
+
// Get column access control for permission filtering
|
|
225
|
+
const columnAccessControl = model.getColumnAccessControlForAllColumns();
|
|
226
|
+
const relations = this.getRelationReferences(columns);
|
|
227
|
+
for (const key in columns) {
|
|
228
|
+
const column = columns[key];
|
|
229
|
+
if (!column) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
// Skip Entity columns but keep EntityArray columns
|
|
233
|
+
if (column.type === TableColumnType_1.default.Entity) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
// Filter out columns with no permissions (root-only access)
|
|
237
|
+
const accessControl = columnAccessControl[key];
|
|
238
|
+
if (accessControl) {
|
|
239
|
+
// Check if column has any permissions defined for read operation (general schema assumes read access)
|
|
240
|
+
const hasReadPermissions = accessControl.read && accessControl.read.length > 0;
|
|
241
|
+
// If no read permissions are defined, exclude the column from general schema
|
|
242
|
+
if (!hasReadPermissions) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
let zodType;
|
|
247
|
+
if (column.type === TableColumnType_1.default.ObjectID) {
|
|
248
|
+
zodType = (0, TypeSchemas_1.getObjectIDSchema)();
|
|
249
|
+
}
|
|
250
|
+
else if (column.type === TableColumnType_1.default.Color) {
|
|
251
|
+
zodType = (0, TypeSchemas_1.getColorSchema)();
|
|
252
|
+
}
|
|
253
|
+
else if (column.type === TableColumnType_1.default.MonitorSteps) {
|
|
254
|
+
zodType = (0, MonitorSchemas_1.getMonitorStepsSchema)();
|
|
255
|
+
}
|
|
256
|
+
else if (column.type === TableColumnType_1.default.Date) {
|
|
257
|
+
zodType = (0, TypeSchemas_1.getDateSchema)();
|
|
258
|
+
}
|
|
259
|
+
else if (column.type === TableColumnType_1.default.VeryLongText) {
|
|
260
|
+
zodType = Zod_1.default
|
|
261
|
+
.string()
|
|
262
|
+
.openapi(ModelSchema.getTextOpenApi(column, VERY_LONG_TEXT_EXAMPLE));
|
|
263
|
+
}
|
|
264
|
+
else if (column.type === TableColumnType_1.default.Number ||
|
|
265
|
+
column.type === TableColumnType_1.default.PositiveNumber) {
|
|
266
|
+
const openapiConfig = { type: "number", example: 42 };
|
|
267
|
+
if (column.defaultValue !== undefined) {
|
|
268
|
+
openapiConfig.default = column.defaultValue;
|
|
269
|
+
}
|
|
270
|
+
zodType = Zod_1.default.number().openapi(openapiConfig);
|
|
271
|
+
}
|
|
272
|
+
else if (column.type === TableColumnType_1.default.Email) {
|
|
273
|
+
zodType = (0, TypeSchemas_1.getEmailSchema)();
|
|
274
|
+
}
|
|
275
|
+
else if (column.type === TableColumnType_1.default.HashedString) {
|
|
276
|
+
/*
|
|
277
|
+
* format: password marks the field as a secret for spec consumers
|
|
278
|
+
* (the Terraform provider generator emits Sensitive: true for it).
|
|
279
|
+
*/
|
|
280
|
+
zodType = Zod_1.default.string().openapi({
|
|
281
|
+
type: "string",
|
|
282
|
+
format: "password",
|
|
283
|
+
example: "hashed_string_value",
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
else if (column.type === TableColumnType_1.default.Slug) {
|
|
287
|
+
zodType = Zod_1.default
|
|
288
|
+
.string()
|
|
289
|
+
.openapi({ type: "string", example: "example-slug-value" });
|
|
290
|
+
}
|
|
291
|
+
else if (column.type === TableColumnType_1.default.ShortText) {
|
|
292
|
+
const openapiConfig = ModelSchema.getTextOpenApi(column, SHORT_TEXT_EXAMPLE);
|
|
293
|
+
if (column.defaultValue !== undefined) {
|
|
294
|
+
openapiConfig.default = column.defaultValue;
|
|
295
|
+
}
|
|
296
|
+
zodType = Zod_1.default.string().openapi(openapiConfig);
|
|
297
|
+
}
|
|
298
|
+
else if (column.type === TableColumnType_1.default.LongText) {
|
|
299
|
+
const openapiConfig = ModelSchema.getTextOpenApi(column, LONG_TEXT_EXAMPLE);
|
|
300
|
+
if (column.defaultValue !== undefined) {
|
|
301
|
+
openapiConfig.default = column.defaultValue;
|
|
302
|
+
}
|
|
303
|
+
zodType = Zod_1.default.string().openapi(openapiConfig);
|
|
304
|
+
}
|
|
305
|
+
else if (column.type === TableColumnType_1.default.Phone) {
|
|
306
|
+
zodType = (0, TypeSchemas_1.getPhoneSchema)();
|
|
307
|
+
}
|
|
308
|
+
else if (column.type === TableColumnType_1.default.Version) {
|
|
309
|
+
zodType = (0, TypeSchemas_1.getVersionSchema)();
|
|
310
|
+
}
|
|
311
|
+
else if (column.type === TableColumnType_1.default.Password) {
|
|
312
|
+
zodType = Zod_1.default.string().openapi({
|
|
313
|
+
type: "string",
|
|
314
|
+
format: "password",
|
|
315
|
+
example: "••••••••",
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else if (column.type === TableColumnType_1.default.Name) {
|
|
319
|
+
zodType = (0, TypeSchemas_1.getNameSchema)();
|
|
320
|
+
}
|
|
321
|
+
else if (column.type === TableColumnType_1.default.Description) {
|
|
322
|
+
zodType = Zod_1.default.string().openapi({
|
|
323
|
+
type: "string",
|
|
324
|
+
example: "This is a description of the item",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
else if (column.type === TableColumnType_1.default.File) {
|
|
328
|
+
zodType = Zod_1.default.any().openapi({
|
|
329
|
+
type: "string",
|
|
330
|
+
format: "binary",
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
else if (column.type === TableColumnType_1.default.Buffer) {
|
|
334
|
+
zodType = Zod_1.default.any().openapi({
|
|
335
|
+
type: "string",
|
|
336
|
+
format: "binary",
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
else if (column.type === TableColumnType_1.default.ShortURL) {
|
|
340
|
+
zodType = Zod_1.default.string().url().openapi({
|
|
341
|
+
type: "string",
|
|
342
|
+
example: "https://short.url/abc123",
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
else if (column.type === TableColumnType_1.default.Markdown) {
|
|
346
|
+
zodType = Zod_1.default.string().openapi({
|
|
347
|
+
type: "string",
|
|
348
|
+
example: "# Heading\n\nThis is **markdown** content",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
else if (column.type === TableColumnType_1.default.Domain) {
|
|
352
|
+
zodType = (0, TypeSchemas_1.getDomainSchema)();
|
|
353
|
+
}
|
|
354
|
+
else if (column.type === TableColumnType_1.default.Port) {
|
|
355
|
+
zodType = (0, TypeSchemas_1.getPortSchema)();
|
|
356
|
+
}
|
|
357
|
+
else if (column.type === TableColumnType_1.default.IP) {
|
|
358
|
+
zodType = (0, TypeSchemas_1.getIPSchema)();
|
|
359
|
+
}
|
|
360
|
+
else if (column.type === TableColumnType_1.default.LongURL) {
|
|
361
|
+
zodType = Zod_1.default.string().url().openapi({
|
|
362
|
+
type: "string",
|
|
363
|
+
example: "https://www.example.com/path/to/resource?param=value",
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
else if (column.type === TableColumnType_1.default.OTP) {
|
|
367
|
+
zodType = Zod_1.default.string().openapi({
|
|
368
|
+
type: "string",
|
|
369
|
+
example: "123456",
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
else if (column.type === TableColumnType_1.default.HTML) {
|
|
373
|
+
zodType = Zod_1.default.string().openapi({
|
|
374
|
+
type: "string",
|
|
375
|
+
example: "<div><h1>Title</h1><p>Content</p></div>",
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
else if (column.type === TableColumnType_1.default.JavaScript) {
|
|
379
|
+
zodType = Zod_1.default.string().openapi({
|
|
380
|
+
type: "string",
|
|
381
|
+
example: "function example() { return true; }",
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
else if (column.type === TableColumnType_1.default.CSS) {
|
|
385
|
+
zodType = Zod_1.default.string().openapi({
|
|
386
|
+
type: "string",
|
|
387
|
+
example: "body { color: #333; margin: 0; }",
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
else if (column.type === TableColumnType_1.default.Array) {
|
|
391
|
+
zodType = Zod_1.default.array(Zod_1.default.any()).openapi({
|
|
392
|
+
type: "array",
|
|
393
|
+
items: {
|
|
394
|
+
type: "string",
|
|
395
|
+
},
|
|
396
|
+
"x-ordered": column.ordered === true,
|
|
397
|
+
example: ["item1", "item2", "item3"],
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
else if (column.type === TableColumnType_1.default.SmallPositiveNumber) {
|
|
401
|
+
const openapiConfig = {
|
|
402
|
+
type: "integer",
|
|
403
|
+
example: 5,
|
|
404
|
+
};
|
|
405
|
+
if (column.defaultValue !== undefined) {
|
|
406
|
+
openapiConfig.default = column.defaultValue;
|
|
407
|
+
}
|
|
408
|
+
zodType = Zod_1.default.number().int().nonnegative().openapi(openapiConfig);
|
|
409
|
+
}
|
|
410
|
+
else if (column.type === TableColumnType_1.default.BigPositiveNumber) {
|
|
411
|
+
const openapiConfig = {
|
|
412
|
+
type: "number",
|
|
413
|
+
example: 1000000,
|
|
414
|
+
};
|
|
415
|
+
if (column.defaultValue !== undefined) {
|
|
416
|
+
openapiConfig.default = column.defaultValue;
|
|
417
|
+
}
|
|
418
|
+
zodType = Zod_1.default.number().nonnegative().openapi(openapiConfig);
|
|
419
|
+
}
|
|
420
|
+
else if (column.type === TableColumnType_1.default.SmallNumber) {
|
|
421
|
+
const openapiConfig = {
|
|
422
|
+
type: "integer",
|
|
423
|
+
example: 10,
|
|
424
|
+
};
|
|
425
|
+
if (column.defaultValue !== undefined) {
|
|
426
|
+
openapiConfig.default = column.defaultValue;
|
|
427
|
+
}
|
|
428
|
+
zodType = Zod_1.default.number().int().openapi(openapiConfig);
|
|
429
|
+
}
|
|
430
|
+
else if (column.type === TableColumnType_1.default.BigNumber) {
|
|
431
|
+
const openapiConfig = {
|
|
432
|
+
type: "number",
|
|
433
|
+
example: 1000000,
|
|
434
|
+
};
|
|
435
|
+
if (column.defaultValue !== undefined) {
|
|
436
|
+
openapiConfig.default = column.defaultValue;
|
|
437
|
+
}
|
|
438
|
+
zodType = Zod_1.default.number().openapi(openapiConfig);
|
|
439
|
+
}
|
|
440
|
+
else if (column.type === TableColumnType_1.default.Permission) {
|
|
441
|
+
zodType = Zod_1.default.any().openapi({
|
|
442
|
+
type: "object",
|
|
443
|
+
example: { read: true, write: false, delete: false },
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
else if (column.type === TableColumnType_1.default.CustomFieldType) {
|
|
447
|
+
// What a custom field holds: "Text", "Number", "Dropdown"...
|
|
448
|
+
zodType = Zod_1.default.string().openapi({
|
|
449
|
+
type: "string",
|
|
450
|
+
enum: Object.values(CustomFieldType_1.default),
|
|
451
|
+
example: CustomFieldType_1.default.Text,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
else if (column.type === TableColumnType_1.default.MonitorType) {
|
|
455
|
+
zodType = Zod_1.default.string().openapi({
|
|
456
|
+
type: "string",
|
|
457
|
+
enum: Object.values(MonitorType_1.default),
|
|
458
|
+
example: MonitorType_1.default.Manual,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
else if (column.type === TableColumnType_1.default.WorkflowStatus) {
|
|
462
|
+
zodType = Zod_1.default.string().openapi({
|
|
463
|
+
type: "string",
|
|
464
|
+
enum: Object.values(WorkflowStatus_1.default),
|
|
465
|
+
example: "In Progress",
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
else if (column.type === TableColumnType_1.default.Boolean) {
|
|
469
|
+
const openapiConfig = { type: "boolean", example: true };
|
|
470
|
+
if (column.defaultValue !== undefined) {
|
|
471
|
+
openapiConfig.default = column.defaultValue;
|
|
472
|
+
}
|
|
473
|
+
zodType = Zod_1.default.boolean().openapi(openapiConfig);
|
|
474
|
+
}
|
|
475
|
+
else if (column.type === TableColumnType_1.default.JSON) {
|
|
476
|
+
zodType = Zod_1.default.any().openapi({
|
|
477
|
+
type: "object",
|
|
478
|
+
example: { key: "value", nested: { data: 123 } },
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
else if (column.type === TableColumnType_1.default.EntityArray) {
|
|
482
|
+
const entityArrayType = column.modelType;
|
|
483
|
+
if (!entityArrayType) {
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
zodType = Zod_1.default
|
|
487
|
+
.array(Zod_1.default.lazy(() => {
|
|
488
|
+
return ModelSchema.getModelSchema({
|
|
489
|
+
modelType: entityArrayType,
|
|
490
|
+
});
|
|
491
|
+
}))
|
|
492
|
+
.openapi({
|
|
493
|
+
type: "array",
|
|
494
|
+
items: {
|
|
495
|
+
type: "object",
|
|
496
|
+
properties: {
|
|
497
|
+
_id: {
|
|
498
|
+
type: "string",
|
|
499
|
+
format: "uuid",
|
|
500
|
+
description: "Unique identifier for the entity",
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
"x-ordered": column.ordered === true,
|
|
505
|
+
example: [
|
|
506
|
+
{
|
|
507
|
+
_id: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
|
|
508
|
+
},
|
|
509
|
+
],
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
else if (column.type === TableColumnType_1.default.Entity) {
|
|
513
|
+
const entityType = column.modelType;
|
|
514
|
+
if (!entityType) {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
const schema = ModelSchema.getModelSchema({
|
|
518
|
+
modelType: entityType,
|
|
519
|
+
});
|
|
520
|
+
zodType = Zod_1.default
|
|
521
|
+
.lazy(() => {
|
|
522
|
+
return schema;
|
|
523
|
+
})
|
|
524
|
+
.openapi({
|
|
525
|
+
type: "object",
|
|
526
|
+
properties: {
|
|
527
|
+
_id: {
|
|
528
|
+
type: "string",
|
|
529
|
+
format: "uuid",
|
|
530
|
+
description: "Unique identifier for the entity",
|
|
531
|
+
example: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
example: {
|
|
535
|
+
_id: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
// Fallback for unknown column types - use a generic object type
|
|
541
|
+
zodType = Zod_1.default.any().openapi({
|
|
542
|
+
type: "object",
|
|
543
|
+
description: "Unknown type field",
|
|
544
|
+
example: null,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (column.required) {
|
|
548
|
+
// leave as is
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
zodType = zodType.optional();
|
|
552
|
+
}
|
|
553
|
+
// add title and description to the schema
|
|
554
|
+
let finalDescription = "";
|
|
555
|
+
// Add column description first if it exists
|
|
556
|
+
if (column.description) {
|
|
557
|
+
finalDescription = column.description;
|
|
558
|
+
}
|
|
559
|
+
else if (column.title) {
|
|
560
|
+
finalDescription = column.title;
|
|
561
|
+
}
|
|
562
|
+
// The column's description, then who may read and write it.
|
|
563
|
+
finalDescription = ModelSchema.describeColumnWithPermissions(finalDescription, this.getColumnPermissionsDescription(model, key));
|
|
564
|
+
// Set the final combined description
|
|
565
|
+
zodType = this.annotateColumn({
|
|
566
|
+
zodType: zodType,
|
|
567
|
+
description: finalDescription,
|
|
568
|
+
relation: relations[key],
|
|
569
|
+
});
|
|
570
|
+
// Mark computed fields as readOnly in OpenAPI spec
|
|
571
|
+
if (column.computed) {
|
|
572
|
+
zodType = zodType.openapi({ readOnly: true });
|
|
573
|
+
}
|
|
574
|
+
// A secret, as getZodTypeForColumn says too.
|
|
575
|
+
zodType = ModelSchema.annotateSecret(zodType, column);
|
|
576
|
+
shape[key] = zodType;
|
|
577
|
+
}
|
|
578
|
+
const schema = Zod_1.default.object(shape);
|
|
579
|
+
return schema;
|
|
580
|
+
}
|
|
581
|
+
/*
|
|
582
|
+
* A column's own documentation, set where the generated spec reads it.
|
|
583
|
+
*
|
|
584
|
+
* `.describe()` alone loses to a type that brings a description of its own
|
|
585
|
+
* in its openapi metadata - ObjectID ("A unique identifier for an object,
|
|
586
|
+
* represented as a UUID") and Date ("A date time object") among them - so
|
|
587
|
+
* every id and date column of every model was documented as nothing but its
|
|
588
|
+
* type. Setting it as openapi metadata as well lets the column's words win.
|
|
589
|
+
*
|
|
590
|
+
* A relation's id column and a relation list also name the model they point
|
|
591
|
+
* at (`x-oneuptime-relation`): `tag` is the name that model's endpoints are
|
|
592
|
+
* tagged with, so a client generated from the spec - the Terraform provider
|
|
593
|
+
* - can say which of its resources an id belongs to.
|
|
594
|
+
*/
|
|
595
|
+
static annotateColumn(data) {
|
|
596
|
+
let zodType = data.zodType;
|
|
597
|
+
if (data.description) {
|
|
598
|
+
zodType = zodType.describe(data.description);
|
|
599
|
+
}
|
|
600
|
+
if (data.disableOpenApiSchema) {
|
|
601
|
+
return zodType;
|
|
602
|
+
}
|
|
603
|
+
if (data.description) {
|
|
604
|
+
zodType = zodType.openapi({ description: data.description });
|
|
605
|
+
}
|
|
606
|
+
if (data.relation) {
|
|
607
|
+
zodType = zodType.openapi({
|
|
608
|
+
"x-oneuptime-relation": data.relation,
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
return zodType;
|
|
612
|
+
}
|
|
613
|
+
/*
|
|
614
|
+
* The model each relation of `columns` points at, keyed by the column a
|
|
615
|
+
* caller writes: a many-to-one relation's id column (`labelId` for
|
|
616
|
+
* `label`), and a relation list itself (`labels`).
|
|
617
|
+
*/
|
|
618
|
+
static getRelationReferences(columns) {
|
|
619
|
+
const references = {};
|
|
620
|
+
for (const key in columns) {
|
|
621
|
+
const column = columns[key];
|
|
622
|
+
if (!(column === null || column === void 0 ? void 0 : column.modelType)) {
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
let columnKey = undefined;
|
|
626
|
+
if (column.type === TableColumnType_1.default.Entity &&
|
|
627
|
+
column.manyToOneRelationColumn) {
|
|
628
|
+
columnKey = column.manyToOneRelationColumn;
|
|
629
|
+
}
|
|
630
|
+
else if (column.type === TableColumnType_1.default.EntityArray) {
|
|
631
|
+
columnKey = key;
|
|
632
|
+
}
|
|
633
|
+
if (!columnKey) {
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
const target = new column.modelType();
|
|
637
|
+
const tableName = target.tableName;
|
|
638
|
+
if (!tableName) {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
references[columnKey] = {
|
|
642
|
+
tag: target.singularName || tableName,
|
|
643
|
+
tableName: tableName,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return references;
|
|
647
|
+
}
|
|
648
|
+
static getSortableTypes() {
|
|
649
|
+
return [
|
|
650
|
+
TableColumnType_1.default.VeryLongText,
|
|
651
|
+
TableColumnType_1.default.Slug,
|
|
652
|
+
TableColumnType_1.default.ShortText,
|
|
653
|
+
TableColumnType_1.default.LongText,
|
|
654
|
+
TableColumnType_1.default.Number,
|
|
655
|
+
TableColumnType_1.default.Date,
|
|
656
|
+
TableColumnType_1.default.Boolean,
|
|
657
|
+
TableColumnType_1.default.Description,
|
|
658
|
+
TableColumnType_1.default.ObjectID,
|
|
659
|
+
];
|
|
660
|
+
}
|
|
661
|
+
/*
|
|
662
|
+
* The columns a query may name, each referring to its type's filter
|
|
663
|
+
* (getQueryFilterSchema).
|
|
664
|
+
*
|
|
665
|
+
* Neither this object's .openapi() nor a field's names a `type`:
|
|
666
|
+
* zod-to-openapi takes a `type` there for the whole schema and leaves out
|
|
667
|
+
* the properties and operators it would have generated, so the spec listed
|
|
668
|
+
* no field of any query at all.
|
|
669
|
+
*
|
|
670
|
+
* Other keys are not refused: a query also filters a record by the fields
|
|
671
|
+
* of a record its relation names, and one with owners by who owns it
|
|
672
|
+
* (QueryPermission checks both), as the API reference describes.
|
|
673
|
+
*/
|
|
674
|
+
static getQueryModelSchema(data) {
|
|
675
|
+
const model = new data.modelType();
|
|
676
|
+
const columns = this.getReadableColumns(model);
|
|
677
|
+
const shape = {};
|
|
678
|
+
for (const { key, column } of columns) {
|
|
679
|
+
shape[key] = this.getQueryFilterSchema(column.type).optional();
|
|
680
|
+
}
|
|
681
|
+
return this.applyOpenApi(Zod_1.default.object(shape), {
|
|
682
|
+
description: `Query schema for ${model.tableName || "model"}. A field takes a value, which it matches exactly, or an operator its type allows. A relation is filtered by the fields of the record it names, {"<relation>": {"<field>": <value or Search>}}, and a resource with owners by who owns it, {"owners": {"_type": "OwnedBy", "userIds": [...], "teamIds": [...]}}.`,
|
|
683
|
+
example: this.getQuerySchemaExample(columns),
|
|
684
|
+
}, data.disableOpenApiSchema || false);
|
|
685
|
+
}
|
|
686
|
+
/*
|
|
687
|
+
* The operators a query can use on a column of this type - on a JSON
|
|
688
|
+
* column, on each of its keys.
|
|
689
|
+
*/
|
|
690
|
+
static getValidOperatorsForColumnType(columnType) {
|
|
691
|
+
return OPERATORS_BY_COLUMN_TYPE[columnType] || COMMON_OPERATORS;
|
|
692
|
+
}
|
|
693
|
+
/*
|
|
694
|
+
* What a query field of this type takes: a value, which it matches exactly,
|
|
695
|
+
* or one of its operators. Built once for each type and published as a
|
|
696
|
+
* schema of its own, <Type>Filter, that every query field of the type
|
|
697
|
+
* refers to: spelled out on each of the 7,700 query fields, the operators
|
|
698
|
+
* would have made most of the spec, and a client generated from it would
|
|
699
|
+
* have had a type for each.
|
|
700
|
+
*/
|
|
701
|
+
static getQueryFilterSchema(columnType) {
|
|
702
|
+
let filter = QUERY_FILTER_SCHEMAS.get(columnType);
|
|
703
|
+
if (filter) {
|
|
704
|
+
return filter;
|
|
705
|
+
}
|
|
706
|
+
const operators = this.getValidOperatorsForColumnType(columnType);
|
|
707
|
+
const value = this.getQueryValueSchema(columnType);
|
|
708
|
+
/*
|
|
709
|
+
* A JSON column is filtered by key. IsNull and NotNull on the column
|
|
710
|
+
* itself ask whether it holds anything; any other operator there would
|
|
711
|
+
* be read as a key of its own.
|
|
712
|
+
*/
|
|
713
|
+
filter =
|
|
714
|
+
columnType === TableColumnType_1.default.JSON
|
|
715
|
+
? Zod_1.default.union([
|
|
716
|
+
this.getOperatorSchema("IsNull", value),
|
|
717
|
+
this.getOperatorSchema("NotNull", value),
|
|
718
|
+
Zod_1.default
|
|
719
|
+
.object({})
|
|
720
|
+
.catchall(this.getValueOrOperatorSchema(columnType, operators)),
|
|
721
|
+
])
|
|
722
|
+
: this.getValueOrOperatorSchema(columnType, operators);
|
|
723
|
+
filter = filter.openapi(`${this.getColumnTypeKey(columnType)}Filter`, {
|
|
724
|
+
description: this.getQueryFilterDescription(columnType, operators),
|
|
725
|
+
example: this.getQueryFilterExample(columnType),
|
|
726
|
+
});
|
|
727
|
+
QUERY_FILTER_SCHEMAS.set(columnType, filter);
|
|
728
|
+
return filter;
|
|
729
|
+
}
|
|
730
|
+
/*
|
|
731
|
+
* A value, which matches exactly, or one of the operators. A relation
|
|
732
|
+
* list's value is a list of ids, which matches the records related to any
|
|
733
|
+
* of them.
|
|
734
|
+
*/
|
|
735
|
+
static getValueOrOperatorSchema(columnType, operators) {
|
|
736
|
+
const value = this.getQueryValueSchema(columnType);
|
|
737
|
+
const branches = [];
|
|
738
|
+
for (const operator of operators) {
|
|
739
|
+
if (operator === "EqualTo" &&
|
|
740
|
+
columnType === TableColumnType_1.default.EntityArray) {
|
|
741
|
+
branches.push(Zod_1.default.array(value));
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (operator === "EqualTo") {
|
|
745
|
+
branches.push(value);
|
|
746
|
+
}
|
|
747
|
+
branches.push(this.getOperatorSchema(operator, value));
|
|
748
|
+
}
|
|
749
|
+
return branches.length === 1
|
|
750
|
+
? branches[0]
|
|
751
|
+
: Zod_1.default.union(branches);
|
|
752
|
+
}
|
|
753
|
+
// An operator as JSONFunctions.deserialize reads it on the API.
|
|
754
|
+
static getOperatorSchema(operator, value) {
|
|
755
|
+
switch (operator) {
|
|
756
|
+
case "IsNull":
|
|
757
|
+
case "NotNull":
|
|
758
|
+
return Zod_1.default.object({ _type: Zod_1.default.literal(operator) });
|
|
759
|
+
case "InBetween":
|
|
760
|
+
return Zod_1.default.object({
|
|
761
|
+
_type: Zod_1.default.literal(operator),
|
|
762
|
+
startValue: value,
|
|
763
|
+
endValue: value,
|
|
764
|
+
});
|
|
765
|
+
case "Includes":
|
|
766
|
+
return Zod_1.default.object({ _type: Zod_1.default.literal(operator), value: Zod_1.default.array(value) });
|
|
767
|
+
case "Search":
|
|
768
|
+
return Zod_1.default.object({ _type: Zod_1.default.literal(operator), value: Zod_1.default.string() });
|
|
769
|
+
default:
|
|
770
|
+
return Zod_1.default.object({ _type: Zod_1.default.literal(operator), value: value });
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/*
|
|
774
|
+
* What a query compares a column of this type with, as JSON carries it: on
|
|
775
|
+
* a relation list, one of its ids; on a JSON column, a key's value. Always
|
|
776
|
+
* the plain value, never the {_type, value} a response writes for an
|
|
777
|
+
* email, a name or a color: inside an operator the API binds that as
|
|
778
|
+
* "[object Object]".
|
|
779
|
+
*/
|
|
780
|
+
static getQueryValueSchema(columnType) {
|
|
781
|
+
switch (columnType) {
|
|
782
|
+
case TableColumnType_1.default.ObjectID:
|
|
783
|
+
case TableColumnType_1.default.Entity:
|
|
784
|
+
case TableColumnType_1.default.EntityArray:
|
|
785
|
+
return Zod_1.default.string().openapi({ format: "uuid" });
|
|
786
|
+
case TableColumnType_1.default.Email:
|
|
787
|
+
return Zod_1.default.string().openapi({ format: "email" });
|
|
788
|
+
case TableColumnType_1.default.Date:
|
|
789
|
+
return Zod_1.default.string().openapi({ format: "date-time" });
|
|
790
|
+
case TableColumnType_1.default.Number:
|
|
791
|
+
case TableColumnType_1.default.PositiveNumber:
|
|
792
|
+
case TableColumnType_1.default.SmallNumber:
|
|
793
|
+
case TableColumnType_1.default.SmallPositiveNumber:
|
|
794
|
+
case TableColumnType_1.default.BigNumber:
|
|
795
|
+
case TableColumnType_1.default.BigPositiveNumber:
|
|
796
|
+
case TableColumnType_1.default.Port:
|
|
797
|
+
return Zod_1.default.number();
|
|
798
|
+
case TableColumnType_1.default.Boolean:
|
|
799
|
+
return Zod_1.default.boolean();
|
|
800
|
+
case TableColumnType_1.default.JSON:
|
|
801
|
+
return Zod_1.default.union([Zod_1.default.string(), Zod_1.default.number(), Zod_1.default.boolean()]);
|
|
802
|
+
default:
|
|
803
|
+
return Zod_1.default.string();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
static getQueryFilterDescription(columnType, operators) {
|
|
807
|
+
if (columnType === TableColumnType_1.default.JSON) {
|
|
808
|
+
return `A filter on a ${columnType} field, by key: {"<field>": {"<key>": <value or operator>}}. A key takes a value, which it matches exactly, or one of these operators: ${operators.join(", ")}. IsNull and NotNull on the field itself ask whether it holds anything.`;
|
|
809
|
+
}
|
|
810
|
+
if (!operators.includes("EqualTo")) {
|
|
811
|
+
return `A filter on a ${columnType} field: only whether it holds anything can be asked, with ${operators.join(" or ")}.`;
|
|
812
|
+
}
|
|
813
|
+
let description = `A filter on a ${columnType} field: a value, which it matches exactly, or one of these operators: ${operators.join(", ")}.`;
|
|
814
|
+
if (columnType === TableColumnType_1.default.EntityArray) {
|
|
815
|
+
description +=
|
|
816
|
+
" A list of ids, or Includes, matches the records related to any of them; IsNull those related to none.";
|
|
817
|
+
}
|
|
818
|
+
else if (columnType === TableColumnType_1.default.Date) {
|
|
819
|
+
description += ` Times are ISO-8601, such as ${EXAMPLE_TIME}.`;
|
|
820
|
+
}
|
|
821
|
+
return description;
|
|
822
|
+
}
|
|
823
|
+
static getQueryFilterExample(columnType) {
|
|
824
|
+
const operators = this.getValidOperatorsForColumnType(columnType);
|
|
825
|
+
if (columnType === TableColumnType_1.default.JSON) {
|
|
826
|
+
return { key: "value" };
|
|
827
|
+
}
|
|
828
|
+
if (columnType === TableColumnType_1.default.EntityArray) {
|
|
829
|
+
return [EXAMPLE_ID];
|
|
830
|
+
}
|
|
831
|
+
if (operators.includes("Search")) {
|
|
832
|
+
return { _type: "Search", value: "example" };
|
|
833
|
+
}
|
|
834
|
+
if (operators.includes("GreaterThan")) {
|
|
835
|
+
return {
|
|
836
|
+
_type: "GreaterThan",
|
|
837
|
+
value: columnType === TableColumnType_1.default.Date ? EXAMPLE_TIME : 10,
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
switch (columnType) {
|
|
841
|
+
case TableColumnType_1.default.ObjectID:
|
|
842
|
+
return EXAMPLE_ID;
|
|
843
|
+
case TableColumnType_1.default.Boolean:
|
|
844
|
+
return true;
|
|
845
|
+
case TableColumnType_1.default.Email:
|
|
846
|
+
return "user@example.com";
|
|
847
|
+
default:
|
|
848
|
+
return { _type: "NotNull" };
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
// A column type as an identifier: its key in TableColumnType.
|
|
852
|
+
static getColumnTypeKey(columnType) {
|
|
853
|
+
return (Object.keys(TableColumnType_1.default).find((key) => {
|
|
854
|
+
return (TableColumnType_1.default[key] === columnType);
|
|
855
|
+
}) || "Unknown");
|
|
856
|
+
}
|
|
857
|
+
/*
|
|
858
|
+
* The columns of a model a query, sort or select may name, as the API
|
|
859
|
+
* checks them (QueryPermission, SelectPermission): those somebody may
|
|
860
|
+
* read, and the ids and times it lets through all the same. Not a
|
|
861
|
+
* relation, which is filtered and selected through its own fields, nor a
|
|
862
|
+
* column the documentation hides.
|
|
863
|
+
*/
|
|
864
|
+
static getReadableColumns(model) {
|
|
865
|
+
var _a;
|
|
866
|
+
const columns = (0, TableColumn_1.getTableColumns)(model);
|
|
867
|
+
const accessControl = model.getColumnAccessControlForAllColumns();
|
|
868
|
+
const readable = [];
|
|
869
|
+
for (const key in columns) {
|
|
870
|
+
const column = columns[key];
|
|
871
|
+
if (!column ||
|
|
872
|
+
column.type === TableColumnType_1.default.Entity ||
|
|
873
|
+
column.hideColumnInDocumentation) {
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (BaseSchema_1.ALWAYS_READABLE_COLUMNS.includes(key) ||
|
|
877
|
+
(((_a = accessControl[key]) === null || _a === void 0 ? void 0 : _a.read) || []).length > 0) {
|
|
878
|
+
readable.push({ key, column });
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return readable;
|
|
882
|
+
}
|
|
883
|
+
static getSortModelSchema(data) {
|
|
884
|
+
const modelType = data.modelType;
|
|
885
|
+
const model = new modelType();
|
|
886
|
+
return this.generateSortSchema({
|
|
887
|
+
model,
|
|
888
|
+
tableName: model.tableName || "model",
|
|
889
|
+
getSortableTypes: () => {
|
|
890
|
+
return this.getSortableTypes();
|
|
891
|
+
},
|
|
892
|
+
getColumnsForSorting: (model) => {
|
|
893
|
+
return this.getReadableColumns(model).map(({ key, column }) => {
|
|
894
|
+
return { key, type: column.type };
|
|
895
|
+
});
|
|
896
|
+
},
|
|
897
|
+
disableOpenApiSchema: data.disableOpenApiSchema || false,
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
static getSelectModelSchema(data) {
|
|
901
|
+
const modelType = data.modelType;
|
|
902
|
+
const model = new modelType();
|
|
903
|
+
return this.generateSelectSchema({
|
|
904
|
+
model,
|
|
905
|
+
tableName: model.tableName || "model",
|
|
906
|
+
getColumns: (model) => {
|
|
907
|
+
return this.getReadableColumns(model).map(({ key, column }) => {
|
|
908
|
+
return { key, type: column.type };
|
|
909
|
+
});
|
|
910
|
+
},
|
|
911
|
+
getSelectSchemaExample: () => {
|
|
912
|
+
return this.getSelectSchemaExample(modelType);
|
|
913
|
+
},
|
|
914
|
+
allowNested: true,
|
|
915
|
+
getNestedSchema: (key, model) => {
|
|
916
|
+
const column = (0, TableColumn_1.getTableColumns)(model)[key];
|
|
917
|
+
if (column &&
|
|
918
|
+
column.modelType &&
|
|
919
|
+
column.type === TableColumnType_1.default.EntityArray) {
|
|
920
|
+
return this.getRelationSelectSchema(column.modelType);
|
|
921
|
+
}
|
|
922
|
+
return null;
|
|
923
|
+
},
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
/*
|
|
927
|
+
* What a select may name of the records a relation list holds, as the API
|
|
928
|
+
* checks it (QueryPermission.checkRelationQueryPermission): their ids and
|
|
929
|
+
* times, and the columns marked canReadOnRelationQuery. Built once for each
|
|
930
|
+
* model and published as <Table>RelationSelectSchema, which every relation
|
|
931
|
+
* list of its records refers to.
|
|
932
|
+
*/
|
|
933
|
+
static getRelationSelectSchema(modelType) {
|
|
934
|
+
var _a;
|
|
935
|
+
const model = new modelType();
|
|
936
|
+
const tableName = model.tableName || "model";
|
|
937
|
+
let schema = RELATION_SELECT_SCHEMAS.get(tableName);
|
|
938
|
+
if (schema) {
|
|
939
|
+
return schema;
|
|
940
|
+
}
|
|
941
|
+
const columns = (0, TableColumn_1.getTableColumns)(model);
|
|
942
|
+
const shape = {};
|
|
943
|
+
for (const key in columns) {
|
|
944
|
+
const column = columns[key];
|
|
945
|
+
if (!column ||
|
|
946
|
+
column.type === TableColumnType_1.default.Entity ||
|
|
947
|
+
column.type === TableColumnType_1.default.EntityArray ||
|
|
948
|
+
column.hideColumnInDocumentation) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
/*
|
|
952
|
+
* An id or a time is read with the model's own read permissions, which
|
|
953
|
+
* a model read through other records only (a File) does not have.
|
|
954
|
+
*/
|
|
955
|
+
const readers = ((_a = model.getColumnAccessControlFor(key)) === null || _a === void 0 ? void 0 : _a.read) ||
|
|
956
|
+
model.getReadPermissions() ||
|
|
957
|
+
[];
|
|
958
|
+
if (column.canReadOnRelationQuery ||
|
|
959
|
+
(BaseSchema_1.ALWAYS_READABLE_COLUMNS.includes(key) && readers.length > 0)) {
|
|
960
|
+
shape[key] = Zod_1.default.boolean().optional();
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
schema = Zod_1.default.object(shape).openapi(`${tableName}RelationSelectSchema`, {
|
|
964
|
+
description: `What a select may name of the ${tableName} records a relation holds: set a field to true to include it.`,
|
|
965
|
+
example: shape["_id"] ? { _id: true } : {},
|
|
966
|
+
additionalProperties: false,
|
|
967
|
+
});
|
|
968
|
+
RELATION_SELECT_SCHEMAS.set(tableName, schema);
|
|
969
|
+
return schema;
|
|
970
|
+
}
|
|
971
|
+
/*
|
|
972
|
+
* Records of a database table are not grouped: DatabaseService.findBy
|
|
973
|
+
* refuses any groupBy ("GroupBy is currently not supported"), so no field
|
|
974
|
+
* is offered, and no path of the spec refers to this schema.
|
|
975
|
+
*/
|
|
976
|
+
static getGroupByModelSchema(data) {
|
|
977
|
+
const model = new data.modelType();
|
|
978
|
+
return Zod_1.default.object({}).openapi({
|
|
979
|
+
description: `Group by schema for ${model.tableName || "model"}. Its records cannot be grouped: the API refuses a groupBy on them.`,
|
|
980
|
+
example: {},
|
|
981
|
+
additionalProperties: false,
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
// A query on a record's age and on words in it, where the model has them.
|
|
985
|
+
static getQuerySchemaExample(columns) {
|
|
986
|
+
const example = {};
|
|
987
|
+
const createdAt = columns.find(({ key }) => {
|
|
988
|
+
return key === "createdAt";
|
|
989
|
+
});
|
|
990
|
+
const searchable = columns.find(({ column }) => {
|
|
991
|
+
return this.getValidOperatorsForColumnType(column.type).includes("Search");
|
|
992
|
+
});
|
|
993
|
+
for (const field of [createdAt, searchable]) {
|
|
994
|
+
if (field) {
|
|
995
|
+
example[field.key] = this.getQueryFilterExample(field.column.type);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
if (Object.keys(example).length === 0 && columns[0]) {
|
|
999
|
+
example[columns[0].key] = this.getQueryFilterExample(columns[0].column.type);
|
|
1000
|
+
}
|
|
1001
|
+
return example;
|
|
1002
|
+
}
|
|
1003
|
+
static getSelectSchemaExample(modelType) {
|
|
1004
|
+
if (!modelType) {
|
|
1005
|
+
throw new BadDataException_1.default("Model type is required to generate select schema example.");
|
|
1006
|
+
}
|
|
1007
|
+
const model = new modelType();
|
|
1008
|
+
const columns = this.getReadableColumns(model);
|
|
1009
|
+
const example = {};
|
|
1010
|
+
// Add common fields that most models have
|
|
1011
|
+
const commonFields = ["_id", "createdAt", "updatedAt"];
|
|
1012
|
+
for (const { key } of columns) {
|
|
1013
|
+
if (commonFields.includes(key)) {
|
|
1014
|
+
example[key] = true;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
// Add first few non-common fields as examples
|
|
1018
|
+
let fieldCount = 0;
|
|
1019
|
+
const maxFields = 5;
|
|
1020
|
+
for (const { key, column } of columns) {
|
|
1021
|
+
if (fieldCount >= maxFields) {
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
if (commonFields.includes(key)) {
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
// Prioritize fields that are likely to be commonly selected
|
|
1028
|
+
if (column.type === TableColumnType_1.default.ShortText ||
|
|
1029
|
+
column.type === TableColumnType_1.default.Name ||
|
|
1030
|
+
column.type === TableColumnType_1.default.Email ||
|
|
1031
|
+
column.type === TableColumnType_1.default.Description) {
|
|
1032
|
+
example[key] = true;
|
|
1033
|
+
fieldCount++;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return example;
|
|
1037
|
+
}
|
|
1038
|
+
// Shared method to build model schemas with different field exclusions
|
|
1039
|
+
static buildModelSchema(data) {
|
|
1040
|
+
var _a;
|
|
1041
|
+
const modelType = data.modelType;
|
|
1042
|
+
const model = new modelType();
|
|
1043
|
+
const columns = (0, TableColumn_1.getTableColumns)(model);
|
|
1044
|
+
const shape = {};
|
|
1045
|
+
// Get column access control for permission filtering
|
|
1046
|
+
const columnAccessControl = model.getColumnAccessControlForAllColumns();
|
|
1047
|
+
const relations = this.getRelationReferences(columns);
|
|
1048
|
+
for (const key in columns) {
|
|
1049
|
+
const column = columns[key];
|
|
1050
|
+
if (!column) {
|
|
1051
|
+
continue;
|
|
1052
|
+
}
|
|
1053
|
+
if (column.hideColumnInDocumentation) {
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
// Skip Entity columns but keep EntityArray columns
|
|
1057
|
+
if (column.type === TableColumnType_1.default.Entity) {
|
|
1058
|
+
continue;
|
|
1059
|
+
}
|
|
1060
|
+
// Skip excluded fields
|
|
1061
|
+
if (data.excludedFields && data.excludedFields.includes(key)) {
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
// Only include specified fields if includedFields is provided
|
|
1065
|
+
if (data.includedFields && !data.includedFields.includes(key)) {
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1068
|
+
// Skip computed fields for create and update operations
|
|
1069
|
+
if (column.computed &&
|
|
1070
|
+
(data.schemaType === "create" || data.schemaType === "update")) {
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
// Filter out columns with no permissions (root-only access)
|
|
1074
|
+
const accessControl = columnAccessControl[key];
|
|
1075
|
+
if (accessControl) {
|
|
1076
|
+
let hasPermissions = false;
|
|
1077
|
+
// Check if column has any permissions defined for the current operation
|
|
1078
|
+
if (data.schemaType === "create" &&
|
|
1079
|
+
accessControl.create &&
|
|
1080
|
+
accessControl.create.length > 0) {
|
|
1081
|
+
hasPermissions = true;
|
|
1082
|
+
}
|
|
1083
|
+
else if (data.schemaType === "read" &&
|
|
1084
|
+
accessControl.read &&
|
|
1085
|
+
accessControl.read.length > 0) {
|
|
1086
|
+
hasPermissions = true;
|
|
1087
|
+
}
|
|
1088
|
+
else if (data.schemaType === "update" &&
|
|
1089
|
+
accessControl.update &&
|
|
1090
|
+
accessControl.update.length > 0) {
|
|
1091
|
+
hasPermissions = true;
|
|
1092
|
+
}
|
|
1093
|
+
else if (data.schemaType === "delete") {
|
|
1094
|
+
// For delete operations, we don't filter by column permissions
|
|
1095
|
+
hasPermissions = true;
|
|
1096
|
+
}
|
|
1097
|
+
// If no permissions are defined for this operation, exclude the column
|
|
1098
|
+
if (!hasPermissions) {
|
|
1099
|
+
continue;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
let zodType = this.getZodTypeForColumn(column, data.schemaType, data.disableOpenApiSchema || false);
|
|
1103
|
+
/*
|
|
1104
|
+
* Check if the column is required and make it optional if not
|
|
1105
|
+
* Also make columns with default values optional in create schemas
|
|
1106
|
+
*/
|
|
1107
|
+
if (column.isDefaultValueColumn) {
|
|
1108
|
+
// should be optional
|
|
1109
|
+
zodType = zodType.optional();
|
|
1110
|
+
}
|
|
1111
|
+
else if (column.type === TableColumnType_1.default.Slug) {
|
|
1112
|
+
/*
|
|
1113
|
+
* Slugs are generated by the server from the slugify column. Some
|
|
1114
|
+
* models mark the column required at the database level, but API
|
|
1115
|
+
* clients never supply it.
|
|
1116
|
+
*/
|
|
1117
|
+
zodType = zodType.optional();
|
|
1118
|
+
}
|
|
1119
|
+
else if (((_a = column.title) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "project id" &&
|
|
1120
|
+
column.type === TableColumnType_1.default.ObjectID) {
|
|
1121
|
+
// this is optional in the API as well as it's derived from API key
|
|
1122
|
+
zodType = zodType.optional();
|
|
1123
|
+
}
|
|
1124
|
+
else if (column.required) {
|
|
1125
|
+
// leave as is
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
zodType = zodType.optional();
|
|
1129
|
+
}
|
|
1130
|
+
// Make fields optional if specified (for global override)
|
|
1131
|
+
if (data.makeOptional) {
|
|
1132
|
+
zodType = zodType.optional();
|
|
1133
|
+
}
|
|
1134
|
+
// Add title and description to the schema
|
|
1135
|
+
let finalDescription = "";
|
|
1136
|
+
// Add column description first if it exists
|
|
1137
|
+
if (column.description) {
|
|
1138
|
+
finalDescription = column.description;
|
|
1139
|
+
}
|
|
1140
|
+
else if (column.title) {
|
|
1141
|
+
finalDescription = column.title;
|
|
1142
|
+
}
|
|
1143
|
+
// The column's description, then who may read and write it.
|
|
1144
|
+
finalDescription = ModelSchema.describeColumnWithPermissions(finalDescription, this.getColumnPermissionsDescription(model, key));
|
|
1145
|
+
// Set the final combined description
|
|
1146
|
+
zodType = this.annotateColumn({
|
|
1147
|
+
zodType: zodType,
|
|
1148
|
+
description: finalDescription,
|
|
1149
|
+
relation: relations[key],
|
|
1150
|
+
disableOpenApiSchema: data.disableOpenApiSchema || false,
|
|
1151
|
+
});
|
|
1152
|
+
shape[key] = zodType;
|
|
1153
|
+
}
|
|
1154
|
+
const schema = Zod_1.default.object(shape).openapi({
|
|
1155
|
+
description: `${data.description} schema for ${model.tableName || "model"} model. ${data.description}`,
|
|
1156
|
+
additionalProperties: false,
|
|
1157
|
+
example: data.example,
|
|
1158
|
+
});
|
|
1159
|
+
return schema;
|
|
1160
|
+
}
|
|
1161
|
+
// Helper method to get Zod type for a column
|
|
1162
|
+
static getZodTypeForColumn(column, schemaType, disableOpenApiSchema = false) {
|
|
1163
|
+
let zodType;
|
|
1164
|
+
// Helper function to add default value to openapi schema if it exists
|
|
1165
|
+
const addDefaultToOpenApi = (openApiConfig) => {
|
|
1166
|
+
if (column.defaultValue !== undefined && column.defaultValue !== null) {
|
|
1167
|
+
return Object.assign(Object.assign({}, openApiConfig), { default: column.defaultValue });
|
|
1168
|
+
}
|
|
1169
|
+
return openApiConfig;
|
|
1170
|
+
};
|
|
1171
|
+
// Helper function to conditionally apply OpenAPI schema
|
|
1172
|
+
const applyOpenApi = (baseType, openApiConfig) => {
|
|
1173
|
+
if (disableOpenApiSchema) {
|
|
1174
|
+
return baseType;
|
|
1175
|
+
}
|
|
1176
|
+
return baseType.openapi(addDefaultToOpenApi(openApiConfig));
|
|
1177
|
+
};
|
|
1178
|
+
if (column.type === TableColumnType_1.default.ObjectID) {
|
|
1179
|
+
zodType = (0, TypeSchemas_1.getObjectIDSchema)();
|
|
1180
|
+
}
|
|
1181
|
+
else if (column.type === TableColumnType_1.default.Port) {
|
|
1182
|
+
zodType = (0, TypeSchemas_1.getPortSchema)();
|
|
1183
|
+
}
|
|
1184
|
+
else if (column.type === TableColumnType_1.default.MonitorSteps) {
|
|
1185
|
+
zodType = (0, MonitorSchemas_1.getMonitorStepsSchema)();
|
|
1186
|
+
}
|
|
1187
|
+
else if (column.type === TableColumnType_1.default.IP) {
|
|
1188
|
+
zodType = (0, TypeSchemas_1.getIPSchema)();
|
|
1189
|
+
}
|
|
1190
|
+
else if (column.type === TableColumnType_1.default.Color) {
|
|
1191
|
+
zodType = (0, TypeSchemas_1.getColorSchema)();
|
|
1192
|
+
}
|
|
1193
|
+
else if (column.type === TableColumnType_1.default.Date) {
|
|
1194
|
+
zodType = (0, TypeSchemas_1.getDateSchema)();
|
|
1195
|
+
}
|
|
1196
|
+
else if (column.type === TableColumnType_1.default.VeryLongText) {
|
|
1197
|
+
zodType = applyOpenApi(Zod_1.default.string(), ModelSchema.getTextOpenApi(column, VERY_LONG_TEXT_EXAMPLE));
|
|
1198
|
+
}
|
|
1199
|
+
else if (column.type === TableColumnType_1.default.Number ||
|
|
1200
|
+
column.type === TableColumnType_1.default.PositiveNumber) {
|
|
1201
|
+
zodType = applyOpenApi(Zod_1.default.number(), { type: "number", example: 42 });
|
|
1202
|
+
}
|
|
1203
|
+
else if (column.type === TableColumnType_1.default.Email) {
|
|
1204
|
+
zodType = (0, TypeSchemas_1.getEmailSchema)();
|
|
1205
|
+
}
|
|
1206
|
+
else if (column.type === TableColumnType_1.default.HashedString) {
|
|
1207
|
+
/*
|
|
1208
|
+
* format: password marks the field as a secret for spec consumers
|
|
1209
|
+
* (the Terraform provider generator emits Sensitive: true for it).
|
|
1210
|
+
*/
|
|
1211
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1212
|
+
type: "string",
|
|
1213
|
+
format: "password",
|
|
1214
|
+
example: "hashed_string_value",
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
else if (column.type === TableColumnType_1.default.Slug) {
|
|
1218
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1219
|
+
type: "string",
|
|
1220
|
+
example: "example-slug-value",
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
else if (column.type === TableColumnType_1.default.ShortText) {
|
|
1224
|
+
zodType = applyOpenApi(Zod_1.default.string(), ModelSchema.getTextOpenApi(column, SHORT_TEXT_EXAMPLE));
|
|
1225
|
+
}
|
|
1226
|
+
else if (column.type === TableColumnType_1.default.LongText) {
|
|
1227
|
+
zodType = applyOpenApi(Zod_1.default.string(), ModelSchema.getTextOpenApi(column, LONG_TEXT_EXAMPLE));
|
|
1228
|
+
}
|
|
1229
|
+
else if (column.type === TableColumnType_1.default.Phone) {
|
|
1230
|
+
zodType = (0, TypeSchemas_1.getPhoneSchema)();
|
|
1231
|
+
}
|
|
1232
|
+
else if (column.type === TableColumnType_1.default.Version) {
|
|
1233
|
+
zodType = (0, TypeSchemas_1.getVersionSchema)();
|
|
1234
|
+
}
|
|
1235
|
+
else if (column.type === TableColumnType_1.default.Password) {
|
|
1236
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1237
|
+
type: "string",
|
|
1238
|
+
format: "password",
|
|
1239
|
+
example: "••••••••",
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
else if (column.type === TableColumnType_1.default.Name) {
|
|
1243
|
+
zodType = (0, TypeSchemas_1.getNameSchema)();
|
|
1244
|
+
}
|
|
1245
|
+
else if (column.type === TableColumnType_1.default.Description) {
|
|
1246
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1247
|
+
type: "string",
|
|
1248
|
+
example: "This is a description of the item",
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
else if (column.type === TableColumnType_1.default.File) {
|
|
1252
|
+
zodType = applyOpenApi(Zod_1.default.any(), {
|
|
1253
|
+
type: "string",
|
|
1254
|
+
format: "binary",
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
else if (column.type === TableColumnType_1.default.Buffer) {
|
|
1258
|
+
zodType = applyOpenApi(Zod_1.default.any(), {
|
|
1259
|
+
type: "string",
|
|
1260
|
+
format: "binary",
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
else if (column.type === TableColumnType_1.default.ShortURL) {
|
|
1264
|
+
zodType = applyOpenApi(Zod_1.default.string().url(), {
|
|
1265
|
+
type: "string",
|
|
1266
|
+
example: "https://short.url/abc123",
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
else if (column.type === TableColumnType_1.default.Markdown) {
|
|
1270
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1271
|
+
type: "string",
|
|
1272
|
+
example: "# Heading\n\nThis is **markdown** content",
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
else if (column.type === TableColumnType_1.default.Domain) {
|
|
1276
|
+
zodType = (0, TypeSchemas_1.getDomainSchema)();
|
|
1277
|
+
}
|
|
1278
|
+
else if (column.type === TableColumnType_1.default.LongURL) {
|
|
1279
|
+
zodType = applyOpenApi(Zod_1.default.string().url(), {
|
|
1280
|
+
type: "string",
|
|
1281
|
+
example: "https://www.example.com/path/to/resource?param=value",
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
else if (column.type === TableColumnType_1.default.OTP) {
|
|
1285
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1286
|
+
type: "string",
|
|
1287
|
+
example: "123456",
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
else if (column.type === TableColumnType_1.default.HTML) {
|
|
1291
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1292
|
+
type: "string",
|
|
1293
|
+
example: "<div><h1>Title</h1><p>Content</p></div>",
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
else if (column.type === TableColumnType_1.default.JavaScript) {
|
|
1297
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1298
|
+
type: "string",
|
|
1299
|
+
example: "function example() { return true; }",
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
else if (column.type === TableColumnType_1.default.CSS) {
|
|
1303
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1304
|
+
type: "string",
|
|
1305
|
+
example: "body { color: #333; margin: 0; }",
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
else if (column.type === TableColumnType_1.default.Array) {
|
|
1309
|
+
zodType = Zod_1.default.array(Zod_1.default.any()).openapi(addDefaultToOpenApi({
|
|
1310
|
+
type: "array",
|
|
1311
|
+
items: {
|
|
1312
|
+
type: "string",
|
|
1313
|
+
},
|
|
1314
|
+
example: ["item1", "item2", "item3"],
|
|
1315
|
+
}));
|
|
1316
|
+
}
|
|
1317
|
+
else if (column.type === TableColumnType_1.default.SmallPositiveNumber) {
|
|
1318
|
+
zodType = Zod_1.default
|
|
1319
|
+
.number()
|
|
1320
|
+
.int()
|
|
1321
|
+
.nonnegative()
|
|
1322
|
+
.openapi(addDefaultToOpenApi({
|
|
1323
|
+
type: "integer",
|
|
1324
|
+
example: 5,
|
|
1325
|
+
}));
|
|
1326
|
+
}
|
|
1327
|
+
else if (column.type === TableColumnType_1.default.BigPositiveNumber) {
|
|
1328
|
+
zodType = Zod_1.default
|
|
1329
|
+
.number()
|
|
1330
|
+
.nonnegative()
|
|
1331
|
+
.openapi(addDefaultToOpenApi({
|
|
1332
|
+
type: "number",
|
|
1333
|
+
example: 1000000,
|
|
1334
|
+
}));
|
|
1335
|
+
}
|
|
1336
|
+
else if (column.type === TableColumnType_1.default.SmallNumber) {
|
|
1337
|
+
zodType = Zod_1.default
|
|
1338
|
+
.number()
|
|
1339
|
+
.int()
|
|
1340
|
+
.openapi(addDefaultToOpenApi({
|
|
1341
|
+
type: "integer",
|
|
1342
|
+
example: 10,
|
|
1343
|
+
}));
|
|
1344
|
+
}
|
|
1345
|
+
else if (column.type === TableColumnType_1.default.BigNumber) {
|
|
1346
|
+
zodType = Zod_1.default.number().openapi(addDefaultToOpenApi({
|
|
1347
|
+
type: "number",
|
|
1348
|
+
example: 1000000,
|
|
1349
|
+
}));
|
|
1350
|
+
}
|
|
1351
|
+
else if (column.type === TableColumnType_1.default.Permission) {
|
|
1352
|
+
zodType = applyOpenApi(Zod_1.default.any(), {
|
|
1353
|
+
type: "object",
|
|
1354
|
+
example: { read: true, write: false, delete: false },
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
else if (column.type === TableColumnType_1.default.CustomFieldType) {
|
|
1358
|
+
// What a custom field holds: "Text", "Number", "Dropdown"...
|
|
1359
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1360
|
+
type: "string",
|
|
1361
|
+
enum: Object.values(CustomFieldType_1.default),
|
|
1362
|
+
example: CustomFieldType_1.default.Text,
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
else if (column.type === TableColumnType_1.default.MonitorType) {
|
|
1366
|
+
// A value the API takes ("HTTP" is none).
|
|
1367
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1368
|
+
type: "string",
|
|
1369
|
+
enum: Object.values(MonitorType_1.default),
|
|
1370
|
+
example: MonitorType_1.default.Manual,
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
else if (column.type === TableColumnType_1.default.WorkflowStatus) {
|
|
1374
|
+
zodType = applyOpenApi(Zod_1.default.string(), {
|
|
1375
|
+
type: "string",
|
|
1376
|
+
enum: Object.values(WorkflowStatus_1.default),
|
|
1377
|
+
example: "In Progress",
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
else if (column.type === TableColumnType_1.default.Boolean) {
|
|
1381
|
+
zodType = applyOpenApi(Zod_1.default.boolean(), { type: "boolean", example: true });
|
|
1382
|
+
}
|
|
1383
|
+
else if (column.type === TableColumnType_1.default.JSON) {
|
|
1384
|
+
zodType = applyOpenApi(Zod_1.default.any(), {
|
|
1385
|
+
type: "object",
|
|
1386
|
+
example: { key: "value", nested: { data: 123 } },
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
else if (column.type === TableColumnType_1.default.EntityArray) {
|
|
1390
|
+
const entityArrayType = column.modelType;
|
|
1391
|
+
if (!entityArrayType) {
|
|
1392
|
+
return applyOpenApi(Zod_1.default.any(), {
|
|
1393
|
+
type: "array",
|
|
1394
|
+
items: { type: "object" },
|
|
1395
|
+
example: [],
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
// Use the appropriate schema method based on the operation type
|
|
1399
|
+
let schemaMethod;
|
|
1400
|
+
switch (schemaType) {
|
|
1401
|
+
case "create":
|
|
1402
|
+
schemaMethod = ModelSchema.getCreateModelSchema;
|
|
1403
|
+
break;
|
|
1404
|
+
case "read":
|
|
1405
|
+
schemaMethod = ModelSchema.getReadModelSchema;
|
|
1406
|
+
break;
|
|
1407
|
+
case "update":
|
|
1408
|
+
schemaMethod = ModelSchema.getUpdateModelSchema;
|
|
1409
|
+
break;
|
|
1410
|
+
case "delete":
|
|
1411
|
+
schemaMethod = ModelSchema.getDeleteModelSchema;
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
const arrayType = Zod_1.default.array(Zod_1.default.lazy(() => {
|
|
1415
|
+
return schemaMethod({
|
|
1416
|
+
modelType: entityArrayType,
|
|
1417
|
+
});
|
|
1418
|
+
}));
|
|
1419
|
+
zodType = disableOpenApiSchema
|
|
1420
|
+
? arrayType
|
|
1421
|
+
: arrayType.openapi(addDefaultToOpenApi({
|
|
1422
|
+
type: "array",
|
|
1423
|
+
items: {
|
|
1424
|
+
type: "object",
|
|
1425
|
+
properties: {
|
|
1426
|
+
id: { type: "string" },
|
|
1427
|
+
},
|
|
1428
|
+
},
|
|
1429
|
+
example: [{ id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }],
|
|
1430
|
+
}));
|
|
1431
|
+
}
|
|
1432
|
+
else if (column.type === TableColumnType_1.default.Entity) {
|
|
1433
|
+
const entityType = column.modelType;
|
|
1434
|
+
if (!entityType) {
|
|
1435
|
+
return applyOpenApi(Zod_1.default.any(), {
|
|
1436
|
+
type: "object",
|
|
1437
|
+
description: "Entity reference",
|
|
1438
|
+
example: { _id: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" },
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
// Use the appropriate schema method based on the operation type
|
|
1442
|
+
let schema;
|
|
1443
|
+
switch (schemaType) {
|
|
1444
|
+
case "create":
|
|
1445
|
+
schema = ModelSchema.getCreateModelSchema({ modelType: entityType });
|
|
1446
|
+
break;
|
|
1447
|
+
case "read":
|
|
1448
|
+
schema = ModelSchema.getReadModelSchema({ modelType: entityType });
|
|
1449
|
+
break;
|
|
1450
|
+
case "update":
|
|
1451
|
+
schema = ModelSchema.getUpdateModelSchema({ modelType: entityType });
|
|
1452
|
+
break;
|
|
1453
|
+
case "delete":
|
|
1454
|
+
schema = ModelSchema.getDeleteModelSchema({ modelType: entityType });
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
const lazyType = Zod_1.default.lazy(() => {
|
|
1458
|
+
return schema;
|
|
1459
|
+
});
|
|
1460
|
+
zodType = disableOpenApiSchema
|
|
1461
|
+
? lazyType
|
|
1462
|
+
: lazyType.openapi(addDefaultToOpenApi({
|
|
1463
|
+
type: "object",
|
|
1464
|
+
example: { id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" },
|
|
1465
|
+
}));
|
|
1466
|
+
}
|
|
1467
|
+
else {
|
|
1468
|
+
zodType = applyOpenApi(Zod_1.default.any(), { type: "null", example: null });
|
|
1469
|
+
}
|
|
1470
|
+
// Apply default value if it exists in the column metadata
|
|
1471
|
+
if (column.defaultValue !== undefined && column.defaultValue !== null) {
|
|
1472
|
+
zodType = zodType.default(column.defaultValue);
|
|
1473
|
+
}
|
|
1474
|
+
// Mark computed fields as readOnly in OpenAPI spec
|
|
1475
|
+
if (column.computed && !disableOpenApiSchema) {
|
|
1476
|
+
zodType = zodType.openapi({ readOnly: true });
|
|
1477
|
+
}
|
|
1478
|
+
/*
|
|
1479
|
+
* A secret - an encrypted or hashed column, or one its model marks
|
|
1480
|
+
* secret: a password, a token, a key - so the spec says so
|
|
1481
|
+
* (annotateSecret): the Terraform provider marks the attribute
|
|
1482
|
+
* Sensitive, and plans and outputs never print it.
|
|
1483
|
+
*/
|
|
1484
|
+
if (!disableOpenApiSchema) {
|
|
1485
|
+
zodType = ModelSchema.annotateSecret(zodType, column);
|
|
1486
|
+
}
|
|
1487
|
+
return zodType;
|
|
1488
|
+
}
|
|
1489
|
+
/*
|
|
1490
|
+
* Whether a column's value is a secret: a hashed or password column, an
|
|
1491
|
+
* encrypted text column, or one its model marks `secret` - a key, a
|
|
1492
|
+
* token or a webhook address stored as it is (TableColumnMetadata.secret).
|
|
1493
|
+
*/
|
|
1494
|
+
static isSecretColumn(column) {
|
|
1495
|
+
return (Boolean(column.secret) ||
|
|
1496
|
+
column.type === TableColumnType_1.default.HashedString ||
|
|
1497
|
+
column.type === TableColumnType_1.default.Password ||
|
|
1498
|
+
Boolean(column.encrypted && ENCRYPTED_SECRET_COLUMN_TYPES.includes(column.type)));
|
|
1499
|
+
}
|
|
1500
|
+
/*
|
|
1501
|
+
* A secret, as the spec says it: x-oneuptime-secret on every one, which
|
|
1502
|
+
* the clients published from the spec read (the Terraform provider marks
|
|
1503
|
+
* the attribute Sensitive), and format: password on an encrypted text
|
|
1504
|
+
* column, as OpenAPI writes a secret string. A secret of another type
|
|
1505
|
+
* keeps its own format - an API key is still a uuid.
|
|
1506
|
+
*/
|
|
1507
|
+
static annotateSecret(zodType, column) {
|
|
1508
|
+
if (!ModelSchema.isSecretColumn(column)) {
|
|
1509
|
+
return zodType;
|
|
1510
|
+
}
|
|
1511
|
+
let annotated = zodType.openapi({
|
|
1512
|
+
"x-oneuptime-secret": true,
|
|
1513
|
+
});
|
|
1514
|
+
if (column.encrypted &&
|
|
1515
|
+
ENCRYPTED_SECRET_COLUMN_TYPES.includes(column.type)) {
|
|
1516
|
+
annotated = annotated.openapi({ format: "password" });
|
|
1517
|
+
}
|
|
1518
|
+
return annotated;
|
|
1519
|
+
}
|
|
1520
|
+
static getCreateModelSchema(data) {
|
|
1521
|
+
// Auto-generated fields to exclude from create schema
|
|
1522
|
+
const excludedFields = [
|
|
1523
|
+
"_id",
|
|
1524
|
+
"createdAt",
|
|
1525
|
+
"updatedAt",
|
|
1526
|
+
"deletedAt",
|
|
1527
|
+
"version",
|
|
1528
|
+
];
|
|
1529
|
+
return this.buildModelSchema({
|
|
1530
|
+
modelType: data.modelType,
|
|
1531
|
+
excludedFields,
|
|
1532
|
+
schemaType: "create",
|
|
1533
|
+
description: "Create",
|
|
1534
|
+
example: this.generateDynamicExample({
|
|
1535
|
+
modelType: data.modelType,
|
|
1536
|
+
schemaType: "create",
|
|
1537
|
+
excludedFields,
|
|
1538
|
+
}),
|
|
1539
|
+
disableOpenApiSchema: data.disableOpenApiSchema || false,
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
static getReadModelSchema(data) {
|
|
1543
|
+
// For read operations, include all fields
|
|
1544
|
+
return this.buildModelSchema({
|
|
1545
|
+
modelType: data.modelType,
|
|
1546
|
+
schemaType: "read",
|
|
1547
|
+
description: "Read",
|
|
1548
|
+
example: this.generateDynamicExample({
|
|
1549
|
+
modelType: data.modelType,
|
|
1550
|
+
schemaType: "read",
|
|
1551
|
+
}),
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
static getUpdateModelSchema(data) {
|
|
1555
|
+
// Auto-generated fields to exclude from update schema (but allow _id for identification)
|
|
1556
|
+
const excludedFields = [
|
|
1557
|
+
"createdAt",
|
|
1558
|
+
"updatedAt",
|
|
1559
|
+
"deletedAt",
|
|
1560
|
+
"version",
|
|
1561
|
+
];
|
|
1562
|
+
return this.buildModelSchema({
|
|
1563
|
+
modelType: data.modelType,
|
|
1564
|
+
excludedFields,
|
|
1565
|
+
schemaType: "update",
|
|
1566
|
+
description: "Update",
|
|
1567
|
+
example: this.generateDynamicExample({
|
|
1568
|
+
modelType: data.modelType,
|
|
1569
|
+
schemaType: "update",
|
|
1570
|
+
excludedFields,
|
|
1571
|
+
}),
|
|
1572
|
+
makeOptional: true, // All fields are optional for updates
|
|
1573
|
+
disableOpenApiSchema: data.disableOpenApiSchema || false,
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
static getDeleteModelSchema(data) {
|
|
1577
|
+
// For delete, we typically only need the ID
|
|
1578
|
+
const includedFields = ["_id"];
|
|
1579
|
+
return this.buildModelSchema({
|
|
1580
|
+
modelType: data.modelType,
|
|
1581
|
+
includedFields,
|
|
1582
|
+
schemaType: "delete",
|
|
1583
|
+
description: "Delete",
|
|
1584
|
+
example: this.generateDynamicExample({
|
|
1585
|
+
modelType: data.modelType,
|
|
1586
|
+
schemaType: "delete",
|
|
1587
|
+
includedFields,
|
|
1588
|
+
}),
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
static generateDynamicExample(data) {
|
|
1592
|
+
const model = new data.modelType();
|
|
1593
|
+
const columns = (0, TableColumn_1.getTableColumns)(model);
|
|
1594
|
+
const columnAccessControl = model.getColumnAccessControlForAllColumns();
|
|
1595
|
+
const example = {};
|
|
1596
|
+
for (const key in columns) {
|
|
1597
|
+
const column = columns[key];
|
|
1598
|
+
if (!column) {
|
|
1599
|
+
continue;
|
|
1600
|
+
}
|
|
1601
|
+
if (column.hideColumnInDocumentation) {
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
// Skip excluded fields
|
|
1605
|
+
if (data.excludedFields && data.excludedFields.includes(key)) {
|
|
1606
|
+
continue;
|
|
1607
|
+
}
|
|
1608
|
+
// Only include specified fields if includedFields is provided
|
|
1609
|
+
if (data.includedFields && !data.includedFields.includes(key)) {
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
// Skip default value columns in create schema examples
|
|
1613
|
+
if (data.schemaType === "create" && column.isDefaultValueColumn) {
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
// Filter out columns with no permissions (root-only access)
|
|
1617
|
+
const accessControl = columnAccessControl[key];
|
|
1618
|
+
if (accessControl) {
|
|
1619
|
+
let hasPermissions = false;
|
|
1620
|
+
// Check if column has any permissions defined for the current operation
|
|
1621
|
+
if (data.schemaType === "create" &&
|
|
1622
|
+
accessControl.create &&
|
|
1623
|
+
accessControl.create.length > 0) {
|
|
1624
|
+
hasPermissions = true;
|
|
1625
|
+
}
|
|
1626
|
+
else if (data.schemaType === "read" &&
|
|
1627
|
+
accessControl.read &&
|
|
1628
|
+
accessControl.read.length > 0) {
|
|
1629
|
+
hasPermissions = true;
|
|
1630
|
+
}
|
|
1631
|
+
else if (data.schemaType === "update" &&
|
|
1632
|
+
accessControl.update &&
|
|
1633
|
+
accessControl.update.length > 0) {
|
|
1634
|
+
hasPermissions = true;
|
|
1635
|
+
}
|
|
1636
|
+
else if (data.schemaType === "delete") {
|
|
1637
|
+
// For delete operations, we don't filter by column permissions
|
|
1638
|
+
hasPermissions = true;
|
|
1639
|
+
}
|
|
1640
|
+
// If no permissions are defined for this operation, exclude the column
|
|
1641
|
+
if (!hasPermissions) {
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
// For create and update, only include required fields
|
|
1646
|
+
if ((data.schemaType === "create" || data.schemaType === "update") &&
|
|
1647
|
+
!column.required) {
|
|
1648
|
+
continue;
|
|
1649
|
+
}
|
|
1650
|
+
// Generate example value based on column type
|
|
1651
|
+
example[key] = this.generateExampleValueForColumn(column);
|
|
1652
|
+
}
|
|
1653
|
+
return example;
|
|
1654
|
+
}
|
|
1655
|
+
static generateExampleValueForColumn(column) {
|
|
1656
|
+
switch (column.type) {
|
|
1657
|
+
case TableColumnType_1.default.ObjectID:
|
|
1658
|
+
return "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
|
|
1659
|
+
case TableColumnType_1.default.ShortText:
|
|
1660
|
+
return this.getShortTextExample();
|
|
1661
|
+
case TableColumnType_1.default.LongText:
|
|
1662
|
+
case TableColumnType_1.default.VeryLongText:
|
|
1663
|
+
return this.getLongTextExample();
|
|
1664
|
+
case TableColumnType_1.default.Email:
|
|
1665
|
+
return "user@example.com";
|
|
1666
|
+
case TableColumnType_1.default.Phone:
|
|
1667
|
+
return "+1-555-0123";
|
|
1668
|
+
case TableColumnType_1.default.LongURL:
|
|
1669
|
+
return "https://example.com";
|
|
1670
|
+
case TableColumnType_1.default.ShortURL:
|
|
1671
|
+
return "https://example.com";
|
|
1672
|
+
case TableColumnType_1.default.Number:
|
|
1673
|
+
case TableColumnType_1.default.SmallNumber:
|
|
1674
|
+
case TableColumnType_1.default.BigNumber:
|
|
1675
|
+
return 42;
|
|
1676
|
+
case TableColumnType_1.default.PositiveNumber:
|
|
1677
|
+
case TableColumnType_1.default.SmallPositiveNumber:
|
|
1678
|
+
case TableColumnType_1.default.BigPositiveNumber:
|
|
1679
|
+
return 100;
|
|
1680
|
+
case TableColumnType_1.default.Boolean:
|
|
1681
|
+
return true;
|
|
1682
|
+
case TableColumnType_1.default.Date:
|
|
1683
|
+
return {
|
|
1684
|
+
_type: "DateTime",
|
|
1685
|
+
value: "2023-10-01T12:00:00Z",
|
|
1686
|
+
};
|
|
1687
|
+
case TableColumnType_1.default.Color:
|
|
1688
|
+
return "#FF0000";
|
|
1689
|
+
case TableColumnType_1.default.JSON:
|
|
1690
|
+
return { key: "value", nested: { data: 123 } };
|
|
1691
|
+
case TableColumnType_1.default.Entity:
|
|
1692
|
+
return {
|
|
1693
|
+
_id: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
|
1694
|
+
};
|
|
1695
|
+
case TableColumnType_1.default.EntityArray:
|
|
1696
|
+
return [
|
|
1697
|
+
{ _id: "cccccccc-cccc-cccc-cccc-cccccccccccc" },
|
|
1698
|
+
{ _id: "dddddddd-dddd-dddd-dddd-dddddddddddd" },
|
|
1699
|
+
];
|
|
1700
|
+
case TableColumnType_1.default.File:
|
|
1701
|
+
return {
|
|
1702
|
+
_id: "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee",
|
|
1703
|
+
name: "example-file.pdf",
|
|
1704
|
+
type: "application/pdf",
|
|
1705
|
+
};
|
|
1706
|
+
case TableColumnType_1.default.Version:
|
|
1707
|
+
return 1;
|
|
1708
|
+
case TableColumnType_1.default.Port:
|
|
1709
|
+
return 8080;
|
|
1710
|
+
case TableColumnType_1.default.HashedString:
|
|
1711
|
+
return "hashed_value_here";
|
|
1712
|
+
case TableColumnType_1.default.Slug:
|
|
1713
|
+
return "example-slug";
|
|
1714
|
+
case TableColumnType_1.default.Permission:
|
|
1715
|
+
return "read";
|
|
1716
|
+
default:
|
|
1717
|
+
return null;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
static getShortTextExample() {
|
|
1721
|
+
return "Example Text";
|
|
1722
|
+
}
|
|
1723
|
+
static getLongTextExample() {
|
|
1724
|
+
return "This is an example of longer text content that provides detailed information.";
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
exports.ModelSchema = ModelSchema;
|