@contractspec/module.workspace 0.0.0-canary-20260113162409
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 +50 -0
- package/dist/ai/prompts/code-generation.d.ts +24 -0
- package/dist/ai/prompts/code-generation.d.ts.map +1 -0
- package/dist/ai/prompts/code-generation.js +134 -0
- package/dist/ai/prompts/code-generation.js.map +1 -0
- package/dist/ai/prompts/spec-creation.d.ts +28 -0
- package/dist/ai/prompts/spec-creation.d.ts.map +1 -0
- package/dist/ai/prompts/spec-creation.js +102 -0
- package/dist/ai/prompts/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 -0
- 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 -0
- 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 -0
- package/dist/analysis/diff/semantic.js.map +1 -0
- package/dist/analysis/example-scan.d.ts +15 -0
- package/dist/analysis/example-scan.d.ts.map +1 -0
- package/dist/analysis/example-scan.js +116 -0
- package/dist/analysis/example-scan.js.map +1 -0
- package/dist/analysis/feature-extractor.js +203 -0
- package/dist/analysis/feature-extractor.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 +56 -0
- 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 +18 -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 +67 -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 +74 -0
- package/dist/analysis/snapshot/types.d.ts.map +1 -0
- package/dist/analysis/spec-parser.d.ts +11 -0
- package/dist/analysis/spec-parser.d.ts.map +1 -0
- package/dist/analysis/spec-parser.js +89 -0
- package/dist/analysis/spec-parser.js.map +1 -0
- package/dist/analysis/spec-parsing-utils.d.ts +26 -0
- package/dist/analysis/spec-parsing-utils.d.ts.map +1 -0
- package/dist/analysis/spec-parsing-utils.js +98 -0
- package/dist/analysis/spec-parsing-utils.js.map +1 -0
- package/dist/analysis/spec-scan.d.ts +20 -0
- package/dist/analysis/spec-scan.d.ts.map +1 -0
- package/dist/analysis/spec-scan.js +141 -0
- package/dist/analysis/spec-scan.js.map +1 -0
- package/dist/analysis/utils/matchers.js +77 -0
- package/dist/analysis/utils/matchers.js.map +1 -0
- package/dist/analysis/utils/variables.js +45 -0
- package/dist/analysis/utils/variables.js.map +1 -0
- package/dist/analysis/validate/index.js +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 +455 -0
- package/dist/analysis/validate/spec-structure.js.map +1 -0
- package/dist/formatter.d.ts +42 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +163 -0
- package/dist/formatter.js.map +1 -0
- package/dist/formatters/index.js +2 -0
- package/dist/formatters/spec-markdown.d.ts +31 -0
- package/dist/formatters/spec-markdown.d.ts.map +1 -0
- package/dist/formatters/spec-markdown.js +263 -0
- package/dist/formatters/spec-markdown.js.map +1 -0
- package/dist/formatters/spec-to-docblock.d.ts +14 -0
- package/dist/formatters/spec-to-docblock.d.ts.map +1 -0
- package/dist/formatters/spec-to-docblock.js +48 -0
- package/dist/formatters/spec-to-docblock.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +39 -0
- 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 +107 -0
- 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 +69 -0
- 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 +41 -0
- 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 +88 -0
- 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 +96 -0
- package/dist/templates/handler.js.map +1 -0
- package/dist/templates/integration-utils.js +105 -0
- 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 +62 -0
- 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 +69 -0
- 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 +61 -0
- 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 +101 -0
- 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 +79 -0
- 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 +90 -0
- 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 -0
- 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 +49 -0
- 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 +68 -0
- package/dist/templates/workflow.js.map +1 -0
- package/dist/types/analysis-types.d.ts +199 -0
- package/dist/types/analysis-types.d.ts.map +1 -0
- package/dist/types/generation-types.d.ts +87 -0
- package/dist/types/generation-types.d.ts.map +1 -0
- package/dist/types/generation-types.js +21 -0
- package/dist/types/generation-types.js.map +1 -0
- package/dist/types/llm-types.d.ts +138 -0
- package/dist/types/llm-types.d.ts.map +1 -0
- package/dist/types/rulesync-types.d.ts +24 -0
- package/dist/types/rulesync-types.d.ts.map +1 -0
- package/dist/types/spec-types.d.ts +343 -0
- package/dist/types/spec-types.d.ts.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AppBlueprintSpecData, AppConfigFeatureFlagData, AppConfigMappingData, AppRouteConfigData, BaseSpecData, DataViewFieldData, DataViewKind, DataViewSpecData, EventSpecData, ExperimentAllocationData, ExperimentMetricData, ExperimentSpecData, ExperimentVariantData, ExperimentVariantOverrideData, FeatureSpecData, FormSpecData, IntegrationCapabilityRefData, IntegrationCapabilityRequirementData, IntegrationCategoryData, IntegrationConfigFieldData, IntegrationConfigFieldType, IntegrationHealthCheckMethod, IntegrationOwnershipModeData, IntegrationSecretFieldData, IntegrationSpecData, KnowledgeCategoryData, KnowledgeRetentionData, KnowledgeSpaceSpecData, KnowledgeTrustLevel, MigrationSpecData, MigrationStepData, MigrationStepKind, OperationSpecData, PresentationKind, PresentationSpecData, RandomAllocationData, SpecType, Stability, StepType, StickyAllocationData, TargetedAllocationData, TargetingRuleData, TelemetryAnomalyRuleData, TelemetryEventData, TelemetryPrivacy, TelemetryPropertyData, TelemetryProviderData, TelemetrySpecData, WorkflowSpecData, WorkflowStepData, WorkflowTransitionData } from "./types/spec-types.js";
|
|
2
|
+
import { AnalyzedOperationKind, AnalyzedSpecType, ContractGraph, ContractNode, ExampleScanResult, ExtractedRef, ExtractedTestTarget, FeatureScanResult, RefInfo, RefType, SemanticDiffItem, SemanticDiffOptions, SemanticDiffType, SpecScanResult, ValidationResult } from "./types/analysis-types.js";
|
|
3
|
+
import { RuleSyncConfig } from "./types/rulesync-types.js";
|
|
4
|
+
import { AIGenerationOptions, CodeGenerationContext, DEFAULT_WORKSPACE_CONFIG, GenerationResult, GenerationTarget, SpecBuildType, SpecGenerationContext, TestTarget, WorkspaceConfig } from "./types/generation-types.js";
|
|
5
|
+
import { AgentType, LLMExportFormat, LLMExportResult, ParsedSpec, ParsedSpecMeta, SpecRef, SpecToMarkdownOptions, VerificationIssue, VerificationResult, VerificationTier } from "./types/llm-types.js";
|
|
6
|
+
import { extractTestCoverage, extractTestTarget } from "./analysis/spec-parsing-utils.js";
|
|
7
|
+
import { inferSpecTypeFromFilePath, scanAllSpecsFromSource, scanSpecSource } from "./analysis/spec-scan.js";
|
|
8
|
+
import { isFeatureFile, scanFeatureSource } from "./analysis/feature-scan.js";
|
|
9
|
+
import { isExampleFile, scanExampleSource } from "./analysis/example-scan.js";
|
|
10
|
+
import { GroupKeyFn, GroupedItems, SpecFilter, SpecGroupingStrategies, filterFeatures, filterSpecs, getUniqueSpecDomains, getUniqueSpecOwners, getUniqueSpecTags, groupSpecs, groupSpecsToArray } from "./analysis/grouping.js";
|
|
11
|
+
import { computeSemanticDiff } from "./analysis/diff/semantic.js";
|
|
12
|
+
import { ContractSnapshot, EventSnapshot, FieldSnapshot, FieldType, HttpBindingSnapshot, IoSnapshot, OperationSnapshot, SnapshotOptions, SpecSnapshot } from "./analysis/snapshot/types.js";
|
|
13
|
+
import { DeepDiffOptions, computeFieldDiff, computeFieldsDiff, computeIoDiff, isBreakingChange } from "./analysis/diff/deep-diff.js";
|
|
14
|
+
import { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot } from "./analysis/deps/graph.js";
|
|
15
|
+
import { parseImportedSpecNames } from "./analysis/deps/parse-imports.js";
|
|
16
|
+
import { RuleSeverity, RulesConfig, SpecKind, validateSpecStructure } from "./analysis/validate/spec-structure.js";
|
|
17
|
+
import { computeHash, normalizeValue, sortFields, sortSpecs, toCanonicalJson } from "./analysis/snapshot/normalizer.js";
|
|
18
|
+
import { generateSnapshot } from "./analysis/snapshot/snapshot.js";
|
|
19
|
+
import { ClassifyOptions, ImpactDelta, ImpactResult, ImpactRule, ImpactSeverity, ImpactStatus, ImpactSummary } from "./analysis/impact/types.js";
|
|
20
|
+
import { BREAKING_RULES, DEFAULT_RULES, INFO_RULES, NON_BREAKING_RULES, findMatchingRule, getRulesBySeverity } from "./analysis/impact/rules.js";
|
|
21
|
+
import { classifyImpact } from "./analysis/impact/classifier.js";
|
|
22
|
+
import { loadSpecFromSource } from "./analysis/spec-parser.js";
|
|
23
|
+
import { generateOperationSpec } from "./templates/operation.js";
|
|
24
|
+
import { generateEventSpec } from "./templates/event.js";
|
|
25
|
+
import { generatePresentationSpec } from "./templates/presentation.js";
|
|
26
|
+
import { generateWorkflowSpec } from "./templates/workflow.js";
|
|
27
|
+
import { generateWorkflowRunnerTemplate } from "./templates/workflow-runner.js";
|
|
28
|
+
import { generateDataViewSpec } from "./templates/data-view.js";
|
|
29
|
+
import { generateTelemetrySpec } from "./templates/telemetry.js";
|
|
30
|
+
import { generateExperimentSpec } from "./templates/experiment.js";
|
|
31
|
+
import { generateAppBlueprintSpec } from "./templates/app-config.js";
|
|
32
|
+
import { generateMigrationSpec } from "./templates/migration.js";
|
|
33
|
+
import { generateIntegrationSpec } from "./templates/integration.js";
|
|
34
|
+
import { generateKnowledgeSpaceSpec } from "./templates/knowledge.js";
|
|
35
|
+
import { generateComponentTemplate, generateHandlerTemplate, generateTestTemplate } from "./templates/handler.js";
|
|
36
|
+
import { capitalize, escapeString, toCamelCase, toKebabCase, toPascalCase } from "./templates/utils.js";
|
|
37
|
+
import { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt } from "./ai/prompts/spec-creation.js";
|
|
38
|
+
import { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt } from "./ai/prompts/code-generation.js";
|
|
39
|
+
import { FormatLogger, FormatResult, FormatterOptions, detectFormatter, formatFiles, formatFilesBatch } from "./formatter.js";
|
|
40
|
+
import { combineSpecMarkdowns, generateSpecsSummaryHeader, specToMarkdown, specToMarkdownWithOptions } from "./formatters/spec-markdown.js";
|
|
41
|
+
import { convertSpecToDocBlock } from "./formatters/spec-to-docblock.js";
|
|
42
|
+
export { AIGenerationOptions, AgentType, AnalyzedOperationKind, AnalyzedSpecType, AppBlueprintSpecData, AppConfigFeatureFlagData, AppConfigMappingData, AppRouteConfigData, BREAKING_RULES, BaseSpecData, ClassifyOptions, CodeGenerationContext, ContractGraph, ContractNode, ContractSnapshot, DEFAULT_RULES, DEFAULT_WORKSPACE_CONFIG, DataViewFieldData, DataViewKind, DataViewSpecData, DeepDiffOptions, EventSnapshot, EventSpecData, ExampleScanResult, ExperimentAllocationData, ExperimentMetricData, ExperimentSpecData, ExperimentVariantData, ExperimentVariantOverrideData, ExtractedRef, ExtractedTestTarget, FeatureScanResult, FeatureSpecData, FieldSnapshot, FieldType, FormSpecData, FormatLogger, FormatResult, FormatterOptions, GenerationResult, GenerationTarget, GroupKeyFn, GroupedItems, HttpBindingSnapshot, INFO_RULES, ImpactDelta, ImpactResult, ImpactRule, ImpactSeverity, ImpactStatus, ImpactSummary, IntegrationCapabilityRefData, IntegrationCapabilityRequirementData, IntegrationCategoryData, IntegrationConfigFieldData, IntegrationConfigFieldType, IntegrationHealthCheckMethod, IntegrationOwnershipModeData, IntegrationSecretFieldData, IntegrationSpecData, IoSnapshot, KnowledgeCategoryData, KnowledgeRetentionData, KnowledgeSpaceSpecData, KnowledgeTrustLevel, LLMExportFormat, LLMExportResult, MigrationSpecData, MigrationStepData, MigrationStepKind, NON_BREAKING_RULES, OperationSnapshot, OperationSpecData, ParsedSpec, ParsedSpecMeta, PresentationKind, PresentationSpecData, RandomAllocationData, RefInfo, RefType, RuleSeverity, RuleSyncConfig, RulesConfig, SemanticDiffItem, SemanticDiffOptions, SemanticDiffType, SnapshotOptions, SpecBuildType, SpecFilter, SpecGenerationContext, SpecGroupingStrategies, SpecKind, SpecRef, SpecScanResult, SpecSnapshot, SpecToMarkdownOptions, SpecType, Stability, StepType, StickyAllocationData, TargetedAllocationData, TargetingRuleData, TelemetryAnomalyRuleData, TelemetryEventData, TelemetryPrivacy, TelemetryPropertyData, TelemetryProviderData, TelemetrySpecData, TestTarget, ValidationResult, VerificationIssue, VerificationResult, VerificationTier, WorkflowSpecData, WorkflowStepData, WorkflowTransitionData, WorkspaceConfig, addContractNode, addExampleContext, buildComponentPrompt, buildEventSpecPrompt, buildFormPrompt, buildHandlerPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, buildReverseEdges, buildTestPrompt, capitalize, classifyImpact, combineSpecMarkdowns, computeFieldDiff, computeFieldsDiff, computeHash, computeIoDiff, computeSemanticDiff, convertSpecToDocBlock, createContractGraph, detectCycles, detectFormatter, escapeString, extractTestCoverage, extractTestTarget, filterFeatures, filterSpecs, findMatchingRule, findMissingDependencies, formatFiles, formatFilesBatch, generateAppBlueprintSpec, generateComponentTemplate, generateDataViewSpec, generateEventSpec, generateExperimentSpec, generateHandlerTemplate, generateIntegrationSpec, generateKnowledgeSpaceSpec, generateMigrationSpec, generateOperationSpec, generatePresentationSpec, generateSnapshot, generateSpecsSummaryHeader, generateTelemetrySpec, generateTestTemplate, generateWorkflowRunnerTemplate, generateWorkflowSpec, getCodeGenSystemPrompt, getRulesBySeverity, getSystemPrompt, getUniqueSpecDomains, getUniqueSpecOwners, getUniqueSpecTags, groupSpecs, groupSpecsToArray, inferSpecTypeFromFilePath, isBreakingChange, isExampleFile, isFeatureFile, loadSpecFromSource, normalizeValue, parseImportedSpecNames, scanAllSpecsFromSource, scanExampleSource, scanFeatureSource, scanSpecSource, sortFields, sortSpecs, specToMarkdown, specToMarkdownWithOptions, toCamelCase, toCanonicalJson, toDot, toKebabCase, toPascalCase, validateSpecStructure };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DEFAULT_WORKSPACE_CONFIG } from "./types/generation-types.js";
|
|
2
|
+
import { extractTestCoverage, extractTestTarget } from "./analysis/spec-parsing-utils.js";
|
|
3
|
+
import { inferSpecTypeFromFilePath, scanAllSpecsFromSource, scanSpecSource } from "./analysis/spec-scan.js";
|
|
4
|
+
import { isFeatureFile, scanFeatureSource } from "./analysis/feature-scan.js";
|
|
5
|
+
import { isExampleFile, scanExampleSource } from "./analysis/example-scan.js";
|
|
6
|
+
import { SpecGroupingStrategies, filterFeatures, filterSpecs, getUniqueSpecDomains, getUniqueSpecOwners, getUniqueSpecTags, groupSpecs, groupSpecsToArray } from "./analysis/grouping.js";
|
|
7
|
+
import { computeSemanticDiff } from "./analysis/diff/semantic.js";
|
|
8
|
+
import { computeFieldDiff, computeFieldsDiff, computeIoDiff, isBreakingChange } from "./analysis/diff/deep-diff.js";
|
|
9
|
+
import { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot } from "./analysis/deps/graph.js";
|
|
10
|
+
import { parseImportedSpecNames } from "./analysis/deps/parse-imports.js";
|
|
11
|
+
import { validateSpecStructure } from "./analysis/validate/spec-structure.js";
|
|
12
|
+
import { computeHash, normalizeValue, sortFields, sortSpecs, toCanonicalJson } from "./analysis/snapshot/normalizer.js";
|
|
13
|
+
import { generateSnapshot } from "./analysis/snapshot/snapshot.js";
|
|
14
|
+
import { BREAKING_RULES, DEFAULT_RULES, INFO_RULES, NON_BREAKING_RULES, findMatchingRule, getRulesBySeverity } from "./analysis/impact/rules.js";
|
|
15
|
+
import { classifyImpact } from "./analysis/impact/classifier.js";
|
|
16
|
+
import { loadSpecFromSource } from "./analysis/spec-parser.js";
|
|
17
|
+
import "./analysis/index.js";
|
|
18
|
+
import { capitalize, escapeString, toCamelCase, toKebabCase, toPascalCase } from "./templates/utils.js";
|
|
19
|
+
import { generateOperationSpec } from "./templates/operation.js";
|
|
20
|
+
import { generateEventSpec } from "./templates/event.js";
|
|
21
|
+
import { generatePresentationSpec } from "./templates/presentation.js";
|
|
22
|
+
import { generateWorkflowSpec } from "./templates/workflow.js";
|
|
23
|
+
import { generateWorkflowRunnerTemplate } from "./templates/workflow-runner.js";
|
|
24
|
+
import { generateDataViewSpec } from "./templates/data-view.js";
|
|
25
|
+
import { generateTelemetrySpec } from "./templates/telemetry.js";
|
|
26
|
+
import { generateExperimentSpec } from "./templates/experiment.js";
|
|
27
|
+
import { generateAppBlueprintSpec } from "./templates/app-config.js";
|
|
28
|
+
import { generateMigrationSpec } from "./templates/migration.js";
|
|
29
|
+
import { generateIntegrationSpec } from "./templates/integration.js";
|
|
30
|
+
import { generateKnowledgeSpaceSpec } from "./templates/knowledge.js";
|
|
31
|
+
import { generateComponentTemplate, generateHandlerTemplate, generateTestTemplate } from "./templates/handler.js";
|
|
32
|
+
import { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt } from "./ai/prompts/spec-creation.js";
|
|
33
|
+
import { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt } from "./ai/prompts/code-generation.js";
|
|
34
|
+
import { detectFormatter, formatFiles, formatFilesBatch } from "./formatter.js";
|
|
35
|
+
import { combineSpecMarkdowns, generateSpecsSummaryHeader, specToMarkdown, specToMarkdownWithOptions } from "./formatters/spec-markdown.js";
|
|
36
|
+
import { convertSpecToDocBlock } from "./formatters/spec-to-docblock.js";
|
|
37
|
+
import "./formatters/index.js";
|
|
38
|
+
|
|
39
|
+
export { BREAKING_RULES, DEFAULT_RULES, DEFAULT_WORKSPACE_CONFIG, INFO_RULES, NON_BREAKING_RULES, SpecGroupingStrategies, addContractNode, addExampleContext, buildComponentPrompt, buildEventSpecPrompt, buildFormPrompt, buildHandlerPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, buildReverseEdges, buildTestPrompt, capitalize, classifyImpact, combineSpecMarkdowns, computeFieldDiff, computeFieldsDiff, computeHash, computeIoDiff, computeSemanticDiff, convertSpecToDocBlock, createContractGraph, detectCycles, detectFormatter, escapeString, extractTestCoverage, extractTestTarget, filterFeatures, filterSpecs, findMatchingRule, findMissingDependencies, formatFiles, formatFilesBatch, generateAppBlueprintSpec, generateComponentTemplate, generateDataViewSpec, generateEventSpec, generateExperimentSpec, generateHandlerTemplate, generateIntegrationSpec, generateKnowledgeSpaceSpec, generateMigrationSpec, generateOperationSpec, generatePresentationSpec, generateSnapshot, generateSpecsSummaryHeader, generateTelemetrySpec, generateTestTemplate, generateWorkflowRunnerTemplate, generateWorkflowSpec, getCodeGenSystemPrompt, getRulesBySeverity, getSystemPrompt, getUniqueSpecDomains, getUniqueSpecOwners, getUniqueSpecTags, groupSpecs, groupSpecsToArray, inferSpecTypeFromFilePath, isBreakingChange, isExampleFile, isFeatureFile, loadSpecFromSource, normalizeValue, parseImportedSpecNames, scanAllSpecsFromSource, scanExampleSource, scanFeatureSource, scanSpecSource, sortFields, sortSpecs, specToMarkdown, specToMarkdownWithOptions, toCamelCase, toCanonicalJson, toDot, toKebabCase, toPascalCase, validateSpecStructure };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppBlueprintSpecData } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/app-config.d.ts
|
|
4
|
+
declare function generateAppBlueprintSpec(data: AppBlueprintSpecData): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { generateAppBlueprintSpec };
|
|
7
|
+
//# sourceMappingURL=app-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.d.ts","names":[],"sources":["../../src/templates/app-config.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,wBAAA,OAA+B"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { toPascalCase } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/app-config.ts
|
|
4
|
+
function generateAppBlueprintSpec(data) {
|
|
5
|
+
const exportName = toPascalCase(data.name.split(".").pop() ?? "App") + "AppConfig";
|
|
6
|
+
const capabilitiesSection = buildCapabilitiesSection(data);
|
|
7
|
+
const featuresSection = buildFeaturesSection(data);
|
|
8
|
+
const dataViewsSection = buildMappingSection("dataViews", data.dataViews);
|
|
9
|
+
const workflowsSection = buildMappingSection("workflows", data.workflows);
|
|
10
|
+
const policiesSection = buildPolicySection(data);
|
|
11
|
+
const themeSection = buildThemeSection(data);
|
|
12
|
+
const telemetrySection = buildTelemetrySection(data);
|
|
13
|
+
const experimentsSection = buildExperimentsSection(data);
|
|
14
|
+
const flagsSection = buildFeatureFlagsSection(data);
|
|
15
|
+
const routesSection = buildRoutesSection(data);
|
|
16
|
+
const notesSection = data.notes ? ` notes: '${escapeString(data.notes)}',\n` : "";
|
|
17
|
+
return `import type { AppBlueprintSpec } from '@contractspec/lib.contracts/app-config';
|
|
18
|
+
|
|
19
|
+
export const ${exportName}: AppBlueprintSpec = {
|
|
20
|
+
meta: {
|
|
21
|
+
key: '${escapeString(data.name)}',
|
|
22
|
+
version: '${data.version}',
|
|
23
|
+
title: '${escapeString(data.title)}',
|
|
24
|
+
description: '${escapeString(data.description)}',
|
|
25
|
+
domain: '${escapeString(data.domain)}',
|
|
26
|
+
owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
|
|
27
|
+
tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
|
|
28
|
+
stability: '${data.stability}',
|
|
29
|
+
appId: '${escapeString(data.appId)}',
|
|
30
|
+
},
|
|
31
|
+
${capabilitiesSection}${featuresSection}${dataViewsSection}${workflowsSection}${policiesSection}${themeSection}${telemetrySection}${experimentsSection}${flagsSection}${routesSection}${notesSection}};\n`;
|
|
32
|
+
}
|
|
33
|
+
function buildCapabilitiesSection(data) {
|
|
34
|
+
if (data.capabilitiesEnabled.length === 0 && data.capabilitiesDisabled.length === 0) return "";
|
|
35
|
+
return ` capabilities: {\n${data.capabilitiesEnabled.length > 0 ? ` enabled: [${data.capabilitiesEnabled.map((key) => formatCapabilityRef(key)).join(", ")}],\n` : ""}${data.capabilitiesDisabled.length > 0 ? ` disabled: [${data.capabilitiesDisabled.map((key) => formatCapabilityRef(key)).join(", ")}],\n` : ""} },\n`;
|
|
36
|
+
}
|
|
37
|
+
function buildFeaturesSection(data) {
|
|
38
|
+
if (data.featureIncludes.length === 0 && data.featureExcludes.length === 0) return "";
|
|
39
|
+
return ` features: {\n${data.featureIncludes.length > 0 ? ` include: [${data.featureIncludes.map((key) => `{ key: '${escapeString(key)}' }`).join(", ")}],\n` : ""}${data.featureExcludes.length > 0 ? ` exclude: [${data.featureExcludes.map((key) => `{ key: '${escapeString(key)}' }`).join(", ")}],\n` : ""} },\n`;
|
|
40
|
+
}
|
|
41
|
+
function buildMappingSection(prop, mappings) {
|
|
42
|
+
if (mappings.length === 0) return "";
|
|
43
|
+
return ` ${prop}: {\n${mappings.map((mapping) => ` ${mapping.slot}: {
|
|
44
|
+
name: '${escapeString(mapping.name)}',
|
|
45
|
+
version: '${mapping.version}',
|
|
46
|
+
}`).join(",\n")}\n },\n`;
|
|
47
|
+
}
|
|
48
|
+
function buildPolicySection(data) {
|
|
49
|
+
if (data.policyRefs.length === 0) return "";
|
|
50
|
+
return ` policies: [\n${data.policyRefs.map((policy) => ` {
|
|
51
|
+
name: '${escapeString(policy.name)}',
|
|
52
|
+
version: '${policy.version}',
|
|
53
|
+
}`).join(",\n")}\n ],\n`;
|
|
54
|
+
}
|
|
55
|
+
function buildThemeSection(data) {
|
|
56
|
+
if (!data.theme) return "";
|
|
57
|
+
return ` theme: {\n${` primary: { name: '${escapeString(data.theme.name)}', version: ${data.theme.version} },\n`}${data.themeFallbacks.length > 0 ? ` fallbacks: [${data.themeFallbacks.map((theme) => `{ name: '${escapeString(theme.name)}', version: '${theme.version}' }`).join(", ")}],\n` : ""} },\n`;
|
|
58
|
+
}
|
|
59
|
+
function buildTelemetrySection(data) {
|
|
60
|
+
if (!data.telemetry) return "";
|
|
61
|
+
return ` telemetry: {
|
|
62
|
+
spec: {
|
|
63
|
+
name: '${escapeString(data.telemetry.name)}'${data.telemetry.version !== void 0 ? `,\n version: '${data.telemetry.version}'` : ""}
|
|
64
|
+
},
|
|
65
|
+
},\n`;
|
|
66
|
+
}
|
|
67
|
+
function buildExperimentsSection(data) {
|
|
68
|
+
if (data.activeExperiments.length === 0 && data.pausedExperiments.length === 0) return "";
|
|
69
|
+
return ` experiments: {\n${data.activeExperiments.length > 0 ? ` active: [${data.activeExperiments.map((exp) => formatExperimentRef(exp)).join(", ")}],\n` : ""}${data.pausedExperiments.length > 0 ? ` paused: [${data.pausedExperiments.map((exp) => formatExperimentRef(exp)).join(", ")}],\n` : ""} },\n`;
|
|
70
|
+
}
|
|
71
|
+
function buildFeatureFlagsSection(data) {
|
|
72
|
+
if (data.featureFlags.length === 0) return "";
|
|
73
|
+
return ` featureFlags: [\n${data.featureFlags.map((flag) => ` {
|
|
74
|
+
key: '${escapeString(flag.key)}',
|
|
75
|
+
enabled: ${flag.enabled},
|
|
76
|
+
${flag.variant ? `variant: '${escapeString(flag.variant)}',` : ""}
|
|
77
|
+
${flag.description ? `description: '${escapeString(flag.description)}',` : ""}
|
|
78
|
+
}`).join(",\n")}\n ],\n`;
|
|
79
|
+
}
|
|
80
|
+
function buildRoutesSection(data) {
|
|
81
|
+
if (data.routes.length === 0) return "";
|
|
82
|
+
return ` routes: [\n${data.routes.map((route) => {
|
|
83
|
+
return ` { ${[
|
|
84
|
+
`path: '${escapeString(route.path)}'`,
|
|
85
|
+
route.label ? `label: '${escapeString(route.label)}'` : null,
|
|
86
|
+
route.dataView ? `dataView: '${escapeString(route.dataView)}'` : null,
|
|
87
|
+
route.workflow ? `workflow: '${escapeString(route.workflow)}'` : null,
|
|
88
|
+
route.guardName ? `guard: { name: '${escapeString(route.guardName)}'${route.guardVersion !== void 0 ? `, version: '${route.guardVersion}'` : ""} }` : null,
|
|
89
|
+
route.featureFlag ? `featureFlag: '${escapeString(route.featureFlag)}'` : null,
|
|
90
|
+
route.experimentName ? `experiment: { name: '${escapeString(route.experimentName)}'${route.experimentVersion !== void 0 ? `, version: '${route.experimentVersion}'` : ""} }` : null
|
|
91
|
+
].filter(Boolean).join(", ")} }`;
|
|
92
|
+
}).join(",\n")}\n ],\n`;
|
|
93
|
+
}
|
|
94
|
+
function formatCapabilityRef(key) {
|
|
95
|
+
return `{ key: '${escapeString(key)}' }`;
|
|
96
|
+
}
|
|
97
|
+
function formatExperimentRef(exp) {
|
|
98
|
+
const version = typeof exp.version === "string" ? `, version: ${exp.version}` : "";
|
|
99
|
+
return `{ name: '${escapeString(exp.name)}'${version} }`;
|
|
100
|
+
}
|
|
101
|
+
function escapeString(value) {
|
|
102
|
+
return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { generateAppBlueprintSpec };
|
|
107
|
+
//# sourceMappingURL=app-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.js","names":[],"sources":["../../src/templates/app-config.ts"],"sourcesContent":["import type { AppBlueprintSpecData } from '../types/spec-types';\nimport { toPascalCase } from './utils';\n\nexport function generateAppBlueprintSpec(data: AppBlueprintSpecData): string {\n const exportName =\n toPascalCase(data.name.split('.').pop() ?? 'App') + 'AppConfig';\n\n const capabilitiesSection = buildCapabilitiesSection(data);\n const featuresSection = buildFeaturesSection(data);\n const dataViewsSection = buildMappingSection('dataViews', data.dataViews);\n const workflowsSection = buildMappingSection('workflows', data.workflows);\n const policiesSection = buildPolicySection(data);\n const themeSection = buildThemeSection(data);\n const telemetrySection = buildTelemetrySection(data);\n const experimentsSection = buildExperimentsSection(data);\n const flagsSection = buildFeatureFlagsSection(data);\n const routesSection = buildRoutesSection(data);\n const notesSection = data.notes\n ? ` notes: '${escapeString(data.notes)}',\\n`\n : '';\n\n return `import type { AppBlueprintSpec } from '@contractspec/lib.contracts/app-config';\n\nexport const ${exportName}: AppBlueprintSpec = {\n meta: {\n key: '${escapeString(data.name)}',\n version: '${data.version}',\n title: '${escapeString(data.title)}',\n description: '${escapeString(data.description)}',\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 appId: '${escapeString(data.appId)}',\n },\n${capabilitiesSection}${featuresSection}${dataViewsSection}${workflowsSection}${policiesSection}${themeSection}${telemetrySection}${experimentsSection}${flagsSection}${routesSection}${notesSection}};\\n`;\n}\n\nfunction buildCapabilitiesSection(data: AppBlueprintSpecData): string {\n if (\n data.capabilitiesEnabled.length === 0 &&\n data.capabilitiesDisabled.length === 0\n ) {\n return '';\n }\n const enabled =\n data.capabilitiesEnabled.length > 0\n ? ` enabled: [${data.capabilitiesEnabled.map((key) => formatCapabilityRef(key)).join(', ')}],\\n`\n : '';\n const disabled =\n data.capabilitiesDisabled.length > 0\n ? ` disabled: [${data.capabilitiesDisabled.map((key) => formatCapabilityRef(key)).join(', ')}],\\n`\n : '';\n return ` capabilities: {\\n${enabled}${disabled} },\\n`;\n}\n\nfunction buildFeaturesSection(data: AppBlueprintSpecData): string {\n if (data.featureIncludes.length === 0 && data.featureExcludes.length === 0) {\n return '';\n }\n const include =\n data.featureIncludes.length > 0\n ? ` include: [${data.featureIncludes.map((key) => `{ key: '${escapeString(key)}' }`).join(', ')}],\\n`\n : '';\n const exclude =\n data.featureExcludes.length > 0\n ? ` exclude: [${data.featureExcludes.map((key) => `{ key: '${escapeString(key)}' }`).join(', ')}],\\n`\n : '';\n return ` features: {\\n${include}${exclude} },\\n`;\n}\n\nfunction buildMappingSection(\n prop: 'dataViews' | 'workflows',\n mappings: AppBlueprintSpecData['dataViews']\n): string {\n if (mappings.length === 0) return '';\n const body = mappings\n .map(\n (mapping) => ` ${mapping.slot}: {\n name: '${escapeString(mapping.name)}',\n version: '${mapping.version}',\n }`\n )\n .join(',\\n');\n return ` ${prop}: {\\n${body}\\n },\\n`;\n}\n\nfunction buildPolicySection(data: AppBlueprintSpecData): string {\n if (data.policyRefs.length === 0) return '';\n const entries = data.policyRefs\n .map(\n (policy) => ` {\n name: '${escapeString(policy.name)}',\n version: '${policy.version}',\n }`\n )\n .join(',\\n');\n return ` policies: [\\n${entries}\\n ],\\n`;\n}\n\nfunction buildThemeSection(data: AppBlueprintSpecData): string {\n if (!data.theme) return '';\n const primary = ` primary: { name: '${escapeString(data.theme.name)}', version: ${data.theme.version} },\\n`;\n const fallbacks =\n data.themeFallbacks.length > 0\n ? ` fallbacks: [${data.themeFallbacks\n .map(\n (theme) =>\n `{ name: '${escapeString(theme.name)}', version: '${theme.version}' }`\n )\n .join(', ')}],\\n`\n : '';\n return ` theme: {\\n${primary}${fallbacks} },\\n`;\n}\n\nfunction buildTelemetrySection(data: AppBlueprintSpecData): string {\n if (!data.telemetry) return '';\n return ` telemetry: {\n spec: {\n name: '${escapeString(data.telemetry.name)}'${\n data.telemetry.version !== undefined\n ? `,\\n version: '${data.telemetry.version}'`\n : ''\n }\n },\n },\\n`;\n}\n\nfunction buildExperimentsSection(data: AppBlueprintSpecData): string {\n if (\n data.activeExperiments.length === 0 &&\n data.pausedExperiments.length === 0\n ) {\n return '';\n }\n const active =\n data.activeExperiments.length > 0\n ? ` active: [${data.activeExperiments.map((exp) => formatExperimentRef(exp)).join(', ')}],\\n`\n : '';\n const paused =\n data.pausedExperiments.length > 0\n ? ` paused: [${data.pausedExperiments.map((exp) => formatExperimentRef(exp)).join(', ')}],\\n`\n : '';\n return ` experiments: {\\n${active}${paused} },\\n`;\n}\n\nfunction buildFeatureFlagsSection(data: AppBlueprintSpecData): string {\n if (data.featureFlags.length === 0) return '';\n const flags = data.featureFlags\n .map(\n (flag) => ` {\n key: '${escapeString(flag.key)}',\n enabled: ${flag.enabled},\n ${flag.variant ? `variant: '${escapeString(flag.variant)}',` : ''}\n ${flag.description ? `description: '${escapeString(flag.description)}',` : ''}\n }`\n )\n .join(',\\n');\n return ` featureFlags: [\\n${flags}\\n ],\\n`;\n}\n\nfunction buildRoutesSection(data: AppBlueprintSpecData): string {\n if (data.routes.length === 0) return '';\n const routes = data.routes\n .map((route) => {\n const entries = [\n `path: '${escapeString(route.path)}'`,\n route.label ? `label: '${escapeString(route.label)}'` : null,\n route.dataView ? `dataView: '${escapeString(route.dataView)}'` : null,\n route.workflow ? `workflow: '${escapeString(route.workflow)}'` : null,\n route.guardName\n ? `guard: { name: '${escapeString(route.guardName)}'${\n route.guardVersion !== undefined\n ? `, version: '${route.guardVersion}'`\n : ''\n } }`\n : null,\n route.featureFlag\n ? `featureFlag: '${escapeString(route.featureFlag)}'`\n : null,\n route.experimentName\n ? `experiment: { name: '${escapeString(route.experimentName)}'${\n route.experimentVersion !== undefined\n ? `, version: '${route.experimentVersion}'`\n : ''\n } }`\n : null,\n ].filter(Boolean);\n return ` { ${entries.join(', ')} }`;\n })\n .join(',\\n');\n return ` routes: [\\n${routes}\\n ],\\n`;\n}\n\nfunction formatCapabilityRef(key: string): string {\n return `{ key: '${escapeString(key)}' }`;\n}\n\nfunction formatExperimentRef(exp: { name: string; version?: string }): string {\n const version =\n typeof exp.version === 'string' ? `, version: ${exp.version}` : '';\n return `{ name: '${escapeString(exp.name)}'${version} }`;\n}\n\nfunction escapeString(value: string): string {\n return value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n}\n"],"mappings":";;;AAGA,SAAgB,yBAAyB,MAAoC;CAC3E,MAAM,aACJ,aAAa,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,MAAM,GAAG;CAEtD,MAAM,sBAAsB,yBAAyB,KAAK;CAC1D,MAAM,kBAAkB,qBAAqB,KAAK;CAClD,MAAM,mBAAmB,oBAAoB,aAAa,KAAK,UAAU;CACzE,MAAM,mBAAmB,oBAAoB,aAAa,KAAK,UAAU;CACzE,MAAM,kBAAkB,mBAAmB,KAAK;CAChD,MAAM,eAAe,kBAAkB,KAAK;CAC5C,MAAM,mBAAmB,sBAAsB,KAAK;CACpD,MAAM,qBAAqB,wBAAwB,KAAK;CACxD,MAAM,eAAe,yBAAyB,KAAK;CACnD,MAAM,gBAAgB,mBAAmB,KAAK;CAC9C,MAAM,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,IAAI,YAAY;AAClE,QAAO,YAAY,aAAa,IAAI,KAAK,CAAC,GAAG,QAAQ;;AAGvD,SAAS,aAAa,OAAuB;AAC3C,QAAO,MAAM,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-view.d.ts","names":[],"sources":["../../src/templates/data-view.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,oBAAA,OAA2B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { escapeString, toPascalCase } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/data-view.ts
|
|
4
|
+
function generateDataViewSpec(data) {
|
|
5
|
+
const viewVarName = toPascalCase(data.name.split(".").pop() ?? "DataView") + "DataView";
|
|
6
|
+
const fields = data.fields.map((field) => ` {
|
|
7
|
+
key: '${escapeString(field.key)}',
|
|
8
|
+
label: '${escape(field.label)}',
|
|
9
|
+
dataPath: '${escapeString(field.dataPath)}',
|
|
10
|
+
${field.format ? `format: '${escapeString(field.format)}',` : ""}
|
|
11
|
+
${field.sortable ? "sortable: true," : ""}
|
|
12
|
+
${field.filterable ? "filterable: true," : ""}
|
|
13
|
+
}`).join(",\n");
|
|
14
|
+
const secondaryFields = data.secondaryFields?.length ? `secondaryFields: [${data.secondaryFields.map((key) => `'${escapeString(key)}'`).join(", ")}],` : "";
|
|
15
|
+
const itemOperation = data.itemOperation ? `item: { name: '${escapeString(data.itemOperation.name)}', version: ${data.itemOperation.version} },` : "";
|
|
16
|
+
return `import type { DataViewSpec } from '@contractspec/lib.contracts/data-views';
|
|
17
|
+
|
|
18
|
+
export const ${viewVarName}: DataViewSpec = {
|
|
19
|
+
meta: {
|
|
20
|
+
key: '${escapeString(data.name)}',
|
|
21
|
+
version: ${data.version},
|
|
22
|
+
entity: '${escapeString(data.entity)}',
|
|
23
|
+
title: '${escape(data.title)}',
|
|
24
|
+
description: '${escape(data.description || "Describe the purpose of this data view.")}',
|
|
25
|
+
domain: '${escape(data.domain || data.entity)}',
|
|
26
|
+
owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
|
|
27
|
+
tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
|
|
28
|
+
stability: '${data.stability}',
|
|
29
|
+
},
|
|
30
|
+
source: {
|
|
31
|
+
primary: {
|
|
32
|
+
name: '${escapeString(data.primaryOperation.name)}',
|
|
33
|
+
version: ${data.primaryOperation.version},
|
|
34
|
+
},
|
|
35
|
+
${itemOperation}
|
|
36
|
+
refreshEvents: [
|
|
37
|
+
// { name: 'entity.updated', version: '1.0.0' },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
view: {
|
|
41
|
+
kind: '${data.kind}',
|
|
42
|
+
fields: [
|
|
43
|
+
${fields}
|
|
44
|
+
],
|
|
45
|
+
${data.primaryField ? `primaryField: '${escapeString(data.primaryField)}',` : ""}
|
|
46
|
+
${secondaryFields}
|
|
47
|
+
filters: [
|
|
48
|
+
// Example filter:
|
|
49
|
+
// { key: 'search', label: 'Search', field: 'fullName', type: 'search' },
|
|
50
|
+
],
|
|
51
|
+
actions: [
|
|
52
|
+
// Example action:
|
|
53
|
+
// { key: 'open', label: 'Open', kind: 'navigation' },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
states: {
|
|
57
|
+
// empty: { name: 'app.data.empty', version: '1.0.0' },
|
|
58
|
+
// error: { name: 'app.data.error', version: '1.0.0' },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
function escape(value) {
|
|
64
|
+
return value.replace(/'/g, "\\'");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { generateDataViewSpec };
|
|
69
|
+
//# sourceMappingURL=data-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-view.js","names":[],"sources":["../../src/templates/data-view.ts"],"sourcesContent":["import type { DataViewSpecData } from '../types/spec-types';\nimport { toPascalCase, escapeString } from './utils';\n\nexport function generateDataViewSpec(data: DataViewSpecData): string {\n const viewVarName =\n toPascalCase(data.name.split('.').pop() ?? 'DataView') + 'DataView';\n\n const fields = data.fields\n .map(\n (field) => ` {\n key: '${escapeString(field.key)}',\n label: '${escape(field.label)}',\n dataPath: '${escapeString(field.dataPath)}',\n ${field.format ? `format: '${escapeString(field.format)}',` : ''}\n ${field.sortable ? 'sortable: true,' : ''}\n ${field.filterable ? 'filterable: true,' : ''}\n }`\n )\n .join(',\\n');\n\n const secondaryFields = data.secondaryFields?.length\n ? `secondaryFields: [${data.secondaryFields\n .map((key) => `'${escapeString(key)}'`)\n .join(', ')}],`\n : '';\n\n const itemOperation = data.itemOperation\n ? `item: { name: '${escapeString(data.itemOperation.name)}', version: ${data.itemOperation.version} },`\n : '';\n\n return `import type { DataViewSpec } from '@contractspec/lib.contracts/data-views';\n\nexport const ${viewVarName}: DataViewSpec = {\n meta: {\n key: '${escapeString(data.name)}',\n version: ${data.version},\n entity: '${escapeString(data.entity)}',\n title: '${escape(data.title)}',\n description: '${escape(\n data.description || 'Describe the purpose of this data view.'\n )}',\n domain: '${escape(data.domain || data.entity)}',\n owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(', ')}],\n tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(', ')}],\n stability: '${data.stability}',\n },\n source: {\n primary: {\n name: '${escapeString(data.primaryOperation.name)}',\n version: ${data.primaryOperation.version},\n },\n ${itemOperation}\n refreshEvents: [\n // { name: 'entity.updated', version: '1.0.0' },\n ],\n },\n view: {\n kind: '${data.kind}',\n fields: [\n${fields}\n ],\n ${data.primaryField ? `primaryField: '${escapeString(data.primaryField)}',` : ''}\n ${secondaryFields}\n filters: [\n // Example filter:\n // { key: 'search', label: 'Search', field: 'fullName', type: 'search' },\n ],\n actions: [\n // Example action:\n // { key: 'open', label: 'Open', kind: 'navigation' },\n ],\n },\n states: {\n // empty: { name: 'app.data.empty', version: '1.0.0' },\n // error: { name: 'app.data.error', version: '1.0.0' },\n },\n};\n`;\n}\n\nfunction escape(value: string): string {\n return value.replace(/'/g, \"\\\\'\");\n}\n"],"mappings":";;;AAGA,SAAgB,qBAAqB,MAAgC;CACnE,MAAM,cACJ,aAAa,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,WAAW,GAAG;CAE3D,MAAM,SAAS,KAAK,OACjB,KACE,UAAU;gBACD,aAAa,MAAM,IAAI,CAAC;kBACtB,OAAO,MAAM,MAAM,CAAC;qBACjB,aAAa,MAAM,SAAS,CAAC;UACxC,MAAM,SAAS,YAAY,aAAa,MAAM,OAAO,CAAC,MAAM,GAAG;UAC/D,MAAM,WAAW,oBAAoB,GAAG;UACxC,MAAM,aAAa,sBAAsB,GAAG;SAEjD,CACA,KAAK,MAAM;CAEd,MAAM,kBAAkB,KAAK,iBAAiB,SAC1C,qBAAqB,KAAK,gBACvB,KAAK,QAAQ,IAAI,aAAa,IAAI,CAAC,GAAG,CACtC,KAAK,KAAK,CAAC,MACd;CAEJ,MAAM,gBAAgB,KAAK,gBACvB,kBAAkB,aAAa,KAAK,cAAc,KAAK,CAAC,cAAc,KAAK,cAAc,QAAQ,OACjG;AAEJ,QAAO;;eAEM,YAAY;;YAEf,aAAa,KAAK,KAAK,CAAC;eACrB,KAAK,QAAQ;eACb,aAAa,KAAK,OAAO,CAAC;cAC3B,OAAO,KAAK,MAAM,CAAC;oBACb,OACd,KAAK,eAAe,0CACrB,CAAC;eACS,OAAO,KAAK,UAAU,KAAK,OAAO,CAAC;eACnC,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;;;;eAIlB,aAAa,KAAK,iBAAiB,KAAK,CAAC;iBACvC,KAAK,iBAAiB,QAAQ;;MAEzC,cAAc;;;;;;aAMP,KAAK,KAAK;;EAErB,OAAO;;MAEH,KAAK,eAAe,kBAAkB,aAAa,KAAK,aAAa,CAAC,MAAM,GAAG;MAC/E,gBAAgB;;;;;;;;;;;;;;;;;AAkBtB,SAAS,OAAO,OAAuB;AACrC,QAAO,MAAM,QAAQ,MAAM,MAAM"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventSpecData } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/event.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate event spec TypeScript code.
|
|
7
|
+
*/
|
|
8
|
+
declare function generateEventSpec(data: EventSpecData): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { generateEventSpec };
|
|
11
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","names":[],"sources":["../../src/templates/event.ts"],"sourcesContent":[],"mappings":";;;;;;;iBAWgB,iBAAA,OAAwB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { toPascalCase } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/event.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate event spec TypeScript code.
|
|
6
|
+
*/
|
|
7
|
+
function generateEventSpec(data) {
|
|
8
|
+
const { name, version, description, stability, owners, tags, piiFields } = data;
|
|
9
|
+
const eventVarName = toPascalCase(name.replace(/\./g, "_")) + "V" + version;
|
|
10
|
+
const payloadSchemaName = eventVarName + "Payload";
|
|
11
|
+
return `import { defineEvent } from '@contractspec/lib.contracts';
|
|
12
|
+
import { ScalarTypeEnum, SchemaModel } from '@contractspec/lib.schema';
|
|
13
|
+
|
|
14
|
+
// TODO: Define event payload schema
|
|
15
|
+
export const ${payloadSchemaName} = new SchemaModel({
|
|
16
|
+
name: '${payloadSchemaName}',
|
|
17
|
+
description: 'Payload for ${name}',
|
|
18
|
+
fields: {
|
|
19
|
+
// Add your payload fields here
|
|
20
|
+
// example: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const ${eventVarName} = defineEvent({
|
|
25
|
+
meta: {
|
|
26
|
+
name: '${name}',
|
|
27
|
+
version: ${version},
|
|
28
|
+
description: '${description}',
|
|
29
|
+
stability: '${stability}',
|
|
30
|
+
owners: [${owners.map((o) => `'${o}'`).join(", ")}],
|
|
31
|
+
tags: [${tags.map((t) => `'${t}'`).join(", ")}],
|
|
32
|
+
},
|
|
33
|
+
${piiFields.length > 0 ? `pii: [${piiFields.map((f) => `'${f}'`).join(", ")}],` : "// pii: [],"}
|
|
34
|
+
payload: ${payloadSchemaName},
|
|
35
|
+
});
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { generateEventSpec };
|
|
41
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","names":[],"sources":["../../src/templates/event.ts"],"sourcesContent":["/**\n * Event spec template generation.\n * Extracted from cli-contractspec/src/templates/event.template.ts\n */\n\nimport type { EventSpecData } from '../types/spec-types';\nimport { toPascalCase } from './utils';\n\n/**\n * Generate event spec TypeScript code.\n */\nexport function generateEventSpec(data: EventSpecData): string {\n const { name, version, description, stability, owners, tags, piiFields } =\n data;\n\n const eventVarName = toPascalCase(name.replace(/\\./g, '_')) + 'V' + version;\n const payloadSchemaName = eventVarName + 'Payload';\n\n return `import { defineEvent } from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum, SchemaModel } from '@contractspec/lib.schema';\n\n// TODO: Define event payload schema\nexport const ${payloadSchemaName} = new SchemaModel({\n name: '${payloadSchemaName}',\n description: 'Payload for ${name}',\n fields: {\n // Add your payload fields here\n // example: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const ${eventVarName} = defineEvent({\n meta: {\n name: '${name}',\n version: ${version},\n description: '${description}',\n stability: '${stability}',\n owners: [${owners.map((o) => `'${o}'`).join(', ')}],\n tags: [${tags.map((t) => `'${t}'`).join(', ')}],\n },\n ${piiFields.length > 0 ? `pii: [${piiFields.map((f) => `'${f}'`).join(', ')}],` : '// pii: [],'}\n payload: ${payloadSchemaName},\n});\n`;\n}\n"],"mappings":";;;;;;AAWA,SAAgB,kBAAkB,MAA6B;CAC7D,MAAM,EAAE,MAAM,SAAS,aAAa,WAAW,QAAQ,MAAM,cAC3D;CAEF,MAAM,eAAe,aAAa,KAAK,QAAQ,OAAO,IAAI,CAAC,GAAG,MAAM;CACpE,MAAM,oBAAoB,eAAe;AAEzC,QAAO;;;;eAIM,kBAAkB;WACtB,kBAAkB;8BACC,KAAK;;;;;;;eAOpB,aAAa;;aAEf,KAAK;eACH,QAAQ;oBACH,YAAY;kBACd,UAAU;eACb,OAAO,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC;aACzC,KAAK,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC;;IAE9C,UAAU,SAAS,IAAI,SAAS,UAAU,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC,MAAM,cAAc;aACrF,kBAAkB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExperimentSpecData } from "../types/spec-types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/templates/experiment.d.ts
|
|
4
|
+
declare function generateExperimentSpec(data: ExperimentSpecData): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { generateExperimentSpec };
|
|
7
|
+
//# sourceMappingURL=experiment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiment.d.ts","names":[],"sources":["../../src/templates/experiment.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,sBAAA,OAA6B"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { toPascalCase } from "./utils.js";
|
|
2
|
+
|
|
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 '@contractspec/lib.contracts/experiments';
|
|
32
|
+
|
|
33
|
+
export const ${specVar}: ExperimentSpec = {
|
|
34
|
+
meta: {
|
|
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}',
|
|
43
|
+
},
|
|
44
|
+
controlVariant: '${escapeString(data.controlVariant)}',
|
|
45
|
+
variants: [
|
|
46
|
+
${variants}
|
|
47
|
+
],
|
|
48
|
+
allocation: ${allocation},
|
|
49
|
+
${metrics}
|
|
50
|
+
};
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function renderAllocation(allocation) {
|
|
54
|
+
switch (allocation.type) {
|
|
55
|
+
case "random": return `{
|
|
56
|
+
type: 'random',
|
|
57
|
+
${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ""}
|
|
58
|
+
}`;
|
|
59
|
+
case "sticky": return `{
|
|
60
|
+
type: 'sticky',
|
|
61
|
+
attribute: '${allocation.attribute}',
|
|
62
|
+
${allocation.salt ? `salt: '${escapeString(allocation.salt)}',` : ""}
|
|
63
|
+
}`;
|
|
64
|
+
case "targeted": return `{
|
|
65
|
+
type: 'targeted',
|
|
66
|
+
rules: [
|
|
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")}
|
|
73
|
+
],
|
|
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 '@contractspec/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,M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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"}
|