@adhd/apigen-core-client 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/lib/extract.d.ts CHANGED
@@ -9,6 +9,19 @@ export interface ExtractOptions {
9
9
  * words are derived from the raw string. Defaults to `''`.
10
10
  */
11
11
  namespace?: string;
12
+ /**
13
+ * When `true`, omits the file-derived path segment (normally the source
14
+ * file's basename, e.g. `client-d` from `client.d.ts`) from every
15
+ * operation's `path`. Default `false` (unchanged behavior — the file
16
+ * segment disambiguates same-named exports across multiple source files
17
+ * within one extraction run). Set this only when the source is a single,
18
+ * stable file whose name is an extraction artifact, not a meaningful
19
+ * namespace component (e.g. a generated `.d.ts`) — dropping it can cause
20
+ * two same-named exports from different files to collide; the hard
21
+ * extract-time collision guard (`@adhd/apigen-engine-naming`'s
22
+ * `checkCollisions`) still catches that.
23
+ */
24
+ dropFileSegment?: boolean;
12
25
  /** Absolute path to a tsconfig.json for type resolution. Optional. */
13
26
  tsconfig?: string;
14
27
  /**
package/llms.txt ADDED
@@ -0,0 +1,85 @@
1
+ # @adhd/apigen-core-client
2
+
3
+ > Core apigen engine: TypeScript source → JSON Schema extraction, composition, and plugin contracts.
4
+
5
+ ## Functions
6
+
7
+ - `extract(opts: ExtractOptions): Promise<Operation[]>` — v2 symbol-based extractor. Handles 6 export shapes (named fn, const/arrow, named-object, default named, anonymous default, CJS) + renamed exports. Produces canonical `Operation[]` with deterministic ids, JSON Schema input/output, and same-host TypeText sugar. Ctx first-param excluded by name match only.
8
+ - `tokenize(raw: string): string[]` — Splits camelCase/PascalCase/kebab-case/snake_case into lower-cased words. Deterministic. Used for casing-neutral Segment construction.
9
+ - `generateSchemas(opts: GenerateSchemasOptions): Promise<GeneratedSchemas>` — v1 schema extraction. Three export modes: named (default), default, named-object. Promise<T> unwrapped. Session-sharing for cache hits.
10
+ - `composeSchemas(domain: GeneratedSchemas, middlewares: SlimMiddleware[], overrides?): ComposedSchemas` — Merges domain schemas with middleware envelope fields. Always wraps with data:{}. Only `false` suppresses a middleware.
11
+ - `extractClasses(opts: ExtractClassesOptions): Promise<Operation[]>` — Class export extraction (SPEC §10). Static methods always extracted. Constructor + instance methods opt-in via includeInstances. Instance methods carry instanceId envelope.
12
+ - `createExtractionSession(): ExtractionSession` — Per-run shared cache. One ts-morph Project per tsconfig, one schema generator per file, memoized schemas. dispose() releases per-run resources.
13
+ - `clearPersistentProjectCache(): void` — Drops process-lifetime Project and schema caches.
14
+ - `languageOfSource(file: string): PluginLanguage | undefined` — Extension → language tag (.ts→'ts', .py→'py', etc.). Undefined for unknown.
15
+ - `pluginConsumesSource(plugin: LanguageAwarePlugin, file: string): boolean` — Does plugin's language match file's extension?
16
+ - `sourcesForPlugin(plugin: LanguageAwarePlugin, files: string[]): string[]` — Filter files by plugin language. Primary serve dispatch entry-point.
17
+ - `effectiveLanguage(plugin: LanguageAwarePlugin): PluginLanguage` — Declared language or default 'ts'.
18
+
19
+ ## Types
20
+
21
+ ### Descriptor (SPEC §4)
22
+ - `Operation` — Canonical operation: id, host, namespace, path (Segment[]), kind, async, streaming, safe, input/output JSONSchema, envelope, typeText.
23
+ - `OperationKind` — 'action' | 'query' | 'constructor' | 'instance-method'.
24
+ - `Segment` — { raw: string, words: string[] }. Casing-neutral identity.
25
+ - `JSONSchema` — JSON Schema 2020-12 fragment with $defs/$ref + ApigenSchemaHints.
26
+ - `ApigenSchemaHints` — Advisory x-apigen-nominal, x-apigen-enum-repr, fidelity.
27
+ - `TypeText` — { lang, input, output }. Same-host textual sugar. Null when unavailable.
28
+
29
+ ### v1 Plugin
30
+ - `OutputPlugin` — { id, description, language?, optionsSchema?, generate(PluginInput): PluginOutput, run?(RunInput): Promise<void> }
31
+ - `PluginInput` — { packages, outputDir, options, logger? }
32
+ - `PluginOutput` — { files: {path,content}[], postCommands? }
33
+ - `RunInput` — PluginInput + { signal?: AbortSignal }
34
+ - `PluginLanguage` — 'ts' | 'py' | 'rust' | 'go' | 'java'
35
+
36
+ ### v2 Plugin (SPEC §7.1)
37
+ - `Plugin<Opts>` — { id, description?, language?, optionsSchema?, capabilities: { target?, layer?, mount?, envelope? } }
38
+ - `TargetCapability<Opts>` — { name, generate(Descriptor, Opts): File[], serve?(Descriptor, Harness, Opts): Promise<Server> }
39
+ - `LayerCapability` — { envelopeFields?, layer(Call, Next): Promise<Result> | AsyncIterable<Chunk> }
40
+ - `MountCapability` — { operations(Descriptor, opts?): MountedOperation[] }
41
+ - `MountedOperation` — Operation + { transports?, handler(Call): unknown }
42
+ - `EnvelopeCapability` — { request?, response? } — side-channel field schemas
43
+ - `Call` — { operation, data, envelope, ctx(Extensions), transport, signal, raw? }
44
+ - `Next` — () => Promise<Result> | AsyncIterable<Chunk>
45
+ - `Transport` — 'http' | 'grpc' | 'mcp' | 'cli'
46
+ - `Extensions` — { get<T>(key), set<T>(key, value) } — typed request-extensions map
47
+ - `Descriptor` — { operations, host, namespace? } — merged canonical descriptor
48
+ - `Harness` — { invoke(op, call): Promise<Result> | AsyncIterable<Chunk> }
49
+ - `Server` — { close(): Promise<void> }
50
+ - `File` — { path, content }
51
+
52
+ ### Schema
53
+ - `GeneratedSchemas` — { metadata: { namespace, phase }, schemas: Record<name, { input, output, hasCtx? }> }
54
+ - `ComposedSchemas` — Record<name, { input (includes envelope+data), output, hasCtx? }>
55
+ - `GenerateSchemasOptions` — { sourceFile, exportMode?, namespace?, phase?, tsconfig?, session? }
56
+ - `ExportMode` — { type: 'named' } | { type: 'default' } | { type: 'named-object', name: string }
57
+
58
+ ### Session
59
+ - `ExtractionSession` — { dispose(), readonly stats: ISessionStats }
60
+ - `ISessionStats` — { projectsBuilt, generatorsBuilt, schemaCacheHits, schemaCacheMisses }
61
+
62
+ ### Source Language
63
+ - `LanguageAwarePlugin` — { language?: PluginLanguage }
64
+ - `ExtractOptions` — { sourceFile, namespace?, tsconfig?, session? }
65
+ - `ExtractClassesOptions` — { sourceFile, namespace?, tsconfig?, includeInstances?, session? }
66
+
67
+ ### Re-exported
68
+ - `Logger` — re-exported from pino
69
+
70
+ ## Invariants
71
+ - `ctx-name-only`: First param named `ctx` excluded by name, no type check. hasCtx flag recorded.
72
+ - `data-wrapper-always-present`: composeSchemas always wraps with data:{}.
73
+ - `false-suppresses-middleware`: Only `false` suppresses; null/undefined/0/'' do not.
74
+ - `hints-advisory`: x-apigen-* hints are advisory. Removing them leaves valid schema.
75
+ - `do-not-parallelize-buildSchema`: Synchronous CPU, morph-walk mutates shared SourceFile.
76
+ - `language-agnostic-output`: Core does not restrict emitted file language.
77
+
78
+ ## Dependencies
79
+ - ts-morph ^23.0.0, ts-json-schema-generator ^2.3.0, pino 10.3.1, typescript ^6.0.3, decimal.js ^10.4.3, @adhd/apigen-base-logical ^0.0.1
80
+
81
+ ## See also
82
+ - [README.md](./README.md)
83
+ - [CHANGELOG.md](./CHANGELOG.md)
84
+ - [docs/reference/](./docs/reference/)
85
+ - [docs/how-to/](./docs/how-to/)
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adhd/apigen-core-client",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "dependencies": {
5
5
  "ts-morph": "^23.0.0",
6
6
  "ts-json-schema-generator": "^2.3.0",
7
7
  "pino": "10.3.1",
8
8
  "typescript": "^6.0.3",
9
- "@adhd/apigen-base-logical": "^0.0.5"
9
+ "@adhd/apigen-base-logical": "^0.1.0"
10
10
  },
11
11
  "main": "./index.js",
12
12
  "module": "./index.mjs",