tywrap 0.1.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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +263 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/index.d.ts +41 -0
  8. package/dist/config/index.d.ts.map +1 -0
  9. package/dist/config/index.js +234 -0
  10. package/dist/config/index.js.map +1 -0
  11. package/dist/core/analyzer.d.ts +63 -0
  12. package/dist/core/analyzer.d.ts.map +1 -0
  13. package/dist/core/analyzer.js +676 -0
  14. package/dist/core/analyzer.js.map +1 -0
  15. package/dist/core/discovery.d.ts +85 -0
  16. package/dist/core/discovery.d.ts.map +1 -0
  17. package/dist/core/discovery.js +344 -0
  18. package/dist/core/discovery.js.map +1 -0
  19. package/dist/core/generator.d.ts +37 -0
  20. package/dist/core/generator.d.ts.map +1 -0
  21. package/dist/core/generator.js +368 -0
  22. package/dist/core/generator.js.map +1 -0
  23. package/dist/core/mapper.d.ts +40 -0
  24. package/dist/core/mapper.d.ts.map +1 -0
  25. package/dist/core/mapper.js +401 -0
  26. package/dist/core/mapper.js.map +1 -0
  27. package/dist/core/validation.d.ts +79 -0
  28. package/dist/core/validation.d.ts.map +1 -0
  29. package/dist/core/validation.js +486 -0
  30. package/dist/core/validation.js.map +1 -0
  31. package/dist/index.d.ts +26 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +29 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/runtime/base.d.ts +12 -0
  36. package/dist/runtime/base.d.ts.map +1 -0
  37. package/dist/runtime/base.js +6 -0
  38. package/dist/runtime/base.js.map +1 -0
  39. package/dist/runtime/errors.d.ts +17 -0
  40. package/dist/runtime/errors.d.ts.map +1 -0
  41. package/dist/runtime/errors.js +21 -0
  42. package/dist/runtime/errors.js.map +1 -0
  43. package/dist/runtime/http.d.ts +22 -0
  44. package/dist/runtime/http.d.ts.map +1 -0
  45. package/dist/runtime/http.js +79 -0
  46. package/dist/runtime/http.js.map +1 -0
  47. package/dist/runtime/index.d.ts +8 -0
  48. package/dist/runtime/index.d.ts.map +1 -0
  49. package/dist/runtime/index.js +17 -0
  50. package/dist/runtime/index.js.map +1 -0
  51. package/dist/runtime/node.d.ts +48 -0
  52. package/dist/runtime/node.d.ts.map +1 -0
  53. package/dist/runtime/node.js +328 -0
  54. package/dist/runtime/node.js.map +1 -0
  55. package/dist/runtime/optimized-node.d.ts +131 -0
  56. package/dist/runtime/optimized-node.d.ts.map +1 -0
  57. package/dist/runtime/optimized-node.js +622 -0
  58. package/dist/runtime/optimized-node.js.map +1 -0
  59. package/dist/runtime/protocol.d.ts +3 -0
  60. package/dist/runtime/protocol.d.ts.map +1 -0
  61. package/dist/runtime/protocol.js +3 -0
  62. package/dist/runtime/protocol.js.map +1 -0
  63. package/dist/runtime/pyodide.d.ts +27 -0
  64. package/dist/runtime/pyodide.d.ts.map +1 -0
  65. package/dist/runtime/pyodide.js +191 -0
  66. package/dist/runtime/pyodide.js.map +1 -0
  67. package/dist/tools/python_suite.js +173 -0
  68. package/dist/tools/python_suite.js.map +1 -0
  69. package/dist/types/index.d.ts +299 -0
  70. package/dist/types/index.d.ts.map +1 -0
  71. package/dist/types/index.js +5 -0
  72. package/dist/types/index.js.map +1 -0
  73. package/dist/tywrap.d.ts +29 -0
  74. package/dist/tywrap.d.ts.map +1 -0
  75. package/dist/tywrap.js +589 -0
  76. package/dist/tywrap.js.map +1 -0
  77. package/dist/utils/bundle-optimizer.d.ts +182 -0
  78. package/dist/utils/bundle-optimizer.d.ts.map +1 -0
  79. package/dist/utils/bundle-optimizer.js +680 -0
  80. package/dist/utils/bundle-optimizer.js.map +1 -0
  81. package/dist/utils/cache.d.ts +149 -0
  82. package/dist/utils/cache.d.ts.map +1 -0
  83. package/dist/utils/cache.js +492 -0
  84. package/dist/utils/cache.js.map +1 -0
  85. package/dist/utils/codec.d.ts +94 -0
  86. package/dist/utils/codec.d.ts.map +1 -0
  87. package/dist/utils/codec.js +150 -0
  88. package/dist/utils/codec.js.map +1 -0
  89. package/dist/utils/logger.d.ts +42 -0
  90. package/dist/utils/logger.d.ts.map +1 -0
  91. package/dist/utils/logger.js +140 -0
  92. package/dist/utils/logger.js.map +1 -0
  93. package/dist/utils/memory-profiler.d.ts +123 -0
  94. package/dist/utils/memory-profiler.d.ts.map +1 -0
  95. package/dist/utils/memory-profiler.js +426 -0
  96. package/dist/utils/memory-profiler.js.map +1 -0
  97. package/dist/utils/parallel-processor.d.ts +146 -0
  98. package/dist/utils/parallel-processor.d.ts.map +1 -0
  99. package/dist/utils/parallel-processor.js +636 -0
  100. package/dist/utils/parallel-processor.js.map +1 -0
  101. package/dist/utils/python.d.ts +8 -0
  102. package/dist/utils/python.d.ts.map +1 -0
  103. package/dist/utils/python.js +56 -0
  104. package/dist/utils/python.js.map +1 -0
  105. package/dist/utils/runtime.d.ts +153 -0
  106. package/dist/utils/runtime.d.ts.map +1 -0
  107. package/dist/utils/runtime.js +519 -0
  108. package/dist/utils/runtime.js.map +1 -0
  109. package/package.json +136 -0
  110. package/runtime/python_bridge.py +476 -0
  111. package/src/cli.ts +331 -0
  112. package/src/config/index.ts +289 -0
  113. package/src/core/analyzer.ts +788 -0
  114. package/src/core/discovery.ts +415 -0
  115. package/src/core/generator.ts +447 -0
  116. package/src/core/mapper.ts +504 -0
  117. package/src/core/validation.ts +693 -0
  118. package/src/index.ts +83 -0
  119. package/src/runtime/base.ts +32 -0
  120. package/src/runtime/errors.ts +19 -0
  121. package/src/runtime/http.ts +132 -0
  122. package/src/runtime/index.ts +24 -0
  123. package/src/runtime/node.ts +431 -0
  124. package/src/runtime/optimized-node.ts +838 -0
  125. package/src/runtime/protocol.ts +2 -0
  126. package/src/runtime/pyodide.ts +228 -0
  127. package/src/types/global.d.ts +60 -0
  128. package/src/types/index.ts +410 -0
  129. package/src/tywrap.ts +669 -0
  130. package/src/utils/bundle-optimizer.ts +876 -0
  131. package/src/utils/cache.ts +634 -0
  132. package/src/utils/codec.ts +275 -0
  133. package/src/utils/logger.ts +201 -0
  134. package/src/utils/memory-profiler.ts +582 -0
  135. package/src/utils/parallel-processor.ts +879 -0
  136. package/src/utils/python.ts +79 -0
  137. package/src/utils/runtime.ts +616 -0
@@ -0,0 +1,2 @@
1
+ export const TYWRAP_PROTOCOL = 'tywrap/1';
2
+ export const TYWRAP_PROTOCOL_VERSION = 1;
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Pyodide runtime bridge (browser)
3
+ */
4
+
5
+ import { RuntimeBridge } from './base.js';
6
+
7
+ export interface PyodideBridgeOptions {
8
+ indexURL: string;
9
+ packages?: string[];
10
+ }
11
+
12
+ type LoadPyodide = (options: { indexURL: string }) => Promise<PyodideInstance>;
13
+
14
+ interface PyodideInstance {
15
+ runPython: (code: string) => unknown;
16
+ runPythonAsync: (code: string) => Promise<unknown>;
17
+ globals: { get: (key: string) => unknown; set: (k: string, v: unknown) => void };
18
+ toPy: (obj: unknown) => unknown;
19
+ loadPackage: (name: string | string[]) => Promise<void>;
20
+ }
21
+
22
+ export class PyodideBridge extends RuntimeBridge {
23
+ private readonly indexURL: string;
24
+ private readonly packages: readonly string[];
25
+ private py?: PyodideInstance;
26
+ private initPromise?: Promise<void>;
27
+
28
+ constructor(options: PyodideBridgeOptions = { indexURL: 'https://cdn.jsdelivr.net/pyodide/' }) {
29
+ super();
30
+ this.indexURL = options.indexURL;
31
+ this.packages = [...(options.packages ?? [])];
32
+ }
33
+
34
+ private async ensureReady(): Promise<void> {
35
+ if (this.py) {
36
+ return;
37
+ }
38
+ // If already initializing, wait for that promise
39
+ if (this.initPromise) {
40
+ return this.initPromise;
41
+ }
42
+ // Start initialization and store the promise to prevent concurrent initialization
43
+ this.initPromise = this.doInit();
44
+ return this.initPromise;
45
+ }
46
+
47
+ private async doInit(): Promise<void> {
48
+ const loadPyodideFn: LoadPyodide | undefined = await this.resolveLoadPyodide();
49
+ if (!loadPyodideFn) {
50
+ throw new Error('Pyodide is not available in this environment');
51
+ }
52
+ this.py = await loadPyodideFn({ indexURL: this.indexURL });
53
+ if (this.packages.length > 0) {
54
+ await this.py.loadPackage([...this.packages]);
55
+ }
56
+ await this.bootstrapHelpers();
57
+ }
58
+
59
+ async init(): Promise<void> {
60
+ await this.ensureReady();
61
+ }
62
+
63
+ private async resolveLoadPyodide(): Promise<LoadPyodide | undefined> {
64
+ // Prefer global loadPyodide when present (browser script tag include)
65
+ const g = (globalThis as unknown as { loadPyodide?: LoadPyodide }) ?? {};
66
+ if (typeof g.loadPyodide === 'function') {
67
+ return g.loadPyodide;
68
+ }
69
+ try {
70
+ // Attempt dynamic import if available
71
+ const mod = (await import('pyodide')) as unknown as { loadPyodide?: LoadPyodide };
72
+ if (typeof mod.loadPyodide === 'function') {
73
+ return mod.loadPyodide;
74
+ }
75
+ } catch {
76
+ // Ignore import errors - pyodide may not be installed
77
+ // This is expected in most environments
78
+ }
79
+ return undefined;
80
+ }
81
+
82
+ private async bootstrapHelpers(): Promise<void> {
83
+ if (!this.py) {
84
+ return;
85
+ }
86
+ const helper = [
87
+ 'import importlib',
88
+ '__tywrap_instances = {}',
89
+ 'def __tywrap_call(module, function_name, args, kwargs):',
90
+ ' mod = importlib.import_module(module)',
91
+ ' fn = getattr(mod, function_name)',
92
+ ' return fn(*args, **(kwargs or {}))',
93
+ 'def __tywrap_instantiate(module, class_name, args, kwargs):',
94
+ ' mod = importlib.import_module(module)',
95
+ ' cls = getattr(mod, class_name)',
96
+ ' obj = cls(*args, **(kwargs or {}))',
97
+ ' handle = str(id(obj))',
98
+ ' __tywrap_instances[handle] = obj',
99
+ ' return handle',
100
+ 'def __tywrap_call_method(handle, method_name, args, kwargs):',
101
+ ' if handle not in __tywrap_instances:',
102
+ ' raise KeyError(f"Unknown handle: {handle}")',
103
+ ' obj = __tywrap_instances[handle]',
104
+ ' fn = getattr(obj, method_name)',
105
+ ' return fn(*args, **(kwargs or {}))',
106
+ 'def __tywrap_dispose_instance(handle):',
107
+ ' return __tywrap_instances.pop(handle, None) is not None',
108
+ ].join('\n');
109
+ await this.py.runPythonAsync(helper);
110
+ }
111
+
112
+ async call<T = unknown>(
113
+ module: string,
114
+ functionName: string,
115
+ args: unknown[],
116
+ kwargs?: Record<string, unknown>
117
+ ): Promise<T> {
118
+ await this.ensureReady();
119
+ const py = this.py;
120
+ if (!py) {
121
+ throw new Error('Pyodide not initialized');
122
+ }
123
+ const fn = py.globals.get('__tywrap_call');
124
+ if (!fn) {
125
+ throw new Error('Pyodide helper not initialized');
126
+ }
127
+ const invoke = fn as (module: string, f: string, a: unknown, k: unknown) => unknown;
128
+ const pyArgs = py.toPy(args ?? []);
129
+ const pyKwargs = py.toPy(kwargs ?? {});
130
+ try {
131
+ const out = invoke(module, functionName, pyArgs, pyKwargs);
132
+ return out as T;
133
+ } finally {
134
+ this.destroyPyProxy(pyArgs);
135
+ this.destroyPyProxy(pyKwargs);
136
+ this.destroyPyProxy(fn);
137
+ }
138
+ }
139
+
140
+ async instantiate<T = unknown>(
141
+ module: string,
142
+ className: string,
143
+ args: unknown[],
144
+ kwargs?: Record<string, unknown>
145
+ ): Promise<T> {
146
+ await this.ensureReady();
147
+ const py = this.py;
148
+ if (!py) {
149
+ throw new Error('Pyodide not initialized');
150
+ }
151
+ const fn = py.globals.get('__tywrap_instantiate');
152
+ if (!fn) {
153
+ throw new Error('Pyodide helper not initialized');
154
+ }
155
+ const invoke = fn as (module: string, c: string, a: unknown, k: unknown) => unknown;
156
+ const pyArgs = py.toPy(args ?? []);
157
+ const pyKwargs = py.toPy(kwargs ?? {});
158
+ try {
159
+ const out = invoke(module, className, pyArgs, pyKwargs);
160
+ return out as T;
161
+ } finally {
162
+ this.destroyPyProxy(pyArgs);
163
+ this.destroyPyProxy(pyKwargs);
164
+ this.destroyPyProxy(fn);
165
+ }
166
+ }
167
+
168
+ async callMethod<T = unknown>(
169
+ handle: string,
170
+ methodName: string,
171
+ args: unknown[],
172
+ kwargs?: Record<string, unknown>
173
+ ): Promise<T> {
174
+ await this.ensureReady();
175
+ const py = this.py;
176
+ if (!py) {
177
+ throw new Error('Pyodide not initialized');
178
+ }
179
+ const fn = py.globals.get('__tywrap_call_method');
180
+ if (!fn) {
181
+ throw new Error('Pyodide helper not initialized');
182
+ }
183
+ const invoke = fn as (h: string, m: string, a: unknown, k: unknown) => unknown;
184
+ const pyArgs = py.toPy(args ?? []);
185
+ const pyKwargs = py.toPy(kwargs ?? {});
186
+ try {
187
+ const out = invoke(handle, methodName, pyArgs, pyKwargs);
188
+ return out as T;
189
+ } finally {
190
+ this.destroyPyProxy(pyArgs);
191
+ this.destroyPyProxy(pyKwargs);
192
+ this.destroyPyProxy(fn);
193
+ }
194
+ }
195
+
196
+ async disposeInstance(handle: string): Promise<void> {
197
+ await this.ensureReady();
198
+ const py = this.py;
199
+ if (!py) {
200
+ throw new Error('Pyodide not initialized');
201
+ }
202
+ const fn = py.globals.get('__tywrap_dispose_instance');
203
+ if (!fn) {
204
+ throw new Error('Pyodide helper not initialized');
205
+ }
206
+ const invoke = fn as (h: string) => unknown;
207
+ try {
208
+ invoke(handle);
209
+ } finally {
210
+ this.destroyPyProxy(fn);
211
+ }
212
+ }
213
+
214
+ async dispose(): Promise<void> {
215
+ // Pyodide has no explicit dispose for instance; rely on GC
216
+ this.py = undefined;
217
+ }
218
+
219
+ private destroyPyProxy(value: unknown): void {
220
+ if (value && typeof (value as { destroy?: () => void }).destroy === 'function') {
221
+ try {
222
+ (value as { destroy: () => void }).destroy();
223
+ } catch {
224
+ // ignore cleanup failures
225
+ }
226
+ }
227
+ }
228
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Global type declarations for runtime environments
3
+ */
4
+
5
+ // Deno runtime types
6
+ declare namespace DenoTypes {
7
+ interface Version {
8
+ deno: string;
9
+ }
10
+
11
+ interface DenoGlobal {
12
+ version: Version;
13
+ readTextFile(path: string): Promise<string>;
14
+ writeTextFile(path: string, content: string): Promise<void>;
15
+ Command: new (
16
+ cmd: string,
17
+ options?: { args?: string[] }
18
+ ) => {
19
+ output(): Promise<{ code: number; stdout: Uint8Array; stderr: Uint8Array }>;
20
+ };
21
+ }
22
+ }
23
+
24
+ // Bun runtime types
25
+ declare namespace BunTypes {
26
+ interface BunGlobal {
27
+ version: string;
28
+
29
+ file(path: string): {
30
+ text(): Promise<string>;
31
+ };
32
+
33
+ write(path: string, content: string): Promise<void>;
34
+
35
+ spawn(
36
+ cmd: string[],
37
+ options?: {
38
+ stdout?: string;
39
+ stderr?: string;
40
+ }
41
+ ): {
42
+ stdout: ReadableStream;
43
+ stderr: ReadableStream;
44
+ exitCode?: number;
45
+ exited: Promise<void>;
46
+ };
47
+ }
48
+ }
49
+
50
+ // Global runtime declarations
51
+ declare global {
52
+ // eslint-disable-next-line @typescript-eslint/naming-convention
53
+ var Deno: DenoTypes.DenoGlobal | undefined;
54
+ // eslint-disable-next-line @typescript-eslint/naming-convention
55
+ var Bun: BunTypes.BunGlobal | undefined;
56
+ // Node.js compat for atob in browser-less environments
57
+ function atob(data: string): string;
58
+ }
59
+
60
+ export {};
@@ -0,0 +1,410 @@
1
+ /**
2
+ * Core type definitions for tywrap
3
+ */
4
+
5
+ export interface PythonModule {
6
+ name: string;
7
+ path?: string;
8
+ version?: string;
9
+ functions: PythonFunction[];
10
+ classes: PythonClass[];
11
+ imports: PythonImport[];
12
+ exports: string[];
13
+ }
14
+
15
+ export interface PythonFunction {
16
+ name: string;
17
+ signature: FunctionSignature;
18
+ docstring?: string;
19
+ decorators: string[];
20
+ isAsync: boolean;
21
+ isGenerator: boolean;
22
+ returnType: PythonType;
23
+ parameters: Parameter[];
24
+ }
25
+
26
+ export interface PythonClass {
27
+ name: string;
28
+ bases: string[];
29
+ methods: PythonFunction[];
30
+ properties: Property[];
31
+ docstring?: string;
32
+ decorators: string[];
33
+ kind?: 'class' | 'protocol' | 'typed_dict' | 'namedtuple' | 'dataclass' | 'pydantic';
34
+ }
35
+
36
+ export interface PythonImport {
37
+ module: string;
38
+ name?: string;
39
+ alias?: string;
40
+ fromImport: boolean;
41
+ }
42
+
43
+ export interface Parameter {
44
+ name: string;
45
+ type: PythonType;
46
+ optional: boolean;
47
+ defaultValue?: unknown;
48
+ varArgs: boolean;
49
+ kwArgs: boolean;
50
+ }
51
+
52
+ export interface Property {
53
+ name: string;
54
+ type: PythonType;
55
+ readonly: boolean;
56
+ setter?: boolean;
57
+ getter?: boolean;
58
+ }
59
+
60
+ export interface FunctionSignature {
61
+ parameters: Parameter[];
62
+ returnType: PythonType;
63
+ isAsync: boolean;
64
+ isGenerator: boolean;
65
+ }
66
+
67
+ // Python type system
68
+ export type PythonType =
69
+ | PrimitiveType
70
+ | CollectionType
71
+ | UnionType
72
+ | OptionalType
73
+ | GenericType
74
+ | CallableType
75
+ | LiteralType
76
+ | AnnotatedType
77
+ | CustomType
78
+ | TypeVarType
79
+ | FinalType
80
+ | ClassVarType;
81
+
82
+ export interface PrimitiveType {
83
+ kind: 'primitive';
84
+ name: 'int' | 'float' | 'str' | 'bool' | 'bytes' | 'None';
85
+ }
86
+
87
+ export interface CollectionType {
88
+ kind: 'collection';
89
+ name: 'list' | 'dict' | 'tuple' | 'set' | 'frozenset';
90
+ itemTypes: PythonType[];
91
+ }
92
+
93
+ export interface UnionType {
94
+ kind: 'union';
95
+ types: PythonType[];
96
+ }
97
+
98
+ export interface OptionalType {
99
+ kind: 'optional';
100
+ type: PythonType;
101
+ }
102
+
103
+ export interface GenericType {
104
+ kind: 'generic';
105
+ name: string;
106
+ typeArgs: PythonType[];
107
+ }
108
+
109
+ export interface CustomType {
110
+ kind: 'custom';
111
+ name: string;
112
+ module?: string;
113
+ }
114
+
115
+ export interface CallableType {
116
+ kind: 'callable';
117
+ parameters: PythonType[];
118
+ returnType: PythonType;
119
+ }
120
+
121
+ export interface LiteralType {
122
+ kind: 'literal';
123
+ value: string | number | boolean | null;
124
+ }
125
+
126
+ export interface AnnotatedType {
127
+ kind: 'annotated';
128
+ base: PythonType;
129
+ metadata: readonly unknown[];
130
+ }
131
+
132
+ export interface TypeVarType {
133
+ kind: 'typevar';
134
+ name: string;
135
+ bound?: PythonType;
136
+ constraints?: PythonType[];
137
+ variance?: 'covariant' | 'contravariant' | 'invariant';
138
+ }
139
+
140
+ export interface FinalType {
141
+ kind: 'final';
142
+ type: PythonType;
143
+ }
144
+
145
+ export interface ClassVarType {
146
+ kind: 'classvar';
147
+ type: PythonType;
148
+ }
149
+
150
+ // TypeScript type system
151
+ export type TypescriptType =
152
+ | TSPrimitiveType
153
+ | TSArrayType
154
+ | TSTupleType
155
+ | TSObjectType
156
+ | TSUnionType
157
+ | TSFunctionType
158
+ | TSGenericType
159
+ | TSLiteralType
160
+ | TSCustomType;
161
+
162
+ export interface TSPrimitiveType {
163
+ kind: 'primitive';
164
+ name:
165
+ | 'string'
166
+ | 'number'
167
+ | 'boolean'
168
+ | 'null'
169
+ | 'undefined'
170
+ | 'void'
171
+ | 'unknown'
172
+ | 'never'
173
+ | 'object';
174
+ }
175
+
176
+ export interface TSArrayType {
177
+ kind: 'array';
178
+ elementType: TypescriptType;
179
+ }
180
+
181
+ export interface TSTupleType {
182
+ kind: 'tuple';
183
+ elementTypes: TypescriptType[];
184
+ }
185
+
186
+ export interface TSObjectType {
187
+ kind: 'object';
188
+ properties: TSProperty[];
189
+ indexSignature?: TSIndexSignature;
190
+ }
191
+
192
+ export interface TSProperty {
193
+ name: string;
194
+ type: TypescriptType;
195
+ optional: boolean;
196
+ readonly: boolean;
197
+ }
198
+
199
+ export interface TSIndexSignature {
200
+ keyType: TypescriptType;
201
+ valueType: TypescriptType;
202
+ }
203
+
204
+ export interface TSUnionType {
205
+ kind: 'union';
206
+ types: TypescriptType[];
207
+ }
208
+
209
+ export interface TSFunctionType {
210
+ kind: 'function';
211
+ parameters: TSParameter[];
212
+ returnType: TypescriptType;
213
+ isAsync: boolean;
214
+ }
215
+
216
+ export interface TSParameter {
217
+ name: string;
218
+ type: TypescriptType;
219
+ optional: boolean;
220
+ rest: boolean;
221
+ }
222
+
223
+ export interface TSGenericType {
224
+ kind: 'generic';
225
+ name: string;
226
+ typeArgs: TypescriptType[];
227
+ }
228
+
229
+ export interface TSCustomType {
230
+ kind: 'custom';
231
+ name: string;
232
+ module?: string;
233
+ }
234
+
235
+ export interface TSLiteralType {
236
+ kind: 'literal';
237
+ value: string | number | boolean | null;
238
+ }
239
+
240
+ // Runtime and configuration types
241
+ export type RuntimeStrategy = 'pyodide' | 'node' | 'http' | 'auto';
242
+
243
+ export interface TywrapOptions {
244
+ pythonModules: Record<string, PythonModuleConfig>;
245
+ output: OutputConfig;
246
+ runtime: RuntimeConfig;
247
+ performance: PerformanceConfig;
248
+ development: DevelopmentConfig;
249
+ types?: TypeMappingConfig;
250
+ debug?: boolean;
251
+ }
252
+
253
+ export interface PythonModuleConfig {
254
+ version?: string;
255
+ runtime: RuntimeStrategy;
256
+ functions?: string[];
257
+ classes?: string[];
258
+ alias?: string;
259
+ typeHints: 'strict' | 'loose' | 'ignore';
260
+ watch?: boolean;
261
+ }
262
+
263
+ export interface OutputConfig {
264
+ dir: string;
265
+ format: 'esm' | 'cjs' | 'both';
266
+ declaration: boolean;
267
+ sourceMap: boolean;
268
+ annotatedJSDoc?: boolean;
269
+ }
270
+
271
+ export interface RuntimeConfig {
272
+ pyodide?: PyodideConfig;
273
+ node?: NodeConfig;
274
+ http?: HttpConfig;
275
+ }
276
+
277
+ export interface PyodideConfig {
278
+ indexURL?: string;
279
+ packages?: string[];
280
+ }
281
+
282
+ export interface NodeConfig {
283
+ pythonPath?: string;
284
+ virtualEnv?: string;
285
+ timeout?: number;
286
+ }
287
+
288
+ export interface HttpConfig {
289
+ baseURL: string;
290
+ timeout?: number;
291
+ headers?: Record<string, string>;
292
+ }
293
+
294
+ export interface PerformanceConfig {
295
+ caching: boolean;
296
+ batching: boolean;
297
+ compression: 'auto' | 'gzip' | 'brotli' | 'none';
298
+ }
299
+
300
+ export interface DevelopmentConfig {
301
+ hotReload: boolean;
302
+ sourceMap: boolean;
303
+ validation: 'runtime' | 'compile' | 'both' | 'none';
304
+ }
305
+
306
+ export type TypePreset = 'numpy' | 'pandas' | 'pydantic' | 'stdlib' | 'scipy' | 'torch' | 'sklearn';
307
+
308
+ export interface TypeMappingConfig {
309
+ presets?: TypePreset[];
310
+ }
311
+
312
+ export interface BridgeInfo {
313
+ protocol: string;
314
+ protocolVersion: number;
315
+ bridge: 'python-subprocess';
316
+ pythonVersion: string;
317
+ pid: number;
318
+ codecFallback: 'json' | 'none';
319
+ arrowAvailable: boolean;
320
+ instances: number;
321
+ }
322
+
323
+ // Analysis and generation results
324
+ export interface AnalysisResult {
325
+ module: PythonModule;
326
+ errors: AnalysisError[];
327
+ warnings: AnalysisWarning[];
328
+ dependencies: string[];
329
+ statistics: AnalysisStatistics;
330
+ }
331
+
332
+ export interface AnalysisError {
333
+ type: 'syntax' | 'import' | 'type' | 'unsupported';
334
+ message: string;
335
+ line?: number;
336
+ column?: number;
337
+ file?: string;
338
+ }
339
+
340
+ export interface AnalysisWarning {
341
+ type: 'missing-type' | 'deprecated' | 'performance' | 'compatibility';
342
+ message: string;
343
+ line?: number;
344
+ column?: number;
345
+ file?: string;
346
+ }
347
+
348
+ export interface AnalysisStatistics {
349
+ functionsAnalyzed: number;
350
+ classesAnalyzed: number;
351
+ typeHintsCoverage: number;
352
+ estimatedComplexity: number;
353
+ }
354
+
355
+ export interface GeneratedCode {
356
+ typescript: string;
357
+ declaration: string;
358
+ sourceMap?: string;
359
+ metadata: GenerationMetadata;
360
+ }
361
+
362
+ export interface GenerationMetadata {
363
+ generatedAt: Date;
364
+ sourceFiles: string[];
365
+ runtime: RuntimeStrategy;
366
+ optimizations: string[];
367
+ }
368
+
369
+ // Runtime bridge interface
370
+ export interface RuntimeExecution {
371
+ call<T = unknown>(
372
+ module: string,
373
+ functionName: string,
374
+ args: unknown[],
375
+ kwargs?: Record<string, unknown>
376
+ ): Promise<T>;
377
+
378
+ instantiate<T = unknown>(
379
+ module: string,
380
+ className: string,
381
+ args: unknown[],
382
+ kwargs?: Record<string, unknown>
383
+ ): Promise<T>;
384
+
385
+ callMethod<T = unknown>(
386
+ handle: string,
387
+ methodName: string,
388
+ args: unknown[],
389
+ kwargs?: Record<string, unknown>
390
+ ): Promise<T>;
391
+
392
+ disposeInstance(handle: string): Promise<void>;
393
+
394
+ dispose(): Promise<void>;
395
+ }
396
+
397
+ // Utility types
398
+ export type DeepReadonly<T> = {
399
+ readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
400
+ };
401
+
402
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
403
+
404
+ export type RequiredKeys<T> = {
405
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
406
+ }[keyof T];
407
+
408
+ export type OptionalKeys<T> = {
409
+ [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
410
+ }[keyof T];