@servicenow/sdk-build-core 3.0.3 → 4.0.0

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 (252) hide show
  1. package/dist/app.d.ts +25 -0
  2. package/dist/app.js +8 -0
  3. package/dist/app.js.map +1 -0
  4. package/dist/compiler.d.ts +60 -0
  5. package/dist/compiler.js +320 -0
  6. package/dist/compiler.js.map +1 -0
  7. package/dist/compression.d.ts +7 -0
  8. package/dist/compression.js +79 -0
  9. package/dist/compression.js.map +1 -0
  10. package/dist/crypto.d.ts +1 -0
  11. package/dist/crypto.js +9 -0
  12. package/dist/crypto.js.map +1 -0
  13. package/dist/diagnostic.d.ts +41 -0
  14. package/dist/diagnostic.js +130 -0
  15. package/dist/diagnostic.js.map +1 -0
  16. package/dist/{plugins/Diagnostic.d.ts → fluent-diagnostic.d.ts} +3 -2
  17. package/dist/fluent-diagnostic.js +23 -0
  18. package/dist/fluent-diagnostic.js.map +1 -0
  19. package/dist/fluent-directive.d.ts +8 -0
  20. package/dist/fluent-directive.js +54 -0
  21. package/dist/fluent-directive.js.map +1 -0
  22. package/dist/fluent-file.d.ts +5 -0
  23. package/dist/fluent-file.js +15 -0
  24. package/dist/fluent-file.js.map +1 -0
  25. package/dist/formatter.d.ts +11 -0
  26. package/dist/formatter.js +77 -0
  27. package/dist/formatter.js.map +1 -0
  28. package/dist/fs.d.ts +174 -0
  29. package/dist/fs.js +313 -0
  30. package/dist/fs.js.map +1 -0
  31. package/dist/guid.d.ts +2 -0
  32. package/dist/{GUID.js → guid.js} +3 -6
  33. package/dist/guid.js.map +1 -0
  34. package/dist/index.d.ts +19 -5
  35. package/dist/index.js +19 -5
  36. package/dist/index.js.map +1 -1
  37. package/dist/json.d.ts +5 -0
  38. package/dist/json.js +43 -0
  39. package/dist/json.js.map +1 -0
  40. package/dist/keys-registry.d.ts +64 -0
  41. package/dist/keys-registry.js +339 -0
  42. package/dist/keys-registry.js.map +1 -0
  43. package/dist/logger.d.ts +8 -0
  44. package/dist/logger.js +17 -0
  45. package/dist/logger.js.map +1 -0
  46. package/dist/now-config.d.ts +348 -0
  47. package/dist/now-config.js +283 -0
  48. package/dist/now-config.js.map +1 -0
  49. package/dist/path.d.ts +3 -0
  50. package/dist/path.js +12 -0
  51. package/dist/path.js.map +1 -0
  52. package/dist/plugins/cache.d.ts +20 -0
  53. package/dist/plugins/cache.js +46 -0
  54. package/dist/plugins/cache.js.map +1 -0
  55. package/dist/plugins/context.d.ts +85 -0
  56. package/dist/plugins/{Context.js → context.js} +1 -1
  57. package/dist/plugins/context.js.map +1 -0
  58. package/dist/plugins/database.d.ts +27 -0
  59. package/dist/plugins/database.js +102 -0
  60. package/dist/plugins/database.js.map +1 -0
  61. package/dist/plugins/file.d.ts +10 -0
  62. package/dist/plugins/{behaviors/Arranger.js → file.js} +1 -1
  63. package/dist/plugins/file.js.map +1 -0
  64. package/dist/plugins/index.d.ts +9 -5
  65. package/dist/plugins/index.js +9 -6
  66. package/dist/plugins/index.js.map +1 -1
  67. package/dist/plugins/plugin.d.ts +478 -0
  68. package/dist/plugins/plugin.js +533 -0
  69. package/dist/plugins/plugin.js.map +1 -0
  70. package/dist/plugins/product.d.ts +15 -0
  71. package/dist/plugins/product.js +38 -0
  72. package/dist/plugins/product.js.map +1 -0
  73. package/dist/plugins/project.d.ts +25 -0
  74. package/dist/plugins/{behaviors/Generator.js → project.js} +1 -1
  75. package/dist/plugins/project.js.map +1 -0
  76. package/dist/plugins/shape.d.ts +424 -0
  77. package/dist/plugins/shape.js +1181 -0
  78. package/dist/plugins/shape.js.map +1 -0
  79. package/dist/plugins/time.d.ts +12 -0
  80. package/dist/plugins/time.js +84 -0
  81. package/dist/plugins/time.js.map +1 -0
  82. package/dist/plugins/usage.d.ts +11 -0
  83. package/dist/plugins/usage.js +26 -0
  84. package/dist/plugins/usage.js.map +1 -0
  85. package/dist/prettier/config-loader.d.ts +13 -0
  86. package/dist/prettier/config-loader.js +105 -0
  87. package/dist/prettier/config-loader.js.map +1 -0
  88. package/dist/telemetry/index.d.ts +25 -0
  89. package/dist/telemetry/index.js +18 -0
  90. package/dist/telemetry/index.js.map +1 -0
  91. package/dist/typescript.d.ts +293 -0
  92. package/dist/typescript.js +454 -0
  93. package/dist/typescript.js.map +1 -0
  94. package/dist/util/get-file-type.d.ts +2 -0
  95. package/dist/util/get-file-type.js +13 -0
  96. package/dist/util/get-file-type.js.map +1 -0
  97. package/dist/util/index.d.ts +2 -6
  98. package/dist/util/index.js +2 -6
  99. package/dist/util/index.js.map +1 -1
  100. package/dist/util/{Scope.js → is-sn-scope.js} +1 -1
  101. package/dist/util/is-sn-scope.js.map +1 -0
  102. package/dist/xml.d.ts +24 -0
  103. package/dist/xml.js +71 -0
  104. package/dist/xml.js.map +1 -0
  105. package/now.config.schema.json +336 -0
  106. package/package.json +22 -12
  107. package/src/app.ts +33 -0
  108. package/src/compiler.ts +384 -0
  109. package/src/compression.ts +93 -0
  110. package/src/crypto.ts +5 -0
  111. package/src/diagnostic.ts +108 -0
  112. package/src/{plugins/Diagnostic.ts → fluent-diagnostic.ts} +3 -10
  113. package/src/fluent-directive.ts +63 -0
  114. package/src/fluent-file.ts +13 -0
  115. package/src/formatter.ts +58 -0
  116. package/src/fs.ts +438 -0
  117. package/src/{GUID.ts → guid.ts} +2 -6
  118. package/src/index.ts +19 -5
  119. package/src/json.ts +20 -0
  120. package/src/keys-registry.ts +384 -0
  121. package/src/logger.ts +20 -0
  122. package/src/now-config.ts +337 -0
  123. package/src/path.ts +9 -0
  124. package/src/plugins/cache.ts +45 -0
  125. package/src/plugins/context.ts +93 -0
  126. package/src/plugins/database.ts +121 -0
  127. package/src/plugins/file.ts +19 -0
  128. package/src/plugins/index.ts +9 -5
  129. package/src/plugins/plugin.ts +995 -0
  130. package/src/plugins/product.ts +44 -0
  131. package/src/plugins/project.ts +39 -0
  132. package/src/plugins/shape.ts +1532 -0
  133. package/src/plugins/time.ts +108 -0
  134. package/src/plugins/usage.ts +26 -0
  135. package/src/prettier/config-loader.ts +130 -0
  136. package/src/telemetry/index.ts +27 -0
  137. package/src/typescript.ts +502 -0
  138. package/src/util/get-file-type.ts +11 -0
  139. package/src/util/index.ts +2 -6
  140. package/src/xml.ts +86 -0
  141. package/dist/GUID.d.ts +0 -2
  142. package/dist/GUID.js.map +0 -1
  143. package/dist/IncludePaths.d.ts +0 -25
  144. package/dist/IncludePaths.js +0 -97
  145. package/dist/IncludePaths.js.map +0 -1
  146. package/dist/Keys.d.ts +0 -32
  147. package/dist/Keys.js +0 -245
  148. package/dist/Keys.js.map +0 -1
  149. package/dist/TypeScript.d.ts +0 -5
  150. package/dist/TypeScript.js +0 -58
  151. package/dist/TypeScript.js.map +0 -1
  152. package/dist/XML.d.ts +0 -32
  153. package/dist/XML.js +0 -83
  154. package/dist/XML.js.map +0 -1
  155. package/dist/plugins/Context.d.ts +0 -190
  156. package/dist/plugins/Context.js.map +0 -1
  157. package/dist/plugins/Diagnostic.js +0 -28
  158. package/dist/plugins/Diagnostic.js.map +0 -1
  159. package/dist/plugins/Plugin.d.ts +0 -175
  160. package/dist/plugins/Plugin.js +0 -15
  161. package/dist/plugins/Plugin.js.map +0 -1
  162. package/dist/plugins/behaviors/Arranger.d.ts +0 -26
  163. package/dist/plugins/behaviors/Arranger.js.map +0 -1
  164. package/dist/plugins/behaviors/Composer.d.ts +0 -102
  165. package/dist/plugins/behaviors/Composer.js +0 -15
  166. package/dist/plugins/behaviors/Composer.js.map +0 -1
  167. package/dist/plugins/behaviors/Diagnostics.d.ts +0 -7
  168. package/dist/plugins/behaviors/Diagnostics.js +0 -3
  169. package/dist/plugins/behaviors/Diagnostics.js.map +0 -1
  170. package/dist/plugins/behaviors/Generator.d.ts +0 -21
  171. package/dist/plugins/behaviors/Generator.js.map +0 -1
  172. package/dist/plugins/behaviors/OwnedTables.d.ts +0 -6
  173. package/dist/plugins/behaviors/OwnedTables.js +0 -3
  174. package/dist/plugins/behaviors/OwnedTables.js.map +0 -1
  175. package/dist/plugins/behaviors/PostProcessor.d.ts +0 -5
  176. package/dist/plugins/behaviors/PostProcessor.js +0 -3
  177. package/dist/plugins/behaviors/PostProcessor.js.map +0 -1
  178. package/dist/plugins/behaviors/Serializer.d.ts +0 -30
  179. package/dist/plugins/behaviors/Serializer.js +0 -3
  180. package/dist/plugins/behaviors/Serializer.js.map +0 -1
  181. package/dist/plugins/behaviors/Transformer.d.ts +0 -23
  182. package/dist/plugins/behaviors/Transformer.js +0 -3
  183. package/dist/plugins/behaviors/Transformer.js.map +0 -1
  184. package/dist/plugins/behaviors/extractors/Data.d.ts +0 -119
  185. package/dist/plugins/behaviors/extractors/Data.js +0 -244
  186. package/dist/plugins/behaviors/extractors/Data.js.map +0 -1
  187. package/dist/plugins/behaviors/extractors/Extractors.d.ts +0 -63
  188. package/dist/plugins/behaviors/extractors/Extractors.js +0 -3
  189. package/dist/plugins/behaviors/extractors/Extractors.js.map +0 -1
  190. package/dist/plugins/behaviors/extractors/index.d.ts +0 -2
  191. package/dist/plugins/behaviors/extractors/index.js +0 -19
  192. package/dist/plugins/behaviors/extractors/index.js.map +0 -1
  193. package/dist/plugins/behaviors/index.d.ts +0 -9
  194. package/dist/plugins/behaviors/index.js +0 -26
  195. package/dist/plugins/behaviors/index.js.map +0 -1
  196. package/dist/plugins/util/CallExpression.d.ts +0 -5
  197. package/dist/plugins/util/CallExpression.js +0 -88
  198. package/dist/plugins/util/CallExpression.js.map +0 -1
  199. package/dist/plugins/util/CodeTransformation.d.ts +0 -95
  200. package/dist/plugins/util/CodeTransformation.js +0 -624
  201. package/dist/plugins/util/CodeTransformation.js.map +0 -1
  202. package/dist/plugins/util/ObjectLiteral.d.ts +0 -9
  203. package/dist/plugins/util/ObjectLiteral.js +0 -37
  204. package/dist/plugins/util/ObjectLiteral.js.map +0 -1
  205. package/dist/plugins/util/index.d.ts +0 -3
  206. package/dist/plugins/util/index.js +0 -20
  207. package/dist/plugins/util/index.js.map +0 -1
  208. package/dist/util/Debug.d.ts +0 -4
  209. package/dist/util/Debug.js +0 -20
  210. package/dist/util/Debug.js.map +0 -1
  211. package/dist/util/Directive.d.ts +0 -16
  212. package/dist/util/Directive.js +0 -107
  213. package/dist/util/Directive.js.map +0 -1
  214. package/dist/util/RuntimeTableSchema.d.ts +0 -5
  215. package/dist/util/RuntimeTableSchema.js +0 -58
  216. package/dist/util/RuntimeTableSchema.js.map +0 -1
  217. package/dist/util/Scope.js.map +0 -1
  218. package/dist/util/Util.d.ts +0 -1
  219. package/dist/util/Util.js +0 -12
  220. package/dist/util/Util.js.map +0 -1
  221. package/dist/util/XMLUploadParser.d.ts +0 -22
  222. package/dist/util/XMLUploadParser.js +0 -67
  223. package/dist/util/XMLUploadParser.js.map +0 -1
  224. package/src/IncludePaths.ts +0 -122
  225. package/src/Keys.ts +0 -274
  226. package/src/TypeScript.ts +0 -65
  227. package/src/XML.ts +0 -98
  228. package/src/plugins/Context.ts +0 -239
  229. package/src/plugins/Plugin.ts +0 -278
  230. package/src/plugins/behaviors/Arranger.ts +0 -42
  231. package/src/plugins/behaviors/Composer.ts +0 -125
  232. package/src/plugins/behaviors/Diagnostics.ts +0 -12
  233. package/src/plugins/behaviors/Generator.ts +0 -31
  234. package/src/plugins/behaviors/OwnedTables.ts +0 -5
  235. package/src/plugins/behaviors/PostProcessor.ts +0 -6
  236. package/src/plugins/behaviors/Serializer.ts +0 -40
  237. package/src/plugins/behaviors/Transformer.ts +0 -32
  238. package/src/plugins/behaviors/extractors/Data.ts +0 -332
  239. package/src/plugins/behaviors/extractors/Extractors.ts +0 -73
  240. package/src/plugins/behaviors/extractors/index.ts +0 -2
  241. package/src/plugins/behaviors/index.ts +0 -9
  242. package/src/plugins/util/CallExpression.ts +0 -110
  243. package/src/plugins/util/CodeTransformation.ts +0 -731
  244. package/src/plugins/util/ObjectLiteral.ts +0 -37
  245. package/src/plugins/util/index.ts +0 -3
  246. package/src/util/Debug.ts +0 -24
  247. package/src/util/Directive.ts +0 -123
  248. package/src/util/RuntimeTableSchema.ts +0 -44
  249. package/src/util/Util.ts +0 -7
  250. package/src/util/XMLUploadParser.ts +0 -90
  251. /package/dist/util/{Scope.d.ts → is-sn-scope.d.ts} +0 -0
  252. /package/src/util/{Scope.ts → is-sn-scope.ts} +0 -0
@@ -0,0 +1,502 @@
1
+ /**
2
+ * For some reason ts-morph.d.ts doesn't export these types even though they are actually
3
+ * exported by the runtime library, so we are declaring them here
4
+ *
5
+ * @version 23.0.0
6
+ */
7
+ declare module 'ts-morph' {
8
+ abstract class BaseError extends Error {
9
+ protected constructor()
10
+ }
11
+
12
+ class PathNotFoundError extends BaseError {
13
+ readonly path: string
14
+ constructor(path: string, prefix?: string)
15
+ readonly code: 'ENOENT'
16
+ }
17
+
18
+ class FileNotFoundError extends Error {
19
+ constructor(filePath: string)
20
+ }
21
+
22
+ class DirectoryNotFoundError extends Error {
23
+ constructor(dirPath: string)
24
+ }
25
+ }
26
+
27
+ // biome-ignore lint/style/noRestrictedImports: This is where our re-export comes from
28
+ import * as ts from 'ts-morph'
29
+ // biome-ignore lint/style/noRestrictedImports: This is where our re-export comes from
30
+ import { ts as tsc } from 'ts-morph'
31
+
32
+ export { ts, tsc }
33
+
34
+ export function getValueDeclaration(node: ts.Node) {
35
+ const symbol = node.getSymbol()
36
+ if (!symbol) {
37
+ return undefined
38
+ }
39
+
40
+ // Obtain the declaration for the symbol (possibly undefined)
41
+ const valueDeclaration = getValueDeclarationFromSymbolOrAlias(symbol)
42
+
43
+ // Guard against TypeScript erroneously resolving a property access like `data.some` to
44
+ // the *PropertyAccessExpression* itself. When that happens `getValueDeclaration()` is
45
+ // called on the identifier `some` and we get back its parent `PropertyAccessExpression`
46
+ // whose `.getNameNode()` is the same identifier. Returning that node causes infinite
47
+ // recursion (`Identifier → PropertyAccessExpression → Identifier …`) and eventually
48
+ // crashes. Since there's no useful way to handle that scenario, we just bail out here.
49
+ if (
50
+ valueDeclaration &&
51
+ (valueDeclaration === node ||
52
+ (ts.Node.isPropertyAccessExpression(valueDeclaration) &&
53
+ (valueDeclaration.getNameNode() === node || valueDeclaration.getExpression() === node)))
54
+ ) {
55
+ return undefined
56
+ }
57
+
58
+ if (!ts.Node.isShorthandPropertyAssignment(valueDeclaration)) {
59
+ return valueDeclaration
60
+ }
61
+
62
+ const valueSymbol = valueDeclaration.getValueSymbol()
63
+ if (!valueSymbol) {
64
+ throw `Expected value declaration for shorthand property assignment to have value symbol: ${valueDeclaration.getText()}`
65
+ }
66
+
67
+ return getValueDeclarationFromSymbolOrAlias(valueSymbol)
68
+ }
69
+
70
+ function getValueDeclarationFromSymbolOrAlias(symbol: ts.Symbol) {
71
+ return symbol.getValueDeclaration() ?? symbol.getAliasedSymbol()?.getValueDeclaration()
72
+ }
73
+
74
+ export function parseType(
75
+ type: ts.Type,
76
+ location: ts.Node,
77
+ unparsableTypeHandler: (unparsableType: ts.Type) => unknown = (unparsableType) => {
78
+ throw `Unparsable type: ${unparsableType.getText()}`
79
+ }
80
+ ): unknown {
81
+ if (type.isBooleanLiteral()) {
82
+ return type.getText() === 'true'
83
+ } else if (type.isLiteral()) {
84
+ return type.getLiteralValueOrThrow()
85
+ } else if (type.isTuple()) {
86
+ return type.getTupleElements().map((e) => parseType(e, location, unparsableTypeHandler))
87
+ } else if (type.isObject() && !type.isArray()) {
88
+ return type.getProperties().reduce((result, property) => {
89
+ result[property.getName()] = parseType(
90
+ property.getTypeAtLocation(location),
91
+ location,
92
+ unparsableTypeHandler
93
+ )
94
+ return result
95
+ }, {})
96
+ } else {
97
+ return unparsableTypeHandler(type)
98
+ }
99
+ }
100
+
101
+ /**
102
+ * A lot of the extra information here only exists because TypeScript doesn't
103
+ * export a union containing all the different node types, so you can't narrow
104
+ * a node's type by its kind. Narrowing based on kind is very useful for plugins
105
+ * since you can define a property using a kind name and the type of the 'node'
106
+ * argument can be inferred instead of every plugin needing to cast it manually.
107
+ * If you find yourself needing to parse any node kinds that aren't on this list,
108
+ * please add them here.
109
+ *
110
+ * See: https://github.com/microsoft/TypeScript/issues/13634
111
+ */
112
+ export const SupportedKinds = {
113
+ [ts.SyntaxKind.TypeAliasDeclaration]: {
114
+ name: 'TypeAliasDeclaration',
115
+ node: {} as ts.TypeAliasDeclaration,
116
+ },
117
+ [ts.SyntaxKind.TypeReference]: {
118
+ name: 'TypeReference',
119
+ node: {} as ts.TypeReferenceNode,
120
+ },
121
+ [ts.SyntaxKind.TypeLiteral]: {
122
+ name: 'TypeLiteral',
123
+ node: {} as ts.TypeLiteralNode,
124
+ },
125
+ [ts.SyntaxKind.PropertySignature]: {
126
+ name: 'PropertySignature',
127
+ node: {} as ts.PropertySignature,
128
+ },
129
+ [ts.SyntaxKind.TupleType]: {
130
+ name: 'TupleType',
131
+ node: {} as ts.TupleTypeNode,
132
+ },
133
+ [ts.SyntaxKind.BinaryExpression]: {
134
+ name: 'BinaryExpression',
135
+ node: {} as ts.BinaryExpression,
136
+ },
137
+ [ts.SyntaxKind.FunctionExpression]: {
138
+ name: 'FunctionExpression',
139
+ node: {} as ts.FunctionExpression,
140
+ },
141
+ [ts.SyntaxKind.FunctionDeclaration]: {
142
+ name: 'FunctionDeclaration',
143
+ node: {} as ts.FunctionDeclaration,
144
+ },
145
+ [ts.SyntaxKind.ArrayLiteralExpression]: {
146
+ name: 'ArrayLiteralExpression',
147
+ node: {} as ts.ArrayLiteralExpression,
148
+ },
149
+ [ts.SyntaxKind.CallExpression]: {
150
+ name: 'CallExpression',
151
+ node: {} as ts.CallExpression,
152
+ },
153
+ [ts.SyntaxKind.StringLiteral]: {
154
+ name: 'StringLiteral',
155
+ node: {} as ts.StringLiteral,
156
+ },
157
+ [ts.SyntaxKind.NumericLiteral]: {
158
+ name: 'NumericLiteral',
159
+ node: {} as ts.NumericLiteral,
160
+ },
161
+ [ts.SyntaxKind.TrueKeyword]: {
162
+ name: 'TrueKeyword',
163
+ node: {} as ts.TrueLiteral,
164
+ },
165
+ [ts.SyntaxKind.FalseKeyword]: {
166
+ name: 'FalseKeyword',
167
+ node: {} as ts.FalseLiteral,
168
+ },
169
+ [ts.SyntaxKind.NullKeyword]: {
170
+ name: 'NullKeyword',
171
+ node: {} as ts.NullLiteral,
172
+ },
173
+ [ts.SyntaxKind.Identifier]: {
174
+ name: 'Identifier',
175
+ node: {} as ts.Identifier,
176
+ },
177
+ [ts.SyntaxKind.SourceFile]: {
178
+ name: 'SourceFile',
179
+ node: {} as ts.SourceFile,
180
+ },
181
+ [ts.SyntaxKind.VariableDeclaration]: {
182
+ name: 'VariableDeclaration',
183
+ node: {} as ts.VariableDeclaration,
184
+ },
185
+ [ts.SyntaxKind.ClassDeclaration]: {
186
+ name: 'ClassDeclaration',
187
+ node: {} as ts.ClassDeclaration,
188
+ },
189
+ [ts.SyntaxKind.ExportDeclaration]: {
190
+ name: 'ExportDeclaration',
191
+ node: {} as ts.ExportDeclaration,
192
+ },
193
+ [ts.SyntaxKind.ObjectLiteralExpression]: {
194
+ name: 'ObjectLiteralExpression',
195
+ node: {} as ts.ObjectLiteralExpression,
196
+ },
197
+ [ts.SyntaxKind.AsExpression]: {
198
+ name: 'AsExpression',
199
+ node: {} as ts.AsExpression,
200
+ },
201
+ [ts.SyntaxKind.ComputedPropertyName]: {
202
+ name: 'ComputedPropertyName',
203
+ node: {} as ts.ComputedPropertyName,
204
+ },
205
+ [ts.SyntaxKind.PropertyAssignment]: {
206
+ name: 'PropertyAssignment',
207
+ node: {} as ts.PropertyAssignment,
208
+ },
209
+ [ts.SyntaxKind.PropertyAccessExpression]: {
210
+ name: 'PropertyAccessExpression',
211
+ node: {} as ts.PropertyAccessExpression,
212
+ },
213
+ [ts.SyntaxKind.NoSubstitutionTemplateLiteral]: {
214
+ name: 'NoSubstitutionTemplateLiteral',
215
+ node: {} as ts.NoSubstitutionTemplateLiteral,
216
+ },
217
+ [ts.SyntaxKind.ExpressionStatement]: {
218
+ name: 'ExpressionStatement',
219
+ node: {} as ts.ExpressionStatement,
220
+ },
221
+ [ts.SyntaxKind.TaggedTemplateExpression]: {
222
+ name: 'TaggedTemplateExpression',
223
+ node: {} as ts.TaggedTemplateExpression,
224
+ },
225
+ [ts.SyntaxKind.ExportAssignment]: {
226
+ name: 'ExportAssignment',
227
+ node: {} as ts.ExportAssignment,
228
+ },
229
+ [ts.SyntaxKind.NamedExports]: {
230
+ name: 'NamedExports',
231
+ node: {} as ts.NamedExports,
232
+ },
233
+ [ts.SyntaxKind.ExportSpecifier]: {
234
+ name: 'ExportSpecifier',
235
+ node: {} as ts.ExportSpecifier,
236
+ },
237
+ [ts.SyntaxKind.ElementAccessExpression]: {
238
+ name: 'ElementAccessExpression',
239
+ node: {} as ts.ElementAccessExpression,
240
+ },
241
+ [ts.SyntaxKind.TemplateExpression]: {
242
+ name: 'TemplateExpression',
243
+ node: {} as ts.TemplateExpression,
244
+ },
245
+ [ts.SyntaxKind.ImportClause]: {
246
+ name: 'ImportClause',
247
+ node: {} as ts.ImportClause,
248
+ },
249
+ [ts.SyntaxKind.ImportSpecifier]: {
250
+ name: 'ImportSpecifier',
251
+ node: {} as ts.ImportSpecifier,
252
+ },
253
+ [ts.SyntaxKind.ImportDeclaration]: {
254
+ name: 'ImportDeclaration',
255
+ node: {} as ts.ImportDeclaration,
256
+ },
257
+ [ts.SyntaxKind.NamedImports]: {
258
+ name: 'NamedImports',
259
+ node: {} as ts.NamedImports,
260
+ },
261
+ [ts.SyntaxKind.VariableStatement]: {
262
+ name: 'VariableStatement',
263
+ node: {} as ts.VariableStatement,
264
+ },
265
+ [ts.SyntaxKind.VariableDeclarationList]: {
266
+ name: 'VariableDeclarationList',
267
+ node: {} as ts.VariableDeclarationList,
268
+ },
269
+ [ts.SyntaxKind.PlusToken]: {
270
+ name: 'PlusToken',
271
+ node: {} as ts.Node<tsc.PlusToken>,
272
+ },
273
+ [ts.SyntaxKind.EndOfFileToken]: {
274
+ name: 'EndOfFileToken',
275
+ node: {} as ts.Node<tsc.EndOfFileToken>,
276
+ },
277
+ [ts.SyntaxKind.ExportKeyword]: {
278
+ name: 'ExportKeyword',
279
+ node: {} as ts.Node<tsc.ExportKeyword>,
280
+ },
281
+ [ts.SyntaxKind.AnyKeyword]: {
282
+ name: 'AnyKeyword',
283
+ node: {} as ts.Node<tsc.KeywordTypeNode<tsc.SyntaxKind.AnyKeyword>>,
284
+ },
285
+ [ts.SyntaxKind.ModuleDeclaration]: {
286
+ name: 'ModuleDeclaration',
287
+ node: {} as ts.ModuleDeclaration,
288
+ },
289
+ [ts.SyntaxKind.ModuleBlock]: {
290
+ name: 'ModuleBlock',
291
+ node: {} as ts.ModuleBlock,
292
+ },
293
+ [ts.SyntaxKind.Block]: {
294
+ name: 'Block',
295
+ node: {} as ts.Block,
296
+ },
297
+ [ts.SyntaxKind.Parameter]: {
298
+ name: 'Parameter',
299
+ node: {} as ts.ParameterDeclaration,
300
+ },
301
+ [ts.SyntaxKind.EqualsToken]: {
302
+ name: 'EqualsToken',
303
+ node: {} as ts.Node<tsc.EqualsToken>,
304
+ },
305
+ [ts.SyntaxKind.EqualsGreaterThanToken]: {
306
+ name: 'EqualsGreaterThanToken',
307
+ node: {} as ts.Node<tsc.EqualsGreaterThanToken>,
308
+ },
309
+ [ts.SyntaxKind.ArrowFunction]: {
310
+ name: 'ArrowFunction',
311
+ node: {} as ts.ArrowFunction,
312
+ },
313
+ [ts.SyntaxKind.TemplateHead]: {
314
+ name: 'TemplateHead',
315
+ node: {} as ts.TemplateHead,
316
+ },
317
+ [ts.SyntaxKind.TemplateMiddle]: {
318
+ name: 'TemplateMiddle',
319
+ node: {} as ts.TemplateMiddle,
320
+ },
321
+ [ts.SyntaxKind.TemplateSpan]: {
322
+ name: 'TemplateSpan',
323
+ node: {} as ts.TemplateSpan,
324
+ },
325
+ [ts.SyntaxKind.TemplateTail]: {
326
+ name: 'TemplateTail',
327
+ node: {} as ts.TemplateTail,
328
+ },
329
+ [ts.SyntaxKind.PrefixUnaryExpression]: {
330
+ name: 'PrefixUnaryExpression',
331
+ node: {} as ts.PrefixUnaryExpression,
332
+ },
333
+ } satisfies {
334
+ [K in ts.SyntaxKind]?: {
335
+ name: keyof typeof ts.SyntaxKind
336
+ node: ts.Node<tsc.Node & { kind: K }>
337
+ }
338
+ }
339
+
340
+ export type SupportedKind = keyof typeof SupportedKinds
341
+ export type SupportedKindName = (typeof SupportedKinds)[SupportedKind]['name']
342
+ export type SupportedNode = (typeof SupportedKinds)[SupportedKind]['node']
343
+ export type SupportedNodeByKind<K extends SupportedKind> = (typeof SupportedKinds)[K]['node']
344
+ export type SupportedNodeByKindName<K extends SupportedKindName> = Extract<
345
+ (typeof SupportedKinds)[SupportedKind],
346
+ { name: K }
347
+ >['node']
348
+
349
+ export function isSupportedKind(kind: ts.SyntaxKind): kind is SupportedKind {
350
+ return kind in SupportedKinds
351
+ }
352
+
353
+ export function isSupportedNode(node: ts.Node | undefined): node is SupportedNode {
354
+ return !!node && isSupportedKind(node.getKind())
355
+ }
356
+
357
+ export function getKind(node: SupportedNode): SupportedKind {
358
+ return node.getKind() as SupportedKind
359
+ }
360
+
361
+ export function getKindName(nodeOrKind: SupportedNode | SupportedKind): SupportedKindName {
362
+ const kind: SupportedKind = typeof nodeOrKind === 'object' ? getKind(nodeOrKind) : nodeOrKind
363
+ return SupportedKinds[kind].name
364
+ }
365
+
366
+ export function isUndefined(node: ts.Node): boolean {
367
+ return (
368
+ ts.Node.isUndefinedKeyword(node) ||
369
+ ts.Node.isNullLiteral(node) ||
370
+ (ts.Node.isIdentifier(node) && (node.getText() === 'undefined' || node.getText() === 'null'))
371
+ )
372
+ }
373
+
374
+ export function isOnlyChild(node: ts.Node | undefined): boolean {
375
+ if (!node) {
376
+ return false
377
+ }
378
+
379
+ const parent = node.getParent()
380
+ if (!parent) {
381
+ return true
382
+ }
383
+
384
+ if (ts.Node.isInitializerExpressionGetable(parent) && parent.getInitializer() === node) {
385
+ return true
386
+ }
387
+
388
+ if (ts.Node.hasExpression(parent) && parent.getExpression() === node) {
389
+ return true
390
+ }
391
+
392
+ if (ts.Node.isImportDeclaration(parent) && parent.getImportClause() === node) {
393
+ return true
394
+ }
395
+
396
+ if (ts.Node.isExportSpecifier(parent) && parent.getNameNode() === node) {
397
+ return true
398
+ }
399
+
400
+ const syntaxList = node.getParentSyntaxList()
401
+ if (syntaxList && syntaxList.getChildCount() === 1 && syntaxList.getChildAtIndex(0) === node) {
402
+ return true
403
+ }
404
+
405
+ return parent.getChildCount() === 1 && parent.getChildAtIndex(0) === node
406
+ }
407
+
408
+ type RemovableNode = Extract<SupportedNode, { remove(): void }>
409
+
410
+ export function isRemovable(node: ts.Node | undefined): node is RemovableNode {
411
+ return isSupportedNode(node) && 'remove' in node
412
+ }
413
+
414
+ function buildUnaryChain(node: ts.Node, chain: ts.Node[] = []) {
415
+ chain.push(node)
416
+ return isOnlyChild(node) ? buildUnaryChain(node.getParentOrThrow(), chain) : chain
417
+ }
418
+
419
+ /**
420
+ * Recursively walks up the tree to remove the furthest possible ancestor along a
421
+ * unary chain from this node, or the node itself if that's all we can do. This
422
+ * avoids leaving behind dead code as much as possible.
423
+ *
424
+ * @throws Error if the node cannot be removed
425
+ */
426
+ export function remove(target: ts.Node): void {
427
+ if (target.wasForgotten()) {
428
+ return
429
+ }
430
+
431
+ const chain = buildUnaryChain(target, [])
432
+ for (const node of chain) {
433
+ const parent = node.getParent()
434
+
435
+ // We can remove this node via the parent if it's an element in an array
436
+ if (ts.Node.isArrayLiteralExpression(parent)) {
437
+ for (const [i, e] of parent.getElements().entries()) {
438
+ if (e === node) {
439
+ parent.removeElement(i)
440
+ return
441
+ }
442
+ }
443
+ }
444
+
445
+ // We need to avoid leaving imports without any specifiers (side effect imports)
446
+ if (ts.Node.isImportSpecifier(node) && isOnlyChild(node)) {
447
+ node.getImportDeclaration().remove()
448
+ return
449
+ }
450
+
451
+ if (isRemovable(node)) {
452
+ node.remove()
453
+ return
454
+ }
455
+ }
456
+
457
+ throw new Error(`Unable to remove "${getUnsupportedKindName(target)}" node: ${target.getText()}`)
458
+ }
459
+
460
+ /**
461
+ * Recursively walks up the tree removing references to this node and any ancestors
462
+ * along a unary chain. In other words, if this node is the only child of its parent,
463
+ * we also remove references to the parent, and repeat that process recursively. This
464
+ * avoids leaving behind dead code as much as possible.
465
+ */
466
+ export function removeReferences(target: ts.Node): void {
467
+ const chain = buildUnaryChain(target, [])
468
+ for (const node of chain) {
469
+ if (ts.Node.isReferenceFindable(node)) {
470
+ node.findReferencesAsNodes().forEach(remove)
471
+ }
472
+ }
473
+ }
474
+
475
+ /**
476
+ * This is a hack to get more accurate names for given syntax kinds. TypeScript's
477
+ * `SyntaxKind` enum has a lot of reused numeric values, so when you try to index
478
+ * it with a number, you might get a different name than you expect. For example,
479
+ * `VariableStatement` and `FirstStatement` both have the same numeric value, and
480
+ * you probably never would expect the latter. Thankfully, all the names that you
481
+ * probably never want are towards the end, so this just grabs all the first ones
482
+ * and ignores any duplicates that come after.
483
+ */
484
+ let unsupportedKindNames: globalThis.Record<ts.SyntaxKind, string> | undefined
485
+ export function getUnsupportedKindName(node: ts.Node): string | undefined {
486
+ if (!unsupportedKindNames) {
487
+ unsupportedKindNames = Object.entries(ts.SyntaxKind)
488
+ .filter(([k]) => Number.isNaN(Number(k)))
489
+ .reduce(
490
+ (names, [name, value]) => {
491
+ if (typeof value === 'number' && !names[value]) {
492
+ names[value] = name // Only add if it hasn't been added already
493
+ }
494
+
495
+ return names
496
+ },
497
+ {} as globalThis.Record<ts.SyntaxKind, string>
498
+ )
499
+ }
500
+
501
+ return unsupportedKindNames[node.getKind()]
502
+ }
@@ -0,0 +1,11 @@
1
+ import type { FileType } from '../plugins'
2
+
3
+ export function getFileType(filePath: string): FileType {
4
+ return filePath.endsWith('.now.ts')
5
+ ? 'fluent'
6
+ : filePath.endsWith('.ts') || filePath.endsWith('.js')
7
+ ? 'module'
8
+ : filePath.endsWith('.json') || filePath.endsWith('.jsonc')
9
+ ? 'json'
10
+ : 'unknown'
11
+ }
package/src/util/index.ts CHANGED
@@ -1,6 +1,2 @@
1
- export * from './Debug'
2
- export * from './Util'
3
- export * from './XMLUploadParser'
4
- export * from './Scope'
5
- export * from './Directive'
6
- export * from './RuntimeTableSchema'
1
+ export * from './is-sn-scope'
2
+ export * from './get-file-type'
package/src/xml.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { type Action, Record, RecordId, ResolvableShape, Shape, StringShape } from './plugins'
2
+ import { create } from 'xmlbuilder2'
3
+ import type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'
4
+
5
+ export function unloadBuilder({ scope, scopeId }: { scope: string; scopeId: string }) {
6
+ const xml = create({ version: '1.0' }).ele('record_update')
7
+ const end = () => xml.end({ prettyPrint: true })
8
+
9
+ // Root Builder
10
+ return {
11
+ xml,
12
+ end,
13
+ record: (record: Record) => {
14
+ const rec = recordXml(xml, record.getTable(), record.getId().getValue(), {
15
+ attr: { action: record.getAction() },
16
+ })
17
+ rec.field('sys_scope', scopeId, { display_value: scope })
18
+ // TODO: Add sys_update_name here too
19
+ return rec
20
+ },
21
+ createXML: (tableName: string, id: string | number, action: Action = 'INSERT_OR_UPDATE') => {
22
+ const rec = recordXml(xml, tableName, id, { attr: { action } })
23
+ rec.addSysScope(scope, scopeId)
24
+ return rec
25
+ },
26
+ }
27
+ }
28
+
29
+ export function recordXml(
30
+ xml: XMLBuilder,
31
+ tableName: string,
32
+ id: string | number,
33
+ options: {
34
+ attr?: globalThis.Record<string, string>
35
+ excludeScopeElement?: boolean
36
+ } = {}
37
+ ) {
38
+ const recordXml = xml.ele(tableName, options.attr || { action: 'INSERT_OR_UPDATE' })
39
+ recordXml.ele('sys_id', undefined).txt(`${id}`)
40
+
41
+ // Record Builder
42
+ return {
43
+ field(columnName: string, value: unknown, attributes: globalThis.Record<string, string> = {}) {
44
+ if (value instanceof ResolvableShape) {
45
+ value = value.resolve()
46
+ }
47
+
48
+ if (value instanceof Record) {
49
+ value = value.getId()
50
+ }
51
+
52
+ if (value instanceof RecordId) {
53
+ attributes = { ...attributes, ...serializeKeys(value) }
54
+ }
55
+
56
+ const { stringValue, contentType } =
57
+ value instanceof Shape
58
+ ? value.toString().pipe((s) => ({ stringValue: s.getValue(), contentType: s.getContentType() }))
59
+ : { stringValue: `${value ?? ''}`, contentType: 'plain' }
60
+
61
+ /*
62
+ &nbsp is not a predefined entity for XML, to overcome that the platform uses &amp;nbsp; in XMLs.
63
+ When we transform XML that contains &amp;nbsp; that translates to `&nbsp;`.
64
+ But when fluent generates the XML from source it creates XML with &nbsp; which makes the XML invalid since `nbsp` is not defined.
65
+
66
+ So we are replacing &nbsp; with &amp;nbsp; to ensure the XML is valid.
67
+ */
68
+ const sanitizedValue = stringValue.replaceAll('&nbsp;', '&amp;nbsp;')
69
+
70
+ const element = recordXml.ele(columnName, attributes)
71
+ return contentType === 'plain'
72
+ ? element.txt(sanitizedValue)
73
+ : element.dat(StringShape.escapeCdataTags(sanitizedValue))
74
+ },
75
+ addSysScope(scope: string, scopeId: string) {
76
+ return recordXml.ele('sys_scope', { display_value: scope }).txt(scopeId)
77
+ },
78
+ }
79
+ }
80
+
81
+ function serializeKeys(id: RecordId): globalThis.Record<string, string> | undefined {
82
+ const keys = id.getKeys()
83
+ return keys
84
+ ? Object.fromEntries(Object.entries(keys).map(([k, v]) => [k, v instanceof RecordId ? v.getValue() : v]))
85
+ : undefined
86
+ }
package/dist/GUID.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function GUID(): string;
2
- export declare function isGUID(guid: string | number): guid is string;
package/dist/GUID.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"GUID.js","sourceRoot":"","sources":["../src/GUID.ts"],"names":[],"mappings":";;AAEA,oBAEC;AAKD,wBAMC;AAfD,yDAAgD;AAEhD,SAAgB,IAAI;IAChB,OAAO,oBAAM,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAClD,CAAC;AAED,kDAAkD;AAClD,MAAM,SAAS,GAAG,iBAAiB,CAAA;AAEnC,SAAgB,MAAM,CAAC,IAAqB;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"}
@@ -1,25 +0,0 @@
1
- import { Context } from './plugins';
2
- export type IncludePaths = {
3
- [table: string]: {
4
- fields: {
5
- [field: string]: string;
6
- }[];
7
- };
8
- };
9
- type CustomizedFieldPaths = {
10
- field: string;
11
- path: string;
12
- };
13
- export type CustomizedIncludePathForTable = {
14
- table: string;
15
- guid: string;
16
- fields: CustomizedFieldPaths[];
17
- };
18
- export type CustomizedIncludePaths = {
19
- [table: string]: CustomizedIncludePathForTable[];
20
- };
21
- export declare const DefaultIncludePaths: IncludePaths;
22
- export declare const getIncludePaths: (context: Context) => IncludePaths;
23
- export declare const calculateCustomPathsFromDocs: (context: Context) => CustomizedIncludePaths;
24
- export declare function replaceTemplate(template: string, properties: Record<string, any>): string;
25
- export {};