@effected/markdown 0.21.0 → 0.22.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/FrontmatterResolver.js +5 -18
- package/index.d.ts +24 -9
- package/package.json +2 -2
package/FrontmatterResolver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Predicate, Result, Schema } from "effect";
|
|
1
|
+
import { Effect, Option, Predicate, Result, Schema } from "effect";
|
|
2
2
|
|
|
3
3
|
// src/FrontmatterResolver.ts
|
|
4
4
|
/**
|
|
@@ -189,24 +189,11 @@ var SchemaResolver = class SchemaResolver {
|
|
|
189
189
|
value
|
|
190
190
|
}));
|
|
191
191
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Extract and classify the `$schema` declaration from decoded frontmatter
|
|
194
|
-
* data.
|
|
195
|
-
*
|
|
196
|
-
* @remarks
|
|
197
|
-
* Non-mapping data and a mapping without a `$schema` key both carry no
|
|
198
|
-
* declaration: the result succeeds with `undefined` by default, or fails
|
|
199
|
-
* with {@link SchemaDeclarationMissingError} under `requireDeclaration`.
|
|
200
|
-
*
|
|
201
|
-
* @param data - The decoded frontmatter data.
|
|
202
|
-
* @param options - `requireDeclaration` makes a missing `$schema` a typed
|
|
203
|
-
* error.
|
|
204
|
-
* @returns The classified declaration, `undefined` when absent and
|
|
205
|
-
* tolerated, or the typed error.
|
|
206
|
-
*/
|
|
207
192
|
static declarationOf(data, options) {
|
|
208
|
-
|
|
209
|
-
|
|
193
|
+
const required = options?.requireDeclaration === true;
|
|
194
|
+
if (!Predicate.isObject(data) || !Object.hasOwn(data, "$schema")) return required ? Result.fail(new SchemaDeclarationMissingError()) : Result.succeed(Option.none());
|
|
195
|
+
const classified = SchemaResolver.classify(data.$schema);
|
|
196
|
+
return required ? classified : Result.map(classified, Option.some);
|
|
210
197
|
}
|
|
211
198
|
/**
|
|
212
199
|
* The package's one built-in resolver: a name-keyed registry with
|
package/index.d.ts
CHANGED
|
@@ -2251,19 +2251,34 @@ export declare class SchemaResolver {
|
|
|
2251
2251
|
* data.
|
|
2252
2252
|
*
|
|
2253
2253
|
* @remarks
|
|
2254
|
-
*
|
|
2255
|
-
*
|
|
2256
|
-
* with
|
|
2254
|
+
* A lookup that can miss, so by default the success channel is an
|
|
2255
|
+
* `Option`: non-mapping data and a mapping without a `$schema` key both
|
|
2256
|
+
* carry no declaration and succeed with `Option.none()`, and the error
|
|
2257
|
+
* union is {@link SchemaDeclarationInvalidError} alone. Under
|
|
2258
|
+
* `requireDeclaration: true` the miss becomes a typed
|
|
2259
|
+
* {@link SchemaDeclarationMissingError} and the success is the bare
|
|
2260
|
+
* declaration, since it is statically always present. The two overloads
|
|
2261
|
+
* keep each caller's types honest: no `Option` to unwrap when the
|
|
2262
|
+
* declaration is required, no `SchemaDeclarationMissingError` to handle
|
|
2263
|
+
* when it is not. A present key is classified by
|
|
2264
|
+
* {@link SchemaResolver.classify}, and its
|
|
2265
|
+
* {@link SchemaDeclarationInvalidError} propagates unchanged. Hand an
|
|
2266
|
+
* optional declaration to a {@link FrontmatterSchemaResolver} with
|
|
2267
|
+
* `Option.getOrUndefined`, since the seam takes the absent case as
|
|
2268
|
+
* `undefined`; a required one passes straight through.
|
|
2257
2269
|
*
|
|
2258
2270
|
* @param data - The decoded frontmatter data.
|
|
2259
|
-
* @param options - `requireDeclaration` makes a missing `$schema` a
|
|
2260
|
-
* error.
|
|
2261
|
-
* @returns The classified declaration
|
|
2262
|
-
*
|
|
2271
|
+
* @param options - `requireDeclaration: true` makes a missing `$schema` a
|
|
2272
|
+
* typed error and narrows the success to the declaration itself.
|
|
2273
|
+
* @returns The classified declaration under `requireDeclaration`;
|
|
2274
|
+
* otherwise `Option.some` of it, or `Option.none()` when absent.
|
|
2263
2275
|
*/
|
|
2276
|
+
static declarationOf(data: unknown, options: {
|
|
2277
|
+
readonly requireDeclaration: true;
|
|
2278
|
+
}): Result.Result<SchemaDeclaration, SchemaDeclarationInvalidError | SchemaDeclarationMissingError>;
|
|
2264
2279
|
static declarationOf(data: unknown, options?: {
|
|
2265
|
-
readonly requireDeclaration?:
|
|
2266
|
-
}): Result.Result<SchemaDeclaration
|
|
2280
|
+
readonly requireDeclaration?: false;
|
|
2281
|
+
}): Result.Result<Option.Option<SchemaDeclaration>, SchemaDeclarationInvalidError>;
|
|
2267
2282
|
/**
|
|
2268
2283
|
* The package's one built-in resolver: a name-keyed registry with
|
|
2269
2284
|
* exact version-segment resolution.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "CommonMark and GFM markdown parse, edit and transform schemas for Effect",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@effected/jsonc": "^0.20.0",
|
|
43
43
|
"@effected/toml": "^0.16.0",
|
|
44
|
-
"@effected/yaml": "^0.
|
|
44
|
+
"@effected/yaml": "^0.25.0",
|
|
45
45
|
"effect": "^4.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|