@promptlycms/prompts 0.6.1-canary.8246366 → 0.6.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/cli.js +50 -56
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -365,57 +365,63 @@ var generateTypeDeclaration = (prompts, composers = []) => {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
lines.push(" }");
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
} else {
|
|
379
|
-
versions.push(`'${composer.version}'`);
|
|
380
|
-
}
|
|
381
|
-
lines.push(` ${composerKey}: {`);
|
|
382
|
-
if (versions.length === 1) {
|
|
383
|
-
if (variables.length === 0) {
|
|
384
|
-
lines.push(` [V in ${versions[0]}]: Record<string, never>;`);
|
|
385
|
-
} else {
|
|
386
|
-
lines.push(` [V in ${versions[0]}]: {`);
|
|
387
|
-
for (const v of variables) {
|
|
388
|
-
lines.push(` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`);
|
|
368
|
+
if (composers.length > 0) {
|
|
369
|
+
lines.push(" interface ComposerVariableMap {");
|
|
370
|
+
for (const composer of composers) {
|
|
371
|
+
const variables = extractComposerVariables(composer);
|
|
372
|
+
const composerKey = typePropertyKey(composer.composerId);
|
|
373
|
+
const schemaMap = buildSchemaMap(composer.config.schema);
|
|
374
|
+
const versions = ["'latest'"];
|
|
375
|
+
if (composer.publishedVersions) {
|
|
376
|
+
for (const pv of composer.publishedVersions) {
|
|
377
|
+
versions.push(`'${pv.version}'`);
|
|
389
378
|
}
|
|
390
|
-
|
|
379
|
+
} else {
|
|
380
|
+
versions.push(`'${composer.version}'`);
|
|
391
381
|
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
382
|
+
lines.push(` ${composerKey}: {`);
|
|
383
|
+
if (versions.length === 1) {
|
|
384
|
+
if (variables.length === 0) {
|
|
385
|
+
lines.push(` [V in ${versions[0]}]: Record<string, never>;`);
|
|
386
|
+
} else {
|
|
387
|
+
lines.push(` [V in ${versions[0]}]: {`);
|
|
388
|
+
for (const v of variables) {
|
|
389
|
+
lines.push(
|
|
390
|
+
` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
lines.push(" };");
|
|
394
|
+
}
|
|
396
395
|
} else {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
lines.push(`
|
|
396
|
+
const versionUnion = versions.join(" | ");
|
|
397
|
+
if (variables.length === 0) {
|
|
398
|
+
lines.push(` [V in ${versionUnion}]: Record<string, never>;`);
|
|
399
|
+
} else {
|
|
400
|
+
lines.push(` [V in ${versionUnion}]: {`);
|
|
401
|
+
for (const v of variables) {
|
|
402
|
+
lines.push(
|
|
403
|
+
` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
lines.push(" };");
|
|
400
407
|
}
|
|
401
|
-
lines.push(" };");
|
|
402
408
|
}
|
|
409
|
+
lines.push(" };");
|
|
403
410
|
}
|
|
404
|
-
lines.push("
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
lines.push(` ${composerKey}: ${union};`);
|
|
411
|
+
lines.push(" }");
|
|
412
|
+
lines.push(" interface ComposerPromptMap {");
|
|
413
|
+
for (const composer of composers) {
|
|
414
|
+
const names = extractComposerPromptNames(composer);
|
|
415
|
+
const composerKey = typePropertyKey(composer.composerId);
|
|
416
|
+
if (names.length === 0) {
|
|
417
|
+
lines.push(` ${composerKey}: never;`);
|
|
418
|
+
} else {
|
|
419
|
+
const union = names.map((n) => `'${n}'`).join(" | ");
|
|
420
|
+
lines.push(` ${composerKey}: ${union};`);
|
|
421
|
+
}
|
|
416
422
|
}
|
|
423
|
+
lines.push(" }");
|
|
417
424
|
}
|
|
418
|
-
lines.push(" }");
|
|
419
425
|
lines.push("}");
|
|
420
426
|
lines.push("");
|
|
421
427
|
return lines.join("\n");
|
|
@@ -467,19 +473,7 @@ var warnMissingProviders = (prompts, composers = []) => {
|
|
|
467
473
|
var generate = async (apiKey, outputPath, baseUrl) => {
|
|
468
474
|
const [prompts, composers] = await Promise.all([
|
|
469
475
|
fetchAllPrompts(apiKey, baseUrl),
|
|
470
|
-
fetchAllComposers(apiKey, baseUrl).catch((
|
|
471
|
-
if (err instanceof PromptlyError) {
|
|
472
|
-
console.warn(
|
|
473
|
-
` Warning: failed to fetch composers (${err.code}, HTTP ${err.status}): ${err.message}`
|
|
474
|
-
);
|
|
475
|
-
console.warn(
|
|
476
|
-
" Composer types will be omitted from promptly-env.d.ts."
|
|
477
|
-
);
|
|
478
|
-
} else {
|
|
479
|
-
console.warn(` Warning: failed to fetch composers: ${String(err)}`);
|
|
480
|
-
}
|
|
481
|
-
return [];
|
|
482
|
-
})
|
|
476
|
+
fetchAllComposers(apiKey, baseUrl).catch(() => [])
|
|
483
477
|
]);
|
|
484
478
|
if (prompts.length === 0 && composers.length === 0) {
|
|
485
479
|
console.log(" No prompts or composers found for this API key.");
|