@servicenow/sdk-build-core 3.0.2 → 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 -77
  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 -92
  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
package/dist/app.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { FileSystem } from './fs';
2
+ import type { NowConfig } from './now-config';
3
+ import type { PackageJson } from 'type-fest';
4
+ export type App = {
5
+ /**
6
+ * The parsed package.json
7
+ */
8
+ package: Package;
9
+ /**
10
+ * SDK-specific configuration
11
+ */
12
+ config: NowConfig;
13
+ /**
14
+ * Root directory of the project
15
+ */
16
+ rootDir: string;
17
+ };
18
+ export type Package = PackageJson & {
19
+ name: string;
20
+ version: string;
21
+ now?: NowConfig;
22
+ dependencies?: Record<string, string>;
23
+ devDependencies?: Record<string, string>;
24
+ };
25
+ export declare function parsePackageJson(rootDir: string, fs: FileSystem): Package;
package/dist/app.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePackageJson = parsePackageJson;
4
+ const json_1 = require("./json");
5
+ function parsePackageJson(rootDir, fs) {
6
+ return (0, json_1.readJson)(rootDir, 'package.json', fs);
7
+ }
8
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;AA8BA,4CAEC;AA9BD,iCAAiC;AA4BjC,SAAgB,gBAAgB,CAAC,OAAe,EAAE,EAAc;IAC5D,OAAO,IAAA,eAAQ,EAAC,OAAO,EAAE,cAAc,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { type SupportedNode, ts } from './typescript';
2
+ import { Diagnostic } from './diagnostic';
3
+ import { FileSystem } from './fs';
4
+ import type { Diagnostics } from './plugins/context';
5
+ export type CompilerOptions = ts.CompilerOptions;
6
+ export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
7
+ export declare class Compiler extends ts.Project {
8
+ private readonly fs;
9
+ private readonly rootDir;
10
+ private readonly sourceFileToRelativeModuleSpecifier;
11
+ private readonly generatedTableFilePath;
12
+ private moduleProject;
13
+ constructor(fs: FileSystem, { rootDir, sourceFilePaths, compilerOptions, }?: {
14
+ rootDir?: string;
15
+ sourceFilePaths?: string[];
16
+ compilerOptions?: CompilerOptions;
17
+ });
18
+ addGlobalTableDefinitionFile(): void;
19
+ addGlobalModuleExtensions(): void;
20
+ /**
21
+ * Recursively adds any source files in the specified directory, and returns the added
22
+ * files. Glob patterns can be supplied to control which files are added. This will also
23
+ * resolve the dependencies of the added files. If the directory does not exist, an empty
24
+ * array will be returned.
25
+ */
26
+ addSourceFilesFromDirectory(dir: string, extensions?: string[], ignore_extensions?: string[]): ts.SourceFile[];
27
+ /**
28
+ * Recursively adds any .now.ts files in the specified directory, and returns the added
29
+ * files. Glob patterns can be supplied to control which files are added. This will also
30
+ * resolve the dependencies of the added files. If the directory does not exist, an empty
31
+ * array will be returned.
32
+ */
33
+ addFluentSourceFilesFromDirectory(dir: string): ts.SourceFile[];
34
+ addFluentSourceFilesAtPaths(paths: string[]): ts.SourceFile[];
35
+ getFluentSourceFilesFromDirectory(dir: string): ts.SourceFile[];
36
+ getDiagnosticsForFluentFile(fileOrPath: string | ts.SourceFile): TypeScriptDiagnostic[];
37
+ getOrCreateSourceFile(path: string, options?: ts.SourceFileCreateOptions): ts.SourceFile;
38
+ visitSupportedNodes(node: ts.Node, visitor: (node: SupportedNode) => void | Promise<void>, unsupportedNodeVisitor?: (node: ts.Node) => void | Promise<void>): Promise<void>;
39
+ private getTableSchemaModule;
40
+ private getTableInterface;
41
+ interfaceExistsInGlobalDeclaration(tableName: string): ts.InterfaceDeclaration | undefined;
42
+ propertyExistsInGlobalDeclaration(tableName: string): ts.PropertySignature | undefined;
43
+ importExistsInGlobalDeclaration(resolvedModuleSpecifier: string): ts.ImportDeclaration | undefined;
44
+ getGeneratedTableFile(): ts.SourceFile | undefined;
45
+ addTableInterfacesToGlobalDeclaration(data: {
46
+ interfaces: any;
47
+ properties: any;
48
+ imports: any;
49
+ namedImports: any;
50
+ }): void;
51
+ removeTableInterfaceFromGlobalDeclaration(sourceFile: string | ts.SourceFile): void;
52
+ isGeneratedTableFile(sourceFile: string | ts.SourceFile): boolean;
53
+ private createModuleProject;
54
+ compileModule(moduleFile: ts.SourceFile, fs: FileSystem, diagnostics: Diagnostics, tsConfigPath?: string): string | undefined;
55
+ }
56
+ export declare class TypeScriptDiagnostic extends Diagnostic {
57
+ private readonly diagnostic;
58
+ constructor(diagnostic: ts.Diagnostic);
59
+ asTypeScriptDiagnostic(): ts.ts.Diagnostic;
60
+ }
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeScriptDiagnostic = exports.Compiler = exports.DEFAULT_COMPILER_OPTIONS = void 0;
4
+ const path_1 = require("./path");
5
+ const typescript_1 = require("./typescript");
6
+ const diagnostic_1 = require("./diagnostic");
7
+ const fs_1 = require("./fs");
8
+ const fluent_file_1 = require("./fluent-file");
9
+ exports.DEFAULT_COMPILER_OPTIONS = {
10
+ noEmit: true,
11
+ lib: ['lib.es5.d.ts'],
12
+ target: typescript_1.ts.ScriptTarget.ES2023,
13
+ module: typescript_1.ts.ModuleKind.NodeNext,
14
+ esModuleInterop: true,
15
+ isolatedModules: true,
16
+ allowJs: true,
17
+ checkJs: false,
18
+ strict: true,
19
+ alwaysStrict: true,
20
+ exactOptionalPropertyTypes: true,
21
+ noEmitOnError: true,
22
+ noFallthroughCasesInSwitch: true,
23
+ noImplicitOverride: true,
24
+ noImplicitReturns: true,
25
+ noImplicitThis: true,
26
+ noImplicitAny: false,
27
+ noUncheckedIndexedAccess: true,
28
+ noUnusedLocals: true,
29
+ noUnusedParameters: true,
30
+ noPropertyAccessFromIndexSignature: true,
31
+ forceConsistentCasingInFileNames: true,
32
+ resolveJsonModule: true,
33
+ skipLibCheck: true,
34
+ skipDefaultLibCheck: true,
35
+ allowImportingTsExtensions: true,
36
+ };
37
+ const SUPPORTED_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.cts', '.cjs', '.mts', '.mjs', '.json'];
38
+ const UNSUPPORTED_EXTENSIONS = ['.test.ts', '.test.js', '.d.ts'];
39
+ class Compiler extends typescript_1.ts.Project {
40
+ fs;
41
+ rootDir;
42
+ sourceFileToRelativeModuleSpecifier = {};
43
+ generatedTableFilePath;
44
+ moduleProject;
45
+ constructor(fs, { rootDir = '/', sourceFilePaths = [], compilerOptions = exports.DEFAULT_COMPILER_OPTIONS, } = {}) {
46
+ super({
47
+ compilerOptions,
48
+ fileSystem: new fs_1.TsMorphFileSystemWrapper(fs),
49
+ });
50
+ this.fs = fs;
51
+ this.rootDir = rootDir;
52
+ this.generatedTableFilePath = path_1.path.join(this.rootDir, '$$GENERATED$$_common_table.ts');
53
+ this.addGlobalTableDefinitionFile();
54
+ // TODO: move this somewhere better, it doesn't work when I put the file contents in packages/core/src/global
55
+ this.addGlobalModuleExtensions();
56
+ this.addFluentSourceFilesAtPaths(sourceFilePaths);
57
+ }
58
+ addGlobalTableDefinitionFile() {
59
+ const globalTableDefinitionContent = `
60
+ import '@servicenow/sdk/global'
61
+ import { Table } from '@servicenow/sdk/core'
62
+
63
+ declare global {
64
+ namespace Now {
65
+ namespace Internal {
66
+ namespace TableSchemas {
67
+ }
68
+
69
+ interface Tables {
70
+ }
71
+ }
72
+ }
73
+ }
74
+ `;
75
+ this.createSourceFile(this.generatedTableFilePath, globalTableDefinitionContent, {
76
+ overwrite: true,
77
+ scriptKind: typescript_1.ts.ScriptKind.TS,
78
+ });
79
+ }
80
+ addGlobalModuleExtensions() {
81
+ const globalModuleDefinition = `
82
+ declare module '*.html' {
83
+ const content: string;
84
+ export default content;
85
+ }`;
86
+ this.createSourceFile(path_1.path.join(this.rootDir, '$$GENERATED$$_module_extensions.ts'), globalModuleDefinition, {
87
+ overwrite: true,
88
+ scriptKind: typescript_1.ts.ScriptKind.TS,
89
+ });
90
+ }
91
+ /**
92
+ * Recursively adds any source files in the specified directory, and returns the added
93
+ * files. Glob patterns can be supplied to control which files are added. This will also
94
+ * resolve the dependencies of the added files. If the directory does not exist, an empty
95
+ * array will be returned.
96
+ */
97
+ addSourceFilesFromDirectory(dir, extensions = SUPPORTED_EXTENSIONS, ignore_extensions = UNSUPPORTED_EXTENSIONS) {
98
+ const files = [];
99
+ // Using the filesystem API directly instead of using ts-morph's directory APIs is a
100
+ // workaround for this issue: https://github.com/dsherret/ts-morph/issues/1554
101
+ fs_1.FileSystem.traverseDirectory(this.fs, dir, {
102
+ extensions,
103
+ ignore_extensions,
104
+ visitor: (filePath) => {
105
+ files.push(this.addSourceFileAtPath(filePath));
106
+ },
107
+ });
108
+ return files;
109
+ }
110
+ /**
111
+ * Recursively adds any .now.ts files in the specified directory, and returns the added
112
+ * files. Glob patterns can be supplied to control which files are added. This will also
113
+ * resolve the dependencies of the added files. If the directory does not exist, an empty
114
+ * array will be returned.
115
+ */
116
+ addFluentSourceFilesFromDirectory(dir) {
117
+ return this.addSourceFilesFromDirectory(dir, [fluent_file_1.NOW_FILE_EXTENSION]);
118
+ }
119
+ addFluentSourceFilesAtPaths(paths) {
120
+ return this.addSourceFilesAtPaths(paths).filter((file) => file.getBaseName().endsWith(fluent_file_1.NOW_FILE_EXTENSION));
121
+ }
122
+ getFluentSourceFilesFromDirectory(dir) {
123
+ const directory = this.getDirectoryOrThrow(dir);
124
+ return directory.getDescendantSourceFiles().filter((file) => file.getBaseName().endsWith(fluent_file_1.NOW_FILE_EXTENSION));
125
+ }
126
+ getDiagnosticsForFluentFile(fileOrPath) {
127
+ const file = fileOrPath instanceof typescript_1.ts.SourceFile ? fileOrPath : this.getSourceFileOrThrow(fileOrPath);
128
+ if (!file.getFilePath().endsWith(fluent_file_1.NOW_FILE_EXTENSION)) {
129
+ return [];
130
+ }
131
+ return file
132
+ .getPreEmitDiagnostics()
133
+ .map((diagnostic) => {
134
+ try {
135
+ return new TypeScriptDiagnostic(diagnostic);
136
+ }
137
+ catch (e) {
138
+ return undefined;
139
+ }
140
+ })
141
+ .filter((d) => d);
142
+ }
143
+ getOrCreateSourceFile(path, options) {
144
+ return this.getSourceFile(path) ?? this.createSourceFile(path, '', options);
145
+ }
146
+ async visitSupportedNodes(node, visitor, unsupportedNodeVisitor) {
147
+ if (node.wasForgotten()) {
148
+ return;
149
+ }
150
+ if (!(0, typescript_1.isSupportedNode)(node)) {
151
+ await unsupportedNodeVisitor?.(node);
152
+ return;
153
+ }
154
+ // Surprisingly, forEachChild() is not the same as getChildren().forEach() so we need to
155
+ // collect all the children using forEachChild() and then iterate
156
+ const children = [];
157
+ node.forEachChild((child) => {
158
+ children.push(child);
159
+ });
160
+ for (const child of children) {
161
+ await this.visitSupportedNodes(child, visitor, unsupportedNodeVisitor);
162
+ }
163
+ await visitor(node);
164
+ }
165
+ getTableSchemaModule(sourceFile) {
166
+ return sourceFile?.getModule('global')?.getModule('Now')?.getModule('Internal')?.getModule('TableSchemas');
167
+ }
168
+ getTableInterface(sourceFile) {
169
+ return sourceFile?.getModule('global')?.getModule('Now')?.getModule('Internal')?.getInterface('Tables');
170
+ }
171
+ interfaceExistsInGlobalDeclaration(tableName) {
172
+ const generatedTableFile = this.getSourceFile(this.generatedTableFilePath);
173
+ const tableSchema = this.getTableSchemaModule(generatedTableFile);
174
+ return tableSchema?.getInterfaces().find((value) => value.getName() === tableName);
175
+ }
176
+ propertyExistsInGlobalDeclaration(tableName) {
177
+ const generatedTableFile = this.getSourceFile(this.generatedTableFilePath);
178
+ const tableInterface = this.getTableInterface(generatedTableFile);
179
+ return tableInterface?.getProperties().find((value) => value.getName() === tableName);
180
+ }
181
+ importExistsInGlobalDeclaration(resolvedModuleSpecifier) {
182
+ const generatedTableFile = this.getSourceFile(this.generatedTableFilePath);
183
+ return generatedTableFile
184
+ ?.getImportDeclarations()
185
+ .find((value) => value.getModuleSpecifierValue() === resolvedModuleSpecifier);
186
+ }
187
+ getGeneratedTableFile() {
188
+ return this.getSourceFile(this.generatedTableFilePath);
189
+ }
190
+ addTableInterfacesToGlobalDeclaration(data) {
191
+ const { interfaces, properties, imports, namedImports } = data;
192
+ const generatedTableFile = this.getSourceFile(this.generatedTableFilePath);
193
+ const tableSchema = this.getTableSchemaModule(generatedTableFile);
194
+ const tableInterface = this.getTableInterface(generatedTableFile);
195
+ tableSchema?.addInterfaces(interfaces);
196
+ tableInterface?.addProperties(properties);
197
+ generatedTableFile?.addImportDeclarations(Object.values(imports));
198
+ namedImports.forEach((i) => {
199
+ i.existingImport.addNamedImport({
200
+ name: i.name,
201
+ });
202
+ });
203
+ Object.keys(imports).forEach((filePath) => {
204
+ this.sourceFileToRelativeModuleSpecifier[filePath] = imports[filePath].moduleSpecifier;
205
+ });
206
+ }
207
+ removeTableInterfaceFromGlobalDeclaration(sourceFile) {
208
+ const filePath = sourceFile instanceof typescript_1.ts.SourceFile ? sourceFile.getFilePath() : sourceFile;
209
+ const generatedTableFile = this.getSourceFile(this.generatedTableFilePath);
210
+ const relativeModuleSpecifier = this.sourceFileToRelativeModuleSpecifier[filePath];
211
+ if (relativeModuleSpecifier) {
212
+ const foundDecl = generatedTableFile
213
+ ?.getImportDeclarations()
214
+ .find((v) => v.getModuleSpecifierValue() === relativeModuleSpecifier);
215
+ if (foundDecl) {
216
+ const tables = foundDecl.getNamedImports().map((v) => v.getName());
217
+ const tableSchema = this.getTableSchemaModule(generatedTableFile);
218
+ const tableInterface = this.getTableInterface(generatedTableFile);
219
+ tables.forEach((table) => {
220
+ tableSchema?.getInterface(table)?.remove();
221
+ tableInterface?.getProperty(table)?.remove();
222
+ });
223
+ foundDecl.remove();
224
+ }
225
+ }
226
+ }
227
+ isGeneratedTableFile(sourceFile) {
228
+ const sourcePath = sourceFile instanceof typescript_1.ts.SourceFile ? sourceFile.getFilePath() : sourceFile;
229
+ return this.generatedTableFilePath === sourcePath;
230
+ }
231
+ createModuleProject(fs, tsConfigPath) {
232
+ return new typescript_1.ts.Project({
233
+ fileSystem: new fs_1.TsMorphFileSystemWrapper(fs),
234
+ ...(tsConfigPath
235
+ ? {
236
+ tsConfigFilePath: tsConfigPath,
237
+ // We always want to emit files even if the user config says not to
238
+ compilerOptions: { noEmit: false },
239
+ }
240
+ : {
241
+ compilerOptions: {
242
+ target: typescript_1.ts.ScriptTarget.ES2022,
243
+ module: typescript_1.ts.ModuleKind.ES2022,
244
+ moduleResolution: typescript_1.ts.ModuleResolutionKind.Bundler,
245
+ allowImportingTsExtensions: true,
246
+ declaration: false,
247
+ sourceMap: false,
248
+ skipDefaultLibCheck: true,
249
+ skipLibCheck: true,
250
+ },
251
+ }),
252
+ });
253
+ }
254
+ compileModule(moduleFile, fs, diagnostics, tsConfigPath) {
255
+ if (!this.moduleProject) {
256
+ this.moduleProject = this.createModuleProject(fs, tsConfigPath);
257
+ }
258
+ const modulePath = moduleFile.getFilePath();
259
+ let sourceFile;
260
+ if (tsConfigPath) {
261
+ sourceFile = this.moduleProject.getSourceFile(modulePath);
262
+ if (!sourceFile) {
263
+ diagnostics.error(moduleFile, `${path_1.path} not included in project. Check your tsconfig: ${tsConfigPath}`);
264
+ return undefined;
265
+ }
266
+ }
267
+ else {
268
+ sourceFile = this.moduleProject.createSourceFile(modulePath, moduleFile.getFullText(), {
269
+ overwrite: true,
270
+ scriptKind: typescript_1.ts.ScriptKind.TS,
271
+ });
272
+ }
273
+ sourceFile.getPreEmitDiagnostics().forEach((diagnostic) => {
274
+ try {
275
+ diagnostics.add(new TypeScriptDiagnostic(diagnostic));
276
+ }
277
+ catch (e) {
278
+ //ignore
279
+ }
280
+ });
281
+ const emitResult = sourceFile.getEmitOutput();
282
+ emitResult.getDiagnostics().forEach((d) => {
283
+ try {
284
+ const diagnostic = new TypeScriptDiagnostic(d);
285
+ if (diagnostic.level === diagnostic_1.Diagnostic.Level.Error) {
286
+ diagnostics.add(diagnostic);
287
+ }
288
+ }
289
+ catch (e) {
290
+ //ignore
291
+ }
292
+ });
293
+ const output = emitResult.getOutputFiles()[0];
294
+ if (!output) {
295
+ diagnostics.error(moduleFile, `Failed to get emit output for module: ${modulePath}`);
296
+ }
297
+ return output?.getText();
298
+ }
299
+ }
300
+ exports.Compiler = Compiler;
301
+ class TypeScriptDiagnostic extends diagnostic_1.Diagnostic {
302
+ diagnostic;
303
+ constructor(diagnostic) {
304
+ const message = diagnostic.getMessageText();
305
+ const messageText = typeof message === 'string' ? message : message.getMessageText();
306
+ const start = diagnostic.getStart() ?? 0;
307
+ const end = start + (diagnostic.getLength() ?? 0);
308
+ const file = diagnostic.getSourceFile();
309
+ if (!file) {
310
+ throw new Error(`TypeScript diagnostic does not have a source file (Message: ${messageText})`);
311
+ }
312
+ super(messageText, file, { start, end }, diagnostic.getCode(), 'ts', diagnostic_1.Diagnostic.Level.fromCategory(diagnostic.getCategory()));
313
+ this.diagnostic = diagnostic;
314
+ }
315
+ asTypeScriptDiagnostic() {
316
+ return this.diagnostic.compilerObject;
317
+ }
318
+ }
319
+ exports.TypeScriptDiagnostic = TypeScriptDiagnostic;
320
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,6CAAsE;AACtE,6CAAyC;AACzC,6BAA2D;AAC3D,+CAAkD;AAIrC,QAAA,wBAAwB,GAAoB;IACrD,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,CAAC,cAAc,CAAC;IACrB,MAAM,EAAE,eAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,eAAE,CAAC,UAAU,CAAC,QAAQ;IAC9B,eAAe,EAAE,IAAI;IACrB,eAAe,EAAE,IAAI;IACrB,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,0BAA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AAC,CAC1D,CAAA;QAlBwB,eAAU,GAAV,UAAU,CAAe;IAmBtD,CAAC;IAEe,sBAAsB;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAA;IACzC,CAAC;CACJ;AAzBD,oDAyBC"}
@@ -0,0 +1,7 @@
1
+ import { gzipSync } from 'fflate';
2
+ import { FileSystem } from './fs';
3
+ export declare const unzipAppPackage: (fs: FileSystem, zipPath: string, targetPath: string) => Promise<{
4
+ files: string[];
5
+ }>;
6
+ export declare const zipDirectory: (fs: FileSystem, source: string, destination: string) => Promise<string>;
7
+ export { gzipSync };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gzipSync = exports.zipDirectory = exports.unzipAppPackage = void 0;
4
+ const fflate_1 = require("fflate");
5
+ Object.defineProperty(exports, "gzipSync", { enumerable: true, get: function () { return fflate_1.gzipSync; } });
6
+ const fs_1 = require("./fs");
7
+ const path_1 = require("./path");
8
+ const ZIP_STATUS_FILE = 'status.json';
9
+ const unzipAppPackage = async (fs, zipPath, targetPath) => {
10
+ const zipArrBuf = new Uint8Array(fs.readFileSync(zipPath));
11
+ const unzipResult = (0, fflate_1.unzipSync)(zipArrBuf);
12
+ //remove unnecessary package inventory file if present
13
+ if (unzipResult['package_inventory.csv']) {
14
+ delete unzipResult['package_inventory.csv'];
15
+ }
16
+ // check the status of download operation
17
+ if (ZIP_STATUS_FILE in unzipResult) {
18
+ const response = JSON.parse(Buffer.from(unzipResult[ZIP_STATUS_FILE]).toString('utf8'));
19
+ if (response.status === 'error') {
20
+ throw new Error('Application download failed with error, ' + response.message);
21
+ }
22
+ delete unzipResult[ZIP_STATUS_FILE];
23
+ }
24
+ const files = Object.entries(unzipResult).map(([filePath, data]) => {
25
+ const fullPath = path_1.path.join(targetPath, filePath);
26
+ // Create directories if necessary
27
+ const dir = path_1.path.dirname(fullPath);
28
+ fs_1.FileSystem.ensureDirSync(fs, dir);
29
+ // Write file content to the filesystem
30
+ fs.writeFileSync(fullPath, data);
31
+ return fullPath;
32
+ });
33
+ return { files };
34
+ };
35
+ exports.unzipAppPackage = unzipAppPackage;
36
+ const zipDirectory = async (fs, source, destination) => {
37
+ return new Promise((resolve, reject) => {
38
+ try {
39
+ const z = new fflate_1.Zip();
40
+ const outputStream = fs_1.FileSystem.createWriteStream(fs, destination);
41
+ z.ondata = (err, data, final) => {
42
+ if (err) {
43
+ outputStream.destroy();
44
+ reject(err);
45
+ }
46
+ else {
47
+ outputStream.write(data);
48
+ if (final) {
49
+ outputStream.end();
50
+ }
51
+ }
52
+ };
53
+ outputStream.on('finish', () => {
54
+ resolve(destination);
55
+ });
56
+ outputStream.on('error', (error) => {
57
+ reject(error);
58
+ });
59
+ // Using our own glob for browser compatibility
60
+ const wrappedFs = new fs_1.TsMorphFileSystemWrapper(fs);
61
+ const files = wrappedFs.globSync(['**'], {
62
+ cwd: source,
63
+ });
64
+ for (const file of files) {
65
+ const fp = path_1.path.normalize(file);
66
+ const data = fs.readFileSync(fp);
67
+ const zf = new fflate_1.ZipDeflate(fp.replace(source, ''), { level: 6 });
68
+ z.add(zf);
69
+ zf.push(data, true);
70
+ }
71
+ z.end();
72
+ }
73
+ catch (err) {
74
+ reject(err);
75
+ }
76
+ });
77
+ };
78
+ exports.zipDirectory = zipDirectory;
79
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":";;;AAAA,mCAA6D;AA4FpD,yFA5F4B,iBAAQ,OA4F5B;AA3FjB,6BAA2D;AAC3D,iCAA6B;AAE7B,MAAM,eAAe,GAAG,aAAa,CAAA;AAE9B,MAAM,eAAe,GAAG,KAAK,EAChC,EAAc,EACd,OAAe,EACf,UAAkB,EACU,EAAE;IAC9B,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1D,MA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C,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;gBAC/D,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBACT,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YACvB,CAAC;YAED,CAAC,CAAC,GAAG,EAAE,CAAA;QACX,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,CAAC,GAAG,CAAC,CAAA;QACf,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AA9CY,QAAA,YAAY,gBA8CxB"}
@@ -0,0 +1 @@
1
+ export declare const crypto: Crypto;
package/dist/crypto.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.crypto = void 0;
4
+ // Node 20+ globally available Crypto Module -OR- Browser Crypto Module
5
+ const globalCrypto = globalThis.crypto?.webcrypto || globalThis.crypto;
6
+ // Globally available crypto (Node or Browser) -OR- Node Web Crypto (We can get rid of this in April 2025 after Node 18 is EOL)
7
+ // biome-ignore lint/style/noRestrictedImports: This is where we re-export our version of the module
8
+ exports.crypto = globalCrypto || require('node:crypto').webcrypto;
9
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,MAAM,YAAY,GAAiB,UAAU,CAAC,MAAO,EAAE,SAAS,IAAI,UAAU,CAAC,MAAM,CAAA;AACrF,+HAA+H;AAC/H,oGAAoG;AACvF,QAAA,MAAM,GAAG,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,SAAS,CAAA"}
@@ -0,0 +1,41 @@
1
+ import * as lsp from 'vscode-languageserver';
2
+ import { ts } from './typescript';
3
+ import type { Logger } from './logger';
4
+ type PrintOptions = {
5
+ colors?: boolean;
6
+ noThrow?: boolean;
7
+ };
8
+ export declare abstract class Diagnostic {
9
+ readonly message: string;
10
+ readonly file: ts.SourceFile;
11
+ readonly position: {
12
+ start: number;
13
+ end: number;
14
+ };
15
+ readonly code: ts.SyntaxKind;
16
+ readonly source: 'fluent' | 'ts';
17
+ readonly level: Diagnostic.Level;
18
+ constructor(message: string, file: ts.SourceFile, position: {
19
+ start: number;
20
+ end: number;
21
+ }, code: ts.SyntaxKind, source: 'fluent' | 'ts', level?: Diagnostic.Level);
22
+ abstract asTypeScriptDiagnostic(): ts.ts.Diagnostic;
23
+ asLspDiagnostic(): lsp.Diagnostic;
24
+ getFormattedText(colors?: boolean): string;
25
+ print(logger: Logger, { noThrow, colors }?: PrintOptions): void;
26
+ }
27
+ export declare namespace Diagnostic {
28
+ enum Level {
29
+ Error = 1,
30
+ Warn = 2,
31
+ Info = 3,
32
+ Hint = 4
33
+ }
34
+ namespace Level {
35
+ function fromCategory(category: ts.DiagnosticCategory): Level;
36
+ function toCategory(level: Level): ts.DiagnosticCategory;
37
+ function fromSeverity(severity: lsp.DiagnosticSeverity): Level;
38
+ function toSeverity(level: Level): lsp.DiagnosticSeverity;
39
+ }
40
+ }
41
+ export {};