@servicenow/sdk-build-plugins 3.0.3 → 4.0.1
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 +39 -0
- package/dist/atf/step-configs.js +2334 -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 +600 -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 +164 -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 +2384 -0
- package/src/atf/test-plugin.ts +739 -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 +179 -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 +658 -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 -1630
- 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 -2072
- 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
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import {
|
|
3
|
-
BusinessRule,
|
|
4
|
-
BusinessRuleSchema,
|
|
5
|
-
BusinessRuleSchemaInc,
|
|
6
|
-
getRolesArray,
|
|
7
|
-
localWhenSchemaTransformer,
|
|
8
|
-
} from '@servicenow/sdk-core/runtime/app'
|
|
9
|
-
import {
|
|
10
|
-
Plugin,
|
|
11
|
-
generateCallExpressionExportForDocument,
|
|
12
|
-
getSysUpdateName,
|
|
13
|
-
getCallExpressionName,
|
|
14
|
-
getOrCreateEntitySourceFile,
|
|
15
|
-
linkDocument,
|
|
16
|
-
removeNode,
|
|
17
|
-
stringify,
|
|
18
|
-
transformFunctionArguments,
|
|
19
|
-
writeArrayPropertyAsReference,
|
|
20
|
-
writeCustomProperty,
|
|
21
|
-
getOrCreatePropertyAssignment,
|
|
22
|
-
EntityData,
|
|
23
|
-
ObjectData,
|
|
24
|
-
StringData,
|
|
25
|
-
NumberData,
|
|
26
|
-
BooleanData,
|
|
27
|
-
Data,
|
|
28
|
-
UndefinedData,
|
|
29
|
-
transformCustomizedProperties,
|
|
30
|
-
} from '@servicenow/sdk-build-core'
|
|
31
|
-
import { additionalProperties } from '@servicenow/sdk-core/runtime/util'
|
|
32
|
-
import { processScript } from './ScriptTemplatePlugin'
|
|
33
|
-
import { extractCallExpressionAsRecord } from './db/RecordPlugin'
|
|
34
|
-
import * as z from 'zod'
|
|
35
|
-
import { Diagnostic, ts } from '@servicenow/sdk-project'
|
|
36
|
-
import { Record, TableName } from '@servicenow/sdk-core/runtime/db'
|
|
37
|
-
import { getRolesString } from './aclAndRole/RolePlugin'
|
|
38
|
-
import { ModuleFunctionData } from './ServerModulePlugin'
|
|
39
|
-
|
|
40
|
-
// Similar to lodash's groupBy, but simply stores the last element of each group
|
|
41
|
-
function groupByExistence<T>(collection: T[] | undefined, keyProvider: (element: T) => string): { [key: string]: T } {
|
|
42
|
-
return (
|
|
43
|
-
collection?.reduce((groups, e) => {
|
|
44
|
-
groups[keyProvider(e)] = e
|
|
45
|
-
return groups
|
|
46
|
-
}, {}) ?? {}
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function businessRuleAsRecord<const T extends TableName>(entity: EntityData<BusinessRule<T>>): ObjectData<Record> {
|
|
51
|
-
const node = entity.getNode()
|
|
52
|
-
const br = entity.getProperties()
|
|
53
|
-
const rest = additionalProperties(br, BusinessRuleSchema)
|
|
54
|
-
|
|
55
|
-
const scriptData = br.script
|
|
56
|
-
const script = new StringData(
|
|
57
|
-
ModuleFunctionData.getGlueCode(scriptData, (n) => `${n}(current, previous)`),
|
|
58
|
-
scriptData?.getNode() ?? node
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const roleConditionsData = br.role_conditions
|
|
62
|
-
const roleConditions = new StringData(
|
|
63
|
-
roleConditionsData && Data.isArray(roleConditionsData) ? getRolesString(roleConditionsData) : '',
|
|
64
|
-
roleConditionsData?.getNode() ?? node
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
const { insertAction, updateAction, deleteAction, queryAction } = groupByExistence(
|
|
68
|
-
entity.getProperty('action', 'array')?.getElements(),
|
|
69
|
-
(action) => `${action.getValue()}Action`
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
const when = new StringData(localWhenSchemaTransformer(br.when.getValue()), br.when.getNode())
|
|
73
|
-
|
|
74
|
-
return new ObjectData(
|
|
75
|
-
{
|
|
76
|
-
$id: br.$id,
|
|
77
|
-
table: new StringData('sys_script', node),
|
|
78
|
-
data: new ObjectData(
|
|
79
|
-
{
|
|
80
|
-
...rest,
|
|
81
|
-
name: br.name,
|
|
82
|
-
collection: br.table,
|
|
83
|
-
script,
|
|
84
|
-
order: br.order ?? new NumberData(100, node),
|
|
85
|
-
action_insert: new BooleanData(!!insertAction, insertAction?.getNode() ?? node),
|
|
86
|
-
action_update: new BooleanData(!!updateAction, updateAction?.getNode() ?? node),
|
|
87
|
-
action_query: new BooleanData(!!queryAction, queryAction?.getNode() ?? node),
|
|
88
|
-
action_delete: new BooleanData(!!deleteAction, deleteAction?.getNode() ?? node),
|
|
89
|
-
active: br.active ?? new BooleanData(true, node),
|
|
90
|
-
when: br.when ? when : new StringData('before', node),
|
|
91
|
-
message: br.message ?? new UndefinedData(node),
|
|
92
|
-
add_message: br.add_message ?? new BooleanData(br.message ? true : false, node),
|
|
93
|
-
condition: br.condition ?? new UndefinedData(node),
|
|
94
|
-
filter_condition: br.filter_condition ?? new UndefinedData(node),
|
|
95
|
-
template: br.set_field_value ?? new UndefinedData(node),
|
|
96
|
-
description: br.description ?? new UndefinedData(node),
|
|
97
|
-
role_conditions: roleConditions,
|
|
98
|
-
},
|
|
99
|
-
node
|
|
100
|
-
),
|
|
101
|
-
},
|
|
102
|
-
node
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default Plugin({
|
|
107
|
-
name: 'BusinessRule',
|
|
108
|
-
ownedTables: {
|
|
109
|
-
sys_script: { diagnosticLevel: Diagnostic.Level.Warn },
|
|
110
|
-
},
|
|
111
|
-
extractors: {
|
|
112
|
-
entity: {
|
|
113
|
-
fluent: {
|
|
114
|
-
CallExpression(node, context) {
|
|
115
|
-
return extractCallExpressionAsRecord(
|
|
116
|
-
BusinessRule,
|
|
117
|
-
businessRuleAsRecord,
|
|
118
|
-
(br) => context.registerExplicitId('sys_script', br.$id as string),
|
|
119
|
-
node,
|
|
120
|
-
context
|
|
121
|
-
)
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
generators: {
|
|
127
|
-
record(document, context) {
|
|
128
|
-
const tableName = document.data!['table']
|
|
129
|
-
if (tableName !== 'sys_script') {
|
|
130
|
-
return undefined
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return linkDocument(
|
|
134
|
-
document,
|
|
135
|
-
generateCallExpressionExportForDocument(
|
|
136
|
-
context,
|
|
137
|
-
{
|
|
138
|
-
sourceFile: getOrCreateEntitySourceFile(context, getSysUpdateName(document, 'sys_script')),
|
|
139
|
-
moduleSpecifier: '@servicenow/sdk/core',
|
|
140
|
-
},
|
|
141
|
-
BusinessRule,
|
|
142
|
-
{ $id: document.guid }
|
|
143
|
-
).getExpressionIfKindOrThrow(ts.SyntaxKind.CallExpression)
|
|
144
|
-
)
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
transformers: {
|
|
148
|
-
record: {
|
|
149
|
-
CallExpression(document) {
|
|
150
|
-
if (getCallExpressionName(document.node) !== BusinessRule.name) {
|
|
151
|
-
return false
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (document.action === 'DELETE') {
|
|
155
|
-
removeNode(document.node)
|
|
156
|
-
return true
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const changedData = (document.changedData as any).data
|
|
160
|
-
const modified_properties = BusinessRuleSchemaInc.deepPartial().safeParse(changedData)
|
|
161
|
-
const merged_properties = BusinessRuleSchemaInc.safeParse((document.data as any).data)
|
|
162
|
-
const incoming_properties = BusinessRuleSchemaInc.safeParse((document.xmlData as any).data)
|
|
163
|
-
if (!modified_properties.success || !merged_properties.success || !incoming_properties.success) {
|
|
164
|
-
return false
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const [args] = document.node.getArguments()
|
|
168
|
-
if (!ts.Node.isObjectLiteralExpression(args)) {
|
|
169
|
-
return false
|
|
170
|
-
}
|
|
171
|
-
const {
|
|
172
|
-
role_conditions: roles,
|
|
173
|
-
filter_condition: filters,
|
|
174
|
-
collection,
|
|
175
|
-
script,
|
|
176
|
-
template,
|
|
177
|
-
action_delete,
|
|
178
|
-
action_insert,
|
|
179
|
-
action_query,
|
|
180
|
-
action_update,
|
|
181
|
-
...rest
|
|
182
|
-
} = modified_properties.data
|
|
183
|
-
|
|
184
|
-
const xml_actions = getActionsArray(incoming_properties.data)
|
|
185
|
-
if (xml_actions.length > 0 || getActionsArray(merged_properties.data).length > 0) {
|
|
186
|
-
writeCustomProperty(args, 'action', '[]', stringify(xml_actions))
|
|
187
|
-
} else {
|
|
188
|
-
const actionsProp = getOrCreatePropertyAssignment(args, 'action', '[]')
|
|
189
|
-
actionsProp.remove()
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (roles) {
|
|
193
|
-
writeArrayPropertyAsReference(args, 'role_conditions', '[]', getRolesArray(roles))
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (filters) {
|
|
197
|
-
writeCustomProperty(args, 'filter_condition', '', `\`${filters}\``)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (script !== undefined) {
|
|
201
|
-
processScript(args, 'script', script)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (template) {
|
|
205
|
-
writeCustomProperty(args, 'set_field_value', '', stringify(template))
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const reqSchema = BusinessRuleSchemaInc.required()
|
|
209
|
-
transformCustomizedProperties(BusinessRule, document.node, changedData, modified_properties.data)
|
|
210
|
-
const result = transformFunctionArguments(document.node, BusinessRule, {
|
|
211
|
-
table: collection,
|
|
212
|
-
...(rest as Partial<z.infer<typeof reqSchema>>),
|
|
213
|
-
})
|
|
214
|
-
return result
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
function getActionsArray(data) {
|
|
221
|
-
const actions: BR_ACTIONS[] = []
|
|
222
|
-
if (data.action_update) {
|
|
223
|
-
actions.push('update')
|
|
224
|
-
}
|
|
225
|
-
if (data.action_delete) {
|
|
226
|
-
actions.push('delete')
|
|
227
|
-
}
|
|
228
|
-
if (data.action_insert) {
|
|
229
|
-
actions.push('insert')
|
|
230
|
-
}
|
|
231
|
-
if (data.action_query) {
|
|
232
|
-
actions.push('query')
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return actions
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
type BR_ACTIONS = 'insert' | 'update' | 'delete' | 'query'
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { CrossScopePrivilege, CrossScopePrivilegeSchema } from '@servicenow/sdk-core/runtime/app'
|
|
2
|
-
import {
|
|
3
|
-
EntityData,
|
|
4
|
-
extractCallExpression,
|
|
5
|
-
generateCallExpressionExportForDocument,
|
|
6
|
-
getCallExpressionName,
|
|
7
|
-
getOrCreateEntitySourceFile,
|
|
8
|
-
getSysUpdateName,
|
|
9
|
-
linkDocument,
|
|
10
|
-
ObjectData,
|
|
11
|
-
Plugin,
|
|
12
|
-
removeNode,
|
|
13
|
-
transformFunctionArguments,
|
|
14
|
-
} from '@servicenow/sdk-build-core'
|
|
15
|
-
import { RecordPlugin } from './db/RecordPlugin'
|
|
16
|
-
import { Diagnostic, ts } from '@servicenow/sdk-project'
|
|
17
|
-
import { Record } from '@servicenow/sdk-core/runtime/db'
|
|
18
|
-
import { except } from './scripts/scriptUtils'
|
|
19
|
-
import z from 'zod'
|
|
20
|
-
|
|
21
|
-
export default Plugin({
|
|
22
|
-
name: 'CrossScopePrivilege',
|
|
23
|
-
ownedTables: {
|
|
24
|
-
sys_scope_privilege: { diagnosticLevel: Diagnostic.Level.Warn },
|
|
25
|
-
},
|
|
26
|
-
extractors: {
|
|
27
|
-
entity: {
|
|
28
|
-
fluent: {
|
|
29
|
-
CallExpression: (node, context) =>
|
|
30
|
-
extractCallExpression(CrossScopePrivilege, 'sys_scope_privilege', node, context, (privilege) =>
|
|
31
|
-
context.registerExplicitId('sys_scope_privilege', privilege.$id as string)
|
|
32
|
-
),
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
composers: {
|
|
37
|
-
entity: {
|
|
38
|
-
sys_scope_privilege(entity, context) {
|
|
39
|
-
const scopeId = context.app.config.scopeId
|
|
40
|
-
const privilege = CrossScopePrivilegeSchema.and(z.any()).safeParse(entity.getValue())
|
|
41
|
-
if (!privilege.success) {
|
|
42
|
-
return Promise.resolve(undefined)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { $id, ...rest } = privilege.data
|
|
46
|
-
|
|
47
|
-
const privilegeRecord = Record({
|
|
48
|
-
table: 'sys_scope_privilege',
|
|
49
|
-
$id,
|
|
50
|
-
data: {
|
|
51
|
-
source_scope: scopeId,
|
|
52
|
-
...rest,
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
return context.composeEntities(
|
|
57
|
-
[
|
|
58
|
-
new EntityData(
|
|
59
|
-
'record',
|
|
60
|
-
entity.getGuid(),
|
|
61
|
-
ObjectData.fromObjectValue(privilegeRecord, entity.getNode()),
|
|
62
|
-
entity.getNode(),
|
|
63
|
-
entity.getInstallMethod()
|
|
64
|
-
),
|
|
65
|
-
],
|
|
66
|
-
[RecordPlugin]
|
|
67
|
-
)
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
generators: {
|
|
72
|
-
record(document, ctx) {
|
|
73
|
-
const tableName = document.data!['table']
|
|
74
|
-
if (tableName !== 'sys_scope_privilege') {
|
|
75
|
-
return undefined
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return linkDocument(
|
|
79
|
-
document,
|
|
80
|
-
generateCallExpressionExportForDocument(
|
|
81
|
-
ctx,
|
|
82
|
-
{
|
|
83
|
-
sourceFile: getOrCreateEntitySourceFile(ctx, getSysUpdateName(document, 'sys_scope_privilege')),
|
|
84
|
-
moduleSpecifier: '@servicenow/sdk/core',
|
|
85
|
-
},
|
|
86
|
-
CrossScopePrivilege,
|
|
87
|
-
{ $id: document.guid }
|
|
88
|
-
).getExpressionIfKindOrThrow(ts.SyntaxKind.CallExpression)
|
|
89
|
-
)
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
transformers: {
|
|
94
|
-
record: {
|
|
95
|
-
CallExpression(document) {
|
|
96
|
-
if (getCallExpressionName(document.node) !== CrossScopePrivilege.name) {
|
|
97
|
-
return false
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (document.action === 'DELETE') {
|
|
101
|
-
removeNode(document.node)
|
|
102
|
-
return true
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!document.changedData) {
|
|
106
|
-
return false
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const crossScopeData = (document.changedData as any).data
|
|
110
|
-
const cleanedData = except(crossScopeData, (key) => key.startsWith('sys_') || key === 'source_scope')
|
|
111
|
-
return transformFunctionArguments(document.node, CrossScopePrivilege, cleanedData)
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
})
|
package/src/DefaultPlugin.ts
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { isSupportedNode } from '@servicenow/sdk-project'
|
|
2
|
-
import {
|
|
3
|
-
getValueDeclaration,
|
|
4
|
-
Plugin,
|
|
5
|
-
BooleanData,
|
|
6
|
-
FluentDiagnostic,
|
|
7
|
-
StringData,
|
|
8
|
-
NumberData,
|
|
9
|
-
Data,
|
|
10
|
-
ArrayData,
|
|
11
|
-
ObjectData,
|
|
12
|
-
getDirectiveDiagnostics,
|
|
13
|
-
} from '@servicenow/sdk-build-core'
|
|
14
|
-
import { ts } from '@servicenow/sdk-project'
|
|
15
|
-
|
|
16
|
-
export default Plugin({
|
|
17
|
-
name: 'Default',
|
|
18
|
-
extractors: {
|
|
19
|
-
raw: {
|
|
20
|
-
any: {
|
|
21
|
-
TrueKeyword(node) {
|
|
22
|
-
return {
|
|
23
|
-
handled: true,
|
|
24
|
-
diagnostics: [],
|
|
25
|
-
data: new BooleanData(true, node),
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
FalseKeyword(node) {
|
|
30
|
-
return {
|
|
31
|
-
handled: true,
|
|
32
|
-
diagnostics: [],
|
|
33
|
-
data: new BooleanData(false, node),
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
StringLiteral(node) {
|
|
38
|
-
return {
|
|
39
|
-
handled: true,
|
|
40
|
-
diagnostics: [],
|
|
41
|
-
data: new StringData(node.getLiteralValue(), node),
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
NoSubstitutionTemplateLiteral(node) {
|
|
46
|
-
return {
|
|
47
|
-
handled: true,
|
|
48
|
-
diagnostics: [],
|
|
49
|
-
data: new StringData(node.getLiteralValue(), node),
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
NumericLiteral(node) {
|
|
54
|
-
return {
|
|
55
|
-
handled: true,
|
|
56
|
-
diagnostics: [],
|
|
57
|
-
data: new NumberData(node.getLiteralValue(), node),
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
AsExpression(node, context) {
|
|
62
|
-
return context.extractAst(node.getExpression())
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
ExportAssignment(node, context) {
|
|
66
|
-
return context.extractAst(node.getExpression())
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
ComputedPropertyName(node, context) {
|
|
70
|
-
return context.extractAst(node.getExpression())
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
Identifier(node, context) {
|
|
74
|
-
const extracted = context.extractAst(getValueDeclaration(node))
|
|
75
|
-
|
|
76
|
-
const newDiagnostics: FluentDiagnostic[] = []
|
|
77
|
-
if (extracted['diagnostics']) {
|
|
78
|
-
extracted['diagnostics'].forEach((diagnostic) => {
|
|
79
|
-
newDiagnostics.push(new FluentDiagnostic(node, diagnostic.message))
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
handled: extracted.handled,
|
|
84
|
-
data: extracted['data'],
|
|
85
|
-
diagnostics: newDiagnostics,
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
PropertyAccessExpression(node, context) {
|
|
90
|
-
return context.extractAst(node.getNameNode())
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
ShorthandPropertyAssignment(node, context) {
|
|
94
|
-
return context.extractAst(node.getNameNode())
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
VariableDeclaration(node, context) {
|
|
98
|
-
const initializer = node.getInitializer()
|
|
99
|
-
if (!initializer) {
|
|
100
|
-
return {
|
|
101
|
-
handled: true,
|
|
102
|
-
diagnostics: [
|
|
103
|
-
new FluentDiagnostic(
|
|
104
|
-
node,
|
|
105
|
-
`Expected variable declaration to have an initializer: ${node.getText()}`
|
|
106
|
-
),
|
|
107
|
-
],
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return context.extractAst(initializer)
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
PropertyAssignment(node, context) {
|
|
115
|
-
const initializer = node.getInitializer()
|
|
116
|
-
if (!initializer) {
|
|
117
|
-
return {
|
|
118
|
-
handled: true,
|
|
119
|
-
diagnostics: [
|
|
120
|
-
new FluentDiagnostic(
|
|
121
|
-
node,
|
|
122
|
-
`Expected property assignment to have an initializer: ${node.getText()}`
|
|
123
|
-
),
|
|
124
|
-
],
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return context.extractAst(initializer)
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
ArrayLiteralExpression(node, context) {
|
|
132
|
-
const diagnostics: FluentDiagnostic[] = []
|
|
133
|
-
const data: Data[] = []
|
|
134
|
-
|
|
135
|
-
for (const element of node.getElements()) {
|
|
136
|
-
const result = context.extractAst(element)
|
|
137
|
-
if (!result.handled) {
|
|
138
|
-
return {
|
|
139
|
-
handled: true,
|
|
140
|
-
diagnostics: [new FluentDiagnostic(element, 'Unsupported array element')],
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
diagnostics.push(...result.diagnostics)
|
|
145
|
-
if (result.data) {
|
|
146
|
-
data.push(result.data)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
handled: true,
|
|
152
|
-
diagnostics,
|
|
153
|
-
data: new ArrayData(data, node),
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
ObjectLiteralExpression(node, context) {
|
|
158
|
-
const diagnostics: FluentDiagnostic[] = []
|
|
159
|
-
const data: Record<string, Data> = {}
|
|
160
|
-
|
|
161
|
-
for (const prop of node.getProperties()) {
|
|
162
|
-
if (!ts.Node.isPropertyAssignment(prop) && !ts.Node.isShorthandPropertyAssignment(prop)) {
|
|
163
|
-
diagnostics.push(new FluentDiagnostic(prop, 'Only property assignments are allowed'))
|
|
164
|
-
continue
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const nameNode = prop.getNameNode()
|
|
168
|
-
const result = context.extractAst(prop)
|
|
169
|
-
if (!result.handled) {
|
|
170
|
-
return {
|
|
171
|
-
handled: true,
|
|
172
|
-
diagnostics: [new FluentDiagnostic(prop, 'Unsupported property assignment')],
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
diagnostics.push(...result.diagnostics)
|
|
177
|
-
if (!result.data) {
|
|
178
|
-
diagnostics.push(
|
|
179
|
-
new FluentDiagnostic(nameNode, `Property assignment has unsupported structure`)
|
|
180
|
-
)
|
|
181
|
-
continue
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const name = ts.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName()
|
|
185
|
-
data[name] = result.data
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
handled: true,
|
|
190
|
-
diagnostics,
|
|
191
|
-
data: new ObjectData(data, node),
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
TemplateExpression(node, context) {
|
|
196
|
-
const diagnostics: FluentDiagnostic[] = []
|
|
197
|
-
const text =
|
|
198
|
-
node.getHead().getLiteralText() +
|
|
199
|
-
node
|
|
200
|
-
.getTemplateSpans()
|
|
201
|
-
.map((s) => {
|
|
202
|
-
const result = context.extractAst(s.getExpression())
|
|
203
|
-
if (!result.handled) {
|
|
204
|
-
diagnostics.push(new FluentDiagnostic(s, 'Unsupported expression in template'))
|
|
205
|
-
return undefined
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!result.data) {
|
|
209
|
-
diagnostics.push(new FluentDiagnostic(s, `Unsupported expression in template`))
|
|
210
|
-
return undefined
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
diagnostics.push(...result.diagnostics)
|
|
214
|
-
return `${result.data.getValue()}${s.getLiteral().getLiteralText()}`
|
|
215
|
-
})
|
|
216
|
-
.join('')
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
handled: true,
|
|
220
|
-
diagnostics,
|
|
221
|
-
data: new StringData(text, node),
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
//Added support for -ve number alone. Can be upgraded later to support other expressions as required.
|
|
226
|
-
PrefixUnaryExpression(node) {
|
|
227
|
-
if (
|
|
228
|
-
!ts.Node.isNumericLiteral(node.getOperand()) ||
|
|
229
|
-
node.getOperatorToken() !== ts.SyntaxKind.MinusToken
|
|
230
|
-
) {
|
|
231
|
-
return {
|
|
232
|
-
handled: true,
|
|
233
|
-
diagnostics: [new FluentDiagnostic(node, 'Unsupported prefix unary expression')],
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
handled: true,
|
|
239
|
-
diagnostics: [],
|
|
240
|
-
data: new NumberData(
|
|
241
|
-
-node.getOperand().asKind(ts.SyntaxKind.NumericLiteral)!.getLiteralValue(),
|
|
242
|
-
node
|
|
243
|
-
),
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
diagnostics: {
|
|
250
|
-
Node(node) {
|
|
251
|
-
if (isSupportedNode(node)) {
|
|
252
|
-
return getDirectiveDiagnostics(node)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return [new FluentDiagnostic(node, `${getRawKindName(node)} is not allowed`)]
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
let rawKindNames: Record<ts.SyntaxKind, string> | undefined
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* This is a hack to get more accurate names for given syntax kinds. TypeScript's
|
|
264
|
-
* `SyntaxKind` enum has a lot of reused numeric values, so when you try to index
|
|
265
|
-
* it with a number, you might get a different name than you expect. For example,
|
|
266
|
-
* `VariableStatement` and `FirstStatement` both have the same numeric value, and
|
|
267
|
-
* you probably never would expect the latter. Thankfully, all the names that you
|
|
268
|
-
* probably never want are towards the end, so this just grabs all the first ones
|
|
269
|
-
* and ignores any duplicates that come after.
|
|
270
|
-
*/
|
|
271
|
-
function getRawKindName(node: ts.Node): string | undefined {
|
|
272
|
-
if (!rawKindNames) {
|
|
273
|
-
rawKindNames = Object.entries(ts.SyntaxKind)
|
|
274
|
-
.filter(([k]) => isNaN(Number(k)))
|
|
275
|
-
.reduce(
|
|
276
|
-
(names, [name, value]) => {
|
|
277
|
-
if (typeof value === 'number' && !names[value]) {
|
|
278
|
-
names[value] = name // Only add if it hasn't been added already
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return names
|
|
282
|
-
},
|
|
283
|
-
{} as Record<ts.SyntaxKind, string>
|
|
284
|
-
)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return rawKindNames[node.getKind()]
|
|
288
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Plugin, StringData, UndefinedData } from '@servicenow/sdk-build-core'
|
|
2
|
-
import { ts } from '@servicenow/sdk-project'
|
|
3
|
-
|
|
4
|
-
const TEMPLATE_LITERAL_TAG = 'html'
|
|
5
|
-
|
|
6
|
-
export default Plugin({
|
|
7
|
-
name: 'htmlTemplate',
|
|
8
|
-
extractors: {
|
|
9
|
-
raw: {
|
|
10
|
-
fluent: {
|
|
11
|
-
TaggedTemplateExpression: (node) => {
|
|
12
|
-
if (node.getTag().getText() !== TEMPLATE_LITERAL_TAG) {
|
|
13
|
-
return { handled: false }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const value = getTemplateLiteralValue(node)?.trim()
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
handled: true,
|
|
20
|
-
diagnostics: [],
|
|
21
|
-
data: typeof value === 'string' ? new StringData(value, node) : new UndefinedData(node),
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
function getTemplateLiteralValue(node: ts.TaggedTemplateExpression) {
|
|
30
|
-
return node?.getTemplate().asKind(ts.SyntaxKind.NoSubstitutionTemplateLiteral)?.getLiteralValue()
|
|
31
|
-
}
|