@prunellejs/cms 0.7.3 → 0.8.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 +2 -2
- package/src/schema.ts +13 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Schema-driven dev-only CMS plugin for Prunelle Markdown content collections",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"directory": "packages/plugin-cms"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"prunelle": "^0.
|
|
24
|
+
"prunelle": "^0.8.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/schema.ts
CHANGED
|
@@ -87,32 +87,31 @@ function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
|
87
87
|
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// A schema library whose JSON Schema export throws is treated as having none.
|
|
91
|
+
function exportedOrUndefined(exportSchema: () => unknown): unknown {
|
|
92
|
+
try {
|
|
93
|
+
return exportSchema()
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
/** Extracts a raw JSON Schema object from a Standard Schema, returning `undefined` when unavailable. */
|
|
91
101
|
export function extractJsonSchema(schema: StandardSchemaV1): Record<string, unknown> | undefined {
|
|
92
102
|
const candidate = schema as unknown as SchemaCandidate
|
|
93
103
|
const stdInput = candidate['~standard']?.jsonSchema?.input
|
|
94
104
|
if (typeof stdInput === 'function') {
|
|
95
105
|
for (const target of ['draft-2020-12', 'draft-07']) {
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
result = stdInput({ target })
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
result = err instanceof Error ? undefined : undefined
|
|
102
|
-
}
|
|
106
|
+
const result = exportedOrUndefined(() => stdInput({ target }))
|
|
103
107
|
if (isPlainRecord(result))
|
|
104
108
|
return result
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
if (typeof candidate.toJSONSchema === 'function') {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
result = candidate.toJSONSchema()
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
result = err instanceof Error ? undefined : undefined
|
|
115
|
-
}
|
|
113
|
+
const toJSONSchema = candidate.toJSONSchema
|
|
114
|
+
const result = exportedOrUndefined(() => toJSONSchema.call(candidate))
|
|
116
115
|
if (isPlainRecord(result))
|
|
117
116
|
return result
|
|
118
117
|
}
|