@servicenow/sdk-build-plugins 2.0.1 → 2.1.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.
Files changed (133) hide show
  1. package/dist/AttachmentPlugin.d.ts +8 -6
  2. package/dist/AttachmentPlugin.js +4 -2
  3. package/dist/AttachmentPlugin.js.map +1 -1
  4. package/dist/BusinessRulePlugin.d.ts +5 -31
  5. package/dist/BusinessRulePlugin.js +45 -72
  6. package/dist/BusinessRulePlugin.js.map +1 -1
  7. package/dist/CrossScopePrivilegePlugin.d.ts +14 -1
  8. package/dist/CrossScopePrivilegePlugin.js +36 -1
  9. package/dist/CrossScopePrivilegePlugin.js.map +1 -1
  10. package/dist/DefaultPlugin.d.ts +60 -57
  11. package/dist/DefaultPlugin.js +151 -146
  12. package/dist/DefaultPlugin.js.map +1 -1
  13. package/dist/HtmlTemplatePlugin.d.ts +21 -0
  14. package/dist/HtmlTemplatePlugin.js +52 -0
  15. package/dist/HtmlTemplatePlugin.js.map +1 -0
  16. package/dist/IdPlugin.d.ts +18 -8
  17. package/dist/IdPlugin.js +55 -28
  18. package/dist/IdPlugin.js.map +1 -1
  19. package/dist/JsonPlugin.d.ts +23 -0
  20. package/dist/JsonPlugin.js +74 -0
  21. package/dist/JsonPlugin.js.map +1 -0
  22. package/dist/ListPlugin.d.ts +7 -13
  23. package/dist/ListPlugin.js +32 -15
  24. package/dist/ListPlugin.js.map +1 -1
  25. package/dist/NowConfigPlugin.d.ts +45 -0
  26. package/dist/NowConfigPlugin.js +90 -0
  27. package/dist/NowConfigPlugin.js.map +1 -0
  28. package/dist/PackageJsonPlugin.d.ts +20 -0
  29. package/dist/PackageJsonPlugin.js +48 -0
  30. package/dist/PackageJsonPlugin.js.map +1 -0
  31. package/dist/PropertyPlugin.d.ts +9 -35
  32. package/dist/PropertyPlugin.js +53 -32
  33. package/dist/PropertyPlugin.js.map +1 -1
  34. package/dist/ScriptTemplatePlugin.d.ts +3 -20
  35. package/dist/ScriptTemplatePlugin.js +20 -138
  36. package/dist/ScriptTemplatePlugin.js.map +1 -1
  37. package/dist/ServerModulePlugin.d.ts +62 -0
  38. package/dist/ServerModulePlugin.js +231 -0
  39. package/dist/ServerModulePlugin.js.map +1 -0
  40. package/dist/UserPreferencePlugin.d.ts +4 -1
  41. package/dist/UserPreferencePlugin.js +12 -10
  42. package/dist/UserPreferencePlugin.js.map +1 -1
  43. package/dist/aclAndRole/AclPlugin.d.ts +41 -79
  44. package/dist/aclAndRole/AclPlugin.js +50 -72
  45. package/dist/aclAndRole/AclPlugin.js.map +1 -1
  46. package/dist/aclAndRole/RolePlugin.d.ts +27 -18
  47. package/dist/aclAndRole/RolePlugin.js +66 -41
  48. package/dist/aclAndRole/RolePlugin.js.map +1 -1
  49. package/dist/app/ApplicationMenuPlugin.d.ts +4 -2
  50. package/dist/app/ApplicationMenuPlugin.js +12 -7
  51. package/dist/app/ApplicationMenuPlugin.js.map +1 -1
  52. package/dist/atf/ATFComposer.js +324 -324
  53. package/dist/atf/TestPlugin.d.ts +12 -10
  54. package/dist/atf/TestPlugin.js +14 -12
  55. package/dist/atf/TestPlugin.js.map +1 -1
  56. package/dist/db/ColumnPlugins.d.ts +559 -97
  57. package/dist/db/ColumnPlugins.js +28 -24
  58. package/dist/db/ColumnPlugins.js.map +1 -1
  59. package/dist/db/DBUtils.d.ts +2 -0
  60. package/dist/db/DBUtils.js +27 -0
  61. package/dist/db/DBUtils.js.map +1 -0
  62. package/dist/db/DocumentationPlugin.d.ts +58 -0
  63. package/dist/db/DocumentationPlugin.js +248 -0
  64. package/dist/db/DocumentationPlugin.js.map +1 -0
  65. package/dist/db/RecordPlugin.d.ts +15 -13
  66. package/dist/db/RecordPlugin.js +74 -79
  67. package/dist/db/RecordPlugin.js.map +1 -1
  68. package/dist/db/TablePlugin.d.ts +38 -105
  69. package/dist/db/TablePlugin.js +205 -111
  70. package/dist/db/TablePlugin.js.map +1 -1
  71. package/dist/db/index.d.ts +2 -0
  72. package/dist/db/index.js +4 -1
  73. package/dist/db/index.js.map +1 -1
  74. package/dist/index.d.ts +7 -2
  75. package/dist/index.js +12 -2
  76. package/dist/index.js.map +1 -1
  77. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +8 -6
  78. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +1 -1
  79. package/dist/scriptedRESTAPI/RESTSerializationUtils.js +7 -6
  80. package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +1 -1
  81. package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +74 -85
  82. package/dist/scriptedRESTAPI/RestApiPlugin.js +71 -54
  83. package/dist/scriptedRESTAPI/RestApiPlugin.js.map +1 -1
  84. package/dist/scriptedRESTAPI/RestUtils.d.ts +2 -0
  85. package/dist/scriptedRESTAPI/RestUtils.js +37 -9
  86. package/dist/scriptedRESTAPI/RestUtils.js.map +1 -1
  87. package/dist/scripts/ClientScriptPlugin.d.ts +18 -16
  88. package/dist/scripts/ClientScriptPlugin.js +48 -45
  89. package/dist/scripts/ClientScriptPlugin.js.map +1 -1
  90. package/dist/scripts/scriptUtils.d.ts +0 -14
  91. package/dist/scripts/scriptUtils.js +0 -74
  92. package/dist/scripts/scriptUtils.js.map +1 -1
  93. package/dist/uxf/ExperiencePlugin.d.ts +31 -3
  94. package/dist/uxf/ExperiencePlugin.js +10 -4
  95. package/dist/uxf/ExperiencePlugin.js.map +1 -1
  96. package/dist/uxf/RoutesPlugin.d.ts +10 -3
  97. package/dist/uxf/RoutesPlugin.js +20 -14
  98. package/dist/uxf/RoutesPlugin.js.map +1 -1
  99. package/package.json +6 -6
  100. package/src/AttachmentPlugin.ts +10 -2
  101. package/src/BusinessRulePlugin.ts +79 -104
  102. package/src/CrossScopePrivilegePlugin.ts +65 -5
  103. package/src/DefaultPlugin.ts +181 -173
  104. package/src/HtmlTemplatePlugin.ts +31 -0
  105. package/src/IdPlugin.ts +59 -28
  106. package/src/JsonPlugin.ts +81 -0
  107. package/src/ListPlugin.ts +38 -19
  108. package/src/NowConfigPlugin.ts +72 -0
  109. package/src/PackageJsonPlugin.ts +24 -0
  110. package/src/PropertyPlugin.ts +60 -38
  111. package/src/ScriptTemplatePlugin.ts +22 -179
  112. package/src/ServerModulePlugin.ts +267 -0
  113. package/src/UserPreferencePlugin.ts +28 -19
  114. package/src/aclAndRole/AclPlugin.ts +78 -109
  115. package/src/aclAndRole/RolePlugin.ts +85 -58
  116. package/src/app/ApplicationMenuPlugin.ts +15 -11
  117. package/src/atf/ATFComposer.ts +1 -1
  118. package/src/atf/TestPlugin.ts +14 -12
  119. package/src/db/ColumnPlugins.ts +36 -37
  120. package/src/db/DBUtils.ts +36 -0
  121. package/src/db/DocumentationPlugin.ts +282 -0
  122. package/src/db/RecordPlugin.ts +96 -98
  123. package/src/db/TablePlugin.ts +278 -152
  124. package/src/db/index.ts +2 -0
  125. package/src/index.ts +7 -2
  126. package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +15 -7
  127. package/src/scriptedRESTAPI/RESTSerializationUtils.ts +7 -6
  128. package/src/scriptedRESTAPI/RestApiPlugin.ts +85 -75
  129. package/src/scriptedRESTAPI/RestUtils.ts +44 -11
  130. package/src/scripts/ClientScriptPlugin.ts +64 -68
  131. package/src/scripts/scriptUtils.ts +0 -76
  132. package/src/uxf/ExperiencePlugin.ts +14 -13
  133. package/src/uxf/RoutesPlugin.ts +22 -27
@@ -0,0 +1,231 @@
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.ModuleFunctionData = exports.ModuleEntityData = void 0;
27
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
28
+ const sdk_project_1 = require("@servicenow/sdk-project");
29
+ const pathModule = __importStar(require("path"));
30
+ const ts_morph_1 = require("ts-morph");
31
+ class ModuleEntityData extends sdk_build_core_1.EntityData {
32
+ constructor(content, file, context) {
33
+ const { scope } = context.app.config;
34
+ const { name: packageName, version } = context.app.package;
35
+ const relativePath = pathModule.relative(context.app.rootDir, pathModule.normalize(file.getFilePath()));
36
+ const mappedPath = applyModulePathMappings(relativePath, context);
37
+ const path = pathModule.join(scope, packageName, version, mappedPath);
38
+ super('module', context.registerExplicitId('sys_module', mappedPath.replaceAll(/[./\\]/g, '_')), new sdk_build_core_1.ObjectData({
39
+ path: new sdk_build_core_1.StringData(path, file),
40
+ content: new sdk_build_core_1.StringData(content, file),
41
+ }, file), file);
42
+ }
43
+ }
44
+ exports.ModuleEntityData = ModuleEntityData;
45
+ class ModuleFunctionData extends sdk_build_core_1.ObjectData {
46
+ constructor(name, module, node) {
47
+ super({
48
+ exportName: new sdk_build_core_1.StringData(name, node),
49
+ modulePath: new sdk_build_core_1.StringData(module.getPropertyOrThrow('path', 'string').getValue(), node),
50
+ isDefault: new sdk_build_core_1.BooleanData(node.isDefaultExport(), node),
51
+ }, node);
52
+ }
53
+ getGlueCode(callExpressionProvider) {
54
+ return ModuleFunctionData.getGlueCode(this, callExpressionProvider);
55
+ }
56
+ static getGlueCode(scriptData, callExpressionProvider) {
57
+ if (sdk_build_core_1.Data.isString(scriptData)) {
58
+ return scriptData.getValue();
59
+ }
60
+ else if (!scriptData) {
61
+ return '';
62
+ }
63
+ scriptData = scriptData instanceof ModuleFunctionData ? scriptData.getValue() : scriptData;
64
+ if (scriptData instanceof sdk_build_core_1.Data) {
65
+ throw new Error(`Unsupported script data type: ${scriptData.getNode().getText()}`);
66
+ }
67
+ const { exportName, modulePath, isDefault } = scriptData;
68
+ return isDefault
69
+ ? `const ${exportName} = require('${modulePath}').default;\n${callExpressionProvider(exportName)};`
70
+ : `const { ${exportName} } = require('${modulePath}');\n${callExpressionProvider(exportName)};`;
71
+ }
72
+ }
73
+ exports.ModuleFunctionData = ModuleFunctionData;
74
+ function applyModulePathMappings(path, context) {
75
+ const { modulePaths } = context.app.config;
76
+ if (!modulePaths) {
77
+ return path;
78
+ }
79
+ // TODO: Naive implementation for now that just supports simple patterns. We can explore supporting more complex patterns later.
80
+ for (const [source, target] of Object.entries(modulePaths)) {
81
+ const match = path.match(source.replace(/\*+/, '(.*)'))?.[1];
82
+ if (match !== undefined) {
83
+ return target.replace(/\*+/, match);
84
+ }
85
+ }
86
+ return path;
87
+ }
88
+ /**
89
+ * Removes invalid control characters that would cause XML parsing errors.
90
+ * Regex taken from: https://github.com/oozcitak/xmlbuilder-js/blob/b20136cd1591d0f17ab2f184053c7150150428b2/src/XMLStringifier.coffee#L119C15-L119C127
91
+ */
92
+ function removeInvalidControlCharacters(content) {
93
+ return content.replace(
94
+ // eslint-disable-next-line no-control-regex
95
+ /[\0-\x08\x0B\f\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g, '');
96
+ }
97
+ /**
98
+ * If the code contains the character sequence ']]>' it will be parsed as the end of
99
+ * the CDATA section. To avoid this, we need to split the sequence by dividing the
100
+ * content into two CDATA sections at that point.
101
+ */
102
+ function sanitizeNestedCdataTags(content) {
103
+ return content.replace(/]]>/g, ']]]]><![CDATA[>');
104
+ }
105
+ function sanitizeModuleContent(content) {
106
+ return sanitizeNestedCdataTags(removeInvalidControlCharacters(content));
107
+ }
108
+ function extractFunctionDeclaration(node, context) {
109
+ const result = context.extractEntities(node.getSourceFile());
110
+ if (!result.handled) {
111
+ return result;
112
+ }
113
+ const module = result.data[0];
114
+ if (!(module instanceof ModuleEntityData)) {
115
+ return { handled: false };
116
+ }
117
+ const name = node.getName() ?? 'functionModule';
118
+ if (!name) {
119
+ return {
120
+ handled: true,
121
+ data: [],
122
+ diagnostics: [new sdk_build_core_1.FluentDiagnostic(node, 'Function declaration must have a name')],
123
+ };
124
+ }
125
+ return {
126
+ handled: true,
127
+ diagnostics: [],
128
+ data: [new ModuleFunctionData(name, module, node)],
129
+ };
130
+ }
131
+ function getEmitOutput(file) {
132
+ const path = pathModule.normalize(file.getFilePath());
133
+ if (!path.endsWith('.ts')) {
134
+ return file.getFullText();
135
+ }
136
+ const project = new ts_morph_1.Project({
137
+ // TODO: Use the project's local tsconfig.json if there is one
138
+ compilerOptions: {
139
+ target: ts_morph_1.ScriptTarget.ES2022,
140
+ module: ts_morph_1.ModuleKind.ES2022,
141
+ declaration: false,
142
+ sourceMap: false,
143
+ },
144
+ });
145
+ const emitResult = project
146
+ .createSourceFile('module.ts', file.getFullText(), { overwrite: true, scriptKind: ts_morph_1.ScriptKind.TS })
147
+ .getEmitOutput();
148
+ const diagnostics = emitResult
149
+ .getDiagnostics()
150
+ .map((d) => new sdk_project_1.TypeScriptDiagnostic(d))
151
+ .filter((d) => d.level === sdk_project_1.Diagnostic.Level.Error);
152
+ if (diagnostics.length > 0) {
153
+ return diagnostics;
154
+ }
155
+ const output = emitResult.getOutputFiles()[0];
156
+ if (!output) {
157
+ return [new sdk_build_core_1.FluentDiagnostic(file, `Failed to get emit output for module: ${path}`)];
158
+ }
159
+ return output.getText();
160
+ }
161
+ exports.default = (0, sdk_build_core_1.Plugin)({
162
+ name: 'ServerModule',
163
+ extractors: {
164
+ raw: {
165
+ module: {
166
+ FunctionDeclaration: extractFunctionDeclaration,
167
+ FunctionExpression(node, context) {
168
+ const parent = node.getParentIfKind(ts_morph_1.SyntaxKind.VariableDeclaration);
169
+ if (!parent) {
170
+ return { handled: false };
171
+ }
172
+ return extractFunctionDeclaration(parent, context);
173
+ },
174
+ },
175
+ },
176
+ entity: {
177
+ module: {
178
+ SourceFile(file, context) {
179
+ const path = pathModule.normalize(file.getFilePath());
180
+ if (path === pathModule.normalize(context.getKeysSourceFile().getFilePath())) {
181
+ return { handled: false };
182
+ }
183
+ const content = getEmitOutput(file);
184
+ if (Array.isArray(content)) {
185
+ return {
186
+ handled: true,
187
+ data: [],
188
+ diagnostics: content,
189
+ };
190
+ }
191
+ return {
192
+ handled: true,
193
+ diagnostics: [],
194
+ data: [new ModuleEntityData(content, file, context)],
195
+ };
196
+ },
197
+ },
198
+ },
199
+ },
200
+ composers: {
201
+ entity: {
202
+ module(module) {
203
+ return {
204
+ kind: 'module',
205
+ guid: module.getGuid(),
206
+ node: module.getNode(),
207
+ data: module.getValue(),
208
+ };
209
+ },
210
+ },
211
+ },
212
+ serializers: {
213
+ module(module, context) {
214
+ const { path, content } = module.data;
215
+ return {
216
+ name: `sys_module_${module.guid}.xml`,
217
+ directory: 'update',
218
+ content: `<?xml version="1.0"?>
219
+ <record_update>
220
+ <sys_module action="INSERT_OR_UPDATE">
221
+ <sys_scope>${context.app.config.scopeId}</sys_scope>
222
+ <path>${path}</path>
223
+ <external_source>false</external_source>
224
+ <content><![CDATA[${sanitizeModuleContent(content)}]]></content>
225
+ </sys_module>
226
+ </record_update>`,
227
+ };
228
+ },
229
+ },
230
+ });
231
+ //# sourceMappingURL=ServerModulePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerModulePlugin.js","sourceRoot":"","sources":["../src/ServerModulePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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G,aAAa,CAAC,IAAI,CAAC,CAAA;oBACnC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;wBACzB,OAAO;4BACH,OAAO,EAAE,IAAI;4BACb,IAAI,EAAE,EAAE;4BACR,WAAW,EAAE,OAAO;yBACvB,CAAA;oBACL,CAAC;oBAED,OAAO;wBACH,OAAO,EAAE,IAAI;wBACb,WAAW,EAAE,EAAE;wBACf,IAAI,EAAE,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;qBACvD,CAAA;gBACL,CAAC;aACJ;SACJ;KACJ;IACD,SAAS,EAAE;QACP,MAAM,EAAE;YACJ,MAAM,CAAC,MAAM;gBACT,OAAO;oBACH,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE;oBACtB,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE;oBACtB,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE;iBAC1B,CAAA;YACL,CAAC;SACJ;KACJ;IACD,WAAW,EAAE;QACT,MAAM,CAAC,MAAM,EAAE,OAAO;YAClB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,IAAW,CAAA;YAC5C,OAAO;gBACH,IAAI,EAAE,cAAc,MAAM,CAAC,IAAI,MAAM;gBACrC,SAAS,EAAE,QAAQ;gBACnB,OAAO,EAAE;;;iBAGR,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO;YAC/B,IAAI;;wBAEQ,qBAAqB,CAAC,OAAO,CAAC;;iBAErC;aACJ,CAAA;QACL,CAAC;KACJ;CACJ,CAAC,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { EntityData } from '@servicenow/sdk-build-core';
1
2
  import { Diagnostic } from '@servicenow/sdk-project';
2
3
  import { Record } from '@servicenow/sdk-core/runtime/db';
3
4
  declare const _default: {
@@ -9,7 +10,9 @@ declare const _default: {
9
10
  };
10
11
  readonly extractors: {
11
12
  readonly entity: {
12
- readonly CallExpression: (node: import("ts-morph").CallExpression<import("ts-morph").ts.CallExpression>, context: import("@servicenow/sdk-build-core").Context) => import("@servicenow/sdk-build-core").ExtractionResult<import("@servicenow/sdk-build-core").EntityData<Record<"sys_user_preference">>>;
13
+ readonly fluent: {
14
+ readonly CallExpression: (node: import("ts-morph").CallExpression<import("ts-morph").ts.CallExpression>, context: import("@servicenow/sdk-build-core").Context) => import("@servicenow/sdk-build-core").ExtractionResult<EntityData<Record<keyof Now.Internal.Tables>>>;
15
+ };
13
16
  };
14
17
  };
15
18
  };
@@ -4,17 +4,17 @@ const app_1 = require("@servicenow/sdk-core/runtime/app");
4
4
  const sdk_build_core_1 = require("@servicenow/sdk-build-core");
5
5
  const RecordPlugin_1 = require("./db/RecordPlugin");
6
6
  const sdk_project_1 = require("@servicenow/sdk-project");
7
- const db_1 = require("@servicenow/sdk-core/runtime/db");
8
- function asRecord(config) {
9
- const { $id, value, ...rest } = app_1.UserPreferenceSchema.parse(config);
10
- return (0, db_1.Record)({
11
- table: 'sys_user_preference',
7
+ function asRecord(entity) {
8
+ const node = entity.getNode();
9
+ const { $id, value, ...rest } = entity.getProperties();
10
+ return new sdk_build_core_1.ObjectData({
11
+ table: new sdk_build_core_1.StringData('sys_user_preference', node),
12
12
  $id,
13
- data: {
13
+ data: new sdk_build_core_1.ObjectData({
14
14
  ...rest,
15
- value: `${value}`, // TODO: Should be allowed to assign non-strings to string columns
16
- },
17
- });
15
+ value: new sdk_build_core_1.StringData(value.getValue().toString(), value.getNode()),
16
+ }, node),
17
+ }, node);
18
18
  }
19
19
  exports.default = (0, sdk_build_core_1.Plugin)({
20
20
  name: 'UserPreference',
@@ -23,7 +23,9 @@ exports.default = (0, sdk_build_core_1.Plugin)({
23
23
  },
24
24
  extractors: {
25
25
  entity: {
26
- CallExpression: (node, context) => (0, RecordPlugin_1.extractCallExpressionAsRecord)(app_1.UserPreference, asRecord, (pref) => context.registerExplicitId('sys_user_preference', pref.$id), node, context),
26
+ fluent: {
27
+ CallExpression: (node, context) => (0, RecordPlugin_1.extractCallExpressionAsRecord)(app_1.UserPreference, asRecord, (pref) => context.registerExplicitId('sys_user_preference', pref.$id), node, context),
28
+ },
27
29
  },
28
30
  },
29
31
  });
@@ -1 +1 @@
1
- {"version":3,"file":"UserPreferencePlugin.js","sourceRoot":"","sources":["../src/UserPreferencePlugin.ts"],"names":[],"mappings":";;AAAA,0DAA6G;AAC7G,+DAAmD;AACnD,oDAAiE;AACjE,yDAAoD;AACpD,wDAAwD;AAExD,SAAS,QAAQ,CAAC,MAA4B;IAC1C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,0BAAoB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAClE,OAAO,IAAA,WAAM,EAAC;QACV,KAAK,EAAE,qBAAqB;QAC5B,GAAG;QACH,IAAI,EAAE;YACF,GAAG,IAAI;YACP,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,kEAAkE;SACxF;KACJ,CAAC,CAAA;AACN,CAAC;AAED,kBAAe,IAAA,uBAAM,EAAC;IAClB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE;QACT,mBAAmB,EAAE,EAAE,eAAe,EAAE,wBAAU,CAAC,KAAK,CAAC,IAAI,EAAE;KAClE;IACD,UAAU,EAAE;QACR,MAAM,EAAE;YACJ,cAAc,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAC9B,IAAA,4CAA6B,EACzB,oBAAc,EACd,QAAQ,EACR,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,IAAI,CAAC,GAAa,CAAC,EAC/E,IAAI,EACJ,OAAO,CACV;SACR;KACJ;CACJ,CAAC,CAAA"}
1
+ {"version":3,"file":"UserPreferencePlugin.js","sourceRoot":"","sources":["../src/UserPreferencePlugin.ts"],"names":[],"mappings":";;AAAA,0DAAuF;AACvF,+DAAuF;AACvF,oDAAiE;AACjE,yDAAoD;AAGpD,SAAS,QAAQ,CAAC,MAAwC;IACtD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;IAC7B,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,aAAa,EAAE,CAAA;IACtD,OAAO,IAAI,2BAAU,CACjB;QACI,KAAK,EAAE,IAAI,2BAAU,CAAC,qBAAqB,EAAE,IAAI,CAAC;QAClD,GAAG;QACH,IAAI,EAAE,IAAI,2BAAU,CAChB;YACI,GAAG,IAAI;YACP,KAAK,EAAE,IAAI,2BAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;SACtE,EACD,IAAI,CACP;KACJ,EACD,IAAI,CACP,CAAA;AACL,CAAC;AAED,kBAAe,IAAA,uBAAM,EAAC;IAClB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE;QACT,mBAAmB,EAAE,EAAE,eAAe,EAAE,wBAAU,CAAC,KAAK,CAAC,IAAI,EAAE;KAClE;IACD,UAAU,EAAE;QACR,MAAM,EAAE;YACJ,MAAM,EAAE;gBACJ,cAAc,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAC9B,IAAA,4CAA6B,EACzB,oBAAc,EACd,QAAQ,EACR,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,IAAI,CAAC,GAAa,CAAC,EAC/E,IAAI,EACJ,OAAO,CACV;aACR;SACJ;KACJ;CACJ,CAAC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { Acl } from '@servicenow/sdk-core/runtime/app';
2
- import { Context, FluentDiagnostic, EntityData, ObjectData } from '@servicenow/sdk-build-core';
2
+ import { FluentDiagnostic, EntityData } from '@servicenow/sdk-build-core';
3
3
  import { Record as DBRecord } from '@servicenow/sdk-core/runtime/db';
4
4
  import * as ts from 'ts-morph';
5
5
  import { Diagnostic } from '@servicenow/sdk-project';
@@ -12,74 +12,48 @@ declare const _default: {
12
12
  };
13
13
  readonly extractors: {
14
14
  readonly entity: {
15
- readonly CallExpression: (node: ts.CallExpression<ts.ts.CallExpression>, context: Context) => {
16
- handled: false;
17
- } | {
18
- handled: true;
19
- data: EntityData<Acl<keyof Now.Internal.Tables>>[];
20
- diagnostics: FluentDiagnostic[];
21
- } | {
22
- handled: true;
23
- diagnostics: FluentDiagnostic[];
24
- data: (EntityData<{
25
- readonly table: "sys_security_acl_role";
26
- readonly $id: string;
27
- readonly data: {
28
- readonly sys_security_acl: string;
29
- readonly sys_user_role: string;
30
- };
31
- }> | EntityData<{
32
- data: {
33
- script: string;
34
- name: string;
35
- active: boolean;
36
- type: string;
37
- operation: string;
38
- decision_type: "allow" | "deny";
39
- description: string;
40
- local_or_existing: "Local" | "Existing";
41
- admin_overrides: boolean;
42
- advanced: boolean;
43
- condition: string;
44
- applies_to: string;
45
- security_attribute: string | DBRecord<"sys_security_attribute">;
46
- };
47
- table: "sys_security_acl";
48
- $id: any;
49
- }>)[];
50
- };
51
- };
52
- readonly raw: {
53
- readonly FunctionDeclaration: (node: ts.FunctionDeclaration, context: Context) => {
54
- handled: false;
55
- diagnostics?: never;
56
- data?: never;
57
- } | {
58
- handled: true;
59
- diagnostics: never[];
60
- data: ObjectData<{
61
- readonly filePath: string;
62
- readonly functionName: string | undefined;
63
- readonly isDefault: boolean;
64
- }>[];
65
- };
66
- readonly FunctionExpression: (node: ts.FunctionExpression, context: Context) => {
67
- handled: false;
68
- diagnostics?: never;
69
- data?: never;
70
- } | {
71
- handled: true;
72
- diagnostics: never[];
73
- data: ObjectData<{
74
- readonly filePath: string;
75
- readonly functionName: string | undefined;
76
- readonly isDefault: boolean;
77
- }>[];
15
+ readonly fluent: {
16
+ readonly CallExpression: (node: ts.CallExpression<ts.ts.CallExpression>, context: import("@servicenow/sdk-build-core").Context) => {
17
+ handled: false;
18
+ } | {
19
+ handled: true;
20
+ data: EntityData<Acl<keyof Now.Internal.Tables>>[];
21
+ diagnostics: FluentDiagnostic[];
22
+ } | {
23
+ handled: true;
24
+ diagnostics: FluentDiagnostic[];
25
+ data: (EntityData<{
26
+ readonly table: "sys_security_acl_role";
27
+ readonly $id: string;
28
+ readonly data: {
29
+ readonly sys_security_acl: string;
30
+ readonly sys_user_role: string;
31
+ };
32
+ }> | EntityData<{
33
+ data: {
34
+ script: string;
35
+ name: string;
36
+ active: boolean;
37
+ type: string;
38
+ operation: string;
39
+ decision_type: "allow" | "deny";
40
+ description: string;
41
+ local_or_existing: "Local" | "Existing";
42
+ admin_overrides: boolean;
43
+ advanced: boolean;
44
+ condition: string;
45
+ applies_to: string;
46
+ security_attribute: string | DBRecord<"sys_security_attribute">;
47
+ };
48
+ table: "sys_security_acl";
49
+ $id: any;
50
+ }>)[];
51
+ };
78
52
  };
79
53
  };
80
54
  };
81
55
  readonly arrangers: {
82
- readonly record: (document: import("@servicenow/sdk-build-core").Document<"record">, context: Context) => {
56
+ readonly record: (document: import("@servicenow/sdk-build-core").Document<string>, context: import("@servicenow/sdk-build-core").Context) => {
83
57
  handled: false;
84
58
  result?: never;
85
59
  } | {
@@ -91,26 +65,14 @@ declare const _default: {
91
65
  };
92
66
  };
93
67
  readonly generators: {
94
- 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>> | {
95
- node: (ts.CallExpression<ts.ts.CallExpression> | ts.Node<ts.ts.EndOfFileToken> | ts.TypeAliasDeclaration | ts.TypeReferenceNode | ts.TypeLiteralNode | ts.PropertySignature | ts.TupleTypeNode | ts.FunctionExpression | ts.FunctionDeclaration | ts.ArrayLiteralExpression | ts.StringLiteral | ts.NumericLiteral | ts.TrueLiteral | ts.FalseLiteral | ts.Identifier | ts.SourceFile | ts.VariableDeclaration | ts.ClassDeclaration | ts.ExportDeclaration | ts.ObjectLiteralExpression | ts.AsExpression | ts.ComputedPropertyName | ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.PropertyAccessExpression<ts.ts.PropertyAccessExpression> | ts.NoSubstitutionTemplateLiteral | ts.ExpressionStatement | ts.TaggedTemplateExpression | ts.ExportAssignment | ts.ElementAccessExpression<ts.ts.ElementAccessExpression> | ts.TemplateExpression | ts.ImportClause | ts.ImportSpecifier | ts.ImportDeclaration | ts.NamedImports | ts.VariableStatement | ts.VariableDeclarationList | ts.Node<ts.ts.PlusToken> | ts.Node<ts.ts.ExportKeyword> | ts.Node<ts.ts.KeywordTypeNode<ts.ts.SyntaxKind.AnyKeyword>> | ts.ModuleDeclaration | ts.ModuleBlock | ts.Block | ts.ParameterDeclaration | ts.Node<ts.ts.EqualsGreaterThanToken> | ts.ArrowFunction | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateSpan | ts.TemplateTail | ts.PrefixUnaryExpression | undefined) & (ts.CallExpression<ts.ts.CallExpression> | ts.Node<ts.ts.EndOfFileToken> | ts.TypeAliasDeclaration | ts.TypeReferenceNode | ts.TypeLiteralNode | ts.PropertySignature | ts.TupleTypeNode | ts.FunctionExpression | ts.FunctionDeclaration | ts.ArrayLiteralExpression | ts.StringLiteral | ts.NumericLiteral | ts.TrueLiteral | ts.FalseLiteral | ts.Identifier | ts.SourceFile | ts.VariableDeclaration | ts.ClassDeclaration | ts.ExportDeclaration | ts.ObjectLiteralExpression | ts.AsExpression | ts.ComputedPropertyName | ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.PropertyAccessExpression<ts.ts.PropertyAccessExpression> | ts.NoSubstitutionTemplateLiteral | ts.ExpressionStatement | ts.TaggedTemplateExpression | ts.ExportAssignment | ts.ElementAccessExpression<ts.ts.ElementAccessExpression> | ts.TemplateExpression | ts.ImportClause | ts.ImportSpecifier | ts.ImportDeclaration | ts.NamedImports | ts.VariableStatement | ts.VariableDeclarationList | ts.Node<ts.ts.PlusToken> | ts.Node<ts.ts.ExportKeyword> | ts.Node<ts.ts.KeywordTypeNode<ts.ts.SyntaxKind.AnyKeyword>> | ts.ModuleDeclaration | ts.ModuleBlock | ts.Block | ts.ParameterDeclaration | ts.Node<ts.ts.EqualsGreaterThanToken> | ts.ArrowFunction | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateSpan | ts.TemplateTail | ts.PrefixUnaryExpression);
96
- data: unknown;
97
- kind: "record";
98
- guid: string;
99
- changedData?: unknown;
100
- xmlData?: unknown;
101
- action?: import("@servicenow/sdk-build-core").Action;
102
- parent?: import("@servicenow/sdk-build-core").Document<string, ts.CallExpression<ts.ts.CallExpression> | ts.Node<ts.ts.EndOfFileToken> | ts.TypeAliasDeclaration | ts.TypeReferenceNode | ts.TypeLiteralNode | ts.PropertySignature | ts.TupleTypeNode | ts.FunctionExpression | ts.FunctionDeclaration | ts.ArrayLiteralExpression | ts.StringLiteral | ts.NumericLiteral | ts.TrueLiteral | ts.FalseLiteral | ts.Identifier | ts.SourceFile | ts.VariableDeclaration | ts.ClassDeclaration | ts.ExportDeclaration | ts.ObjectLiteralExpression | ts.AsExpression | ts.ComputedPropertyName | ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.PropertyAccessExpression<ts.ts.PropertyAccessExpression> | ts.NoSubstitutionTemplateLiteral | ts.ExpressionStatement | ts.TaggedTemplateExpression | ts.ExportAssignment | ts.ElementAccessExpression<ts.ts.ElementAccessExpression> | ts.TemplateExpression | ts.ImportClause | ts.ImportSpecifier | ts.ImportDeclaration | ts.NamedImports | ts.VariableStatement | ts.VariableDeclarationList | ts.Node<ts.ts.PlusToken> | ts.Node<ts.ts.ExportKeyword> | ts.Node<ts.ts.KeywordTypeNode<ts.ts.SyntaxKind.AnyKeyword>> | ts.ModuleDeclaration | ts.ModuleBlock | ts.Block | ts.ParameterDeclaration | ts.Node<ts.ts.EqualsGreaterThanToken> | ts.ArrowFunction | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateSpan | ts.TemplateTail | ts.PrefixUnaryExpression> & {
103
- entity?: EntityData;
104
- node: ts.CallExpression<ts.ts.CallExpression> | ts.Node<ts.ts.EndOfFileToken> | ts.TypeAliasDeclaration | ts.TypeReferenceNode | ts.TypeLiteralNode | ts.PropertySignature | ts.TupleTypeNode | ts.FunctionExpression | ts.FunctionDeclaration | ts.ArrayLiteralExpression | ts.StringLiteral | ts.NumericLiteral | ts.TrueLiteral | ts.FalseLiteral | ts.Identifier | ts.SourceFile | ts.VariableDeclaration | ts.ClassDeclaration | ts.ExportDeclaration | ts.ObjectLiteralExpression | ts.AsExpression | ts.ComputedPropertyName | ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.PropertyAccessExpression<ts.ts.PropertyAccessExpression> | ts.NoSubstitutionTemplateLiteral | ts.ExpressionStatement | ts.TaggedTemplateExpression | ts.ExportAssignment | ts.ElementAccessExpression<ts.ts.ElementAccessExpression> | ts.TemplateExpression | ts.ImportClause | ts.ImportSpecifier | ts.ImportDeclaration | ts.NamedImports | ts.VariableStatement | ts.VariableDeclarationList | ts.Node<ts.ts.PlusToken> | ts.Node<ts.ts.ExportKeyword> | ts.Node<ts.ts.KeywordTypeNode<ts.ts.SyntaxKind.AnyKeyword>> | ts.ModuleDeclaration | ts.ModuleBlock | ts.Block | ts.ParameterDeclaration | ts.Node<ts.ts.EqualsGreaterThanToken> | ts.ArrowFunction | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateSpan | ts.TemplateTail | ts.PrefixUnaryExpression;
105
- } & import("@servicenow/sdk-build-core").Arranged<"resolved">;
106
- } | undefined;
68
+ readonly record: (document: any, context: any, linkedDocuments: any) => any;
107
69
  };
108
70
  readonly transformers: {
109
71
  readonly record: {
110
72
  readonly CallExpression: (document: import("@servicenow/sdk-build-core").Document<any, ts.CallExpression<ts.ts.CallExpression>> & {
111
73
  entity?: EntityData;
112
74
  node: ts.CallExpression<ts.ts.CallExpression>;
113
- } & import("@servicenow/sdk-build-core").Arranged, context: Context) => boolean;
75
+ } & import("@servicenow/sdk-build-core").Arranged, context: import("@servicenow/sdk-build-core").Context) => boolean;
114
76
  };
115
77
  };
116
78
  };
@@ -32,6 +32,7 @@ const ts = __importStar(require("ts-morph"));
32
32
  const app_2 = require("@servicenow/sdk-core/runtime/app");
33
33
  const ScriptTemplatePlugin_1 = require("../ScriptTemplatePlugin");
34
34
  const sdk_project_1 = require("@servicenow/sdk-project");
35
+ const ServerModulePlugin_1 = require("../ServerModulePlugin");
35
36
  const ExecuteOnlyTypes = new Set([
36
37
  'client_callable_flow_object',
37
38
  'client_callable_script_include',
@@ -47,8 +48,8 @@ function aclAsRecord(config) {
47
48
  if (!name) {
48
49
  throw new Error(`ACL of type ${config.type} and $id '${config.$id}' has no name or associated table`);
49
50
  }
50
- if (config.operation === 'execute' && !ExecuteOnlyTypes.has(config.type)) {
51
- throw new Error(`ACL ${name} cannot use operation 'execute', because it is of type '${config.type}'`);
51
+ if (config.operation !== 'execute' && ExecuteOnlyTypes.has(config.type)) {
52
+ throw new Error(`ACL ${name} must use operation 'execute', because it is of type '${config.type}'`);
52
53
  }
53
54
  if (config.script && config.type === 'graphql') {
54
55
  throw new Error(`ACL ${name} does not support scripts, because it is of type ${config.type}`);
@@ -88,58 +89,45 @@ exports.default = (0, sdk_build_core_1.Plugin)({
88
89
  },
89
90
  extractors: {
90
91
  entity: {
91
- CallExpression(node, context) {
92
- const result = (0, sdk_build_core_1.extractCallExpression)(app_1.Acl, 'record', node, context, (acl) => context.registerExplicitId('sys_security_acl', acl.$id));
93
- if (!result.handled || !(0 in result.data)) {
94
- return result;
95
- }
96
- const acl = result.data[0];
97
- const scriptVal = getScript(acl, context);
98
- const aclRecord = aclAsRecord(acl.getValue());
99
- const m2mRoleToAcl = acl
100
- .getProperty('roles')
101
- ?.getValue()
102
- ?.map((role) => {
103
- const roleId = typeof role === 'string' ? role : role.$id;
104
- const aclId = context.keys.registerExplicitId('sys_security_acl', aclRecord.$id);
105
- const roleSysId = typeof role === 'string' ? role : context.registerExplicitId('sys_user_role', role.$id);
106
- const guid = context.keys.registerCompositeId('sys_security_acl_role', {
107
- sys_security_acl: aclRecord.$id,
108
- sys_user_role: roleId,
109
- });
110
- return new sdk_build_core_1.EntityData('record', guid, sdk_build_core_1.ObjectData.fromObjectValue((0, db_1.Record)({
111
- table: 'sys_security_acl_role',
112
- $id: guid,
113
- data: {
114
- sys_security_acl: aclId,
115
- sys_user_role: roleSysId,
116
- },
117
- }), node), node);
118
- }) || [];
119
- const diagnostics = performDiagnosticChecksOnSecurityAttribute(node, acl.getValue(), m2mRoleToAcl, context.mode);
120
- const aclWithScript = { ...aclRecord, data: { ...aclRecord.data, script: scriptVal || '' } };
121
- const aclEntityData = new sdk_build_core_1.EntityData('record', acl.getGuid(), sdk_build_core_1.ObjectData.fromObjectValue(aclWithScript, node), node);
122
- return {
123
- handled: true,
124
- diagnostics: [...result.diagnostics, ...diagnostics],
125
- data: [aclEntityData, ...m2mRoleToAcl],
126
- };
127
- },
128
- },
129
- raw: {
130
- FunctionDeclaration(node, context) {
131
- const info = (0, scriptUtils_1.scriptInfo)(node, context, app_1.Acl.name);
132
- if (!info) {
133
- return { handled: false };
134
- }
135
- return { handled: true, diagnostics: [], data: [info] };
136
- },
137
- FunctionExpression(node, context) {
138
- const info = (0, scriptUtils_1.scriptInfo)(node, context, app_1.Acl.name);
139
- if (!info) {
140
- return { handled: false };
141
- }
142
- return { handled: true, diagnostics: [], data: [info] };
92
+ fluent: {
93
+ CallExpression(node, context) {
94
+ const result = (0, sdk_build_core_1.extractCallExpression)(app_1.Acl, 'record', node, context, (acl) => context.registerExplicitId('sys_security_acl', acl.$id));
95
+ if (!result.handled || !(0 in result.data)) {
96
+ return result;
97
+ }
98
+ const acl = result.data[0];
99
+ const aclRecord = aclAsRecord(acl.getValue());
100
+ const scriptVal = ServerModulePlugin_1.ModuleFunctionData.getGlueCode(acl.getProperty('script'), (n) => `answer = ${n}(current)`);
101
+ const m2mRoleToAcl = acl
102
+ .getProperty('roles')
103
+ ?.getValue(true)
104
+ ?.map((role) => {
105
+ const roleId = typeof role === 'string' ? role : role.$id;
106
+ const roleSysId = typeof role === 'string'
107
+ ? role
108
+ : context.registerExplicitId('sys_user_role', role.$id);
109
+ const guid = context.keys.registerCompositeId('sys_security_acl_role', {
110
+ sys_security_acl: aclRecord.$id,
111
+ sys_user_role: roleId,
112
+ });
113
+ return new sdk_build_core_1.EntityData('record', guid, sdk_build_core_1.ObjectData.fromObjectValue((0, db_1.Record)({
114
+ table: 'sys_security_acl_role',
115
+ $id: guid,
116
+ data: {
117
+ sys_security_acl: acl.getGuid(),
118
+ sys_user_role: roleSysId,
119
+ },
120
+ }), node), node);
121
+ }) || [];
122
+ const diagnostics = performDiagnosticChecksOnSecurityAttribute(node, acl.getValue(true), m2mRoleToAcl);
123
+ const aclWithScript = { ...aclRecord, data: { ...aclRecord.data, script: scriptVal || '' } };
124
+ const aclEntityData = new sdk_build_core_1.EntityData('record', acl.getGuid(), sdk_build_core_1.ObjectData.fromObjectValue(aclWithScript, node), node);
125
+ return {
126
+ handled: true,
127
+ diagnostics: [...result.diagnostics, ...diagnostics],
128
+ data: [aclEntityData, ...m2mRoleToAcl],
129
+ };
130
+ },
143
131
  },
144
132
  },
145
133
  },
@@ -190,7 +178,8 @@ exports.default = (0, sdk_build_core_1.Plugin)({
190
178
  }
191
179
  if (documentType === 'sys_security_acl_role') {
192
180
  if (!document.parent) {
193
- return true;
181
+ // Record plugin can handle this as its own entity
182
+ return false;
194
183
  }
195
184
  const acl2Role = document.data.data;
196
185
  if (document.action === 'DELETE') {
@@ -227,20 +216,22 @@ exports.default = (0, sdk_build_core_1.Plugin)({
227
216
  };
228
217
  const { script } = modifiedAclData;
229
218
  if (script !== undefined) {
230
- (0, ScriptTemplatePlugin_1.processScript)(args, 'script', script, document.guid, 'sys_security_acl', context);
219
+ (0, ScriptTemplatePlugin_1.processScript)(args, 'script', script);
231
220
  }
232
- return (0, sdk_build_core_1.transformFunctionArguments)(document.node, app_1.Acl, aclData);
221
+ (0, sdk_build_core_1.transformFunctionArguments)(document.node, app_1.Acl, aclData);
222
+ (0, sdk_build_core_1.fixFunctionArgumentTypes)(context, document.node);
223
+ return true;
233
224
  },
234
225
  },
235
226
  },
236
227
  });
237
228
  // security_attribute.is_localizsed ? 'Local' : 'Existing'
238
- function performDiagnosticChecksOnSecurityAttribute(callExpression, aclData, roles, mode) {
229
+ function performDiagnosticChecksOnSecurityAttribute(callExpression, aclData, roles) {
239
230
  const diagnostics = [];
240
231
  if (roles.length < 1) {
241
232
  const attributeRecord = aclData.security_attribute;
242
233
  if (!aclData.security_attribute && !aclData.script && !aclData.condition) {
243
- diagnostics.push(new sdk_build_core_1.FluentDiagnostic(callExpression, 'ACLs must have at least one of the following: roles, security_attribute, condition, or script', { level: mode === 'transform' ? sdk_project_1.Diagnostic.Level.Warn : sdk_project_1.Diagnostic.Level.Error }));
234
+ diagnostics.push(new sdk_build_core_1.FluentDiagnostic(callExpression, 'ACLs must have at least one of the following: roles, security_attribute, condition, or script', { level: sdk_project_1.Diagnostic.Level.Warn }));
244
235
  }
245
236
  else if (attributeRecord && attributeRecord.data) {
246
237
  if (aclData.local_or_existing === 'Existing' &&
@@ -264,19 +255,6 @@ function getTableOrName(type, name) {
264
255
  const field = tablePathParts[1] || '';
265
256
  return { table, field };
266
257
  }
267
- // TODO: The casting and type guards in this function are a bit of a mess and prone to errors.
268
- function getScript(acl, context) {
269
- const scriptData = acl.getProperty('script')?.getValue();
270
- let scriptVal;
271
- if (scriptData && scriptData.filePath) {
272
- const { filePath, functionName, isDefault } = scriptData;
273
- scriptVal = (0, scriptUtils_1.buildScriptImport)(filePath, functionName, isDefault, context, (funcName) => `answer = ${funcName}(current)\n`);
274
- }
275
- else {
276
- scriptVal = scriptData;
277
- }
278
- return scriptVal;
279
- }
280
258
  function reverseLookup(obj, sysId) {
281
259
  return (Object.entries(obj)
282
260
  .filter(([_, id]) => id === sysId)