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