@servicenow/sdk-build-plugins 4.0.2 → 4.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 (111) hide show
  1. package/dist/acl-plugin.js +23 -16
  2. package/dist/acl-plugin.js.map +1 -1
  3. package/dist/application-menu-plugin.js +15 -14
  4. package/dist/application-menu-plugin.js.map +1 -1
  5. package/dist/atf/test-plugin.js +37 -34
  6. package/dist/atf/test-plugin.js.map +1 -1
  7. package/dist/basic-syntax-plugin.js +50 -1
  8. package/dist/basic-syntax-plugin.js.map +1 -1
  9. package/dist/business-rule-plugin.js +12 -10
  10. package/dist/business-rule-plugin.js.map +1 -1
  11. package/dist/claims-plugin.d.ts +3 -0
  12. package/dist/claims-plugin.js +95 -0
  13. package/dist/claims-plugin.js.map +1 -0
  14. package/dist/client-script-plugin.js +1 -1
  15. package/dist/client-script-plugin.js.map +1 -1
  16. package/dist/column/column-to-record.d.ts +3 -3
  17. package/dist/column/column-to-record.js +17 -16
  18. package/dist/column/column-to-record.js.map +1 -1
  19. package/dist/column-plugin.js +86 -8
  20. package/dist/column-plugin.js.map +1 -1
  21. package/dist/cross-scope-privilege-plugin.js +17 -3
  22. package/dist/cross-scope-privilege-plugin.js.map +1 -1
  23. package/dist/html-import-plugin.js +8 -1
  24. package/dist/html-import-plugin.js.map +1 -1
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +3 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/json-plugin.d.ts +7 -2
  29. package/dist/json-plugin.js +28 -12
  30. package/dist/json-plugin.js.map +1 -1
  31. package/dist/list-plugin.js +29 -17
  32. package/dist/list-plugin.js.map +1 -1
  33. package/dist/now-config-plugin.js +14 -5
  34. package/dist/now-config-plugin.js.map +1 -1
  35. package/dist/now-include-plugin.d.ts +6 -7
  36. package/dist/now-include-plugin.js +59 -26
  37. package/dist/now-include-plugin.js.map +1 -1
  38. package/dist/now-ref-plugin.js +1 -1
  39. package/dist/now-ref-plugin.js.map +1 -1
  40. package/dist/package-json-plugin.js +5 -7
  41. package/dist/package-json-plugin.js.map +1 -1
  42. package/dist/property-plugin.js +1 -1
  43. package/dist/property-plugin.js.map +1 -1
  44. package/dist/record-plugin.js +23 -9
  45. package/dist/record-plugin.js.map +1 -1
  46. package/dist/repack/index.d.ts +2 -0
  47. package/dist/repack/index.js +8 -0
  48. package/dist/repack/index.js.map +1 -1
  49. package/dist/rest-api-plugin.js +12 -12
  50. package/dist/rest-api-plugin.js.map +1 -1
  51. package/dist/role-plugin.js +18 -16
  52. package/dist/role-plugin.js.map +1 -1
  53. package/dist/script-action-plugin.js +1 -1
  54. package/dist/script-action-plugin.js.map +1 -1
  55. package/dist/script-include-plugin.js +6 -4
  56. package/dist/script-include-plugin.js.map +1 -1
  57. package/dist/server-module-plugin/index.d.ts +3 -1
  58. package/dist/server-module-plugin/index.js +110 -28
  59. package/dist/server-module-plugin/index.js.map +1 -1
  60. package/dist/service-portal/angular-provider-plugin.js +3 -3
  61. package/dist/service-portal/angular-provider-plugin.js.map +1 -1
  62. package/dist/service-portal/dependency-plugin.js +9 -12
  63. package/dist/service-portal/dependency-plugin.js.map +1 -1
  64. package/dist/service-portal/widget-plugin.js +8 -8
  65. package/dist/service-portal/widget-plugin.js.map +1 -1
  66. package/dist/static-content-plugin.d.ts +2 -0
  67. package/dist/static-content-plugin.js +16 -13
  68. package/dist/static-content-plugin.js.map +1 -1
  69. package/dist/table-plugin.js +55 -33
  70. package/dist/table-plugin.js.map +1 -1
  71. package/dist/ui-action-plugin.js +29 -19
  72. package/dist/ui-action-plugin.js.map +1 -1
  73. package/dist/ui-page-plugin.js +6 -3
  74. package/dist/ui-page-plugin.js.map +1 -1
  75. package/dist/user-preference-plugin.js +2 -2
  76. package/dist/user-preference-plugin.js.map +1 -1
  77. package/package.json +10 -6
  78. package/src/acl-plugin.ts +31 -27
  79. package/src/application-menu-plugin.ts +39 -39
  80. package/src/atf/test-plugin.ts +82 -81
  81. package/src/basic-syntax-plugin.ts +54 -1
  82. package/src/business-rule-plugin.ts +74 -73
  83. package/src/claims-plugin.ts +116 -0
  84. package/src/client-script-plugin.ts +1 -1
  85. package/src/column/column-to-record.ts +59 -53
  86. package/src/column-plugin.ts +93 -8
  87. package/src/cross-scope-privilege-plugin.ts +18 -3
  88. package/src/html-import-plugin.ts +12 -2
  89. package/src/index.ts +2 -1
  90. package/src/json-plugin.ts +35 -15
  91. package/src/list-plugin.ts +39 -30
  92. package/src/now-config-plugin.ts +19 -8
  93. package/src/now-include-plugin.ts +64 -30
  94. package/src/now-ref-plugin.ts +1 -1
  95. package/src/package-json-plugin.ts +7 -6
  96. package/src/property-plugin.ts +1 -1
  97. package/src/record-plugin.ts +25 -9
  98. package/src/repack/index.ts +14 -0
  99. package/src/rest-api-plugin.ts +15 -15
  100. package/src/role-plugin.ts +15 -15
  101. package/src/script-action-plugin.ts +1 -1
  102. package/src/script-include-plugin.ts +7 -4
  103. package/src/server-module-plugin/index.ts +158 -43
  104. package/src/service-portal/angular-provider-plugin.ts +12 -10
  105. package/src/service-portal/dependency-plugin.ts +12 -13
  106. package/src/service-portal/widget-plugin.ts +36 -30
  107. package/src/static-content-plugin.ts +12 -10
  108. package/src/table-plugin.ts +71 -56
  109. package/src/ui-action-plugin.ts +49 -33
  110. package/src/ui-page-plugin.ts +6 -3
  111. package/src/user-preference-plugin.ts +2 -2
@@ -1,4 +1,4 @@
1
- import { CallExpressionShape, Plugin } from '@servicenow/sdk-build-core'
1
+ import { CallExpressionShape, Plugin, type RecordId } from '@servicenow/sdk-build-core'
2
2
  import { NowIdShape } from './now-id-plugin'
3
3
 
4
4
  /**
@@ -31,7 +31,21 @@ export const ApplicationMenuPlugin = Plugin.create({
31
31
  inverse: true,
32
32
  },
33
33
  },
34
- toShape(record, { factory }) {
34
+ async toShape(record, { factory }) {
35
+ const roles = record.get('roles')
36
+ const roleNames = roles.ifString()?.ifNotEmpty()?.split(',') ?? []
37
+ const roleReferences: RecordId[] = []
38
+
39
+ for (const roleName of roleNames) {
40
+ roleReferences.push(
41
+ await factory.createReference({
42
+ source: roles,
43
+ table: 'sys_user_role',
44
+ keys: { name: roleName },
45
+ })
46
+ )
47
+ }
48
+
35
49
  return {
36
50
  success: true,
37
51
  value: new CallExpressionShape({
@@ -47,17 +61,7 @@ export const ApplicationMenuPlugin = Plugin.create({
47
61
  name: $.def(''),
48
62
  active: $.toBoolean().def(true),
49
63
  order: $.map((v) => v.ifString()?.ifNotEmpty()?.toNumber()).def(100),
50
- roles: $.map((v) => {
51
- const roleNames =
52
- v.isString() && v.asString().getValue() !== '' ? v.asString().split(',') : []
53
- return roleNames.map((roleName) =>
54
- factory.createReference({
55
- source: v,
56
- table: 'sys_user_role',
57
- keys: { name: roleName },
58
- })
59
- )
60
- }).def([]),
64
+ roles: $.val(roleReferences).def([]),
61
65
  })),
62
66
  ],
63
67
  }),
@@ -74,34 +78,30 @@ export const ApplicationMenuPlugin = Plugin.create({
74
78
  return { success: false }
75
79
  }
76
80
 
81
+ const menu = callExpression.getArgument(0).asObject()
77
82
  return {
78
83
  success: true,
79
- value: callExpression
80
- .getArgument(0)
81
- .asObject()
82
- .pipe((menu) =>
83
- factory.createRecord({
84
- source: callExpression,
85
- table: 'sys_app_application',
86
- explicitId: menu.get('$id'),
87
- properties: menu.transform(({ $ }) => ({
88
- title: $,
89
- hint: $.def(''),
90
- description: $.def(''),
91
- name: $.def(''),
92
- active: $.def(true),
93
- order: $.def(100),
94
- device_type: $.val('browser'),
95
- roles: $.map((v) =>
96
- v
97
- .ifArray()
98
- ?.map((r) => (r.ifRecord()?.get('name') ?? r.asString()).getValue())
99
- .join(',')
100
- ).def(''),
101
- category: $,
102
- })),
103
- })
104
- ),
84
+ value: await factory.createRecord({
85
+ source: callExpression,
86
+ table: 'sys_app_application',
87
+ explicitId: menu.get('$id'),
88
+ properties: menu.transform(({ $ }) => ({
89
+ title: $,
90
+ hint: $.def(''),
91
+ description: $.def(''),
92
+ name: $.def(''),
93
+ active: $.def(true),
94
+ order: $.def(100),
95
+ device_type: $.val('browser'),
96
+ roles: $.map((v) =>
97
+ v
98
+ .ifArray()
99
+ ?.map((r) => (r.ifRecord()?.get('name') ?? r.asString()).getValue())
100
+ .join(',')
101
+ ).def(''),
102
+ category: $,
103
+ })),
104
+ }),
105
105
  }
106
106
  },
107
107
  },
@@ -171,15 +171,17 @@ export const TestPlugin = Plugin.create({
171
171
  coalesce: ['document', 'document_key', 'variable'],
172
172
  },
173
173
  sys_atf_step: {
174
- toFile(step, { database }) {
174
+ composite: true,
175
+ toFile(step, { database, config }) {
175
176
  const recordUpdate = create().ele('record_update', { table: 'sys_atf_step' })
176
- const stepElement = recordUpdate.ele('sys_atf_step', { action: 'INSERT_OR_UPDATE' })
177
+ const stepElement = recordUpdate.ele('sys_atf_step', { action: step.getAction() })
177
178
  const stepId = step.getId().getValue()
178
179
  if (!stepId) {
179
180
  throw new Error('Invalid step id')
180
181
  }
181
182
 
182
183
  stepElement.ele('sys_id').txt(stepId)
184
+ stepElement.ele('sys_scope', { display_value: config.scope }).txt(config.scopeId)
183
185
 
184
186
  Object.entries(step.properties()).forEach(([key, value]) => {
185
187
  stepElement.ele(key).txt(value.ifDefined()?.toString()?.getValue() ?? '')
@@ -196,7 +198,7 @@ export const TestPlugin = Plugin.create({
196
198
  })
197
199
 
198
200
  variableValues.forEach((varRecord) => {
199
- const variableElement = recordUpdate.ele('sys_variable_value', { action: 'INSERT_OR_UPDATE' })
201
+ const variableElement = recordUpdate.ele('sys_variable_value', { action: step.getAction() })
200
202
  variableElement.ele('sys_id').txt(varRecord.getId().getValue())
201
203
  Object.entries(varRecord.properties()).forEach(([key, value]) => {
202
204
  variableElement.ele(key).txt(value instanceof UndefinedShape ? '' : value.toString().getValue())
@@ -213,7 +215,7 @@ export const TestPlugin = Plugin.create({
213
215
 
214
216
  elementMappingRecords.forEach((record) => {
215
217
  const elementMappingElement = recordUpdate.ele('sys_element_mapping', {
216
- action: 'INSERT_OR_UPDATE',
218
+ action: step.getAction(),
217
219
  })
218
220
  elementMappingElement.ele('sys_id').txt(record.getId().getValue())
219
221
  Object.entries(record.properties()).forEach(([key, value]) => {
@@ -224,6 +226,7 @@ export const TestPlugin = Plugin.create({
224
226
  return {
225
227
  success: true,
226
228
  value: {
229
+ source: step,
227
230
  name: `sys_atf_step_${step.getId().getValue()}.xml`,
228
231
  category: step.getInstallCategory(),
229
232
  content: recordUpdate.end({ prettyPrint: true }),
@@ -253,7 +256,7 @@ export const TestPlugin = Plugin.create({
253
256
  return { success: false }
254
257
  }
255
258
 
256
- const testRecord = factory.createRecord({
259
+ const testRecord = await factory.createRecord({
257
260
  source: callExpression,
258
261
  table: 'sys_atf_test',
259
262
  explicitId: testId,
@@ -265,85 +268,83 @@ export const TestPlugin = Plugin.create({
265
268
  })),
266
269
  })
267
270
 
268
- const stepRecords = steps.map((step, index) => {
269
- const rawTimeout = step.values.get('timeout')
270
- const timeout = rawTimeout.isUndefined()
271
- ? step.defaultTimeout
272
- : convertTimeoutToSystemFormat(rawTimeout)
273
-
274
- return factory.createRecord({
275
- table: 'sys_atf_step',
276
- source: step.source,
277
- explicitId: step.values.get('$id'),
278
- properties: step.values.transform(({ $ }) => ({
279
- active: $.toBoolean().def(true),
280
- description: $,
281
- display_name: $.val(step.displayName),
282
- notes: $,
283
- order: $.val(index + 1),
284
- step_config: $.val(step.stepConfigId),
285
- table: $.val(step.table),
286
- test: $.val(testRecord.getId()),
287
- timeout: $.val(timeout),
288
- warning_message: $.from('warning'),
289
- })),
271
+ const stepRecords = await Promise.all(
272
+ steps.map(async (step, index) => {
273
+ const rawTimeout = step.values.get('timeout')
274
+ const timeout = rawTimeout.isUndefined()
275
+ ? step.defaultTimeout
276
+ : convertTimeoutToSystemFormat(rawTimeout)
277
+
278
+ return await factory.createRecord({
279
+ table: 'sys_atf_step',
280
+ source: step.source,
281
+ explicitId: step.values.get('$id'),
282
+ properties: step.values.transform(({ $ }) => ({
283
+ active: $.toBoolean().def(true),
284
+ description: $,
285
+ display_name: $.val(step.displayName),
286
+ notes: $,
287
+ order: $.val(index + 1),
288
+ step_config: $.val(step.stepConfigId),
289
+ table: $.val(step.table),
290
+ test: $.val(testRecord.getId()),
291
+ timeout: $.val(timeout),
292
+ warning_message: $.from('warning'),
293
+ })),
294
+ })
290
295
  })
291
- })
292
-
293
- const stepAndVariableValueRecords = steps.flatMap((step, index) => {
294
- const variableRecords: RecordShape[] = Object.entries(step.variables).flatMap(
295
- ([varName, atfVariableInfo]) => {
296
- const valueShape = step.values.get(varName, false)
297
-
298
- let elementMappingRecord: RecordShape | undefined
299
-
300
- const value = createGemExpressionsFromShape(valueShape, stepRecords, diagnostics)
301
- if (value !== undefined) {
302
- elementMappingRecord = factory.createRecord({
303
- table: 'sys_element_mapping',
304
- source: step.source,
305
- properties: {
306
- field: atfVariableInfo.field,
307
- id: stepRecords[index]?.getId(),
308
- table: `var__m_atf_input_variable_${step.stepConfigId}`,
309
- value: serializeValueToRecord(
310
- value,
311
- atfVariableInfo.type,
312
- atfVariableInfo.default
313
- ),
314
- },
315
- })
316
- }
317
-
318
- return [
319
- factory.createRecord({
320
- table: 'sys_variable_value',
321
- source: step.source,
322
- properties: {
323
- document: 'sys_atf_step',
324
- document_key: stepRecords[index]?.getId(),
325
- value: serializeValueToRecord(
326
- value ??
327
- valueShape
328
- .ifArray()
329
- ?.getElements()
330
- .map((v) => v.ifRecord()?.getId().getValue() ?? v.getValue()) ??
331
- valueShape.ifResolvable()?.resolve().ifRecord()?.getId().getValue() ??
332
- valueShape.getValue(),
333
- atfVariableInfo.type,
334
- atfVariableInfo.default
335
- ),
336
- variable: atfVariableInfo.inputVariableId,
337
- order: atfVariableInfo.order,
338
- },
339
- }),
340
- ...(elementMappingRecord ? [elementMappingRecord] : []),
341
- ]
296
+ )
297
+
298
+ const stepAndVariableValueRecords: RecordShape[] = []
299
+ for (const [index, step] of steps.entries()) {
300
+ for (const [varName, atfVariableInfo] of Object.entries(step.variables)) {
301
+ const valueShape = step.values.get(varName, false)
302
+
303
+ let elementMappingRecord: RecordShape | undefined
304
+
305
+ const value = createGemExpressionsFromShape(valueShape, stepRecords, diagnostics)
306
+ if (value !== undefined) {
307
+ elementMappingRecord = await factory.createRecord({
308
+ table: 'sys_element_mapping',
309
+ source: step.source,
310
+ properties: {
311
+ field: atfVariableInfo.field,
312
+ id: stepRecords[index]?.getId(),
313
+ table: `var__m_atf_input_variable_${step.stepConfigId}`,
314
+ value: serializeValueToRecord(value, atfVariableInfo.type, atfVariableInfo.default),
315
+ },
316
+ })
342
317
  }
343
- )
344
318
 
345
- return variableRecords
346
- })
319
+ stepAndVariableValueRecords.push(
320
+ await factory.createRecord({
321
+ table: 'sys_variable_value',
322
+ source: step.source,
323
+ properties: {
324
+ document: 'sys_atf_step',
325
+ document_key: stepRecords[index]?.getId(),
326
+ value: serializeValueToRecord(
327
+ value ??
328
+ valueShape
329
+ .ifArray()
330
+ ?.getElements()
331
+ .map((v) => v.ifRecord()?.getId().getValue() ?? v.getValue()) ??
332
+ valueShape.ifResolvable()?.resolve().ifRecord()?.getId().getValue() ??
333
+ valueShape.getValue(),
334
+ atfVariableInfo.type,
335
+ atfVariableInfo.default
336
+ ),
337
+ variable: atfVariableInfo.inputVariableId,
338
+ order: atfVariableInfo.order,
339
+ },
340
+ })
341
+ )
342
+
343
+ if (elementMappingRecord) {
344
+ stepAndVariableValueRecords.push(elementMappingRecord)
345
+ }
346
+ }
347
+ }
347
348
 
348
349
  return {
349
350
  success: true,
@@ -23,6 +23,7 @@ import {
23
23
  removeReferences,
24
24
  remove,
25
25
  isFluentFile,
26
+ path as pathModule,
26
27
  } from '@servicenow/sdk-build-core'
27
28
 
28
29
  export const BasicSyntaxPlugin = Plugin.create({
@@ -34,6 +35,53 @@ export const BasicSyntaxPlugin = Plugin.create({
34
35
  },
35
36
  ],
36
37
  shapes: [
38
+ {
39
+ shape: SourceFileShape,
40
+ getTarget(shape, { compiler, project }) {
41
+ const source = shape.getOriginalSource()
42
+ return {
43
+ success: true,
44
+ value: ts.Node.isNode(source)
45
+ ? source
46
+ : compiler.getOrCreateSourceFile(project.resolvePath(shape.getPath())),
47
+ }
48
+ },
49
+ commit(shape, _target, { project }) {
50
+ const file = project.getFileIfExists(shape.getPath())
51
+ if (file) {
52
+ file.setContent(shape.getContent())
53
+ } else {
54
+ project.addFile({ path: shape.getPath(), content: shape.getContent() })
55
+ }
56
+
57
+ return { success: true }
58
+ },
59
+ },
60
+ {
61
+ shape: Shape,
62
+ getTarget(shape, { compiler, project, config }) {
63
+ const source = shape.getOriginalSource()
64
+ if (ts.Node.isNode(source)) {
65
+ return { success: true, value: source }
66
+ }
67
+
68
+ // Avoid creating empty files with undefined shapes or deleted records
69
+ if (shape.isNoOp() || shape.isUndefined() || (shape.isRecord() && shape.isDeleted())) {
70
+ return { success: false }
71
+ }
72
+
73
+ const name = pathModule.basename(source.path).replace(RegExp(`${pathModule.extname(source.path)}$`), '')
74
+ const file = compiler.getOrCreateSourceFile(project.resolvePath(config.generatedDir, `${name}.now.ts`))
75
+ const statement = project
76
+ .addFile(file.getFilePath(), { resolveDependencies: false })
77
+ .addStatement(shape.getCode())
78
+
79
+ return {
80
+ success: true,
81
+ value: statement.isKind(ts.SyntaxKind.ExpressionStatement) ? statement.getExpression() : statement,
82
+ }
83
+ },
84
+ },
37
85
  {
38
86
  shape: DeletedShape,
39
87
  commit(_, target) {
@@ -271,6 +319,11 @@ export const BasicSyntaxPlugin = Plugin.create({
271
319
  shape: VariableStatementShape,
272
320
  async commit(shape, target, { commit }) {
273
321
  if (!ts.Node.isVariableStatement(target)) {
322
+ const parentStatement = target.getParentIfKind(ts.SyntaxKind.ExpressionStatement)
323
+ if (ts.Node.isCallExpression(target) && parentStatement) {
324
+ parentStatement.replaceWithText(shape.getCode())
325
+ return { success: true }
326
+ }
274
327
  target.replaceWithText(shape.getCode())
275
328
  return { success: true }
276
329
  }
@@ -325,7 +378,7 @@ export const BasicSyntaxPlugin = Plugin.create({
325
378
 
326
379
  return {
327
380
  success: true,
328
- value: new SourceFileShape({ file }),
381
+ value: new SourceFileShape({ source: file, path: file.getFilePath(), content: file.getFullText() }),
329
382
  }
330
383
  },
331
384
  },
@@ -2,6 +2,7 @@ import { CallExpressionShape, type ObjectShape, Plugin, type ArrayShape, type Sh
2
2
  import { ModuleFunctionShape } from './server-module-plugin'
3
3
  import { NowIdShape } from './now-id-plugin'
4
4
  import { generateDeprecatedDiagnostics } from './utils'
5
+ import { NowIncludeShape } from './now-include-plugin'
5
6
 
6
7
  // Similar to lodash's groupBy, but simply stores the last element of each group
7
8
  function groupByExistence<T>(collection: T[] | undefined, keyProvider: (element: T) => string): { [key: string]: T } {
@@ -43,7 +44,9 @@ export const BusinessRulePlugin = Plugin.create({
43
44
  name: 'BusinessRulePlugin',
44
45
  records: {
45
46
  sys_script: {
46
- toShape(record) {
47
+ async toShape(record, { transform }) {
48
+ const script = await NowIncludeShape.fromRecord(record, record.get('script'), transform)
49
+
47
50
  return {
48
51
  success: true,
49
52
  value: new CallExpressionShape({
@@ -71,8 +74,8 @@ export const BusinessRulePlugin = Plugin.create({
71
74
  roleConditions: $.from('role_conditions').map((v) =>
72
75
  v.ifString()?.ifNotEmpty()?.getValue().split(',')
73
76
  ),
74
- script: $.def(DEFAULT_SCRIPT),
75
- priority: $.map((p) => p.ifNumber()?.asNumber()).def(100),
77
+ script: $.val(script).def(DEFAULT_SCRIPT),
78
+ priority: $.map((p) => p.ifString()?.ifNotEmpty()?.toNumber()).def(100),
76
79
 
77
80
  changeFields: $.from('change_fields').toBoolean().def(false),
78
81
  clientCallable: $.from('client_callable').toBoolean().def(false),
@@ -131,89 +134,87 @@ export const BusinessRulePlugin = Plugin.create({
131
134
  return { success: false }
132
135
  }
133
136
 
134
- const arg = callExpression.getArgument(0).asObject().withAliasedKeys(brAliases)
135
- const rest = arg.get('rest').ifDefined()?.asObject()
137
+ const br = callExpression.getArgument(0).asObject().withAliasedKeys(brAliases)
138
+ const rest = br.get('rest').ifDefined()?.asObject()
136
139
 
137
- generateDeprecatedDiagnostics(arg, diagnostics)
140
+ generateDeprecatedDiagnostics(br, diagnostics)
138
141
 
139
- if (arg.get('script').isUnresolved()) {
142
+ if (br.get('script').isUnresolved()) {
140
143
  diagnostics.error(
141
- arg.get('script').getOriginalNode(),
144
+ br.get('script').getOriginalNode(),
142
145
  `Unable to resolve the script reference, ensure the imported module is within the ${config.serverModulesDir} directory.`
143
146
  )
144
147
  }
145
148
 
146
149
  return {
147
150
  success: true,
148
- value: arg.pipe((br) =>
149
- factory.createRecord({
150
- source: callExpression,
151
- table: 'sys_script',
152
- explicitId: br.get('$id'),
153
- properties: br.transform(({ $, merge }) => ({
154
- name: $,
155
- order: $.def(100),
156
- active: $.def(true),
157
- message: $,
158
- add_message: $.from('addMessage').map((v) => {
159
- return (
160
- v.ifBoolean()?.getValue() ??
161
- (($._('message').val as Shape).getValue() !== undefined ? true : false)
162
- )
163
- }),
164
- condition: $,
165
- filter_condition: $.from('filterCondition'),
166
- description: $,
167
- advanced: $.val(
168
- br
169
- .get('script')
170
- .pipe((script) => script.isDefined() && script.getValue() !== DEFAULT_SCRIPT)
171
- ),
172
- script: $.map(
173
- (v) =>
174
- v
175
- .if(ModuleFunctionShape)
176
- ?.toString((n) => `${n}({{PARAMS}})`, ['current', 'previous']) ?? v
151
+ value: await factory.createRecord({
152
+ source: callExpression,
153
+ table: 'sys_script',
154
+ explicitId: br.get('$id'),
155
+ properties: br.transform(({ $, merge }) => ({
156
+ name: $,
157
+ order: $.def(100),
158
+ active: $.def(true),
159
+ message: $,
160
+ add_message: $.from('addMessage').map((v) => {
161
+ return (
162
+ v.ifBoolean()?.getValue() ??
163
+ (($._('message').val as Shape).getValue() !== undefined ? true : false)
164
+ )
165
+ }),
166
+ condition: $,
167
+ filter_condition: $.from('filterCondition'),
168
+ description: $,
169
+ advanced: $.val(
170
+ br
171
+ .get('script')
172
+ .pipe((script) => script.isDefined() && script.getValue() !== DEFAULT_SCRIPT)
173
+ ),
174
+ script: $.map(
175
+ (v) =>
176
+ v
177
+ .if(ModuleFunctionShape)
178
+ ?.toString((n) => `${n}({{PARAMS}})`, ['current', 'previous']) ?? v
179
+ )
180
+ .toCdata()
181
+ .def(DEFAULT_SCRIPT),
182
+ collection: $.from('table'),
183
+ when: $.map((v) => (v.ifString() ? whenBidiMap.get(v.asString().getValue()) : v)).def(
184
+ 'before'
185
+ ),
186
+ [merge]: $.from('action').map((v) => {
187
+ const { insertAction, updateAction, deleteAction, queryAction } = groupByExistence(
188
+ v.ifArray()?.getElements(),
189
+ (action) => `${action.asString().getValue()}Action`
177
190
  )
178
- .toCdata()
179
- .def(DEFAULT_SCRIPT),
180
- collection: $.from('table'),
181
- when: $.map((v) => (v.ifString() ? whenBidiMap.get(v.asString().getValue()) : v)).def(
182
- 'before'
183
- ),
184
- [merge]: $.from('action').map((v) => {
185
- const { insertAction, updateAction, deleteAction, queryAction } = groupByExistence(
186
- v.ifArray()?.getElements(),
187
- (action) => `${action.asString().getValue()}Action`
188
- )
189
191
 
190
- return {
191
- action_insert: !!insertAction,
192
- action_update: !!updateAction,
193
- action_query: !!queryAction,
194
- action_delete: !!deleteAction,
195
- }
196
- }),
197
- template: $.from('setFieldValue'),
198
- role_conditions: $.from('roleConditions').map((v) => getRolesString(v.ifArray())),
199
- abort_action: $.from('abortAction').def(false),
200
- priority: $.def(100),
192
+ return {
193
+ action_insert: !!insertAction,
194
+ action_update: !!updateAction,
195
+ action_query: !!queryAction,
196
+ action_delete: !!deleteAction,
197
+ }
198
+ }),
199
+ template: $.from('setFieldValue'),
200
+ role_conditions: $.from('roleConditions').map((v) => getRolesString(v.ifArray())),
201
+ abort_action: $.from('abortAction').def(false),
202
+ priority: $.def(100),
201
203
 
202
- is_rest: $.val(rest?.get('webService')).def(false),
203
- rest_variables: $.val(rest?.get('variables')),
204
- rest_method: $.val(rest?.get('method')),
205
- rest_method_text: $.val(rest?.get('methodText')),
206
- rest_service: $.val(rest?.get('service')),
207
- rest_service_text: $.val(rest?.get('serviceText')),
204
+ is_rest: $.val(rest?.get('webService')).def(false),
205
+ rest_variables: $.val(rest?.get('variables')),
206
+ rest_method: $.val(rest?.get('method')),
207
+ rest_method_text: $.val(rest?.get('methodText')),
208
+ rest_service: $.val(rest?.get('service')),
209
+ rest_service_text: $.val(rest?.get('serviceText')),
208
210
 
209
- change_fields: $.from('changeFields').def(false),
210
- client_callable: $.from('clientCallable').def(false),
211
- execute_function: $.from('executeFunction').def(false),
212
- access: $.def('package_private'),
213
- sys_policy: $.from('protectionPolicy'),
214
- })),
215
- })
216
- ),
211
+ change_fields: $.from('changeFields').def(false),
212
+ client_callable: $.from('clientCallable').def(false),
213
+ execute_function: $.from('executeFunction').def(false),
214
+ access: $.def('package_private'),
215
+ sys_policy: $.from('protectionPolicy'),
216
+ })),
217
+ }),
217
218
  }
218
219
  },
219
220
  },