@servicenow/sdk-build-plugins 2.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/AttachmentPlugin.d.ts +253 -0
- package/dist/AttachmentPlugin.js +216 -0
- package/dist/AttachmentPlugin.js.map +1 -0
- package/dist/BusinessRulePlugin.d.ts +56 -0
- package/dist/BusinessRulePlugin.js +171 -0
- package/dist/BusinessRulePlugin.js.map +1 -0
- package/dist/CrossScopePrivilegePlugin.d.ts +22 -0
- package/dist/CrossScopePrivilegePlugin.js +42 -0
- package/dist/CrossScopePrivilegePlugin.js.map +1 -0
- package/dist/DefaultPlugin.d.ts +71 -0
- package/dist/DefaultPlugin.js +238 -0
- package/dist/DefaultPlugin.js.map +1 -0
- package/dist/IdPlugin.d.ts +17 -0
- package/dist/IdPlugin.js +45 -0
- package/dist/IdPlugin.js.map +1 -0
- package/dist/ListPlugin.d.ts +91 -0
- package/dist/ListPlugin.js +398 -0
- package/dist/ListPlugin.js.map +1 -0
- package/dist/PropertyPlugin.d.ts +122 -0
- package/dist/PropertyPlugin.js +165 -0
- package/dist/PropertyPlugin.js.map +1 -0
- package/dist/ScriptTemplatePlugin.d.ts +31 -0
- package/dist/ScriptTemplatePlugin.js +208 -0
- package/dist/ScriptTemplatePlugin.js.map +1 -0
- package/dist/UserPreferencePlugin.d.ts +16 -0
- package/dist/UserPreferencePlugin.js +30 -0
- package/dist/UserPreferencePlugin.js.map +1 -0
- package/dist/aclAndRole/AclPlugin.d.ts +117 -0
- package/dist/aclAndRole/AclPlugin.js +285 -0
- package/dist/aclAndRole/AclPlugin.js.map +1 -0
- package/dist/aclAndRole/RolePlugin.d.ts +58 -0
- package/dist/aclAndRole/RolePlugin.js +152 -0
- package/dist/aclAndRole/RolePlugin.js.map +1 -0
- package/dist/aclAndRole/Util.d.ts +3 -0
- package/dist/aclAndRole/Util.js +106 -0
- package/dist/aclAndRole/Util.js.map +1 -0
- package/dist/app/ApplicationMenuPlugin.d.ts +32 -0
- package/dist/app/ApplicationMenuPlugin.js +106 -0
- package/dist/app/ApplicationMenuPlugin.js.map +1 -0
- package/dist/atf/ATFComposer.d.ts +492 -0
- package/dist/atf/ATFComposer.js +2717 -0
- package/dist/atf/ATFComposer.js.map +1 -0
- package/dist/atf/TestPlugin.d.ts +31 -0
- package/dist/atf/TestPlugin.js +95 -0
- package/dist/atf/TestPlugin.js.map +1 -0
- package/dist/atf/index.d.ts +1 -0
- package/dist/atf/index.js +9 -0
- package/dist/atf/index.js.map +1 -0
- package/dist/db/ColumnPlugins.d.ts +278 -0
- package/dist/db/ColumnPlugins.js +112 -0
- package/dist/db/ColumnPlugins.js.map +1 -0
- package/dist/db/RecordPlugin.d.ts +208 -0
- package/dist/db/RecordPlugin.js +287 -0
- package/dist/db/RecordPlugin.js.map +1 -0
- package/dist/db/TablePlugin.d.ts +742 -0
- package/dist/db/TablePlugin.js +1249 -0
- package/dist/db/TablePlugin.js.map +1 -0
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.js +27 -0
- package/dist/db/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +12 -0
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +371 -0
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +1 -0
- package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +15 -0
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +177 -0
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +1 -0
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +144 -0
- package/dist/scriptedRESTAPI/RestApiPlugin.js +318 -0
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +1 -0
- package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +190 -0
- package/dist/scriptedRESTAPI/RestSchemaUtils.js +53 -0
- package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +1 -0
- package/dist/scriptedRESTAPI/RestUtils.d.ts +75 -0
- package/dist/scriptedRESTAPI/RestUtils.js +469 -0
- package/dist/scriptedRESTAPI/RestUtils.js.map +1 -0
- package/dist/scripts/ClientScriptPlugin.d.ts +43 -0
- package/dist/scripts/ClientScriptPlugin.js +190 -0
- package/dist/scripts/ClientScriptPlugin.js.map +1 -0
- package/dist/scripts/scriptUtils.d.ts +15 -0
- package/dist/scripts/scriptUtils.js +83 -0
- package/dist/scripts/scriptUtils.js.map +1 -0
- package/dist/uxf/ExperiencePlugin.d.ts +22 -0
- package/dist/uxf/ExperiencePlugin.js +55 -0
- package/dist/uxf/ExperiencePlugin.js.map +1 -0
- package/dist/uxf/RoutesPlugin.d.ts +22 -0
- package/dist/uxf/RoutesPlugin.js +176 -0
- package/dist/uxf/RoutesPlugin.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +4 -0
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js +65 -0
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +189 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js +158 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +13 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +604 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +12 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +551 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +31 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +64 -0
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/index.d.ts +3 -0
- package/dist/uxf/UxfFormulaParser/index.js +11 -0
- package/dist/uxf/UxfFormulaParser/index.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/parser.d.ts +8 -0
- package/dist/uxf/UxfFormulaParser/parser.js +87 -0
- package/dist/uxf/UxfFormulaParser/parser.js.map +1 -0
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +8 -0
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +17 -0
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +1 -0
- package/dist/uxf/constants.d.ts +2 -0
- package/dist/uxf/constants.js +8 -0
- package/dist/uxf/constants.js.map +1 -0
- package/dist/uxf/index.d.ts +2 -0
- package/dist/uxf/index.js +11 -0
- package/dist/uxf/index.js.map +1 -0
- package/dist/uxf/tectonicIdGenerator.d.ts +12 -0
- package/dist/uxf/tectonicIdGenerator.js +102 -0
- package/dist/uxf/tectonicIdGenerator.js.map +1 -0
- package/license +9 -0
- package/package.json +42 -0
- package/src/AttachmentPlugin.ts +262 -0
- package/src/BusinessRulePlugin.ts +251 -0
- package/src/CrossScopePrivilegePlugin.ts +54 -0
- package/src/DefaultPlugin.ts +272 -0
- package/src/IdPlugin.ts +47 -0
- package/src/ListPlugin.ts +497 -0
- package/src/PropertyPlugin.ts +218 -0
- package/src/ScriptTemplatePlugin.ts +223 -0
- package/src/UserPreferencePlugin.ts +36 -0
- package/src/aclAndRole/AclPlugin.ts +410 -0
- package/src/aclAndRole/RolePlugin.ts +225 -0
- package/src/aclAndRole/Util.ts +104 -0
- package/src/app/ApplicationMenuPlugin.ts +158 -0
- package/src/atf/ATFComposer.ts +3356 -0
- package/src/atf/TestPlugin.ts +119 -0
- package/src/atf/index.ts +1 -0
- package/src/db/ColumnPlugins.ts +117 -0
- package/src/db/RecordPlugin.ts +391 -0
- package/src/db/TablePlugin.ts +1581 -0
- package/src/db/index.ts +3 -0
- package/src/index.ts +16 -0
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +410 -0
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +227 -0
- package/src/scriptedRESTAPI/RestApiPlugin.ts +438 -0
- package/src/scriptedRESTAPI/RestSchemaUtils.ts +72 -0
- package/src/scriptedRESTAPI/RestUtils.ts +507 -0
- package/src/scripts/ClientScriptPlugin.ts +251 -0
- package/src/scripts/scriptUtils.ts +81 -0
- package/src/uxf/ExperiencePlugin.ts +64 -0
- package/src/uxf/RoutesPlugin.ts +215 -0
- package/src/uxf/UxfFormulaParser/cleanUxValue.ts +73 -0
- package/src/uxf/UxfFormulaParser/grammerParser/api.js +166 -0
- package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +606 -0
- package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +551 -0
- package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +65 -0
- package/src/uxf/UxfFormulaParser/index.ts +4 -0
- package/src/uxf/UxfFormulaParser/parser.ts +64 -0
- package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +13 -0
- package/src/uxf/constants.ts +4 -0
- package/src/uxf/index.ts +2 -0
- package/src/uxf/tectonicIdGenerator.ts +81 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RestApiSchema, RouteAttributes } from '@servicenow/sdk-core/runtime/rest';
|
|
2
|
+
import { Record } from '@servicenow/sdk-core/runtime/db';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { Context } from '@servicenow/sdk-build-core';
|
|
5
|
+
import type { TableName } from '@servicenow/sdk-core/runtime/db';
|
|
6
|
+
export type Versions = z.infer<typeof RestApiSchema.shape.versions>;
|
|
7
|
+
export type Routes = z.infer<typeof RestApiSchema.shape.routes>;
|
|
8
|
+
export type EnforceAcl = z.infer<typeof RestApiSchema.shape.enforce_acl>;
|
|
9
|
+
export declare const mergeACLIds: (acls: any[]) => string;
|
|
10
|
+
export declare function generateVersionRecords(context: Context, defaultVersion: string, versions: Versions, apiRecord: Record<'sys_ws_definition'>): {
|
|
11
|
+
records: Record[];
|
|
12
|
+
mapping: Map<string, Record<"sys_ws_version">>;
|
|
13
|
+
};
|
|
14
|
+
export declare function generateRouteAttributesRecords<T extends TableName, M extends TableName>(context: Context, restId: string | number, routeId: string | number, attributes: RouteAttributes[], collection: T, mapping_collection: M, attrField: string, apiRecord: Record<'sys_ws_definition'>, routeRecord: Record<'sys_ws_operation'>, recordMap: Map<string, Record>): Record[];
|
|
15
|
+
export declare function generateRoutesAndRouteAttrRecords(context: Context, restId: string | number, routes: Routes, apiData: any, apiRecord: Record<'sys_ws_definition'>, versionMap: Map<string, Record<'sys_ws_version'>>): Record[];
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.mergeACLIds = void 0;
|
|
27
|
+
exports.generateVersionRecords = generateVersionRecords;
|
|
28
|
+
exports.generateRouteAttributesRecords = generateRouteAttributesRecords;
|
|
29
|
+
exports.generateRoutesAndRouteAttrRecords = generateRoutesAndRouteAttrRecords;
|
|
30
|
+
const db_1 = require("@servicenow/sdk-core/runtime/db");
|
|
31
|
+
const _ = __importStar(require("lodash"));
|
|
32
|
+
const mergeACLIds = (acls) => _.join(acls, ',');
|
|
33
|
+
exports.mergeACLIds = mergeACLIds;
|
|
34
|
+
function generateVersionRecords(context, defaultVersion, versions, apiRecord) {
|
|
35
|
+
const versionsRecords = [];
|
|
36
|
+
const versionRecordMap = new Map();
|
|
37
|
+
for (const version of versions) {
|
|
38
|
+
const versionId = `v${version.version}`;
|
|
39
|
+
const versionRecord = (0, db_1.Record)({
|
|
40
|
+
table: 'sys_ws_version',
|
|
41
|
+
$id: context.keys.registerExplicitId('sys_ws_version', version.$id),
|
|
42
|
+
data: {
|
|
43
|
+
active: version.active,
|
|
44
|
+
deprecated: version.deprecated,
|
|
45
|
+
is_default: defaultVersion === versionId ? true : false,
|
|
46
|
+
short_description: version.short_description,
|
|
47
|
+
version: version.version,
|
|
48
|
+
version_id: versionId,
|
|
49
|
+
web_service_definition: apiRecord,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
versionsRecords.push(versionRecord);
|
|
53
|
+
/** versions have to be unique */
|
|
54
|
+
if (versionRecordMap.has(versionId)) {
|
|
55
|
+
throw Error(`Found duplicated version: ${version.version} in ${apiRecord.$id}. All versions must be unique.`);
|
|
56
|
+
}
|
|
57
|
+
versionRecordMap.set(versionId, versionRecord);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
records: versionsRecords,
|
|
61
|
+
mapping: versionRecordMap,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function generateRouteAttributesRecords(context, restId, routeId, attributes, collection, mapping_collection, attrField, apiRecord, routeRecord, recordMap) {
|
|
65
|
+
const attributeRecords = [];
|
|
66
|
+
for (const attribute of attributes) {
|
|
67
|
+
const attrId = context.keys.registerExplicitId(collection, attribute.$id);
|
|
68
|
+
const attributeRecord = (0, db_1.Record)({
|
|
69
|
+
table: collection,
|
|
70
|
+
$id: attrId,
|
|
71
|
+
data: {
|
|
72
|
+
name: attribute.name,
|
|
73
|
+
required: attribute.required,
|
|
74
|
+
short_description: attribute.short_description,
|
|
75
|
+
example_value: attribute.example_value,
|
|
76
|
+
web_service_definition: apiRecord,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* In RestApi since we associate same parameter and headers with multiple routes
|
|
81
|
+
* during serialization we would end up generating duplicated records for headers
|
|
82
|
+
* and parameters. Here we throw error if two duplicated record have different data.
|
|
83
|
+
* Note: two duplicated records would have different data when user refercening a parameter
|
|
84
|
+
* in multiple routes updated in just one place.
|
|
85
|
+
*/
|
|
86
|
+
checkForDuplicateRecords(recordMap, attrId, attributeRecord, attributeRecords);
|
|
87
|
+
const attrMapId = context.keys.registerCompositeId(mapping_collection, {
|
|
88
|
+
attr: attribute.$id,
|
|
89
|
+
route: routeId,
|
|
90
|
+
rest: restId,
|
|
91
|
+
});
|
|
92
|
+
const attrMapRecord = (0, db_1.Record)({
|
|
93
|
+
table: mapping_collection,
|
|
94
|
+
$id: attrMapId,
|
|
95
|
+
data: {
|
|
96
|
+
web_service_operation: routeRecord,
|
|
97
|
+
[attrField]: attributeRecord,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
attributeRecords.push(attrMapRecord);
|
|
101
|
+
}
|
|
102
|
+
return attributeRecords;
|
|
103
|
+
}
|
|
104
|
+
function checkForDuplicateRecords(recordMap, recordId, record, attrRecords) {
|
|
105
|
+
if (!recordMap.has(recordId)) {
|
|
106
|
+
recordMap.set(recordId, record);
|
|
107
|
+
attrRecords.push(record);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const matchRec = recordMap.get(recordId);
|
|
111
|
+
const { web_service_definition: _mwd, ...mRest } = matchRec.data;
|
|
112
|
+
const { web_service_definition: _wd, ...rest } = record.data;
|
|
113
|
+
if (!_.isEqual(rest, mRest)) {
|
|
114
|
+
throw Error(`Found duplicate route attribute map records starting with id: ${recordId}, to have conflicting data.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function generateRoutesAndRouteAttrRecords(context, restId, routes, apiData, apiRecord, versionMap) {
|
|
119
|
+
const routesRecords = [];
|
|
120
|
+
const headerRecordMap = new Map();
|
|
121
|
+
const paramRecordMap = new Map();
|
|
122
|
+
for (const route of routes) {
|
|
123
|
+
const routeParameters = route.parameters;
|
|
124
|
+
const routeHeaders = route.headers;
|
|
125
|
+
const defaultOperationURI = `${apiData.base_uri}${route.path}`;
|
|
126
|
+
const baseOperationURI = `/api/${apiData.namespace}`;
|
|
127
|
+
const remOperationURI = `${apiData.service_id}${route.path}`;
|
|
128
|
+
const operationURI = route.version
|
|
129
|
+
? `${baseOperationURI}/v${route.version}/${remOperationURI}`
|
|
130
|
+
: `${baseOperationURI}/${remOperationURI}`;
|
|
131
|
+
const routeRecord = (0, db_1.Record)({
|
|
132
|
+
table: 'sys_ws_operation',
|
|
133
|
+
$id: context.keys.registerExplicitId('sys_ws_operation', route.$id),
|
|
134
|
+
data: {
|
|
135
|
+
name: route.name,
|
|
136
|
+
active: route.active,
|
|
137
|
+
consumes: route.consumes,
|
|
138
|
+
consumes_customized: apiData.consumes === route.consumes ? false : true,
|
|
139
|
+
default_operation_uri: `v${route.version}` === apiData.default_version ? defaultOperationURI : '',
|
|
140
|
+
http_method: route.method,
|
|
141
|
+
operation_script: route.script,
|
|
142
|
+
operation_uri: operationURI,
|
|
143
|
+
produces: route.produces,
|
|
144
|
+
produces_customized: apiData.produces === route.produces ? false : true,
|
|
145
|
+
relative_path: route.path,
|
|
146
|
+
enforce_acl: (0, exports.mergeACLIds)(route.enforce_acl),
|
|
147
|
+
requires_acl_authorization: route.authorization,
|
|
148
|
+
requires_authentication: route.authentication,
|
|
149
|
+
requires_snc_internal_role: route.internalRole,
|
|
150
|
+
short_description: route.short_description,
|
|
151
|
+
request_example: route.request_example,
|
|
152
|
+
web_service_definition: apiRecord,
|
|
153
|
+
web_service_version: getRestRouteVersion(route, versionMap),
|
|
154
|
+
...(route.policy && { sys_policy: route.policy }),
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
routesRecords.push(routeRecord);
|
|
158
|
+
/** generates the sys_ws_query_parameter and sys_ws_query_parameter_map records */
|
|
159
|
+
const routeParamRecords = generateRouteAttributesRecords(context, restId, route.$id, routeParameters, 'sys_ws_query_parameter', 'sys_ws_query_parameter_map', 'web_service_query_parameter', apiRecord, routeRecord, paramRecordMap);
|
|
160
|
+
/** generates the sys_ws_header and sys_ws_header_map records */
|
|
161
|
+
const routeHeaderRecords = generateRouteAttributesRecords(context, restId, route.$id, routeHeaders, 'sys_ws_header', 'sys_ws_header_map', 'web_service_header', apiRecord, routeRecord, headerRecordMap);
|
|
162
|
+
routesRecords.push(...[...routeParamRecords, ...routeHeaderRecords]);
|
|
163
|
+
}
|
|
164
|
+
return routesRecords;
|
|
165
|
+
}
|
|
166
|
+
function getRestRouteVersion(route, versionMap) {
|
|
167
|
+
/** throws error when a route specifies version not mentioned in versions array of rest*/
|
|
168
|
+
const version = '';
|
|
169
|
+
if (route.version) {
|
|
170
|
+
if (!versionMap.has(`v${route.version}`)) {
|
|
171
|
+
throw Error(`Unable to resolve version record for version ${route.version}. Check if the version is listed in your API versions list.`);
|
|
172
|
+
}
|
|
173
|
+
return versionMap.get(`v${route.version}`);
|
|
174
|
+
}
|
|
175
|
+
return version;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=RESTSerializationUtils.js.map
|
|
@@ -0,0 +1 @@
|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,yFAAyF;IACzF,MAAM,OAAO,GAAG,EAAE,CAAA;IAClB,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;YACvC,MAAM,KAAK,CACP,gDAAgD,KAAK,CAAC,OAAO,6DAA6D,CAC7H,CAAA;QACL,CAAC;QACD,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAE,CAAA;IAC/C,CAAC;IAED,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { RestApiConfig, Version } from '@servicenow/sdk-core/runtime/rest';
|
|
2
|
+
import { Context, Document, EntityData, ObjectData } from '@servicenow/sdk-build-core';
|
|
3
|
+
import * as ts from 'ts-morph';
|
|
4
|
+
import { Diagnostic } from '@servicenow/sdk-project';
|
|
5
|
+
declare const _default: {
|
|
6
|
+
readonly name: "RestApi";
|
|
7
|
+
readonly ownedTables: {
|
|
8
|
+
readonly sys_ws_definition: {
|
|
9
|
+
readonly diagnosticLevel: Diagnostic.Level.Warn;
|
|
10
|
+
};
|
|
11
|
+
readonly sys_ws_version: {
|
|
12
|
+
readonly diagnosticLevel: Diagnostic.Level.Warn;
|
|
13
|
+
};
|
|
14
|
+
readonly sys_ws_operation: {
|
|
15
|
+
readonly diagnosticLevel: Diagnostic.Level.Warn;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly extractors: {
|
|
19
|
+
readonly entity: {
|
|
20
|
+
readonly CallExpression: (node: ts.CallExpression<ts.ts.CallExpression>, context: Context) => {
|
|
21
|
+
handled: false;
|
|
22
|
+
} | {
|
|
23
|
+
handled: true;
|
|
24
|
+
data: EntityData<RestApiConfig<number, Version<number>>>[];
|
|
25
|
+
diagnostics: import("@servicenow/sdk-build-core").FluentDiagnostic[];
|
|
26
|
+
} | {
|
|
27
|
+
handled: true;
|
|
28
|
+
diagnostics: import("@servicenow/sdk-build-core").FluentDiagnostic[];
|
|
29
|
+
data: EntityData<{
|
|
30
|
+
readonly enforce_acl: string[];
|
|
31
|
+
readonly active: boolean;
|
|
32
|
+
readonly $id: string | number;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly short_description: string;
|
|
35
|
+
readonly consumes: string;
|
|
36
|
+
readonly doc_link: string;
|
|
37
|
+
readonly produces: string;
|
|
38
|
+
readonly service_id: string;
|
|
39
|
+
readonly policy: "" | "read" | "protected";
|
|
40
|
+
readonly routes: {
|
|
41
|
+
active: boolean;
|
|
42
|
+
$id: string | number;
|
|
43
|
+
path: string;
|
|
44
|
+
name: string;
|
|
45
|
+
short_description: string;
|
|
46
|
+
consumes: string;
|
|
47
|
+
enforce_acl: any[];
|
|
48
|
+
produces: string;
|
|
49
|
+
request_example: string;
|
|
50
|
+
parameters: {
|
|
51
|
+
$id: string | number;
|
|
52
|
+
name: string;
|
|
53
|
+
short_description: string;
|
|
54
|
+
required: boolean;
|
|
55
|
+
example_value: string;
|
|
56
|
+
}[];
|
|
57
|
+
headers: {
|
|
58
|
+
$id: string | number;
|
|
59
|
+
name: string;
|
|
60
|
+
short_description: string;
|
|
61
|
+
required: boolean;
|
|
62
|
+
example_value: string;
|
|
63
|
+
}[];
|
|
64
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
65
|
+
authorization: boolean;
|
|
66
|
+
authentication: boolean;
|
|
67
|
+
internalRole: boolean;
|
|
68
|
+
policy: "" | "read" | "protected";
|
|
69
|
+
script?: any;
|
|
70
|
+
version?: number | undefined;
|
|
71
|
+
}[];
|
|
72
|
+
readonly versions: {
|
|
73
|
+
active: boolean;
|
|
74
|
+
$id: string | number;
|
|
75
|
+
version: number;
|
|
76
|
+
short_description: string;
|
|
77
|
+
deprecated: boolean;
|
|
78
|
+
is_default: boolean;
|
|
79
|
+
}[];
|
|
80
|
+
}>[];
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
readonly raw: {
|
|
84
|
+
readonly FunctionDeclaration: (node: ts.FunctionDeclaration, context: Context) => {
|
|
85
|
+
handled: false;
|
|
86
|
+
diagnostics?: never;
|
|
87
|
+
data?: never;
|
|
88
|
+
} | {
|
|
89
|
+
handled: true;
|
|
90
|
+
diagnostics: never[];
|
|
91
|
+
data: ObjectData<{
|
|
92
|
+
readonly filePath: string;
|
|
93
|
+
readonly functionName: string | undefined;
|
|
94
|
+
readonly isDefault: boolean;
|
|
95
|
+
}>[];
|
|
96
|
+
};
|
|
97
|
+
readonly FunctionExpression: (node: ts.FunctionExpression, context: Context) => {
|
|
98
|
+
handled: false;
|
|
99
|
+
diagnostics?: never;
|
|
100
|
+
data?: never;
|
|
101
|
+
} | {
|
|
102
|
+
handled: true;
|
|
103
|
+
diagnostics: never[];
|
|
104
|
+
data: ObjectData<{
|
|
105
|
+
readonly filePath: string;
|
|
106
|
+
readonly functionName: string | undefined;
|
|
107
|
+
readonly isDefault: boolean;
|
|
108
|
+
}>[];
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
readonly composers: {
|
|
113
|
+
readonly entity: {
|
|
114
|
+
readonly restApi: (entity: EntityData<globalThis.Record<string, unknown>>, context: Context) => import("@servicenow/sdk-build-core").LinkedDocument[] | undefined;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
readonly arrangers: {
|
|
118
|
+
readonly record: (document: Document<"record">, context: Context) => {
|
|
119
|
+
handled: false;
|
|
120
|
+
result?: never;
|
|
121
|
+
} | {
|
|
122
|
+
handled: true;
|
|
123
|
+
result: import("@servicenow/sdk-build-core").DocumentPointer | undefined;
|
|
124
|
+
} | {
|
|
125
|
+
handled: true;
|
|
126
|
+
result: {
|
|
127
|
+
kind: string;
|
|
128
|
+
guid: any;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
readonly generators: {
|
|
133
|
+
readonly record: (document: import("@servicenow/sdk-build-core").UnlinkedDocument<"record"> & import("@servicenow/sdk-build-core").Arranged, context: Context, linkedDocuments: import("@servicenow/sdk-build-core").LinkedDocument[]) => import("@servicenow/sdk-build-core").LinkedDocument<"record", ts.CallExpression<ts.ts.CallExpression>> | undefined;
|
|
134
|
+
};
|
|
135
|
+
readonly transformers: {
|
|
136
|
+
readonly record: {
|
|
137
|
+
readonly CallExpression: (document: Document<any, ts.CallExpression<ts.ts.CallExpression>> & {
|
|
138
|
+
entity?: EntityData;
|
|
139
|
+
node: ts.CallExpression<ts.ts.CallExpression>;
|
|
140
|
+
} & import("@servicenow/sdk-build-core").Arranged, context: Context) => boolean;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export default _default;
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const rest_1 = require("@servicenow/sdk-core/runtime/rest");
|
|
27
|
+
const db_1 = require("@servicenow/sdk-core/runtime/db");
|
|
28
|
+
const sdk_build_core_1 = require("@servicenow/sdk-build-core");
|
|
29
|
+
const RecordPlugin_1 = require("../db/RecordPlugin");
|
|
30
|
+
const scriptUtils_1 = require("../scripts/scriptUtils");
|
|
31
|
+
const RESTSerializationUtils_1 = require("./RESTSerializationUtils");
|
|
32
|
+
const ts = __importStar(require("ts-morph"));
|
|
33
|
+
const RESTDeserializationUtils_1 = require("./RESTDeserializationUtils");
|
|
34
|
+
const RestSchemaUtils_1 = require("./RestSchemaUtils");
|
|
35
|
+
const RestUtils_1 = require("./RestUtils");
|
|
36
|
+
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
37
|
+
const methodsAllowedToOverrideRequests = ['PUT', 'PATCH', 'POST'];
|
|
38
|
+
const parseAcls = (enforce_acl, context) => enforce_acl.map((acl) => (typeof acl === 'string' ? acl : context.keys.registerExplicitId(acl.table, acl.$id)));
|
|
39
|
+
function restApiAsRecord(config) {
|
|
40
|
+
const api = rest_1.RestApiSchema.parse(config);
|
|
41
|
+
return (0, db_1.Record)({
|
|
42
|
+
table: 'sys_ws_definition',
|
|
43
|
+
$id: api.$id,
|
|
44
|
+
data: {
|
|
45
|
+
active: api.active,
|
|
46
|
+
name: api.name,
|
|
47
|
+
consumes: api.consumes,
|
|
48
|
+
consumes_customized: api.consumes === rest_1.RestApiSchema.shape.consumes._def.defaultValue() ? false : true,
|
|
49
|
+
produces: api.produces,
|
|
50
|
+
produces_customized: api.produces === rest_1.RestApiSchema.shape.produces._def.defaultValue() ? false : true,
|
|
51
|
+
default_version: '',
|
|
52
|
+
doc_link: api.doc_link,
|
|
53
|
+
is_versioned: false,
|
|
54
|
+
service_id: api.service_id,
|
|
55
|
+
short_description: api.short_description,
|
|
56
|
+
base_uri: '',
|
|
57
|
+
namespace: '',
|
|
58
|
+
enforce_acl: api.enforce_acl,
|
|
59
|
+
...(api.policy && { sys_policy: api.policy }),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.default = (0, sdk_build_core_1.Plugin)({
|
|
64
|
+
name: 'RestApi',
|
|
65
|
+
ownedTables: {
|
|
66
|
+
sys_ws_definition: { diagnosticLevel: sdk_project_1.Diagnostic.Level.Warn },
|
|
67
|
+
sys_ws_version: { diagnosticLevel: sdk_project_1.Diagnostic.Level.Warn },
|
|
68
|
+
sys_ws_operation: { diagnosticLevel: sdk_project_1.Diagnostic.Level.Warn },
|
|
69
|
+
},
|
|
70
|
+
extractors: {
|
|
71
|
+
entity: {
|
|
72
|
+
CallExpression: (node, context) => {
|
|
73
|
+
const result = (0, sdk_build_core_1.extractCallExpression)(rest_1.RestApi, 'restApi', node, context, (restApi) => context.registerExplicitId('sys_ws_definition', restApi.$id));
|
|
74
|
+
if (!result.handled || !(0 in result.data)) {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
const restAPIEntity = result.data[0];
|
|
78
|
+
const entityData = rest_1.RestApiSchema.parse(restAPIEntity.getValue());
|
|
79
|
+
const { routes, enforce_acl, consumes, produces } = entityData;
|
|
80
|
+
for (const route of routes) {
|
|
81
|
+
const { enforce_acl } = route;
|
|
82
|
+
const rawOperationScript = route.script;
|
|
83
|
+
route.name = route.name ? route.name : route.path;
|
|
84
|
+
if (typeof rawOperationScript !== 'string') {
|
|
85
|
+
const { filePath, functionName, isDefault } = rawOperationScript;
|
|
86
|
+
route.script = (0, scriptUtils_1.buildScriptImport)(filePath, functionName, isDefault, context, (funcName) => `${funcName}(request, response)\n`);
|
|
87
|
+
}
|
|
88
|
+
/** allow users to override consumes for allowed http methods*/
|
|
89
|
+
if (route.consumes &&
|
|
90
|
+
route.consumes !== consumes &&
|
|
91
|
+
!methodsAllowedToOverrideRequests.includes(route.method)) {
|
|
92
|
+
throw Error(`Cannot override consumer type for ${route.method} method`);
|
|
93
|
+
}
|
|
94
|
+
route.consumes = route.consumes ? route.consumes : consumes;
|
|
95
|
+
route.produces = route.produces ? route.produces : produces;
|
|
96
|
+
route.enforce_acl = parseAcls(enforce_acl, context);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
handled: true,
|
|
100
|
+
diagnostics: result.diagnostics,
|
|
101
|
+
data: [
|
|
102
|
+
new sdk_build_core_1.EntityData(restAPIEntity.getKind(), restAPIEntity.getGuid(), sdk_build_core_1.ObjectData.fromObjectValue({
|
|
103
|
+
...entityData,
|
|
104
|
+
enforce_acl: parseAcls(enforce_acl, context),
|
|
105
|
+
}, restAPIEntity.getNode()), restAPIEntity.getNode()),
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
raw: {
|
|
111
|
+
FunctionDeclaration(node, context) {
|
|
112
|
+
const info = (0, scriptUtils_1.scriptInfo)(node, context, rest_1.RestApi.name);
|
|
113
|
+
if (!info) {
|
|
114
|
+
return { handled: false };
|
|
115
|
+
}
|
|
116
|
+
return { handled: true, diagnostics: [], data: [info] };
|
|
117
|
+
},
|
|
118
|
+
FunctionExpression(node, context) {
|
|
119
|
+
const info = (0, scriptUtils_1.scriptInfo)(node, context, rest_1.RestApi.name);
|
|
120
|
+
if (!info) {
|
|
121
|
+
return { handled: false };
|
|
122
|
+
}
|
|
123
|
+
return { handled: true, diagnostics: [], data: [info] };
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
composers: {
|
|
128
|
+
entity: {
|
|
129
|
+
restApi(entity, context) {
|
|
130
|
+
const restEntity = entity.getValue();
|
|
131
|
+
const parsedEntity = rest_1.RestApiSchema.safeParse(restEntity);
|
|
132
|
+
if (!parsedEntity.success) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { routes, versions, enforce_acl } = parsedEntity.data;
|
|
136
|
+
const defaultVersions = versions.filter((version) => version.is_default);
|
|
137
|
+
if (defaultVersions.length > 1) {
|
|
138
|
+
throw Error(`Multiple versions cannot be set to default.`);
|
|
139
|
+
}
|
|
140
|
+
const { app: { config: { scope }, }, } = context;
|
|
141
|
+
const restRecord = restApiAsRecord(restEntity);
|
|
142
|
+
const apiData = { ...restRecord.data };
|
|
143
|
+
apiData.base_uri = `/api/${scope}/${apiData.service_id}`;
|
|
144
|
+
apiData.namespace = scope;
|
|
145
|
+
apiData.default_version =
|
|
146
|
+
defaultVersions.length > 0 ? `v${defaultVersions[0].version}` : 'No active default version';
|
|
147
|
+
apiData.enforce_acl = (0, RESTSerializationUtils_1.mergeACLIds)(enforce_acl);
|
|
148
|
+
apiData.is_versioned = versions.length > 0 ? true : false;
|
|
149
|
+
/** generates sys_ws_definition record */
|
|
150
|
+
const updatedRestRecord = (0, db_1.Record)({
|
|
151
|
+
table: 'sys_ws_definition',
|
|
152
|
+
$id: entity.getGuid(),
|
|
153
|
+
data: apiData,
|
|
154
|
+
});
|
|
155
|
+
/** generates the sys_ws_version record */
|
|
156
|
+
const versionRecordsAndMap = (0, RESTSerializationUtils_1.generateVersionRecords)(context, apiData.default_version, versions, updatedRestRecord);
|
|
157
|
+
/** generates the sys_ws_operation, sys_ws_header, sys_ws_header_map, sys_ws_query_paramter, sys_ws_query_parameter_map records */
|
|
158
|
+
const routesAndRouteAttrRecords = (0, RESTSerializationUtils_1.generateRoutesAndRouteAttrRecords)(context, restRecord.$id, routes, apiData, updatedRestRecord, versionRecordsAndMap.mapping);
|
|
159
|
+
return context.composeEntities([updatedRestRecord, ...versionRecordsAndMap.records, ...routesAndRouteAttrRecords].map((r) => new sdk_build_core_1.EntityData('record', r.$id, sdk_build_core_1.ObjectData.fromObjectValue(r, entity.getNode()), entity.getNode())), [RecordPlugin_1.RecordPlugin]);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
arrangers: {
|
|
164
|
+
record(document, context) {
|
|
165
|
+
const table = document.data['table'];
|
|
166
|
+
/** skipping arrangers while serializing as we don't care about the order here. */
|
|
167
|
+
if (!RestUtils_1.restTables.includes(table) || context.mode === 'serialize') {
|
|
168
|
+
return { handled: false };
|
|
169
|
+
}
|
|
170
|
+
/** generates rest document map and validates the params and their mapping records */
|
|
171
|
+
const restDocMap = (0, RestUtils_1.getRestDocumentMap)(context);
|
|
172
|
+
switch (table) {
|
|
173
|
+
case 'sys_ws_operation':
|
|
174
|
+
case 'sys_ws_version':
|
|
175
|
+
return {
|
|
176
|
+
handled: true,
|
|
177
|
+
result: { kind: 'record', guid: document.data['data']['web_service_definition'] },
|
|
178
|
+
};
|
|
179
|
+
case 'sys_ws_header':
|
|
180
|
+
case 'sys_ws_query_parameter':
|
|
181
|
+
if (!document.node) {
|
|
182
|
+
/** handles case where the incoming xml doesn't have any node associated with it. */
|
|
183
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrResult)(document, restDocMap), document);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const docNode = document.node;
|
|
187
|
+
if ((0, sdk_build_core_1.getCallExpressionName)(docNode) === db_1.Record.name) {
|
|
188
|
+
/** handles case where the incoming xml is currently associated with record call */
|
|
189
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrWithRecordNodeResult)(document, context, restDocMap), document);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
/** handles case where the incoming xml is currently associated with rest call */
|
|
193
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrWithRestNodeResult)(document, context, restDocMap), document);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
case 'sys_ws_header_map':
|
|
197
|
+
case 'sys_ws_query_parameter_map':
|
|
198
|
+
if (!document.node) {
|
|
199
|
+
/** handles case where the incoming xml doesn't have any node associated with it. */
|
|
200
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrMapResult)(document, restDocMap), document);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const docNode = document.node;
|
|
204
|
+
if ((0, sdk_build_core_1.getCallExpressionName)(docNode) === db_1.Record.name) {
|
|
205
|
+
/** handles case where the incoming xml is currently associated with record call */
|
|
206
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrMapWithRecordNodeResult)(document, context, restDocMap), document);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
/** handles case where the incoming xml is currently associated with rest call */
|
|
210
|
+
return (0, RestUtils_1.handleAndReturnResult)((0, RestUtils_1.getRouteAttrMapWithRestNodeResult)(document, context, restDocMap), document);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
default:
|
|
214
|
+
return { handled: true, result: undefined };
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
generators: {
|
|
219
|
+
record(document, context, linkedDocuments) {
|
|
220
|
+
const table = document.data['table'];
|
|
221
|
+
/**
|
|
222
|
+
* Edge case: m2m record maps non-app rest causing you to unassociate the only associated
|
|
223
|
+
* param record to rest. May require creation of record call for unassociated param if not consumed
|
|
224
|
+
* by any
|
|
225
|
+
*/
|
|
226
|
+
RestUtils_1.completelyUnassociatedParamIds.forEach((id) => {
|
|
227
|
+
if (RestUtils_1.potentialRecordCallRouteParams.has(id)) {
|
|
228
|
+
(0, RestUtils_1.createRecordCall)(id, context);
|
|
229
|
+
RestUtils_1.potentialRecordCallRouteParams.delete(id);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
RestUtils_1.completelyUnassociatedParamIds.clear();
|
|
233
|
+
/** unHandledIds contains rest record ids for which we need to create record call */
|
|
234
|
+
if (!RestUtils_1.restTables.includes(table) || RestUtils_1.unHandledIds.includes(document.guid)) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
switch (table) {
|
|
238
|
+
case 'sys_ws_definition':
|
|
239
|
+
// eslint-disable-next-line no-case-declarations
|
|
240
|
+
const linkedDoc = (0, sdk_build_core_1.linkDocument)(document, (0, sdk_build_core_1.generateCallExpressionExportForDocument)(context, {
|
|
241
|
+
sourceFile: (0, sdk_build_core_1.getOrCreateEntitySourceFile)(context, (0, sdk_build_core_1.getSysUpdateName)(document, 'sys_ws_definition')),
|
|
242
|
+
moduleSpecifier: '@servicenow/sdk/core',
|
|
243
|
+
}, rest_1.RestApi, {}).getExpressionIfKindOrThrow(ts.SyntaxKind.CallExpression));
|
|
244
|
+
return linkedDoc;
|
|
245
|
+
case 'sys_ws_operation':
|
|
246
|
+
case 'sys_ws_version':
|
|
247
|
+
case 'sys_ws_header':
|
|
248
|
+
case 'sys_ws_query_parameter':
|
|
249
|
+
// eslint-disable-next-line no-case-declarations
|
|
250
|
+
const restDef = linkedDocuments.find((doc) => doc.data.table === 'sys_ws_definition' &&
|
|
251
|
+
doc.guid === document.data.data.web_service_definition);
|
|
252
|
+
// eslint-disable-next-line no-case-declarations
|
|
253
|
+
const o_v_node = document.parent.node ? document.parent.node : restDef?.node;
|
|
254
|
+
if (!o_v_node) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
return (0, sdk_build_core_1.linkDocument)(document, o_v_node);
|
|
258
|
+
case 'sys_ws_header_map':
|
|
259
|
+
case 'sys_ws_query_parameter_map':
|
|
260
|
+
// eslint-disable-next-line no-case-declarations
|
|
261
|
+
const operationDef = linkedDocuments.find((doc) => doc.data.table === 'sys_ws_operation' &&
|
|
262
|
+
doc.guid === document.data.data.web_service_operation);
|
|
263
|
+
// eslint-disable-next-line no-case-declarations
|
|
264
|
+
const h_q_node = document.parent?.node ? document.parent?.node : operationDef?.node;
|
|
265
|
+
if (!h_q_node) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
return (0, sdk_build_core_1.linkDocument)(document, h_q_node);
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
transformers: {
|
|
274
|
+
record: {
|
|
275
|
+
CallExpression(document, context) {
|
|
276
|
+
if (!shouldHandle(document)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
const documentMap = context.getDocumentMap();
|
|
280
|
+
const table = document.data['table'];
|
|
281
|
+
switch (table) {
|
|
282
|
+
case 'sys_ws_definition':
|
|
283
|
+
return (0, RESTDeserializationUtils_1.transformDefinition)(document, context);
|
|
284
|
+
case 'sys_ws_version':
|
|
285
|
+
return (0, RESTDeserializationUtils_1.transformRestAttrs)(document, context);
|
|
286
|
+
case 'sys_ws_operation':
|
|
287
|
+
return (0, RESTDeserializationUtils_1.transformRoutes)(document, context, documentMap);
|
|
288
|
+
case 'sys_ws_header':
|
|
289
|
+
return (0, RESTDeserializationUtils_1.transformRouteAttrs)(document, context, 'headers');
|
|
290
|
+
case 'sys_ws_query_parameter':
|
|
291
|
+
return (0, RESTDeserializationUtils_1.transformRouteAttrs)(document, context, 'parameters');
|
|
292
|
+
case 'sys_ws_query_parameter_map':
|
|
293
|
+
return (0, RESTDeserializationUtils_1.transformRouteAttrsMap)(document, context, documentMap, RestSchemaUtils_1.RestRouteQueryMap, 'parameters', (data) => {
|
|
294
|
+
return {
|
|
295
|
+
operationId: data.web_service_operation,
|
|
296
|
+
attrId: data.web_service_query_parameter,
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
case 'sys_ws_header_map':
|
|
300
|
+
return (0, RESTDeserializationUtils_1.transformRouteAttrsMap)(document, context, documentMap, RestSchemaUtils_1.RestRouteHeaderMap, 'headers', (data) => {
|
|
301
|
+
return { operationId: data.web_service_operation, attrId: data.web_service_header };
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
function shouldHandle(document) {
|
|
310
|
+
const docNode = document.node;
|
|
311
|
+
return !docNode.wasForgotten() &&
|
|
312
|
+
(0, sdk_build_core_1.getCallExpressionName)(docNode) === rest_1.RestApi.name &&
|
|
313
|
+
document.data['table'] &&
|
|
314
|
+
docNode.getArguments()[0]
|
|
315
|
+
? true
|
|
316
|
+
: false;
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=RestApiPlugin.js.map
|