tjs-lang 0.6.44 → 0.7.3
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/CLAUDE.md +85 -422
- package/README.md +15 -82
- package/bin/benchmarks.ts +7 -7
- package/bin/dev.ts +2 -1
- package/demo/autocomplete.test.ts +1 -1
- package/demo/docs.json +744 -48
- package/demo/src/demo-nav.ts +5 -5
- package/demo/src/index.ts +28 -36
- package/demo/src/module-sw.ts +1 -1
- package/demo/src/playground-shared.ts +17 -17
- package/demo/src/playground.ts +13 -1
- package/demo/src/style.ts +4 -1
- package/demo/src/tjs-playground.ts +5 -5
- package/demo/src/user-store.ts +2 -1
- package/demo/static/favicon.svg +17 -24
- package/demo/static/tosi-platform.json +9304 -0
- package/dist/index.js +158 -156
- package/dist/index.js.map +14 -13
- package/dist/scripts/compat-effect.d.ts +16 -0
- package/dist/scripts/compat-kysely.d.ts +13 -0
- package/dist/scripts/compat-radash.d.ts +13 -0
- package/dist/scripts/compat-superstruct.d.ts +13 -0
- package/dist/scripts/compat-ts-pattern.d.ts +13 -0
- package/dist/scripts/compat-zod.d.ts +12 -0
- package/dist/src/lang/emitters/from-ts.d.ts +1 -1
- package/dist/src/lang/emitters/js-tests.d.ts +4 -0
- package/dist/src/lang/emitters/js.d.ts +2 -2
- package/dist/src/lang/index.d.ts +1 -0
- package/dist/src/lang/json-schema.d.ts +40 -0
- package/dist/src/lang/parser-transforms.d.ts +14 -0
- package/dist/src/lang/runtime.d.ts +39 -6
- package/dist/src/types/Type.d.ts +5 -0
- package/dist/tjs-full.js +158 -156
- package/dist/tjs-full.js.map +14 -13
- package/dist/tjs-vm.js +44 -43
- package/dist/tjs-vm.js.map +5 -5
- package/docs/README.md +21 -20
- package/docs/WASM-QUICKSTART.md +283 -0
- package/docs/diagrams/architecture-shift.svg +117 -0
- package/docs/diagrams/compile-runtime.svg +130 -0
- package/docs/diagrams/icon-riff-1.svg +55 -0
- package/docs/diagrams/icon-riff-2.svg +62 -0
- package/docs/diagrams/icon-riff-3.svg +61 -0
- package/docs/diagrams/platform-overview.svg +114 -0
- package/docs/diagrams/safe-eval.svg +147 -0
- package/docs/eval-v4/arch-comparison.svg +277 -0
- package/docs/eval-v4/bundler-tree.svg +250 -0
- package/docs/eval-v4/http-lifecycle.svg +148 -0
- package/docs/function-predicate-design.md +8 -8
- package/docs/native-engine-integration.md +2 -2
- package/editors/codemirror/autocomplete.test.ts +29 -29
- package/package.json +10 -4
- package/src/cli/commands/convert.test.ts +11 -8
- package/src/cli/tjs.ts +1 -1
- package/src/lang/codegen.test.ts +117 -112
- package/src/lang/docs.test.ts +22 -22
- package/src/lang/docs.ts +5 -8
- package/src/lang/emitters/dts.test.ts +13 -13
- package/src/lang/emitters/from-ts.ts +36 -9
- package/src/lang/emitters/js-tests.ts +143 -28
- package/src/lang/emitters/js.ts +49 -28
- package/src/lang/features.test.ts +259 -43
- package/src/lang/from-ts.test.ts +3 -3
- package/src/lang/function-predicate.test.ts +1 -1
- package/src/lang/index.ts +8 -47
- package/src/lang/json-schema.test.ts +261 -0
- package/src/lang/json-schema.ts +167 -0
- package/src/lang/parser-params.ts +28 -44
- package/src/lang/parser-transforms.ts +255 -0
- package/src/lang/parser.test.ts +32 -13
- package/src/lang/parser.ts +49 -11
- package/src/lang/perf.test.ts +11 -11
- package/src/lang/roundtrip.test.ts +3 -3
- package/src/lang/runtime.test.ts +167 -0
- package/src/lang/runtime.ts +234 -46
- package/src/lang/transpiler.test.ts +21 -21
- package/src/lang/typescript-syntax.test.ts +11 -9
- package/src/types/Type.ts +38 -1
- package/src/use-cases/bootstrap.test.ts +7 -7
- package/src/use-cases/client-server.test.ts +1 -1
- package/src/use-cases/malicious-actor.test.ts +1 -1
- package/src/use-cases/rag-processor.test.ts +1 -1
- package/src/use-cases/sophisticated-agents.test.ts +2 -2
- package/src/use-cases/transpiler-llm.test.ts +1 -1
- package/src/use-cases/unbundled-imports.test.ts +9 -9
- package/tjs-lang.svg +17 -25
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Effect Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones Effect (the "final boss" of TypeScript complexity), transpiles
|
|
6
|
+
* its source using fromTS, and attempts to run its Vitest suite.
|
|
7
|
+
*
|
|
8
|
+
* Effect uses higher-kinded types, massive intersections, and the most
|
|
9
|
+
* advanced TypeScript patterns in the wild.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* bun scripts/compat-effect.ts
|
|
13
|
+
* bun scripts/compat-effect.ts --clean
|
|
14
|
+
* bun scripts/compat-effect.ts --test # Also run tests (requires pnpm)
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Kysely Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones Kysely, transpiles its TS source using TJS's fromTS.
|
|
6
|
+
* Kysely's tests require database connections so we only verify
|
|
7
|
+
* that all source files transpile without error.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* bun scripts/compat-kysely.ts
|
|
11
|
+
* bun scripts/compat-kysely.ts --clean
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Radash Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones Radash, transpiles its TypeScript source using TJS's fromTS,
|
|
6
|
+
* and runs Radash's own test suite to verify compatibility.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* bun scripts/compat-radash.ts # Direct mode (fromTS → JS)
|
|
10
|
+
* bun scripts/compat-radash.ts --full # Full pipeline (fromTS → TJS → JS)
|
|
11
|
+
* bun scripts/compat-radash.ts --clean # Remove clone and start fresh
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Superstruct Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones Superstruct, transpiles its TS source using TJS's fromTS,
|
|
6
|
+
* and runs Superstruct's own test suite to verify compatibility.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* bun scripts/compat-superstruct.ts # Direct mode (fromTS → JS)
|
|
10
|
+
* bun scripts/compat-superstruct.ts --full # Full pipeline (fromTS → TJS → JS)
|
|
11
|
+
* bun scripts/compat-superstruct.ts --clean # Remove clone and start fresh
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* ts-pattern Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones ts-pattern, transpiles its TS source using TJS's fromTS,
|
|
6
|
+
* and runs ts-pattern's own test suite to verify compatibility.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* bun scripts/compat-ts-pattern.ts # Direct mode (fromTS → JS)
|
|
10
|
+
* bun scripts/compat-ts-pattern.ts --full # Full pipeline (fromTS → TJS → JS)
|
|
11
|
+
* bun scripts/compat-ts-pattern.ts --clean # Remove clone and start fresh
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Zod Compatibility Test
|
|
4
|
+
*
|
|
5
|
+
* Clones Zod (monorepo), transpiles its TS source using TJS's fromTS,
|
|
6
|
+
* and runs Zod's own test suite to verify compatibility.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* bun scripts/compat-zod.ts # Direct mode (fromTS → JS)
|
|
10
|
+
* bun scripts/compat-zod.ts --clean # Remove clone and start fresh
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
@@ -49,6 +49,10 @@ interface SignatureTestInfo {
|
|
|
49
49
|
defaults?: Record<string, unknown>;
|
|
50
50
|
line: number;
|
|
51
51
|
isAsync?: boolean;
|
|
52
|
+
/** For class method tests: the class name */
|
|
53
|
+
className?: string;
|
|
54
|
+
/** For class method tests: args to pass to the first constructor */
|
|
55
|
+
constructorArgs?: unknown[];
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* Extract signature test info from source without executing
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Unlike the AST emitter (for AgentJS), this outputs executable JS code.
|
|
6
6
|
*
|
|
7
7
|
* Input:
|
|
8
|
-
* function greet(name: 'world')
|
|
8
|
+
* function greet(name: 'world'): '' {
|
|
9
9
|
* return `Hello, ${name}!`
|
|
10
10
|
* }
|
|
11
11
|
*
|
|
@@ -135,7 +135,7 @@ interface SafetyOptions {
|
|
|
135
135
|
unsafe?: boolean;
|
|
136
136
|
/** Function marked with (?) - always validate inputs */
|
|
137
137
|
safe?: boolean;
|
|
138
|
-
/** Return type safety: 'safe' (
|
|
138
|
+
/** Return type safety: 'safe' (:?) or 'unsafe' (:!) */
|
|
139
139
|
returnSafety?: 'safe' | 'unsafe';
|
|
140
140
|
}
|
|
141
141
|
/**
|
package/dist/src/lang/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { generateDTS, typeDescriptorToTS, type GenerateDTSOptions, } from './emi
|
|
|
30
30
|
export { fromTS, type FromTSOptions, type FromTSResult, } from './emitters/from-ts';
|
|
31
31
|
export * from './inference';
|
|
32
32
|
export { Schema } from './schema';
|
|
33
|
+
export { typeDescriptorToJSONSchema, exampleToJSONSchema, functionMetaToJSONSchema, type JSONSchemaObject, } from './json-schema';
|
|
33
34
|
export { MetadataCache, getGlobalCache, setGlobalCache } from './metadata-cache';
|
|
34
35
|
export { lint, type LintResult, type LintDiagnostic, type LintOptions, } from './linter';
|
|
35
36
|
export { generateDocs, generateDocsMarkdown, type DocResult, type DocItem, type FunctionTypeInfo, type ParamTypeInfo, } from './docs';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema generation from TJS TypeDescriptors and example values
|
|
3
|
+
*
|
|
4
|
+
* Converts TJS type information into standard JSON Schema (draft 2020-12).
|
|
5
|
+
*/
|
|
6
|
+
import type { TypeDescriptor } from './types';
|
|
7
|
+
export interface JSONSchemaObject {
|
|
8
|
+
type?: string | string[];
|
|
9
|
+
properties?: Record<string, JSONSchemaObject>;
|
|
10
|
+
items?: JSONSchemaObject | JSONSchemaObject[];
|
|
11
|
+
required?: string[];
|
|
12
|
+
additionalProperties?: boolean;
|
|
13
|
+
anyOf?: JSONSchemaObject[];
|
|
14
|
+
minimum?: number;
|
|
15
|
+
examples?: unknown[];
|
|
16
|
+
description?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert a TypeDescriptor to JSON Schema
|
|
21
|
+
*/
|
|
22
|
+
export declare function typeDescriptorToJSONSchema(td: TypeDescriptor): JSONSchemaObject;
|
|
23
|
+
/**
|
|
24
|
+
* Infer a JSON Schema from an example value (without going through TypeDescriptor)
|
|
25
|
+
*/
|
|
26
|
+
export declare function exampleToJSONSchema(value: unknown): JSONSchemaObject;
|
|
27
|
+
/**
|
|
28
|
+
* Generate JSON Schema for function parameters (as an object schema)
|
|
29
|
+
* and return type from __tjs metadata
|
|
30
|
+
*/
|
|
31
|
+
export declare function functionMetaToJSONSchema(meta: {
|
|
32
|
+
params: Record<string, any>;
|
|
33
|
+
returns?: {
|
|
34
|
+
type: any;
|
|
35
|
+
example?: any;
|
|
36
|
+
};
|
|
37
|
+
}): {
|
|
38
|
+
input: JSONSchemaObject;
|
|
39
|
+
output?: JSONSchemaObject;
|
|
40
|
+
};
|
|
@@ -295,3 +295,17 @@ export declare function validateNoDate(source: string): string;
|
|
|
295
295
|
export declare function transformConstBang(source: string): string;
|
|
296
296
|
export declare function validateNoVar(source: string): string;
|
|
297
297
|
export declare function validateNoEval(source: string): string;
|
|
298
|
+
/**
|
|
299
|
+
* Transform bang access (!.) to __tjs.bang() calls.
|
|
300
|
+
*
|
|
301
|
+
* x!.foo → __tjs.bang(x,'foo')
|
|
302
|
+
* x.y!.foo → __tjs.bang(x.y,'foo')
|
|
303
|
+
* fn()!.foo → __tjs.bang(fn(),'foo')
|
|
304
|
+
* arr[0]!.foo → __tjs.bang(arr[0],'foo')
|
|
305
|
+
* x!.foo!.bar → __tjs.bang(__tjs.bang(x,'foo'),'bar')
|
|
306
|
+
*
|
|
307
|
+
* If the source is null/undefined, returns MonadicError.
|
|
308
|
+
* If the source is a MonadicError, propagates it.
|
|
309
|
+
* Otherwise, performs a bare property access (throws as usual).
|
|
310
|
+
*/
|
|
311
|
+
export declare function transformBangAccess(source: string): string;
|
|
@@ -107,8 +107,18 @@ export interface TJSConfig {
|
|
|
107
107
|
safety?: SafetyLevel;
|
|
108
108
|
/** Require explicit return types (error if -> not specified) */
|
|
109
109
|
requireReturnTypes?: boolean;
|
|
110
|
-
/**
|
|
110
|
+
/** Track call stacks for error diagnostics (default: false).
|
|
111
|
+
* Useful for server-side logging and agent debugging without devtools.
|
|
112
|
+
* Uses a fixed ring buffer — no allocation pressure. */
|
|
113
|
+
callStacks?: boolean;
|
|
114
|
+
/** Ring buffer size for call stack tracking (default: 64) */
|
|
111
115
|
maxStackSize?: number;
|
|
116
|
+
/** Track recent type errors in a ring buffer (default: true).
|
|
117
|
+
* Zero cost on happy path — only writes when an error occurs.
|
|
118
|
+
* Lets you catch monadic errors that were silently ignored. */
|
|
119
|
+
trackErrors?: boolean;
|
|
120
|
+
/** Ring buffer size for error tracking (default: 64) */
|
|
121
|
+
maxErrors?: number;
|
|
112
122
|
/** Log type errors to console.error when they occur (default: false) */
|
|
113
123
|
logTypeErrors?: boolean;
|
|
114
124
|
/** Throw type errors instead of returning them (default: false).
|
|
@@ -137,22 +147,37 @@ export declare function configure(options: TJSConfig): void;
|
|
|
137
147
|
*/
|
|
138
148
|
export declare function getConfig(): TJSConfig;
|
|
139
149
|
/**
|
|
140
|
-
* Push a function onto the call stack
|
|
141
|
-
*
|
|
150
|
+
* Push a function onto the call stack ring buffer.
|
|
151
|
+
* Only tracks when callStacks or debug is enabled.
|
|
152
|
+
* O(1), no allocation.
|
|
142
153
|
*/
|
|
143
154
|
export declare function pushStack(name: string): void;
|
|
144
155
|
/**
|
|
145
|
-
* Pop a function from the call stack
|
|
156
|
+
* Pop a function from the call stack ring buffer.
|
|
157
|
+
* O(1), no allocation.
|
|
146
158
|
*/
|
|
147
159
|
export declare function popStack(): void;
|
|
148
160
|
/**
|
|
149
|
-
* Get current call stack snapshot
|
|
161
|
+
* Get current call stack snapshot (most recent entries, newest last)
|
|
150
162
|
*/
|
|
151
163
|
export declare function getStack(): string[];
|
|
164
|
+
/**
|
|
165
|
+
* Get recent type errors (newest last).
|
|
166
|
+
* Only tracks when trackErrors is enabled (default: true).
|
|
167
|
+
*/
|
|
168
|
+
export declare function errors(): MonadicError[];
|
|
169
|
+
/**
|
|
170
|
+
* Clear error history. Returns the cleared errors.
|
|
171
|
+
*/
|
|
172
|
+
export declare function clearErrors(): MonadicError[];
|
|
173
|
+
/**
|
|
174
|
+
* Total error count since last clear (may exceed buffer size).
|
|
175
|
+
*/
|
|
176
|
+
export declare function getErrorCount(): number;
|
|
152
177
|
/**
|
|
153
178
|
* Reset runtime state to defaults
|
|
154
179
|
*
|
|
155
|
-
* Resets: config, callStack, unsafeDepth
|
|
180
|
+
* Resets: config, callStack, errors, unsafeDepth
|
|
156
181
|
* Use this in test teardown to prevent state leaking between tests.
|
|
157
182
|
*/
|
|
158
183
|
export declare function resetRuntime(): void;
|
|
@@ -338,6 +363,7 @@ export declare function createRuntime(): {
|
|
|
338
363
|
MonadicError: typeof MonadicError;
|
|
339
364
|
typeError: (path: string, expected: string, value: unknown) => MonadicError;
|
|
340
365
|
isMonadicError: typeof isMonadicError;
|
|
366
|
+
bang: (obj: unknown, prop: string) => unknown;
|
|
341
367
|
isError: typeof isError;
|
|
342
368
|
error: (message: string, details?: Partial<Omit<TJSError, "$error" | "message">>) => TJSError;
|
|
343
369
|
composeErrors: typeof composeErrors;
|
|
@@ -349,11 +375,15 @@ export declare function createRuntime(): {
|
|
|
349
375
|
wrapClass: typeof wrapClass;
|
|
350
376
|
compareVersions: typeof compareVersions;
|
|
351
377
|
versionsCompatible: typeof versionsCompatible;
|
|
378
|
+
createRuntime: typeof createRuntime;
|
|
352
379
|
configure: (options: TJSConfig) => void;
|
|
353
380
|
getConfig: () => TJSConfig;
|
|
354
381
|
pushStack: (name: string) => void;
|
|
355
382
|
popStack: () => void;
|
|
356
383
|
getStack: () => string[];
|
|
384
|
+
errors: () => MonadicError[];
|
|
385
|
+
clearErrors: () => MonadicError[];
|
|
386
|
+
getErrorCount: () => number;
|
|
357
387
|
resetRuntime: () => void;
|
|
358
388
|
enterUnsafe: () => void;
|
|
359
389
|
exitUnsafe: () => void;
|
|
@@ -418,6 +448,9 @@ export declare const runtime: {
|
|
|
418
448
|
pushStack: typeof pushStack;
|
|
419
449
|
popStack: typeof popStack;
|
|
420
450
|
getStack: typeof getStack;
|
|
451
|
+
errors: typeof errors;
|
|
452
|
+
clearErrors: typeof clearErrors;
|
|
453
|
+
getErrorCount: typeof getErrorCount;
|
|
421
454
|
resetRuntime: typeof resetRuntime;
|
|
422
455
|
enterUnsafe: typeof enterUnsafe;
|
|
423
456
|
exitUnsafe: typeof exitUnsafe;
|
package/dist/src/types/Type.d.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* ZipCode.description // '5-digit US zip code'
|
|
17
17
|
*/
|
|
18
18
|
import { type Base } from 'tosijs-schema';
|
|
19
|
+
import { type JSONSchemaObject } from '../lang/json-schema';
|
|
19
20
|
/** JSON Schema object type (simplified) */
|
|
20
21
|
type JSONSchema = {
|
|
21
22
|
type?: string;
|
|
@@ -42,6 +43,10 @@ export interface RuntimeType<T = unknown> {
|
|
|
42
43
|
readonly examples?: T[];
|
|
43
44
|
/** Default value (for instantiation) */
|
|
44
45
|
readonly default?: T;
|
|
46
|
+
/** Generate JSON Schema for this type */
|
|
47
|
+
toJSONSchema(): JSONSchemaObject;
|
|
48
|
+
/** Strip a value down to only the fields matching this type's schema */
|
|
49
|
+
strip(value: unknown): unknown;
|
|
45
50
|
/** Brand for type identification */
|
|
46
51
|
readonly __runtimeType: true;
|
|
47
52
|
}
|