tywrap 0.3.0 → 0.5.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.
- package/README.md +40 -5
- package/dist/cli.js +24 -6
- package/dist/cli.js.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +19 -13
- package/dist/config/index.js.map +1 -1
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +0 -1
- package/dist/core/analyzer.js.map +1 -1
- package/dist/dev.d.ts +57 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +743 -0
- package/dist/dev.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/runtime/base.d.ts +7 -7
- package/dist/runtime/base.js +8 -8
- package/dist/runtime/bounded-context.d.ts +15 -31
- package/dist/runtime/bounded-context.d.ts.map +1 -1
- package/dist/runtime/bounded-context.js +16 -15
- package/dist/runtime/bounded-context.js.map +1 -1
- package/dist/runtime/http.d.ts +24 -5
- package/dist/runtime/http.d.ts.map +1 -1
- package/dist/runtime/http.js +57 -12
- package/dist/runtime/http.js.map +1 -1
- package/dist/runtime/node.d.ts +33 -7
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +144 -120
- package/dist/runtime/node.js.map +1 -1
- package/dist/runtime/optimized-node.d.ts +5 -4
- package/dist/runtime/optimized-node.d.ts.map +1 -1
- package/dist/runtime/optimized-node.js +5 -4
- package/dist/runtime/optimized-node.js.map +1 -1
- package/dist/runtime/pooled-transport.d.ts +2 -18
- package/dist/runtime/pooled-transport.d.ts.map +1 -1
- package/dist/runtime/pooled-transport.js +2 -29
- package/dist/runtime/pooled-transport.js.map +1 -1
- package/dist/runtime/process-io.d.ts +2 -18
- package/dist/runtime/process-io.d.ts.map +1 -1
- package/dist/runtime/process-io.js +3 -30
- package/dist/runtime/process-io.js.map +1 -1
- package/dist/runtime/pyodide-bootstrap-core.generated.d.ts +12 -0
- package/dist/runtime/pyodide-bootstrap-core.generated.d.ts.map +1 -0
- package/dist/runtime/pyodide-bootstrap-core.generated.js +12 -0
- package/dist/runtime/pyodide-bootstrap-core.generated.js.map +1 -0
- package/dist/runtime/pyodide-io.d.ts +7 -37
- package/dist/runtime/pyodide-io.d.ts.map +1 -1
- package/dist/runtime/pyodide-io.js +90 -214
- package/dist/runtime/pyodide-io.js.map +1 -1
- package/dist/runtime/pyodide.d.ts +25 -5
- package/dist/runtime/pyodide.d.ts.map +1 -1
- package/dist/runtime/pyodide.js +59 -10
- package/dist/runtime/pyodide.js.map +1 -1
- package/dist/runtime/{bridge-protocol.d.ts → rpc-client.d.ts} +59 -46
- package/dist/runtime/rpc-client.d.ts.map +1 -0
- package/dist/runtime/{bridge-protocol.js → rpc-client.js} +60 -42
- package/dist/runtime/rpc-client.js.map +1 -0
- package/dist/runtime/worker-pool.d.ts +8 -20
- package/dist/runtime/worker-pool.d.ts.map +1 -1
- package/dist/runtime/worker-pool.js +58 -59
- package/dist/runtime/worker-pool.js.map +1 -1
- package/dist/types/index.d.ts +8 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/tywrap.d.ts +6 -0
- package/dist/tywrap.d.ts.map +1 -1
- package/dist/tywrap.js +10 -3
- package/dist/tywrap.js.map +1 -1
- package/package.json +22 -18
- package/runtime/__pycache__/safe_codec.cpython-311.pyc +0 -0
- package/runtime/__pycache__/tywrap_bridge_core.cpython-311.pyc +0 -0
- package/runtime/python_bridge.py +85 -702
- package/runtime/safe_codec.py +10 -2
- package/runtime/tywrap_bridge_core.py +875 -0
- package/src/cli.ts +27 -6
- package/src/config/index.ts +28 -15
- package/src/core/analyzer.ts +1 -2
- package/src/dev.ts +983 -0
- package/src/index.ts +7 -7
- package/src/runtime/base.ts +8 -8
- package/src/runtime/bounded-context.ts +17 -56
- package/src/runtime/http.ts +85 -13
- package/src/runtime/node.ts +172 -178
- package/src/runtime/optimized-node.ts +5 -4
- package/src/runtime/pooled-transport.ts +2 -57
- package/src/runtime/process-io.ts +3 -55
- package/src/runtime/pyodide-bootstrap-core.generated.ts +12 -0
- package/src/runtime/pyodide-io.ts +92 -243
- package/src/runtime/pyodide.ts +87 -10
- package/src/runtime/{bridge-protocol.ts → rpc-client.ts} +76 -49
- package/src/runtime/worker-pool.ts +67 -88
- package/src/types/index.ts +20 -12
- package/src/tywrap.ts +17 -3
- package/dist/runtime/bridge-core.d.ts +0 -65
- package/dist/runtime/bridge-core.d.ts.map +0 -1
- package/dist/runtime/bridge-core.js +0 -379
- package/dist/runtime/bridge-core.js.map +0 -1
- package/dist/runtime/bridge-protocol.d.ts.map +0 -1
- package/dist/runtime/bridge-protocol.js.map +0 -1
- package/src/runtime/bridge-core.ts +0 -494
package/src/cli.ts
CHANGED
|
@@ -287,7 +287,9 @@ async function main(): Promise<void> {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
const res = await generate(options, { check: argv.check });
|
|
290
|
+
const failures = res.failures ?? [];
|
|
290
291
|
const warnings = res.warnings ?? [];
|
|
292
|
+
const hasFailures = failures.length > 0;
|
|
291
293
|
const moduleCount = Object.keys(options.pythonModules ?? {}).length;
|
|
292
294
|
|
|
293
295
|
const emitWarnings = (): void => {
|
|
@@ -301,24 +303,43 @@ async function main(): Promise<void> {
|
|
|
301
303
|
process.stderr.write('\n');
|
|
302
304
|
};
|
|
303
305
|
|
|
306
|
+
const emitFailures = (): void => {
|
|
307
|
+
if (failures.length === 0) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
process.stderr.write(`Failures (count ${failures.length}):\n`);
|
|
311
|
+
for (const failure of failures) {
|
|
312
|
+
process.stderr.write(`- ${failure.message}\n`);
|
|
313
|
+
}
|
|
314
|
+
process.stderr.write('\n');
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
emitWarnings();
|
|
318
|
+
|
|
304
319
|
if (argv.check) {
|
|
320
|
+
if (hasFailures) {
|
|
321
|
+
emitFailures();
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
|
|
305
325
|
const outOfDate = res.outOfDate ?? [];
|
|
306
326
|
if (outOfDate.length === 0) {
|
|
307
|
-
emitWarnings();
|
|
308
327
|
process.stdout.write('Generated wrappers are up to date.\n');
|
|
309
328
|
} else {
|
|
310
|
-
emitWarnings();
|
|
311
329
|
process.stderr.write('Generated wrappers are out of date:\n');
|
|
312
330
|
for (const file of outOfDate) {
|
|
313
331
|
process.stderr.write(`- ${file}\n`);
|
|
314
332
|
}
|
|
315
333
|
process.stderr.write('\nRun `tywrap generate` to update.\n');
|
|
316
|
-
if (!(argv.failOnWarn &&
|
|
334
|
+
if (!(argv.failOnWarn && warnings.length > 0)) {
|
|
317
335
|
process.exit(3);
|
|
318
336
|
}
|
|
319
337
|
}
|
|
320
338
|
} else {
|
|
321
|
-
|
|
339
|
+
if (hasFailures) {
|
|
340
|
+
emitFailures();
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
322
343
|
|
|
323
344
|
const written = res.written ?? [];
|
|
324
345
|
if (written.length === 0) {
|
|
@@ -355,9 +376,9 @@ async function main(): Promise<void> {
|
|
|
355
376
|
process.stdout.write(`- ${file}\n`);
|
|
356
377
|
}
|
|
357
378
|
}
|
|
358
|
-
if (argv.failOnWarn &&
|
|
379
|
+
if (argv.failOnWarn && warnings.length > 0) {
|
|
359
380
|
log.error(
|
|
360
|
-
`Warnings encountered (count ${
|
|
381
|
+
`Warnings encountered (count ${warnings.length}). Failing due to --fail-on-warn.`
|
|
361
382
|
);
|
|
362
383
|
process.exit(2);
|
|
363
384
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -17,7 +17,6 @@ import type {
|
|
|
17
17
|
OutputConfig,
|
|
18
18
|
RuntimeConfig,
|
|
19
19
|
PerformanceConfig,
|
|
20
|
-
DevelopmentConfig,
|
|
21
20
|
} from '../types/index.js';
|
|
22
21
|
import { getDefaultPythonPath } from '../utils/python.js';
|
|
23
22
|
|
|
@@ -48,11 +47,16 @@ const DEFAULT_CONFIG: ResolvedTywrapConfig = {
|
|
|
48
47
|
output: { dir: './generated', format: 'esm', declaration: false, sourceMap: false },
|
|
49
48
|
runtime: { node: { pythonPath: getDefaultPythonPath(), timeout: 30000 } },
|
|
50
49
|
performance: { caching: false, batching: false, compression: 'none' },
|
|
51
|
-
development: { hotReload: false, sourceMap: false, validation: 'none' },
|
|
52
50
|
types: { presets: [] },
|
|
53
51
|
debug: false,
|
|
54
52
|
};
|
|
55
53
|
|
|
54
|
+
const LEGACY_DEVELOPMENT_MESSAGE =
|
|
55
|
+
'Legacy config field "development" is no longer supported. Use createBridgeReloader() or startNodeWatchSession() from "tywrap/dev" instead.';
|
|
56
|
+
|
|
57
|
+
const LEGACY_MODULE_WATCH_MESSAGE =
|
|
58
|
+
'Legacy config field "pythonModules.<module>.watch" is no longer supported. Use startNodeWatchSession() from "tywrap/dev" instead.';
|
|
59
|
+
|
|
56
60
|
/**
|
|
57
61
|
* Recursively merge two configuration objects. Arrays are overwritten by
|
|
58
62
|
* overrides instead of concatenated.
|
|
@@ -89,17 +93,38 @@ function safeExists(path: string): boolean {
|
|
|
89
93
|
return existsSync(path);
|
|
90
94
|
}
|
|
91
95
|
|
|
96
|
+
function detectLegacyFields(config: TywrapConfig): void {
|
|
97
|
+
const rawConfig = config as unknown as Record<string, unknown>;
|
|
98
|
+
if (Object.prototype.hasOwnProperty.call(rawConfig, 'development')) {
|
|
99
|
+
throw new Error(LEGACY_DEVELOPMENT_MESSAGE);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const pythonModules = rawConfig.pythonModules;
|
|
103
|
+
if (!isPlainObject(pythonModules)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const moduleConfig of Object.values(pythonModules)) {
|
|
108
|
+
if (
|
|
109
|
+
isPlainObject(moduleConfig) &&
|
|
110
|
+
Object.prototype.hasOwnProperty.call(moduleConfig, 'watch')
|
|
111
|
+
) {
|
|
112
|
+
throw new Error(LEGACY_MODULE_WATCH_MESSAGE);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
92
117
|
/**
|
|
93
118
|
* Validate configuration values and throw user-friendly errors when invalid.
|
|
94
119
|
*/
|
|
95
120
|
function validateConfig(config: ResolvedTywrapConfig): void {
|
|
121
|
+
detectLegacyFields(config);
|
|
96
122
|
const allowedTopLevel = new Set([
|
|
97
123
|
'pythonModules',
|
|
98
124
|
'pythonImportPath',
|
|
99
125
|
'output',
|
|
100
126
|
'runtime',
|
|
101
127
|
'performance',
|
|
102
|
-
'development',
|
|
103
128
|
'types',
|
|
104
129
|
'debug',
|
|
105
130
|
]);
|
|
@@ -153,18 +178,6 @@ function validateConfig(config: ResolvedTywrapConfig): void {
|
|
|
153
178
|
throw new Error(`performance.compression must be one of ${validCompression.join(', ')}`);
|
|
154
179
|
}
|
|
155
180
|
|
|
156
|
-
const dev: DevelopmentConfig = config.development;
|
|
157
|
-
if (typeof dev.hotReload !== 'boolean') {
|
|
158
|
-
throw new Error('development.hotReload must be a boolean');
|
|
159
|
-
}
|
|
160
|
-
if (typeof dev.sourceMap !== 'boolean') {
|
|
161
|
-
throw new Error('development.sourceMap must be a boolean');
|
|
162
|
-
}
|
|
163
|
-
const validValidation = ['runtime', 'compile', 'both', 'none'];
|
|
164
|
-
if (!validValidation.includes(dev.validation)) {
|
|
165
|
-
throw new Error(`development.validation must be one of ${validValidation.join(', ')}`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
181
|
if (config.types) {
|
|
169
182
|
const presets = config.types.presets;
|
|
170
183
|
const validPresets = new Set([
|
package/src/core/analyzer.ts
CHANGED
|
@@ -26,8 +26,7 @@ import { getComponentLogger } from '../utils/logger.js';
|
|
|
26
26
|
const log = getComponentLogger('Analyzer');
|
|
27
27
|
|
|
28
28
|
const UNKNOWN_TYPE: PythonType = { kind: 'custom', name: 'Any', module: 'typing' };
|
|
29
|
-
|
|
30
|
-
const PYTHON_LANGUAGE = Python as unknown as Parser.Language;
|
|
29
|
+
const PYTHON_LANGUAGE = Python as unknown as Parameters<Parser['setLanguage']>[0];
|
|
31
30
|
|
|
32
31
|
export class PyAnalyzer {
|
|
33
32
|
private parser: Parser;
|