typespun-codegen 0.0.4 → 0.0.8
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/README.md +170 -47
- package/package.json +2 -2
- package/dist/analyzer/analyze.d.ts +0 -4
- package/dist/analyzer/analyze.d.ts.map +0 -1
- package/dist/analyzer/analyze.js +0 -414
- package/dist/analyzer/annotations.d.ts +0 -14
- package/dist/analyzer/annotations.d.ts.map +0 -1
- package/dist/analyzer/annotations.js +0 -102
- package/dist/analyzer/default-expression.d.ts +0 -10
- package/dist/analyzer/default-expression.d.ts.map +0 -1
- package/dist/analyzer/default-expression.js +0 -67
- package/dist/analyzer/diagnostic.d.ts +0 -5
- package/dist/analyzer/diagnostic.d.ts.map +0 -1
- package/dist/analyzer/diagnostic.js +0 -16
- package/dist/analyzer/ir.d.ts +0 -2
- package/dist/analyzer/ir.d.ts.map +0 -1
- package/dist/analyzer/ir.js +0 -1
- package/dist/bin.d.ts +0 -3
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -3
- package/dist/cli/diagnostics.d.ts +0 -7
- package/dist/cli/diagnostics.d.ts.map +0 -1
- package/dist/cli/diagnostics.js +0 -26
- package/dist/cli/init.d.ts +0 -18
- package/dist/cli/init.d.ts.map +0 -1
- package/dist/cli/init.js +0 -417
- package/dist/cli/main.d.ts +0 -13
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js +0 -157
- package/dist/contracts.d.ts +0 -33
- package/dist/contracts.d.ts.map +0 -1
- package/dist/contracts.js +0 -1
- package/dist/emitter/emit.d.ts +0 -13
- package/dist/emitter/emit.d.ts.map +0 -1
- package/dist/emitter/emit.js +0 -65
- package/dist/emitter/fingerprint.d.ts +0 -10
- package/dist/emitter/fingerprint.d.ts.map +0 -1
- package/dist/emitter/fingerprint.js +0 -28
- package/dist/generate.d.ts +0 -29
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js +0 -267
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/project/config.d.ts +0 -20
- package/dist/project/config.d.ts.map +0 -1
- package/dist/project/config.js +0 -140
- package/dist/project/defaults.d.ts +0 -22
- package/dist/project/defaults.d.ts.map +0 -1
- package/dist/project/defaults.js +0 -216
- package/dist/project/discovery.d.ts +0 -9
- package/dist/project/discovery.d.ts.map +0 -1
- package/dist/project/discovery.js +0 -66
package/README.md
CHANGED
|
@@ -4,92 +4,215 @@
|
|
|
4
4
|
|
|
5
5
|
# typespun-codegen
|
|
6
6
|
|
|
7
|
-
The TypeScript
|
|
8
|
-
|
|
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.
|
|
9
12
|
|
|
10
13
|
[](https://www.npmjs.com/package/typespun-codegen)
|
|
11
14
|
[](LICENSE)
|
|
12
15
|
|
|
13
|
-
|
|
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:
|
|
14
26
|
|
|
15
27
|
```sh
|
|
16
28
|
bun add typespun
|
|
17
29
|
bun add --dev typespun-codegen
|
|
30
|
+
bun typespun init --env-prefix APP
|
|
18
31
|
```
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
`typespun`. The package root intentionally has no programmatic compiler API in
|
|
22
|
-
version 0.1.
|
|
33
|
+
Using npm:
|
|
23
34
|
|
|
24
|
-
|
|
35
|
+
```sh
|
|
36
|
+
npm install typespun
|
|
37
|
+
npm install --save-dev typespun-codegen
|
|
38
|
+
npx typespun init --env-prefix APP
|
|
39
|
+
```
|
|
25
40
|
|
|
26
|
-
|
|
41
|
+
The default initialization creates, when missing:
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
74
|
```
|
|
36
75
|
|
|
37
|
-
|
|
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:
|
|
38
117
|
|
|
39
118
|
```ts
|
|
40
119
|
/** @typespun */
|
|
41
120
|
export interface AppConfig {
|
|
42
121
|
server: { host: string; port: number };
|
|
43
122
|
/** @secret */
|
|
44
|
-
|
|
123
|
+
databaseUrl: string;
|
|
45
124
|
}
|
|
46
125
|
```
|
|
47
126
|
|
|
48
|
-
|
|
127
|
+
Regenerate and import the generated module:
|
|
49
128
|
|
|
50
129
|
```sh
|
|
51
130
|
bun run config:generate
|
|
52
|
-
# Generated src/generated/typespun.ts.
|
|
53
131
|
```
|
|
54
132
|
|
|
55
|
-
|
|
56
|
-
|
|
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:
|
|
57
165
|
|
|
58
166
|
```sh
|
|
167
|
+
bun run config:generate
|
|
59
168
|
bun run config:check
|
|
60
169
|
```
|
|
61
170
|
|
|
62
|
-
|
|
171
|
+
The underlying commands are:
|
|
63
172
|
|
|
64
173
|
```text
|
|
65
|
-
typespun init [--style interface|class] [--input <path>]
|
|
66
|
-
[--output <path>] [--env-prefix <prefix>]
|
|
67
174
|
typespun generate [--config <path>]
|
|
68
175
|
typespun check [--config <path>]
|
|
69
176
|
```
|
|
70
177
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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)
|
|
94
217
|
|
|
95
218
|
MIT © Typespun contributors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespun-codegen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "TypeScript schema analyzer, generator, and CLI for Typespun",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"typescript": "6.0.3",
|
|
51
|
-
"typespun": "^0.0.
|
|
51
|
+
"typespun": "^0.0.8",
|
|
52
52
|
"yaml": "2.9.1"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -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"}
|