@nxgt/typespec 0.13.0 → 0.13.2
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 +2 -1
- package/dist/index.d.ts +5 -5
- package/dist/operation-ids.d.ts +1 -1
- package/dist/resource.d.ts +1 -1
- package/docs/guide/scalars.md +6 -3
- package/docs/roadmap.md +10 -3
- package/docs/troubleshooting.md +13 -7
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -339,7 +339,8 @@ model Place {
|
|
|
339
339
|
Each is an OpenAPI component named as in GraphQL (`Latitude`, `URL`), with a
|
|
340
340
|
`format`, a pattern or bounds approximating the rule, and `x-nxgt-scalar`
|
|
341
341
|
naming it. The exact rules (checksums, ISO and IANA lists) are outside the
|
|
342
|
-
pattern
|
|
342
|
+
pattern; [`@nxgt/openapi-codegen`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars)'s
|
|
343
|
+
`scalars: 'exact'` checks them with the schemas of `@nxgt/zod`. TypeSpec's own `url` takes any scheme; `httpUrl` takes `http:` and
|
|
343
344
|
`https:`. Every scalar by category, in
|
|
344
345
|
[Scalars](docs/guide/scalars.md); the ids, the addresses and the columns, in
|
|
345
346
|
[Scalars and columns](docs/guide/columns.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* export would declare it a second time, in the global namespace.
|
|
8
8
|
*/
|
|
9
9
|
import type { Program } from '@typespec/compiler';
|
|
10
|
-
import { operationIds } from './operation-ids';
|
|
11
|
-
import { queryMethod } from './query-method';
|
|
12
|
-
export { $onEmit } from './emitter';
|
|
13
|
-
export { $lib } from './lib';
|
|
14
|
-
export { $linter } from './linter';
|
|
10
|
+
import { operationIds } from './operation-ids.js';
|
|
11
|
+
import { queryMethod } from './query-method.js';
|
|
12
|
+
export { $onEmit } from './emitter.js';
|
|
13
|
+
export { $lib } from './lib.js';
|
|
14
|
+
export { $linter } from './linter.js';
|
|
15
15
|
export declare function $onValidate(program: Program): void;
|
|
16
16
|
export declare const $decorators: {
|
|
17
17
|
Nxgt: {
|
package/dist/operation-ids.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* the interface's resource: `create` in `Users` is `createUser` (`verbs.ts`).
|
|
6
6
|
*/
|
|
7
7
|
import { type DecoratorContext, type Interface, type Namespace, type Operation, type Program } from '@typespec/compiler';
|
|
8
|
-
import { type OperationIdsOptions } from './resource';
|
|
8
|
+
import { type OperationIdsOptions } from './resource.js';
|
|
9
9
|
/**
|
|
10
10
|
* Marks the interface or the namespace; its ids are set once the program is
|
|
11
11
|
* checked. On a template, TypeSpec runs it on each instance, which
|
package/dist/resource.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* them, layered from the library's, the namespaces', and the interface's.
|
|
5
5
|
*/
|
|
6
6
|
import type { Operation, Program } from '@typespec/compiler';
|
|
7
|
-
import { type Grammar } from './verbs';
|
|
7
|
+
import { type Grammar } from './verbs.js';
|
|
8
8
|
/** `@operationIds`' options, as `OperationIdsOptions` declares them. */
|
|
9
9
|
export interface OperationIdsOptions {
|
|
10
10
|
readonly singular?: string;
|
package/docs/guide/scalars.md
CHANGED
|
@@ -67,9 +67,12 @@ components:
|
|
|
67
67
|
| `description` | The rule in words, and what the pattern leaves out. |
|
|
68
68
|
|
|
69
69
|
A generator that knows nothing of `x-nxgt-scalar` still validates the pattern
|
|
70
|
-
and the bounds.
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
and the bounds. `@nxgt/openapi-codegen` with
|
|
71
|
+
[`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars) maps it to the exact Zod
|
|
72
|
+
schema from `@nxgt/zod`, the checksum, the list or the `Intl` rule included;
|
|
73
|
+
with the default `'pattern'`, what a scalar leaves out is not checked. The
|
|
74
|
+
codecs (`dateTime`, `timestamp`, `bigInt`, `long`) keep their pattern under
|
|
75
|
+
`'exact'` too.
|
|
73
76
|
|
|
74
77
|
## Names
|
|
75
78
|
|
package/docs/roadmap.md
CHANGED
|
@@ -10,9 +10,7 @@ Nothing in progress.
|
|
|
10
10
|
|
|
11
11
|
## Next
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
`x-nxgt-scalar` to the exact Zod schema from `@nxgt/zod`: the checksums,
|
|
15
|
-
the ISO and IANA lists and the `Intl` rules the patterns leave out.
|
|
13
|
+
Nothing planned beyond what is under Later.
|
|
16
14
|
|
|
17
15
|
## Later
|
|
18
16
|
|
|
@@ -27,6 +25,15 @@ Nothing in progress.
|
|
|
27
25
|
|
|
28
26
|
## Shipped
|
|
29
27
|
|
|
28
|
+
### 0.13.2
|
|
29
|
+
|
|
30
|
+
- **Exact scalar rules in the generated code.** `@nxgt/openapi-codegen`
|
|
31
|
+
with `scalars: 'exact'` maps `x-nxgt-scalar` to the exact Zod schema from
|
|
32
|
+
`@nxgt/zod`: the checksums, the ISO and IANA lists, the `Intl` rules and the
|
|
33
|
+
refusal of `-0` the patterns leave out. The codecs keep their pattern until
|
|
34
|
+
`@nxgt/zod` offers their wire schemas. The guides and the troubleshooting
|
|
35
|
+
entries say so.
|
|
36
|
+
|
|
30
37
|
### 0.13.0
|
|
31
38
|
|
|
32
39
|
- **The emitter `@nxgt/typespec`.** `emit: ["@nxgt/typespec"]` runs
|
package/docs/troubleshooting.md
CHANGED
|
@@ -628,12 +628,17 @@ one.
|
|
|
628
628
|
|
|
629
629
|
**Why:** the scalar's pattern checks the shape. A list (`countryCode`,
|
|
630
630
|
`currency`, `timeZone`, `locale`) or a checksum (`iban`, ISBN) does not fit in
|
|
631
|
-
a pattern. `x-nxgt-scalar` names the exact rule,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
`
|
|
631
|
+
a pattern. `x-nxgt-scalar` names the exact rule, and `@nxgt/openapi-codegen`
|
|
632
|
+
maps it to the `@nxgt/zod` schema only with `scalars: 'exact'`; the default is
|
|
633
|
+
`'pattern'`.
|
|
634
|
+
|
|
635
|
+
**Fix:** generate with
|
|
636
|
+
[`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars)
|
|
637
|
+
(`bun add @nxgt/zod`, then `generate({ …, scalars: 'exact' })`): `iban` is
|
|
638
|
+
checked by `ibanSchema`, `countryCode` by its list of assigned codes. If you
|
|
639
|
+
cannot, check the value in the handler against the exact rule, the list or the
|
|
640
|
+
checksum, from `@nxgt/zod` or your own table, and answer `400` as the generated
|
|
641
|
+
validator does:
|
|
637
642
|
|
|
638
643
|
```ts
|
|
639
644
|
if (!knownCountries.has(body.country)) {
|
|
@@ -651,7 +656,8 @@ where `@nxgt/graphql-scalars` refuses it.
|
|
|
651
656
|
tell from `0`. For `nonNegativeInt`, `nonPositiveInt`, `port`, the bound holds,
|
|
652
657
|
so the value passes (`positiveInt` and `negativeInt` refuse it by their bound).
|
|
653
658
|
|
|
654
|
-
**Fix:**
|
|
659
|
+
**Fix:** generate with [`scalars: 'exact'`](https://github.com/softistx/nxgt-http/blob/develop/packages/openapi-codegen/docs/guide/options.md#scalars), whose schemas refuse `-0` for
|
|
660
|
+
an integer scalar. Otherwise normalise in the handler when the sign matters:
|
|
655
661
|
|
|
656
662
|
```ts
|
|
657
663
|
const quantity = Object.is(body.quantity, -0) ? 0 : body.quantity;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxgt/typespec",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "bun run ../../build.ts",
|
|
38
38
|
"fixtures": "bun run test/generate.ts",
|
|
39
|
-
"test": "bun run fixtures && bun test src",
|
|
39
|
+
"test": "bun run ../../scripts/check-dist-fresh.ts . && bun run fixtures && bun test src",
|
|
40
40
|
"typecheck": "bun run fixtures && tsc --noEmit",
|
|
41
41
|
"fixtures:typespec": "bun run test/generate.ts --accept"
|
|
42
42
|
},
|
|
@@ -61,8 +61,9 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@nxgt/openapi-codegen": "^0.
|
|
65
|
-
"@nxgt/openapi-hono": "^0.3.
|
|
64
|
+
"@nxgt/openapi-codegen": "^0.10.0",
|
|
65
|
+
"@nxgt/openapi-hono": "^0.3.3",
|
|
66
|
+
"@nxgt/zod": "^0.1.3",
|
|
66
67
|
"@types/bun": "^1.4.0",
|
|
67
68
|
"@typespec/compiler": "1.17.0",
|
|
68
69
|
"@typespec/http": "1.17.0",
|