typespun-codegen 0.1.0 → 0.1.1

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/package.json +3 -3
  4. package/dist/analyzer/analyze.d.ts +0 -4
  5. package/dist/analyzer/analyze.d.ts.map +0 -1
  6. package/dist/analyzer/analyze.js +0 -414
  7. package/dist/analyzer/annotations.d.ts +0 -14
  8. package/dist/analyzer/annotations.d.ts.map +0 -1
  9. package/dist/analyzer/annotations.js +0 -102
  10. package/dist/analyzer/default-expression.d.ts +0 -10
  11. package/dist/analyzer/default-expression.d.ts.map +0 -1
  12. package/dist/analyzer/default-expression.js +0 -67
  13. package/dist/analyzer/diagnostic.d.ts +0 -5
  14. package/dist/analyzer/diagnostic.d.ts.map +0 -1
  15. package/dist/analyzer/diagnostic.js +0 -16
  16. package/dist/analyzer/ir.d.ts +0 -2
  17. package/dist/analyzer/ir.d.ts.map +0 -1
  18. package/dist/analyzer/ir.js +0 -1
  19. package/dist/bin.d.ts +0 -3
  20. package/dist/bin.d.ts.map +0 -1
  21. package/dist/bin.js +0 -3
  22. package/dist/cli/diagnostics.d.ts +0 -7
  23. package/dist/cli/diagnostics.d.ts.map +0 -1
  24. package/dist/cli/diagnostics.js +0 -26
  25. package/dist/cli/init.d.ts +0 -18
  26. package/dist/cli/init.d.ts.map +0 -1
  27. package/dist/cli/init.js +0 -417
  28. package/dist/cli/main.d.ts +0 -13
  29. package/dist/cli/main.d.ts.map +0 -1
  30. package/dist/cli/main.js +0 -157
  31. package/dist/contracts.d.ts +0 -33
  32. package/dist/contracts.d.ts.map +0 -1
  33. package/dist/contracts.js +0 -1
  34. package/dist/emitter/emit.d.ts +0 -13
  35. package/dist/emitter/emit.d.ts.map +0 -1
  36. package/dist/emitter/emit.js +0 -65
  37. package/dist/emitter/fingerprint.d.ts +0 -10
  38. package/dist/emitter/fingerprint.d.ts.map +0 -1
  39. package/dist/emitter/fingerprint.js +0 -28
  40. package/dist/generate.d.ts +0 -29
  41. package/dist/generate.d.ts.map +0 -1
  42. package/dist/generate.js +0 -267
  43. package/dist/index.d.ts +0 -3
  44. package/dist/index.d.ts.map +0 -1
  45. package/dist/index.js +0 -2
  46. package/dist/project/config.d.ts +0 -20
  47. package/dist/project/config.d.ts.map +0 -1
  48. package/dist/project/config.js +0 -140
  49. package/dist/project/defaults.d.ts +0 -22
  50. package/dist/project/defaults.d.ts.map +0 -1
  51. package/dist/project/defaults.js +0 -216
  52. package/dist/project/discovery.d.ts +0 -9
  53. package/dist/project/discovery.d.ts.map +0 -1
  54. package/dist/project/discovery.js +0 -66
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Typespun contributors
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/README.md ADDED
@@ -0,0 +1,218 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/omkar273/typespun/main/docs/assets/typespun-mark.svg" width="64" height="64" alt="Typespun threads converging into typed brackets">
3
+ </p>
4
+
5
+ # typespun-codegen
6
+
7
+ The TypeScript compiler and `typespun` command-line tool for
8
+ [Typespun](https://github.com/omkar273/typespun). It initializes a project,
9
+ analyzes one TypeScript configuration declaration, and emits a deterministic
10
+ loader for the separate [`typespun`](https://www.npmjs.com/package/typespun)
11
+ runtime package.
12
+
13
+ [![npm](https://img.shields.io/npm/v/typespun-codegen.svg)](https://www.npmjs.com/package/typespun-codegen)
14
+ [![license](https://img.shields.io/npm/l/typespun-codegen.svg)](LICENSE)
15
+
16
+ The package name is `typespun-codegen`; the executable it provides is
17
+ `typespun`. There is no supported programmatic compiler API in version 0.1.
18
+
19
+ ## Start with `init`
20
+
21
+ Run initialization from the root of an existing TypeScript project. The
22
+ project must already contain a valid `package.json` and a usable
23
+ `tsconfig.json`.
24
+
25
+ Install the runtime and generator, then invoke the local executable:
26
+
27
+ ```sh
28
+ bun add typespun
29
+ bun add --dev typespun-codegen
30
+ bun typespun init --env-prefix APP
31
+ ```
32
+
33
+ Using npm:
34
+
35
+ ```sh
36
+ npm install typespun
37
+ npm install --save-dev typespun-codegen
38
+ npx typespun init --env-prefix APP
39
+ ```
40
+
41
+ The default initialization creates, when missing:
42
+
43
+ - `src/config.ts`, containing an `@typespun` interface with a numeric `port`
44
+ field;
45
+ - `config.yaml`, containing `port: 3000` for a new starter schema or an empty
46
+ object when adopting an existing schema;
47
+ - `typespun.json`, pointing from `src/config.ts` to
48
+ `src/generated/typespun.ts`, with commented examples for every optional
49
+ setting and allowed policy value; and
50
+ - `config:generate` and `config:check` scripts in `package.json`.
51
+
52
+ When both `typespun` and `typespun-codegen` resolve from the project or an
53
+ ancestor `node_modules`, `init` also creates the first generated loader at
54
+ `src/generated/typespun.ts`.
55
+
56
+ You can scaffold before installing either package with a package-qualified
57
+ zero-install command:
58
+
59
+ ```sh
60
+ bunx --package typespun-codegen typespun init
61
+ npx --package=typespun-codegen typespun init
62
+ ```
63
+
64
+ In that case, `init` creates the project files and exits successfully but does
65
+ not generate output, because the dependencies are not installed in the project.
66
+ It prints install commands for the manager selected by `packageManager` or a
67
+ recognized lockfile, falling back to npm. It never runs an installer. Install
68
+ both packages and generate:
69
+
70
+ ```sh
71
+ bun add typespun
72
+ bun add --dev typespun-codegen
73
+ bun run config:generate
74
+ ```
75
+
76
+ The installed `bun typespun init` and `npx typespun init` flows are shorter and
77
+ generate immediately because both dependencies are already present.
78
+
79
+ `init` preserves existing scripts and initialized files. Re-running it is
80
+ byte-stable. It refuses conflicting options, input/output aliases, and an
81
+ existing output file or symlink that is not recognizable as Typespun-generated;
82
+ there is no force-overwrite option.
83
+
84
+ ## Customize initialization
85
+
86
+ ```text
87
+ typespun init [--style interface|class] [--input <path>]
88
+ [--output <path>] [--env-prefix <prefix>]
89
+ ```
90
+
91
+ | Option | Effect |
92
+ | -------------------------- | --------------------------------------------------------------------------- |
93
+ | `--style interface\|class` | Creates an annotated interface (the default) or a decorated class. |
94
+ | `--input <path>` | Selects the schema path. It must end in `.ts`, `.mts`, or `.cts`. |
95
+ | `--output <path>` | Selects the generated module path. It must end in `.ts`, `.mts`, or `.cts`. |
96
+ | `--env-prefix <prefix>` | Stores the environment-variable prefix in `typespun.json`. |
97
+
98
+ For example:
99
+
100
+ ```sh
101
+ bun typespun init \
102
+ --style class \
103
+ --input config/app.mts \
104
+ --output config/generated.mts \
105
+ --env-prefix APP
106
+ ```
107
+
108
+ Without explicit paths, `init` adopts one existing conventional schema at
109
+ `src/config.ts`, `src/config.mts`, or `src/config.cts`; otherwise it creates
110
+ `src/config.ts`. The output defaults to `src/generated/typespun` with the same
111
+ extension as the input. Multiple conventional schemas require `--input`.
112
+
113
+ ## Use the generated loader
114
+
115
+ After the default initialization, expand `src/config.ts` into your application
116
+ schema:
117
+
118
+ ```ts
119
+ /** @typespun */
120
+ export interface AppConfig {
121
+ server: { host: string; port: number };
122
+ /** @secret */
123
+ databaseUrl: string;
124
+ }
125
+ ```
126
+
127
+ Regenerate and import the generated module:
128
+
129
+ ```sh
130
+ bun run config:generate
131
+ ```
132
+
133
+ ```ts
134
+ import { loadConfig } from './generated/typespun.js';
135
+
136
+ const config = loadConfig({
137
+ source: {
138
+ SERVER_HOST: '127.0.0.1',
139
+ SERVER_PORT: '3000',
140
+ DATABASE_URL: 'postgres://localhost/example',
141
+ },
142
+ });
143
+
144
+ console.log(config.server.port); // 3000, typed as number
145
+ ```
146
+
147
+ The generated module exports the declaration-backed `Config` type and
148
+ `loadConfig()`. Commit that module: output is deterministic for the same
149
+ declaration, resolved configuration, defaults, and generator version.
150
+
151
+ ## Generate and check
152
+
153
+ Initialization adds these scripts:
154
+
155
+ ```json
156
+ {
157
+ "scripts": {
158
+ "config:generate": "typespun generate",
159
+ "config:check": "typespun check"
160
+ }
161
+ }
162
+ ```
163
+
164
+ Use them locally and in CI:
165
+
166
+ ```sh
167
+ bun run config:generate
168
+ bun run config:check
169
+ ```
170
+
171
+ The underlying commands are:
172
+
173
+ ```text
174
+ typespun generate [--config <path>]
175
+ typespun check [--config <path>]
176
+ ```
177
+
178
+ `generate` reads `typespun.json`, the schema, the resolved `tsconfig.json`, and
179
+ an optional JSON or YAML defaults file. It writes atomically only when the
180
+ canonical output differs, reporting either `Generated` or `Unchanged`.
181
+
182
+ `check` performs the same analysis but never writes. It exits nonzero when the
183
+ output is missing or stale and tells you to run `typespun generate`. Pass
184
+ `--config <path>` once to either command to use a configuration file other than
185
+ `typespun.json`; relative paths inside it resolve from that file's directory.
186
+
187
+ ## Errors and exit status
188
+
189
+ - Exit `0`: help or success. For `init`, this also includes the safe
190
+ dependency-installation handoff described above.
191
+ - Exit `1`: schema, defaults, output, or stale-output failure.
192
+ - Exit `2`: invalid CLI usage or unusable project/TypeScript configuration.
193
+
194
+ Warnings and diagnostics are written to stderr. Secret-default warnings identify
195
+ the field path without printing the received secret value. `generate` and
196
+ `check` accept only `--config`; unknown options, duplicate options, and missing
197
+ option values are usage errors.
198
+
199
+ Run `bun typespun --help`, `bun typespun generate --help`, or
200
+ `bun typespun check --help` for the built-in command summary.
201
+
202
+ ## Package role
203
+
204
+ `typespun-codegen` carries the TypeScript compiler and YAML parser needed while
205
+ authoring and checking configuration. Applications import the generated loader,
206
+ which delegates runtime loading and validation to `typespun`; they do not import
207
+ compiler internals from this package. Keeping code generation separate lets the
208
+ compiler remain a development dependency.
209
+
210
+ Further documentation:
211
+
212
+ - [Getting started](https://github.com/omkar273/typespun/blob/main/docs/getting-started.md)
213
+ - [CLI reference](https://github.com/omkar273/typespun/blob/main/docs/api/cli.md)
214
+ - [`typespun.json` reference](https://github.com/omkar273/typespun/blob/main/docs/reference/configuration.md)
215
+ - [Declaration syntax](https://github.com/omkar273/typespun/blob/main/docs/concepts/declarations.md)
216
+ - [Generated loader API](https://github.com/omkar273/typespun/blob/main/docs/api/generated-loader.md)
217
+
218
+ MIT © Typespun contributors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespun-codegen",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "TypeScript schema analyzer, generator, and CLI for Typespun",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "!dist/.tsbuildinfo"
30
30
  ],
31
31
  "bin": {
32
- "typespun": "./dist/bin.js"
32
+ "typespun": "dist/bin.js"
33
33
  },
34
34
  "main": "./dist/index.js",
35
35
  "types": "./dist/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "typescript": "6.0.3",
51
- "typespun": "workspace:*",
51
+ "typespun": "^0.1.1",
52
52
  "yaml": "2.9.1"
53
53
  }
54
54
  }
@@ -1,4 +0,0 @@
1
- import ts from 'typescript';
2
- import type { AnalyzeResult } from '../contracts.js';
3
- export declare function analyzeProgram(program: ts.Program, inputPath: string, envPrefix?: string): AnalyzeResult;
4
- //# sourceMappingURL=analyze.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/analyzer/analyze.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,KAAK,EACV,aAAa,EAId,MAAM,iBAAiB,CAAC;AASzB,wBAAgB,cAAc,CAC5B,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,SAAK,GACb,aAAa,CAqmBf"}