@contractkit/plugin-python 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.turbo/turbo-build$colon$ci.log +35 -0
  2. package/.turbo/turbo-build.log +15 -0
  3. package/.turbo/turbo-test$colon$ci.log +59 -0
  4. package/.turbo/turbo-test.log +15 -0
  5. package/CHANGELOG.md +118 -0
  6. package/README.md +86 -0
  7. package/coverage/base.css +224 -0
  8. package/coverage/block-navigation.js +87 -0
  9. package/coverage/clover.xml +559 -0
  10. package/coverage/coverage-final.json +4 -0
  11. package/coverage/favicon.png +0 -0
  12. package/coverage/index.html +131 -0
  13. package/coverage/prettify.css +1 -0
  14. package/coverage/prettify.js +2 -0
  15. package/coverage/sort-arrow-sprite.png +0 -0
  16. package/coverage/sorter.js +210 -0
  17. package/coverage/src/codegen-client.ts.html +2071 -0
  18. package/coverage/src/codegen-models.ts.html +1360 -0
  19. package/coverage/src/index.html +131 -0
  20. package/coverage/tests/helpers.ts.html +667 -0
  21. package/coverage/tests/index.html +116 -0
  22. package/dist/codegen-client.d.ts +30 -0
  23. package/dist/codegen-client.d.ts.map +1 -0
  24. package/dist/codegen-models.d.ts +19 -0
  25. package/dist/codegen-models.d.ts.map +1 -0
  26. package/dist/index.d.ts +17 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +1046 -0
  29. package/dist/index.js.map +1 -0
  30. package/eslint.config.js +6 -0
  31. package/package.json +45 -0
  32. package/src/codegen-client.ts +662 -0
  33. package/src/codegen-models.ts +425 -0
  34. package/src/index.ts +143 -0
  35. package/tests/codegen-client.test.ts +361 -0
  36. package/tests/codegen-models.test.ts +295 -0
  37. package/tests/helpers.ts +194 -0
  38. package/tsconfig.json +9 -0
  39. package/vitest.config.ts +14 -0
@@ -0,0 +1,194 @@
1
+ // Re-export all helpers from the SDK plugin's test helpers (same AST builder utilities)
2
+ export type {
3
+ ContractRootNode,
4
+ ModelNode,
5
+ FieldNode,
6
+ ContractTypeNode,
7
+ ScalarTypeNode,
8
+ ArrayTypeNode,
9
+ TupleTypeNode,
10
+ RecordTypeNode,
11
+ EnumTypeNode,
12
+ LiteralTypeNode,
13
+ UnionTypeNode,
14
+ ModelRefTypeNode,
15
+ InlineObjectTypeNode,
16
+ LazyTypeNode,
17
+ SourceLocation,
18
+ OpRootNode,
19
+ OpRouteNode,
20
+ OpOperationNode,
21
+ OpParamNode,
22
+ OpRequestNode,
23
+ OpResponseNode,
24
+ HttpMethod,
25
+ ParamSource,
26
+ RouteModifier,
27
+ } from '@contractkit/core';
28
+
29
+ import type {
30
+ ContractRootNode,
31
+ ModelNode,
32
+ FieldNode,
33
+ ContractTypeNode,
34
+ ScalarTypeNode,
35
+ ArrayTypeNode,
36
+ TupleTypeNode,
37
+ RecordTypeNode,
38
+ EnumTypeNode,
39
+ LiteralTypeNode,
40
+ UnionTypeNode,
41
+ ModelRefTypeNode,
42
+ InlineObjectTypeNode,
43
+ LazyTypeNode,
44
+ SourceLocation,
45
+ OpRootNode,
46
+ OpRouteNode,
47
+ OpOperationNode,
48
+ OpParamNode,
49
+ OpRequestNode,
50
+ OpResponseNode,
51
+ HttpMethod,
52
+ ParamSource,
53
+ RouteModifier,
54
+ } from '@contractkit/core';
55
+
56
+ // ─── AST Builder Helpers ────────────────────────────────────────────────────
57
+
58
+ export function loc(line = 1, file = 'test.ck'): SourceLocation {
59
+ return { file, line };
60
+ }
61
+
62
+ export function scalarType(name: ScalarTypeNode['name'], mods?: Partial<ScalarTypeNode>): ScalarTypeNode {
63
+ return { kind: 'scalar', name, ...mods };
64
+ }
65
+
66
+ export function arrayType(item: ContractTypeNode, mods?: { min?: number; max?: number }): ArrayTypeNode {
67
+ return { kind: 'array', item, ...mods };
68
+ }
69
+
70
+ export function tupleType(...items: ContractTypeNode[]): TupleTypeNode {
71
+ return { kind: 'tuple', items };
72
+ }
73
+
74
+ export function recordType(key: ContractTypeNode, value: ContractTypeNode): RecordTypeNode {
75
+ return { kind: 'record', key, value };
76
+ }
77
+
78
+ export function enumType(...values: string[]): EnumTypeNode {
79
+ return { kind: 'enum', values };
80
+ }
81
+
82
+ export function literalType(value: string | number | boolean): LiteralTypeNode {
83
+ return { kind: 'literal', value };
84
+ }
85
+
86
+ export function unionType(...members: ContractTypeNode[]): UnionTypeNode {
87
+ return { kind: 'union', members };
88
+ }
89
+
90
+ export function refType(name: string): ModelRefTypeNode {
91
+ return { kind: 'ref', name };
92
+ }
93
+
94
+ export function inlineObjectType(fields: FieldNode[]): InlineObjectTypeNode {
95
+ return { kind: 'inlineObject', fields };
96
+ }
97
+
98
+ export function lazyType(inner: ContractTypeNode): LazyTypeNode {
99
+ return { kind: 'lazy', inner };
100
+ }
101
+
102
+ export function field(name: string, type: ContractTypeNode, overrides?: Partial<FieldNode>): FieldNode {
103
+ return {
104
+ name,
105
+ optional: false,
106
+ nullable: false,
107
+ visibility: 'normal',
108
+ type,
109
+ loc: loc(),
110
+ ...overrides,
111
+ };
112
+ }
113
+
114
+ export function model(name: string, fields: FieldNode[], overrides?: Partial<ModelNode>): ModelNode {
115
+ return {
116
+ kind: 'model',
117
+ name,
118
+ fields,
119
+ loc: loc(),
120
+ ...overrides,
121
+ };
122
+ }
123
+
124
+ export function contractRoot(models: ModelNode[], file = 'test.ck'): ContractRootNode {
125
+ return { kind: 'contractRoot', meta: {}, models, file };
126
+ }
127
+
128
+ export function opParam(name: string, type: ContractTypeNode): OpParamNode {
129
+ return { name, type, loc: loc(1, 'test.op') };
130
+ }
131
+
132
+ export function paramNodes(nodes: OpParamNode[]): ParamSource {
133
+ return { kind: 'params', nodes };
134
+ }
135
+
136
+ export function paramRef(name: string): ParamSource {
137
+ return { kind: 'ref', name };
138
+ }
139
+
140
+ export function paramType(node: ContractTypeNode): ParamSource {
141
+ return { kind: 'type', node };
142
+ }
143
+
144
+ export function opRequest(bodyType: string | ContractTypeNode, contentType: string = 'application/json'): OpRequestNode {
145
+ const bt: ContractTypeNode = typeof bodyType === 'string' ? refType(bodyType) : bodyType;
146
+ return { bodies: [{ contentType, bodyType: bt }] };
147
+ }
148
+
149
+ export function opResponse(statusCode: number, bodyType?: string | ContractTypeNode, contentType?: string): OpResponseNode {
150
+ const bt: ContractTypeNode | undefined =
151
+ bodyType === undefined ? undefined : typeof bodyType === 'string' ? parseBodyTypeString(bodyType) : bodyType;
152
+ return { statusCode, contentType, bodyType: bt };
153
+ }
154
+
155
+ function parseBodyTypeString(s: string): ContractTypeNode {
156
+ const arrayMatch = s.match(/^array\((.+)\)$/);
157
+ if (arrayMatch?.[1]) return { kind: 'array', item: refType(arrayMatch[1]) };
158
+ return refType(s);
159
+ }
160
+
161
+ function normalizeParamSource(value: unknown): ParamSource {
162
+ if (!value) return value as ParamSource;
163
+ if (typeof value === 'string') return { kind: 'ref', name: value };
164
+ if (Array.isArray(value)) return { kind: 'params', nodes: value as OpParamNode[] };
165
+ const v = value as ParamSource;
166
+ if (v.kind === 'params' || v.kind === 'ref' || v.kind === 'type') return v;
167
+ return { kind: 'type', node: value as ContractTypeNode };
168
+ }
169
+
170
+ export function opOperation(method: HttpMethod, overrides?: Partial<OpOperationNode> & { query?: unknown; headers?: unknown }): OpOperationNode {
171
+ const normalized = { ...overrides } as Partial<OpOperationNode>;
172
+ if (overrides?.query !== undefined) normalized.query = normalizeParamSource(overrides.query);
173
+ if (overrides?.headers !== undefined) normalized.headers = normalizeParamSource(overrides.headers);
174
+ return {
175
+ method,
176
+ responses: [],
177
+ loc: loc(1, 'test.op'),
178
+ ...normalized,
179
+ };
180
+ }
181
+
182
+ export function opRoute(
183
+ path: string,
184
+ operations: OpOperationNode[],
185
+ params?: ParamSource | OpParamNode[] | string,
186
+ modifiers?: RouteModifier[],
187
+ ): OpRouteNode {
188
+ const normalizedParams = params !== undefined ? normalizeParamSource(params) : undefined;
189
+ return { path, params: normalizedParams, operations, modifiers, loc: loc(1, 'test.op') };
190
+ }
191
+
192
+ export function opRoot(routes: OpRouteNode[], file = 'payments.op.ck', meta: Record<string, string> = {}): OpRootNode {
193
+ return { kind: 'opRoot', meta, routes, file };
194
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@repo/config-typescript/base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
@@ -0,0 +1,14 @@
1
+ import { defineProject } from 'vitest/config';
2
+ import swc from 'unplugin-swc';
3
+
4
+ export default defineProject({
5
+ test: {
6
+ globals: true,
7
+ include: ['./tests/**/*.test.ts'],
8
+ environment: 'node',
9
+ testTimeout: 50000,
10
+ hookTimeout: 30000,
11
+ fileParallelism: true,
12
+ },
13
+ plugins: [swc.vite()],
14
+ });