@lssm/bundle.contractspec-workspace 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217072406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/rolldown_runtime.js +22 -1
- package/dist/adapters/ai.js +82 -1
- package/dist/adapters/factory.js +36 -1
- package/dist/adapters/fs.js +118 -1
- package/dist/adapters/git.js +54 -1
- package/dist/adapters/index.js +7 -1
- package/dist/adapters/logger.js +80 -1
- package/dist/adapters/watcher.js +69 -1
- package/dist/adapters/workspace.js +190 -2
- package/dist/ai/agents/claude-code-agent.js +146 -9
- package/dist/ai/agents/cursor-agent.js +286 -17
- package/dist/ai/agents/index.js +5 -1
- package/dist/ai/agents/openai-codex-agent.js +140 -8
- package/dist/ai/agents/orchestrator.js +142 -1
- package/dist/ai/agents/simple-agent.js +80 -4
- package/dist/ai/client.js +162 -1
- package/dist/ai/index.js +27 -1
- package/dist/ai/prompts/code-generation.js +55 -13
- package/dist/ai/prompts/index.js +12 -1
- package/dist/ai/prompts/spec-creation.js +61 -20
- package/dist/ai/providers.js +40 -1
- package/dist/formatters/index.js +18 -1
- package/dist/formatters/json.js +71 -1
- package/dist/formatters/sarif.js +163 -1
- package/dist/formatters/text.js +208 -2
- package/dist/index.js +81 -1
- package/dist/libs/ai-providers/dist/factory.js +154 -1
- package/dist/libs/ai-providers/dist/index.js +4 -1
- package/dist/libs/ai-providers/dist/legacy.js +72 -1
- package/dist/libs/ai-providers/dist/models.js +287 -1
- package/dist/libs/ai-providers/dist/validation.js +1 -1
- package/dist/libs/contracts/dist/capabilities/openbanking.js +88 -1
- package/dist/libs/contracts/dist/client/index.js +5 -1
- package/dist/libs/contracts/dist/client/react/feature-render.js +2 -1
- package/dist/libs/contracts/dist/client/react/form-render.js +4 -1
- package/dist/libs/contracts/dist/client/react/index.js +4 -1
- package/dist/libs/contracts/dist/contract-registry/index.js +1 -1
- package/dist/libs/contracts/dist/contract-registry/schemas.js +60 -1
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
- package/dist/libs/contracts/dist/docs/index.js +29 -1
- package/dist/libs/contracts/dist/docs/presentations.js +71 -1
- package/dist/libs/contracts/dist/docs/registry.js +44 -1
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
- package/dist/libs/contracts/dist/events.js +8 -1
- package/dist/libs/contracts/dist/experiments/evaluator.js +1 -1
- package/dist/libs/contracts/dist/index.js +72 -1
- package/dist/libs/contracts/dist/install.js +2 -1
- package/dist/libs/contracts/dist/integrations/contracts.js +377 -1
- package/dist/libs/contracts/dist/integrations/index.js +18 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +242 -1
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +13 -1
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -1
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -1
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -1
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -1
- package/dist/libs/contracts/dist/integrations/providers/index.js +11 -1
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -1
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -1
- package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -1
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -1
- package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -1
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -1
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -1
- package/dist/libs/contracts/dist/jsonschema.js +24 -1
- package/dist/libs/contracts/dist/knowledge/contracts.js +306 -1
- package/dist/libs/contracts/dist/knowledge/index.js +7 -1
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -1
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -1
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
- package/dist/libs/contracts/dist/llm/exporters.js +352 -4
- package/dist/libs/contracts/dist/llm/index.js +2 -1
- package/dist/libs/contracts/dist/llm/prompts.js +143 -7
- package/dist/libs/contracts/dist/onboarding-base.js +196 -1
- package/dist/libs/contracts/dist/openapi.js +75 -1
- package/dist/libs/contracts/dist/ownership.js +21 -1
- package/dist/libs/contracts/dist/presentations.js +1 -1
- package/dist/libs/contracts/dist/presentations.v2.js +11 -1
- package/dist/libs/contracts/dist/prompt.js +1 -1
- package/dist/libs/contracts/dist/promptRegistry.js +1 -1
- package/dist/libs/contracts/dist/regenerator/index.js +2 -1
- package/dist/libs/contracts/dist/regenerator/service.js +92 -1
- package/dist/libs/contracts/dist/regenerator/utils.js +51 -1
- package/dist/libs/contracts/dist/registry.js +208 -1
- package/dist/libs/contracts/dist/resources.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -1
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +49 -1
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +34 -1
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -1
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/index.js +6 -1
- package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -1
- package/dist/libs/contracts/dist/server/index.js +8 -1
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -1
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -1
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -1
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -1
- package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -1
- package/dist/libs/contracts/dist/server/provider-mcp.js +1 -1
- package/dist/libs/contracts/dist/server/rest-elysia.js +1 -1
- package/dist/libs/contracts/dist/server/rest-express.js +1 -1
- package/dist/libs/contracts/dist/server/rest-generic.js +1 -1
- package/dist/libs/contracts/dist/server/rest-next-app.js +1 -1
- package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -1
- package/dist/libs/contracts/dist/spec.js +35 -1
- package/dist/libs/contracts/dist/telemetry/index.js +1 -1
- package/dist/libs/contracts/dist/telemetry/tracker.js +1 -1
- package/dist/libs/contracts/dist/tests/index.js +1 -1
- package/dist/libs/contracts/dist/tests/runner.js +150 -1
- package/dist/libs/contracts/dist/workflow/index.js +1 -1
- package/dist/libs/contracts/dist/workflow/runner.js +1 -1
- package/dist/libs/contracts-transformers/dist/common/utils.js +47 -1
- package/dist/libs/contracts-transformers/dist/openapi/exporter.js +1 -1
- package/dist/libs/contracts-transformers/dist/openapi/importer.js +255 -2
- package/dist/libs/contracts-transformers/dist/openapi/index.js +4 -1
- package/dist/libs/contracts-transformers/dist/openapi/parser.js +231 -1
- package/dist/libs/contracts-transformers/dist/openapi/schema-converter.js +201 -4
- package/dist/modules/contractspec-workspace/dist/ai/code-generation.js +50 -13
- package/dist/modules/contractspec-workspace/dist/ai/spec-creation.js +50 -18
- package/dist/modules/contractspec-workspace/dist/analysis/deps/graph.js +84 -2
- package/dist/modules/contractspec-workspace/dist/analysis/deps/parse-imports.js +30 -1
- package/dist/modules/contractspec-workspace/dist/analysis/diff/semantic.js +96 -1
- package/dist/modules/contractspec-workspace/dist/analysis/feature-scan.js +151 -1
- package/dist/modules/contractspec-workspace/dist/analysis/spec-scan.js +344 -1
- package/dist/modules/contractspec-workspace/dist/analysis/validate/spec-structure.js +122 -1
- package/dist/modules/contractspec-workspace/dist/templates/app-config.js +100 -28
- package/dist/modules/contractspec-workspace/dist/templates/data-view.js +41 -27
- package/dist/modules/contractspec-workspace/dist/templates/event.js +28 -14
- package/dist/modules/contractspec-workspace/dist/templates/experiment.js +76 -51
- package/dist/modules/contractspec-workspace/dist/templates/handler.js +49 -17
- package/dist/modules/contractspec-workspace/dist/templates/integration-utils.js +97 -26
- package/dist/modules/contractspec-workspace/dist/templates/integration.js +46 -23
- package/dist/modules/contractspec-workspace/dist/templates/knowledge.js +59 -19
- package/dist/modules/contractspec-workspace/dist/templates/migration.js +49 -26
- package/dist/modules/contractspec-workspace/dist/templates/operation.js +40 -28
- package/dist/modules/contractspec-workspace/dist/templates/presentation.js +45 -20
- package/dist/modules/contractspec-workspace/dist/templates/telemetry.js +73 -53
- package/dist/modules/contractspec-workspace/dist/templates/utils.js +38 -1
- package/dist/modules/contractspec-workspace/dist/templates/workflow-runner.js +12 -6
- package/dist/modules/contractspec-workspace/dist/templates/workflow.js +50 -24
- package/dist/modules/contractspec-workspace/dist/types/generation-types.js +20 -1
- package/dist/services/agent-guide/adapters/claude-code.js +144 -3
- package/dist/services/agent-guide/adapters/cursor-cli.js +135 -3
- package/dist/services/agent-guide/adapters/generic-mcp.js +159 -3
- package/dist/services/agent-guide/adapters/index.js +30 -1
- package/dist/services/agent-guide/agent-guide-service.js +148 -1
- package/dist/services/agent-guide/index.js +5 -1
- package/dist/services/build.js +140 -1
- package/dist/services/ci-check/ci-check-service.js +393 -1
- package/dist/services/ci-check/index.js +2 -1
- package/dist/services/ci-check/types.js +28 -1
- package/dist/services/clean.js +71 -1
- package/dist/services/config.js +76 -1
- package/dist/services/deps.js +62 -1
- package/dist/services/diff.js +33 -1
- package/dist/services/doctor/checks/ai.js +118 -2
- package/dist/services/doctor/checks/cli.js +146 -1
- package/dist/services/doctor/checks/config.js +170 -1
- package/dist/services/doctor/checks/deps.js +180 -1
- package/dist/services/doctor/checks/index.js +6 -1
- package/dist/services/doctor/checks/mcp.js +144 -1
- package/dist/services/doctor/checks/workspace.js +243 -1
- package/dist/services/doctor/doctor-service.js +115 -2
- package/dist/services/doctor/index.js +2 -1
- package/dist/services/doctor/types.js +26 -1
- package/dist/services/implementation/discovery.js +143 -2
- package/dist/services/implementation/index.js +2 -1
- package/dist/services/implementation/resolver.js +223 -1
- package/dist/services/index.js +53 -1
- package/dist/services/integrity-diagram.js +274 -6
- package/dist/services/integrity.js +272 -1
- package/dist/services/list.js +35 -1
- package/dist/services/openapi/export-service.js +51 -2
- package/dist/services/openapi/import-service.js +75 -1
- package/dist/services/openapi/index.js +4 -1
- package/dist/services/openapi/sync-service.js +121 -1
- package/dist/services/openapi/validate-service.js +130 -1
- package/dist/services/regenerator.js +23 -1
- package/dist/services/registry.js +73 -1
- package/dist/services/setup/config-generators.js +113 -26
- package/dist/services/setup/file-merger.js +60 -2
- package/dist/services/setup/index.js +4 -1
- package/dist/services/setup/setup-service.js +95 -1
- package/dist/services/setup/targets/agents-md.js +46 -1
- package/dist/services/setup/targets/cli-config.js +59 -1
- package/dist/services/setup/targets/cursor-rules.js +47 -1
- package/dist/services/setup/targets/mcp-claude.js +59 -1
- package/dist/services/setup/targets/mcp-cursor.js +58 -1
- package/dist/services/setup/targets/vscode-settings.js +62 -1
- package/dist/services/setup/types.js +26 -1
- package/dist/services/sync.js +62 -1
- package/dist/services/test.js +30 -1
- package/dist/services/validate-implementation.js +69 -1
- package/dist/services/validate.js +47 -1
- package/dist/services/verification-cache/adapters/filesystem.js +121 -1
- package/dist/services/verification-cache/adapters/in-memory.js +45 -1
- package/dist/services/verification-cache/adapters/index.js +3 -1
- package/dist/services/verification-cache/adapters/workspace-state.js +90 -1
- package/dist/services/verification-cache/cache-service.js +255 -1
- package/dist/services/verification-cache/index.js +6 -1
- package/dist/services/verification-cache/types.js +15 -1
- package/dist/services/verify/ai-verifier.js +336 -9
- package/dist/services/verify/behavior-verifier.js +185 -1
- package/dist/services/verify/index.js +4 -1
- package/dist/services/verify/structure-verifier.js +195 -2
- package/dist/services/verify/verify-service.js +203 -3
- package/dist/services/watch.js +31 -1
- package/dist/services/workspace-info.js +102 -2
- package/dist/templates/app-config.template.js +101 -28
- package/dist/templates/data-view.template.js +42 -27
- package/dist/templates/event.template.js +29 -14
- package/dist/templates/experiment.template.js +77 -51
- package/dist/templates/handler.template.js +53 -17
- package/dist/templates/index.js +36 -1
- package/dist/templates/integration.template.js +134 -50
- package/dist/templates/knowledge.template.js +62 -21
- package/dist/templates/migration.template.js +50 -26
- package/dist/templates/operation.template.js +44 -28
- package/dist/templates/presentation.template.js +46 -20
- package/dist/templates/telemetry.template.js +74 -53
- package/dist/templates/workflow-runner.template.js +12 -6
- package/dist/templates/workflow.template.js +51 -24
- package/package.json +13 -9
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../../libs/contracts/dist/spec.js
|
|
2
|
+
const isEmitDeclRef = (e) => "ref" in e;
|
|
3
|
+
/**
|
|
4
|
+
* Helper to define a Command (write operation).
|
|
5
|
+
* Sets `kind: 'command'` and defaults `idempotent: false`.
|
|
6
|
+
*/
|
|
7
|
+
const defineCommand = (spec) => ({
|
|
8
|
+
...spec,
|
|
9
|
+
meta: {
|
|
10
|
+
...spec.meta,
|
|
11
|
+
kind: "command"
|
|
12
|
+
},
|
|
13
|
+
policy: {
|
|
14
|
+
...spec.policy,
|
|
15
|
+
idempotent: spec.policy?.["policy"]?.idempotent ?? false
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Helper to define a Query (read-only operation).
|
|
20
|
+
* Sets `kind: 'query'` and forces `idempotent: true`.
|
|
21
|
+
*/
|
|
22
|
+
const defineQuery = (spec) => ({
|
|
23
|
+
...spec,
|
|
24
|
+
meta: {
|
|
25
|
+
...spec.meta,
|
|
26
|
+
kind: "query"
|
|
27
|
+
},
|
|
28
|
+
policy: {
|
|
29
|
+
...spec.policy,
|
|
30
|
+
idempotent: true
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { defineCommand, defineQuery, isEmitDeclRef };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./tracker.js";
|
|
1
|
+
import "./tracker.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"crypto";
|
|
1
|
+
import "crypto";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { TestRunner } from "./runner.js";
|
|
@@ -1 +1,150 @@
|
|
|
1
|
-
import"../index.js";
|
|
1
|
+
import "../index.js";
|
|
2
|
+
import { deepStrictEqual } from "node:assert";
|
|
3
|
+
|
|
4
|
+
//#region ../../libs/contracts/dist/tests/runner.js
|
|
5
|
+
var TestRunner = class {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
async run(spec) {
|
|
10
|
+
const scenarios = [];
|
|
11
|
+
let passed = 0;
|
|
12
|
+
let failed = 0;
|
|
13
|
+
for (const scenario of spec.scenarios) {
|
|
14
|
+
await this.config.beforeEach?.(scenario);
|
|
15
|
+
const result = await this.runScenario(spec, scenario);
|
|
16
|
+
scenarios.push(result);
|
|
17
|
+
if (result.status === "passed") passed += 1;
|
|
18
|
+
else failed += 1;
|
|
19
|
+
await this.config.afterEach?.(scenario, result);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
spec,
|
|
23
|
+
scenarios,
|
|
24
|
+
passed,
|
|
25
|
+
failed
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async runScenario(spec, scenario) {
|
|
29
|
+
const assertionResults = [];
|
|
30
|
+
try {
|
|
31
|
+
const context = await this.createContext();
|
|
32
|
+
const fixtures = [...spec.fixtures ?? [], ...scenario.given ?? []];
|
|
33
|
+
const events = [];
|
|
34
|
+
for (const fixture of fixtures) await this.executeOperation(fixture, context, events);
|
|
35
|
+
const actionResult = await this.executeOperation(scenario.when, context, events);
|
|
36
|
+
const assertions = scenario.then ?? [];
|
|
37
|
+
for (const assertion of assertions) {
|
|
38
|
+
const assertionResult = this.evaluateAssertion(assertion, actionResult, events);
|
|
39
|
+
assertionResults.push(assertionResult);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
scenario,
|
|
43
|
+
status: assertionResults.some((assertion) => assertion.status === "failed") ? "failed" : "passed",
|
|
44
|
+
assertionResults
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
scenario,
|
|
49
|
+
status: "failed",
|
|
50
|
+
error,
|
|
51
|
+
assertionResults
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async createContext() {
|
|
56
|
+
return { ...await this.config.createContext?.() ?? {} };
|
|
57
|
+
}
|
|
58
|
+
async executeOperation(action, baseCtx, recordedEvents) {
|
|
59
|
+
const ctx = {
|
|
60
|
+
...baseCtx,
|
|
61
|
+
eventPublisher: async (event) => {
|
|
62
|
+
recordedEvents.push({
|
|
63
|
+
name: event.name,
|
|
64
|
+
version: event.version,
|
|
65
|
+
payload: event.payload
|
|
66
|
+
});
|
|
67
|
+
await baseCtx.eventPublisher?.(event);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
return {
|
|
72
|
+
output: await this.config.registry.execute(action.operation.name, action.operation.version, action.input ?? null, ctx),
|
|
73
|
+
events: recordedEvents
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return {
|
|
77
|
+
error,
|
|
78
|
+
events: recordedEvents
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
evaluateAssertion(assertion, result, events) {
|
|
83
|
+
switch (assertion.type) {
|
|
84
|
+
case "expectOutput": return this.evaluateOutputAssertion(assertion, result);
|
|
85
|
+
case "expectError": return this.evaluateErrorAssertion(assertion, result);
|
|
86
|
+
case "expectEvents": return this.evaluateEventsAssertion(assertion, events);
|
|
87
|
+
default: return {
|
|
88
|
+
assertion,
|
|
89
|
+
status: "failed",
|
|
90
|
+
message: `Unknown assertion type ${assertion.type}`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
evaluateOutputAssertion(assertion, result) {
|
|
95
|
+
if (result.error) return {
|
|
96
|
+
assertion,
|
|
97
|
+
status: "failed",
|
|
98
|
+
message: `Expected output but operation threw error: ${result.error.message}`
|
|
99
|
+
};
|
|
100
|
+
try {
|
|
101
|
+
deepStrictEqual(result.output, assertion.match);
|
|
102
|
+
return {
|
|
103
|
+
assertion,
|
|
104
|
+
status: "passed"
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return {
|
|
108
|
+
assertion,
|
|
109
|
+
status: "failed",
|
|
110
|
+
message: error instanceof Error ? error.message : "Output assertion failed"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
evaluateErrorAssertion(assertion, result) {
|
|
115
|
+
if (!result.error) return {
|
|
116
|
+
assertion,
|
|
117
|
+
status: "failed",
|
|
118
|
+
message: "Expected an error but operation completed successfully"
|
|
119
|
+
};
|
|
120
|
+
if (assertion.messageIncludes && !result.error.message.includes(assertion.messageIncludes)) return {
|
|
121
|
+
assertion,
|
|
122
|
+
status: "failed",
|
|
123
|
+
message: `Error message "${result.error.message}" did not include expected substring "${assertion.messageIncludes}"`
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
assertion,
|
|
127
|
+
status: "passed"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
evaluateEventsAssertion(assertion, events) {
|
|
131
|
+
const failures = [];
|
|
132
|
+
for (const expected of assertion.events) {
|
|
133
|
+
const count = events.filter((event) => event.name === expected.name && event.version === expected.version).length;
|
|
134
|
+
if (typeof expected.min === "number" && count < expected.min || typeof expected.max === "number" && count > expected.max) failures.push(`Event ${expected.name}.v${expected.version} occurred ${count} times (expected ${expected.min ?? 0} - ${expected.max ?? "∞"})`);
|
|
135
|
+
else if (typeof expected.min === "undefined" && typeof expected.max === "undefined" && count === 0) failures.push(`Event ${expected.name}.v${expected.version} did not occur`);
|
|
136
|
+
}
|
|
137
|
+
if (failures.length > 0) return {
|
|
138
|
+
assertion,
|
|
139
|
+
status: "failed",
|
|
140
|
+
message: failures.join("; ")
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
assertion,
|
|
144
|
+
status: "passed"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
export { TestRunner };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./runner.js";
|
|
1
|
+
import "./runner.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:crypto";
|
|
1
|
+
import "node:crypto";
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../../libs/contracts-transformers/dist/common/utils.js
|
|
2
|
+
/**
|
|
3
|
+
* Common utilities for contract transformations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Convert a string to PascalCase.
|
|
7
|
+
*/
|
|
8
|
+
function toPascalCase(str) {
|
|
9
|
+
return str.replace(/[-_./\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^./, (c) => c.toUpperCase());
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert a string to camelCase.
|
|
13
|
+
*/
|
|
14
|
+
function toCamelCase(str) {
|
|
15
|
+
const pascal = toPascalCase(str);
|
|
16
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert a string to kebab-case.
|
|
20
|
+
*/
|
|
21
|
+
function toKebabCase(str) {
|
|
22
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_./]+/g, "-").toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sanitize a string to be a valid TypeScript identifier.
|
|
26
|
+
*/
|
|
27
|
+
function toValidIdentifier(str) {
|
|
28
|
+
let result = str.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
29
|
+
if (/^[0-9]/.test(result)) result = "_" + result;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate a ContractSpec name from an operation identifier.
|
|
34
|
+
*/
|
|
35
|
+
function toSpecName(operationId, prefix) {
|
|
36
|
+
const name = toCamelCase(operationId);
|
|
37
|
+
return prefix ? `${prefix}.${name}` : name;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate a file name from a spec name.
|
|
41
|
+
*/
|
|
42
|
+
function toFileName(specName) {
|
|
43
|
+
return toKebabCase(specName.replace(/\./g, "-")) + ".ts";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { toCamelCase, toFileName, toPascalCase, toSpecName, toValidIdentifier };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"zod";
|
|
1
|
+
import "zod";
|
|
@@ -1,2 +1,255 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
1
|
+
import { toFileName, toPascalCase, toSpecName, toValidIdentifier } from "../common/utils.js";
|
|
2
|
+
import { generateImports, generateSchemaModelCode } from "./schema-converter.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../libs/contracts-transformers/dist/openapi/importer.js
|
|
5
|
+
/**
|
|
6
|
+
* HTTP methods that typically indicate a command (state-changing).
|
|
7
|
+
*/
|
|
8
|
+
const COMMAND_METHODS = [
|
|
9
|
+
"post",
|
|
10
|
+
"put",
|
|
11
|
+
"delete",
|
|
12
|
+
"patch"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Determine if an operation is a command or query based on HTTP method.
|
|
16
|
+
*/
|
|
17
|
+
function inferOpKind(method) {
|
|
18
|
+
return COMMAND_METHODS.includes(method.toLowerCase()) ? "command" : "query";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determine auth level based on security requirements.
|
|
22
|
+
*/
|
|
23
|
+
function inferAuthLevel(operation, defaultAuth) {
|
|
24
|
+
if (!operation.security || operation.security.length === 0) return defaultAuth;
|
|
25
|
+
for (const sec of operation.security) if (Object.keys(sec).length === 0) return "anonymous";
|
|
26
|
+
return "user";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a merged input schema from all parameter sources.
|
|
30
|
+
*/
|
|
31
|
+
function buildInputSchema(operation) {
|
|
32
|
+
const fields = [];
|
|
33
|
+
for (const param of operation.pathParams) fields.push({
|
|
34
|
+
name: param.name,
|
|
35
|
+
schema: param.schema,
|
|
36
|
+
required: true
|
|
37
|
+
});
|
|
38
|
+
for (const param of operation.queryParams) fields.push({
|
|
39
|
+
name: param.name,
|
|
40
|
+
schema: param.schema,
|
|
41
|
+
required: param.required
|
|
42
|
+
});
|
|
43
|
+
const excludedHeaders = [
|
|
44
|
+
"authorization",
|
|
45
|
+
"content-type",
|
|
46
|
+
"accept",
|
|
47
|
+
"user-agent"
|
|
48
|
+
];
|
|
49
|
+
for (const param of operation.headerParams) if (!excludedHeaders.includes(param.name.toLowerCase())) fields.push({
|
|
50
|
+
name: param.name,
|
|
51
|
+
schema: param.schema,
|
|
52
|
+
required: param.required
|
|
53
|
+
});
|
|
54
|
+
if (operation.requestBody?.schema) {
|
|
55
|
+
const bodySchema = operation.requestBody.schema;
|
|
56
|
+
if (!("$ref" in bodySchema)) {
|
|
57
|
+
const schemaObj = bodySchema;
|
|
58
|
+
const properties = schemaObj["properties"];
|
|
59
|
+
const required = schemaObj["required"] ?? [];
|
|
60
|
+
if (properties) for (const [propName, propSchema] of Object.entries(properties)) fields.push({
|
|
61
|
+
name: propName,
|
|
62
|
+
schema: propSchema,
|
|
63
|
+
required: required.includes(propName)
|
|
64
|
+
});
|
|
65
|
+
} else fields.push({
|
|
66
|
+
name: "body",
|
|
67
|
+
schema: bodySchema,
|
|
68
|
+
required: operation.requestBody.required
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (fields.length === 0) return {
|
|
72
|
+
schema: null,
|
|
73
|
+
fields: []
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
schema: {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: fields.reduce((acc, f) => {
|
|
79
|
+
acc[f.name] = f.schema;
|
|
80
|
+
return acc;
|
|
81
|
+
}, {}),
|
|
82
|
+
required: fields.filter((f) => f.required).map((f) => f.name)
|
|
83
|
+
},
|
|
84
|
+
fields
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the output schema from the operation responses.
|
|
89
|
+
*/
|
|
90
|
+
function getOutputSchema(operation) {
|
|
91
|
+
for (const code of [
|
|
92
|
+
"200",
|
|
93
|
+
"201",
|
|
94
|
+
"202",
|
|
95
|
+
"204"
|
|
96
|
+
]) {
|
|
97
|
+
const response = operation.responses[code];
|
|
98
|
+
if (response?.schema) return response.schema;
|
|
99
|
+
}
|
|
100
|
+
for (const [code, response] of Object.entries(operation.responses)) if (code.startsWith("2") && response.schema) return response.schema;
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generate ContractSpec TypeScript code for an operation.
|
|
105
|
+
*/
|
|
106
|
+
function generateSpecCode(operation, options, inputModel, outputModel) {
|
|
107
|
+
const specName = toSpecName(operation.operationId, options.prefix);
|
|
108
|
+
const kind = inferOpKind(operation.method);
|
|
109
|
+
const auth = inferAuthLevel(operation, options.defaultAuth ?? "user");
|
|
110
|
+
const lines = [];
|
|
111
|
+
lines.push("import { defineCommand, defineQuery } from '@lssm/lib.contracts';");
|
|
112
|
+
if (inputModel || outputModel) lines.push(generateImports([...inputModel?.fields ?? [], ...outputModel?.fields ?? []]));
|
|
113
|
+
lines.push("");
|
|
114
|
+
if (inputModel && inputModel.code) {
|
|
115
|
+
lines.push("// Input schema");
|
|
116
|
+
lines.push(inputModel.code);
|
|
117
|
+
lines.push("");
|
|
118
|
+
}
|
|
119
|
+
if (outputModel && outputModel.code) {
|
|
120
|
+
lines.push("// Output schema");
|
|
121
|
+
lines.push(outputModel.code);
|
|
122
|
+
lines.push("");
|
|
123
|
+
}
|
|
124
|
+
const defineFunc = kind === "command" ? "defineCommand" : "defineQuery";
|
|
125
|
+
const safeName = toValidIdentifier(toPascalCase(operation.operationId));
|
|
126
|
+
lines.push(`/**`);
|
|
127
|
+
lines.push(` * ${operation.summary ?? operation.operationId}`);
|
|
128
|
+
if (operation.description) {
|
|
129
|
+
lines.push(` *`);
|
|
130
|
+
lines.push(` * ${operation.description}`);
|
|
131
|
+
}
|
|
132
|
+
lines.push(` *`);
|
|
133
|
+
lines.push(` * @source OpenAPI: ${operation.method.toUpperCase()} ${operation.path}`);
|
|
134
|
+
lines.push(` */`);
|
|
135
|
+
lines.push(`export const ${safeName}Spec = ${defineFunc}({`);
|
|
136
|
+
lines.push(" meta: {");
|
|
137
|
+
lines.push(` name: '${specName}',`);
|
|
138
|
+
lines.push(" version: 1,");
|
|
139
|
+
lines.push(` stability: '${options.defaultStability ?? "stable"}',`);
|
|
140
|
+
lines.push(` owners: [${(options.defaultOwners ?? []).map((o) => `'${o}'`).join(", ")}],`);
|
|
141
|
+
lines.push(` tags: [${operation.tags.map((t) => `'${t}'`).join(", ")}],`);
|
|
142
|
+
lines.push(` description: ${JSON.stringify(operation.summary ?? operation.operationId)},`);
|
|
143
|
+
lines.push(` goal: ${JSON.stringify(operation.description ?? "Imported from OpenAPI")},`);
|
|
144
|
+
lines.push(` context: 'Imported from OpenAPI: ${operation.method.toUpperCase()} ${operation.path}',`);
|
|
145
|
+
lines.push(" },");
|
|
146
|
+
lines.push(" io: {");
|
|
147
|
+
if (inputModel) lines.push(` input: ${inputModel.name},`);
|
|
148
|
+
else lines.push(" input: null,");
|
|
149
|
+
if (outputModel) lines.push(` output: ${outputModel.name},`);
|
|
150
|
+
else lines.push(" output: null, // TODO: Define output schema");
|
|
151
|
+
lines.push(" },");
|
|
152
|
+
lines.push(" policy: {");
|
|
153
|
+
lines.push(` auth: '${auth}',`);
|
|
154
|
+
lines.push(" },");
|
|
155
|
+
lines.push(" transport: {");
|
|
156
|
+
lines.push(" rest: {");
|
|
157
|
+
lines.push(` method: '${operation.method.toUpperCase()}',`);
|
|
158
|
+
lines.push(` path: '${operation.path}',`);
|
|
159
|
+
lines.push(" },");
|
|
160
|
+
lines.push(" },");
|
|
161
|
+
lines.push("});");
|
|
162
|
+
return lines.join("\n");
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Import operations from a parsed OpenAPI document.
|
|
166
|
+
*/
|
|
167
|
+
function importFromOpenApi(parseResult, options = {}) {
|
|
168
|
+
const { tags, exclude = [], include } = options;
|
|
169
|
+
const specs = [];
|
|
170
|
+
const skipped = [];
|
|
171
|
+
const errors = [];
|
|
172
|
+
for (const operation of parseResult.operations) {
|
|
173
|
+
if (tags && tags.length > 0) {
|
|
174
|
+
if (!operation.tags.some((t) => tags.includes(t))) {
|
|
175
|
+
skipped.push({
|
|
176
|
+
sourceId: operation.operationId,
|
|
177
|
+
reason: `No matching tags (has: ${operation.tags.join(", ")})`
|
|
178
|
+
});
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (include && include.length > 0) {
|
|
183
|
+
if (!include.includes(operation.operationId)) {
|
|
184
|
+
skipped.push({
|
|
185
|
+
sourceId: operation.operationId,
|
|
186
|
+
reason: "Not in include list"
|
|
187
|
+
});
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
} else if (exclude.includes(operation.operationId)) {
|
|
191
|
+
skipped.push({
|
|
192
|
+
sourceId: operation.operationId,
|
|
193
|
+
reason: "In exclude list"
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (operation.deprecated && options.defaultStability !== "deprecated") {
|
|
198
|
+
skipped.push({
|
|
199
|
+
sourceId: operation.operationId,
|
|
200
|
+
reason: "Deprecated operation"
|
|
201
|
+
});
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const { schema: inputSchema } = buildInputSchema(operation);
|
|
206
|
+
const inputModel = inputSchema ? generateSchemaModelCode(inputSchema, `${operation.operationId}Input`) : null;
|
|
207
|
+
const outputSchema = getOutputSchema(operation);
|
|
208
|
+
const code = generateSpecCode(operation, options, inputModel, outputSchema ? generateSchemaModelCode(outputSchema, `${operation.operationId}Output`) : null);
|
|
209
|
+
const fileName = toFileName(toSpecName(operation.operationId, options.prefix));
|
|
210
|
+
const transportHints = { rest: {
|
|
211
|
+
method: operation.method.toUpperCase(),
|
|
212
|
+
path: operation.path,
|
|
213
|
+
params: {
|
|
214
|
+
path: operation.pathParams.map((p) => p.name),
|
|
215
|
+
query: operation.queryParams.map((p) => p.name),
|
|
216
|
+
header: operation.headerParams.map((p) => p.name),
|
|
217
|
+
cookie: operation.cookieParams.map((p) => p.name)
|
|
218
|
+
}
|
|
219
|
+
} };
|
|
220
|
+
const source = {
|
|
221
|
+
type: "openapi",
|
|
222
|
+
sourceId: operation.operationId,
|
|
223
|
+
operationId: operation.operationId,
|
|
224
|
+
openApiVersion: parseResult.version,
|
|
225
|
+
importedAt: /* @__PURE__ */ new Date()
|
|
226
|
+
};
|
|
227
|
+
specs.push({
|
|
228
|
+
spec: {},
|
|
229
|
+
code,
|
|
230
|
+
fileName,
|
|
231
|
+
source,
|
|
232
|
+
transportHints
|
|
233
|
+
});
|
|
234
|
+
} catch (error) {
|
|
235
|
+
errors.push({
|
|
236
|
+
sourceId: operation.operationId,
|
|
237
|
+
error: error instanceof Error ? error.message : String(error)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
specs,
|
|
243
|
+
skipped,
|
|
244
|
+
errors,
|
|
245
|
+
summary: {
|
|
246
|
+
total: parseResult.operations.length,
|
|
247
|
+
imported: specs.length,
|
|
248
|
+
skipped: skipped.length,
|
|
249
|
+
errors: errors.length
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//#endregion
|
|
255
|
+
export { importFromOpenApi };
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { detectFormat, detectVersion, parseOpenApi, parseOpenApiDocument, parseOpenApiString } from "./parser.js";
|
|
2
|
+
import "./exporter.js";
|
|
3
|
+
import { generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType } from "./schema-converter.js";
|
|
4
|
+
import { importFromOpenApi } from "./importer.js";
|