@ts-pf/docs 0.1.1 → 0.1.3
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
CHANGED
|
@@ -69,6 +69,8 @@ import { writeFileSync } from 'node:fs'
|
|
|
69
69
|
writeFileSync('contract.d.ts', emit(catalog(contract, { prefix: '/rpc' })))
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
`emit()` prints JSDoc from `docs()`. Other `.meta()` keys stay on the catalog JSON.
|
|
73
|
+
|
|
72
74
|
Serve the JSON in **userland**, outside the RPC prefix (`GET /rpc/...` is a procedure miss, not a spec):
|
|
73
75
|
|
|
74
76
|
```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.d.ts","sourceRoot":"","sources":["../../src/converters/typebox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"typebox.d.ts","sourceRoot":"","sources":["../../src/converters/typebox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAgB5D,eAAO,MAAM,0BAA0B,EAAE,mBAgBxC,CAAA"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const JSON_SCHEMA_TYPES = new Set([
|
|
2
|
+
'string',
|
|
3
|
+
'number',
|
|
4
|
+
'integer',
|
|
5
|
+
'boolean',
|
|
6
|
+
'null',
|
|
7
|
+
'object',
|
|
8
|
+
'array',
|
|
9
|
+
]);
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
1
13
|
export const typeboxJsonSchemaConverter = {
|
|
2
14
|
vendor: 'typebox',
|
|
3
15
|
accept(schema) {
|
|
@@ -7,7 +19,68 @@ export const typeboxJsonSchemaConverter = {
|
|
|
7
19
|
typeof schema['~kind'] === 'string');
|
|
8
20
|
},
|
|
9
21
|
convert(schema) {
|
|
10
|
-
|
|
22
|
+
const cloned = JSON.parse(JSON.stringify(schema));
|
|
23
|
+
rewriteNamedRefs(cloned);
|
|
24
|
+
assertJsonSchemaTypes(cloned);
|
|
25
|
+
return cloned;
|
|
11
26
|
},
|
|
12
27
|
};
|
|
28
|
+
function rewriteNamedRefs(root) {
|
|
29
|
+
const defsKey = isRecord(root.$defs)
|
|
30
|
+
? '$defs'
|
|
31
|
+
: isRecord(root.definitions)
|
|
32
|
+
? 'definitions'
|
|
33
|
+
: undefined;
|
|
34
|
+
if (defsKey === undefined) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const names = new Set(Object.keys(root[defsKey]));
|
|
38
|
+
rewrite(root, names, defsKey);
|
|
39
|
+
}
|
|
40
|
+
function rewrite(value, names, defsKey) {
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
for (const item of value) {
|
|
43
|
+
rewrite(item, names, defsKey);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!isRecord(value)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value.$ref === 'string' && names.has(value.$ref)) {
|
|
51
|
+
value.$ref = `#/${defsKey}/${escapePointer(value.$ref)}`;
|
|
52
|
+
}
|
|
53
|
+
for (const child of Object.values(value)) {
|
|
54
|
+
rewrite(child, names, defsKey);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function assertJsonSchemaTypes(value) {
|
|
58
|
+
if (Array.isArray(value)) {
|
|
59
|
+
for (const item of value) {
|
|
60
|
+
assertJsonSchemaTypes(item);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(value)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value.type === 'string') {
|
|
68
|
+
if (!JSON_SCHEMA_TYPES.has(value.type)) {
|
|
69
|
+
throw new Error(`TypeBox type "${value.type}" is not JSON Schema`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (Array.isArray(value.type)) {
|
|
73
|
+
for (const item of value.type) {
|
|
74
|
+
if (typeof item === 'string' && !JSON_SCHEMA_TYPES.has(item)) {
|
|
75
|
+
throw new Error(`TypeBox type "${item}" is not JSON Schema`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const child of Object.values(value)) {
|
|
80
|
+
assertJsonSchemaTypes(child);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function escapePointer(value) {
|
|
84
|
+
return value.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
85
|
+
}
|
|
13
86
|
//# sourceMappingURL=typebox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.js","sourceRoot":"","sources":["../../src/converters/typebox.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAAwB;IAC7D,MAAM,EAAE,SAAS;IACjB,MAAM,CAAC,MAAM;QACX,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,KAAK,IAAI;YACf,OAAO,IAAI,MAAM;YACjB,OAAQ,MAA+B,CAAC,OAAO,CAAC,KAAK,QAAQ,CAC9D,CAAA;IACH,CAAC;IACD,OAAO,CAAC,MAAM;QACZ,
|
|
1
|
+
{"version":3,"file":"typebox.js","sourceRoot":"","sources":["../../src/converters/typebox.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,MAAM;IACN,QAAQ;IACR,OAAO;CACR,CAAC,CAAA;AAEF,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,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BAC7D,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,sBAAsB,CAAC,CAAA;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACzC,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-pf/docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Opt-in procedure catalog from a contract (docs, catalog)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-pf",
|
|
@@ -28,18 +28,12 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
-
"types": "./
|
|
32
|
-
"import": "./
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
"exports": {
|
|
38
|
-
".": {
|
|
39
|
-
"types": "./dist/index.d.ts",
|
|
40
|
-
"import": "./dist/index.js"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
36
|
+
"access": "public"
|
|
43
37
|
},
|
|
44
38
|
"files": [
|
|
45
39
|
"dist",
|
|
@@ -53,9 +47,9 @@
|
|
|
53
47
|
},
|
|
54
48
|
"dependencies": {
|
|
55
49
|
"@standard-schema/spec": "^1.0.0",
|
|
56
|
-
"@ts-pf/contract": "0.1.
|
|
57
|
-
"@ts-pf/http": "0.1.
|
|
58
|
-
"@ts-pf/protocol": "0.1.
|
|
50
|
+
"@ts-pf/contract": "0.1.2",
|
|
51
|
+
"@ts-pf/http": "0.1.1",
|
|
52
|
+
"@ts-pf/protocol": "0.1.1"
|
|
59
53
|
},
|
|
60
54
|
"peerDependencies": {
|
|
61
55
|
"typebox": "^1.0.0"
|
|
@@ -66,7 +60,7 @@
|
|
|
66
60
|
}
|
|
67
61
|
},
|
|
68
62
|
"devDependencies": {
|
|
69
|
-
"@ts-pf/stream": "0.1.
|
|
63
|
+
"@ts-pf/stream": "0.1.2",
|
|
70
64
|
"typebox": "^1.3.24",
|
|
71
65
|
"zod": "^4.0.0"
|
|
72
66
|
}
|
|
@@ -38,7 +38,7 @@ if (url.pathname === '/catalog.json') {
|
|
|
38
38
|
## Pair with
|
|
39
39
|
|
|
40
40
|
- OpenAPI: `ts-pf-openapi`
|
|
41
|
-
- Split-repo `.d.ts`: `ts-pf-codegen`
|
|
41
|
+
- Split-repo `.d.ts`: `ts-pf-codegen` (`emit()` prints JSDoc from `docs()`)
|
|
42
42
|
- Descriptions live on existing `.meta()` — not `.docs()` on the builder
|
|
43
43
|
|
|
44
44
|
## Don't
|