@contractkit/plugin-typescript 0.32.0 → 0.33.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.
- package/.turbo/turbo-build$colon$ci.log +5 -5
- package/.turbo/turbo-test$colon$ci.log +22 -20
- package/CHANGELOG.md +94 -0
- package/README.md +9 -4
- package/dist/codegen-contract.d.ts +7 -0
- package/dist/codegen-contract.d.ts.map +1 -1
- package/dist/codegen-mcp.d.ts.map +1 -1
- package/dist/codegen-operation.d.ts.map +1 -1
- package/dist/codegen-plain-types.d.ts.map +1 -1
- package/dist/codegen-revive.d.ts +42 -0
- package/dist/codegen-revive.d.ts.map +1 -0
- package/dist/codegen-sdk.d.ts +18 -6
- package/dist/codegen-sdk.d.ts.map +1 -1
- package/dist/decimal-runtime.d.ts +47 -0
- package/dist/decimal-runtime.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +538 -40
- package/dist/index.js.map +1 -1
- package/dist/ts-render.d.ts.map +1 -1
- package/llms.txt +111 -0
- package/package.json +2 -2
- package/src/codegen-contract.ts +58 -3
- package/src/codegen-mcp.ts +5 -0
- package/src/codegen-operation.ts +23 -1
- package/src/codegen-plain-types.ts +42 -2
- package/src/codegen-revive.ts +304 -0
- package/src/codegen-sdk.ts +248 -37
- package/src/decimal-runtime.ts +50 -0
- package/src/index.ts +30 -3
- package/src/ts-render.ts +6 -0
- package/tests/codegen-contract.test.ts +124 -1
- package/tests/codegen-operation.test.ts +14 -0
- package/tests/codegen-sdk.test.ts +77 -6
- package/tests/pipeline.test.ts +24 -0
|
@@ -5,9 +5,9 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
|
|
|
5
5
|
[34mCLI[39m tsup v8.5.1
|
|
6
6
|
[34mCLI[39m Target: esnext
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
9
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
8
|
+
[32mESM[39m [1mdist/index.js [22m[32m210.74 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m480.07 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 359ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
13
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 6133ms
|
|
13
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.14 KB[39m
|
|
@@ -3,34 +3,36 @@ $ vitest run --coverage
|
|
|
3
3
|
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/packages/plugin-typescript[39m
|
|
4
4
|
[2mCoverage enabled with [22m[33mv8[39m
|
|
5
5
|
|
|
6
|
-
[32m✓[39m tests/codegen-contract.test.ts [2m([22m[
|
|
7
|
-
[32m✓[39m tests/codegen-
|
|
8
|
-
[32m✓[39m tests/codegen-
|
|
9
|
-
[32m✓[39m tests/codegen-plain-types.test.ts [2m([22m[2m66 tests[22m[2m)[22m[32m
|
|
10
|
-
[32m✓[39m tests/codegen-server.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m
|
|
11
|
-
[32m✓[39m tests/pipeline.test.ts [2m([22m[
|
|
12
|
-
[32m✓[39m tests/codegen-mcp.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m
|
|
13
|
-
[32m✓[39m tests/escaping-security.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m
|
|
6
|
+
[32m✓[39m tests/codegen-contract.test.ts [2m([22m[2m140 tests[22m[2m)[22m[32m 154[2mms[22m[39m
|
|
7
|
+
[32m✓[39m tests/codegen-operation.test.ts [2m([22m[2m155 tests[22m[2m)[22m[32m 220[2mms[22m[39m
|
|
8
|
+
[32m✓[39m tests/codegen-sdk.test.ts [2m([22m[2m159 tests[22m[2m)[22m[32m 227[2mms[22m[39m
|
|
9
|
+
[32m✓[39m tests/codegen-plain-types.test.ts [2m([22m[2m66 tests[22m[2m)[22m[32m 61[2mms[22m[39m
|
|
10
|
+
[32m✓[39m tests/codegen-server.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 143[2mms[22m[39m
|
|
11
|
+
[32m✓[39m tests/pipeline.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 269[2mms[22m[39m
|
|
12
|
+
[32m✓[39m tests/codegen-mcp.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m 57[2mms[22m[39m
|
|
13
|
+
[32m✓[39m tests/escaping-security.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m 24[2mms[22m[39m
|
|
14
14
|
|
|
15
15
|
[2m Test Files [22m [1m[32m8 passed[39m[22m[90m (8)[39m
|
|
16
|
-
[2m Tests [22m [1m[
|
|
17
|
-
[2m Start at [22m
|
|
18
|
-
[2m Duration [22m
|
|
16
|
+
[2m Tests [22m [1m[32m622 passed[39m[22m[90m (622)[39m
|
|
17
|
+
[2m Start at [22m 18:42:58
|
|
18
|
+
[2m Duration [22m 10.53s[2m (transform 7.47s, setup 0ms, import 19.72s, tests 1.15s, environment 1ms)[22m
|
|
19
19
|
|
|
20
20
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
21
21
|
-------------------|---------|----------|---------|---------|-------------------
|
|
22
22
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
23
23
|
-------------------|---------|----------|---------|---------|-------------------
|
|
24
|
-
All files |
|
|
25
|
-
src |
|
|
26
|
-
...n-contract.ts |
|
|
27
|
-
codegen-mcp.ts | 82.
|
|
28
|
-
...-operation.ts | 83.
|
|
29
|
-
...lain-types.ts |
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
All files | 83.01 | 77.14 | 86.06 | 85.64 |
|
|
25
|
+
src | 82.87 | 76.85 | 85.8 | 85.49 |
|
|
26
|
+
...n-contract.ts | 89.24 | 83.92 | 90.16 | 90.42 | ...1150,1155-1156
|
|
27
|
+
codegen-mcp.ts | 82.33 | 74.84 | 84.21 | 85.77 | ...97,302-303,386
|
|
28
|
+
...-operation.ts | 83.02 | 80.71 | 79.71 | 85.18 | ...1032,1037-1038
|
|
29
|
+
...lain-types.ts | 88.44 | 80.74 | 97.05 | 90.74 | ...71,197,309,315
|
|
30
|
+
...gen-revive.ts | 57.77 | 52.04 | 75 | 62.74 | ...65-196,278-284
|
|
31
|
+
codegen-sdk.ts | 88.96 | 82.01 | 90.56 | 91.78 | ...1632,1636-1637
|
|
32
|
+
...al-runtime.ts | 100 | 100 | 100 | 100 |
|
|
33
|
+
index.ts | 67.96 | 54.68 | 75 | 71.09 | ...1079,1095-1114
|
|
32
34
|
path-utils.ts | 70.28 | 51.13 | 100 | 73.5 | ...65-168,216-231
|
|
33
|
-
ts-render.ts |
|
|
35
|
+
ts-render.ts | 85.18 | 87.5 | 79.16 | 89.39 | 83,165,198-206
|
|
34
36
|
tests | 91.22 | 92.68 | 90.32 | 94 |
|
|
35
37
|
helpers.ts | 91.22 | 92.68 | 90.32 | 94 | 115-123
|
|
36
38
|
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @contractkit/contractkit-plugin-typescript
|
|
2
2
|
|
|
3
|
+
## 0.33.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ffb2ec6: Ship an `llms.txt` in every package, so an AI assistant reading the package out of `node_modules` gets its exact name, a config block with real key names, the full option table, the programmatic API, and the mistakes specific to it — without needing the repo checked out.
|
|
8
|
+
|
|
9
|
+
Correct several documented snippets that could not work as written. The five plugin READMEs named packages that do not exist (`@contractkit/contractkit-plugin-*`, and `-python-sdk` for the Python plugin) in both their install commands and their `contractkit.config.json` keys. `@contractkit/core`'s README exported `Diagnostics` and `validateOperation`, which are really `DiagnosticCollector` and `validateOp`, and gave the wrong signatures for three validation passes. `@contractkit/cli`'s README documented the OpenAPI importer as `contractkit openapi-to-ck --input <spec>`; it is `contractkit import-openapi <spec>`, with the path positional. `@contractkit/plugin-openapi` described its output as OpenAPI 3.0, but it emits 3.1.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ffb2ec6]
|
|
12
|
+
- @contractkit/core@0.28.1
|
|
13
|
+
|
|
14
|
+
## 0.33.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- e102a2c: Add a `decimal` scalar, for money and anything else that has to be exact
|
|
19
|
+
|
|
20
|
+
`number` compiles to `z.coerce.number()` — an IEEE-754 double. Anything monetary has to be exact,
|
|
21
|
+
so contracts either lied about their types or routed the value through `string` by hand. `decimal`
|
|
22
|
+
gives the language a type for it:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
contract Payslip: {
|
|
26
|
+
gross: decimal(min=0, scale=2)
|
|
27
|
+
rate: decimal
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A decimal travels as a **quoted JSON string** (`{"gross": "1250.00"}`) and becomes a decimal.js
|
|
32
|
+
`Decimal` — the same class Prisma hands you for a `Decimal` column, so a value moves between the
|
|
33
|
+
two with no conversion. Python gets `decimal.Decimal`; OpenAPI gets `type: string, format: decimal`.
|
|
34
|
+
|
|
35
|
+
A raw JSON number is **rejected**, not coerced. By the time one reaches the schema it has already
|
|
36
|
+
been through a double, which is precisely the loss the scalar exists to prevent, so accepting it
|
|
37
|
+
would defeat the point silently.
|
|
38
|
+
|
|
39
|
+
**`scale=` is a validation constraint — at most N decimal places — not a formatting directive.**
|
|
40
|
+
It cannot be one: the router assigns `ctx.body` and Koa serializes it with a `JSON.stringify` we
|
|
41
|
+
have no replacer for, so the wire form is whatever decimal.js normalizes to and `"1250.00"` reads
|
|
42
|
+
back as `"1250"`. The two are the same number; format at the display edge if you need the trailing
|
|
43
|
+
zeros. This is also what `scale` means in OpenAPI `pattern`, pydantic `condecimal(decimal_places=)`
|
|
44
|
+
and Prisma `@db.Decimal(_, n)`, so every downstream mapping stays honest.
|
|
45
|
+
|
|
46
|
+
Generated code sets `Decimal.set({ toExpNeg: -9e15, toExpPos: 9e15 })` so values never serialize in
|
|
47
|
+
exponential notation — without it `0.00000001` ships as `"1e-8"` and any peer validating
|
|
48
|
+
`^-?\d+(\.\d+)?$` rejects it. Note this is global decimal.js configuration and affects every
|
|
49
|
+
`Decimal` in the consuming process.
|
|
50
|
+
|
|
51
|
+
SDK clients rehydrate decimals through generated `reviveX` functions. The `bigint` approach does
|
|
52
|
+
not transfer — it works only because bigint invented a tagged `"123n"` wire encoding, and tagging a
|
|
53
|
+
decimal would corrupt the format for every non-ContractKit consumer. Re-parsing responses through
|
|
54
|
+
the Zod schema is not available either: `XOutput` is a type alias with no runtime value, and models
|
|
55
|
+
default to `z.strictObject`, so any field the server added would throw in every deployed client.
|
|
56
|
+
The revivers mutate in place, which preserves unknown server-added keys.
|
|
57
|
+
|
|
58
|
+
Two placements are rejected at parse time, both errors rather than warnings since no existing
|
|
59
|
+
contract can be relying on them. A decimal inside an **undiscriminated union** cannot be rehydrated
|
|
60
|
+
— the SDK has no way to tell which arm arrived, and a convert-if-string fallback would silently
|
|
61
|
+
rewrite a genuine `string` field in a sibling arm. A decimal in a **response header** has no
|
|
62
|
+
parsing step at all, so the annotation would simply be false at runtime.
|
|
63
|
+
|
|
64
|
+
`min`/`max` are kept as exact decimal strings rather than coerced through `Number()`, and OpenAPI
|
|
65
|
+
carries them in `x-contractkit-min`/`-max` extensions, since JSON Schema's numeric `minimum` and
|
|
66
|
+
`maximum` are ignored on a string type. A contract round-trips through OpenAPI and back with its
|
|
67
|
+
bounds intact.
|
|
68
|
+
|
|
69
|
+
SDKs that scaffold a `package.json` gain `decimal.js` as a dependency when a covered model uses the
|
|
70
|
+
scalar. Existing scaffolds are write-once and are not updated, so add it by hand there.
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- e102a2c: Fix scalar lists that had drifted out of sync with the language
|
|
75
|
+
|
|
76
|
+
Four places kept a hand-written copy of the language's scalar names, and three had already fallen
|
|
77
|
+
behind without anything failing to build:
|
|
78
|
+
- The VS Code completion list and hover map were both missing `interval`, so the editor silently
|
|
79
|
+
stopped recognising it — no completion, no hover.
|
|
80
|
+
- The constraint-argument regex that decides when to offer `min=`/`max=` completions was missing
|
|
81
|
+
`time`, `interval`, and every non-constrainable scalar.
|
|
82
|
+
- `docs/language.md`'s scalar table was missing `duration`.
|
|
83
|
+
|
|
84
|
+
The completion and semantic-token providers now read `SCALAR_NAMES` from `@contractkit/core`
|
|
85
|
+
directly, which removes the drift class rather than patching this instance of it, and the
|
|
86
|
+
constraint regex is built from those lists. What genuinely cannot derive from the set — a TextMate
|
|
87
|
+
alternation, a per-scalar documentation map, a Markdown table — is now covered by a test that fails
|
|
88
|
+
when any of them falls behind.
|
|
89
|
+
|
|
90
|
+
Also fixes the SDK scaffold's luxon detection, which omitted `duration`. `generateContract` imports
|
|
91
|
+
`Duration` from luxon whenever that scalar is present, so a contract whose only temporal type was a
|
|
92
|
+
duration scaffolded a `package.json` with no `luxon` dependency and did not compile.
|
|
93
|
+
|
|
94
|
+
- Updated dependencies [e102a2c]
|
|
95
|
+
- @contractkit/core@0.28.0
|
|
96
|
+
|
|
3
97
|
## 0.32.0
|
|
4
98
|
|
|
5
99
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @contractkit/
|
|
1
|
+
# @contractkit/plugin-typescript
|
|
2
2
|
|
|
3
3
|
ContractKit plugin that generates TypeScript output from `.ck` contract files. Covers all server-side and client-side TypeScript needs: Koa routers, SDK clients, Zod schemas, and plain TypeScript interfaces.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add @contractkit/
|
|
8
|
+
pnpm add @contractkit/plugin-typescript
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Configuration
|
|
@@ -15,7 +15,7 @@ Add the plugin to `contractkit.config.json`. Each sub-config is independent —
|
|
|
15
15
|
```json
|
|
16
16
|
{
|
|
17
17
|
"plugins": {
|
|
18
|
-
"@contractkit/
|
|
18
|
+
"@contractkit/plugin-typescript": {
|
|
19
19
|
"server": {
|
|
20
20
|
"baseDir": "apps/api/",
|
|
21
21
|
"zod": true,
|
|
@@ -100,6 +100,11 @@ Generates plain TypeScript interface/type files from `contract` declarations. No
|
|
|
100
100
|
The `server` and `sdk` sub-generators set `target` themselves (`server` and `client` respectively), so
|
|
101
101
|
their plain-type output already matches the runtime that consumes it.
|
|
102
102
|
|
|
103
|
+
`decimal` is the one scalar that renders the same for both targets — decimal.js `Decimal` — because
|
|
104
|
+
it has no output transform, so the wire view and the server view agree. That also means plain-type
|
|
105
|
+
output carries a real `import Decimal from 'decimal.js'`, and the scaffolded `package.json` adds
|
|
106
|
+
`decimal.js` as a dependency whenever a covered model uses the scalar.
|
|
107
|
+
|
|
103
108
|
## Path templates
|
|
104
109
|
|
|
105
110
|
Output paths support the following variables:
|
|
@@ -165,7 +170,7 @@ statuses fall into which set.
|
|
|
165
170
|
## Programmatic use
|
|
166
171
|
|
|
167
172
|
```typescript
|
|
168
|
-
import { createTypescriptPlugin } from '@contractkit/
|
|
173
|
+
import { createTypescriptPlugin } from '@contractkit/plugin-typescript';
|
|
169
174
|
|
|
170
175
|
const plugin = createTypescriptPlugin({
|
|
171
176
|
server: {
|
|
@@ -24,6 +24,13 @@ export interface ContractCodegenContext {
|
|
|
24
24
|
* `generateContract`, whose Zod schemas are server-shaped by construction. Default `'client'`.
|
|
25
25
|
*/
|
|
26
26
|
target?: TsRenderTarget;
|
|
27
|
+
/** Model names that carry a `decimal`, directly or transitively. */
|
|
28
|
+
modelsWithDecimal?: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Emit `reviveX()` hydration functions alongside the schemas. Set only for SDK type files: a
|
|
31
|
+
* server handler receives decimals already parsed by `_ZodDecimal`, so it has nothing to revive.
|
|
32
|
+
*/
|
|
33
|
+
emitRevivers?: boolean;
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* Compute which models need Input variants, including transitive dependencies.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-contract.d.ts","sourceRoot":"","sources":["../src/codegen-contract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EAET,gBAAgB,EAWhB,UAAU,EACb,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-contract.d.ts","sourceRoot":"","sources":["../src/codegen-contract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EAET,gBAAgB,EAWhB,UAAU,EACb,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIrD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAStD;AAID,4GAA4G;AAC5G,MAAM,WAAW,sBAAsB;IACnC,sDAAsD;IACtD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,6GAA6G;IAC7G,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,oEAAoE;IACpE,iBAAiB,CAAC,EAAE,GAAG,CAAC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AC1E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CA4BvG;AAmCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CA6D/D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAgB3F;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-mcp.d.ts","sourceRoot":"","sources":["../src/codegen-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA8E,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-mcp.d.ts","sourceRoot":"","sources":["../src/codegen-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA8E,MAAM,mBAAmB,CAAC;AAUhI,MAAM,WAAW,iBAAiB;IAC9B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,qDAAqD;IACrD,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,yFAAyF;IACzF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,eAAe,UAAQ,GAAG,OAAO,CASnF;AA+VD,0GAA0G;AAC1G,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CA2DzF;AAED,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IAC/B,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAe3E;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAuBzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-operation.d.ts","sourceRoot":"","sources":["../src/codegen-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,WAAW,EACX,eAAe,EAGf,gBAAgB,EAInB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-operation.d.ts","sourceRoot":"","sources":["../src/codegen-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,WAAW,EACX,eAAe,EAGf,gBAAgB,EAInB,MAAM,mBAAmB,CAAC;AAkC3B;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,GAAG,OAAO,CA0E5F;AAID,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,qFAAqF;IACrF,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAgHnF;AAwSD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAY7H;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,eAAe,GAAG,MAAM,CAqBzE;AA0aD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWnD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAgBpE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAkFnG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ContractTypeNode, ModelNode } from '@contractkit/core';
|
|
2
|
+
/**
|
|
3
|
+
* Emitters for the `reviveX` functions that rehydrate `decimal` fields in an SDK response.
|
|
4
|
+
*
|
|
5
|
+
* A decimal arrives as a quoted JSON string, but the generated types say `Decimal`, so something
|
|
6
|
+
* has to construct one. The SDK cannot do it the way `bigint` does — `bigIntReviver` works only
|
|
7
|
+
* because bigint invented a tagged `"123n"` wire encoding, and `"10.50"` is indistinguishable from
|
|
8
|
+
* an ordinary string without knowing the schema. Nor can it re-parse the response through the Zod
|
|
9
|
+
* schema: `XOutput` is a `z.output<>` type alias with no runtime value behind it, and models
|
|
10
|
+
* default to `z.strictObject`, so any field the server added would throw in every deployed client.
|
|
11
|
+
*
|
|
12
|
+
* So the knowledge lives in generated code instead: one function per model that walks to the field
|
|
13
|
+
* positions a decimal can occupy and converts in place. Mutating rather than rebuilding keeps the
|
|
14
|
+
* cost proportional to the number of decimal fields, and preserves unknown server-added keys —
|
|
15
|
+
* the forward compatibility a strict re-parse would destroy.
|
|
16
|
+
*
|
|
17
|
+
* Emitted from the AST, so zod mode and plain-types mode produce identical runtime behaviour.
|
|
18
|
+
*/
|
|
19
|
+
export interface ReviveCodegenOptions {
|
|
20
|
+
/** Models that carry a decimal, directly or transitively. Only these get a reviver. */
|
|
21
|
+
modelsWithDecimal: Set<string>;
|
|
22
|
+
/** Models with an `Output` variant, which need a second reviver keyed by the output casing. */
|
|
23
|
+
modelsWithOutput?: Set<string>;
|
|
24
|
+
/** Every model in scope, for resolving discriminated-union members to their literal tag. */
|
|
25
|
+
modelMap?: Map<string, ModelNode>;
|
|
26
|
+
}
|
|
27
|
+
/** The per-file coercion helper. Emitted once in any file that declares a reviver. */
|
|
28
|
+
export declare const DECIMAL_COERCE_DECL: string[];
|
|
29
|
+
/** `reviveInvoice` / `reviveInvoiceOutput`. */
|
|
30
|
+
export declare function reviveFnName(model: string, variant?: 'base' | 'output'): string;
|
|
31
|
+
/** Whether a type reaches a decimal, following refs through `modelsWithDecimal`. */
|
|
32
|
+
export declare function typeReachesDecimal(type: ContractTypeNode, opts: ReviveCodegenOptions): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* A standalone reviver for an arbitrary type node — used for a response body that is not a plain
|
|
35
|
+
* model reference (an inline object, a record, a tuple), where there is no `reviveX` to call.
|
|
36
|
+
*
|
|
37
|
+
* Returns `null` when the type holds no decimal, so the caller emits nothing at all.
|
|
38
|
+
*/
|
|
39
|
+
export declare function renderInlineReviver(fnName: string, tsType: string, type: ContractTypeNode, opts: ReviveCodegenOptions, variant?: 'base' | 'output'): string[] | null;
|
|
40
|
+
/** The `reviveX` (and `reviveXOutput`) declarations for one model, or `[]` if it holds no decimal. */
|
|
41
|
+
export declare function renderReviveFunctions(model: ModelNode, opts: ReviveCodegenOptions): string[];
|
|
42
|
+
//# sourceMappingURL=codegen-revive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-revive.d.ts","sourceRoot":"","sources":["../src/codegen-revive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAa,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEhF;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,oBAAoB;IACjC,uFAAuF;IACvF,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,+FAA+F;IAC/F,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACrC;AAED,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,UAW/B,CAAC;AAEF,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG,QAAiB,GAAG,MAAM,CAEvF;AAQD,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAuB9F;AA0JD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,MAAM,GAAG,QAAmB,GACtC,MAAM,EAAE,GAAG,IAAI,CAajB;AAED,sGAAsG;AACtG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAQ5F"}
|
package/dist/codegen-sdk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OpRootNode } from '@contractkit/core';
|
|
1
|
+
import type { OpRootNode, ModelNode } from '@contractkit/core';
|
|
2
2
|
/** Options shared by every SDK code-generation entry point. */
|
|
3
3
|
export interface SdkCodegenOptions {
|
|
4
4
|
/** Template for type import paths when `modelOutPaths` is not provided. Supports `{module}` and `{base}`. */
|
|
@@ -13,6 +13,10 @@ export interface SdkCodegenOptions {
|
|
|
13
13
|
modelsWithInput?: Set<string>;
|
|
14
14
|
/** Set of model names that have Output variants (models with format(output=...)) */
|
|
15
15
|
modelsWithOutput?: Set<string>;
|
|
16
|
+
/** Model names carrying a `decimal`, whose response bodies need rehydrating client-side. */
|
|
17
|
+
modelsWithDecimal?: Set<string>;
|
|
18
|
+
/** Every model in scope, for resolving discriminated-union members inside an inline reviver. */
|
|
19
|
+
modelMap?: Map<string, ModelNode>;
|
|
16
20
|
/**
|
|
17
21
|
* Whether to emit SDK methods for operations marked `internal`. Defaults to `false` —
|
|
18
22
|
* internal ops are omitted from the SDK so consumers don't pick them up. Set to `true`
|
|
@@ -41,16 +45,22 @@ export declare function hasPublicOperations(root: OpRootNode, includeInternal?:
|
|
|
41
45
|
export declare function generateSdk(root: OpRootNode, options?: SdkCodegenOptions): string;
|
|
42
46
|
/**
|
|
43
47
|
* Render the method-block lines for an operation file as if they were declared inside a
|
|
44
|
-
* client class.
|
|
45
|
-
* level, with leading blank lines between methods) plus the set of method names emitted —
|
|
46
|
-
* the caller uses the names to detect cross-file collisions when multiple files contribute
|
|
47
|
-
* to the same area-level client.
|
|
48
|
+
* client class.
|
|
48
49
|
*
|
|
49
50
|
* Skips operations marked `internal` unless `options.includeInternal` is set.
|
|
51
|
+
*
|
|
52
|
+
* @returns `lines`, one consolidated array pre-indented for class-body level with leading blank
|
|
53
|
+
* lines between methods; `methodNames`, used by the caller to detect cross-file collisions when
|
|
54
|
+
* several files contribute to the same area-level client; `preludeLines`, module-level
|
|
55
|
+
* declarations the methods reference (decimal revivers and their `__dec` helper) which the caller
|
|
56
|
+
* must splice in above the class; and `needsDecimalImport`, true when those declarations require
|
|
57
|
+
* `import { Decimal } from 'decimal.js'` in the emitting file.
|
|
50
58
|
*/
|
|
51
59
|
export declare function generateClientMethods(root: OpRootNode, options: SdkCodegenOptions): {
|
|
52
60
|
lines: string[];
|
|
53
61
|
methodNames: string[];
|
|
62
|
+
preludeLines: string[];
|
|
63
|
+
needsDecimalImport: boolean;
|
|
54
64
|
};
|
|
55
65
|
/**
|
|
56
66
|
* Module-level `…ErrorBody` aliases for every operation whose thrown statuses declare a body.
|
|
@@ -87,8 +97,10 @@ export declare function generateSdkOptions(): string;
|
|
|
87
97
|
export interface SdkScaffoldDeps {
|
|
88
98
|
/** Zod schema files are emitted (`config.zod`) — the SDK imports `zod`. */
|
|
89
99
|
zod: boolean;
|
|
90
|
-
/** Any covered model uses a `date`/`time`/`datetime`/`interval` scalar — the SDK imports `luxon`. */
|
|
100
|
+
/** Any covered model uses a `date`/`time`/`datetime`/`duration`/`interval` scalar — the SDK imports `luxon`. */
|
|
91
101
|
luxon: boolean;
|
|
102
|
+
/** Any covered model uses a `decimal` scalar — the SDK imports `decimal.js`. */
|
|
103
|
+
decimal: boolean;
|
|
92
104
|
}
|
|
93
105
|
/**
|
|
94
106
|
* Generate a starter `package.json` for a generated SDK package. Emitted with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-sdk.d.ts","sourceRoot":"","sources":["../src/codegen-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,
|
|
1
|
+
{"version":3,"file":"codegen-sdk.d.ts","sourceRoot":"","sources":["../src/codegen-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EAQV,SAAS,EAEZ,MAAM,mBAAmB,CAAC;AA6D3B,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAC9B,6GAA6G;IAC7G,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,8GAA8G;IAC9G,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,4FAA4F;IAC5F,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAChC,gGAAgG;IAChG,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClC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AC5C,MAAM,WAAW,eAAe;IAC5B,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,+HAA+H;IAC/H,OAAO,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,2EAA2E;IAC3E,cAAc,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,EAAE,CAAC;IAClE,yEAAyE;IACzE,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAqJjE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAyCvE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The emitted decimal.js runtime shared by every generator that renders a `decimal` scalar.
|
|
3
|
+
*
|
|
4
|
+
* `_ZodBinary`/`_ZodDatetime`/`_ZodInterval` are duplicated as literals across codegen-contract,
|
|
5
|
+
* codegen-operation and codegen-mcp, and have already drifted once (the three files emit their
|
|
6
|
+
* luxon import lists in two different orders). The decimal runtime is defined once here so the
|
|
7
|
+
* three call sites cannot disagree about it; each still decides *whether* to emit it with its own
|
|
8
|
+
* detection strategy, which is the part that legitimately differs between them.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The decimal.js import — **named, not default**.
|
|
12
|
+
*
|
|
13
|
+
* `decimal.d.ts` declares `Decimal` three times over: a class, a namespace, and a function, with
|
|
14
|
+
* `export default Decimal` alongside. Under the `NodeNext` resolution the scaffolded SDK uses
|
|
15
|
+
* (`module: NodeNext` + `"type": "module"`), the default export resolves to the *namespace*
|
|
16
|
+
* meaning, so `import Decimal from 'decimal.js'` fails to compile with "Cannot use namespace
|
|
17
|
+
* 'Decimal' as a type" and "Property 'set' does not exist". The named import binds the merged
|
|
18
|
+
* class and is the only form that typechecks.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DECIMAL_IMPORT = "import { Decimal } from 'decimal.js';";
|
|
21
|
+
/**
|
|
22
|
+
* Global decimal.js configuration, emitted in **every** file that imports `Decimal` — plain-types
|
|
23
|
+
* mode included, where there is no Zod schema but `String(value)` and `JSON.stringify` still run.
|
|
24
|
+
*
|
|
25
|
+
* Load-bearing, not cosmetic. decimal.js switches to exponential
|
|
26
|
+
* notation outside `toExpNeg`/`toExpPos` (defaults -7/21), so without it `new Decimal('0.00000001')`
|
|
27
|
+
* serializes as `"1e-8"` and any peer validating `^-?\d+(\.\d+)?$` rejects it. It is the only lever
|
|
28
|
+
* that reaches the `JSON.stringify` Koa runs over `ctx.body`, which we do not otherwise control.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export declare const DECIMAL_CONFIG_LINE = "Decimal.set({ toExpNeg: -9e15, toExpPos: 9e15 });";
|
|
32
|
+
/**
|
|
33
|
+
* The Zod schema for a `decimal`.
|
|
34
|
+
*
|
|
35
|
+
* Deliberately has no output `.transform()`. `isRevalidatable` in codegen-operation treats every
|
|
36
|
+
* scalar as idempotent under re-parse — the assumption `server.validateResponses` rests on — and
|
|
37
|
+
* preprocess passes an already-`Decimal` value through untouched, so it holds.
|
|
38
|
+
*
|
|
39
|
+
* A raw JSON number fails validation rather than being coerced: by the time one reaches us it has
|
|
40
|
+
* already been through an IEEE-754 double, which is the loss this scalar exists to prevent. Bad
|
|
41
|
+
* strings are returned unchanged from preprocess rather than throwing, so they surface as an
|
|
42
|
+
* ordinary Zod issue instead of a `DecimalError` escaping the parse.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DECIMAL_ZOD_SCHEMA_LINE = "const _ZodDecimal = z.preprocess((val) => { if (typeof val !== 'string') return val; try { return new Decimal(val); } catch { return val; } }, z.custom<Decimal>((val) => Decimal.isDecimal(val), { message: 'Must be an exact decimal sent as a quoted string, e.g. \"1250.00\"' }));";
|
|
45
|
+
/** The decimal runtime for a file that also holds Zod schemas, in emission order. */
|
|
46
|
+
export declare const DECIMAL_PRELUDE_LINES: readonly string[];
|
|
47
|
+
//# sourceMappingURL=decimal-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal-runtime.d.ts","sourceRoot":"","sources":["../src/decimal-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,0CAA0C,CAAC;AAEtE;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AAEvF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,2RAAyR,CAAC;AAE9T,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAmD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,8 @@ export interface SdkConfig {
|
|
|
42
42
|
* write-once: the files are created only when absent and are never overwritten or
|
|
43
43
|
* cleaned up on later builds, so any edits you make to them are preserved.
|
|
44
44
|
* Dependency ranges are derived from the contracts (always `zod` when `zod: true`;
|
|
45
|
-
* `luxon` when any covered model uses a date/time/datetime/interval scalar
|
|
45
|
+
* `luxon` when any covered model uses a date/time/datetime/duration/interval scalar;
|
|
46
|
+
* `decimal.js` when any uses a decimal).
|
|
46
47
|
*/
|
|
47
48
|
scaffold?: boolean;
|
|
48
49
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,iBAAiB,EAQpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,iBAAiB,EAQpB,MAAM,mBAAmB,CAAC;AAgD3B,gFAAgF;AAChF,MAAM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