@platecms/delta-cast 0.3.0 → 0.4.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/index.d.ts +1 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/schemas/schema.d.ts +15 -0
- package/src/lib/schemas/schema.json +92 -0
- package/src/lib/validate-cast.d.ts +1 -0
- package/src/lib/validate-cast.js +41 -0
- package/src/lib/validate-cast.js.map +1 -1
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": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"tslib": "2.8.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@platecms/delta-plate-resource-notation": "
|
|
25
|
+
"@platecms/delta-plate-resource-notation": "0.4.0"
|
|
26
26
|
},
|
|
27
27
|
"type": "commonjs"
|
|
28
28
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/schemas/schema"), exports);
|
|
5
4
|
tslib_1.__exportStar(require("./lib/validate-cast"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./lib/invalid-cast.error"), exports);
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/cast/src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/cast/src/index.ts"],"names":[],"mappings":";;;AACA,8DAAoC;AACpC,mEAAyC"}
|
|
@@ -19,6 +19,8 @@ export interface InlineContentMap {
|
|
|
19
19
|
inlineCode: InlineCode;
|
|
20
20
|
highlight: Highlight;
|
|
21
21
|
contentValue: InterpolatedContentValue;
|
|
22
|
+
externalLink: ExternalLink;
|
|
23
|
+
internalLink: InternalLink;
|
|
22
24
|
}
|
|
23
25
|
export interface Parent extends UnistParent {
|
|
24
26
|
children: Content[];
|
|
@@ -88,3 +90,16 @@ export interface InterpolatedContentValue extends Node {
|
|
|
88
90
|
prn: string;
|
|
89
91
|
value?: Root;
|
|
90
92
|
}
|
|
93
|
+
export interface ExternalLink extends Parent {
|
|
94
|
+
type: "externalLink";
|
|
95
|
+
children: Text[];
|
|
96
|
+
url: string;
|
|
97
|
+
target?: "_parent" | "_top" | "blank" | "self";
|
|
98
|
+
}
|
|
99
|
+
export interface InternalLink extends Parent {
|
|
100
|
+
type: "internalLink";
|
|
101
|
+
children: Text[];
|
|
102
|
+
prn: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
target?: "_parent" | "_top" | "blank" | "self";
|
|
105
|
+
}
|
|
@@ -124,6 +124,12 @@
|
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"$ref": "#/definitions/InterpolatedContentValue"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"$ref": "#/definitions/ExternalLink"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"$ref": "#/definitions/InternalLink"
|
|
127
133
|
}
|
|
128
134
|
]
|
|
129
135
|
},
|
|
@@ -131,6 +137,44 @@
|
|
|
131
137
|
"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```",
|
|
132
138
|
"type": "object"
|
|
133
139
|
},
|
|
140
|
+
"ExternalLink": {
|
|
141
|
+
"properties": {
|
|
142
|
+
"children": {
|
|
143
|
+
"description": "List of children.",
|
|
144
|
+
"items": {
|
|
145
|
+
"$ref": "#/definitions/Text"
|
|
146
|
+
},
|
|
147
|
+
"type": "array"
|
|
148
|
+
},
|
|
149
|
+
"data": {
|
|
150
|
+
"$ref": "#/definitions/Data",
|
|
151
|
+
"description": "Info from the ecosystem."
|
|
152
|
+
},
|
|
153
|
+
"position": {
|
|
154
|
+
"$ref": "#/definitions/Position",
|
|
155
|
+
"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."
|
|
156
|
+
},
|
|
157
|
+
"target": {
|
|
158
|
+
"enum": [
|
|
159
|
+
"_parent",
|
|
160
|
+
"_top",
|
|
161
|
+
"blank",
|
|
162
|
+
"self"
|
|
163
|
+
],
|
|
164
|
+
"type": "string"
|
|
165
|
+
},
|
|
166
|
+
"type": {
|
|
167
|
+
"const": "externalLink",
|
|
168
|
+
"description": "Node type.",
|
|
169
|
+
"type": "string"
|
|
170
|
+
},
|
|
171
|
+
"url": {
|
|
172
|
+
"description": "The URL of the link.",
|
|
173
|
+
"type": "string"
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
"type": "object"
|
|
177
|
+
},
|
|
134
178
|
"Heading": {
|
|
135
179
|
"properties": {
|
|
136
180
|
"children": {
|
|
@@ -240,9 +284,57 @@
|
|
|
240
284
|
},
|
|
241
285
|
{
|
|
242
286
|
"$ref": "#/definitions/InterpolatedContentValue"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"$ref": "#/definitions/ExternalLink"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"$ref": "#/definitions/InternalLink"
|
|
243
293
|
}
|
|
244
294
|
]
|
|
245
295
|
},
|
|
296
|
+
"InternalLink": {
|
|
297
|
+
"properties": {
|
|
298
|
+
"children": {
|
|
299
|
+
"description": "List of children.",
|
|
300
|
+
"items": {
|
|
301
|
+
"$ref": "#/definitions/Text"
|
|
302
|
+
},
|
|
303
|
+
"type": "array"
|
|
304
|
+
},
|
|
305
|
+
"data": {
|
|
306
|
+
"$ref": "#/definitions/Data",
|
|
307
|
+
"description": "Info from the ecosystem."
|
|
308
|
+
},
|
|
309
|
+
"position": {
|
|
310
|
+
"$ref": "#/definitions/Position",
|
|
311
|
+
"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."
|
|
312
|
+
},
|
|
313
|
+
"prn": {
|
|
314
|
+
"description": "The PRN (identifier) of the referenced Path Part or Grid Placement.",
|
|
315
|
+
"type": "string"
|
|
316
|
+
},
|
|
317
|
+
"target": {
|
|
318
|
+
"enum": [
|
|
319
|
+
"_parent",
|
|
320
|
+
"_top",
|
|
321
|
+
"blank",
|
|
322
|
+
"self"
|
|
323
|
+
],
|
|
324
|
+
"type": "string"
|
|
325
|
+
},
|
|
326
|
+
"type": {
|
|
327
|
+
"const": "internalLink",
|
|
328
|
+
"description": "Node type.",
|
|
329
|
+
"type": "string"
|
|
330
|
+
},
|
|
331
|
+
"url": {
|
|
332
|
+
"description": "The URL of the link. Consists of the channel and the path part. Optionally includes a grid placement reference (e.g. #anchor-name).\nEven though the URL is marked as optional, it is always defined when retrieving an internal link.\nIt is not required when saving an internal link.",
|
|
333
|
+
"type": "string"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
"type": "object"
|
|
337
|
+
},
|
|
246
338
|
"InterpolatedContentValue": {
|
|
247
339
|
"description": "Represents an interpolated Content Value. Interpolated values are values that are stored elsewhere in the database\nand inserted into the document at request-time.",
|
|
248
340
|
"properties": {
|
package/src/lib/validate-cast.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.URL_REGEX = void 0;
|
|
3
4
|
exports.validateCast = validateCast;
|
|
4
5
|
const invalid_cast_error_1 = require("./invalid-cast.error");
|
|
5
6
|
const delta_plate_resource_notation_1 = require("@platecms/delta-plate-resource-notation");
|
|
7
|
+
exports.URL_REGEX = /^(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)|mailto:[^\s@]+@[^\s@]+\.[^\s@]+|tel:\+?[0-9\s\-().]{7,}|\/[^\s]*)$/u;
|
|
6
8
|
function assertNonNullObject(value) {
|
|
7
9
|
if (typeof value !== "object" || value == null) {
|
|
8
10
|
throw new invalid_cast_error_1.InvalidCastError(`Invalid object`);
|
|
9
11
|
}
|
|
10
12
|
}
|
|
13
|
+
function assertTextNode(value) {
|
|
14
|
+
assertNonNullObject(value);
|
|
15
|
+
if ("type" in value && typeof value.type === "string" && value.type !== "text") {
|
|
16
|
+
throw new invalid_cast_error_1.InvalidCastError(`Invalid node: ${value.type} node is not a text node`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
11
19
|
function assertValidParent(value) {
|
|
12
20
|
assertNonNullObject(value);
|
|
13
21
|
const parent = value;
|
|
@@ -60,6 +68,33 @@ function assertValidInterpolatedContentValue(value) {
|
|
|
60
68
|
throw error;
|
|
61
69
|
}
|
|
62
70
|
}
|
|
71
|
+
function assertValidExternalLink(value) {
|
|
72
|
+
assertNonNullObject(value);
|
|
73
|
+
assertValidParent(value);
|
|
74
|
+
const link = value;
|
|
75
|
+
if (typeof link.url !== "string") {
|
|
76
|
+
throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid url`);
|
|
77
|
+
}
|
|
78
|
+
if (!exports.URL_REGEX.test(link.url)) {
|
|
79
|
+
throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid url ${link.url}`);
|
|
80
|
+
}
|
|
81
|
+
link.children.forEach(assertTextNode);
|
|
82
|
+
}
|
|
83
|
+
function assertValidInternalLink(value) {
|
|
84
|
+
assertNonNullObject(value);
|
|
85
|
+
assertValidParent(value);
|
|
86
|
+
const link = value;
|
|
87
|
+
try {
|
|
88
|
+
delta_plate_resource_notation_1.PRN.fromString(link.prn);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof delta_plate_resource_notation_1.InvalidPrnError) {
|
|
92
|
+
throw new invalid_cast_error_1.InvalidCastError(`Invalid link: invalid PRN ${link.prn}`);
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
link.children.forEach(assertTextNode);
|
|
97
|
+
}
|
|
63
98
|
function assertValidContent(value) {
|
|
64
99
|
assertNonNullObject(value);
|
|
65
100
|
const content = value;
|
|
@@ -74,6 +109,12 @@ function assertValidContent(value) {
|
|
|
74
109
|
case "highlight":
|
|
75
110
|
assertValidParent(content);
|
|
76
111
|
break;
|
|
112
|
+
case "externalLink":
|
|
113
|
+
assertValidExternalLink(content);
|
|
114
|
+
break;
|
|
115
|
+
case "internalLink":
|
|
116
|
+
assertValidInternalLink(content);
|
|
117
|
+
break;
|
|
77
118
|
case "heading":
|
|
78
119
|
assertValidHeading(content);
|
|
79
120
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-cast.js","sourceRoot":"","sources":["../../../../../../packages/cast/src/lib/validate-cast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-cast.js","sourceRoot":"","sources":["../../../../../../packages/cast/src/lib/validate-cast.ts"],"names":[],"mappings":";;;AAwLA,oCAaC;AAxLD,6DAAwD;AACxD,2FAA+E;AAMlE,QAAA,SAAS,GACpB,8KAA8K,CAAC;AAEjL,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAC/C,MAAM,IAAI,qCAAgB,CAAC,gBAAgB,CAAC,CAAC;IA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