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.
Files changed (86) hide show
  1. package/CLAUDE.md +85 -422
  2. package/README.md +15 -82
  3. package/bin/benchmarks.ts +7 -7
  4. package/bin/dev.ts +2 -1
  5. package/demo/autocomplete.test.ts +1 -1
  6. package/demo/docs.json +744 -48
  7. package/demo/src/demo-nav.ts +5 -5
  8. package/demo/src/index.ts +28 -36
  9. package/demo/src/module-sw.ts +1 -1
  10. package/demo/src/playground-shared.ts +17 -17
  11. package/demo/src/playground.ts +13 -1
  12. package/demo/src/style.ts +4 -1
  13. package/demo/src/tjs-playground.ts +5 -5
  14. package/demo/src/user-store.ts +2 -1
  15. package/demo/static/favicon.svg +17 -24
  16. package/demo/static/tosi-platform.json +9304 -0
  17. package/dist/index.js +158 -156
  18. package/dist/index.js.map +14 -13
  19. package/dist/scripts/compat-effect.d.ts +16 -0
  20. package/dist/scripts/compat-kysely.d.ts +13 -0
  21. package/dist/scripts/compat-radash.d.ts +13 -0
  22. package/dist/scripts/compat-superstruct.d.ts +13 -0
  23. package/dist/scripts/compat-ts-pattern.d.ts +13 -0
  24. package/dist/scripts/compat-zod.d.ts +12 -0
  25. package/dist/src/lang/emitters/from-ts.d.ts +1 -1
  26. package/dist/src/lang/emitters/js-tests.d.ts +4 -0
  27. package/dist/src/lang/emitters/js.d.ts +2 -2
  28. package/dist/src/lang/index.d.ts +1 -0
  29. package/dist/src/lang/json-schema.d.ts +40 -0
  30. package/dist/src/lang/parser-transforms.d.ts +14 -0
  31. package/dist/src/lang/runtime.d.ts +39 -6
  32. package/dist/src/types/Type.d.ts +5 -0
  33. package/dist/tjs-full.js +158 -156
  34. package/dist/tjs-full.js.map +14 -13
  35. package/dist/tjs-vm.js +44 -43
  36. package/dist/tjs-vm.js.map +5 -5
  37. package/docs/README.md +21 -20
  38. package/docs/WASM-QUICKSTART.md +283 -0
  39. package/docs/diagrams/architecture-shift.svg +117 -0
  40. package/docs/diagrams/compile-runtime.svg +130 -0
  41. package/docs/diagrams/icon-riff-1.svg +55 -0
  42. package/docs/diagrams/icon-riff-2.svg +62 -0
  43. package/docs/diagrams/icon-riff-3.svg +61 -0
  44. package/docs/diagrams/platform-overview.svg +114 -0
  45. package/docs/diagrams/safe-eval.svg +147 -0
  46. package/docs/eval-v4/arch-comparison.svg +277 -0
  47. package/docs/eval-v4/bundler-tree.svg +250 -0
  48. package/docs/eval-v4/http-lifecycle.svg +148 -0
  49. package/docs/function-predicate-design.md +8 -8
  50. package/docs/native-engine-integration.md +2 -2
  51. package/editors/codemirror/autocomplete.test.ts +29 -29
  52. package/package.json +10 -4
  53. package/src/cli/commands/convert.test.ts +11 -8
  54. package/src/cli/tjs.ts +1 -1
  55. package/src/lang/codegen.test.ts +117 -112
  56. package/src/lang/docs.test.ts +22 -22
  57. package/src/lang/docs.ts +5 -8
  58. package/src/lang/emitters/dts.test.ts +13 -13
  59. package/src/lang/emitters/from-ts.ts +36 -9
  60. package/src/lang/emitters/js-tests.ts +143 -28
  61. package/src/lang/emitters/js.ts +49 -28
  62. package/src/lang/features.test.ts +259 -43
  63. package/src/lang/from-ts.test.ts +3 -3
  64. package/src/lang/function-predicate.test.ts +1 -1
  65. package/src/lang/index.ts +8 -47
  66. package/src/lang/json-schema.test.ts +261 -0
  67. package/src/lang/json-schema.ts +167 -0
  68. package/src/lang/parser-params.ts +28 -44
  69. package/src/lang/parser-transforms.ts +255 -0
  70. package/src/lang/parser.test.ts +32 -13
  71. package/src/lang/parser.ts +49 -11
  72. package/src/lang/perf.test.ts +11 -11
  73. package/src/lang/roundtrip.test.ts +3 -3
  74. package/src/lang/runtime.test.ts +167 -0
  75. package/src/lang/runtime.ts +234 -46
  76. package/src/lang/transpiler.test.ts +21 -21
  77. package/src/lang/typescript-syntax.test.ts +11 -9
  78. package/src/types/Type.ts +38 -1
  79. package/src/use-cases/bootstrap.test.ts +7 -7
  80. package/src/use-cases/client-server.test.ts +1 -1
  81. package/src/use-cases/malicious-actor.test.ts +1 -1
  82. package/src/use-cases/rag-processor.test.ts +1 -1
  83. package/src/use-cases/sophisticated-agents.test.ts +2 -2
  84. package/src/use-cases/transpiler-llm.test.ts +1 -1
  85. package/src/use-cases/unbundled-imports.test.ts +9 -9
  86. 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 {};
@@ -15,7 +15,7 @@
15
15
  * }
16
16
  *
17
17
  * // Output TJS:
18
- * function greet(name: '', age = 0) -> '' {
18
+ * function greet(name: '', age = 0): '' {
19
19
  * return `Hello, ${name}!`
20
20
  * }
21
21
  *
@@ -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' (-?) or 'unsafe' (-!) */
138
+ /** Return type safety: 'safe' (:?) or 'unsafe' (:!) */
139
139
  returnSafety?: 'safe' | 'unsafe';
140
140
  }
141
141
  /**
@@ -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
- /** Maximum call stack size to prevent memory issues (default: 100) */
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 (debug mode only)
141
- * Respects maxStackSize to prevent unbounded memory growth
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 (debug mode only)
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;
@@ -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
  }