@rpc-dart/trpc-adapter 0.1.4 → 0.2.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/dist/classify.js CHANGED
@@ -103,6 +103,8 @@ export class TypeClassifier {
103
103
  return 'BigInt';
104
104
  if (flags & ts.TypeFlags.Void)
105
105
  return 'void';
106
+ if (flags & ts.TypeFlags.Never)
107
+ return 'never';
106
108
  if (flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
107
109
  return { kind: 'unknown' };
108
110
  if (flags & ts.TypeFlags.Null || flags & ts.TypeFlags.Undefined)
package/dist/extract.js CHANGED
@@ -4,7 +4,7 @@ import { assembleContract, ExtractionFailure, } from '@rpc-dart/core';
4
4
  import { entryImportPath, buildHarness, harnessFileName, pathAlias } from './harness.js';
5
5
  import { probeRouter } from './probe.js';
6
6
  import { pascal, TypeClassificationError, TypeClassifier } from './classify.js';
7
- const GENERATOR = { name: 'rpc-dart', version: '0.1.0' };
7
+ const GENERATOR = { name: 'rpc-dart', version: '0.2.0' };
8
8
  export async function extractContract(options) {
9
9
  const tsconfigDir = path.dirname(options.tsconfigPath);
10
10
  const entryAbsolute = path.resolve(tsconfigDir, options.entryFile);
@@ -43,8 +43,9 @@ export async function extractContract(options) {
43
43
  : parsed.options.moduleResolution === ts.ModuleResolutionKind.NodeNext
44
44
  ? 'nodenext'
45
45
  : undefined;
46
+ const subscriptionPaths = new Set(probePaths.filter((p) => p.kind === 'subscription').map((p) => p.path));
46
47
  const harnessPath = path.join(tsconfigDir, harnessFileName());
47
- const harnessSource = buildHarness(entryImportPath(tsconfigDir, entryAbsolute, resolution), options.exportName, probePaths.map((p) => p.path));
48
+ const harnessSource = buildHarness(entryImportPath(tsconfigDir, entryAbsolute, resolution), options.exportName, probePaths.map((p) => p.path), subscriptionPaths);
48
49
  // 4. Program under the user's own tsconfig, harness overlaid in memory.
49
50
  // Extraction-neutral overrides: the in-memory program exists only to
50
51
  // answer type queries on the harness, so build/lint-only flags are
@@ -151,6 +152,13 @@ export async function extractContract(options) {
151
152
  access: p.meta['access'] === 'authenticated' ? 'authenticated' : 'public',
152
153
  extra: {},
153
154
  };
155
+ if (p.kind === 'subscription') {
156
+ // `tracked()` yields resolve to a true literal via the harness; without
157
+ // tracked events the client cannot resume, so the flag stays false.
158
+ const trackedType = typeFromAlias(harnessSf, checker, pathAlias(p.path, 'tracked'));
159
+ meta.extra['supportsLastEventId'] =
160
+ trackedType !== undefined && checker.typeToString(trackedType) === 'true';
161
+ }
154
162
  entries.push({ path: p.path, kind: p.kind, input, output, meta, docs: null });
155
163
  }
156
164
  classifier.currentProcedure = undefined;
package/dist/harness.d.ts CHANGED
@@ -4,12 +4,17 @@
4
4
  * utilities - never private internals. Per-path aliases force indexed-access
5
5
  * evaluation so deep conditional/mapped types resolve concretely, and make
6
6
  * per-procedure failures point at exactly one line.
7
+ *
8
+ * Subscription procedures get an extra unwrap layer: tRPC v11 subscription
9
+ * outputs are `AsyncGenerator<Y>` / `AsyncIterable<Y>` / `Observable<Y>` and
10
+ * tracked generators wrap each yield in `TrackedEnvelope<T>` ([id, data,
11
+ * symbol]), so the aliases resolve straight to the streamed item type Y.
7
12
  */
8
13
  export declare function harnessFileName(): string;
9
- export declare function pathAlias(path: string, role: 'in' | 'out'): string;
10
- export declare function buildHarness(entryImportPath: string, exportName: string, paths: string[]): string;
11
- /**
12
- * './router.ts' -> './router' (bundler-style), or explicit extensions under
14
+ export type HarnessAliasRole = 'in' | 'out' | 'tracked';
15
+ export declare function pathAlias(path: string, role: HarnessAliasRole): string;
16
+ export declare function buildHarness(entryImportPath: string, exportName: string, paths: string[], subscriptionPaths?: ReadonlySet<string>): string;
17
+ /** './router.ts' -> './router' (bundler-style), or explicit extensions under
13
18
  * node16/nodenext resolution, where extensionless relative imports are
14
19
  * illegal (TS5097) and the TS-standard specifiers (.js/.mjs/.cjs) resolve to
15
20
  * the .ts/.mts/.cts sources with or without allowImportingTsExtensions.
package/dist/harness.js CHANGED
@@ -4,6 +4,11 @@
4
4
  * utilities - never private internals. Per-path aliases force indexed-access
5
5
  * evaluation so deep conditional/mapped types resolve concretely, and make
6
6
  * per-procedure failures point at exactly one line.
7
+ *
8
+ * Subscription procedures get an extra unwrap layer: tRPC v11 subscription
9
+ * outputs are `AsyncGenerator<Y>` / `AsyncIterable<Y>` / `Observable<Y>` and
10
+ * tracked generators wrap each yield in `TrackedEnvelope<T>` ([id, data,
11
+ * symbol]), so the aliases resolve straight to the streamed item type Y.
7
12
  */
8
13
  export function harnessFileName() {
9
14
  return '__rpc_dart_harness__.ts';
@@ -12,14 +17,21 @@ export function pathAlias(path, role) {
12
17
  const segments = path.split('.').map((s) => s.replace(/[^A-Za-z0-9_]/g, '_'));
13
18
  return ['__p', ...segments, role].join('_');
14
19
  }
15
- export function buildHarness(entryImportPath, exportName, paths) {
20
+ export function buildHarness(entryImportPath, exportName, paths, subscriptionPaths = new Set()) {
16
21
  const aliases = paths
17
22
  .map((p) => {
18
23
  const access = p
19
24
  .split('.')
20
25
  .map((s) => `[${JSON.stringify(s)}]`)
21
26
  .join('');
22
- return `export type ${pathAlias(p, 'in')} = __rpc_dart_inputs${access};\nexport type ${pathAlias(p, 'out')} = __rpc_dart_outputs${access};`;
27
+ const lines = [`export type ${pathAlias(p, 'in')} = __rpc_dart_inputs${access};`];
28
+ if (subscriptionPaths.has(p)) {
29
+ lines.push(`export type ${pathAlias(p, 'out')} = __rpc_dart_unwrap_item<__rpc_dart_outputs${access}>;`, `export type ${pathAlias(p, 'tracked')} = __rpc_dart_is_tracked<__rpc_dart_outputs${access}>;`);
30
+ }
31
+ else {
32
+ lines.push(`export type ${pathAlias(p, 'out')} = __rpc_dart_outputs${access};`);
33
+ }
34
+ return lines.join('\n');
23
35
  })
24
36
  .join('\n');
25
37
  return `import type { ${exportName} } from ${JSON.stringify(entryImportPath)};
@@ -29,11 +41,28 @@ type __rpc_dart_router = typeof ${exportName};
29
41
  export type __rpc_dart_inputs = inferRouterInputs<__rpc_dart_router>;
30
42
  export type __rpc_dart_outputs = inferRouterOutputs<__rpc_dart_router>;
31
43
 
44
+ type __rpc_dart_unwrap_item<T> =
45
+ T extends { subscribe(observer: infer O): unknown }
46
+ ? O extends { next(value: infer Y): void } ? __rpc_dart_unwrap_tracked<Y> : never
47
+ : T extends AsyncIterable<infer Y> ? __rpc_dart_unwrap_tracked<Y> : T;
48
+ // tRPC v11 hands clients tracked events as either the branded tuple
49
+ // TrackedEnvelope<T> = [id, T, symbol] or its TrackedData<T> = { id, data }
50
+ // projection; both reduce to the payload T.
51
+ type __rpc_dart_unwrap_tracked<Y> =
52
+ Y extends readonly [string, infer D, symbol]
53
+ ? D
54
+ : Y extends { id: string; data: infer D } ? D : Y;
55
+ type __rpc_dart_is_tracked<T> =
56
+ T extends AsyncIterable<infer Y>
57
+ ? Y extends readonly [string, unknown, symbol]
58
+ ? true
59
+ : Y extends { id: string; data: unknown } ? true : false
60
+ : false;
61
+
32
62
  ${aliases}
33
63
  `;
34
64
  }
35
- /**
36
- * './router.ts' -> './router' (bundler-style), or explicit extensions under
65
+ /** './router.ts' -> './router' (bundler-style), or explicit extensions under
37
66
  * node16/nodenext resolution, where extensionless relative imports are
38
67
  * illegal (TS5097) and the TS-standard specifiers (.js/.mjs/.cjs) resolve to
39
68
  * the .ts/.mts/.cts sources with or without allowImportingTsExtensions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpc-dart/trpc-adapter",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "tRPC v11 extraction adapter: route probe, inference harness, and Contract IR normalizer.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "dependencies": {
12
- "@rpc-dart/core": "0.1.4",
12
+ "@rpc-dart/core": "0.2.0",
13
13
  "jiti": "^2.6.0",
14
14
  "typescript": "^5.9.0"
15
15
  },