@servicenow/sdk-build-core 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/BuildOptions.d.ts +50 -0
  2. package/dist/BuildOptions.js +46 -0
  3. package/dist/BuildOptions.js.map +1 -0
  4. package/dist/GUID.d.ts +2 -0
  5. package/dist/GUID.js +48 -0
  6. package/dist/GUID.js.map +1 -0
  7. package/dist/Keys.d.ts +29 -0
  8. package/dist/Keys.js +258 -0
  9. package/dist/Keys.js.map +1 -0
  10. package/dist/TypeScript.d.ts +5 -0
  11. package/dist/TypeScript.js +81 -0
  12. package/dist/TypeScript.js.map +1 -0
  13. package/dist/XML.d.ts +25 -0
  14. package/dist/XML.js +72 -0
  15. package/dist/XML.js.map +1 -0
  16. package/dist/index.d.ts +8 -0
  17. package/dist/index.js +38 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/plugins/Context.d.ts +198 -0
  20. package/dist/plugins/Context.js +3 -0
  21. package/dist/plugins/Context.js.map +1 -0
  22. package/dist/plugins/Diagnostic.d.ts +10 -0
  23. package/dist/plugins/Diagnostic.js +52 -0
  24. package/dist/plugins/Diagnostic.js.map +1 -0
  25. package/dist/plugins/Plugin.d.ts +175 -0
  26. package/dist/plugins/Plugin.js +15 -0
  27. package/dist/plugins/Plugin.js.map +1 -0
  28. package/dist/plugins/behaviors/Arranger.d.ts +26 -0
  29. package/dist/plugins/behaviors/Arranger.js +3 -0
  30. package/dist/plugins/behaviors/Arranger.js.map +1 -0
  31. package/dist/plugins/behaviors/Composer.d.ts +101 -0
  32. package/dist/plugins/behaviors/Composer.js +15 -0
  33. package/dist/plugins/behaviors/Composer.js.map +1 -0
  34. package/dist/plugins/behaviors/Diagnostics.d.ts +8 -0
  35. package/dist/plugins/behaviors/Diagnostics.js +3 -0
  36. package/dist/plugins/behaviors/Diagnostics.js.map +1 -0
  37. package/dist/plugins/behaviors/Generator.d.ts +21 -0
  38. package/dist/plugins/behaviors/Generator.js +3 -0
  39. package/dist/plugins/behaviors/Generator.js.map +1 -0
  40. package/dist/plugins/behaviors/OwnedTables.d.ts +6 -0
  41. package/dist/plugins/behaviors/OwnedTables.js +3 -0
  42. package/dist/plugins/behaviors/OwnedTables.js.map +1 -0
  43. package/dist/plugins/behaviors/PostProcessor.d.ts +5 -0
  44. package/dist/plugins/behaviors/PostProcessor.js +3 -0
  45. package/dist/plugins/behaviors/PostProcessor.js.map +1 -0
  46. package/dist/plugins/behaviors/Serializer.d.ts +29 -0
  47. package/dist/plugins/behaviors/Serializer.js +3 -0
  48. package/dist/plugins/behaviors/Serializer.js.map +1 -0
  49. package/dist/plugins/behaviors/Transformer.d.ts +23 -0
  50. package/dist/plugins/behaviors/Transformer.js +3 -0
  51. package/dist/plugins/behaviors/Transformer.js.map +1 -0
  52. package/dist/plugins/behaviors/extractors/Data.d.ts +107 -0
  53. package/dist/plugins/behaviors/extractors/Data.js +191 -0
  54. package/dist/plugins/behaviors/extractors/Data.js.map +1 -0
  55. package/dist/plugins/behaviors/extractors/Extractors.d.ts +41 -0
  56. package/dist/plugins/behaviors/extractors/Extractors.js +3 -0
  57. package/dist/plugins/behaviors/extractors/Extractors.js.map +1 -0
  58. package/dist/plugins/behaviors/extractors/index.d.ts +2 -0
  59. package/dist/plugins/behaviors/extractors/index.js +19 -0
  60. package/dist/plugins/behaviors/extractors/index.js.map +1 -0
  61. package/dist/plugins/behaviors/index.d.ts +9 -0
  62. package/dist/plugins/behaviors/index.js +26 -0
  63. package/dist/plugins/behaviors/index.js.map +1 -0
  64. package/dist/plugins/index.d.ts +5 -0
  65. package/dist/plugins/index.js +23 -0
  66. package/dist/plugins/index.js.map +1 -0
  67. package/dist/plugins/util/CallExpression.d.ts +6 -0
  68. package/dist/plugins/util/CallExpression.js +93 -0
  69. package/dist/plugins/util/CallExpression.js.map +1 -0
  70. package/dist/plugins/util/CodeTransformation.d.ts +74 -0
  71. package/dist/plugins/util/CodeTransformation.js +421 -0
  72. package/dist/plugins/util/CodeTransformation.js.map +1 -0
  73. package/dist/plugins/util/ConfigurationFunction.d.ts +106 -0
  74. package/dist/plugins/util/ConfigurationFunction.js +377 -0
  75. package/dist/plugins/util/ConfigurationFunction.js.map +1 -0
  76. package/dist/plugins/util/ObjectLiteral.d.ts +9 -0
  77. package/dist/plugins/util/ObjectLiteral.js +60 -0
  78. package/dist/plugins/util/ObjectLiteral.js.map +1 -0
  79. package/dist/plugins/util/index.d.ts +4 -0
  80. package/dist/plugins/util/index.js +21 -0
  81. package/dist/plugins/util/index.js.map +1 -0
  82. package/dist/util/Debug.d.ts +8 -0
  83. package/dist/util/Debug.js +39 -0
  84. package/dist/util/Debug.js.map +1 -0
  85. package/dist/util/Util.d.ts +4 -0
  86. package/dist/util/Util.js +41 -0
  87. package/dist/util/Util.js.map +1 -0
  88. package/dist/util/XMLJsonBuilder.d.ts +18 -0
  89. package/dist/util/XMLJsonBuilder.js +59 -0
  90. package/dist/util/XMLJsonBuilder.js.map +1 -0
  91. package/dist/util/XMLUploadParser.d.ts +22 -0
  92. package/dist/util/XMLUploadParser.js +67 -0
  93. package/dist/util/XMLUploadParser.js.map +1 -0
  94. package/dist/util/index.d.ts +4 -0
  95. package/dist/util/index.js +21 -0
  96. package/dist/util/index.js.map +1 -0
  97. package/license +9 -0
  98. package/package.json +42 -0
  99. package/src/BuildOptions.ts +27 -0
  100. package/src/GUID.ts +26 -0
  101. package/src/Keys.ts +287 -0
  102. package/src/TypeScript.ts +65 -0
  103. package/src/XML.ts +85 -0
  104. package/src/index.ts +8 -0
  105. package/src/plugins/Context.ts +249 -0
  106. package/src/plugins/Diagnostic.ts +31 -0
  107. package/src/plugins/Plugin.ts +246 -0
  108. package/src/plugins/behaviors/Arranger.ts +42 -0
  109. package/src/plugins/behaviors/Composer.ts +124 -0
  110. package/src/plugins/behaviors/Diagnostics.ts +13 -0
  111. package/src/plugins/behaviors/Generator.ts +31 -0
  112. package/src/plugins/behaviors/OwnedTables.ts +5 -0
  113. package/src/plugins/behaviors/PostProcessor.ts +6 -0
  114. package/src/plugins/behaviors/Serializer.ts +39 -0
  115. package/src/plugins/behaviors/Transformer.ts +32 -0
  116. package/src/plugins/behaviors/extractors/Data.ts +247 -0
  117. package/src/plugins/behaviors/extractors/Extractors.ts +57 -0
  118. package/src/plugins/behaviors/extractors/index.ts +2 -0
  119. package/src/plugins/behaviors/index.ts +9 -0
  120. package/src/plugins/index.ts +5 -0
  121. package/src/plugins/util/CallExpression.ts +83 -0
  122. package/src/plugins/util/CodeTransformation.ts +500 -0
  123. package/src/plugins/util/ConfigurationFunction.ts +477 -0
  124. package/src/plugins/util/ObjectLiteral.ts +37 -0
  125. package/src/plugins/util/index.ts +4 -0
  126. package/src/util/Debug.ts +46 -0
  127. package/src/util/Util.ts +21 -0
  128. package/src/util/XMLJsonBuilder.ts +64 -0
  129. package/src/util/XMLUploadParser.ts +90 -0
  130. package/src/util/index.ts +4 -0
@@ -0,0 +1,8 @@
1
+ export * as ts from 'ts-morph';
2
+ export * from './util';
3
+ export * from './TypeScript';
4
+ export * from './XML';
5
+ export * from './plugins';
6
+ export * from './GUID';
7
+ export * from './Keys';
8
+ export * from './BuildOptions';
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ts = void 0;
30
+ exports.ts = __importStar(require("ts-morph"));
31
+ __exportStar(require("./util"), exports);
32
+ __exportStar(require("./TypeScript"), exports);
33
+ __exportStar(require("./XML"), exports);
34
+ __exportStar(require("./plugins"), exports);
35
+ __exportStar(require("./GUID"), exports);
36
+ __exportStar(require("./Keys"), exports);
37
+ __exportStar(require("./BuildOptions"), exports);
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA8B;AAC9B,yCAAsB;AACtB,+CAA4B;AAC5B,wCAAqB;AACrB,4CAAyB;AACzB,yCAAsB;AACtB,yCAAsB;AACtB,iDAA8B"}
@@ -0,0 +1,198 @@
1
+ import * as ts from 'ts-morph';
2
+ import { Document, File, LinkedDocument, UnlinkedDocument, Xml, XmlData, EntityData, Arranged, DocumentMap, ExtractionResult } from './behaviors';
3
+ import { Keys } from '../Keys';
4
+ import { Plugin } from './Plugin';
5
+ import { FluentDiagnostic } from './Diagnostic';
6
+ import { ProjectContext } from '@servicenow/sdk-project';
7
+ import type { Diagnostic } from '@servicenow/sdk-project';
8
+ import type { Data } from './behaviors';
9
+ /**
10
+ * The context object is a collection of contextual information and methods
11
+ * passed into all the various behaviors of a plugin when those behaviors are
12
+ * invoked. It is also used by the build system to orchestrate the build.
13
+ *
14
+ * Each behavioral method on the context can accept an array of plugins as
15
+ * an argument to control which plugins are used for that request. If no
16
+ * plugins are provided as input, all available plugins will be used.
17
+ */
18
+ export type Context = ProjectContext & {
19
+ /**
20
+ * Accepts a parsed XML object and returns an array of {@linkcode XmlData}
21
+ * extracted from that object.
22
+ *
23
+ * @see {@linkcode Extractors}
24
+ * @param xml The parsed XML to extract.
25
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
26
+ * @returns an array of extracted data.
27
+ */
28
+ extractXml(this: Context, xml: Xml, plugins?: Plugin[]): XmlData[];
29
+ /**
30
+ * Accepts an AST node and returns a result containing an array of
31
+ * {@linkcode RawData} or {@linkcode EntityData} extracted from that node.
32
+ *
33
+ * @see {@linkcode Extractors}
34
+ * @param node The node to extract.
35
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
36
+ * @returns a result object containing an array of extracted data.
37
+ */
38
+ extractAst(this: Context, node: ts.Node, plugins?: Plugin[]): ExtractionResult;
39
+ /**
40
+ * Accepts an AST node and returns a result containing an array of
41
+ * {@linkcode RawData} extracted from that node.
42
+ *
43
+ * @see {@linkcode Extractors}
44
+ * @param node The node to extract.
45
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
46
+ * @returns a result object containing an array of extracted data.
47
+ */
48
+ extractRaw(this: Context, node: ts.Node, plugins?: Plugin[]): ExtractionResult<Data>;
49
+ /**
50
+ * Accepts an AST node and returns a result containing an array of
51
+ * {@linkcode EntityData} extracted from that node.
52
+ *
53
+ * @see {@linkcode Extractors}
54
+ * @param node The node to extract.
55
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
56
+ * @returns a result object containing an array of extracted entities.
57
+ */
58
+ extractEntities(this: Context, node: ts.Node, plugins?: Plugin[]): ExtractionResult<EntityData>;
59
+ /**
60
+ * Accepts an array of entity data and returns a {@linkcode LinkedDocument}
61
+ * array.
62
+ *
63
+ * @see {@linkcode Composers}
64
+ * @param data The {@linkcode EntityData} to compose.
65
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
66
+ * @returns a {@linkcode LinkedDocument} array.
67
+ */
68
+ composeEntities(this: Context, data: EntityData[], plugins?: Plugin[]): LinkedDocument[];
69
+ /**
70
+ * Accepts an array of XML data and returns an {@linkcode UnlinkedDocument}
71
+ * array.
72
+ *
73
+ * @see {@linkcode Composers}
74
+ * @param data The {@linkcode XmlData} to compose.
75
+ * @param context The {@linkcode Context} object.
76
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
77
+ * @returns an {@linkcode UnlinkedDocument} array.
78
+ */
79
+ composeXml(this: Context, data: XmlData[], plugins?: Plugin[]): UnlinkedDocument[];
80
+ /**
81
+ * Accepts an array of documents and returns the same documents
82
+ * as unresolved arranged documents.
83
+ *
84
+ * @see {@linkcode Arrangers}
85
+ * @param documents The {@linkcode Document}s to arrange.
86
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
87
+ * @returns a {@linkcode Document} & {@linkcode Arranged} array.
88
+ */
89
+ arrange(this: Context, documents: Document[], plugins?: Plugin[]): (Document & Arranged<'unresolved'>)[];
90
+ /**
91
+ * Accepts an array of documents and returns an array of files.
92
+ *
93
+ * @see {@linkcode Serializers}
94
+ * @param documents The {@linkcode Document}s to serialize.
95
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
96
+ * @returns a {@linkcode File} array.
97
+ */
98
+ serialize(this: Context, documents: (Document & Arranged)[], plugins?: Plugin[]): File[];
99
+ /**
100
+ * Accepts an array of documents, generates new AST nodes for those
101
+ * documents, and returns the same documents as linked documents.
102
+ *
103
+ * @see {@linkcode Generators}
104
+ * @param documents The {@linkcode Document}s to generate AST nodes for.
105
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
106
+ * @returns a {@linkcode LinkedDocument} array.
107
+ */
108
+ generate(this: Context, documents: (UnlinkedDocument & Arranged)[], plugins?: Plugin[]): LinkedDocument[];
109
+ /**
110
+ * Accepts an array of linked documents and performs transformations on
111
+ * their original nodes to reflect any changes that may have been made to
112
+ * those documents' data.
113
+ *
114
+ * @see {@linkcode Transformers}
115
+ * @param documents The {@linkcode LinkedDocument}s to transform.
116
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
117
+ */
118
+ transform(this: Context, documents: (LinkedDocument & Arranged)[], plugins?: Plugin[]): void;
119
+ /**
120
+ * Accepts an array of extracted entities and runs post-processors on that
121
+ * data. Post-processors may perform a variety of arbitrary operations.
122
+ *
123
+ * @see {@linkcode PostProcessors}
124
+ * @param data The {@linkcode EntityData} to process.
125
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
126
+ */
127
+ postProcessEntities(this: Context, data: EntityData[], plugins?: Plugin[]): void;
128
+ /**
129
+ * Accepts an AST node and returns an array of {@linkcode FluentDiagnostic}s
130
+ * for that node.
131
+ *
132
+ * @see {@linkcode Diagnostics}
133
+ * @param node The node to get diagnostics for.
134
+ * @param plugins An optional array of {@linkcode Plugin}s to use.
135
+ * @returns an array of diagnostics.
136
+ */
137
+ getAstDiagnostics(this: Context, node: ts.Node, plugins?: Plugin[]): FluentDiagnostic[];
138
+ /**
139
+ * An object with metadata related to plugin like list of all tables that are claimed to be handled by a specific plugin, and
140
+ * the level of enforcement they apply to that table
141
+ * and API that the plugin is responsible for.
142
+ */
143
+ getPluginForTable(table: string): {
144
+ logLevel: Diagnostic.Level;
145
+ api: string;
146
+ } | undefined;
147
+ /**
148
+ * Indicates whether or not the build system is running in debug mode. This
149
+ * should be checked before printing verbose log messages.
150
+ */
151
+ debug: boolean;
152
+ /**
153
+ * Indicates the current mode in which the build system is running.
154
+ */
155
+ mode: 'serialize' | 'transform';
156
+ /**
157
+ * An array of plugins that will be used (unless overridden) during various
158
+ * build process operations.
159
+ *
160
+ * @see {@link Plugin}
161
+ */
162
+ plugins: Plugin[];
163
+ /**
164
+ * An array of plugins which implement entity-handling behaviors which will
165
+ * be used during various build process operations. These plugins are always
166
+ * executed BEFORE the plugins in the {@link Context#plugins} array.
167
+ *
168
+ * @see {@link Plugin}
169
+ */
170
+ entityPlugins: Plugin[];
171
+ /**
172
+ * Record to store and access data across plugins
173
+ */
174
+ store: Record<string, unknown>;
175
+ usageCount: {
176
+ [key: string]: number;
177
+ };
178
+ /**
179
+ * Resets the store to initial state
180
+ */
181
+ resetStore(): void;
182
+ /**
183
+ * An object of XML file names that was marked as handled or ignored by code transformation during the build process.
184
+ */
185
+ handledXmls: Record<string, HandledStates>;
186
+ setAllDocuments: (documents: Document[]) => void;
187
+ getAllDocuments: () => Document[];
188
+ getDocumentMap: () => DocumentMap;
189
+ getDocument: (sysId: string, kind?: string) => Document | undefined;
190
+ /**
191
+ * @deprecated Use the key methods on the context object instead.
192
+ */
193
+ keys: Keys;
194
+ registerExplicitId: Keys['registerExplicitId'];
195
+ registerCompositeId: Keys['registerCompositeId'];
196
+ getDeletedAndUnusedIds: Keys['getDeletedAndUnusedIds'];
197
+ };
198
+ export type HandledStates = 'handled' | 'ignored' | 'skipped' | 'unchanged';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/plugins/Context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import * as ts from 'ts-morph';
2
+ import { Diagnostic } from '@servicenow/sdk-project';
3
+ export declare class FluentDiagnostic extends Diagnostic {
4
+ constructor(node: ts.Node, message: string, { level, code }?: {
5
+ level?: Diagnostic.Level;
6
+ code?: number;
7
+ });
8
+ asTypeScriptDiagnostic(): ts.ts.Diagnostic;
9
+ }
10
+ export declare function findObjectPropertyValue(callExpression: ts.CallExpression, field: string): ts.Expression<ts.ts.Expression>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.FluentDiagnostic = void 0;
27
+ exports.findObjectPropertyValue = findObjectPropertyValue;
28
+ const ts = __importStar(require("ts-morph"));
29
+ const sdk_project_1 = require("@servicenow/sdk-project");
30
+ class FluentDiagnostic extends sdk_project_1.Diagnostic {
31
+ constructor(node, message, { level = sdk_project_1.Diagnostic.Level.Error, code = node.getKind() } = {}) {
32
+ super(message, node.getSourceFile(), { start: node.getStart(), end: node.getEnd() }, code, 'fluent', level);
33
+ }
34
+ asTypeScriptDiagnostic() {
35
+ return {
36
+ messageText: this.message,
37
+ category: sdk_project_1.Diagnostic.Level.toCategory(this.level),
38
+ code: this.code,
39
+ file: this.file.compilerNode,
40
+ start: this.position.start,
41
+ length: this.position.end - this.position.start,
42
+ };
43
+ }
44
+ }
45
+ exports.FluentDiagnostic = FluentDiagnostic;
46
+ function findObjectPropertyValue(callExpression, field) {
47
+ const property = callExpression
48
+ .getFirstDescendantByKind(ts.SyntaxKind.ObjectLiteralExpression)
49
+ ?.getProperty(field);
50
+ return property?.getInitializer() || callExpression;
51
+ }
52
+ //# sourceMappingURL=Diagnostic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diagnostic.js","sourceRoot":"","sources":["../../src/plugins/Diagnostic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,0DAMC;AA9BD,6CAA8B;AAC9B,yDAAoD;AAEpD,MAAa,gBAAiB,SAAQ,wBAAU;IAC5C,YACI,IAAa,EACb,OAAe,EACf,EAAE,KAAK,GAAG,wBAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,KAAkD,EAAE;QAE3G,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC/G,CAAC;IAEe,sBAAsB;QAClC,OAAO;YACH,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,QAAQ,EAAE,wBAAU,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;YACjD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;YAC5B,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK;YAC1B,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK;SAClD,CAAA;IACL,CAAC;CACJ;AAnBD,4CAmBC;AAED,SAAgB,uBAAuB,CAAC,cAAiC,EAAE,KAAa;IACpF,MAAM,QAAQ,GAAG,cAAc;SAC1B,wBAAwB,CAAC,EAAE,CAAC,UAAU,CAAC,uBAAuB,CAAC;QAChE,EAAE,WAAW,CAAC,KAAK,CAA0B,CAAA;IAEjD,OAAO,QAAQ,EAAE,cAAc,EAAE,IAAI,cAAc,CAAA;AACvD,CAAC"}
@@ -0,0 +1,175 @@
1
+ import { SupportedKindName } from '@servicenow/sdk-project';
2
+ import { Extractors, Composers, Serializers, Transformers, Generators, Arrangers, PostProcessors, Diagnostics, TableOwnership } from './behaviors';
3
+ /**
4
+ * A plugin is an object that defines any number of behaviors that will
5
+ * be invoked by the build system during various operations.
6
+ *
7
+ * The order of build operations during a normal build (code to XML) is
8
+ * as follows:
9
+ *
10
+ * Extract -> Compose -> Arrange -> Serialize
11
+ *
12
+ * The order of build operations during a transform (XML to code, AKA
13
+ * "bi-directional sync") is as follows:
14
+ *
15
+ * Extract -> Compose -> Arrange -> Generate -> Transform
16
+ *
17
+ * During each operation, all plugins which define behaviors for that
18
+ * operation will be invoked. Therefore, plugins should always "fail
19
+ * fast" to minimize performance impact. For example, if a plugin defines
20
+ * an extractor for calls to a function named "exampleFunction", that
21
+ * plugin should first validate the function name and return immediately
22
+ * if the name is anything but "exampleFunction".
23
+ *
24
+ * @see {@linkcode Extractors}
25
+ * @see {@linkcode Composers}
26
+ * @see {@linkcode Arrangers}
27
+ * @see {@linkcode Serializers}
28
+ * @see {@linkcode Generators}
29
+ * @see {@linkcode Transformers}
30
+ */
31
+ export type Plugin<DiagnosticsNodeKinds extends SupportedKindName | 'Node' = any, RawNodeKinds extends SupportedKindName = any, EntityNodeKinds extends SupportedKindName = any, ArrangerDocumentKinds extends string = any, SerializerDocumentKinds extends string = any, GeneratorDocumentKinds extends string = any, TransformerDocumentKinds extends string = any> = {
32
+ /**
33
+ * Name of the plugin
34
+ */
35
+ name: string;
36
+ diagnostics?: Diagnostics<DiagnosticsNodeKinds>;
37
+ /**
38
+ * ServiceNow tables that this plugin handles and should not be serialized
39
+ * by generic plugins, and the appropriate diagnostic level to enforce on
40
+ * this relationship
41
+ */
42
+ ownedTables?: TableOwnership;
43
+ /**
44
+ * Plugins may define extractors which extract raw data or entity data from
45
+ * AST nodes, or XML data from parsed XML files. The build system will take
46
+ * any entity data produced by an extractor and pass it along to any plugin
47
+ * that implements a composer for that kind of entity.
48
+ *
49
+ * An extractors object is an object with any of the keys 'xml', 'raw', or
50
+ * 'entity', where the values of those keys are nested objects where each
51
+ * key is the name of a kind of AST node, and the value is one of the types
52
+ * of extractor functions.
53
+ *
54
+ * @example
55
+ * const extractors = {
56
+ * entity: {
57
+ * CallExpression(node, context) { ... }
58
+ * ClassDeclaration(node, context) { ... }
59
+ * }
60
+ * }
61
+ */
62
+ extractors?: Extractors<RawNodeKinds, EntityNodeKinds>;
63
+ /**
64
+ * Plugins may define composers for both entity data (from the
65
+ * source code) and XML data (from XML files). The job of a
66
+ * composer is to turn a piece of extracted data into one or more
67
+ * documents which can then be serialized or transformed.
68
+ *
69
+ * A composers object that has two optional keys: 'entity' and 'xml'. The
70
+ * value of the 'xml' key is a {@linkcode XmlComposerFunction}. The value of
71
+ * the 'entity' key is another object where each key is the name of a kind
72
+ * of entity, and the value is a {@linkcode EntityComposerFunction}.
73
+ *
74
+ * @example
75
+ * const composers = {
76
+ * entity: {
77
+ * MyFirstEntity(data, context) { ... }
78
+ * MyOtherEntity(data, context) { ... }
79
+ * },
80
+ * xml: {
81
+ * record(data, context) { ... }
82
+ * }
83
+ * }
84
+ */
85
+ composers?: Composers;
86
+ /**
87
+ * Plugins may define arrangers which take documents and return their parents
88
+ * so that the build system can arrange them in a tree structure.
89
+ *
90
+ * An arrangers object is an object where each key is the name of a kind of
91
+ * document, and the value is a {@linkcode ArrangerFunction}.
92
+ *
93
+ * @example
94
+ * const arrangers = {
95
+ * MyFirstDocument(document, context) { ... },
96
+ * MyOtherDocument(document, context) { ... }
97
+ * }
98
+ */
99
+ arrangers?: Arrangers<ArrangerDocumentKinds>;
100
+ /**
101
+ * Plugins may define serializers which turn documents into files which the
102
+ * build system will write to the filesystem as output.
103
+ *
104
+ * A serializers object is an object where each key is the name of a kind of
105
+ * document, and the value is a {@linkcode SerializerFunction}.
106
+ *
107
+ * @example
108
+ * const serializers = {
109
+ * MyFirstDocument(document, context) { ... },
110
+ * MyOtherDocument(document, context) { ... }
111
+ * }
112
+ */
113
+ serializers?: Serializers<SerializerDocumentKinds>;
114
+ /**
115
+ * Plugins may define generators which create new nodes for documents that
116
+ * don't have nodes, usually because they were extracted from XML files and
117
+ * aren't defined yet in the source code. The build system will pass each
118
+ * document without a node to any plugin which implements a generator for
119
+ * that kind of document. These documents are then passed along to the
120
+ * transformers along with all the other documents which already had nodes.
121
+ *
122
+ * A generators object is an object where each key is the name of a kind of
123
+ * document, and the value is a {@linkcode GeneratorFunction}.
124
+ *
125
+ * @example
126
+ * const generators = {
127
+ * MyFirstDocument(document, context) { ... },
128
+ * MyOtherDocument(document, context) { ... }
129
+ * }
130
+ */
131
+ generators?: Generators<GeneratorDocumentKinds>;
132
+ /**
133
+ * Plugins may define transformers which take linked documents and perform
134
+ * transformations on their linked nodes to ensure each document is fully
135
+ * represented in the source code.
136
+ *
137
+ * A transformers object is an object where each key is the name of a kind of
138
+ * document, and the value is another object where each key is the name of a
139
+ * kind of AST node, and the value is a {@linkcode TransformerFunction}.
140
+ *
141
+ * @example
142
+ * const transformers = {
143
+ * MyFirstDocument: {
144
+ * CallExpression(document, context) { ... },
145
+ * ClassDeclaration(document, context) { ... }
146
+ * },
147
+ * MyOtherDocument: {
148
+ * CallExpression(document, context) { ... },
149
+ * ClassDeclaration(document, context) { ... }
150
+ * }
151
+ * }
152
+ */
153
+ transformers?: Transformers<TransformerDocumentKinds>;
154
+ /**
155
+ * Plugins may define post-processors for data from certain stages of the build
156
+ * process. For example, a post-processor for entities will be called after the
157
+ * extraction stage and will receive all entities extracted by all plugins.
158
+ * These can be used for arbitrary operations based on extracted data.
159
+ *
160
+ * @example
161
+ * const postProcessors = {
162
+ * entities(entities, context) { ... }
163
+ * }
164
+ */
165
+ postProcessors?: PostProcessors;
166
+ };
167
+ /**
168
+ * Utility function to create a new {@linkcode Plugin} object. Provides
169
+ * the simplest and most type-safe experience for defining a plugin, but
170
+ * is not required.
171
+ *
172
+ * @param plugin The {@linkcode Plugin} configuration
173
+ * @returns a {@linkcode Plugin} object
174
+ */
175
+ export declare function Plugin<const DiagnosticsNodeKinds extends SupportedKindName | 'Node', const RawNodeKinds extends SupportedKindName, const EntityNodeKinds extends SupportedKindName, const SerializerDocumentKinds extends string, const GeneratorDocumentKinds extends string, const TransformerDocumentKinds extends string, const P extends Plugin<DiagnosticsNodeKinds, RawNodeKinds, EntityNodeKinds, SerializerDocumentKinds, GeneratorDocumentKinds, TransformerDocumentKinds>>(plugin: P & Plugin<DiagnosticsNodeKinds, RawNodeKinds, EntityNodeKinds, SerializerDocumentKinds, GeneratorDocumentKinds, TransformerDocumentKinds>): P;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Plugin = Plugin;
4
+ /**
5
+ * Utility function to create a new {@linkcode Plugin} object. Provides
6
+ * the simplest and most type-safe experience for defining a plugin, but
7
+ * is not required.
8
+ *
9
+ * @param plugin The {@linkcode Plugin} configuration
10
+ * @returns a {@linkcode Plugin} object
11
+ */
12
+ function Plugin(plugin) {
13
+ return plugin;
14
+ }
15
+ //# sourceMappingURL=Plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/plugins/Plugin.ts"],"names":[],"mappings":";;AA0NA,wBA2BC;AAnCD;;;;;;;GAOG;AACH,SAAgB,MAAM,CAgBlB,MAQK;IAEL,OAAO,MAAW,CAAA;AACtB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Document, DocumentPointer, LinkedDocument } from './Composer';
2
+ import { Context } from '../Context';
3
+ export type Arranged<Status extends 'unresolved' | 'resolved' = 'resolved'> = {
4
+ parent?: Status extends 'unresolved' ? DocumentPointer & Arranged<'unresolved'> : LinkedDocument & Arranged;
5
+ };
6
+ export type Result<T> = {
7
+ handled: false;
8
+ result?: never;
9
+ } | {
10
+ handled: true;
11
+ result: T;
12
+ };
13
+ /**
14
+ * An arranger function is a function which accepts a document of a known
15
+ * kind as input and returns a pointer to its parent, if applicable.
16
+ *
17
+ * @see {@linkcode Document}
18
+ * @see {@linkcode DocumentPointer}
19
+ */
20
+ export type ArrangerFunction<DocumentKind extends string = string> = (document: Document<DocumentKind>, context: Context) => Result<DocumentPointer | undefined>;
21
+ /**
22
+ * @see {@linkcode Plugin#arrangers}
23
+ */
24
+ export type Arrangers<DocumentKinds extends string = string> = {
25
+ [K in DocumentKinds]: ArrangerFunction<K>;
26
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Arranger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Arranger.js","sourceRoot":"","sources":["../../../src/plugins/behaviors/Arranger.ts"],"names":[],"mappings":""}
@@ -0,0 +1,101 @@
1
+ import { SupportedNode } from '@servicenow/sdk-project';
2
+ import { XmlData, PrimitiveData, Action, EntityData } from './extractors';
3
+ import { Context } from '../Context';
4
+ /**
5
+ * An unlinked document is a document that does not have an
6
+ * association with any AST node.
7
+ *
8
+ * @see {@linkcode Document}
9
+ */
10
+ export type UnlinkedDocument<DocumentKind extends string = string> = Omit<Document<DocumentKind>, 'node'>;
11
+ /**
12
+ * A linked document is a document that has an association
13
+ * with an AST node.
14
+ *
15
+ * @see {@linkcode Document}
16
+ */
17
+ export type LinkedDocument<DocumentKind extends string = string, Node extends SupportedNode = SupportedNode> = Document<DocumentKind, Node> & {
18
+ entity?: EntityData;
19
+ node: Node;
20
+ };
21
+ /**
22
+ * A document is a data structure that has a known kind, an ID,
23
+ * and an action (insert/update or delete). It may also have an
24
+ * associated AST node if the data originated from source code.
25
+ *
26
+ * @see {@linkcode LinkedDocument}
27
+ * @see {@linkcode UnlinkedDocument}
28
+ */
29
+ export type Document<DocumentKind extends string = string, Node extends SupportedNode = SupportedNode> = {
30
+ guid: string;
31
+ kind: DocumentKind;
32
+ data: unknown;
33
+ changedData?: unknown;
34
+ xmlData?: unknown;
35
+ node?: Node;
36
+ action?: Action;
37
+ };
38
+ /**
39
+ * A document pointer is an object that represents a document
40
+ * via its ID and kind. Document pointers can be resolved to
41
+ * actual documents after all documents have been composed.
42
+ *
43
+ * @see {@linkcode Document}
44
+ */
45
+ export type DocumentPointer<DocumentKind extends string = string> = {
46
+ guid: string;
47
+ kind: DocumentKind;
48
+ };
49
+ /**
50
+ * A document map is an object where documents are accessible
51
+ * by their kind and ID. The keys of the object are document
52
+ * kinds, and the values are sub-objects where the keys are
53
+ * document IDs and the values are the corresponding documents.
54
+ *
55
+ * @see {@linkcode Document}
56
+ */
57
+ export type DocumentMap = {
58
+ [kinds: string]: {
59
+ [guids: string]: Document;
60
+ };
61
+ };
62
+ /**
63
+ * An entity composer function is a function that accepts a
64
+ * piece of entity data from the source code and returns one
65
+ * or more linked documents derived from that entity, or returns
66
+ * undefined to indicate that it did not handle the data.
67
+ *
68
+ * @see {@linkcode Entity}
69
+ * @see {@linkcode EntityData}
70
+ */
71
+ export type EntityComposerFunction<Data extends Record<string, unknown> = Record<string, unknown>> = (entityData: EntityData<Data>, context: Context) => LinkedDocument | LinkedDocument[] | undefined;
72
+ /**
73
+ * An XML composer function is a function that accepts a piece
74
+ * of data from an XML file and returns one or more unlinked
75
+ * documents derived from that data, or returns undefined to
76
+ * indicate that it did not handle the data.
77
+ *
78
+ * @see {@linkcode PrimitiveData}
79
+ * @see {@linkcode XmlData}
80
+ */
81
+ export type XmlComposerFunction<Data extends PrimitiveData = PrimitiveData> = (xmlData: XmlData<Data>, context: Context) => UnlinkedDocument | UnlinkedDocument[] | undefined;
82
+ /**
83
+ * @see {@linkcode Plugin#composers}
84
+ */
85
+ export type Composers = {
86
+ entity?: {
87
+ [kind: string]: EntityComposerFunction;
88
+ };
89
+ xml?: {
90
+ [kind: string]: XmlComposerFunction;
91
+ };
92
+ };
93
+ /**
94
+ * Utility which takes an unlinked document and a node and returns the
95
+ * same document linked to the provided node.
96
+ *
97
+ * @param document The {@linkcode UnlinkedDocument} to link
98
+ * @param node The AST node to link the document to
99
+ * @returns A {@linkcode LinkedDocument}
100
+ */
101
+ export declare function linkDocument<const K extends string, const N extends SupportedNode>(document: UnlinkedDocument<K>, node: N): LinkedDocument<K, N>;