@glubean/sdk 0.1.39 → 0.2.0

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.
Files changed (47) hide show
  1. package/dist/contract-core.d.ts +96 -0
  2. package/dist/contract-core.d.ts.map +1 -0
  3. package/dist/contract-core.js +747 -0
  4. package/dist/contract-core.js.map +1 -0
  5. package/dist/contract-http/adapter.d.ts +52 -0
  6. package/dist/contract-http/adapter.d.ts.map +1 -0
  7. package/dist/contract-http/adapter.js +650 -0
  8. package/dist/contract-http/adapter.js.map +1 -0
  9. package/dist/contract-http/factory.d.ts +32 -0
  10. package/dist/contract-http/factory.d.ts.map +1 -0
  11. package/dist/contract-http/factory.js +83 -0
  12. package/dist/contract-http/factory.js.map +1 -0
  13. package/dist/contract-http/flow-helpers.d.ts +12 -0
  14. package/dist/contract-http/flow-helpers.d.ts.map +1 -0
  15. package/dist/contract-http/flow-helpers.js +34 -0
  16. package/dist/contract-http/flow-helpers.js.map +1 -0
  17. package/dist/contract-http/index.d.ts +15 -0
  18. package/dist/contract-http/index.d.ts.map +1 -0
  19. package/dist/contract-http/index.js +14 -0
  20. package/dist/contract-http/index.js.map +1 -0
  21. package/dist/contract-http/markdown.d.ts +10 -0
  22. package/dist/contract-http/markdown.d.ts.map +1 -0
  23. package/dist/contract-http/markdown.js +21 -0
  24. package/dist/contract-http/markdown.js.map +1 -0
  25. package/dist/contract-http/openapi.d.ts +15 -0
  26. package/dist/contract-http/openapi.d.ts.map +1 -0
  27. package/dist/contract-http/openapi.js +38 -0
  28. package/dist/contract-http/openapi.js.map +1 -0
  29. package/dist/contract-http/types.d.ts +252 -0
  30. package/dist/contract-http/types.d.ts.map +1 -0
  31. package/dist/contract-http/types.js +13 -0
  32. package/dist/contract-http/types.js.map +1 -0
  33. package/dist/contract-types.d.ts +420 -467
  34. package/dist/contract-types.d.ts.map +1 -1
  35. package/dist/contract-types.js +16 -4
  36. package/dist/contract-types.js.map +1 -1
  37. package/dist/index.d.ts +21 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +24 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/types.d.ts +22 -10
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/contract.d.ts +0 -64
  45. package/dist/contract.d.ts.map +0 -1
  46. package/dist/contract.js +0 -793
  47. package/dist/contract.js.map +0 -1
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Protocol-agnostic contract core.
3
+ *
4
+ * Provides:
5
+ * - Adapter registry (`_adapters`)
6
+ * - `contract.register(protocol, adapter)` — plugin extension point
7
+ * - `contract[protocol](id, spec)` dispatcher — validates 1:1 case keys,
8
+ * invokes adapter.execute per case, registers tests + ContractRegistryMeta
9
+ * - `contract.flow(id)` — protocol-agnostic FlowBuilder
10
+ * - `runFlow(flow, ctx)` — core flow execution helper (Rule 1/2 teardown)
11
+ * - `normalizeFlow(runtime)` — Runtime → ExtractedFlowProjection
12
+ * - Permissive Proxy tracer for `compute` nodes (best-effort reads/writes)
13
+ *
14
+ * HTTP is NOT handled here — it registers itself in `./contract-http/`.
15
+ * This file has zero HTTP-specific code.
16
+ *
17
+ * See:
18
+ * - `internal/40-discovery/proposals/contract-generics-complete.md` v5
19
+ * - `internal/40-discovery/proposals/contract-flow.md` v9
20
+ */
21
+ import type { TestContext } from "./types.js";
22
+ import type { ContractProtocolAdapter, ExtractedFlowProjection, FieldMapping, FlowBuilder, FlowContract, FlowMeta, RuntimeFlowProjection } from "./contract-types.js";
23
+ /** Internal accessor for plugins / downstream (scanner, runner). */
24
+ export declare function getAdapter(protocol: string): ContractProtocolAdapter<any, any, any, any, any> | undefined;
25
+ /**
26
+ * Register an adapter. Called by built-in HTTP adapter on SDK load, and by
27
+ * external adapter plugins (`@glubean/contract-grpc` etc.) on their import.
28
+ */
29
+ declare function register<Spec, RuntimeSchemas = unknown, RuntimeMeta = unknown, SafeSchemas = unknown, SafeMeta = unknown>(protocol: string, adapter: ContractProtocolAdapter<Spec, RuntimeSchemas, RuntimeMeta, SafeSchemas, SafeMeta>): void;
30
+ type ContractNamespace = {
31
+ register: typeof register;
32
+ flow: typeof flow;
33
+ [protocol: string]: unknown;
34
+ };
35
+ export declare const contract: ContractNamespace;
36
+ /**
37
+ * Protocol-agnostic flow builder. See contract-flow.md v9 §4.1.
38
+ */
39
+ export declare function flow(idOrMeta: string | FlowMeta): FlowBuilder<unknown>;
40
+ /**
41
+ * Core flow execution helper. Implements the Rule 1 / Rule 2 teardown
42
+ * semantics from contract-flow.md §7.
43
+ */
44
+ export declare function runFlow<State>(flowContract: FlowContract<State>, ctx: TestContext): Promise<void>;
45
+ /**
46
+ * Normalize a RuntimeFlowProjection to JSON-safe ExtractedFlowProjection.
47
+ * Runs Proxy dry-run of lens functions to extract FieldMappings.
48
+ *
49
+ * Lens purity is enforced here: if a `step.bindings.in` or `.out` lens
50
+ * violates purity (method call, `new`, etc.), `LensPurityError` is thrown
51
+ * with step context so the author sees which step needs fixing.
52
+ */
53
+ export declare function normalizeFlow<State>(runtime: RuntimeFlowProjection<State> & {
54
+ id: string;
55
+ }): ExtractedFlowProjection;
56
+ /**
57
+ * Run a pure lens `fn: (state) => output` with a tracing Proxy, extracting
58
+ * FieldMappings from state paths to output paths.
59
+ *
60
+ * Pure-lens enforcement: method calls, `new`, and coercion on the state
61
+ * proxy raise `LensPurityError`. Errors are **not** swallowed — the caller
62
+ * (typically `normalizeFlow`) wraps them with step context and re-throws,
63
+ * so authors see the failure at flow build time rather than silently
64
+ * losing projection data.
65
+ */
66
+ export declare function extractMappings(fn: (state: any) => any): FieldMapping[];
67
+ /**
68
+ * Extract FieldMappings from `out: (state, response) => newState`.
69
+ * Same purity contract as `extractMappings`.
70
+ */
71
+ export declare function extractMappingsOut(fn: (state: any, response: any) => any): FieldMapping[];
72
+ /**
73
+ * Raised by the strict lens Proxy when a user lens fn attempts an operation
74
+ * that breaks the "pure field access + repack" contract. Caught and re-
75
+ * thrown with step context by `normalizeFlow`.
76
+ */
77
+ export declare class LensPurityError extends Error {
78
+ readonly path: string;
79
+ readonly operation: string;
80
+ constructor(path: string, operation: string);
81
+ }
82
+ /**
83
+ * Trace a `compute` fn to extract top-level reads + writes.
84
+ *
85
+ * Compute allows arbitrary sync TS (template literals, method calls, .map()),
86
+ * so the Proxy must be permissive: respond to primitive coercion, swallow
87
+ * method calls, etc. We only record top-level property access paths.
88
+ *
89
+ * See contract-flow.md §4.1.1 for design + known limitations.
90
+ */
91
+ export declare function traceComputeFn(fn: (state: any) => any): {
92
+ reads: string[];
93
+ writes: string[];
94
+ };
95
+ export {};
96
+ //# sourceMappingURL=contract-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-core.d.ts","sourceRoot":"","sources":["../src/contract-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAEV,uBAAuB,EAGvB,uBAAuB,EAEvB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,QAAQ,EAKR,qBAAqB,EAEtB,MAAM,qBAAqB,CAAC;AAS7B,oEAAoE;AACpE,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,GACf,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,CAE9D;AAYD;;;GAGG;AACH,iBAAS,QAAQ,CACf,IAAI,EACJ,cAAc,GAAG,OAAO,EACxB,WAAW,GAAG,OAAO,EACrB,WAAW,GAAG,OAAO,EACrB,QAAQ,GAAG,OAAO,EAElB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,uBAAuB,CAAC,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAC,GACzF,IAAI,CAgBN;AA6OD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,OAAO,QAAQ,CAA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