algolia-codegen 0.1.0 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,18 +17,581 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var src_exports = {};
22
32
  __export(src_exports, {
23
- main: () => main
33
+ main: () => main,
34
+ validateConfig: () => validateConfig,
35
+ validateGeneratorConfig: () => validateGeneratorConfig,
36
+ validateUrlSchema: () => validateUrlSchema
24
37
  });
25
38
  module.exports = __toCommonJS(src_exports);
26
- var main = () => {
27
- console.log("Main!");
39
+
40
+ // src/utils/config-loader.ts
41
+ var import_fs = require("fs");
42
+ var import_path = require("path");
43
+ var import_url = require("url");
44
+
45
+ // src/utils/validations/generator-config.ts
46
+ function validateGeneratorConfig(config, path) {
47
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
48
+ throw new Error(
49
+ `Invalid generator config: must be an object
50
+ Path: ${path}`
51
+ );
52
+ }
53
+ const cfg = config;
54
+ const requiredFields = [
55
+ "appId",
56
+ "searchKey",
57
+ "indexName"
58
+ ];
59
+ for (const field of requiredFields) {
60
+ if (!(field in cfg)) {
61
+ throw new Error(
62
+ `Invalid generator config: missing required property '${field}'
63
+ Path: ${path}`
64
+ );
65
+ }
66
+ if (typeof cfg[field] !== "string") {
67
+ throw new Error(
68
+ `Invalid generator config: '${field}' must be a string
69
+ Path: ${path}
70
+ Received: ${typeof cfg[field]}`
71
+ );
72
+ }
73
+ }
74
+ if ("prefix" in cfg && cfg.prefix !== void 0 && typeof cfg.prefix !== "string") {
75
+ throw new Error(
76
+ `Invalid generator config: 'prefix' must be a string or undefined
77
+ Path: ${path}
78
+ Received: ${typeof cfg.prefix}`
79
+ );
80
+ }
81
+ if ("postfix" in cfg && cfg.postfix !== void 0 && typeof cfg.postfix !== "string") {
82
+ throw new Error(
83
+ `Invalid generator config: 'postfix' must be a string or undefined
84
+ Path: ${path}
85
+ Received: ${typeof cfg.postfix}`
86
+ );
87
+ }
88
+ }
89
+
90
+ // src/utils/validations/url-schema.ts
91
+ function validateUrlSchema(urlSchema, path) {
92
+ if (typeof urlSchema !== "object" || urlSchema === null || Array.isArray(urlSchema)) {
93
+ throw new Error(
94
+ `Invalid generates entry: must be an object
95
+ Path: ${path}`
96
+ );
97
+ }
98
+ const schema = urlSchema;
99
+ for (const [filePath, generatorConfig] of Object.entries(schema)) {
100
+ if (typeof filePath !== "string") {
101
+ throw new Error(
102
+ `Invalid generates entry: file path must be a string
103
+ Path: ${path}[${filePath}]`
104
+ );
105
+ }
106
+ validateGeneratorConfig(generatorConfig, `${path}["${filePath}"]`);
107
+ }
108
+ }
109
+
110
+ // src/utils/validations/config.ts
111
+ function validateConfig(config, configPath) {
112
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
113
+ throw new Error(
114
+ `Invalid config: must be an object
115
+ Config file: ${configPath}`
116
+ );
117
+ }
118
+ const cfg = config;
119
+ if (!("overwrite" in cfg)) {
120
+ throw new Error(
121
+ `Invalid config: missing required property 'overwrite'
122
+ Config file: ${configPath}`
123
+ );
124
+ }
125
+ if (typeof cfg.overwrite !== "boolean") {
126
+ throw new Error(
127
+ `Invalid config: 'overwrite' must be a boolean
128
+ Config file: ${configPath}
129
+ Received: ${typeof cfg.overwrite}`
130
+ );
131
+ }
132
+ if (!("generates" in cfg)) {
133
+ throw new Error(
134
+ `Invalid config: missing required property 'generates'
135
+ Config file: ${configPath}`
136
+ );
137
+ }
138
+ const generates = cfg.generates;
139
+ if (Array.isArray(generates)) {
140
+ generates.forEach((item, index) => {
141
+ validateUrlSchema(item, `${configPath}[generates][${index}]`);
142
+ });
143
+ } else if (typeof generates === "object" && generates !== null) {
144
+ validateUrlSchema(generates, `${configPath}[generates]`);
145
+ } else {
146
+ throw new Error(
147
+ `Invalid config: 'generates' must be an object or an array of objects
148
+ Config file: ${configPath}
149
+ Received: ${typeof generates}`
150
+ );
151
+ }
152
+ }
153
+
154
+ // src/utils/config-loader.ts
155
+ async function loadConfig(configPath) {
156
+ const defaultConfigPath = "algolia-codegen.ts";
157
+ const finalConfigPath = configPath || defaultConfigPath;
158
+ const resolvedPath = (0, import_path.resolve)(process.cwd(), finalConfigPath);
159
+ if (!(0, import_fs.existsSync)(resolvedPath)) {
160
+ throw new Error(
161
+ `Config file not found: ${resolvedPath}
162
+ Please create a config file or specify a different path using --config option.`
163
+ );
164
+ }
165
+ const configUrl = (0, import_url.pathToFileURL)(resolvedPath).href;
166
+ let configModule;
167
+ try {
168
+ configModule = await import(configUrl);
169
+ } catch (importError) {
170
+ const jsPath = resolvedPath.replace(/\.ts$/, ".js");
171
+ if ((0, import_fs.existsSync)(jsPath)) {
172
+ const jsUrl = (0, import_url.pathToFileURL)(jsPath).href;
173
+ try {
174
+ configModule = await import(jsUrl);
175
+ } catch (jsImportError) {
176
+ throw new Error(
177
+ `Failed to import config file: ${resolvedPath}
178
+ Tried both .ts and .js extensions.
179
+ Error: ${jsImportError instanceof Error ? jsImportError.message : String(jsImportError)}
180
+ Note: If using TypeScript config, you may need to compile it first or use a tool like tsx.`
181
+ );
182
+ }
183
+ } else {
184
+ const errorMessage = importError instanceof Error ? importError.message : String(importError);
185
+ const isTypeScriptError = resolvedPath.endsWith(".ts") && (errorMessage.includes("Cannot find module") || errorMessage.includes("Unknown file extension"));
186
+ throw new Error(
187
+ `Failed to import config file: ${resolvedPath}
188
+ ` + (isTypeScriptError ? `Node.js cannot directly import TypeScript files.
189
+ Please either:
190
+ 1. Compile your config to JavaScript (.js)
191
+ 2. Use a tool like tsx to run the CLI: tsx algolia-codegen
192
+ 3. Or use a JavaScript config file instead
193
+ ` : `Error: ${errorMessage}`)
194
+ );
195
+ }
196
+ }
197
+ if (!configModule.default) {
198
+ throw new Error(
199
+ `Config file does not export a default object: ${resolvedPath}
200
+ Please ensure your config file exports a default object: export default { ... }`
201
+ );
202
+ }
203
+ const config = configModule.default;
204
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
205
+ throw new Error(
206
+ `Config file default export must be an object: ${resolvedPath}
207
+ Received: ${typeof config}`
208
+ );
209
+ }
210
+ validateConfig(config, resolvedPath);
211
+ return config;
212
+ }
213
+
214
+ // src/utils/fetch-algolia-data.ts
215
+ var import_algoliasearch = __toESM(require("algoliasearch"), 1);
216
+ var import_fs2 = require("fs");
217
+ var import_path2 = require("path");
218
+
219
+ // src/utils/generate-typescript-types.ts
220
+ var TypeGenerator = class {
221
+ typeMap = /* @__PURE__ */ new Map();
222
+ generatedTypes = /* @__PURE__ */ new Set();
223
+ idValueTypes = /* @__PURE__ */ new Set();
224
+ prefix;
225
+ postfix;
226
+ indexName;
227
+ constructor(config) {
228
+ this.prefix = config.prefix || "";
229
+ this.postfix = config.postfix || "";
230
+ this.indexName = config.indexName;
231
+ }
232
+ /**
233
+ * Convert a value to its TypeScript type representation
234
+ */
235
+ inferType(value, path = []) {
236
+ if (value === null || value === void 0) {
237
+ return { type: "unknown", isOptional: true, isArray: false, nestedTypes: /* @__PURE__ */ new Map() };
238
+ }
239
+ if (Array.isArray(value)) {
240
+ if (value.length === 0) {
241
+ return { type: "unknown[]", isOptional: false, isArray: true, nestedTypes: /* @__PURE__ */ new Map() };
242
+ }
243
+ const itemTypes = value.map((item, idx) => this.inferType(item, [...path, `[${idx}]`]));
244
+ if (this.isIdValuePattern(value)) {
245
+ const firstItem = value[0];
246
+ const valueType = this.inferType(firstItem.value, [...path, "[0].value"]);
247
+ const idValueTypeName = `${this.prefix}IdValue`;
248
+ this.idValueTypes.add(idValueTypeName);
249
+ const typeString = valueType.type !== "string" ? `${idValueTypeName}<${valueType.type}>` : idValueTypeName;
250
+ return {
251
+ type: `${typeString}[]`,
252
+ isOptional: false,
253
+ isArray: true,
254
+ nestedTypes: /* @__PURE__ */ new Map()
255
+ };
256
+ }
257
+ const firstType = itemTypes[0];
258
+ const allSameType = itemTypes.every(
259
+ (t) => t.type === firstType.type && !t.isArray && t.nestedTypes.size === firstType.nestedTypes.size
260
+ );
261
+ if (allSameType && !firstType.isArray) {
262
+ return {
263
+ type: `${firstType.type}[]`,
264
+ isOptional: false,
265
+ isArray: true,
266
+ nestedTypes: firstType.nestedTypes
267
+ };
268
+ }
269
+ const uniqueTypes = Array.from(new Set(itemTypes.map((t) => t.type)));
270
+ const unionType = uniqueTypes.length === 1 ? uniqueTypes[0] : uniqueTypes.join(" | ");
271
+ return {
272
+ type: `${unionType}[]`,
273
+ isOptional: false,
274
+ isArray: true,
275
+ nestedTypes: /* @__PURE__ */ new Map()
276
+ };
277
+ }
278
+ if (typeof value === "object") {
279
+ const obj = value;
280
+ const typeName = this.generateTypeName(path);
281
+ const nestedTypes = /* @__PURE__ */ new Map();
282
+ for (const [key, val] of Object.entries(obj)) {
283
+ nestedTypes.set(key, this.inferType(val, [...path, key]));
284
+ }
285
+ if (!this.generatedTypes.has(typeName)) {
286
+ this.generatedTypes.add(typeName);
287
+ this.typeMap.set(typeName, this.generateInterface(typeName, nestedTypes, obj));
288
+ }
289
+ return {
290
+ type: typeName,
291
+ isOptional: false,
292
+ isArray: false,
293
+ nestedTypes
294
+ };
295
+ }
296
+ const jsType = typeof value;
297
+ let tsType;
298
+ if (jsType === "number") {
299
+ tsType = "number";
300
+ } else if (jsType === "boolean") {
301
+ tsType = "boolean";
302
+ } else {
303
+ tsType = "string";
304
+ }
305
+ return { type: tsType, isOptional: false, isArray: false, nestedTypes: /* @__PURE__ */ new Map() };
306
+ }
307
+ /**
308
+ * Check if an array follows the AlgoliaIdValue pattern
309
+ */
310
+ isIdValuePattern(arr) {
311
+ return arr.length > 0 && arr.every(
312
+ (item) => typeof item === "object" && item !== null && "id" in item && "value" in item && typeof item.id === "string"
313
+ );
314
+ }
315
+ /**
316
+ * Generate a TypeScript type name from a path
317
+ */
318
+ generateTypeName(path) {
319
+ if (path.length === 0) {
320
+ return `${this.prefix}Hit${this.postfix}`;
321
+ }
322
+ const lastPart = path[path.length - 1];
323
+ const parts = lastPart.replace(/[\[\]]/g, "").split(/[-_\s]+/).filter(Boolean);
324
+ const pascalCase = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("");
325
+ if (path.length > 1) {
326
+ const parent = path[path.length - 2];
327
+ if (parent.includes("Info")) {
328
+ return `${this.prefix}${pascalCase}Info${this.postfix}`;
329
+ }
330
+ }
331
+ return `${this.prefix}${pascalCase}${this.postfix}`;
332
+ }
333
+ /**
334
+ * Generate TypeScript interface code
335
+ */
336
+ generateInterface(typeName, nestedTypes, sampleObj) {
337
+ const lines = [];
338
+ const description = this.getTypeDescription(typeName);
339
+ lines.push("/**");
340
+ lines.push(` * ${description}`);
341
+ lines.push(" */");
342
+ lines.push(`export interface ${typeName} {`);
343
+ const sortedKeys = Array.from(nestedTypes.keys()).sort();
344
+ for (const key of sortedKeys) {
345
+ const typeInfo = nestedTypes.get(key);
346
+ const value = sampleObj[key];
347
+ const isOptional = typeInfo.isOptional || value === null || value === void 0;
348
+ const optionalMarker = isOptional ? "?" : "";
349
+ let typeString = typeInfo.type;
350
+ if (typeInfo.isArray && !typeString.endsWith("[]")) {
351
+ typeString = `${typeString}[]`;
352
+ }
353
+ if (value === null && typeString !== "null") {
354
+ typeString = `${typeString} | null`;
355
+ }
356
+ lines.push(` ${key}${optionalMarker}: ${typeString};`);
357
+ }
358
+ lines.push("}");
359
+ lines.push("");
360
+ return lines.join("\n");
361
+ }
362
+ /**
363
+ * Get a description for a type based on its name
364
+ */
365
+ getTypeDescription(typeName) {
366
+ const withoutPrefix = typeName.replace(new RegExp(`^${this.prefix}`), "");
367
+ const withoutPostfix = withoutPrefix.replace(new RegExp(`${this.postfix}$`), "");
368
+ const readable = withoutPostfix.replace(/([A-Z])/g, " $1").trim().toLowerCase();
369
+ return readable.charAt(0).toUpperCase() + readable.slice(1) + " structure in Algolia";
370
+ }
371
+ /**
372
+ * Collect all types that need to be generated
373
+ */
374
+ collectTypes(typeInfo, typesToGenerate) {
375
+ if (typeInfo.nestedTypes.size > 0 && !typeInfo.isArray) {
376
+ typesToGenerate.add(typeInfo.type);
377
+ for (const nestedTypeInfo of typeInfo.nestedTypes.values()) {
378
+ this.collectTypes(nestedTypeInfo, typesToGenerate);
379
+ }
380
+ }
381
+ }
382
+ /**
383
+ * Get dependencies for a type (types that it references)
384
+ */
385
+ getTypeDependencies(typeName) {
386
+ const typeCode = this.typeMap.get(typeName);
387
+ if (!typeCode) return [];
388
+ const dependencies = [];
389
+ const importRegex = new RegExp(`(${this.prefix}\\w+)`, "g");
390
+ const matches = typeCode.matchAll(importRegex);
391
+ for (const match of matches) {
392
+ const depTypeName = match[1];
393
+ if (depTypeName !== typeName && this.generatedTypes.has(depTypeName)) {
394
+ dependencies.push(depTypeName);
395
+ }
396
+ }
397
+ return Array.from(new Set(dependencies));
398
+ }
399
+ /**
400
+ * Sort types by dependencies (topological sort)
401
+ */
402
+ sortTypesByDependencies(typeNames) {
403
+ const sorted = [];
404
+ const visited = /* @__PURE__ */ new Set();
405
+ const visiting = /* @__PURE__ */ new Set();
406
+ const visit = (typeName) => {
407
+ if (visiting.has(typeName)) {
408
+ return;
409
+ }
410
+ if (visited.has(typeName)) {
411
+ return;
412
+ }
413
+ visiting.add(typeName);
414
+ const dependencies = this.getTypeDependencies(typeName);
415
+ for (const dep of dependencies) {
416
+ visit(dep);
417
+ }
418
+ visiting.delete(typeName);
419
+ visited.add(typeName);
420
+ sorted.push(typeName);
421
+ };
422
+ for (const typeName of typeNames) {
423
+ visit(typeName);
424
+ }
425
+ return sorted;
426
+ }
427
+ /**
428
+ * Generate IdValue type definition (generic type)
429
+ */
430
+ generateIdValueType(typeName) {
431
+ return `export type ${typeName}<T = string> = {
432
+ id: string;
433
+ value: T;
434
+ };
435
+
436
+ `;
437
+ }
438
+ /**
439
+ * Generate all types as a single file content
440
+ */
441
+ generateAllTypes(sampleHit) {
442
+ const rootType = this.inferType(sampleHit, []);
443
+ const typesToGenerate = /* @__PURE__ */ new Set();
444
+ this.collectTypes(rootType, typesToGenerate);
445
+ const rootTypeName = rootType.type;
446
+ if (rootType.nestedTypes.size > 0 && !rootType.isArray) {
447
+ typesToGenerate.add(rootTypeName);
448
+ }
449
+ const sortedTypes = this.sortTypesByDependencies(Array.from(typesToGenerate));
450
+ const lines = [];
451
+ lines.push("/**");
452
+ lines.push(` * Generated TypeScript types for Algolia index: ${this.indexName}`);
453
+ lines.push(" * This file is auto-generated. Do not edit manually.");
454
+ lines.push(" */");
455
+ lines.push("");
456
+ if (this.idValueTypes.size > 0) {
457
+ const idValueTypeName = Array.from(this.idValueTypes)[0];
458
+ lines.push(this.generateIdValueType(idValueTypeName));
459
+ }
460
+ for (const typeName of sortedTypes) {
461
+ const typeCode = this.typeMap.get(typeName);
462
+ if (typeCode) {
463
+ lines.push(typeCode);
464
+ }
465
+ }
466
+ return lines.join("\n");
467
+ }
468
+ };
469
+ function generateTypeScriptTypes(sampleHit, config) {
470
+ const generator = new TypeGenerator(config);
471
+ return generator.generateAllTypes(sampleHit);
472
+ }
473
+
474
+ // src/utils/fetch-algolia-data.ts
475
+ async function fetchAlgoliaData(filePath, generatorConfig, overwrite) {
476
+ console.log(`
477
+ Processing file: ${filePath}`);
478
+ const resolvedPath = (0, import_path2.resolve)(process.cwd(), filePath);
479
+ if ((0, import_fs2.existsSync)(resolvedPath) && !overwrite) {
480
+ throw new Error(
481
+ `File already exists: ${resolvedPath}
482
+ Set overwrite: true in config to allow overwriting existing files.`
483
+ );
484
+ }
485
+ console.log(`Connecting to Algolia...`);
486
+ console.log(`App ID: ${generatorConfig.appId}`);
487
+ let client;
488
+ try {
489
+ client = (0, import_algoliasearch.default)(
490
+ generatorConfig.appId,
491
+ generatorConfig.searchKey
492
+ );
493
+ } catch (error) {
494
+ throw new Error(
495
+ `Failed to initialize Algolia client: ${error instanceof Error ? error.message : String(error)}`
496
+ );
497
+ }
498
+ console.log(`Fetching sample record from index: ${generatorConfig.indexName}`);
499
+ let results;
500
+ try {
501
+ results = await client.search([
502
+ {
503
+ indexName: generatorConfig.indexName,
504
+ query: "",
505
+ params: {
506
+ hitsPerPage: 1
507
+ }
508
+ }
509
+ ]);
510
+ } catch (error) {
511
+ let errorMessage;
512
+ if (error instanceof Error) {
513
+ errorMessage = error.message;
514
+ } else if (error && typeof error === "object") {
515
+ const errorObj = error;
516
+ if (errorObj.message) {
517
+ errorMessage = String(errorObj.message);
518
+ } else if (errorObj.status) {
519
+ errorMessage = `HTTP ${errorObj.status}: ${errorObj.statusText || "Unknown error"}`;
520
+ } else {
521
+ try {
522
+ errorMessage = JSON.stringify(error, null, 2);
523
+ } catch {
524
+ errorMessage = String(error);
525
+ }
526
+ }
527
+ } else {
528
+ errorMessage = String(error);
529
+ }
530
+ throw new Error(
531
+ `Failed to fetch data from Algolia index "${generatorConfig.indexName}" (App ID: ${generatorConfig.appId}): ${errorMessage}`
532
+ );
533
+ }
534
+ if (!results.results || results.results.length === 0) {
535
+ throw new Error(`No results found in Algolia index: ${generatorConfig.indexName}`);
536
+ }
537
+ const result = results.results[0];
538
+ if (!("hits" in result) || !result.hits || result.hits.length === 0) {
539
+ throw new Error(`No hits found in Algolia index: ${generatorConfig.indexName}`);
540
+ }
541
+ const sampleHit = result.hits[0];
542
+ console.log("Sample record fetched successfully");
543
+ console.log(`ObjectID: ${sampleHit.objectID || "N/A"}`);
544
+ const fileContent = generateTypeScriptTypes(sampleHit, generatorConfig);
545
+ const dir = (0, import_path2.dirname)(resolvedPath);
546
+ if (!(0, import_fs2.existsSync)(dir)) {
547
+ (0, import_fs2.mkdirSync)(dir, { recursive: true });
548
+ }
549
+ (0, import_fs2.writeFileSync)(resolvedPath, fileContent, "utf-8");
550
+ console.log(`Generated file: ${filePath}`);
551
+ }
552
+
553
+ // src/index.ts
554
+ var main = async (configPath) => {
555
+ try {
556
+ const config = await loadConfig(configPath);
557
+ console.log("Config loaded successfully");
558
+ const generatesArray = Array.isArray(config.generates) ? config.generates : [config.generates];
559
+ for (const urlSchema of generatesArray) {
560
+ for (const [filePath, generatorConfig] of Object.entries(urlSchema)) {
561
+ try {
562
+ await fetchAlgoliaData(filePath, generatorConfig, config.overwrite);
563
+ } catch (error) {
564
+ console.error(`
565
+ Error processing file: ${filePath}`);
566
+ if (error instanceof Error) {
567
+ console.error(error.message);
568
+ if (error.stack) {
569
+ console.error(error.stack);
570
+ }
571
+ } else {
572
+ try {
573
+ console.error(JSON.stringify(error, null, 2));
574
+ } catch {
575
+ console.error(String(error));
576
+ }
577
+ }
578
+ }
579
+ }
580
+ }
581
+ } catch (error) {
582
+ console.error("Error loading config:");
583
+ if (error instanceof Error) {
584
+ console.error(error.message);
585
+ } else {
586
+ console.error(String(error));
587
+ }
588
+ process.exit(1);
589
+ }
28
590
  };
29
591
  // Annotate the CommonJS export names for ESM import in node:
30
592
  0 && (module.exports = {
31
- main
593
+ main,
594
+ validateConfig,
595
+ validateGeneratorConfig,
596
+ validateUrlSchema
32
597
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,37 @@
1
- declare const main: () => void;
1
+ type InstanceOrArray<T> = T | T[];
2
+ type UrlSchema = {
3
+ [url: string]: AlgoliaCodegenGeneratorConfig;
4
+ };
5
+ type AlgoliaCodegenGeneratorConfig = {
6
+ appId: string;
7
+ searchKey: string;
8
+ indexName: string;
9
+ prefix?: string;
10
+ postfix?: string;
11
+ };
12
+ type AlgoliaCodegenConfig = {
13
+ overwrite: boolean;
14
+ generates: InstanceOrArray<UrlSchema>;
15
+ };
2
16
 
3
- export { main };
17
+ /**
18
+ * Validates the structure of AlgoliaCodegenConfig
19
+ */
20
+ declare function validateConfig(config: unknown, configPath: string): asserts config is AlgoliaCodegenConfig;
21
+
22
+ /**
23
+ * Validates a UrlSchema object
24
+ */
25
+ declare function validateUrlSchema(urlSchema: unknown, path: string): asserts urlSchema is UrlSchema;
26
+
27
+ /**
28
+ * Validates AlgoliaCodegenGeneratorConfig
29
+ */
30
+ declare function validateGeneratorConfig(config: unknown, path: string): asserts config is AlgoliaCodegenGeneratorConfig;
31
+
32
+ /**
33
+ * Main function to load and process configuration
34
+ */
35
+ declare const main: (configPath?: string) => Promise<void>;
36
+
37
+ export { type AlgoliaCodegenConfig, type AlgoliaCodegenGeneratorConfig, type InstanceOrArray, type UrlSchema, main, validateConfig, validateGeneratorConfig, validateUrlSchema };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,37 @@
1
- declare const main: () => void;
1
+ type InstanceOrArray<T> = T | T[];
2
+ type UrlSchema = {
3
+ [url: string]: AlgoliaCodegenGeneratorConfig;
4
+ };
5
+ type AlgoliaCodegenGeneratorConfig = {
6
+ appId: string;
7
+ searchKey: string;
8
+ indexName: string;
9
+ prefix?: string;
10
+ postfix?: string;
11
+ };
12
+ type AlgoliaCodegenConfig = {
13
+ overwrite: boolean;
14
+ generates: InstanceOrArray<UrlSchema>;
15
+ };
2
16
 
3
- export { main };
17
+ /**
18
+ * Validates the structure of AlgoliaCodegenConfig
19
+ */
20
+ declare function validateConfig(config: unknown, configPath: string): asserts config is AlgoliaCodegenConfig;
21
+
22
+ /**
23
+ * Validates a UrlSchema object
24
+ */
25
+ declare function validateUrlSchema(urlSchema: unknown, path: string): asserts urlSchema is UrlSchema;
26
+
27
+ /**
28
+ * Validates AlgoliaCodegenGeneratorConfig
29
+ */
30
+ declare function validateGeneratorConfig(config: unknown, path: string): asserts config is AlgoliaCodegenGeneratorConfig;
31
+
32
+ /**
33
+ * Main function to load and process configuration
34
+ */
35
+ declare const main: (configPath?: string) => Promise<void>;
36
+
37
+ export { type AlgoliaCodegenConfig, type AlgoliaCodegenGeneratorConfig, type InstanceOrArray, type UrlSchema, main, validateConfig, validateGeneratorConfig, validateUrlSchema };
package/dist/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import {
2
- main
3
- } from "./chunk-U33HDFDI.js";
2
+ main,
3
+ validateConfig,
4
+ validateGeneratorConfig,
5
+ validateUrlSchema
6
+ } from "./chunk-4FWQJC54.js";
4
7
  export {
5
- main
8
+ main,
9
+ validateConfig,
10
+ validateGeneratorConfig,
11
+ validateUrlSchema
6
12
  };