embedoc 0.9.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.
- package/LICENSE +21 -0
- package/README.md +941 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +337 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/dependency.d.ts +59 -0
- package/dist/core/dependency.d.ts.map +1 -0
- package/dist/core/dependency.js +209 -0
- package/dist/core/dependency.js.map +1 -0
- package/dist/core/generator.d.ts +23 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +211 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/inline-datasource.d.ts +117 -0
- package/dist/core/inline-datasource.d.ts.map +1 -0
- package/dist/core/inline-datasource.js +346 -0
- package/dist/core/inline-datasource.js.map +1 -0
- package/dist/core/parser.d.ts +41 -0
- package/dist/core/parser.d.ts.map +1 -0
- package/dist/core/parser.js +250 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/processor.d.ts +18 -0
- package/dist/core/processor.d.ts.map +1 -0
- package/dist/core/processor.js +219 -0
- package/dist/core/processor.js.map +1 -0
- package/dist/datasources/csv.d.ts +17 -0
- package/dist/datasources/csv.d.ts.map +1 -0
- package/dist/datasources/csv.js +54 -0
- package/dist/datasources/csv.js.map +1 -0
- package/dist/datasources/glob.d.ts +17 -0
- package/dist/datasources/glob.d.ts.map +1 -0
- package/dist/datasources/glob.js +72 -0
- package/dist/datasources/glob.js.map +1 -0
- package/dist/datasources/index.d.ts +22 -0
- package/dist/datasources/index.d.ts.map +1 -0
- package/dist/datasources/index.js +53 -0
- package/dist/datasources/index.js.map +1 -0
- package/dist/datasources/json.d.ts +16 -0
- package/dist/datasources/json.d.ts.map +1 -0
- package/dist/datasources/json.js +59 -0
- package/dist/datasources/json.js.map +1 -0
- package/dist/datasources/sqlite.d.ts +15 -0
- package/dist/datasources/sqlite.d.ts.map +1 -0
- package/dist/datasources/sqlite.js +40 -0
- package/dist/datasources/sqlite.js.map +1 -0
- package/dist/datasources/yaml.d.ts +16 -0
- package/dist/datasources/yaml.d.ts.map +1 -0
- package/dist/datasources/yaml.js +60 -0
- package/dist/datasources/yaml.js.map +1 -0
- package/dist/helpers/markdown.d.ts +10 -0
- package/dist/helpers/markdown.d.ts.map +1 -0
- package/dist/helpers/markdown.js +93 -0
- package/dist/helpers/markdown.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +254 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Generator
|
|
3
|
+
* Generate new files from datasource records using Handlebars templates
|
|
4
|
+
*/
|
|
5
|
+
import type { EmbedifyConfig, DatasourceConfig, GenerateResult, Datasource } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate files from datasource
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateFromDatasource(datasourceName: string, datasourceConfig: DatasourceConfig, datasource: Datasource, config: EmbedifyConfig, options?: {
|
|
10
|
+
dryRun?: boolean;
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
generatorName?: string;
|
|
13
|
+
}): Promise<GenerateResult[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Generate files from all datasources
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateAll(config: EmbedifyConfig, datasources: Record<string, Datasource>, options?: {
|
|
18
|
+
dryRun?: boolean;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
datasourceName?: string;
|
|
21
|
+
generatorName?: string;
|
|
22
|
+
}): Promise<GenerateResult[]>;
|
|
23
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAEhB,cAAc,EACd,UAAU,EACX,MAAM,mBAAmB,CAAC;AAqK3B;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACnB,GACL,OAAO,CAAC,cAAc,EAAE,CAAC,CAwD3B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,cAAc,EACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACvC,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACnB,GACL,OAAO,CAAC,cAAc,EAAE,CAAC,CA0C3B"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Generator
|
|
3
|
+
* Generate new files from datasource records using Handlebars templates
|
|
4
|
+
*/
|
|
5
|
+
import { readFile, writeFile, mkdir, access } from 'node:fs/promises';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import Handlebars from 'handlebars';
|
|
8
|
+
/**
|
|
9
|
+
* Register built-in Handlebars helpers
|
|
10
|
+
*/
|
|
11
|
+
function registerHelpers() {
|
|
12
|
+
// today: Current date (YYYY-MM-DD)
|
|
13
|
+
Handlebars.registerHelper('today', () => {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
return now.toISOString().split('T')[0];
|
|
16
|
+
});
|
|
17
|
+
// datetime: Current datetime
|
|
18
|
+
Handlebars.registerHelper('datetime', () => {
|
|
19
|
+
return new Date().toISOString();
|
|
20
|
+
});
|
|
21
|
+
// eq: Equal comparison
|
|
22
|
+
Handlebars.registerHelper('eq', (a, b) => a === b);
|
|
23
|
+
// ne: Not equal comparison
|
|
24
|
+
Handlebars.registerHelper('ne', (a, b) => a !== b);
|
|
25
|
+
// gt: Greater than
|
|
26
|
+
Handlebars.registerHelper('gt', (a, b) => a > b);
|
|
27
|
+
// lt: Less than
|
|
28
|
+
Handlebars.registerHelper('lt', (a, b) => a < b);
|
|
29
|
+
// and: Logical AND
|
|
30
|
+
Handlebars.registerHelper('and', (...args) => {
|
|
31
|
+
args.pop(); // Remove options
|
|
32
|
+
return args.every(Boolean);
|
|
33
|
+
});
|
|
34
|
+
// or: Logical OR
|
|
35
|
+
Handlebars.registerHelper('or', (...args) => {
|
|
36
|
+
args.pop(); // Remove options
|
|
37
|
+
return args.some(Boolean);
|
|
38
|
+
});
|
|
39
|
+
// json: JSON stringify
|
|
40
|
+
Handlebars.registerHelper('json', (obj) => {
|
|
41
|
+
return JSON.stringify(obj, null, 2);
|
|
42
|
+
});
|
|
43
|
+
// uppercase: Convert to uppercase
|
|
44
|
+
Handlebars.registerHelper('uppercase', (str) => {
|
|
45
|
+
return String(str ?? '').toUpperCase();
|
|
46
|
+
});
|
|
47
|
+
// lowercase: Convert to lowercase
|
|
48
|
+
Handlebars.registerHelper('lowercase', (str) => {
|
|
49
|
+
return String(str ?? '').toLowerCase();
|
|
50
|
+
});
|
|
51
|
+
// capitalize: Capitalize first letter
|
|
52
|
+
Handlebars.registerHelper('capitalize', (str) => {
|
|
53
|
+
const s = String(str ?? '');
|
|
54
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
55
|
+
});
|
|
56
|
+
// replace: String replacement
|
|
57
|
+
Handlebars.registerHelper('replace', (str, search, replacement) => {
|
|
58
|
+
return String(str ?? '').replace(new RegExp(search, 'g'), replacement);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Register helpers
|
|
62
|
+
registerHelpers();
|
|
63
|
+
/**
|
|
64
|
+
* Compile and render template
|
|
65
|
+
*/
|
|
66
|
+
async function renderTemplate(templatePath, data) {
|
|
67
|
+
const templateContent = await readFile(templatePath, { encoding: 'utf-8' });
|
|
68
|
+
const template = Handlebars.compile(templateContent);
|
|
69
|
+
return template(data);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Replace output path placeholders
|
|
73
|
+
* {column_name} -> record.column_name
|
|
74
|
+
* Also supports column names with special characters (#, -, ., etc.)
|
|
75
|
+
*/
|
|
76
|
+
function resolveOutputPath(pathTemplate, record) {
|
|
77
|
+
return pathTemplate.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
78
|
+
const value = record[key];
|
|
79
|
+
return value !== null && value !== undefined ? String(value) : '';
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if file exists
|
|
84
|
+
*/
|
|
85
|
+
async function fileExists(filePath) {
|
|
86
|
+
try {
|
|
87
|
+
await access(filePath);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generate file from a single record
|
|
96
|
+
*/
|
|
97
|
+
async function generateFile(record, generatorConfig, templatesDir, config, dryRun = false) {
|
|
98
|
+
// Resolve output path
|
|
99
|
+
const outputPath = resolveOutputPath(generatorConfig.output_path, record);
|
|
100
|
+
const result = {
|
|
101
|
+
filePath: outputPath,
|
|
102
|
+
success: true,
|
|
103
|
+
skipped: false,
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
// Check existing file
|
|
107
|
+
const exists = await fileExists(outputPath);
|
|
108
|
+
if (exists && !generatorConfig.overwrite) {
|
|
109
|
+
result.skipped = true;
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
// Resolve template path
|
|
113
|
+
const templatePath = join(templatesDir, generatorConfig.template);
|
|
114
|
+
// Render template
|
|
115
|
+
const content = await renderTemplate(templatePath, record);
|
|
116
|
+
if (!dryRun) {
|
|
117
|
+
// Create directory
|
|
118
|
+
await mkdir(dirname(outputPath), { recursive: true });
|
|
119
|
+
// Write file
|
|
120
|
+
const lineEnding = config.output?.line_ending ?? 'lf';
|
|
121
|
+
const outputContent = lineEnding === 'crlf' ? content.replace(/\n/g, '\r\n') : content;
|
|
122
|
+
await writeFile(outputPath, outputContent, {
|
|
123
|
+
encoding: config.output?.encoding ?? 'utf-8',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
result.success = false;
|
|
129
|
+
result.error = error instanceof Error ? error : new Error(String(error));
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generate files from datasource
|
|
135
|
+
*/
|
|
136
|
+
export async function generateFromDatasource(datasourceName, datasourceConfig, datasource, config, options = {}) {
|
|
137
|
+
const results = [];
|
|
138
|
+
if (!datasourceConfig.generators || datasourceConfig.generators.length === 0) {
|
|
139
|
+
if (options.verbose) {
|
|
140
|
+
console.log(`No generators defined for datasource: ${datasourceName}`);
|
|
141
|
+
}
|
|
142
|
+
return results;
|
|
143
|
+
}
|
|
144
|
+
// Templates directory
|
|
145
|
+
const templatesDir = config.templates_dir ?? './templates';
|
|
146
|
+
// Get data
|
|
147
|
+
const records = await datasource.getAll();
|
|
148
|
+
if (options.verbose) {
|
|
149
|
+
console.log(`Found ${records.length} records in datasource: ${datasourceName}`);
|
|
150
|
+
}
|
|
151
|
+
// Process each generator
|
|
152
|
+
for (const generatorConfig of datasourceConfig.generators) {
|
|
153
|
+
// Filter by specific generator if provided
|
|
154
|
+
if (options.generatorName && generatorConfig.template !== options.generatorName) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (options.verbose) {
|
|
158
|
+
console.log(` Generator: ${generatorConfig.template}`);
|
|
159
|
+
}
|
|
160
|
+
// Generate file for each record
|
|
161
|
+
for (const record of records) {
|
|
162
|
+
const result = await generateFile(record, generatorConfig, templatesDir, config, options.dryRun);
|
|
163
|
+
results.push(result);
|
|
164
|
+
if (options.verbose) {
|
|
165
|
+
if (result.skipped) {
|
|
166
|
+
console.log(` Skipped (exists): ${result.filePath}`);
|
|
167
|
+
}
|
|
168
|
+
else if (result.success) {
|
|
169
|
+
console.log(` Generated: ${result.filePath}`);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
console.log(` Failed: ${result.filePath} - ${result.error?.message}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return results;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Generate files from all datasources
|
|
181
|
+
*/
|
|
182
|
+
export async function generateAll(config, datasources, options = {}) {
|
|
183
|
+
const results = [];
|
|
184
|
+
if (!config.datasources) {
|
|
185
|
+
return results;
|
|
186
|
+
}
|
|
187
|
+
for (const [name, dsConfig] of Object.entries(config.datasources)) {
|
|
188
|
+
// Filter by specific datasource if provided
|
|
189
|
+
if (options.datasourceName && name !== options.datasourceName) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
// Skip if no generators
|
|
193
|
+
if (!dsConfig.generators || dsConfig.generators.length === 0) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const datasource = datasources[name];
|
|
197
|
+
if (!datasource) {
|
|
198
|
+
if (options.verbose) {
|
|
199
|
+
console.warn(`Datasource not initialized: ${name}`);
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (options.verbose) {
|
|
204
|
+
console.log(`\nProcessing datasource: ${name}`);
|
|
205
|
+
}
|
|
206
|
+
const dsResults = await generateFromDatasource(name, dsConfig, datasource, config, options);
|
|
207
|
+
results.push(...dsResults);
|
|
208
|
+
}
|
|
209
|
+
return results;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,UAAU,MAAM,YAAY,CAAC;AASpC;;GAEG;AACH,SAAS,eAAe;IACtB,mCAAmC;IACnC,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE;QACtC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,6BAA6B;IAC7B,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE;QACzC,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,uBAAuB;IACvB,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnD,2BAA2B;IAC3B,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnD,mBAAmB;IACnB,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEjD,gBAAgB;IAChB,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,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AAC,cAAc,IAAI,IAAI,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC;YAC9D,SAAS;QACX,CAAC;QAED,wBAAwB;QACxB,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7D,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;YACtD,CAAC;YACD,SAAS;QACX,CAAC;QAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,sBAAsB,CAC5C,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,MAAM,EACN,OAAO,CACR,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline Datasource
|
|
3
|
+
* Document-local datasources defined with @embedoc-data markers
|
|
4
|
+
*/
|
|
5
|
+
import type { Datasource, QueryResult } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parsed inline data marker
|
|
8
|
+
*/
|
|
9
|
+
export interface ParsedInlineData {
|
|
10
|
+
/** Datasource name (may contain dots for nested paths) */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Data format */
|
|
13
|
+
format: 'yaml' | 'json' | 'csv' | 'table' | 'text';
|
|
14
|
+
/** Raw content between markers */
|
|
15
|
+
content: string;
|
|
16
|
+
/** Start line number (for error reporting) */
|
|
17
|
+
startLine: number;
|
|
18
|
+
/** End line number (for error reporting) */
|
|
19
|
+
endLine: number;
|
|
20
|
+
/** Byte size of content */
|
|
21
|
+
byteSize: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Inline datasource configuration
|
|
25
|
+
*/
|
|
26
|
+
export interface InlineDatasourceConfig {
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
maxBytes?: number;
|
|
29
|
+
allowedFormats?: string[];
|
|
30
|
+
conflictPolicy?: 'warn' | 'error' | 'prefer_external';
|
|
31
|
+
allowAnonymous?: boolean;
|
|
32
|
+
/** Strip code fences from content (default: true) */
|
|
33
|
+
stripCodeFences?: boolean;
|
|
34
|
+
/** Custom patterns to strip from content start/end (regex strings) */
|
|
35
|
+
stripPatterns?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse dot-path into segments
|
|
39
|
+
* "author.repos[0].name" → ["author", "repos", 0, "name"]
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseDotPath(path: string): (string | number)[];
|
|
42
|
+
/**
|
|
43
|
+
* Resolve dot-path on an object
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveDotPath(obj: unknown, path: string): unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Set value at dot-path, creating intermediate objects as needed
|
|
48
|
+
*/
|
|
49
|
+
export declare function setDotPath(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get root name from dot-path
|
|
52
|
+
* "project.author.name" → "project"
|
|
53
|
+
*/
|
|
54
|
+
export declare function getRootName(path: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Content processing options
|
|
57
|
+
*/
|
|
58
|
+
export interface ContentProcessingOptions {
|
|
59
|
+
stripCodeFences?: boolean;
|
|
60
|
+
stripPatterns?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parse content based on format
|
|
64
|
+
* @param content - Raw content string
|
|
65
|
+
* @param format - Content format (yaml, json, csv, table, text)
|
|
66
|
+
* @param options - Processing options
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseInlineContent(content: string, format: string, options?: ContentProcessingOptions): unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Inline Datasource class
|
|
71
|
+
*/
|
|
72
|
+
export declare class InlineDatasource implements Datasource {
|
|
73
|
+
readonly type = "inline";
|
|
74
|
+
readonly format: string;
|
|
75
|
+
readonly documentPath: string;
|
|
76
|
+
readonly startLine: number;
|
|
77
|
+
readonly endLine: number;
|
|
78
|
+
readonly byteSize: number;
|
|
79
|
+
/** Internal data - exposed for variable resolution */
|
|
80
|
+
readonly data: unknown;
|
|
81
|
+
private _isObject;
|
|
82
|
+
constructor(data: unknown, format: string, documentPath: string, startLine: number, endLine: number, byteSize: number);
|
|
83
|
+
/**
|
|
84
|
+
* Query is not fully supported for inline datasources
|
|
85
|
+
* Returns all data or filters by simple conditions
|
|
86
|
+
*/
|
|
87
|
+
query(_sql: string, _params?: unknown[]): Promise<QueryResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Get all data - returns array for Datasource interface compatibility
|
|
90
|
+
*/
|
|
91
|
+
getAll(): Promise<QueryResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Get raw data (object or array)
|
|
94
|
+
*/
|
|
95
|
+
getRawData(): unknown;
|
|
96
|
+
/**
|
|
97
|
+
* Get value at dot-path
|
|
98
|
+
*/
|
|
99
|
+
get(path: string): Promise<unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* Check if datasource is object type (vs array)
|
|
102
|
+
*/
|
|
103
|
+
isObjectType(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Close (no-op for inline)
|
|
106
|
+
*/
|
|
107
|
+
close(): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Merge another value into this datasource at a path
|
|
110
|
+
*/
|
|
111
|
+
merge(path: string, value: unknown): void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build inline datasources from parsed markers
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildInlineDatasources(parsedData: ParsedInlineData[], documentPath: string, config?: InlineDatasourceConfig): Map<string, InlineDatasource>;
|
|
117
|
+
//# sourceMappingURL=inline-datasource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-datasource.d.ts","sourceRoot":"","sources":["../../src/core/inline-datasource.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IACnD,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,iBAAiB,CAAC;IACtD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qDAAqD;IACrD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAuBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAM9D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE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