@servable/tools 2.1.0 → 2.2.0
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/package.json +1 -1
- package/src/schema/types/index.js +17 -5
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"source": "src/index.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
-
"version": "2.
|
|
7
|
+
"version": "2.2.0",
|
|
8
8
|
"description": "Servable tools is a utility that builds a protocol's manifest and documents it.",
|
|
9
9
|
"author": "Servable Community",
|
|
10
10
|
"license": "ISC",
|
|
@@ -65,7 +65,11 @@ export interface ServableRelation<T> {
|
|
|
65
65
|
/**
|
|
66
66
|
* Generates one TypeScript interface per class in a `servable.schema.json` artifact, each
|
|
67
67
|
* field typed from its Parse field type (`Pointer`/`Relation` narrowed to the target class
|
|
68
|
-
* when that class is also present in the artifact)
|
|
68
|
+
* when that class is also present in the artifact) - plus a merge into
|
|
69
|
+
* @servable/parse-server-engine's `ServableClassMap`, keyed by class name, powering
|
|
70
|
+
* `Servable.App.Typed.object('ClassName')`/`.query('ClassName')` (see that package's own
|
|
71
|
+
* global.d.ts for why that's a separate, opt-in surface rather than a change to `Object`/`Query`
|
|
72
|
+
* themselves).
|
|
69
73
|
*
|
|
70
74
|
* @param {{ classes: Array<{ className: string, fields: Record<string, { type: string, targetClass?: string }> }> }} artifact
|
|
71
75
|
* - a normalized `servable.schema.json` (or anything with the same `classes` shape).
|
|
@@ -75,9 +79,9 @@ export default function generateSchemaTypes(artifact) {
|
|
|
75
79
|
const classes = artifact?.classes || []
|
|
76
80
|
const knownClassNames = new Set(classes.map(c => c.className))
|
|
77
81
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
const sortedClasses = classes.slice().sort((a, b) => a.className.localeCompare(b.className))
|
|
83
|
+
|
|
84
|
+
const interfaces = sortedClasses
|
|
81
85
|
.map(({ className, fields = {} }) => {
|
|
82
86
|
const fieldLines = Object.entries(fields)
|
|
83
87
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
@@ -93,5 +97,13 @@ export default function generateSchemaTypes(artifact) {
|
|
|
93
97
|
})
|
|
94
98
|
.join('\n\n')
|
|
95
99
|
|
|
96
|
-
|
|
100
|
+
// Omitted entirely (rather than merged as an empty interface) when there are no classes at
|
|
101
|
+
// all - matches generateProtocolResourceTypes()'s own ServableServiceCallMap handling.
|
|
102
|
+
const classMapMerge = sortedClasses.length
|
|
103
|
+
? `declare global {\n interface ServableClassMap {\n${sortedClasses
|
|
104
|
+
.map(({ className }) => ` ${JSON.stringify(className)}: ${className}`)
|
|
105
|
+
.join('\n')}\n }\n}\n`
|
|
106
|
+
: ''
|
|
107
|
+
|
|
108
|
+
return [HEADER, interfaces, classMapMerge].filter(Boolean).join('\n')
|
|
97
109
|
}
|