@elliots/typical-compiler 0.2.3 → 0.2.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elliot Shepherd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProjectHandle, TransformResult } from './types.js';
1
+ import type { ProjectHandle, TransformResult, AnalyseResult } from './types.js';
2
2
  export interface TypicalCompilerOptions {
3
3
  /** Path to the typical binary. If not provided, uses the bundled binary. */
4
4
  binaryPath?: string;
@@ -16,8 +16,20 @@ export declare class TypicalCompiler {
16
16
  start(): Promise<void>;
17
17
  close(): Promise<void>;
18
18
  loadProject(configFileName: string): Promise<ProjectHandle>;
19
- transformFile(project: ProjectHandle | string, fileName: string, ignoreTypes?: string[], maxGeneratedFunctions?: number, reusableValidators?: 'auto' | 'never' | 'always'): Promise<TransformResult>;
19
+ transformFile(project: ProjectHandle | string, fileName: string, ignoreTypes?: string[], maxGeneratedFunctions?: number): Promise<TransformResult>;
20
20
  release(handle: ProjectHandle | string): Promise<void>;
21
+ /**
22
+ * Analyse a file for validation points without transforming it.
23
+ * Returns information about which parameters, returns, and casts will be validated.
24
+ * Used by the VSCode extension to show validation indicators.
25
+ *
26
+ * @param project - Project handle or ID
27
+ * @param fileName - Path to the file to analyse
28
+ * @param content - Optional file content for live updates (uses disk version if not provided)
29
+ * @param ignoreTypes - Optional glob patterns for types to skip
30
+ * @returns Analysis result with validation items
31
+ */
32
+ analyseFile(project: ProjectHandle | string, fileName: string, content?: string, ignoreTypes?: string[]): Promise<AnalyseResult>;
21
33
  /**
22
34
  * Transform a standalone TypeScript source string.
23
35
  * Creates a temporary project to enable type checking.
@@ -30,7 +42,6 @@ export declare class TypicalCompiler {
30
42
  transformSource(fileName: string, source: string, options?: {
31
43
  ignoreTypes?: string[];
32
44
  maxGeneratedFunctions?: number;
33
- reusableValidators?: 'auto' | 'never' | 'always';
34
45
  }): Promise<TransformResult>;
35
46
  private request;
36
47
  private handleData;
package/dist/client.js CHANGED
@@ -3,6 +3,7 @@ import { join, dirname } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { createRequire } from 'node:module';
5
5
  import { encodeRequest, decodeResponse } from './protocol.js';
6
+ import { existsSync } from 'node:fs';
6
7
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
8
  const require = createRequire(import.meta.url);
8
9
  const debug = process.env.DEBUG === '1';
@@ -12,17 +13,13 @@ function debugLog(...args) {
12
13
  }
13
14
  }
14
15
  function getBinaryPath() {
15
- // try local binary first (for development)
16
- const localBinPath = join(__dirname, '..', 'bin', 'typical');
17
- try {
18
- require('fs').accessSync(localBinPath);
19
- debugLog(`[CLIENT] Using local binary at ${localBinPath}`);
20
- return localBinPath;
16
+ // use bin/typical in development
17
+ const devPath = join(__dirname, '../bin/typical');
18
+ if (existsSync(devPath)) {
19
+ debugLog(`[CLIENT] Using development binary at ${devPath}`);
20
+ return devPath;
21
21
  }
22
- catch {
23
- // continue to platform-specific package
24
- }
25
- // Then use platform-specific package
22
+ // Find platform-specific package
26
23
  const platform = process.platform; // darwin, linux, win32
27
24
  const arch = process.arch; // arm64, x64
28
25
  const pkgName = `@elliots/typical-compiler-${platform}-${arch}`;
@@ -83,20 +80,39 @@ export class TypicalCompiler {
83
80
  async loadProject(configFileName) {
84
81
  return this.request('loadProject', { configFileName });
85
82
  }
86
- async transformFile(project, fileName, ignoreTypes, maxGeneratedFunctions, reusableValidators) {
83
+ async transformFile(project, fileName, ignoreTypes, maxGeneratedFunctions) {
87
84
  const projectId = typeof project === 'string' ? project : project.id;
88
85
  return this.request('transformFile', {
89
86
  project: projectId,
90
87
  fileName,
91
88
  ignoreTypes,
92
89
  maxGeneratedFunctions,
93
- reusableValidators,
94
90
  });
95
91
  }
96
92
  async release(handle) {
97
93
  const id = typeof handle === 'string' ? handle : handle.id;
98
94
  await this.request('release', id);
99
95
  }
96
+ /**
97
+ * Analyse a file for validation points without transforming it.
98
+ * Returns information about which parameters, returns, and casts will be validated.
99
+ * Used by the VSCode extension to show validation indicators.
100
+ *
101
+ * @param project - Project handle or ID
102
+ * @param fileName - Path to the file to analyse
103
+ * @param content - Optional file content for live updates (uses disk version if not provided)
104
+ * @param ignoreTypes - Optional glob patterns for types to skip
105
+ * @returns Analysis result with validation items
106
+ */
107
+ async analyseFile(project, fileName, content, ignoreTypes) {
108
+ const projectId = typeof project === 'string' ? project : project.id;
109
+ return this.request('analyseFile', {
110
+ project: projectId,
111
+ fileName,
112
+ content,
113
+ ignoreTypes,
114
+ });
115
+ }
100
116
  /**
101
117
  * Transform a standalone TypeScript source string.
102
118
  * Creates a temporary project to enable type checking.
@@ -112,7 +128,6 @@ export class TypicalCompiler {
112
128
  source,
113
129
  ignoreTypes: options?.ignoreTypes,
114
130
  maxGeneratedFunctions: options?.maxGeneratedFunctions,
115
- reusableValidators: options?.reusableValidators,
116
131
  });
117
132
  }
118
133
  async request(method, payload) {
package/dist/types.d.ts CHANGED
@@ -16,3 +16,27 @@ export interface TransformResult {
16
16
  code: string;
17
17
  sourceMap?: RawSourceMap;
18
18
  }
19
+ /** Represents a single validation point in the source code */
20
+ export interface ValidationItem {
21
+ /** 1-based line number */
22
+ startLine: number;
23
+ /** 0-based column */
24
+ startColumn: number;
25
+ /** 1-based line number */
26
+ endLine: number;
27
+ /** 0-based column */
28
+ endColumn: number;
29
+ /** Type of validation: "parameter", "return", "cast", "json-parse", "json-stringify" */
30
+ kind: 'parameter' | 'return' | 'cast' | 'json-parse' | 'json-stringify';
31
+ /** Name of the item being validated (param name, "return value", or expression text) */
32
+ name: string;
33
+ /** Whether the item will be validated or skipped */
34
+ status: 'validated' | 'skipped';
35
+ /** Human-readable type string */
36
+ typeString: string;
37
+ /** Reason for skipping (when status is "skipped") */
38
+ skipReason?: string;
39
+ }
40
+ export interface AnalyseResult {
41
+ items: ValidationItem[];
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliots/typical-compiler",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "TypeScript compiler powered by tsgo for typical validation",
5
5
  "keywords": [
6
6
  "compiler",
@@ -26,16 +26,16 @@
26
26
  "typescript": "^5.7.0"
27
27
  },
28
28
  "optionalDependencies": {
29
- "@elliots/typical-compiler-darwin-arm64": "0.2.3",
30
- "@elliots/typical-compiler-darwin-x64": "0.2.3",
31
- "@elliots/typical-compiler-linux-arm64": "0.2.3",
32
- "@elliots/typical-compiler-linux-x64": "0.2.3",
33
- "@elliots/typical-compiler-win32-arm64": "0.2.3",
34
- "@elliots/typical-compiler-win32-x64": "0.2.3"
29
+ "@elliots/typical-compiler-darwin-arm64": "0.2.4",
30
+ "@elliots/typical-compiler-darwin-x64": "0.2.4",
31
+ "@elliots/typical-compiler-linux-arm64": "0.2.4",
32
+ "@elliots/typical-compiler-linux-x64": "0.2.4",
33
+ "@elliots/typical-compiler-win32-arm64": "0.2.4",
34
+ "@elliots/typical-compiler-win32-x64": "0.2.4"
35
35
  },
36
36
  "scripts": {
37
- "build": "tsc",
38
- "build:go": "./go/scripts/sync-shims.sh && cd go && go build -o ../bin/typical ./cmd/typical",
39
- "test": "npx tsx test/e2e.ts"
37
+ "build": "npm run build:ts && npm run build:go",
38
+ "build:ts": "tsc",
39
+ "build:go": "./go/scripts/sync-shims.sh && cd go && go build -o ../bin/typical ./cmd/typical"
40
40
  }
41
41
  }