@lssm/module.contractspec-workspace 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217073102

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.
@@ -1,33 +1,104 @@
1
- function e(e){let t=e.filter(e=>e.required);return` schema: {
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
- ${t.length>0?` required: [${t.map(e=>`'${e.key}'`).join(`, `)}],
4
- `:``} properties: {
5
- ${(e.length?e.map(e=>{let t=e.description?`, description: '${u(e.description)}'`:``;return` ${e.key}: { type: '${o(e.type)}'${t} }`}).join(`,
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`}function t(e){let t=e.filter(e=>e.required);return` schema: {
13
+ },\n`;
14
+ }
15
+ function renderSecretSchema(fields) {
16
+ const requiredFields = fields.filter((field) => field.required);
17
+ return ` schema: {
9
18
  type: 'object',
10
- ${t.length>0?` required: [${t.map(e=>`'${e.key}'`).join(`, `)}],
11
- `:``} properties: {
12
- ${(e.length?e.map(e=>{let t=e.description?`, description: '${u(e.description)}'`:``;return` ${e.key}: { type: 'string'${t} }`}).join(`,
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`}function n(e){return e.length===0?`{}`:`{
16
- ${e.map(e=>{switch(e.type){case`number`:return` ${e.key}: 0`;case`boolean`:return` ${e.key}: true`;case`string`:default:return` ${e.key}: '${e.key.toUpperCase()}_VALUE'`}}).join(`,
17
- `)}
18
- }`}function r(e){return e.length===0?`{}`:`{
19
- ${e.map(e=>` ${e.key}: '${e.key.toUpperCase()}_SECRET'`).join(`,
20
- `)}
21
- }`}function i(e,t){if(e==null&&t==null)return``;let n=[];return e!=null&&n.push(` rpm: ${e}`),t!=null&&n.push(` rph: ${t}`),` constraints: {
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
- ${n.join(`,
24
- `)}
54
+ ${entries.join(",\n")}
25
55
  },
26
56
  },
27
- `}function a(e,t,n){if(!e.includes(`byok`))return``;let r=t?` setupInstructions: '${u(t)}',\n`:``,i=n&&n.length?` requiredScopes: [${n.map(e=>`'${u(e)}'`).join(`, `)}],\n`:``;return!r&&!i?``:` byokSetup: {
28
- ${r}${i} },
29
- `}function o(e){switch(e){case`number`:return`number`;case`boolean`:return`boolean`;case`string`:default:return`string`}}function s(e){switch(e){case`beta`:return`Beta`;case`stable`:return`Stable`;case`deprecated`:return`Deprecated`;case`experimental`:default:return`Experimental`}}function c(e){return e.capabilitiesProvided.map(e=>` { key: '${e.key}', version: ${e.version} }`).join(`,
30
- `)}function l(e){return e.capabilitiesRequired.length===0?``:` requires: [
31
- ${e.capabilitiesRequired.map(e=>{let t=typeof e.version==`number`?`, version: ${e.version}`:``,n=e.optional?`, optional: true`:``,r=e.reason?`, reason: '${u(e.reason)}'`:``;return` { key: '${e.key}'${t}${n}${r} }`}).join(`,
32
- `)}
33
- ],`}function u(e){return e.replace(/`/g,"\\`").replace(/'/g,`\\'`)}export{u as escape,a as renderByokSetup,n as renderConfigExample,e as renderConfigSchema,i as renderConstraints,c as renderProvides,l as renderRequires,r as renderSecretExample,t as renderSecretSchema,s as stabilityToEnum};
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 };
@@ -1,39 +1,62 @@
1
- import{toPascalCase as e}from"./utils.js";import{escape as t,renderByokSetup as n,renderConfigExample as r,renderConfigSchema as i,renderConstraints as a,renderProvides as o,renderRequires as s,renderSecretExample as c,renderSecretSchema as l,stabilityToEnum as u}from"./integration-utils.js";function d(d){let f=e(d.name.split(`.`).pop()??`Integration`),p=`${f}IntegrationSpec`,m=`register${f}Integration`,h=d.supportedModes.length?d.supportedModes:[`managed`],g=h.map(e=>`'${e}'`).join(`, `),_=o(d),v=s(d),y=i(d.configFields),b=r(d.configFields),x=l(d.secretFields),S=c(d.secretFields),C=d.docsUrl?` docsUrl: '${t(d.docsUrl)}',\n`:``,w=a(d.rateLimitRpm,d.rateLimitRph),T=n(h,d.byokSetupInstructions,d.byokRequiredScopes);return`import { StabilityEnum } from '@lssm/lib.contracts/ownership';
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 ${p}: IntegrationSpec = {
24
+ export const ${varName}: IntegrationSpec = {
6
25
  meta: {
7
- key: '${t(d.name)}',
8
- version: ${d.version},
9
- category: '${d.category}',
10
- displayName: '${t(d.displayName)}',
11
- title: '${t(d.title)}',
12
- description: '${t(d.description)}',
13
- domain: '${t(d.domain)}',
14
- owners: [${d.owners.map(e=>`'${t(e)}'`).join(`, `)}],
15
- tags: [${d.tags.map(e=>`'${t(e)}'`).join(`, `)}],
16
- stability: StabilityEnum.${u(d.stability)},
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: [${g}],
37
+ supportedModes: [${supportedModesLine}],
19
38
  capabilities: {
20
39
  provides: [
21
- ${_}
40
+ ${provides}
22
41
  ],
23
- ${v.length>0?`${v}\n`:``} },
42
+ ${requires.length > 0 ? `${requires}\n` : ""} },
24
43
  configSchema: {
25
- ${y} example: ${b},
44
+ ${configSchema} example: ${configExample},
26
45
  },
27
46
  secretSchema: {
28
- ${x} example: ${S},
47
+ ${secretSchema} example: ${secretExample},
29
48
  },
30
- ${C}${w}${T} healthCheck: {
31
- method: '${d.healthCheckMethod}',
32
- timeoutMs: ${d.healthCheckTimeoutMs??5e3},
49
+ ${docsUrl}${constraints}${byokSetup} healthCheck: {
50
+ method: '${data.healthCheckMethod}',
51
+ timeoutMs: ${data.healthCheckTimeoutMs ?? 5e3},
33
52
  },
34
53
  };
35
54
 
36
- export function ${m}(registry: IntegrationSpecRegistry): IntegrationSpecRegistry {
37
- return registry.register(${p});
55
+ export function ${registerFn}(registry: IntegrationSpecRegistry): IntegrationSpecRegistry {
56
+ return registry.register(${varName});
57
+ }
58
+ `;
38
59
  }
39
- `}export{d as generateIntegrationSpec};
60
+
61
+ //#endregion
62
+ export { generateIntegrationSpec };
@@ -1,28 +1,68 @@
1
- import{escapeString as e,toPascalCase as t}from"./utils.js";function n(n){let c=t(n.name.split(`.`).pop()??`KnowledgeSpace`),l=`${c}KnowledgeSpace`,u=`register${c}KnowledgeSpace`,d=r(n),f=i(n),p=a(n),m=n.policyName&&!n.policyVersion?` // defaults to latest version`:``;return`import { StabilityEnum } from '@lssm/lib.contracts/ownership';
1
+ import { escapeString, toPascalCase } from "./utils.js";
2
+
3
+ //#region src/templates/knowledge.ts
4
+ function generateKnowledgeSpaceSpec(data) {
5
+ const specName = toPascalCase(data.name.split(".").pop() ?? "KnowledgeSpace");
6
+ const varName = `${specName}KnowledgeSpace`;
7
+ const registerFn = `register${specName}KnowledgeSpace`;
8
+ const retention = renderRetention(data);
9
+ const access = renderAccess(data);
10
+ const indexing = renderIndexing(data);
11
+ const policyComment = data.policyName && !data.policyVersion ? ` // defaults to latest version` : "";
12
+ return `import { StabilityEnum } from '@lssm/lib.contracts/ownership';
2
13
  import type { KnowledgeSpaceSpec } from '@lssm/lib.contracts/knowledge/spec';
3
14
  import type { KnowledgeSpaceRegistry } from '@lssm/lib.contracts/knowledge/spec';
4
15
 
5
- export const ${l}: KnowledgeSpaceSpec = {
16
+ export const ${varName}: KnowledgeSpaceSpec = {
6
17
  meta: {
7
- key: '${e(n.name)}',
8
- version: ${n.version},
9
- category: '${n.category}',
10
- displayName: '${s(n.displayName)}',
11
- title: '${s(n.title)}',
12
- description: '${s(n.description)}',
13
- domain: '${s(n.domain)}',
14
- owners: [${n.owners.map(t=>`'${e(t)}'`).join(`, `)}],
15
- tags: [${n.tags.map(t=>`'${e(t)}'`).join(`, `)}],
16
- stability: StabilityEnum.${o(n.stability)},
18
+ key: '${escapeString(data.name)}',
19
+ version: ${data.version},
20
+ category: '${data.category}',
21
+ displayName: '${escape(data.displayName)}',
22
+ title: '${escape(data.title)}',
23
+ description: '${escape(data.description)}',
24
+ domain: '${escape(data.domain)}',
25
+ owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
26
+ tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
27
+ stability: StabilityEnum.${stabilityToEnum(data.stability)},
17
28
  },
18
- retention: ${d},
29
+ retention: ${retention},
19
30
  access: {
20
- ${f}${n.policyName?` policy: { name: '${e(n.policyName)}',${n.policyVersion?` version: ${n.policyVersion}`:``} },${m}\n`:``} },
21
- ${p} description: '${s(n.description||n.displayName)}',
31
+ ${access}${data.policyName ? ` policy: { name: '${escapeString(data.policyName)}',${data.policyVersion ? ` version: ${data.policyVersion}` : ""} },${policyComment}\n` : ""} },
32
+ ${indexing} description: '${escape(data.description || data.displayName)}',
22
33
  };
23
34
 
24
- export function ${u}(registry: KnowledgeSpaceRegistry): KnowledgeSpaceRegistry {
25
- return registry.register(${l});
35
+ export function ${registerFn}(registry: KnowledgeSpaceRegistry): KnowledgeSpaceRegistry {
36
+ return registry.register(${varName});
37
+ }
38
+ `;
39
+ }
40
+ function renderRetention(data) {
41
+ return `{ ttlDays: ${data.retention.ttlDays === null ? "null" : typeof data.retention.ttlDays === "number" ? String(data.retention.ttlDays) : "null"}${typeof data.retention.archiveAfterDays === "number" ? `, archiveAfterDays: ${data.retention.archiveAfterDays}` : ""} }`;
42
+ }
43
+ function renderAccess(data) {
44
+ return `${` trustLevel: '${data.trustLevel}',\n`}${` automationWritable: ${data.automationWritable},\n`}`;
26
45
  }
27
- `}function r(e){return`{ ttlDays: ${e.retention.ttlDays===null?`null`:typeof e.retention.ttlDays==`number`?String(e.retention.ttlDays):`null`}${typeof e.retention.archiveAfterDays==`number`?`, archiveAfterDays: ${e.retention.archiveAfterDays}`:``} }`}function i(e){return`${` trustLevel: '${e.trustLevel}',\n`}${` automationWritable: ${e.automationWritable},\n`}`}function a(e){let t=[];return e.embeddingModel&&t.push(` embeddingModel: '${s(e.embeddingModel)}'`),typeof e.chunkSize==`number`&&t.push(` chunkSize: ${e.chunkSize}`),e.vectorDbIntegration&&t.push(` vectorDbIntegration: '${s(e.vectorDbIntegration)}'`),t.length===0?``:` indexing: {\n${t.join(`,
28
- `)}\n },\n`}function o(e){switch(e){case`beta`:return`Beta`;case`stable`:return`Stable`;case`deprecated`:return`Deprecated`;case`experimental`:default:return`Experimental`}}function s(e){return e.replace(/`/g,"\\`").replace(/'/g,`\\'`)}export{n as generateKnowledgeSpaceSpec};
46
+ function renderIndexing(data) {
47
+ const entries = [];
48
+ if (data.embeddingModel) entries.push(` embeddingModel: '${escape(data.embeddingModel)}'`);
49
+ if (typeof data.chunkSize === "number") entries.push(` chunkSize: ${data.chunkSize}`);
50
+ if (data.vectorDbIntegration) entries.push(` vectorDbIntegration: '${escape(data.vectorDbIntegration)}'`);
51
+ if (entries.length === 0) return "";
52
+ return ` indexing: {\n${entries.join(",\n")}\n },\n`;
53
+ }
54
+ function stabilityToEnum(stability) {
55
+ switch (stability) {
56
+ case "beta": return "Beta";
57
+ case "stable": return "Stable";
58
+ case "deprecated": return "Deprecated";
59
+ case "experimental":
60
+ default: return "Experimental";
61
+ }
62
+ }
63
+ function escape(value) {
64
+ return value.replace(/`/g, "\\`").replace(/'/g, "\\'");
65
+ }
66
+
67
+ //#endregion
68
+ export { generateKnowledgeSpaceSpec };
@@ -1,37 +1,60 @@
1
- import{escapeString as e,toPascalCase as t}from"./utils.js";function n(n){let a=`${t(n.name.split(`.`).pop()??`Migration`)}Migration`,o=n.dependencies.length>0?`dependencies: [${n.dependencies.map(t=>`'${e(t)}'`).join(`, `)}],`:``;return`import type { MigrationSpec } from '@lssm/lib.contracts/migrations';
1
+ import { escapeString, toPascalCase } from "./utils.js";
2
2
 
3
- export const ${a}: MigrationSpec = {
3
+ //#region src/templates/migration.ts
4
+ function generateMigrationSpec(data) {
5
+ const migrationVar = `${toPascalCase(data.name.split(".").pop() ?? "Migration")}Migration`;
6
+ const dependencies = data.dependencies.length > 0 ? `dependencies: [${data.dependencies.map((dep) => `'${escapeString(dep)}'`).join(", ")}],` : "";
7
+ return `import type { MigrationSpec } from '@lssm/lib.contracts/migrations';
8
+
9
+ export const ${migrationVar}: MigrationSpec = {
4
10
  meta: {
5
- name: '${e(n.name)}',
6
- version: ${n.version},
7
- title: '${i(n.title)}',
8
- description: '${i(n.description??``)}',
9
- domain: '${i(n.domain)}',
10
- owners: [${n.owners.map(t=>`'${e(t)}'`).join(`, `)}],
11
- tags: [${n.tags.map(t=>`'${e(t)}'`).join(`, `)}],
12
- stability: '${n.stability}',
11
+ name: '${escapeString(data.name)}',
12
+ version: ${data.version},
13
+ title: '${escape(data.title)}',
14
+ description: '${escape(data.description ?? "")}',
15
+ domain: '${escape(data.domain)}',
16
+ owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
17
+ tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
18
+ stability: '${data.stability}',
13
19
  },
14
20
  plan: {
15
21
  up: [
16
- ${r(n.up)}
17
- ],${n.down&&n.down.length?`
22
+ ${renderSteps(data.up)}
23
+ ],${data.down && data.down.length ? `
18
24
  down: [
19
- ${r(n.down)}
20
- ],`:``}
25
+ ${renderSteps(data.down)}
26
+ ],` : ""}
21
27
  },
22
- ${o}
28
+ ${dependencies}
23
29
  };
24
- `}function r(e){return e.map(e=>{let t=e.description?`description: '${i(e.description)}',`:``;switch(e.kind){case`schema`:return` {
30
+ `;
31
+ }
32
+ function renderSteps(steps) {
33
+ return steps.map((step) => {
34
+ const description = step.description ? `description: '${escape(step.description)}',` : "";
35
+ switch (step.kind) {
36
+ case "schema": return ` {
25
37
  kind: 'schema',
26
- ${t}
27
- sql: \`${i(e.sql??``)}\`,
28
- }`;case`data`:return` {
38
+ ${description}
39
+ sql: \`${escape(step.sql ?? "")}\`,
40
+ }`;
41
+ case "data": return ` {
29
42
  kind: 'data',
30
- ${t}
31
- script: \`${i(e.script??``)}\`,
32
- }`;case`validation`:default:return` {
43
+ ${description}
44
+ script: \`${escape(step.script ?? "")}\`,
45
+ }`;
46
+ case "validation":
47
+ default: return ` {
33
48
  kind: 'validation',
34
- ${t}
35
- assertion: \`${i(e.assertion??``)}\`,
36
- }`}}).join(`,
37
- `)}function i(e){return e.replace(/`/g,"\\`").replace(/'/g,`\\'`)}export{n as generateMigrationSpec};
49
+ ${description}
50
+ assertion: \`${escape(step.assertion ?? "")}\`,
51
+ }`;
52
+ }
53
+ }).join(",\n");
54
+ }
55
+ function escape(value) {
56
+ return value.replace(/`/g, "\\`").replace(/'/g, "\\'");
57
+ }
58
+
59
+ //#endregion
60
+ export { generateMigrationSpec };
@@ -1,10 +1,21 @@
1
- import{capitalize as e,toPascalCase as t}from"./utils.js";function n(n){let{name:r,version:i,kind:a,description:o,goal:s,context:c,stability:l,owners:u,tags:d,auth:f,flags:p}=n,m=t(r.split(`.`).pop()??`Unknown`)+`Spec`,h=m.replace(`Spec`,`Input`),g=m.replace(`Spec`,`Output`);return`import { define${e(a)} } from '@lssm/lib.contracts';
1
+ import { capitalize, toPascalCase } from "./utils.js";
2
+
3
+ //#region src/templates/operation.ts
4
+ /**
5
+ * Generate operation spec TypeScript code.
6
+ */
7
+ function generateOperationSpec(data) {
8
+ const { name, version, kind, description, goal, context, stability, owners, tags, auth, flags } = data;
9
+ const specVarName = toPascalCase(name.split(".").pop() ?? "Unknown") + "Spec";
10
+ const inputSchemaName = specVarName.replace("Spec", "Input");
11
+ const outputSchemaName = specVarName.replace("Spec", "Output");
12
+ return `import { define${capitalize(kind)} } from '@lssm/lib.contracts';
2
13
  import { ScalarTypeEnum, SchemaModel } from '@lssm/lib.schema';
3
14
 
4
15
  // TODO: Define input schema
5
- export const ${h} = new SchemaModel({
6
- name: '${h}',
7
- description: 'Input for ${r}',
16
+ export const ${inputSchemaName} = new SchemaModel({
17
+ name: '${inputSchemaName}',
18
+ description: 'Input for ${name}',
8
19
  fields: {
9
20
  // Add your fields here
10
21
  // example: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
@@ -12,30 +23,30 @@ export const ${h} = new SchemaModel({
12
23
  });
13
24
 
14
25
  // TODO: Define output schema
15
- export const ${g} = new SchemaModel({
16
- name: '${g}',
17
- description: 'Output for ${r}',
26
+ export const ${outputSchemaName} = new SchemaModel({
27
+ name: '${outputSchemaName}',
28
+ description: 'Output for ${name}',
18
29
  fields: {
19
30
  // Add your fields here
20
31
  ok: { type: ScalarTypeEnum.Boolean(), isOptional: false },
21
32
  },
22
33
  });
23
34
 
24
- export const ${m} = define${e(a)}({
35
+ export const ${specVarName} = define${capitalize(kind)}({
25
36
  meta: {
26
- name: '${r}',
27
- version: ${i},
28
- stability: '${l}',
29
- owners: [${u.map(e=>`'${e}'`).join(`, `)}],
30
- tags: [${d.map(e=>`'${e}'`).join(`, `)}],
31
- description: '${o}',
32
- goal: '${s}',
33
- context: '${c}',
37
+ name: '${name}',
38
+ version: ${version},
39
+ stability: '${stability}',
40
+ owners: [${owners.map((o) => `'${o}'`).join(", ")}],
41
+ tags: [${tags.map((t) => `'${t}'`).join(", ")}],
42
+ description: '${description}',
43
+ goal: '${goal}',
44
+ context: '${context}',
34
45
  },
35
46
 
36
47
  io: {
37
- input: ${h},
38
- output: ${g},
48
+ input: ${inputSchemaName},
49
+ output: ${outputSchemaName},
39
50
  errors: {
40
51
  // Define possible errors
41
52
  // EXAMPLE_ERROR: {
@@ -47,24 +58,21 @@ export const ${m} = define${e(a)}({
47
58
  },
48
59
 
49
60
  policy: {
50
- auth: '${f}',
51
- ${p.length>0?`flags: [${p.map(e=>`'${e}'`).join(`, `)}],`:`// flags: [],`}
61
+ auth: '${auth}',
62
+ ${flags.length > 0 ? `flags: [${flags.map((f) => `'${f}'`).join(", ")}],` : "// flags: [],"}
52
63
  },
53
64
 
54
65
  sideEffects: {
55
- ${n.emitsEvents?`emits: [
56
- // Define events to emit
57
- // { ref: SomeEventSpec, when: 'always' }
58
- ],`:`// emits: [],`}
66
+ ${data.emitsEvents ? "emits: [\n // Define events to emit\n // { ref: SomeEventSpec, when: 'always' }\n ]," : "// emits: [],"}
59
67
  analytics: [
60
68
  // Define analytics events
61
69
  ],
62
70
  },
63
71
 
64
72
  transport: {
65
- rest: { method: '${a===`command`?`POST`:`GET`}' },
66
- gql: { field: '${r.replace(/\./g,`_`)}' },
67
- mcp: { toolName: '${r}.v${i}' },
73
+ rest: { method: '${kind === "command" ? "POST" : "GET"}' },
74
+ gql: { field: '${name.replace(/\./g, "_")}' },
75
+ mcp: { toolName: '${name}.v${version}' },
68
76
  },
69
77
 
70
78
  acceptance: {
@@ -85,4 +93,8 @@ export const ${m} = define${e(a)}({
85
93
  ],
86
94
  },
87
95
  });
88
- `}export{n as generateOperationSpec};
96
+ `;
97
+ }
98
+
99
+ //#endregion
100
+ export { generateOperationSpec };
@@ -1,10 +1,22 @@
1
- import{toPascalCase as e}from"./utils.js";function t(t){let{name:n,version:r,description:i,stability:a,owners:o,tags:s,presentationKind:c}=t,l=e(n.replace(/\./g,`_`))+`Presentation`,u=``;switch(c){case`web_component`:u=` content: {
1
+ import { toPascalCase } from "./utils.js";
2
+
3
+ //#region src/templates/presentation.ts
4
+ /**
5
+ * Generate presentation spec TypeScript code.
6
+ */
7
+ function generatePresentationSpec(data) {
8
+ const { name, version, description, stability, owners, tags, presentationKind } = data;
9
+ const varName = toPascalCase(name.replace(/\./g, "_")) + "Presentation";
10
+ let contentBlock = "";
11
+ switch (presentationKind) {
12
+ case "web_component":
13
+ contentBlock = ` content: {
2
14
  kind: 'web_component',
3
15
  framework: 'react',
4
- componentKey: '${n.replace(/\./g,`_`)}',
16
+ componentKey: '${name.replace(/\./g, "_")}',
5
17
  props: new SchemaModel({
6
- name: '${l}Props',
7
- description: 'Props for ${n}',
18
+ name: '${varName}Props',
19
+ description: 'Props for ${name}',
8
20
  fields: {
9
21
  // TODO: Define component props
10
22
  },
@@ -12,35 +24,44 @@ import{toPascalCase as e}from"./utils.js";function t(t){let{name:n,version:r,des
12
24
  analytics: [
13
25
  // TODO: Define analytics events
14
26
  ],
15
- },`;break;case`markdown`:u=` content: {
27
+ },`;
28
+ break;
29
+ case "markdown":
30
+ contentBlock = ` content: {
16
31
  kind: 'markdown',
17
32
  content: \`
18
- # ${i}
33
+ # ${description}
19
34
 
20
35
  TODO: Add markdown content here
21
36
  \`,
22
- // Or use resourceUri: 'feature://${n}/guide.md'
23
- },`;break;case`data`:u=` content: {
37
+ // Or use resourceUri: 'feature://${name}/guide.md'
38
+ },`;
39
+ break;
40
+ case "data":
41
+ contentBlock = ` content: {
24
42
  kind: 'data',
25
43
  mimeType: 'application/json',
26
44
  model: new SchemaModel({
27
- name: '${l}Data',
28
- description: 'Data structure for ${n}',
45
+ name: '${varName}Data',
46
+ description: 'Data structure for ${name}',
29
47
  fields: {
30
48
  // TODO: Define data structure
31
49
  },
32
50
  }),
33
- },`;break}return`import type { PresentationSpec } from '@lssm/lib.contracts/presentations';
51
+ },`;
52
+ break;
53
+ }
54
+ return `import type { PresentationSpec } from '@lssm/lib.contracts/presentations';
34
55
  import { SchemaModel, ScalarTypeEnum } from '@lssm/lib.schema';
35
56
 
36
- export const ${l}: PresentationSpec = {
57
+ export const ${varName}: PresentationSpec = {
37
58
  meta: {
38
- name: '${n}',
39
- version: ${r},
40
- stability: '${a}',
41
- owners: [${o.map(e=>`'${e}'`).join(`, `)}],
42
- tags: [${s.map(e=>`'${e}'`).join(`, `)}],
43
- description: '${i}',
59
+ name: '${name}',
60
+ version: ${version},
61
+ stability: '${stability}',
62
+ owners: [${owners.map((o) => `'${o}'`).join(", ")}],
63
+ tags: [${tags.map((t) => `'${t}'`).join(", ")}],
64
+ description: '${description}',
44
65
  },
45
66
 
46
67
  policy: {
@@ -48,6 +69,10 @@ export const ${l}: PresentationSpec = {
48
69
  // pii: [],
49
70
  },
50
71
 
51
- ${u}
72
+ ${contentBlock}
52
73
  };
53
- `}export{t as generatePresentationSpec};
74
+ `;
75
+ }
76
+
77
+ //#endregion
78
+ export { generatePresentationSpec };