@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.
- package/dist/acl-plugin.js +23 -16
- package/dist/acl-plugin.js.map +1 -1
- package/dist/application-menu-plugin.js +15 -14
- package/dist/application-menu-plugin.js.map +1 -1
- package/dist/atf/test-plugin.js +37 -34
- package/dist/atf/test-plugin.js.map +1 -1
- package/dist/basic-syntax-plugin.js +50 -1
- package/dist/basic-syntax-plugin.js.map +1 -1
- package/dist/business-rule-plugin.js +12 -10
- package/dist/business-rule-plugin.js.map +1 -1
- package/dist/claims-plugin.d.ts +3 -0
- package/dist/claims-plugin.js +95 -0
- package/dist/claims-plugin.js.map +1 -0
- package/dist/client-script-plugin.js +1 -1
- package/dist/client-script-plugin.js.map +1 -1
- package/dist/column/column-to-record.d.ts +3 -3
- package/dist/column/column-to-record.js +17 -16
- package/dist/column/column-to-record.js.map +1 -1
- package/dist/column-plugin.js +86 -8
- package/dist/column-plugin.js.map +1 -1
- package/dist/cross-scope-privilege-plugin.js +17 -3
- package/dist/cross-scope-privilege-plugin.js.map +1 -1
- package/dist/html-import-plugin.js +8 -1
- package/dist/html-import-plugin.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/json-plugin.d.ts +7 -2
- package/dist/json-plugin.js +28 -12
- package/dist/json-plugin.js.map +1 -1
- package/dist/list-plugin.js +29 -17
- package/dist/list-plugin.js.map +1 -1
- package/dist/now-config-plugin.js +14 -5
- package/dist/now-config-plugin.js.map +1 -1
- package/dist/now-include-plugin.d.ts +6 -7
- package/dist/now-include-plugin.js +59 -26
- package/dist/now-include-plugin.js.map +1 -1
- package/dist/now-ref-plugin.js +1 -1
- package/dist/now-ref-plugin.js.map +1 -1
- package/dist/package-json-plugin.js +5 -7
- package/dist/package-json-plugin.js.map +1 -1
- package/dist/property-plugin.js +1 -1
- package/dist/property-plugin.js.map +1 -1
- package/dist/record-plugin.js +23 -9
- package/dist/record-plugin.js.map +1 -1
- package/dist/repack/index.d.ts +2 -0
- package/dist/repack/index.js +8 -0
- package/dist/repack/index.js.map +1 -1
- package/dist/rest-api-plugin.js +12 -12
- package/dist/rest-api-plugin.js.map +1 -1
- package/dist/role-plugin.js +18 -16
- package/dist/role-plugin.js.map +1 -1
- package/dist/script-action-plugin.js +1 -1
- package/dist/script-action-plugin.js.map +1 -1
- package/dist/script-include-plugin.js +6 -4
- package/dist/script-include-plugin.js.map +1 -1
- package/dist/server-module-plugin/index.d.ts +3 -1
- package/dist/server-module-plugin/index.js +110 -28
- package/dist/server-module-plugin/index.js.map +1 -1
- package/dist/service-portal/angular-provider-plugin.js +3 -3
- package/dist/service-portal/angular-provider-plugin.js.map +1 -1
- package/dist/service-portal/dependency-plugin.js +9 -12
- package/dist/service-portal/dependency-plugin.js.map +1 -1
- package/dist/service-portal/widget-plugin.js +8 -8
- package/dist/service-portal/widget-plugin.js.map +1 -1
- package/dist/static-content-plugin.d.ts +2 -0
- package/dist/static-content-plugin.js +16 -13
- package/dist/static-content-plugin.js.map +1 -1
- package/dist/table-plugin.js +55 -33
- package/dist/table-plugin.js.map +1 -1
- package/dist/ui-action-plugin.js +29 -19
- package/dist/ui-action-plugin.js.map +1 -1
- package/dist/ui-page-plugin.js +6 -3
- package/dist/ui-page-plugin.js.map +1 -1
- package/dist/user-preference-plugin.js +2 -2
- package/dist/user-preference-plugin.js.map +1 -1
- package/package.json +10 -6
- package/src/acl-plugin.ts +31 -27
- package/src/application-menu-plugin.ts +39 -39
- package/src/atf/test-plugin.ts +82 -81
- package/src/basic-syntax-plugin.ts +54 -1
- package/src/business-rule-plugin.ts +74 -73
- package/src/claims-plugin.ts +116 -0
- package/src/client-script-plugin.ts +1 -1
- package/src/column/column-to-record.ts +59 -53
- package/src/column-plugin.ts +93 -8
- package/src/cross-scope-privilege-plugin.ts +18 -3
- package/src/html-import-plugin.ts +12 -2
- package/src/index.ts +2 -1
- package/src/json-plugin.ts +35 -15
- package/src/list-plugin.ts +39 -30
- package/src/now-config-plugin.ts +19 -8
- package/src/now-include-plugin.ts +64 -30
- package/src/now-ref-plugin.ts +1 -1
- package/src/package-json-plugin.ts +7 -6
- package/src/property-plugin.ts +1 -1
- package/src/record-plugin.ts +25 -9
- package/src/repack/index.ts +14 -0
- package/src/rest-api-plugin.ts +15 -15
- package/src/role-plugin.ts +15 -15
- package/src/script-action-plugin.ts +1 -1
- package/src/script-include-plugin.ts +7 -4
- package/src/server-module-plugin/index.ts +158 -43
- package/src/service-portal/angular-provider-plugin.ts +12 -10
- package/src/service-portal/dependency-plugin.ts +12 -13
- package/src/service-portal/widget-plugin.ts +36 -30
- package/src/static-content-plugin.ts +12 -10
- package/src/table-plugin.ts +71 -56
- package/src/ui-action-plugin.ts +49 -33
- package/src/ui-page-plugin.ts +6 -3
- 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: $.
|
|
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:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
},
|
package/src/atf/test-plugin.ts
CHANGED
|
@@ -171,15 +171,17 @@ export const TestPlugin = Plugin.create({
|
|
|
171
171
|
coalesce: ['document', 'document_key', 'variable'],
|
|
172
172
|
},
|
|
173
173
|
sys_atf_step: {
|
|
174
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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 =
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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 =
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
135
|
-
const rest =
|
|
137
|
+
const br = callExpression.getArgument(0).asObject().withAliasedKeys(brAliases)
|
|
138
|
+
const rest = br.get('rest').ifDefined()?.asObject()
|
|
136
139
|
|
|
137
|
-
generateDeprecatedDiagnostics(
|
|
140
|
+
generateDeprecatedDiagnostics(br, diagnostics)
|
|
138
141
|
|
|
139
|
-
if (
|
|
142
|
+
if (br.get('script').isUnresolved()) {
|
|
140
143
|
diagnostics.error(
|
|
141
|
-
|
|
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:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
},
|