@servicenow/sdk-build-plugins 3.0.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acl-plugin.d.ts +19 -0
- package/dist/acl-plugin.js +210 -0
- package/dist/acl-plugin.js.map +1 -0
- package/dist/application-menu-plugin.d.ts +18 -0
- package/dist/application-menu-plugin.js +104 -0
- package/dist/application-menu-plugin.js.map +1 -0
- package/dist/arrow-function-plugin.d.ts +16 -0
- package/dist/arrow-function-plugin.js +107 -0
- package/dist/arrow-function-plugin.js.map +1 -0
- package/dist/atf/step-configs.d.ts +37 -0
- package/dist/atf/step-configs.js +2236 -0
- package/dist/atf/step-configs.js.map +1 -0
- package/dist/atf/test-plugin.d.ts +4 -0
- package/dist/atf/test-plugin.js +591 -0
- package/dist/atf/test-plugin.js.map +1 -0
- package/dist/basic-syntax-plugin.d.ts +2 -0
- package/dist/basic-syntax-plugin.js +636 -0
- package/dist/basic-syntax-plugin.js.map +1 -0
- package/dist/business-rule-plugin.d.ts +3 -0
- package/dist/business-rule-plugin.js +205 -0
- package/dist/business-rule-plugin.js.map +1 -0
- package/dist/call-expression-plugin.d.ts +2 -0
- package/dist/call-expression-plugin.js +175 -0
- package/dist/call-expression-plugin.js.map +1 -0
- package/dist/client-script-plugin.d.ts +29 -0
- package/dist/client-script-plugin.js +157 -0
- package/dist/client-script-plugin.js.map +1 -0
- package/dist/column/column-helper.d.ts +12 -0
- package/dist/column/column-helper.js +84 -0
- package/dist/column/column-helper.js.map +1 -0
- package/dist/column/column-to-record.d.ts +3 -0
- package/dist/column/column-to-record.js +105 -0
- package/dist/column/column-to-record.js.map +1 -0
- package/dist/column-plugin.d.ts +8 -0
- package/dist/column-plugin.js +453 -0
- package/dist/column-plugin.js.map +1 -0
- package/dist/cross-scope-privilege-plugin.d.ts +15 -0
- package/dist/cross-scope-privilege-plugin.js +82 -0
- package/dist/cross-scope-privilege-plugin.js.map +1 -0
- package/dist/html-import-plugin.d.ts +2 -0
- package/dist/html-import-plugin.js +72 -0
- package/dist/html-import-plugin.js.map +1 -0
- package/dist/index.d.ts +37 -21
- package/dist/index.js +40 -45
- package/dist/index.js.map +1 -1
- package/dist/json-plugin.d.ts +15 -0
- package/dist/json-plugin.js +104 -0
- package/dist/json-plugin.js.map +1 -0
- package/dist/list-plugin.d.ts +2 -0
- package/dist/list-plugin.js +191 -0
- package/dist/list-plugin.js.map +1 -0
- package/dist/now-config-plugin.d.ts +4 -0
- package/dist/now-config-plugin.js +154 -0
- package/dist/now-config-plugin.js.map +1 -0
- package/dist/now-id-plugin.d.ts +11 -0
- package/dist/now-id-plugin.js +71 -0
- package/dist/now-id-plugin.js.map +1 -0
- package/dist/now-include-plugin.d.ts +16 -0
- package/dist/now-include-plugin.js +118 -0
- package/dist/now-include-plugin.js.map +1 -0
- package/dist/now-ref-plugin.d.ts +2 -0
- package/dist/now-ref-plugin.js +43 -0
- package/dist/now-ref-plugin.js.map +1 -0
- package/dist/now-unresolved-plugin.d.ts +2 -0
- package/dist/now-unresolved-plugin.js +32 -0
- package/dist/now-unresolved-plugin.js.map +1 -0
- package/dist/package-json-plugin.d.ts +2 -0
- package/dist/package-json-plugin.js +70 -0
- package/dist/package-json-plugin.js.map +1 -0
- package/dist/property-plugin.d.ts +2 -0
- package/dist/property-plugin.js +105 -0
- package/dist/property-plugin.js.map +1 -0
- package/dist/record-plugin.d.ts +43 -0
- package/dist/record-plugin.js +147 -0
- package/dist/record-plugin.js.map +1 -0
- package/dist/repack/index.d.ts +1 -0
- package/dist/repack/index.js +10 -2
- package/dist/repack/index.js.map +1 -1
- package/dist/repack/lint/Rules.d.ts +1 -1
- package/dist/repack/lint/Rules.js +7 -3
- package/dist/repack/lint/Rules.js.map +1 -1
- package/dist/repack/lint/index.js +1 -1
- package/dist/rest-api-plugin.d.ts +2 -0
- package/dist/rest-api-plugin.js +469 -0
- package/dist/rest-api-plugin.js.map +1 -0
- package/dist/role-plugin.d.ts +2 -0
- package/dist/role-plugin.js +117 -0
- package/dist/role-plugin.js.map +1 -0
- package/dist/script-action-plugin.d.ts +2 -0
- package/dist/script-action-plugin.js +62 -0
- package/dist/script-action-plugin.js.map +1 -0
- package/dist/script-include-plugin.d.ts +2 -0
- package/dist/script-include-plugin.js +102 -0
- package/dist/script-include-plugin.js.map +1 -0
- package/dist/server-module-plugin/index.d.ts +14 -0
- package/dist/server-module-plugin/index.js +378 -0
- package/dist/server-module-plugin/index.js.map +1 -0
- package/dist/server-module-plugin/sbom-builder.d.ts +45 -0
- package/dist/server-module-plugin/sbom-builder.js +179 -0
- package/dist/server-module-plugin/sbom-builder.js.map +1 -0
- package/dist/service-portal/angular-provider-plugin.d.ts +2 -0
- package/dist/service-portal/angular-provider-plugin.js +78 -0
- package/dist/service-portal/angular-provider-plugin.js.map +1 -0
- package/dist/service-portal/dependency-plugin.d.ts +2 -0
- package/dist/service-portal/dependency-plugin.js +235 -0
- package/dist/service-portal/dependency-plugin.js.map +1 -0
- package/dist/service-portal/widget-plugin.d.ts +6 -0
- package/dist/service-portal/widget-plugin.js +230 -0
- package/dist/service-portal/widget-plugin.js.map +1 -0
- package/dist/static-content-plugin.d.ts +2 -0
- package/dist/static-content-plugin.js +272 -0
- package/dist/static-content-plugin.js.map +1 -0
- package/dist/table-plugin.d.ts +3 -0
- package/dist/table-plugin.js +1324 -0
- package/dist/table-plugin.js.map +1 -0
- package/dist/ui-action-plugin.d.ts +2 -0
- package/dist/ui-action-plugin.js +291 -0
- package/dist/ui-action-plugin.js.map +1 -0
- package/dist/ui-page-plugin.d.ts +2 -0
- package/dist/ui-page-plugin.js +165 -0
- package/dist/ui-page-plugin.js.map +1 -0
- package/dist/user-preference-plugin.d.ts +15 -0
- package/dist/user-preference-plugin.js +63 -0
- package/dist/user-preference-plugin.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +72 -0
- package/dist/utils.js.map +1 -0
- package/dist/view-plugin.d.ts +2 -0
- package/dist/view-plugin.js +45 -0
- package/dist/view-plugin.js.map +1 -0
- package/package.json +17 -13
- package/src/acl-plugin.ts +256 -0
- package/src/application-menu-plugin.ts +109 -0
- package/src/arrow-function-plugin.ts +127 -0
- package/src/atf/step-configs.ts +2284 -0
- package/src/atf/test-plugin.ts +728 -0
- package/src/basic-syntax-plugin.ts +729 -0
- package/src/business-rule-plugin.ts +266 -0
- package/src/call-expression-plugin.ts +202 -0
- package/src/client-script-plugin.ts +170 -0
- package/src/column/column-helper.ts +119 -0
- package/src/column/column-to-record.ts +131 -0
- package/src/column-plugin.ts +506 -0
- package/src/cross-scope-privilege-plugin.ts +82 -0
- package/src/html-import-plugin.ts +79 -0
- package/src/index.ts +39 -21
- package/src/json-plugin.ts +128 -0
- package/src/list-plugin.ts +222 -0
- package/src/now-config-plugin.ts +194 -0
- package/src/now-id-plugin.ts +78 -0
- package/src/now-include-plugin.ts +140 -0
- package/src/now-ref-plugin.ts +48 -0
- package/src/now-unresolved-plugin.ts +30 -0
- package/src/package-json-plugin.ts +87 -0
- package/src/property-plugin.ts +118 -0
- package/src/record-plugin.ts +171 -0
- package/src/repack/index.ts +10 -1
- package/src/repack/lint/Rules.ts +5 -4
- package/src/repack/lint/index.ts +1 -1
- package/src/rest-api-plugin.ts +651 -0
- package/src/role-plugin.ts +128 -0
- package/src/script-action-plugin.ts +63 -0
- package/src/script-include-plugin.ts +110 -0
- package/src/server-module-plugin/index.ts +470 -0
- package/src/server-module-plugin/sbom-builder.ts +183 -0
- package/src/service-portal/angular-provider-plugin.ts +83 -0
- package/src/service-portal/dependency-plugin.ts +284 -0
- package/src/service-portal/widget-plugin.ts +263 -0
- package/src/static-content-plugin.ts +254 -0
- package/src/table-plugin.ts +1698 -0
- package/src/ui-action-plugin.ts +324 -0
- package/src/ui-page-plugin.ts +168 -0
- package/src/user-preference-plugin.ts +62 -0
- package/src/utils.ts +69 -0
- package/src/view-plugin.ts +46 -0
- package/dist/AttachmentPlugin.d.ts +0 -254
- package/dist/AttachmentPlugin.js +0 -220
- package/dist/AttachmentPlugin.js.map +0 -1
- package/dist/BusinessRulePlugin.d.ts +0 -30
- package/dist/BusinessRulePlugin.js +0 -149
- package/dist/BusinessRulePlugin.js.map +0 -1
- package/dist/CrossScopePrivilegePlugin.d.ts +0 -35
- package/dist/CrossScopePrivilegePlugin.js +0 -80
- package/dist/CrossScopePrivilegePlugin.js.map +0 -1
- package/dist/DefaultPlugin.d.ts +0 -86
- package/dist/DefaultPlugin.js +0 -226
- package/dist/DefaultPlugin.js.map +0 -1
- package/dist/HtmlTemplatePlugin.d.ts +0 -21
- package/dist/HtmlTemplatePlugin.js +0 -29
- package/dist/HtmlTemplatePlugin.js.map +0 -1
- package/dist/IdPlugin.d.ts +0 -28
- package/dist/IdPlugin.js +0 -68
- package/dist/IdPlugin.js.map +0 -1
- package/dist/IncludePlugin.d.ts +0 -34
- package/dist/IncludePlugin.js +0 -155
- package/dist/IncludePlugin.js.map +0 -1
- package/dist/JsonPlugin.d.ts +0 -28
- package/dist/JsonPlugin.js +0 -69
- package/dist/JsonPlugin.js.map +0 -1
- package/dist/ListPlugin.d.ts +0 -93
- package/dist/ListPlugin.js +0 -456
- package/dist/ListPlugin.js.map +0 -1
- package/dist/NowConfigPlugin.d.ts +0 -45
- package/dist/NowConfigPlugin.js +0 -64
- package/dist/NowConfigPlugin.js.map +0 -1
- package/dist/PackageJsonPlugin.d.ts +0 -34
- package/dist/PackageJsonPlugin.js +0 -63
- package/dist/PackageJsonPlugin.js.map +0 -1
- package/dist/PropertyPlugin.d.ts +0 -51
- package/dist/PropertyPlugin.js +0 -181
- package/dist/PropertyPlugin.js.map +0 -1
- package/dist/ScriptTemplatePlugin.d.ts +0 -13
- package/dist/ScriptTemplatePlugin.js +0 -55
- package/dist/ScriptTemplatePlugin.js.map +0 -1
- package/dist/ServerModulePlugin.d.ts +0 -75
- package/dist/ServerModulePlugin.js +0 -368
- package/dist/ServerModulePlugin.js.map +0 -1
- package/dist/UserPreferencePlugin.d.ts +0 -19
- package/dist/UserPreferencePlugin.js +0 -32
- package/dist/UserPreferencePlugin.js.map +0 -1
- package/dist/aclAndRole/AclPlugin.d.ts +0 -82
- package/dist/aclAndRole/AclPlugin.js +0 -262
- package/dist/aclAndRole/AclPlugin.js.map +0 -1
- package/dist/aclAndRole/RolePlugin.d.ts +0 -66
- package/dist/aclAndRole/RolePlugin.js +0 -179
- package/dist/aclAndRole/RolePlugin.js.map +0 -1
- package/dist/aclAndRole/Util.d.ts +0 -3
- package/dist/aclAndRole/Util.js +0 -90
- package/dist/aclAndRole/Util.js.map +0 -1
- package/dist/app/ApplicationMenuPlugin.d.ts +0 -34
- package/dist/app/ApplicationMenuPlugin.js +0 -112
- package/dist/app/ApplicationMenuPlugin.js.map +0 -1
- package/dist/db/ColumnPlugins.d.ts +0 -750
- package/dist/db/ColumnPlugins.js +0 -114
- package/dist/db/ColumnPlugins.js.map +0 -1
- package/dist/db/DBUtils.d.ts +0 -2
- package/dist/db/DBUtils.js +0 -27
- package/dist/db/DBUtils.js.map +0 -1
- package/dist/db/DocumentationPlugin.d.ts +0 -67
- package/dist/db/DocumentationPlugin.js +0 -258
- package/dist/db/DocumentationPlugin.js.map +0 -1
- package/dist/db/LicensingPlugin.d.ts +0 -60
- package/dist/db/LicensingPlugin.js +0 -117
- package/dist/db/LicensingPlugin.js.map +0 -1
- package/dist/db/RecordPlugin.d.ts +0 -133
- package/dist/db/RecordPlugin.js +0 -337
- package/dist/db/RecordPlugin.js.map +0 -1
- package/dist/db/TablePlugin.d.ts +0 -231
- package/dist/db/TablePlugin.js +0 -1628
- package/dist/db/TablePlugin.js.map +0 -1
- package/dist/db/index.d.ts +0 -6
- package/dist/db/index.js +0 -32
- package/dist/db/index.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -10
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +0 -373
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +0 -13
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -177
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +0 -81
- package/dist/scriptedRESTAPI/RestApiPlugin.js +0 -345
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +0 -1
- package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +0 -190
- package/dist/scriptedRESTAPI/RestSchemaUtils.js +0 -53
- package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestUtils.d.ts +0 -69
- package/dist/scriptedRESTAPI/RestUtils.js +0 -497
- package/dist/scriptedRESTAPI/RestUtils.js.map +0 -1
- package/dist/scripts/ClientScriptPlugin.d.ts +0 -64
- package/dist/scripts/ClientScriptPlugin.js +0 -170
- package/dist/scripts/ClientScriptPlugin.js.map +0 -1
- package/dist/scripts/scriptUtils.d.ts +0 -1
- package/dist/scripts/scriptUtils.js +0 -9
- package/dist/scripts/scriptUtils.js.map +0 -1
- package/dist/uxf/ExperiencePlugin.d.ts +0 -45
- package/dist/uxf/ExperiencePlugin.js +0 -61
- package/dist/uxf/ExperiencePlugin.js.map +0 -1
- package/dist/uxf/RoutesPlugin.d.ts +0 -29
- package/dist/uxf/RoutesPlugin.js +0 -181
- package/dist/uxf/RoutesPlugin.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +0 -4
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js +0 -65
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +0 -189
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js +0 -158
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +0 -13
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -604
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +0 -12
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +0 -31
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -64
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/index.d.ts +0 -3
- package/dist/uxf/UxfFormulaParser/index.js +0 -11
- package/dist/uxf/UxfFormulaParser/index.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/parser.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/parser.js +0 -87
- package/dist/uxf/UxfFormulaParser/parser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +0 -17
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +0 -1
- package/dist/uxf/constants.d.ts +0 -2
- package/dist/uxf/constants.js +0 -8
- package/dist/uxf/constants.js.map +0 -1
- package/dist/uxf/index.d.ts +0 -2
- package/dist/uxf/index.js +0 -11
- package/dist/uxf/index.js.map +0 -1
- package/dist/uxf/tectonicIdGenerator.d.ts +0 -12
- package/dist/uxf/tectonicIdGenerator.js +0 -79
- package/dist/uxf/tectonicIdGenerator.js.map +0 -1
- package/src/AttachmentPlugin.ts +0 -268
- package/src/BusinessRulePlugin.ts +0 -238
- package/src/CrossScopePrivilegePlugin.ts +0 -115
- package/src/DefaultPlugin.ts +0 -288
- package/src/HtmlTemplatePlugin.ts +0 -31
- package/src/IdPlugin.ts +0 -74
- package/src/IncludePlugin.ts +0 -206
- package/src/JsonPlugin.ts +0 -76
- package/src/ListPlugin.ts +0 -570
- package/src/NowConfigPlugin.ts +0 -69
- package/src/PackageJsonPlugin.ts +0 -68
- package/src/PropertyPlugin.ts +0 -237
- package/src/ScriptTemplatePlugin.ts +0 -53
- package/src/ServerModulePlugin.ts +0 -480
- package/src/UserPreferencePlugin.ts +0 -45
- package/src/aclAndRole/AclPlugin.ts +0 -420
- package/src/aclAndRole/RolePlugin.ts +0 -254
- package/src/aclAndRole/Util.ts +0 -113
- package/src/app/ApplicationMenuPlugin.ts +0 -165
- package/src/db/ColumnPlugins.ts +0 -114
- package/src/db/DBUtils.ts +0 -36
- package/src/db/DocumentationPlugin.ts +0 -316
- package/src/db/LicensingPlugin.ts +0 -138
- package/src/db/RecordPlugin.ts +0 -459
- package/src/db/TablePlugin.ts +0 -2070
- package/src/db/index.ts +0 -6
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +0 -419
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +0 -228
- package/src/scriptedRESTAPI/RestApiPlugin.ts +0 -469
- package/src/scriptedRESTAPI/RestSchemaUtils.ts +0 -72
- package/src/scriptedRESTAPI/RestUtils.ts +0 -569
- package/src/scripts/ClientScriptPlugin.ts +0 -257
- package/src/scripts/scriptUtils.ts +0 -5
- package/src/uxf/ExperiencePlugin.ts +0 -67
- package/src/uxf/RoutesPlugin.ts +0 -211
- package/src/uxf/UxfFormulaParser/cleanUxValue.ts +0 -73
- package/src/uxf/UxfFormulaParser/grammerParser/api.js +0 -166
- package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -606
- package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -65
- package/src/uxf/UxfFormulaParser/index.ts +0 -4
- package/src/uxf/UxfFormulaParser/parser.ts +0 -64
- package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +0 -13
- package/src/uxf/constants.ts +0 -4
- package/src/uxf/index.ts +0 -2
- package/src/uxf/tectonicIdGenerator.ts +0 -78
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { CallExpressionShape, ObjectShape, Plugin, type Record } from '@servicenow/sdk-build-core'
|
|
2
|
+
import { BooleanColumn, choiceDropdown, type choiceDropdownType, GenericColumn } from '@servicenow/sdk-core/runtime/db'
|
|
3
|
+
import isEqual from 'lodash/isEqual'
|
|
4
|
+
import { getChoiceRecords, getDocumentationRecords } from './column/column-to-record'
|
|
5
|
+
import {
|
|
6
|
+
COLUMN_API_TO_TYPE,
|
|
7
|
+
COLUMN_TYPE_TO_API,
|
|
8
|
+
DEFAULT_COLUMN_CALCULATION,
|
|
9
|
+
getDefaultMaxLength,
|
|
10
|
+
} from './column/column-helper'
|
|
11
|
+
import { ModuleFunctionShape } from './server-module-plugin'
|
|
12
|
+
import { generateDeprecatedDiagnostics } from './utils'
|
|
13
|
+
|
|
14
|
+
const PLURAL_EQUALS_LABEL = [
|
|
15
|
+
's',
|
|
16
|
+
'ed',
|
|
17
|
+
'by',
|
|
18
|
+
'Active',
|
|
19
|
+
')',
|
|
20
|
+
' to',
|
|
21
|
+
' with',
|
|
22
|
+
' for',
|
|
23
|
+
' in',
|
|
24
|
+
' out',
|
|
25
|
+
' use',
|
|
26
|
+
'Data',
|
|
27
|
+
' data',
|
|
28
|
+
]
|
|
29
|
+
const PLURAL_SPECIAL_CASE_Y_TO_IES = ['ry', 'ty', 'dy', 'cy', 'fy', 'ly', 'ny']
|
|
30
|
+
const PLURAL_SPECIAL_CASE_ADD_ES = ['x', 'sh', 'ch', 'z']
|
|
31
|
+
|
|
32
|
+
const columnAliases = {
|
|
33
|
+
readOnly: ['read_only'],
|
|
34
|
+
functionDefinition: ['function_definition'],
|
|
35
|
+
tableReference: ['table_reference'],
|
|
36
|
+
elementReference: ['element_reference'],
|
|
37
|
+
spellCheck: ['spell_check'],
|
|
38
|
+
xmlView: ['xml_view'],
|
|
39
|
+
textIndex: ['text_index'],
|
|
40
|
+
dynamicValueDefinitions: ['dynamic_value_definitions'],
|
|
41
|
+
referenceFloats: ['reference_floats'],
|
|
42
|
+
dynamicCreationScript: ['dynamic_creation_script'],
|
|
43
|
+
dynamicCreation: ['dyamic_creation'], // maintaining backwards compatibility with typo
|
|
44
|
+
referenceKey: ['reference_key'],
|
|
45
|
+
referenceQual: ['reference_qual'],
|
|
46
|
+
columnType: ['column_type'],
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const calculationAliases = {
|
|
50
|
+
calculatedValue: ['calculated_value'],
|
|
51
|
+
columnName: ['column_name'],
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const choiceAliases = {
|
|
55
|
+
dependentValue: ['dependent_value'],
|
|
56
|
+
inactiveOnUpdate: ['inactive_on_update'],
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const documentationAliases = {
|
|
60
|
+
urlTarget: ['url_target'],
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const ColumnPlugin = Plugin.create({
|
|
64
|
+
name: 'ColumnPlugin',
|
|
65
|
+
records: {
|
|
66
|
+
sys_choice: { coalesce: ['name', 'element', 'value'] },
|
|
67
|
+
sys_documentation: { coalesce: ['name', 'element', 'language'] },
|
|
68
|
+
},
|
|
69
|
+
shapes: [
|
|
70
|
+
{
|
|
71
|
+
shape: CallExpressionShape,
|
|
72
|
+
fileTypes: ['fluent'],
|
|
73
|
+
async toRecord(callExpression, { factory, diagnostics, config }) {
|
|
74
|
+
const callee = callExpression.getCallee()
|
|
75
|
+
if (!(callee in COLUMN_API_TO_TYPE) && !(callee === GenericColumn.name)) {
|
|
76
|
+
return { success: false }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const column = callExpression.getArgument(0).asObject().withAliasedKeys(columnAliases)
|
|
80
|
+
generateDeprecatedDiagnostics(column, diagnostics)
|
|
81
|
+
if (!column.has('table') || !column.has('name')) {
|
|
82
|
+
return { success: false }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const documentationRecords = getDocumentationRecords(
|
|
86
|
+
callExpression,
|
|
87
|
+
documentationAliases,
|
|
88
|
+
factory,
|
|
89
|
+
diagnostics,
|
|
90
|
+
true
|
|
91
|
+
)
|
|
92
|
+
const choiceRecords = getChoiceRecords(callExpression, choiceAliases, factory, diagnostics)
|
|
93
|
+
|
|
94
|
+
const columnType = COLUMN_API_TO_TYPE[callee] ?? column.get('columnType').asString().getValue()
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
value: factory
|
|
98
|
+
.createRecord({
|
|
99
|
+
source: callExpression,
|
|
100
|
+
table: 'sys_dictionary',
|
|
101
|
+
properties: column.transform(({ $ }) => ({
|
|
102
|
+
name: $.from('table'),
|
|
103
|
+
element: $.from('name'),
|
|
104
|
+
internal_type: $.val(columnType),
|
|
105
|
+
active: $.toBoolean().def(true),
|
|
106
|
+
array: $.toBoolean().def(false),
|
|
107
|
+
attributes: $.map((attributes) => {
|
|
108
|
+
if (!attributes.isObject()) {
|
|
109
|
+
return undefined
|
|
110
|
+
}
|
|
111
|
+
const attributesObj = attributes.asObject().getValue()
|
|
112
|
+
return Object.entries(attributesObj)
|
|
113
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
114
|
+
.join(',')
|
|
115
|
+
}).def(''),
|
|
116
|
+
audit: $.toBoolean().def(false),
|
|
117
|
+
reference_cascade_rule: $.from('cascadeRule'),
|
|
118
|
+
default_value: $.from('default'),
|
|
119
|
+
display: $.toBoolean().def(false),
|
|
120
|
+
dynamic_creation: $.from('dynamicCreation').toBoolean(),
|
|
121
|
+
dynamic_creation_script: $.from('dynamicCreationScript'),
|
|
122
|
+
reference_floats: $.from('referenceFloats'),
|
|
123
|
+
reference_key: $.from('referenceKey'),
|
|
124
|
+
reference_qual: $.from('referenceQual'),
|
|
125
|
+
calculation: $.from('dynamicValueDefinitions')
|
|
126
|
+
.map((dynamicValueDefinitions) => {
|
|
127
|
+
if (
|
|
128
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() !==
|
|
129
|
+
'calculated_value'
|
|
130
|
+
) {
|
|
131
|
+
return undefined
|
|
132
|
+
}
|
|
133
|
+
const dynamicValueObject = dynamicValueDefinitions
|
|
134
|
+
.asObject()
|
|
135
|
+
.withAliasedKeys(calculationAliases)
|
|
136
|
+
generateDeprecatedDiagnostics(dynamicValueObject, diagnostics)
|
|
137
|
+
const calculatedValue = dynamicValueObject.get('calculatedValue')
|
|
138
|
+
|
|
139
|
+
if (calculatedValue.isUnresolved()) {
|
|
140
|
+
diagnostics.error(
|
|
141
|
+
calculatedValue.getOriginalNode(),
|
|
142
|
+
`Unable to resolve the script reference, ensure the imported module is within the ${config.serverModulesDir} directory.`
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
calculatedValue
|
|
148
|
+
.if(ModuleFunctionShape)
|
|
149
|
+
?.toString((n) => `${n}({{PARAMS}})`, ['current']) ?? calculatedValue
|
|
150
|
+
)
|
|
151
|
+
})
|
|
152
|
+
.toCdata(),
|
|
153
|
+
choice: $.from('dropdown')
|
|
154
|
+
.map((d) =>
|
|
155
|
+
d.isString()
|
|
156
|
+
? Math.max(choiceDropdown.indexOf(d.getValue() as choiceDropdownType), 0)
|
|
157
|
+
: undefined
|
|
158
|
+
)
|
|
159
|
+
.def(0),
|
|
160
|
+
choice_table: $.from('dynamicValueDefinitions').map((dynamicValueDefinitions) =>
|
|
161
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() ===
|
|
162
|
+
'choices_from_other_table'
|
|
163
|
+
? dynamicValueDefinitions.asObject().get('table').ifString()
|
|
164
|
+
: undefined
|
|
165
|
+
),
|
|
166
|
+
virtual: $.from('dynamicValueDefinitions')
|
|
167
|
+
.map((dynamicValueDefinitions) => {
|
|
168
|
+
const calculationType = dynamicValueDefinitions
|
|
169
|
+
.ifObject()
|
|
170
|
+
?.get('type')
|
|
171
|
+
.ifString()
|
|
172
|
+
?.getValue()
|
|
173
|
+
if (!calculationType) {
|
|
174
|
+
return undefined
|
|
175
|
+
}
|
|
176
|
+
return calculationType === 'calculated_value'
|
|
177
|
+
})
|
|
178
|
+
.toBoolean(),
|
|
179
|
+
choice_field: $.from('dynamicValueDefinitions').map((dynamicValueDefinitions) =>
|
|
180
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() ===
|
|
181
|
+
'choices_from_other_table'
|
|
182
|
+
? dynamicValueDefinitions.asObject().get('field').ifString()
|
|
183
|
+
: undefined
|
|
184
|
+
),
|
|
185
|
+
dependent: $.from('dynamicValueDefinitions').map((dynamicValueDefinitions) => {
|
|
186
|
+
if (
|
|
187
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() !==
|
|
188
|
+
'dependent_field'
|
|
189
|
+
) {
|
|
190
|
+
return undefined
|
|
191
|
+
}
|
|
192
|
+
const dynamicValueObject = dynamicValueDefinitions
|
|
193
|
+
.asObject()
|
|
194
|
+
.withAliasedKeys(calculationAliases)
|
|
195
|
+
generateDeprecatedDiagnostics(dynamicValueObject, diagnostics)
|
|
196
|
+
return dynamicValueObject.get('columnName').ifString()
|
|
197
|
+
}),
|
|
198
|
+
dependent_on_field: $.from('dynamicValueDefinitions').map((dynamicValueDefinitions) => {
|
|
199
|
+
if (
|
|
200
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() !==
|
|
201
|
+
'dependent_field'
|
|
202
|
+
) {
|
|
203
|
+
return undefined
|
|
204
|
+
}
|
|
205
|
+
const dynamicValueObject = dynamicValueDefinitions
|
|
206
|
+
.asObject()
|
|
207
|
+
.withAliasedKeys(calculationAliases)
|
|
208
|
+
generateDeprecatedDiagnostics(dynamicValueObject, diagnostics)
|
|
209
|
+
return dynamicValueObject.get('columnName').ifString()
|
|
210
|
+
}),
|
|
211
|
+
use_dependent_field: $.from('dynamicValueDefinitions')
|
|
212
|
+
.map(
|
|
213
|
+
(dynamicValueDefinitions) =>
|
|
214
|
+
dynamicValueDefinitions.ifObject()?.get('type').ifString()?.getValue() ===
|
|
215
|
+
'dependent_field'
|
|
216
|
+
)
|
|
217
|
+
.def(false),
|
|
218
|
+
element_reference: $.from('elementReference').toBoolean().def(false),
|
|
219
|
+
function_definition: $.from('functionDefinition'),
|
|
220
|
+
function_field: $.from('functionDefinition')
|
|
221
|
+
.map((f) => f.isString() && f.getValue() !== '')
|
|
222
|
+
.def(false),
|
|
223
|
+
column_label: $.from('label')
|
|
224
|
+
.map((label) => (label.isString() ? label.asString() : undefined))
|
|
225
|
+
.def(column.get('name').asString()),
|
|
226
|
+
mandatory: $.toBoolean().def(false),
|
|
227
|
+
max_length: $.from('maxLength')
|
|
228
|
+
.map(
|
|
229
|
+
(maxLength) =>
|
|
230
|
+
maxLength.ifNumber()?.getValue() ?? maxLength.ifString()?.getValue()
|
|
231
|
+
)
|
|
232
|
+
.def(getDefaultMaxLength(columnType)),
|
|
233
|
+
primary: $.toBoolean().def(false),
|
|
234
|
+
read_only: $.from('readOnly').toBoolean().def(false),
|
|
235
|
+
reference: $.from('referenceTable'),
|
|
236
|
+
spell_check: $.from('spellCheck').toBoolean().def(false),
|
|
237
|
+
table_reference: $.from('tableReference').toBoolean().def(false),
|
|
238
|
+
text_index: $.from('textIndex').toBoolean().def(false),
|
|
239
|
+
unique: $.toBoolean().def(false),
|
|
240
|
+
widget: $,
|
|
241
|
+
xml_view: $.from('xmlView').toBoolean().def(false),
|
|
242
|
+
})),
|
|
243
|
+
})
|
|
244
|
+
.with(...documentationRecords, ...choiceRecords),
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
export function columnToCallExpression(
|
|
252
|
+
column: Record,
|
|
253
|
+
related: { choices: Record[]; documentation: Record[] }
|
|
254
|
+
): CallExpressionShape {
|
|
255
|
+
const callExpression = COLUMN_TYPE_TO_API[column.get('internal_type').asString().getValue()] ?? GenericColumn.name
|
|
256
|
+
const { choices, documentation } = related
|
|
257
|
+
return new CallExpressionShape({
|
|
258
|
+
source: column,
|
|
259
|
+
callee: callExpression,
|
|
260
|
+
args: [
|
|
261
|
+
column
|
|
262
|
+
.transform(({ $ }) => ({
|
|
263
|
+
active: $.toBoolean().def(true),
|
|
264
|
+
array: $.toBoolean().def(false),
|
|
265
|
+
attributes: $.map((attributes) => {
|
|
266
|
+
if (!attributes.isString()) {
|
|
267
|
+
return undefined
|
|
268
|
+
}
|
|
269
|
+
const result = {}
|
|
270
|
+
attributes
|
|
271
|
+
.toString()
|
|
272
|
+
.getValue()
|
|
273
|
+
.split(',')
|
|
274
|
+
.forEach((attr) => {
|
|
275
|
+
if (attr === '') {
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
const [key, value] = attr.split('=').map((s) => s.trim())
|
|
279
|
+
if (value === 'true') {
|
|
280
|
+
result[key!] = true
|
|
281
|
+
} else if (value === 'false') {
|
|
282
|
+
result[key!] = false
|
|
283
|
+
} else {
|
|
284
|
+
result[key!] = value
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
return result
|
|
288
|
+
}).def({
|
|
289
|
+
edge_encryption_enabled: true,
|
|
290
|
+
}),
|
|
291
|
+
audit: $.toBoolean().def(false),
|
|
292
|
+
cascadeRule: $.from('reference_cascade_rule').def(''),
|
|
293
|
+
columnType: callExpression === GenericColumn.name ? $.from('internal_type') : $.val(undefined),
|
|
294
|
+
default: $.from('default_value')
|
|
295
|
+
.map((defaultValue) => {
|
|
296
|
+
// TODO Solve default type inference generally
|
|
297
|
+
if (callExpression === BooleanColumn.name) {
|
|
298
|
+
if (defaultValue.isBoolean()) {
|
|
299
|
+
return defaultValue
|
|
300
|
+
} else if (defaultValue.isString()) {
|
|
301
|
+
const defaultString = defaultValue.asString().getValue().trim()
|
|
302
|
+
if (defaultString === 'true') {
|
|
303
|
+
return true
|
|
304
|
+
}
|
|
305
|
+
if (defaultString === 'false') {
|
|
306
|
+
return false
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (defaultValue.isNumber()) {
|
|
311
|
+
return defaultValue.getValue().toString()
|
|
312
|
+
}
|
|
313
|
+
return defaultValue
|
|
314
|
+
})
|
|
315
|
+
.def(''),
|
|
316
|
+
choices: choices.length
|
|
317
|
+
? $.val(
|
|
318
|
+
choices.reduce(
|
|
319
|
+
(acc, choiceRecord) => {
|
|
320
|
+
const value = choiceRecord.get('value').asString().getValue()
|
|
321
|
+
acc[value] = choiceRecord
|
|
322
|
+
.transform(({ $ }) => ({
|
|
323
|
+
label: $,
|
|
324
|
+
sequence: $.map((sequence) => {
|
|
325
|
+
if (sequence.isNumber()) {
|
|
326
|
+
return sequence
|
|
327
|
+
} else if (sequence.isString()) {
|
|
328
|
+
const sequenceVal = sequence.asString().getValue().trim()
|
|
329
|
+
return sequenceVal !== '' && !isNaN(Number(sequenceVal))
|
|
330
|
+
? Number(sequenceVal)
|
|
331
|
+
: undefined
|
|
332
|
+
}
|
|
333
|
+
return undefined
|
|
334
|
+
}),
|
|
335
|
+
dependentValue: $.from('dependent_value').map((depVal) => {
|
|
336
|
+
if (depVal.isNumber()) {
|
|
337
|
+
return depVal.asNumber().getValue()
|
|
338
|
+
} else if (depVal.isString()) {
|
|
339
|
+
const depValue = depVal.asString().getValue().trim()
|
|
340
|
+
return (
|
|
341
|
+
(isNaN(Number(depValue)) ? depValue : Number(depValue)) ||
|
|
342
|
+
undefined
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
return undefined
|
|
346
|
+
}),
|
|
347
|
+
inactive: $.toBoolean().def(false),
|
|
348
|
+
inactiveOnUpdate: $.from('inactive_on_update').toBoolean().def(false),
|
|
349
|
+
hint: $.def(''),
|
|
350
|
+
// TODO Make default language configurable
|
|
351
|
+
language: $.def('en'),
|
|
352
|
+
}))
|
|
353
|
+
.withAliasedKeys(choiceAliases)
|
|
354
|
+
return acc
|
|
355
|
+
},
|
|
356
|
+
{} as globalThis.Record<string, ObjectShape>
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
: $.val(undefined),
|
|
360
|
+
dropdown: $.from('choice')
|
|
361
|
+
.map((choice) => {
|
|
362
|
+
let dropdownIndex = -1
|
|
363
|
+
if (choice.isNumber()) {
|
|
364
|
+
dropdownIndex = choice.asNumber().getValue()
|
|
365
|
+
} else if (choice.isString()) {
|
|
366
|
+
const parsedChoice = Number(choice.asString().getValue())
|
|
367
|
+
if (!isNaN(parsedChoice)) {
|
|
368
|
+
dropdownIndex = parsedChoice
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return dropdownIndex !== -1 ? choiceDropdown[dropdownIndex] : undefined
|
|
372
|
+
})
|
|
373
|
+
.def('none'),
|
|
374
|
+
dynamicValueDefinitions: $.from('calculation', 'choice_table', 'choice_field', 'dependent').map(
|
|
375
|
+
(calculation, choiceTable, choiceField, dependent) => {
|
|
376
|
+
if (
|
|
377
|
+
calculation.ifString()?.getValue() &&
|
|
378
|
+
calculation.asString().getValue() !== DEFAULT_COLUMN_CALCULATION
|
|
379
|
+
) {
|
|
380
|
+
return new ObjectShape({
|
|
381
|
+
source: calculation,
|
|
382
|
+
properties: {
|
|
383
|
+
type: 'calculated_value',
|
|
384
|
+
calculatedValue: calculation,
|
|
385
|
+
},
|
|
386
|
+
}).withAliasedKeys(calculationAliases)
|
|
387
|
+
}
|
|
388
|
+
if (choiceTable.ifString()?.getValue() && choiceField.ifString()?.getValue()) {
|
|
389
|
+
return {
|
|
390
|
+
type: 'choices_from_other_table',
|
|
391
|
+
table: choiceTable.asString().getValue(),
|
|
392
|
+
field: choiceField.asString().getValue(),
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (dependent.ifString()?.getValue()) {
|
|
396
|
+
return new ObjectShape({
|
|
397
|
+
source: dependent,
|
|
398
|
+
properties: {
|
|
399
|
+
type: 'dependent_field',
|
|
400
|
+
columnName: dependent.asString().getValue(),
|
|
401
|
+
},
|
|
402
|
+
}).withAliasedKeys(calculationAliases)
|
|
403
|
+
}
|
|
404
|
+
return undefined
|
|
405
|
+
}
|
|
406
|
+
),
|
|
407
|
+
elementReference: $.from('element_reference').toBoolean().def(false),
|
|
408
|
+
functionDefinition: $.from('function_definition').def(''),
|
|
409
|
+
label:
|
|
410
|
+
documentation.length &&
|
|
411
|
+
!isDefaultDocumentation(column.get('element').asString().getValue(), documentation)
|
|
412
|
+
? $.val(
|
|
413
|
+
documentation.map((doc) =>
|
|
414
|
+
doc
|
|
415
|
+
.transform(({ $ }) => ({
|
|
416
|
+
hint: $.def(''),
|
|
417
|
+
help: $.def(''),
|
|
418
|
+
label: $.def(''),
|
|
419
|
+
plural: $.def(''),
|
|
420
|
+
language: $.def(''),
|
|
421
|
+
url: $.def(''),
|
|
422
|
+
urlTarget: $.from('url_target').def(''),
|
|
423
|
+
}))
|
|
424
|
+
.withAliasedKeys(documentationAliases)
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
: $.from('column_label').def(column.get('element').getValue()),
|
|
428
|
+
mandatory: $.toBoolean().def(false),
|
|
429
|
+
maxLength: $.from('max_length')
|
|
430
|
+
.map((maxLength) => {
|
|
431
|
+
if (maxLength.isNumber()) {
|
|
432
|
+
return maxLength.asNumber()
|
|
433
|
+
}
|
|
434
|
+
if (maxLength.isString()) {
|
|
435
|
+
const numVal = parseInt(maxLength.asString().getValue())
|
|
436
|
+
return isNaN(numVal) ? maxLength : numVal
|
|
437
|
+
}
|
|
438
|
+
return undefined
|
|
439
|
+
})
|
|
440
|
+
.def(getDefaultMaxLength(column.get('internal_type').asString().getValue())),
|
|
441
|
+
primary: $.toBoolean().def(false),
|
|
442
|
+
readOnly: $.from('read_only').toBoolean().def(false),
|
|
443
|
+
referenceTable: $.from('reference').def(''),
|
|
444
|
+
referenceFloats: $.from('reference_floats').toBoolean().def(false),
|
|
445
|
+
referenceKey: $.from('reference_key').def(''),
|
|
446
|
+
referenceQual: $.from('reference_qual').def(''),
|
|
447
|
+
dynamicCreation: $.from('dynamic_creation').toBoolean().def(false),
|
|
448
|
+
dynamicCreationScript: $.from('dynamic_creation_script').def(''),
|
|
449
|
+
spellCheck: $.from('spell_check').toBoolean().def(false),
|
|
450
|
+
tableReference: $.from('table_reference').toBoolean().def(false),
|
|
451
|
+
textIndex: $.from('text_index').toBoolean().def(false),
|
|
452
|
+
unique: $.toBoolean().def(false),
|
|
453
|
+
widget: $.def(''),
|
|
454
|
+
xmlView: $.from('xml_view').toBoolean().def(false),
|
|
455
|
+
}))
|
|
456
|
+
.withAliasedKeys(columnAliases),
|
|
457
|
+
],
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export function generatePlural(label: string): string | undefined {
|
|
462
|
+
if (!label) {
|
|
463
|
+
return undefined
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
for (const suffix of PLURAL_EQUALS_LABEL) {
|
|
467
|
+
if (label.endsWith(suffix)) {
|
|
468
|
+
return label
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
for (const suffix of PLURAL_SPECIAL_CASE_Y_TO_IES) {
|
|
472
|
+
if (label.endsWith(suffix)) {
|
|
473
|
+
return label.substring(0, label.lastIndexOf('y')) + 'ies'
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
for (const suffix of PLURAL_SPECIAL_CASE_ADD_ES) {
|
|
477
|
+
if (label.endsWith(suffix)) {
|
|
478
|
+
return label + 'es'
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return label + 's'
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export function isDefaultDocumentation(columnName: string, documentation: Record[]): boolean {
|
|
486
|
+
if (documentation.length !== 1) {
|
|
487
|
+
return false
|
|
488
|
+
}
|
|
489
|
+
const doc = documentation[0]!.asObject().getValue() as globalThis.Record<string, unknown>
|
|
490
|
+
const label = (doc['label'] as string | undefined) ?? columnName
|
|
491
|
+
const defaultRecord: globalThis.Record<string, unknown> = {
|
|
492
|
+
name: doc['name'],
|
|
493
|
+
element: doc['element'],
|
|
494
|
+
label,
|
|
495
|
+
plural: generatePlural(label),
|
|
496
|
+
// TODO make default language configurable
|
|
497
|
+
language: 'en',
|
|
498
|
+
}
|
|
499
|
+
const optionalFields = ['hint', 'help', 'url', 'url_target', 'sys_policy'] as const
|
|
500
|
+
optionalFields.forEach((field) => {
|
|
501
|
+
if (field in doc) {
|
|
502
|
+
defaultRecord[field] = ''
|
|
503
|
+
}
|
|
504
|
+
})
|
|
505
|
+
return isEqual(defaultRecord, doc)
|
|
506
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CallExpressionShape, Plugin } from '@servicenow/sdk-build-core'
|
|
2
|
+
import { NowIdShape } from './now-id-plugin'
|
|
3
|
+
import { generateDeprecatedDiagnostics } from './utils'
|
|
4
|
+
|
|
5
|
+
const crossScopeAliases = {
|
|
6
|
+
targetName: ['target_name'],
|
|
7
|
+
targetScope: ['target_scope'],
|
|
8
|
+
targetType: ['target_type'],
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Cross Scope Privilege record (`sys_scope_privilege`).
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.servicenow.com/csh?topicname=c_CrossScopePrivilegeRecord.html&version=latest
|
|
15
|
+
*
|
|
16
|
+
* @param config - an object containing the following properties:
|
|
17
|
+
* * **$id** - unique id for the record, typically using `Now.ID["value"]`
|
|
18
|
+
* * **operation** - operation the script performs on the target
|
|
19
|
+
* * **status** - authorization for this record
|
|
20
|
+
* * **targetName** - name of the table, script include, or script object being requested
|
|
21
|
+
* * **targetScope** - application whose resources are being requested
|
|
22
|
+
* * **targetType** - type of request
|
|
23
|
+
*/
|
|
24
|
+
export const CrossScopePrivilegePlugin = Plugin.create({
|
|
25
|
+
name: 'CrossScopePrivilegePlugin',
|
|
26
|
+
records: {
|
|
27
|
+
sys_scope_privilege: {
|
|
28
|
+
toShape(record) {
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
value: new CallExpressionShape({
|
|
32
|
+
source: record,
|
|
33
|
+
callee: 'CrossScopePrivilege',
|
|
34
|
+
args: [
|
|
35
|
+
record
|
|
36
|
+
.transform(({ $ }) => ({
|
|
37
|
+
$id: $.val(NowIdShape.from(record)),
|
|
38
|
+
operation: $,
|
|
39
|
+
status: $,
|
|
40
|
+
targetName: $.from('target_name'),
|
|
41
|
+
targetScope: $.from('target_scope'),
|
|
42
|
+
targetType: $.from('target_type'),
|
|
43
|
+
}))
|
|
44
|
+
.withAliasedKeys(crossScopeAliases),
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
shapes: [
|
|
52
|
+
{
|
|
53
|
+
shape: CallExpressionShape,
|
|
54
|
+
fileTypes: ['fluent'],
|
|
55
|
+
toRecord(callExpression, { factory, config, diagnostics }) {
|
|
56
|
+
if (callExpression.getCallee() !== 'CrossScopePrivilege') {
|
|
57
|
+
return { success: false }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const csp = callExpression.getArgument(0).asObject().withAliasedKeys(crossScopeAliases)
|
|
61
|
+
generateDeprecatedDiagnostics(csp, diagnostics)
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
value: factory.createRecord({
|
|
66
|
+
source: callExpression,
|
|
67
|
+
table: 'sys_scope_privilege',
|
|
68
|
+
explicitId: csp.get('$id'),
|
|
69
|
+
properties: csp.transform(({ $ }) => ({
|
|
70
|
+
operation: $,
|
|
71
|
+
status: $,
|
|
72
|
+
target_name: $.from('targetName'),
|
|
73
|
+
target_scope: $.from('targetScope'),
|
|
74
|
+
target_type: $.from('targetType'),
|
|
75
|
+
source_scope: $.val(config.scopeId),
|
|
76
|
+
})),
|
|
77
|
+
}),
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { path as pathModule, Plugin, Shape, StringShape, ts } from '@servicenow/sdk-build-core'
|
|
2
|
+
import { applyPathMappings } from './utils'
|
|
3
|
+
|
|
4
|
+
const HTML_IMPORT_PREFIX = `<!-- @fluent-import-html`
|
|
5
|
+
const HTML_IMPORT_WARNING = `WARNING: This file was imported from the output of a static build. Modifications of any kind are likely to result in unintended behavior. In most cases, you should edit the source file of the HTML imported below. If you are absolutely certain you want to take control of this HTML, you can remove this comment to prevent the SDK from regenerating it. However, you will then be responsible for the management of this HTML in your Fluent file. -->`
|
|
6
|
+
|
|
7
|
+
const getDeclarationAndModuleSpecifierIfHtml = (node: ts.Node): [ts.ImportDeclaration, string] | null => {
|
|
8
|
+
const [importClause] = node.getSymbol()?.getDeclarations() ?? []
|
|
9
|
+
if (!importClause) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const importDeclaration = importClause.getParent()?.asKind(ts.SyntaxKind.ImportDeclaration)
|
|
14
|
+
if (!importDeclaration) {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const moduleSpecifier = importDeclaration.getModuleSpecifierValue()
|
|
19
|
+
if (!moduleSpecifier.endsWith('.html')) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return [importDeclaration, moduleSpecifier]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const HtmlImportPlugin = Plugin.create({
|
|
27
|
+
name: 'HtmlImportPlugin',
|
|
28
|
+
shapes: [
|
|
29
|
+
{
|
|
30
|
+
shape: StringShape,
|
|
31
|
+
commit(shape, target) {
|
|
32
|
+
const results = getDeclarationAndModuleSpecifierIfHtml(target)
|
|
33
|
+
if (!results) {
|
|
34
|
+
return { success: false }
|
|
35
|
+
}
|
|
36
|
+
const shapeContent = shape.getValue().trim()
|
|
37
|
+
// skip committing if the content has the import directive comment
|
|
38
|
+
return { success: shapeContent.startsWith(HTML_IMPORT_PREFIX) }
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
nodes: [
|
|
43
|
+
{
|
|
44
|
+
node: 'Identifier',
|
|
45
|
+
fileTypes: ['fluent'],
|
|
46
|
+
toShape(node, context) {
|
|
47
|
+
const { project, diagnostics, config } = context
|
|
48
|
+
const results = getDeclarationAndModuleSpecifierIfHtml(node)
|
|
49
|
+
if (!results) {
|
|
50
|
+
return { success: false }
|
|
51
|
+
}
|
|
52
|
+
const [importDeclaration, moduleSpecifier] = results
|
|
53
|
+
|
|
54
|
+
if (!/^\.\.?\/.*$/.test(moduleSpecifier.trim())) {
|
|
55
|
+
diagnostics.error(importDeclaration, 'import must be a relative path')
|
|
56
|
+
return { success: false }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const currentDir = pathModule.dirname(node.getSourceFile().getFilePath())
|
|
60
|
+
const resolvedPath = project.resolvePath(currentDir, moduleSpecifier)
|
|
61
|
+
const projectRelativePath = pathModule.relative(project.getRootDir(), resolvedPath)
|
|
62
|
+
|
|
63
|
+
if (projectRelativePath.startsWith('..')) {
|
|
64
|
+
diagnostics.error(importDeclaration, `import not within project: ${moduleSpecifier}`)
|
|
65
|
+
return { success: false }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const mappedPath = applyPathMappings(projectRelativePath, config.staticContentPaths)
|
|
69
|
+
const htmlFile = project.addFile(mappedPath, { resolveDependencies: false, excludeFromCompiler: true })
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
success: true,
|
|
73
|
+
// add a directive comment to the imported HTML content to warn users against modifing it
|
|
74
|
+
value: Shape.from(node, `${HTML_IMPORT_PREFIX} ${HTML_IMPORT_WARNING}\n${htmlFile.getContent()}`),
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
})
|