@lssm/module.contractspec-workspace 1.41.0 → 1.42.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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/ai/code-generation.d.ts +28 -0
- package/dist/ai/code-generation.d.ts.map +1 -0
- package/dist/ai/code-generation.js +51 -13
- package/dist/ai/code-generation.js.map +1 -0
- package/dist/ai/spec-creation.d.ts +27 -0
- package/dist/ai/spec-creation.d.ts.map +1 -0
- package/dist/ai/spec-creation.js +51 -18
- package/dist/ai/spec-creation.js.map +1 -0
- package/dist/analysis/deps/graph.d.ts +34 -0
- package/dist/analysis/deps/graph.d.ts.map +1 -0
- package/dist/analysis/deps/graph.js +85 -2
- package/dist/analysis/deps/graph.js.map +1 -0
- package/dist/analysis/deps/parse-imports.d.ts +17 -0
- package/dist/analysis/deps/parse-imports.d.ts.map +1 -0
- package/dist/analysis/deps/parse-imports.js +31 -1
- package/dist/analysis/deps/parse-imports.js.map +1 -0
- package/dist/analysis/diff/deep-diff.d.ts +33 -0
- package/dist/analysis/diff/deep-diff.d.ts.map +1 -0
- package/dist/analysis/diff/deep-diff.js +114 -0
- package/dist/analysis/diff/deep-diff.js.map +1 -0
- package/dist/analysis/diff/semantic.d.ts +11 -0
- package/dist/analysis/diff/semantic.d.ts.map +1 -0
- package/dist/analysis/diff/semantic.js +97 -1
- package/dist/analysis/diff/semantic.js.map +1 -0
- package/dist/analysis/feature-scan.d.ts +15 -0
- package/dist/analysis/feature-scan.d.ts.map +1 -0
- package/dist/analysis/feature-scan.js +152 -1
- package/dist/analysis/feature-scan.js.map +1 -0
- package/dist/analysis/grouping.d.ts +79 -0
- package/dist/analysis/grouping.d.ts.map +1 -0
- package/dist/analysis/grouping.js +115 -0
- package/dist/analysis/grouping.js.map +1 -0
- package/dist/analysis/impact/classifier.d.ts +19 -0
- package/dist/analysis/impact/classifier.d.ts.map +1 -0
- package/dist/analysis/impact/classifier.js +135 -0
- package/dist/analysis/impact/classifier.js.map +1 -0
- package/dist/analysis/impact/index.js +2 -0
- package/dist/analysis/impact/rules.d.ts +35 -0
- package/dist/analysis/impact/rules.d.ts.map +1 -0
- package/dist/analysis/impact/rules.js +154 -0
- package/dist/analysis/impact/rules.js.map +1 -0
- package/dist/analysis/impact/types.d.ts +95 -0
- package/dist/analysis/impact/types.d.ts.map +1 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/snapshot/index.js +2 -0
- package/dist/analysis/snapshot/normalizer.d.ts +36 -0
- package/dist/analysis/snapshot/normalizer.d.ts.map +1 -0
- package/dist/analysis/snapshot/normalizer.js +66 -0
- package/dist/analysis/snapshot/normalizer.js.map +1 -0
- package/dist/analysis/snapshot/snapshot.d.ts +18 -0
- package/dist/analysis/snapshot/snapshot.d.ts.map +1 -0
- package/dist/analysis/snapshot/snapshot.js +163 -0
- package/dist/analysis/snapshot/snapshot.js.map +1 -0
- package/dist/analysis/snapshot/types.d.ts +80 -0
- package/dist/analysis/snapshot/types.d.ts.map +1 -0
- package/dist/analysis/spec-scan.d.ts +34 -0
- package/dist/analysis/spec-scan.d.ts.map +1 -0
- package/dist/analysis/spec-scan.js +349 -1
- package/dist/analysis/spec-scan.js.map +1 -0
- package/dist/analysis/validate/spec-structure.d.ts +29 -0
- package/dist/analysis/validate/spec-structure.d.ts.map +1 -0
- package/dist/analysis/validate/spec-structure.js +139 -1
- package/dist/analysis/validate/spec-structure.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +32 -1
- package/dist/templates/app-config.d.ts +7 -0
- package/dist/templates/app-config.d.ts.map +1 -0
- package/dist/templates/app-config.js +101 -28
- package/dist/templates/app-config.js.map +1 -0
- package/dist/templates/data-view.d.ts +7 -0
- package/dist/templates/data-view.d.ts.map +1 -0
- package/dist/templates/data-view.js +42 -27
- package/dist/templates/data-view.js.map +1 -0
- package/dist/templates/event.d.ts +11 -0
- package/dist/templates/event.d.ts.map +1 -0
- package/dist/templates/event.js +31 -14
- package/dist/templates/event.js.map +1 -0
- package/dist/templates/experiment.d.ts +7 -0
- package/dist/templates/experiment.d.ts.map +1 -0
- package/dist/templates/experiment.js +77 -51
- package/dist/templates/experiment.js.map +1 -0
- package/dist/templates/handler.d.ts +20 -0
- package/dist/templates/handler.d.ts.map +1 -0
- package/dist/templates/handler.js +50 -17
- package/dist/templates/handler.js.map +1 -0
- package/dist/templates/integration-utils.js +98 -26
- package/dist/templates/integration-utils.js.map +1 -0
- package/dist/templates/integration.d.ts +7 -0
- package/dist/templates/integration.d.ts.map +1 -0
- package/dist/templates/integration.js +47 -23
- package/dist/templates/integration.js.map +1 -0
- package/dist/templates/knowledge.d.ts +7 -0
- package/dist/templates/knowledge.d.ts.map +1 -0
- package/dist/templates/knowledge.js +60 -19
- package/dist/templates/knowledge.js.map +1 -0
- package/dist/templates/migration.d.ts +7 -0
- package/dist/templates/migration.d.ts.map +1 -0
- package/dist/templates/migration.js +50 -26
- package/dist/templates/migration.js.map +1 -0
- package/dist/templates/operation.d.ts +11 -0
- package/dist/templates/operation.d.ts.map +1 -0
- package/dist/templates/operation.js +41 -28
- package/dist/templates/operation.js.map +1 -0
- package/dist/templates/presentation.d.ts +11 -0
- package/dist/templates/presentation.d.ts.map +1 -0
- package/dist/templates/presentation.js +46 -20
- package/dist/templates/presentation.js.map +1 -0
- package/dist/templates/telemetry.d.ts +7 -0
- package/dist/templates/telemetry.d.ts.map +1 -0
- package/dist/templates/telemetry.js +74 -53
- package/dist/templates/telemetry.js.map +1 -0
- package/dist/templates/utils.d.ts +27 -0
- package/dist/templates/utils.d.ts.map +1 -0
- package/dist/templates/utils.js +39 -1
- package/dist/templates/utils.js.map +1 -0
- package/dist/templates/workflow-runner.d.ts +16 -0
- package/dist/templates/workflow-runner.d.ts.map +1 -0
- package/dist/templates/workflow-runner.js +13 -6
- package/dist/templates/workflow-runner.js.map +1 -0
- package/dist/templates/workflow.d.ts +11 -0
- package/dist/templates/workflow.d.ts.map +1 -0
- package/dist/templates/workflow.js +51 -24
- package/dist/templates/workflow.js.map +1 -0
- package/dist/types/analysis-types.d.ts +126 -0
- package/dist/types/analysis-types.d.ts.map +1 -0
- package/dist/types/generation-types.d.ts +84 -0
- package/dist/types/generation-types.d.ts.map +1 -0
- package/dist/types/generation-types.js +21 -1
- package/dist/types/generation-types.js.map +1 -0
- package/dist/types/spec-types.d.ts +345 -0
- package/dist/types/spec-types.d.ts.map +1 -0
- package/package.json +17 -9
|
@@ -1,62 +1,88 @@
|
|
|
1
|
-
import{toPascalCase
|
|
2
|
-
${e.overrides.map(e=>` {
|
|
3
|
-
type: '${e.type}',
|
|
4
|
-
target: '${r(e.target)}',
|
|
5
|
-
${typeof e.version==`number`?`version: ${e.version},`:``}
|
|
6
|
-
}`).join(`,
|
|
7
|
-
`)}
|
|
8
|
-
],`:``;return` {
|
|
9
|
-
id: '${r(e.id)}',
|
|
10
|
-
name: '${r(e.name)}',
|
|
11
|
-
${e.description?`description: '${r(e.description)}',`:``}
|
|
12
|
-
${typeof e.weight==`number`?`weight: ${e.weight},`:``}
|
|
13
|
-
${t}
|
|
14
|
-
}`}).join(`,
|
|
15
|
-
`),o=n(t.allocation),s=t.successMetrics?.length?` successMetrics: [
|
|
16
|
-
${t.successMetrics.map(e=>` {
|
|
17
|
-
name: '${r(e.name)}',
|
|
18
|
-
telemetryEvent: { name: '${r(e.eventName)}', version: ${e.eventVersion} },
|
|
19
|
-
aggregation: '${e.aggregation}',
|
|
20
|
-
${typeof e.target==`number`?`target: ${e.target},`:``}
|
|
21
|
-
}`).join(`,
|
|
22
|
-
`)}
|
|
23
|
-
],`:``;return`import type { ExperimentSpec } from '@lssm/lib.contracts/experiments';
|
|
1
|
+
import { toPascalCase } from "./utils.js";
|
|
24
2
|
|
|
25
|
-
|
|
3
|
+
//#region src/templates/experiment.ts
|
|
4
|
+
function generateExperimentSpec(data) {
|
|
5
|
+
const specVar = toPascalCase(data.name.split(".").pop() ?? "Experiment") + "Experiment";
|
|
6
|
+
const variants = data.variants.map((variant) => {
|
|
7
|
+
const overrides = variant.overrides?.length ? ` overrides: [
|
|
8
|
+
${variant.overrides.map((override) => ` {
|
|
9
|
+
type: '${override.type}',
|
|
10
|
+
target: '${escapeString(override.target)}',
|
|
11
|
+
${typeof override.version === "number" ? `version: ${override.version},` : ""}
|
|
12
|
+
}`).join(",\n")}
|
|
13
|
+
],` : "";
|
|
14
|
+
return ` {
|
|
15
|
+
id: '${escapeString(variant.id)}',
|
|
16
|
+
name: '${escapeString(variant.name)}',
|
|
17
|
+
${variant.description ? `description: '${escapeString(variant.description)}',` : ""}
|
|
18
|
+
${typeof variant.weight === "number" ? `weight: ${variant.weight},` : ""}
|
|
19
|
+
${overrides}
|
|
20
|
+
}`;
|
|
21
|
+
}).join(",\n");
|
|
22
|
+
const allocation = renderAllocation(data.allocation);
|
|
23
|
+
const metrics = data.successMetrics?.length ? ` successMetrics: [
|
|
24
|
+
${data.successMetrics.map((metric) => ` {
|
|
25
|
+
name: '${escapeString(metric.name)}',
|
|
26
|
+
telemetryEvent: { name: '${escapeString(metric.eventName)}', version: ${metric.eventVersion} },
|
|
27
|
+
aggregation: '${metric.aggregation}',
|
|
28
|
+
${typeof metric.target === "number" ? `target: ${metric.target},` : ""}
|
|
29
|
+
}`).join(",\n")}
|
|
30
|
+
],` : "";
|
|
31
|
+
return `import type { ExperimentSpec } from '@lssm/lib.contracts/experiments';
|
|
32
|
+
|
|
33
|
+
export const ${specVar}: ExperimentSpec = {
|
|
26
34
|
meta: {
|
|
27
|
-
|
|
28
|
-
version: ${
|
|
29
|
-
title: '${
|
|
30
|
-
description: '${
|
|
31
|
-
domain: '${
|
|
32
|
-
owners: [${
|
|
33
|
-
tags: [${
|
|
34
|
-
stability: '${
|
|
35
|
+
key: '${escapeString(data.name)}',
|
|
36
|
+
version: ${data.version},
|
|
37
|
+
title: '${escapeString(data.name)} experiment',
|
|
38
|
+
description: '${escapeString(data.description || "Describe the experiment goal.")}',
|
|
39
|
+
domain: '${escapeString(data.domain)}',
|
|
40
|
+
owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
|
|
41
|
+
tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
|
|
42
|
+
stability: '${data.stability}',
|
|
35
43
|
},
|
|
36
|
-
controlVariant: '${
|
|
44
|
+
controlVariant: '${escapeString(data.controlVariant)}',
|
|
37
45
|
variants: [
|
|
38
|
-
${
|
|
46
|
+
${variants}
|
|
39
47
|
],
|
|
40
|
-
allocation: ${
|
|
41
|
-
${
|
|
48
|
+
allocation: ${allocation},
|
|
49
|
+
${metrics}
|
|
42
50
|
};
|
|
43
|
-
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function renderAllocation(allocation) {
|
|
54
|
+
switch (allocation.type) {
|
|
55
|
+
case "random": return `{
|
|
44
56
|
type: 'random',
|
|
45
|
-
${
|
|
46
|
-
}`;
|
|
57
|
+
${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ""}
|
|
58
|
+
}`;
|
|
59
|
+
case "sticky": return `{
|
|
47
60
|
type: 'sticky',
|
|
48
|
-
attribute: '${
|
|
49
|
-
${
|
|
50
|
-
}`;
|
|
61
|
+
attribute: '${allocation.attribute}',
|
|
62
|
+
${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ""}
|
|
63
|
+
}`;
|
|
64
|
+
case "targeted": return `{
|
|
51
65
|
type: 'targeted',
|
|
52
66
|
rules: [
|
|
53
|
-
${
|
|
54
|
-
variantId: '${
|
|
55
|
-
${typeof
|
|
56
|
-
${
|
|
57
|
-
${
|
|
58
|
-
}`).join(
|
|
59
|
-
`)}
|
|
67
|
+
${allocation.rules.map((rule) => ` {
|
|
68
|
+
variantId: '${escapeString(rule.variantId)}',
|
|
69
|
+
${typeof rule.percentage === "number" ? `percentage: ${rule.percentage},` : ""}
|
|
70
|
+
${rule.policy ? `policy: { name: '${escapeString(rule.policy.name)}'${typeof rule.policy.version === "number" ? `, version: ${rule.policy.version}` : ""} },` : ""}
|
|
71
|
+
${rule.expression ? `expression: '${escapeString(rule.expression)}',` : ""}
|
|
72
|
+
}`).join(",\n")}
|
|
60
73
|
],
|
|
61
|
-
fallback: '${
|
|
62
|
-
}`;
|
|
74
|
+
fallback: '${allocation.fallback ?? "control"}',
|
|
75
|
+
}`;
|
|
76
|
+
default: return renderUnsupportedAllocation(allocation);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function escapeString(value) {
|
|
80
|
+
return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
81
|
+
}
|
|
82
|
+
function renderUnsupportedAllocation(allocation) {
|
|
83
|
+
throw new Error(`Unsupported allocation type ${allocation}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { generateExperimentSpec };
|
|
88
|
+
//# sourceMappingURL=experiment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiment.js","names":[],"sources":["../../src/templates/experiment.ts"],"sourcesContent":["import type { ExperimentSpecData } from '../types/spec-types';\nimport { toPascalCase } from './utils';\n\nexport function generateExperimentSpec(data: ExperimentSpecData): string {\n const specVar =\n toPascalCase(data.name.split('.').pop() ?? 'Experiment') + 'Experiment';\n\n const variants = data.variants\n .map((variant) => {\n const overrides = variant.overrides?.length\n ? ` overrides: [\n${variant.overrides\n .map(\n (override) => ` {\n type: '${override.type}',\n target: '${escapeString(override.target)}',\n ${typeof override.version === 'number' ? `version: ${override.version},` : ''}\n }`\n )\n .join(',\\n')}\n ],`\n : '';\n return ` {\n id: '${escapeString(variant.id)}',\n name: '${escapeString(variant.name)}',\n ${variant.description ? `description: '${escapeString(variant.description)}',` : ''}\n ${typeof variant.weight === 'number' ? `weight: ${variant.weight},` : ''}\n${overrides}\n }`;\n })\n .join(',\\n');\n\n const allocation = renderAllocation(data.allocation);\n\n const metrics = data.successMetrics?.length\n ? ` successMetrics: [\n${data.successMetrics\n .map(\n (metric) => ` {\n name: '${escapeString(metric.name)}',\n telemetryEvent: { name: '${escapeString(metric.eventName)}', version: ${metric.eventVersion} },\n aggregation: '${metric.aggregation}',\n ${typeof metric.target === 'number' ? `target: ${metric.target},` : ''}\n }`\n )\n .join(',\\n')}\n ],`\n : '';\n\n return `import type { ExperimentSpec } from '@lssm/lib.contracts/experiments';\n\nexport const ${specVar}: ExperimentSpec = {\n meta: {\n key: '${escapeString(data.name)}',\n version: ${data.version},\n title: '${escapeString(data.name)} experiment',\n description: '${escapeString(\n data.description || 'Describe the experiment goal.'\n )}',\n domain: '${escapeString(data.domain)}',\n owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(', ')}],\n tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(', ')}],\n stability: '${data.stability}',\n },\n controlVariant: '${escapeString(data.controlVariant)}',\n variants: [\n${variants}\n ],\n allocation: ${allocation},\n${metrics}\n};\n`;\n}\n\nfunction renderAllocation(\n allocation: ExperimentSpecData['allocation']\n): string {\n switch (allocation.type) {\n case 'random':\n return `{\n type: 'random',\n ${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ''}\n }`;\n case 'sticky':\n return `{\n type: 'sticky',\n attribute: '${allocation.attribute}',\n ${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ''}\n }`;\n case 'targeted':\n return `{\n type: 'targeted',\n rules: [\n${allocation.rules\n .map(\n (rule) => ` {\n variantId: '${escapeString(rule.variantId)}',\n ${typeof rule.percentage === 'number' ? `percentage: ${rule.percentage},` : ''}\n ${\n rule.policy\n ? `policy: { name: '${escapeString(rule.policy.name)}'${typeof rule.policy.version === 'number' ? `, version: ${rule.policy.version}` : ''} },`\n : ''\n }\n ${rule.expression ? `expression: '${escapeString(rule.expression)}',` : ''}\n }`\n )\n .join(',\\n')}\n ],\n fallback: '${allocation.fallback ?? 'control'}',\n }`;\n default:\n return renderUnsupportedAllocation(allocation);\n }\n}\n\nfunction escapeString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n}\n\nfunction renderUnsupportedAllocation(allocation: never): string {\n throw new Error(\n `Unsupported allocation type ${allocation as unknown as string}`\n );\n}\n"],"mappings":";;;AAGA,SAAgB,uBAAuB,MAAkC;CACvE,MAAM,UACJ,aAAa,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,aAAa,GAAG;CAE7D,MAAM,WAAW,KAAK,SACnB,KAAK,YAAY;EAChB,MAAM,YAAY,QAAQ,WAAW,SACjC;EACR,QAAQ,UACP,KACE,aAAa;mBACC,SAAS,KAAK;qBACZ,aAAa,SAAS,OAAO,CAAC;YACvC,OAAO,SAAS,YAAY,WAAW,YAAY,SAAS,QAAQ,KAAK,GAAG;WAErF,CACA,KAAK,MAAM,CAAC;YAEL;AACJ,SAAO;aACA,aAAa,QAAQ,GAAG,CAAC;eACvB,aAAa,QAAQ,KAAK,CAAC;QAClC,QAAQ,cAAc,iBAAiB,aAAa,QAAQ,YAAY,CAAC,MAAM,GAAG;QAClF,OAAO,QAAQ,WAAW,WAAW,WAAW,QAAQ,OAAO,KAAK,GAAG;EAC7E,UAAU;;GAEN,CACD,KAAK,MAAM;CAEd,MAAM,aAAa,iBAAiB,KAAK,WAAW;CAEpD,MAAM,UAAU,KAAK,gBAAgB,SACjC;EACJ,KAAK,eACJ,KACE,WAAW;eACD,aAAa,OAAO,KAAK,CAAC;iCACR,aAAa,OAAO,UAAU,CAAC,cAAc,OAAO,aAAa;sBAC5E,OAAO,YAAY;QACjC,OAAO,OAAO,WAAW,WAAW,WAAW,OAAO,OAAO,KAAK,GAAG;OAE1E,CACA,KAAK,MAAM,CAAC;QAET;AAEJ,QAAO;;eAEM,QAAQ;;YAEX,aAAa,KAAK,KAAK,CAAC;eACrB,KAAK,QAAQ;cACd,aAAa,KAAK,KAAK,CAAC;oBAClB,aACd,KAAK,eAAe,gCACrB,CAAC;eACS,aAAa,KAAK,OAAO,CAAC;eAC1B,KAAK,OAAO,KAAK,UAAU,IAAI,aAAa,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;aACpE,KAAK,KAAK,KAAK,QAAQ,IAAI,aAAa,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;kBACvD,KAAK,UAAU;;qBAEZ,aAAa,KAAK,eAAe,CAAC;;EAErD,SAAS;;gBAEK,WAAW;EACzB,QAAQ;;;;AAKV,SAAS,iBACP,YACQ;AACR,SAAQ,WAAW,MAAnB;EACE,KAAK,SACH,QAAO;;MAEP,WAAW,OAAO,UAAU,aAAa,WAAW,KAAK,CAAC,MAAM,GAAG;;EAErE,KAAK,SACH,QAAO;;kBAEK,WAAW,UAAU;MACjC,WAAW,OAAO,UAAU,aAAa,WAAW,KAAK,CAAC,MAAM,GAAG;;EAErE,KAAK,WACH,QAAO;;;EAGX,WAAW,MACV,KACE,SAAS;sBACQ,aAAa,KAAK,UAAU,CAAC;UACzC,OAAO,KAAK,eAAe,WAAW,eAAe,KAAK,WAAW,KAAK,GAAG;UAE7E,KAAK,SACD,oBAAoB,aAAa,KAAK,OAAO,KAAK,CAAC,GAAG,OAAO,KAAK,OAAO,YAAY,WAAW,cAAc,KAAK,OAAO,YAAY,GAAG,OACzI,GACL;UACC,KAAK,aAAa,gBAAgB,aAAa,KAAK,WAAW,CAAC,MAAM,GAAG;SAEhF,CACA,KAAK,MAAM,CAAC;;iBAEE,WAAW,YAAY,UAAU;;EAE9C,QACE,QAAO,4BAA4B,WAAW;;;AAIpD,SAAS,aAAa,OAAuB;AAC3C,QAAO,MAAM,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,MAAM;;AAG1D,SAAS,4BAA4B,YAA2B;AAC9D,OAAM,IAAI,MACR,+BAA+B,aAChC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/templates/handler.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Handler and component template generation.
|
|
4
|
+
* Extracted from cli-contractspec/src/templates/handler.template.ts
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generate handler implementation template.
|
|
8
|
+
*/
|
|
9
|
+
declare function generateHandlerTemplate(specName: string, kind: 'command' | 'query'): string;
|
|
10
|
+
/**
|
|
11
|
+
* Generate React component template.
|
|
12
|
+
*/
|
|
13
|
+
declare function generateComponentTemplate(componentName: string, description: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate test template.
|
|
16
|
+
*/
|
|
17
|
+
declare function generateTestTemplate(targetName: string, type: 'handler' | 'component'): string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { generateComponentTemplate, generateHandlerTemplate, generateTestTemplate };
|
|
20
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/templates/handler.ts"],"sourcesContent":[],"mappings":";;AAUA;AAyCA;AA6BA;;;;iBAtEgB,uBAAA;;;;iBAyCA,yBAAA;;;;iBA6BA,oBAAA"}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import{toCamelCase
|
|
2
|
-
import { ${o} } from '../contracts/${t(r)}.contracts';
|
|
1
|
+
import { toCamelCase, toKebabCase, toPascalCase } from "./utils.js";
|
|
3
2
|
|
|
3
|
+
//#region src/templates/handler.ts
|
|
4
4
|
/**
|
|
5
|
-
|
|
5
|
+
* Handler and component template generation.
|
|
6
|
+
* Extracted from cli-contractspec/src/templates/handler.template.ts
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Generate handler implementation template.
|
|
10
|
+
*/
|
|
11
|
+
function generateHandlerTemplate(specName, kind) {
|
|
12
|
+
const handlerName = toCamelCase(specName.split(".").pop() ?? "unknown") + "Handler";
|
|
13
|
+
const specVarName = toPascalCase(specName.split(".").pop() ?? "Unknown") + "Spec";
|
|
14
|
+
return `import type { ContractHandler } from '@lssm/lib.contracts';
|
|
15
|
+
import { ${specVarName} } from '../contracts/${toKebabCase(specName)}.contracts';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Handler for ${specName}
|
|
6
19
|
*/
|
|
7
|
-
export const ${
|
|
20
|
+
export const ${handlerName}: ContractHandler<typeof ${specVarName}> = async (
|
|
8
21
|
input,
|
|
9
22
|
context
|
|
10
23
|
) => {
|
|
11
|
-
// TODO: Implement ${
|
|
24
|
+
// TODO: Implement ${kind} logic
|
|
12
25
|
|
|
13
26
|
try {
|
|
14
27
|
// 1. Validate prerequisites
|
|
@@ -24,28 +37,43 @@ export const ${a}: ContractHandler<typeof ${o}> = async (
|
|
|
24
37
|
throw error;
|
|
25
38
|
}
|
|
26
39
|
};
|
|
27
|
-
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate React component template.
|
|
44
|
+
*/
|
|
45
|
+
function generateComponentTemplate(componentName, description) {
|
|
46
|
+
const pascalName = toPascalCase(componentName);
|
|
47
|
+
return `import React from 'react';
|
|
28
48
|
|
|
29
|
-
interface ${
|
|
49
|
+
interface ${pascalName}Props {
|
|
30
50
|
// TODO: Define props based on presentation spec
|
|
31
51
|
}
|
|
32
52
|
|
|
33
53
|
/**
|
|
34
|
-
* ${
|
|
54
|
+
* ${description}
|
|
35
55
|
*/
|
|
36
|
-
export const ${
|
|
56
|
+
export const ${pascalName}: React.FC<${pascalName}Props> = (props) => {
|
|
37
57
|
return (
|
|
38
58
|
<div>
|
|
39
59
|
{/* TODO: Implement component UI */}
|
|
40
|
-
<p>Component: ${
|
|
60
|
+
<p>Component: ${pascalName}</p>
|
|
41
61
|
</div>
|
|
42
62
|
);
|
|
43
63
|
};
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generate test template.
|
|
68
|
+
*/
|
|
69
|
+
function generateTestTemplate(targetName, type) {
|
|
70
|
+
const importPath = type === "handler" ? "../handlers" : "../components";
|
|
71
|
+
const testName = toPascalCase(targetName);
|
|
72
|
+
return `import { describe, it, expect } from 'bun:test';
|
|
73
|
+
import { ${testName} } from '${importPath}/${toKebabCase(targetName)}';
|
|
46
74
|
|
|
47
|
-
describe('${
|
|
48
|
-
it('should ${
|
|
75
|
+
describe('${testName}', () => {
|
|
76
|
+
it('should ${type === "handler" ? "handle valid input" : "render correctly"}', async () => {
|
|
49
77
|
// TODO: Implement test
|
|
50
78
|
expect(true).toBe(true);
|
|
51
79
|
});
|
|
@@ -54,10 +82,15 @@ describe('${a}', () => {
|
|
|
54
82
|
// TODO: Test edge cases
|
|
55
83
|
});
|
|
56
84
|
|
|
57
|
-
${
|
|
85
|
+
${type === "handler" ? `it('should handle errors appropriately', async () => {
|
|
58
86
|
// TODO: Test error scenarios
|
|
59
|
-
})
|
|
87
|
+
});` : `it('should be accessible', async () => {
|
|
60
88
|
// TODO: Test accessibility
|
|
61
89
|
});`}
|
|
62
90
|
});
|
|
63
|
-
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { generateComponentTemplate, generateHandlerTemplate, generateTestTemplate };
|
|
96
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","names":[],"sources":["../../src/templates/handler.ts"],"sourcesContent":["/**\n * Handler and component template generation.\n * Extracted from cli-contractspec/src/templates/handler.template.ts\n */\n\nimport { toPascalCase, toCamelCase, toKebabCase } from './utils';\n\n/**\n * Generate handler implementation template.\n */\nexport function generateHandlerTemplate(\n specName: string,\n kind: 'command' | 'query'\n): string {\n const handlerName =\n toCamelCase(specName.split('.').pop() ?? 'unknown') + 'Handler';\n const specVarName =\n toPascalCase(specName.split('.').pop() ?? 'Unknown') + 'Spec';\n\n return `import type { ContractHandler } from '@lssm/lib.contracts';\nimport { ${specVarName} } from '../contracts/${toKebabCase(specName)}.contracts';\n\n/**\n * Handler for ${specName}\n */\nexport const ${handlerName}: ContractHandler<typeof ${specVarName}> = async (\n input,\n context\n) => {\n // TODO: Implement ${kind} logic\n \n try {\n // 1. Validate prerequisites\n // 2. Perform business logic\n // 3. Emit events if needed\n // 4. Return result\n \n return {\n ok: true,\n };\n } catch (error) {\n // Handle and map errors to spec.io.errors\n throw error;\n }\n};\n`;\n}\n\n/**\n * Generate React component template.\n */\nexport function generateComponentTemplate(\n componentName: string,\n description: string\n): string {\n const pascalName = toPascalCase(componentName);\n\n return `import React from 'react';\n\ninterface ${pascalName}Props {\n // TODO: Define props based on presentation spec\n}\n\n/**\n * ${description}\n */\nexport const ${pascalName}: React.FC<${pascalName}Props> = (props) => {\n return (\n <div>\n {/* TODO: Implement component UI */}\n <p>Component: ${pascalName}</p>\n </div>\n );\n};\n`;\n}\n\n/**\n * Generate test template.\n */\nexport function generateTestTemplate(\n targetName: string,\n type: 'handler' | 'component'\n): string {\n const importPath = type === 'handler' ? '../handlers' : '../components';\n const testName = toPascalCase(targetName);\n\n return `import { describe, it, expect } from 'bun:test';\nimport { ${testName} } from '${importPath}/${toKebabCase(targetName)}';\n\ndescribe('${testName}', () => {\n it('should ${type === 'handler' ? 'handle valid input' : 'render correctly'}', async () => {\n // TODO: Implement test\n expect(true).toBe(true);\n });\n\n it('should handle edge cases', async () => {\n // TODO: Test edge cases\n });\n\n ${\n type === 'handler'\n ? `it('should handle errors appropriately', async () => {\n // TODO: Test error scenarios\n });`\n : `it('should be accessible', async () => {\n // TODO: Test accessibility\n });`\n }\n});\n`;\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,wBACd,UACA,MACQ;CACR,MAAM,cACJ,YAAY,SAAS,MAAM,IAAI,CAAC,KAAK,IAAI,UAAU,GAAG;CACxD,MAAM,cACJ,aAAa,SAAS,MAAM,IAAI,CAAC,KAAK,IAAI,UAAU,GAAG;AAEzD,QAAO;WACE,YAAY,wBAAwB,YAAY,SAAS,CAAC;;;iBAGpD,SAAS;;eAEX,YAAY,2BAA2B,YAAY;;;;uBAI3C,KAAK;;;;;;;;;;;;;;;;;;;;;AAsB5B,SAAgB,0BACd,eACA,aACQ;CACR,MAAM,aAAa,aAAa,cAAc;AAE9C,QAAO;;YAEG,WAAW;;;;;KAKlB,YAAY;;eAEF,WAAW,aAAa,WAAW;;;;sBAI5B,WAAW;;;;;;;;;AAUjC,SAAgB,qBACd,YACA,MACQ;CACR,MAAM,aAAa,SAAS,YAAY,gBAAgB;CACxD,MAAM,WAAW,aAAa,WAAW;AAEzC,QAAO;WACE,SAAS,WAAW,WAAW,GAAG,YAAY,WAAW,CAAC;;YAEzD,SAAS;eACN,SAAS,YAAY,uBAAuB,mBAAmB;;;;;;;;;IAU1E,SAAS,YACL;;SAGA;;OAGL"}
|
|
@@ -1,33 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/templates/integration-utils.ts
|
|
2
|
+
function renderConfigSchema(fields) {
|
|
3
|
+
const requiredFields = fields.filter((field) => field.required);
|
|
4
|
+
return ` schema: {
|
|
2
5
|
type: 'object',
|
|
3
|
-
${
|
|
4
|
-
|
|
5
|
-
${(
|
|
6
|
-
|
|
6
|
+
${requiredFields.length > 0 ? ` required: [${requiredFields.map((field) => `'${field.key}'`).join(", ")}],
|
|
7
|
+
` : ""} properties: {
|
|
8
|
+
${(fields.length ? fields.map((field) => {
|
|
9
|
+
const description = field.description ? `, description: '${escape(field.description)}'` : "";
|
|
10
|
+
return ` ${field.key}: { type: '${mapConfigType(field.type)}'${description} }`;
|
|
11
|
+
}).join(",\n") : "") || " "}
|
|
7
12
|
},
|
|
8
|
-
},\n
|
|
13
|
+
},\n`;
|
|
14
|
+
}
|
|
15
|
+
function renderSecretSchema(fields) {
|
|
16
|
+
const requiredFields = fields.filter((field) => field.required);
|
|
17
|
+
return ` schema: {
|
|
9
18
|
type: 'object',
|
|
10
|
-
${
|
|
11
|
-
|
|
12
|
-
${(
|
|
13
|
-
|
|
19
|
+
${requiredFields.length > 0 ? ` required: [${requiredFields.map((field) => `'${field.key}'`).join(", ")}],
|
|
20
|
+
` : ""} properties: {
|
|
21
|
+
${(fields.length ? fields.map((field) => {
|
|
22
|
+
const description = field.description ? `, description: '${escape(field.description)}'` : "";
|
|
23
|
+
return ` ${field.key}: { type: 'string'${description} }`;
|
|
24
|
+
}).join(",\n") : "") || " "}
|
|
14
25
|
},
|
|
15
|
-
},\n
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
},\n`;
|
|
27
|
+
}
|
|
28
|
+
function renderConfigExample(fields) {
|
|
29
|
+
if (fields.length === 0) return `{}`;
|
|
30
|
+
return `{
|
|
31
|
+
${fields.map((field) => {
|
|
32
|
+
switch (field.type) {
|
|
33
|
+
case "number": return ` ${field.key}: 0`;
|
|
34
|
+
case "boolean": return ` ${field.key}: true`;
|
|
35
|
+
case "string":
|
|
36
|
+
default: return ` ${field.key}: '${field.key.toUpperCase()}_VALUE'`;
|
|
37
|
+
}
|
|
38
|
+
}).join(",\n")}
|
|
39
|
+
}`;
|
|
40
|
+
}
|
|
41
|
+
function renderSecretExample(fields) {
|
|
42
|
+
if (fields.length === 0) return `{}`;
|
|
43
|
+
return `{
|
|
44
|
+
${fields.map((field) => ` ${field.key}: '${field.key.toUpperCase()}_SECRET'`).join(",\n")}
|
|
45
|
+
}`;
|
|
46
|
+
}
|
|
47
|
+
function renderConstraints(rpm, rph) {
|
|
48
|
+
if (rpm == null && rph == null) return "";
|
|
49
|
+
const entries = [];
|
|
50
|
+
if (rpm != null) entries.push(` rpm: ${rpm}`);
|
|
51
|
+
if (rph != null) entries.push(` rph: ${rph}`);
|
|
52
|
+
return ` constraints: {
|
|
22
53
|
rateLimit: {
|
|
23
|
-
${
|
|
24
|
-
`)}
|
|
54
|
+
${entries.join(",\n")}
|
|
25
55
|
},
|
|
26
56
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`)}
|
|
33
|
-
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
function renderByokSetup(modes, instructions, scopes) {
|
|
60
|
+
if (!modes.includes("byok")) return "";
|
|
61
|
+
const instructionsLine = instructions ? ` setupInstructions: '${escape(instructions)}',\n` : "";
|
|
62
|
+
const scopesLine = scopes && scopes.length ? ` requiredScopes: [${scopes.map((scope) => `'${escape(scope)}'`).join(", ")}],\n` : "";
|
|
63
|
+
if (!instructionsLine && !scopesLine) return "";
|
|
64
|
+
return ` byokSetup: {
|
|
65
|
+
${instructionsLine}${scopesLine} },
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
function mapConfigType(type) {
|
|
69
|
+
switch (type) {
|
|
70
|
+
case "number": return "number";
|
|
71
|
+
case "boolean": return "boolean";
|
|
72
|
+
case "string":
|
|
73
|
+
default: return "string";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function stabilityToEnum(stability) {
|
|
77
|
+
switch (stability) {
|
|
78
|
+
case "beta": return "Beta";
|
|
79
|
+
case "stable": return "Stable";
|
|
80
|
+
case "deprecated": return "Deprecated";
|
|
81
|
+
case "experimental":
|
|
82
|
+
default: return "Experimental";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function renderProvides(data) {
|
|
86
|
+
return data.capabilitiesProvided.map((cap) => ` { key: '${cap.key}', version: ${cap.version} }`).join(",\n");
|
|
87
|
+
}
|
|
88
|
+
function renderRequires(data) {
|
|
89
|
+
if (data.capabilitiesRequired.length === 0) return "";
|
|
90
|
+
return ` requires: [
|
|
91
|
+
${data.capabilitiesRequired.map((req) => {
|
|
92
|
+
const version = typeof req.version === "number" ? `, version: ${req.version}` : "";
|
|
93
|
+
const optional = req.optional ? ", optional: true" : "";
|
|
94
|
+
const reason = req.reason ? `, reason: '${escape(req.reason)}'` : "";
|
|
95
|
+
return ` { key: '${req.key}'${version}${optional}${reason} }`;
|
|
96
|
+
}).join(",\n")}
|
|
97
|
+
],`;
|
|
98
|
+
}
|
|
99
|
+
function escape(value) {
|
|
100
|
+
return value.replace(/`/g, "\\`").replace(/'/g, "\\'");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { escape, renderByokSetup, renderConfigExample, renderConfigSchema, renderConstraints, renderProvides, renderRequires, renderSecretExample, renderSecretSchema, stabilityToEnum };
|
|
105
|
+
//# sourceMappingURL=integration-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration-utils.js","names":["entries: string[]"],"sources":["../../src/templates/integration-utils.ts"],"sourcesContent":["import type {\n IntegrationConfigFieldData,\n IntegrationSecretFieldData,\n IntegrationSpecData,\n Stability,\n} from '../types/spec-types';\n\nexport function renderConfigSchema(\n fields: IntegrationConfigFieldData[]\n): string {\n const requiredFields = fields.filter((field) => field.required);\n const requiredBlock =\n requiredFields.length > 0\n ? ` required: [${requiredFields\n .map((field) => `'${field.key}'`)\n .join(', ')}],\n`\n : '';\n\n const properties = fields.length\n ? fields\n .map((field) => {\n const description = field.description\n ? `, description: '${escape(field.description)}'`\n : '';\n return ` ${field.key}: { type: '${mapConfigType(\n field.type\n )}'${description} }`;\n })\n .join(',\\n')\n : '';\n\n return ` schema: {\n type: 'object',\n${requiredBlock} properties: {\n${properties || ' '}\n },\n },\\n`;\n}\n\nexport function renderSecretSchema(\n fields: IntegrationSecretFieldData[]\n): string {\n const requiredFields = fields.filter((field) => field.required);\n const requiredBlock =\n requiredFields.length > 0\n ? ` required: [${requiredFields\n .map((field) => `'${field.key}'`)\n .join(', ')}],\n`\n : '';\n\n const properties = fields.length\n ? fields\n .map((field) => {\n const description = field.description\n ? `, description: '${escape(field.description)}'`\n : '';\n return ` ${field.key}: { type: 'string'${description} }`;\n })\n .join(',\\n')\n : '';\n\n return ` schema: {\n type: 'object',\n${requiredBlock} properties: {\n${properties || ' '}\n },\n },\\n`;\n}\n\nexport function renderConfigExample(\n fields: IntegrationConfigFieldData[]\n): string {\n if (fields.length === 0) {\n return `{}`;\n }\n\n const exampleEntries = fields.map((field) => {\n switch (field.type) {\n case 'number':\n return ` ${field.key}: 0`;\n case 'boolean':\n return ` ${field.key}: true`;\n case 'string':\n default:\n return ` ${field.key}: '${field.key.toUpperCase()}_VALUE'`;\n }\n });\n\n return `{\n${exampleEntries.join(',\\n')}\n }`;\n}\n\nexport function renderSecretExample(\n fields: IntegrationSecretFieldData[]\n): string {\n if (fields.length === 0) {\n return `{}`;\n }\n\n const exampleEntries = fields.map(\n (field) => ` ${field.key}: '${field.key.toUpperCase()}_SECRET'`\n );\n\n return `{\n${exampleEntries.join(',\\n')}\n }`;\n}\n\nexport function renderConstraints(rpm?: number, rph?: number): string {\n if (rpm == null && rph == null) return '';\n const entries: string[] = [];\n if (rpm != null) entries.push(` rpm: ${rpm}`);\n if (rph != null) entries.push(` rph: ${rph}`);\n return ` constraints: {\n rateLimit: {\n${entries.join(',\\n')}\n },\n },\n`;\n}\n\nexport function renderByokSetup(\n modes: string[],\n instructions?: string,\n scopes?: string[]\n): string {\n if (!modes.includes('byok')) {\n return '';\n }\n\n const instructionsLine = instructions\n ? ` setupInstructions: '${escape(instructions)}',\\n`\n : '';\n const scopesLine =\n scopes && scopes.length\n ? ` requiredScopes: [${scopes\n .map((scope) => `'${escape(scope)}'`)\n .join(', ')}],\\n`\n : '';\n\n if (!instructionsLine && !scopesLine) {\n return '';\n }\n\n return ` byokSetup: {\n${instructionsLine}${scopesLine} },\n`;\n}\n\nexport function mapConfigType(\n type: IntegrationConfigFieldData['type']\n): string {\n switch (type) {\n case 'number':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'string':\n default:\n return 'string';\n }\n}\n\nexport function stabilityToEnum(stability: Stability): string {\n switch (stability) {\n case 'beta':\n return 'Beta';\n case 'stable':\n return 'Stable';\n case 'deprecated':\n return 'Deprecated';\n case 'experimental':\n default:\n return 'Experimental';\n }\n}\n\nexport function renderProvides(data: IntegrationSpecData): string {\n return data.capabilitiesProvided\n .map((cap) => ` { key: '${cap.key}', version: ${cap.version} }`)\n .join(',\\n');\n}\n\nexport function renderRequires(data: IntegrationSpecData): string {\n if (data.capabilitiesRequired.length === 0) return '';\n\n return ` requires: [\n${data.capabilitiesRequired\n .map((req) => {\n const version =\n typeof req.version === 'number' ? `, version: ${req.version}` : '';\n const optional = req.optional ? ', optional: true' : '';\n const reason = req.reason ? `, reason: '${escape(req.reason)}'` : '';\n return ` { key: '${req.key}'${version}${optional}${reason} }`;\n })\n .join(',\\n')}\n ],`;\n}\n\nexport function escape(value: string): string {\n return value.replace(/`/g, '\\\\`').replace(/'/g, \"\\\\'\");\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IntegrationSpecData } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/integration.d.ts
|
|
4
|
+
declare function generateIntegrationSpec(data: IntegrationSpecData): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { generateIntegrationSpec };
|
|
7
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/templates/integration.ts"],"sourcesContent":[],"mappings":";;;iBAegB,uBAAA,OAA8B"}
|
|
@@ -1,39 +1,63 @@
|
|
|
1
|
-
import{toPascalCase
|
|
1
|
+
import { toPascalCase } from "./utils.js";
|
|
2
|
+
import { escape, renderByokSetup, renderConfigExample, renderConfigSchema, renderConstraints, renderProvides, renderRequires, renderSecretExample, renderSecretSchema, stabilityToEnum } from "./integration-utils.js";
|
|
3
|
+
|
|
4
|
+
//#region src/templates/integration.ts
|
|
5
|
+
function generateIntegrationSpec(data) {
|
|
6
|
+
const specName = toPascalCase(data.name.split(".").pop() ?? "Integration");
|
|
7
|
+
const varName = `${specName}IntegrationSpec`;
|
|
8
|
+
const registerFn = `register${specName}Integration`;
|
|
9
|
+
const supportedModes = data.supportedModes.length ? data.supportedModes : ["managed"];
|
|
10
|
+
const supportedModesLine = supportedModes.map((mode) => `'${mode}'`).join(", ");
|
|
11
|
+
const provides = renderProvides(data);
|
|
12
|
+
const requires = renderRequires(data);
|
|
13
|
+
const configSchema = renderConfigSchema(data.configFields);
|
|
14
|
+
const configExample = renderConfigExample(data.configFields);
|
|
15
|
+
const secretSchema = renderSecretSchema(data.secretFields);
|
|
16
|
+
const secretExample = renderSecretExample(data.secretFields);
|
|
17
|
+
const docsUrl = data.docsUrl ? ` docsUrl: '${escape(data.docsUrl)}',\n` : "";
|
|
18
|
+
const constraints = renderConstraints(data.rateLimitRpm, data.rateLimitRph);
|
|
19
|
+
const byokSetup = renderByokSetup(supportedModes, data.byokSetupInstructions, data.byokRequiredScopes);
|
|
20
|
+
return `import { StabilityEnum } from '@lssm/lib.contracts/ownership';
|
|
2
21
|
import type { IntegrationSpec } from '@lssm/lib.contracts/integrations/spec';
|
|
3
22
|
import type { IntegrationSpecRegistry } from '@lssm/lib.contracts/integrations/spec';
|
|
4
23
|
|
|
5
|
-
export const ${
|
|
24
|
+
export const ${varName}: IntegrationSpec = {
|
|
6
25
|
meta: {
|
|
7
|
-
key: '${
|
|
8
|
-
version: ${
|
|
9
|
-
category: '${
|
|
10
|
-
displayName: '${
|
|
11
|
-
title: '${
|
|
12
|
-
description: '${
|
|
13
|
-
domain: '${
|
|
14
|
-
owners: [${
|
|
15
|
-
tags: [${
|
|
16
|
-
stability: StabilityEnum.${
|
|
26
|
+
key: '${escape(data.name)}',
|
|
27
|
+
version: ${data.version},
|
|
28
|
+
category: '${data.category}',
|
|
29
|
+
displayName: '${escape(data.displayName)}',
|
|
30
|
+
title: '${escape(data.title)}',
|
|
31
|
+
description: '${escape(data.description)}',
|
|
32
|
+
domain: '${escape(data.domain)}',
|
|
33
|
+
owners: [${data.owners.map((owner) => `'${escape(owner)}'`).join(", ")}],
|
|
34
|
+
tags: [${data.tags.map((tag) => `'${escape(tag)}'`).join(", ")}],
|
|
35
|
+
stability: StabilityEnum.${stabilityToEnum(data.stability)},
|
|
17
36
|
},
|
|
18
|
-
supportedModes: [${
|
|
37
|
+
supportedModes: [${supportedModesLine}],
|
|
19
38
|
capabilities: {
|
|
20
39
|
provides: [
|
|
21
|
-
${
|
|
40
|
+
${provides}
|
|
22
41
|
],
|
|
23
|
-
${
|
|
42
|
+
${requires.length > 0 ? `${requires}\n` : ""} },
|
|
24
43
|
configSchema: {
|
|
25
|
-
${
|
|
44
|
+
${configSchema} example: ${configExample},
|
|
26
45
|
},
|
|
27
46
|
secretSchema: {
|
|
28
|
-
${
|
|
47
|
+
${secretSchema} example: ${secretExample},
|
|
29
48
|
},
|
|
30
|
-
${
|
|
31
|
-
method: '${
|
|
32
|
-
timeoutMs: ${
|
|
49
|
+
${docsUrl}${constraints}${byokSetup} healthCheck: {
|
|
50
|
+
method: '${data.healthCheckMethod}',
|
|
51
|
+
timeoutMs: ${data.healthCheckTimeoutMs ?? 5e3},
|
|
33
52
|
},
|
|
34
53
|
};
|
|
35
54
|
|
|
36
|
-
export function ${
|
|
37
|
-
return registry.register(${
|
|
55
|
+
export function ${registerFn}(registry: IntegrationSpecRegistry): IntegrationSpecRegistry {
|
|
56
|
+
return registry.register(${varName});
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
38
59
|
}
|
|
39
|
-
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { generateIntegrationSpec };
|
|
63
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","names":[],"sources":["../../src/templates/integration.ts"],"sourcesContent":["import type { IntegrationSpecData } from '../types/spec-types';\nimport { toPascalCase } from './utils';\nimport {\n escape,\n renderByokSetup,\n renderConfigExample,\n renderConfigSchema,\n renderConstraints,\n renderProvides,\n renderRequires,\n renderSecretExample,\n renderSecretSchema,\n stabilityToEnum,\n} from './integration-utils';\n\nexport function generateIntegrationSpec(data: IntegrationSpecData): string {\n const specName = toPascalCase(data.name.split('.').pop() ?? 'Integration');\n const varName = `${specName}IntegrationSpec`;\n const registerFn = `register${specName}Integration`;\n\n const supportedModes = data.supportedModes.length\n ? data.supportedModes\n : ['managed'];\n const supportedModesLine = supportedModes\n .map((mode) => `'${mode}'`)\n .join(', ');\n\n const provides = renderProvides(data);\n const requires = renderRequires(data);\n\n const configSchema = renderConfigSchema(data.configFields);\n const configExample = renderConfigExample(data.configFields);\n const secretSchema = renderSecretSchema(data.secretFields);\n const secretExample = renderSecretExample(data.secretFields);\n const docsUrl = data.docsUrl ? ` docsUrl: '${escape(data.docsUrl)}',\\n` : '';\n const constraints = renderConstraints(data.rateLimitRpm, data.rateLimitRph);\n const byokSetup = renderByokSetup(\n supportedModes,\n data.byokSetupInstructions,\n data.byokRequiredScopes\n );\n\n return `import { StabilityEnum } from '@lssm/lib.contracts/ownership';\nimport type { IntegrationSpec } from '@lssm/lib.contracts/integrations/spec';\nimport type { IntegrationSpecRegistry } from '@lssm/lib.contracts/integrations/spec';\n\nexport const ${varName}: IntegrationSpec = {\n meta: {\n key: '${escape(data.name)}',\n version: ${data.version},\n category: '${data.category}',\n displayName: '${escape(data.displayName)}',\n title: '${escape(data.title)}',\n description: '${escape(data.description)}',\n domain: '${escape(data.domain)}',\n owners: [${data.owners.map((owner) => `'${escape(owner)}'`).join(', ')}],\n tags: [${data.tags.map((tag) => `'${escape(tag)}'`).join(', ')}],\n stability: StabilityEnum.${stabilityToEnum(data.stability)},\n },\n supportedModes: [${supportedModesLine}],\n capabilities: {\n provides: [\n${provides}\n ],\n${requires.length > 0 ? `${requires}\\n` : ''} },\n configSchema: {\n${configSchema} example: ${configExample},\n },\n secretSchema: {\n${secretSchema} example: ${secretExample},\n },\n${docsUrl}${constraints}${byokSetup} healthCheck: {\n method: '${data.healthCheckMethod}',\n timeoutMs: ${data.healthCheckTimeoutMs ?? 5000},\n },\n};\n\nexport function ${registerFn}(registry: IntegrationSpecRegistry): IntegrationSpecRegistry {\n return registry.register(${varName});\n}\n`;\n}\n"],"mappings":";;;;AAeA,SAAgB,wBAAwB,MAAmC;CACzE,MAAM,WAAW,aAAa,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,cAAc;CAC1E,MAAM,UAAU,GAAG,SAAS;CAC5B,MAAM,aAAa,WAAW,SAAS;CAEvC,MAAM,iBAAiB,KAAK,eAAe,SACvC,KAAK,iBACL,CAAC,UAAU;CACf,MAAM,qBAAqB,eACxB,KAAK,SAAS,IAAI,KAAK,GAAG,CAC1B,KAAK,KAAK;CAEb,MAAM,WAAW,eAAe,KAAK;CACrC,MAAM,WAAW,eAAe,KAAK;CAErC,MAAM,eAAe,mBAAmB,KAAK,aAAa;CAC1D,MAAM,gBAAgB,oBAAoB,KAAK,aAAa;CAC5D,MAAM,eAAe,mBAAmB,KAAK,aAAa;CAC1D,MAAM,gBAAgB,oBAAoB,KAAK,aAAa;CAC5D,MAAM,UAAU,KAAK,UAAU,eAAe,OAAO,KAAK,QAAQ,CAAC,QAAQ;CAC3E,MAAM,cAAc,kBAAkB,KAAK,cAAc,KAAK,aAAa;CAC3E,MAAM,YAAY,gBAChB,gBACA,KAAK,uBACL,KAAK,mBACN;AAED,QAAO;;;;eAIM,QAAQ;;YAEX,OAAO,KAAK,KAAK,CAAC;eACf,KAAK,QAAQ;iBACX,KAAK,SAAS;oBACX,OAAO,KAAK,YAAY,CAAC;cAC/B,OAAO,KAAK,MAAM,CAAC;oBACb,OAAO,KAAK,YAAY,CAAC;eAC9B,OAAO,KAAK,OAAO,CAAC;eACpB,KAAK,OAAO,KAAK,UAAU,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;aAC9D,KAAK,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;+BACpC,gBAAgB,KAAK,UAAU,CAAC;;qBAE1C,mBAAmB;;;EAGtC,SAAS;;EAET,SAAS,SAAS,IAAI,GAAG,SAAS,MAAM,GAAG;;EAE3C,aAAa,eAAe,cAAc;;;EAG1C,aAAa,eAAe,cAAc;;EAE1C,UAAU,cAAc,UAAU;eACrB,KAAK,kBAAkB;iBACrB,KAAK,wBAAwB,IAAK;;;;kBAIjC,WAAW;6BACA,QAAQ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { KnowledgeSpaceSpecData } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/knowledge.d.ts
|
|
4
|
+
declare function generateKnowledgeSpaceSpec(data: KnowledgeSpaceSpecData): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { generateKnowledgeSpaceSpec };
|
|
7
|
+
//# sourceMappingURL=knowledge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge.d.ts","names":[],"sources":["../../src/templates/knowledge.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,0BAAA,OACR"}
|