@platecms/delta-cast 1.2.0 → 1.3.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/lib/schemas/schema.json +12 -41
- package/src/lib/schemas/schema.ts +7 -20
- package/src/lib/validate-cast.spec.ts +22 -25
- package/src/lib/validate-cast.ts +12 -14
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-cast",
|
|
3
3
|
"description": "Package containing the definition of CAST",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"tslib": "2.8.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@platecms/delta-plate-resource-notation": "1.
|
|
25
|
+
"@platecms/delta-plate-resource-notation": "1.3.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -52,13 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"type": "object"
|
|
54
54
|
},
|
|
55
|
-
"
|
|
55
|
+
"CastSuggestion": {
|
|
56
56
|
"description": "A CAS suggestion node.",
|
|
57
57
|
"properties": {
|
|
58
58
|
"data": {
|
|
59
59
|
"$ref": "#/definitions/Data",
|
|
60
60
|
"description": "Info from the ecosystem."
|
|
61
61
|
},
|
|
62
|
+
"endIndex": {
|
|
63
|
+
"type": "number"
|
|
64
|
+
},
|
|
62
65
|
"message": {
|
|
63
66
|
"description": "A message explaining the suggestion.",
|
|
64
67
|
"type": "string"
|
|
@@ -78,15 +81,15 @@
|
|
|
78
81
|
"$ref": "#/definitions/Position",
|
|
79
82
|
"description": "Position of a node in a source document.\n\nNodes that are generated (not in the original source document) must not\nhave a position."
|
|
80
83
|
},
|
|
84
|
+
"startIndex": {
|
|
85
|
+
"type": "number"
|
|
86
|
+
},
|
|
81
87
|
"suggested": {
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"$ref": "#/definitions/Content"
|
|
85
|
-
},
|
|
86
|
-
"type": "array"
|
|
88
|
+
"$ref": "#/definitions/InterpolatedContentValue",
|
|
89
|
+
"description": "The suggested replacement content."
|
|
87
90
|
},
|
|
88
91
|
"type": {
|
|
89
|
-
"const": "
|
|
92
|
+
"const": "castSuggestion",
|
|
90
93
|
"description": "Node type.",
|
|
91
94
|
"type": "string"
|
|
92
95
|
}
|
|
@@ -143,7 +146,7 @@
|
|
|
143
146
|
"$ref": "#/definitions/ListItem"
|
|
144
147
|
},
|
|
145
148
|
{
|
|
146
|
-
"$ref": "#/definitions/
|
|
149
|
+
"$ref": "#/definitions/CastSuggestion"
|
|
147
150
|
},
|
|
148
151
|
{
|
|
149
152
|
"$ref": "#/definitions/Bold"
|
|
@@ -174,38 +177,9 @@
|
|
|
174
177
|
},
|
|
175
178
|
{
|
|
176
179
|
"$ref": "#/definitions/InternalLink"
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
"$ref": "#/definitions/ContentValueSuggestion"
|
|
180
180
|
}
|
|
181
181
|
]
|
|
182
182
|
},
|
|
183
|
-
"ContentValueSuggestion": {
|
|
184
|
-
"properties": {
|
|
185
|
-
"data": {
|
|
186
|
-
"$ref": "#/definitions/Data",
|
|
187
|
-
"description": "Info from the ecosystem."
|
|
188
|
-
},
|
|
189
|
-
"position": {
|
|
190
|
-
"$ref": "#/definitions/Position",
|
|
191
|
-
"description": "Position of a node in a source document.\n\nNodes that are generated (not in the original source document) must not\nhave a position."
|
|
192
|
-
},
|
|
193
|
-
"prn": {
|
|
194
|
-
"description": "The PRN (identifier) of the referenced Content Value.",
|
|
195
|
-
"type": "string"
|
|
196
|
-
},
|
|
197
|
-
"type": {
|
|
198
|
-
"const": "contentValueSuggestion",
|
|
199
|
-
"description": "Node type.",
|
|
200
|
-
"type": "string"
|
|
201
|
-
},
|
|
202
|
-
"value": {
|
|
203
|
-
"$ref": "#/definitions/Root",
|
|
204
|
-
"description": "The nested CAST tree of the referenced Content Value."
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
"type": "object"
|
|
208
|
-
},
|
|
209
183
|
"Data": {
|
|
210
184
|
"description": "Info associated with nodes by the ecosystem.\n\nThis space is guaranteed to never be specified by unist or specifications\nimplementing unist.\nBut you can use it in utilities and plugins to store data.\n\nThis type can be augmented to register custom data.\nFor example:\n\n```ts\ndeclare module 'unist' {\n interface Data {\n // `someNode.data.myId` is typed as `number | undefined`\n myId?: number | undefined\n }\n}\n```",
|
|
211
185
|
"type": "object"
|
|
@@ -335,7 +309,7 @@
|
|
|
335
309
|
"InlineContent": {
|
|
336
310
|
"anyOf": [
|
|
337
311
|
{
|
|
338
|
-
"$ref": "#/definitions/
|
|
312
|
+
"$ref": "#/definitions/CastSuggestion"
|
|
339
313
|
},
|
|
340
314
|
{
|
|
341
315
|
"$ref": "#/definitions/Bold"
|
|
@@ -366,9 +340,6 @@
|
|
|
366
340
|
},
|
|
367
341
|
{
|
|
368
342
|
"$ref": "#/definitions/InternalLink"
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
"$ref": "#/definitions/ContentValueSuggestion"
|
|
372
343
|
}
|
|
373
344
|
]
|
|
374
345
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, Literal as UnistLiteral, Parent as UnistParent } from "unist";
|
|
2
2
|
|
|
3
|
-
export type Content = BlockContent |
|
|
3
|
+
export type Content = BlockContent | CastSuggestion | InlineContent;
|
|
4
4
|
|
|
5
5
|
export type BlockContent = BlockContentMap[keyof BlockContentMap];
|
|
6
6
|
export type InlineContent = InlineContentMap[keyof InlineContentMap];
|
|
@@ -26,8 +26,7 @@ export interface InlineContentMap {
|
|
|
26
26
|
contentValue: InterpolatedContentValue;
|
|
27
27
|
externalLink: ExternalLink;
|
|
28
28
|
internalLink: InternalLink;
|
|
29
|
-
|
|
30
|
-
contentValueSuggestion: ContentValueSuggestion;
|
|
29
|
+
castSuggestion: CastSuggestion;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export interface Parent extends UnistParent {
|
|
@@ -202,20 +201,6 @@ export interface InterpolatedContentValue extends Node {
|
|
|
202
201
|
value?: Root;
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
export interface ContentValueSuggestion extends Node {
|
|
206
|
-
type: "contentValueSuggestion";
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The PRN (identifier) of the referenced Content Value.
|
|
210
|
-
*/
|
|
211
|
-
prn: string;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* The nested CAST tree of the referenced Content Value.
|
|
215
|
-
*/
|
|
216
|
-
value?: Root;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
204
|
export interface ExternalLink extends Parent {
|
|
220
205
|
type: "externalLink";
|
|
221
206
|
|
|
@@ -252,8 +237,10 @@ export interface InternalLink extends Parent {
|
|
|
252
237
|
/**
|
|
253
238
|
* A CAS suggestion node.
|
|
254
239
|
*/
|
|
255
|
-
export interface
|
|
256
|
-
|
|
240
|
+
export interface CastSuggestion extends Node {
|
|
241
|
+
startIndex: number;
|
|
242
|
+
endIndex: number;
|
|
243
|
+
type: "castSuggestion";
|
|
257
244
|
|
|
258
245
|
/**
|
|
259
246
|
* The original content that is suggested to be replaced.
|
|
@@ -263,7 +250,7 @@ export interface CasSuggestion extends Node {
|
|
|
263
250
|
/**
|
|
264
251
|
* The suggested replacement content.
|
|
265
252
|
*/
|
|
266
|
-
suggested:
|
|
253
|
+
suggested: InterpolatedContentValue;
|
|
267
254
|
|
|
268
255
|
/**
|
|
269
256
|
* A message explaining the suggestion.
|
|
@@ -2,7 +2,7 @@ import { validateCast } from "./validate-cast";
|
|
|
2
2
|
import {
|
|
3
3
|
Blockquote,
|
|
4
4
|
Bold,
|
|
5
|
-
|
|
5
|
+
CastSuggestion,
|
|
6
6
|
Code,
|
|
7
7
|
Content,
|
|
8
8
|
ExternalLink,
|
|
@@ -103,12 +103,18 @@ describe("validateCast", () => {
|
|
|
103
103
|
[
|
|
104
104
|
"valid cas suggestion",
|
|
105
105
|
{
|
|
106
|
-
|
|
106
|
+
startIndex: 0,
|
|
107
|
+
endIndex: 10,
|
|
108
|
+
type: "castSuggestion",
|
|
107
109
|
original: [{ type: "text", value: "Original text" }],
|
|
108
|
-
suggested:
|
|
110
|
+
suggested: {
|
|
111
|
+
type: "contentValue",
|
|
112
|
+
value: { type: "root", children: [{ type: "text", value: "Suggested text" }] },
|
|
113
|
+
prn: "prn:plate-dev:1234:cms:test:abcd",
|
|
114
|
+
} satisfies InterpolatedContentValue,
|
|
109
115
|
message: "This is a suggestion",
|
|
110
116
|
method: "database; reusable",
|
|
111
|
-
} satisfies
|
|
117
|
+
} satisfies CastSuggestion,
|
|
112
118
|
],
|
|
113
119
|
])("validates a %s", (_, input) => {
|
|
114
120
|
const root: Root = { type: "root", children: [input as Content] };
|
|
@@ -334,24 +340,11 @@ describe("validateCast", () => {
|
|
|
334
340
|
type: "root",
|
|
335
341
|
children: [
|
|
336
342
|
{
|
|
337
|
-
|
|
343
|
+
startIndex: 0,
|
|
344
|
+
endIndex: 10,
|
|
345
|
+
type: "castSuggestion",
|
|
338
346
|
original: "notAnArray" as unknown as InlineContent[],
|
|
339
|
-
suggested:
|
|
340
|
-
message: "This is a suggestion",
|
|
341
|
-
method: "database; reusable",
|
|
342
|
-
},
|
|
343
|
-
],
|
|
344
|
-
} satisfies Root,
|
|
345
|
-
],
|
|
346
|
-
[
|
|
347
|
-
"invalid cas suggestion - suggested not an array",
|
|
348
|
-
{
|
|
349
|
-
type: "root",
|
|
350
|
-
children: [
|
|
351
|
-
{
|
|
352
|
-
type: "casSuggestion",
|
|
353
|
-
original: [{ type: "text", value: "Original text" }],
|
|
354
|
-
suggested: "notAnArray" as unknown as InlineContent[],
|
|
347
|
+
suggested: "notAnArray" as unknown as InterpolatedContentValue,
|
|
355
348
|
message: "This is a suggestion",
|
|
356
349
|
method: "database; reusable",
|
|
357
350
|
},
|
|
@@ -364,9 +357,11 @@ describe("validateCast", () => {
|
|
|
364
357
|
type: "root",
|
|
365
358
|
children: [
|
|
366
359
|
{
|
|
367
|
-
|
|
360
|
+
startIndex: 0,
|
|
361
|
+
endIndex: 10,
|
|
362
|
+
type: "castSuggestion",
|
|
368
363
|
original: [{ type: "text", value: "Original text" }],
|
|
369
|
-
suggested: [{ type: "text", value: "Suggested text" }],
|
|
364
|
+
suggested: [{ type: "text", value: "Suggested text" }] as unknown as InterpolatedContentValue,
|
|
370
365
|
message: null as unknown as string,
|
|
371
366
|
method: "database; reusable",
|
|
372
367
|
},
|
|
@@ -379,9 +374,11 @@ describe("validateCast", () => {
|
|
|
379
374
|
type: "root",
|
|
380
375
|
children: [
|
|
381
376
|
{
|
|
382
|
-
|
|
377
|
+
startIndex: 0,
|
|
378
|
+
endIndex: 10,
|
|
379
|
+
type: "castSuggestion",
|
|
383
380
|
original: [{ type: "text", value: "Original text" }],
|
|
384
|
-
suggested: [{ type: "text", value: "Suggested text" }],
|
|
381
|
+
suggested: [{ type: "text", value: "Suggested text" }] as unknown as InterpolatedContentValue,
|
|
385
382
|
message: "This is a suggestion",
|
|
386
383
|
method: 123 as unknown as string,
|
|
387
384
|
},
|
package/src/lib/validate-cast.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
CastSuggestion,
|
|
3
3
|
Code,
|
|
4
4
|
Content,
|
|
5
5
|
ExternalLink,
|
|
@@ -138,37 +138,35 @@ function assertValidInternalLink(value: unknown): asserts value is InternalLink
|
|
|
138
138
|
link.children.forEach(assertTextNode);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function
|
|
141
|
+
function assertValidCastSuggestion(value: unknown): asserts value is CastSuggestion {
|
|
142
142
|
assertNonNullObject(value);
|
|
143
143
|
|
|
144
|
-
const suggestion = value as
|
|
144
|
+
const suggestion = value as CastSuggestion;
|
|
145
145
|
|
|
146
146
|
// Validate required fields
|
|
147
147
|
if (!Array.isArray(suggestion.original)) {
|
|
148
|
-
throw new InvalidCastError("Invalid
|
|
148
|
+
throw new InvalidCastError("Invalid castSuggestion: original must be an array");
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
if (
|
|
152
|
-
throw new InvalidCastError("Invalid
|
|
151
|
+
if (suggestion.suggested === null) {
|
|
152
|
+
throw new InvalidCastError("Invalid castSuggestion: suggested must be an array");
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (typeof suggestion.message !== "string") {
|
|
156
|
-
throw new InvalidCastError("Invalid
|
|
156
|
+
throw new InvalidCastError("Invalid castSuggestion: message must be a string");
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
if (typeof suggestion.method !== "string") {
|
|
160
|
-
throw new InvalidCastError("Invalid
|
|
160
|
+
throw new InvalidCastError("Invalid castSuggestion: method must be a string");
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
164
164
|
suggestion.original.forEach(assertValidContent);
|
|
165
|
-
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
167
|
-
suggestion.suggested.forEach(assertValidContent);
|
|
168
165
|
}
|
|
169
166
|
|
|
170
|
-
function assertValidContent(value: unknown): asserts value is Content {
|
|
167
|
+
export function assertValidContent(value: unknown): asserts value is Content {
|
|
171
168
|
assertNonNullObject(value);
|
|
169
|
+
|
|
172
170
|
const content = value as Content;
|
|
173
171
|
switch (content.type) {
|
|
174
172
|
case "paragraph":
|
|
@@ -187,8 +185,8 @@ function assertValidContent(value: unknown): asserts value is Content {
|
|
|
187
185
|
case "internalLink":
|
|
188
186
|
assertValidInternalLink(content);
|
|
189
187
|
break;
|
|
190
|
-
case "
|
|
191
|
-
|
|
188
|
+
case "castSuggestion":
|
|
189
|
+
assertValidCastSuggestion(content);
|
|
192
190
|
break;
|
|
193
191
|
case "heading":
|
|
194
192
|
assertValidHeading(content);
|