@stackql/provider-utils 0.1.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.
@@ -0,0 +1,90 @@
1
+ // src/docgen/resource/methods.js
2
+ import {
3
+ cleanDescription,
4
+ getSqlMethodsWithOrderedFields,
5
+ sanitizeHtml
6
+ } from '../helpers.js';
7
+
8
+ export function createMethodsSection(resourceData, dereferencedAPI) {
9
+
10
+ let content = `\n## Methods\n\n`;
11
+
12
+ content += 'The following methods are available for this resource:\n\n';
13
+
14
+ // Add the table header
15
+ content += `<table>
16
+ <thead>
17
+ <tr>
18
+ <th>Name</th>
19
+ <th>Accessible by</th>
20
+ <th>Required Params</th>
21
+ <th>Optional Params</th>
22
+ <th>Description</th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>`;
26
+
27
+ const selectMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'select');
28
+ const insertMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'insert');
29
+ const updateMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'update');
30
+ const replaceMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'replace');
31
+ const deleteMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'delete');
32
+ const execMethods = getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, 'exec');
33
+
34
+ // console.dir(selectMethods, { depth: null, colors: true });
35
+
36
+ // Helper function to add methods to the table
37
+ const addMethodsToTable = (methods, accessType) => {
38
+ for (const [methodName, methodDetails] of Object.entries(methods)) {
39
+ console.info(`Adding ${accessType} method to table: ${methodName}`);
40
+
41
+ // Format required params as comma-delimited list with hyperlinks
42
+ const requiredParamsArr = Object.keys(methodDetails.requiredParams || {});
43
+ const requiredParamsStr = requiredParamsArr.length > 0
44
+ ? requiredParamsArr.map(param => `<a href="#parameter-${param}"><code>${param}</code></a>`).join(', ')
45
+ : '';
46
+
47
+ // Format optional params as comma-delimited list with hyperlinks
48
+ const optionalParamsArr = Object.keys(methodDetails.optionalParams || {});
49
+ const optionalParamsStr = optionalParamsArr.length > 0
50
+ ? optionalParamsArr.map(param => `<a href="#parameter-${param}"><code>${param}</code></a>`).join(', ')
51
+ : '';
52
+
53
+ // Add the method row to the table
54
+ content += `
55
+ <tr>
56
+ <td><a href="#${methodName}"><CopyableCode code="${methodName}" /></a></td>
57
+ <td><CopyableCode code="${accessType}" /></td>
58
+ <td>${requiredParamsStr}</td>
59
+ <td>${optionalParamsStr}</td>
60
+ <td>${sanitizeHtml(methodDetails.opDescription)}</td>
61
+ </tr>`;
62
+ }
63
+ };
64
+
65
+ // Add all methods to the table by type
66
+ console.info(`Processing select methods...`);
67
+ addMethodsToTable(selectMethods, 'select');
68
+
69
+ console.info(`Processing insert methods...`);
70
+ addMethodsToTable(insertMethods, 'insert');
71
+
72
+ console.info(`Processing update methods...`);
73
+ addMethodsToTable(updateMethods, 'update');
74
+
75
+ console.info(`Processing replace methods...`);
76
+ addMethodsToTable(replaceMethods, 'replace');
77
+
78
+ console.info(`Processing delete methods...`);
79
+ addMethodsToTable(deleteMethods, 'delete');
80
+
81
+ console.info(`Processing exec methods...`);
82
+ addMethodsToTable(execMethods, 'exec');
83
+
84
+ // Close the table
85
+ content += `
86
+ </tbody>
87
+ </table>`;
88
+
89
+ return content;
90
+ }
@@ -0,0 +1,39 @@
1
+ // src/docgen/resource/overview.js
2
+ import {
3
+ getIndefiniteArticle,
4
+ } from '../helpers.js';
5
+
6
+ export function createOverviewSection(resourceName, providerName, serviceName) {
7
+
8
+ let content = `---
9
+ title: ${resourceName}
10
+ hide_title: false
11
+ hide_table_of_contents: false
12
+ keywords:
13
+ - ${resourceName}
14
+ - ${serviceName}
15
+ - ${providerName}
16
+ - infrastructure-as-code
17
+ - configuration-as-data
18
+ - cloud inventory
19
+ description: Query, deploy and manage ${providerName} resources using SQL
20
+ custom_edit_url: null
21
+ image: /img/providers/${providerName}/stackql-${providerName}-provider-featured-image.png
22
+ ---
23
+
24
+ import CopyableCode from '@site/src/components/CopyableCode/CopyableCode';
25
+ import Tabs from '@theme/Tabs';
26
+ import TabItem from '@theme/TabItem';
27
+
28
+ Creates, updates, deletes, gets or lists ${getIndefiniteArticle(resourceName)} <code>${resourceName}</code> resource.
29
+
30
+ ## Overview
31
+ <table><tbody>
32
+ <tr><td><b>Name</b></td><td><code>${resourceName}</code></td></tr>
33
+ <tr><td><b>Type</b></td><td>Resource</td></tr>
34
+ <tr><td><b>Id</b></td><td><CopyableCode code="${providerName}.${serviceName}.${resourceName}" /></td></tr>
35
+ </tbody></table>
36
+
37
+ `;
38
+ return content;
39
+ }
@@ -0,0 +1,76 @@
1
+ // src/docgen/resource/parameters.js
2
+ import {
3
+ getSqlMethodsWithOrderedFields,
4
+ sanitizeHtml
5
+ } from '../helpers.js';
6
+
7
+ const mdCodeAnchor = "`";
8
+
9
+ export function createParamsSection(resourceData, dereferencedAPI) {
10
+ let content = '\n\n## Parameters\n\n';
11
+
12
+ content += 'Parameters can be passed in the `WHERE` clause of a query. ' +
13
+ 'Check the [Methods](#methods) section to see which parameters are required or optional for each operation.\n\n';
14
+
15
+ // Get all methods at once
16
+ const allMethodTypes = ['select', 'insert', 'update', 'replace', 'delete', 'exec'];
17
+ const allMethods = allMethodTypes.flatMap(type =>
18
+ Object.values(getSqlMethodsWithOrderedFields(resourceData, dereferencedAPI, type))
19
+ );
20
+
21
+ // Collect all unique parameters in one pass
22
+ const requiredParams = {};
23
+ const optionalParams = {};
24
+
25
+ allMethods.forEach(method => {
26
+ // Add required params
27
+ Object.entries(method.requiredParams || {}).forEach(([name, details]) => {
28
+ requiredParams[name] = details;
29
+ });
30
+
31
+ // Add optional params
32
+ Object.entries(method.optionalParams || {}).forEach(([name, details]) => {
33
+ optionalParams[name] = details;
34
+ });
35
+ });
36
+
37
+ // Add the table header
38
+ content += `<table>
39
+ <thead>
40
+ <tr>
41
+ <th>Name</th>
42
+ <th>Datatype</th>
43
+ <th>Description</th>
44
+ </tr>
45
+ </thead>
46
+ <tbody>`;
47
+
48
+ // Helper function to add parameter rows
49
+ const addParamRows = (params) => {
50
+ // Sort parameters alphabetically for better readability
51
+ const sortedParamNames = Object.keys(params).sort();
52
+
53
+ for (const paramName of sortedParamNames) {
54
+ const paramDetails = params[paramName];
55
+ content += `
56
+ <tr id="parameter-${paramName}">
57
+ <td><CopyableCode code="${paramName}" /></td>
58
+ <td><code>${paramDetails.type || ''}</code></td>
59
+ <td>${sanitizeHtml(paramDetails.description) || ''}</td>
60
+ </tr>`;
61
+ }
62
+ };
63
+
64
+ // Add required parameter rows
65
+ addParamRows(requiredParams);
66
+
67
+ // Add optional parameter rows
68
+ addParamRows(optionalParams);
69
+
70
+ // Close the table
71
+ content += `
72
+ </tbody>
73
+ </table>`;
74
+
75
+ return content;
76
+ }
@@ -0,0 +1,25 @@
1
+ // src/docgen/resource-content.js
2
+
3
+ import { createOverviewSection } from './resource/overview.js';
4
+ import { createFieldsSection } from './resource/fields.js';
5
+ import { createMethodsSection } from './resource/methods.js';
6
+ import { createParamsSection } from './resource/parameters.js';
7
+ import { createExamplesSection } from './resource/examples.js';
8
+
9
+ export async function createResourceIndexContent(
10
+ providerName,
11
+ serviceName,
12
+ resourceName,
13
+ resourceData,
14
+ dereferencedAPI,
15
+ ) {
16
+ // Generate each section of the documentation
17
+ const overviewContent = createOverviewSection(resourceName, providerName, serviceName);
18
+ const fieldsContent = createFieldsSection(resourceData, dereferencedAPI);
19
+ const methodsContent = createMethodsSection(resourceData, dereferencedAPI);
20
+ const paramsContent = createParamsSection(resourceData, dereferencedAPI);
21
+ const examplesContent = createExamplesSection(providerName, serviceName, resourceName, resourceData, dereferencedAPI);
22
+
23
+ // Combine all sections into the final content
24
+ return `${overviewContent}${fieldsContent}${methodsContent}${paramsContent}${examplesContent}`;
25
+ }
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // src/index.js
2
+
3
+ // Main entry point for Node.js
4
+ export * as docgen from './docgen/index.js';