@valbuild/core 0.72.0 → 0.72.1

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.
@@ -12,6 +12,7 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
12
12
  readonly opt: boolean;
13
13
  constructor(options: O, opt?: boolean);
14
14
  validate(path: SourcePath, src: Src): ValidationErrors;
15
+ private recursiveValidate;
15
16
  assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
16
17
  private recursiveAssert;
17
18
  nullable(): Schema<Src | null>;
@@ -1,2 +1,2 @@
1
- export declare const ValidationFix: readonly ["image:change-extension", "image:add-metadata", "image:check-metadata", "file:change-extension", "file:add-metadata", "file:check-metadata"];
1
+ export declare const ValidationFix: readonly ["image:change-extension", "image:add-metadata", "image:check-metadata", "file:change-extension", "file:add-metadata", "file:check-metadata", "keyof:check-keys"];
2
2
  export type ValidationFix = (typeof ValidationFix)[number];
@@ -2107,7 +2107,170 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2107
2107
  if (!assertRes.success) {
2108
2108
  return _defineProperty({}, path, assertRes.errors[path]);
2109
2109
  }
2110
- // TODO validate options
2110
+ var nodes = assertRes.data;
2111
+ if (nodes === null && this.opt) {
2112
+ return false;
2113
+ }
2114
+ if (nodes === null) {
2115
+ return _defineProperty({}, path, [{
2116
+ message: "Expected 'array', got 'null'",
2117
+ typeError: true
2118
+ }]);
2119
+ }
2120
+ var current = {};
2121
+ var typeErrorRes = this.recursiveValidate(path, nodes, current);
2122
+ if (typeErrorRes) {
2123
+ return typeErrorRes;
2124
+ }
2125
+ if (Object.keys(current).length > 0) {
2126
+ return current;
2127
+ }
2128
+ return false;
2129
+ }
2130
+ }, {
2131
+ key: "recursiveValidate",
2132
+ value: function recursiveValidate(rootPath, nodes, current) {
2133
+ var addError = function addError(path, message, typeError) {
2134
+ if (!current[path]) {
2135
+ current[path] = [];
2136
+ }
2137
+ current[path].push({
2138
+ message: message,
2139
+ typeError: typeError
2140
+ });
2141
+ };
2142
+ var _iterator = result._createForOfIteratorHelper(nodes),
2143
+ _step;
2144
+ try {
2145
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2146
+ var _this$options$block, _this$options$block2, _this$options$block3, _this$options$block4, _this$options$block5, _this$options$block6, _this$options$block7, _this$options$block8, _this$options$block9, _this$options$block10, _this$options$inline, _this$options$inline2;
2147
+ var node = _step.value;
2148
+ var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
2149
+ if (typeof node === "string") {
2150
+ continue;
2151
+ }
2152
+ if (_typeof(node) !== "object") {
2153
+ return _defineProperty({}, path, [{
2154
+ message: "Expected nodes of type 'object' or 'string', got '".concat(_typeof(node), "'"),
2155
+ typeError: true
2156
+ }]);
2157
+ }
2158
+ if (node === null) {
2159
+ return _defineProperty({}, path, [{
2160
+ message: "Expected nodes of type 'object' or 'string', got 'null'",
2161
+ typeError: true
2162
+ }]);
2163
+ }
2164
+ if (!("tag" in node)) {
2165
+ return _defineProperty({}, path, [{
2166
+ message: "Expected node to either have 'tag' or be of type 'string'",
2167
+ typeError: true
2168
+ }]);
2169
+ }
2170
+ if (typeof node.tag !== "string") {
2171
+ return _defineProperty({}, path, [{
2172
+ message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
2173
+ typeError: true
2174
+ }]);
2175
+ }
2176
+ if (node.tag === "h1" && !((_this$options$block = this.options.block) !== null && _this$options$block !== void 0 && _this$options$block.h1)) {
2177
+ addError(path, "'h' block is not valid", false);
2178
+ }
2179
+ if (node.tag === "h2" && !((_this$options$block2 = this.options.block) !== null && _this$options$block2 !== void 0 && _this$options$block2.h2)) {
2180
+ addError(path, "'h2' block is not valid", false);
2181
+ }
2182
+ if (node.tag === "h3" && !((_this$options$block3 = this.options.block) !== null && _this$options$block3 !== void 0 && _this$options$block3.h3)) {
2183
+ addError(path, "'h3' block is not valid", false);
2184
+ }
2185
+ if (node.tag === "h4" && !((_this$options$block4 = this.options.block) !== null && _this$options$block4 !== void 0 && _this$options$block4.h4)) {
2186
+ addError(path, "'h4' block is not valid", false);
2187
+ }
2188
+ if (node.tag === "h5" && !((_this$options$block5 = this.options.block) !== null && _this$options$block5 !== void 0 && _this$options$block5.h5)) {
2189
+ addError(path, "'h5' block is not valid", false);
2190
+ }
2191
+ if (node.tag === "h6" && !((_this$options$block6 = this.options.block) !== null && _this$options$block6 !== void 0 && _this$options$block6.h6)) {
2192
+ addError(path, "'h6' block is not valid", false);
2193
+ }
2194
+ if (node.tag === "ol" && !((_this$options$block7 = this.options.block) !== null && _this$options$block7 !== void 0 && _this$options$block7.ol)) {
2195
+ addError(path, "'ol' block is not valid", false);
2196
+ }
2197
+ if (node.tag === "ul" && !((_this$options$block8 = this.options.block) !== null && _this$options$block8 !== void 0 && _this$options$block8.ul)) {
2198
+ addError(path, "'ul' block is not valid", false);
2199
+ }
2200
+ if (node.tag === "li" && !((_this$options$block9 = this.options.block) !== null && _this$options$block9 !== void 0 && _this$options$block9.ul) && !((_this$options$block10 = this.options.block) !== null && _this$options$block10 !== void 0 && _this$options$block10.ol)) {
2201
+ addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
2202
+ }
2203
+ if (node.tag === "a" && !((_this$options$inline = this.options.inline) !== null && _this$options$inline !== void 0 && _this$options$inline.a)) {
2204
+ addError(path, "'a' inline is not valid", false);
2205
+ }
2206
+ if (node.tag === "img" && !((_this$options$inline2 = this.options.inline) !== null && _this$options$inline2 !== void 0 && _this$options$inline2.img)) {
2207
+ addError(path, "'img' inline is not valid", false);
2208
+ }
2209
+ if ("styles" in node && node.tag !== "span") {
2210
+ return _defineProperty({}, path, [{
2211
+ message: "Cannot have styles on '".concat(node.tag, "'. This is only allowed on 'span'"),
2212
+ typeError: true
2213
+ }]);
2214
+ }
2215
+ if ("styles" in node) {
2216
+ if (!Array.isArray(node.styles)) {
2217
+ return _defineProperty({}, path, [{
2218
+ message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
2219
+ typeError: true
2220
+ }]);
2221
+ }
2222
+ var stylesPath = unsafeCreateSourcePath(path, "styles");
2223
+ for (var i = 0; i < node.styles.length; i++) {
2224
+ var _this$options$style, _this$options$style2, _this$options$style3;
2225
+ var style = node.styles[i];
2226
+ var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
2227
+ if (typeof style !== "string") {
2228
+ return _defineProperty({}, currentStylePath, [{
2229
+ message: "Expected 'string', got '".concat(_typeof(style), "'"),
2230
+ typeError: true
2231
+ }]);
2232
+ }
2233
+ if (style === "bold" && !((_this$options$style = this.options.style) !== null && _this$options$style !== void 0 && _this$options$style.bold)) {
2234
+ addError(currentStylePath, "Style 'bold' is not valid", false);
2235
+ }
2236
+ if (style === "italic" && !((_this$options$style2 = this.options.style) !== null && _this$options$style2 !== void 0 && _this$options$style2.italic)) {
2237
+ addError(currentStylePath, "Style 'italic' is not valid", false);
2238
+ }
2239
+ if (style === "lineThrough" && !((_this$options$style3 = this.options.style) !== null && _this$options$style3 !== void 0 && _this$options$style3.lineThrough)) {
2240
+ addError(currentStylePath, "Style 'lineThrough' is not valid", false);
2241
+ }
2242
+ }
2243
+ }
2244
+ if ("children" in node) {
2245
+ if (!Array.isArray(node.children)) {
2246
+ return _defineProperty({}, path, [{
2247
+ message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
2248
+ typeError: true
2249
+ }]);
2250
+ }
2251
+ var children = node.children;
2252
+ for (var _i = 0; _i < children.length; _i++) {
2253
+ var child = children[_i];
2254
+ if (_typeof(child) === "object") {
2255
+ var childPath = unsafeCreateSourcePath(path, "children");
2256
+ var res = this.recursiveValidate(childPath, [child], current);
2257
+ if (res) {
2258
+ return res;
2259
+ }
2260
+ } else if (typeof child !== "string") {
2261
+ return _defineProperty({}, path, [{
2262
+ message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
2263
+ typeError: true
2264
+ }]);
2265
+ }
2266
+ }
2267
+ }
2268
+ }
2269
+ } catch (err) {
2270
+ _iterator.e(err);
2271
+ } finally {
2272
+ _iterator.f();
2273
+ }
2111
2274
  return false;
2112
2275
  }
2113
2276
  }, {
@@ -2229,10 +2392,10 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2229
2392
  typeError: true
2230
2393
  });
2231
2394
  } else {
2232
- for (var _i = 0; _i < node.styles.length; _i++) {
2233
- var style = node.styles[_i];
2395
+ for (var _i2 = 0; _i2 < node.styles.length; _i2++) {
2396
+ var style = node.styles[_i2];
2234
2397
  if (typeof style !== "string") {
2235
- var _pathAtError = unsafeCreateSourcePath(path, _i);
2398
+ var _pathAtError = unsafeCreateSourcePath(path, _i2);
2236
2399
  if (!errors[_pathAtError]) {
2237
2400
  errors[_pathAtError] = [];
2238
2401
  }
@@ -3149,6 +3312,21 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3149
3312
  }]);
3150
3313
  }
3151
3314
  }
3315
+ if (serializedSchema.type === "record") {
3316
+ if (typeof src !== "string") {
3317
+ return _defineProperty({}, path, [{
3318
+ message: "Value of keyOf (record) must be 'string'. Found: ".concat(_typeof(src))
3319
+ }]);
3320
+ }
3321
+ return _defineProperty({}, path, [{
3322
+ fixes: ["keyof:check-keys"],
3323
+ message: "Cannot validate keyOf (record) at runtime. This error must be picked up by: keyof:check-keys",
3324
+ value: {
3325
+ key: src,
3326
+ sourcePath: this.sourcePath
3327
+ }
3328
+ }]);
3329
+ }
3152
3330
  return false;
3153
3331
  }
3154
3332
  }, {
@@ -2107,7 +2107,170 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2107
2107
  if (!assertRes.success) {
2108
2108
  return _defineProperty({}, path, assertRes.errors[path]);
2109
2109
  }
2110
- // TODO validate options
2110
+ var nodes = assertRes.data;
2111
+ if (nodes === null && this.opt) {
2112
+ return false;
2113
+ }
2114
+ if (nodes === null) {
2115
+ return _defineProperty({}, path, [{
2116
+ message: "Expected 'array', got 'null'",
2117
+ typeError: true
2118
+ }]);
2119
+ }
2120
+ var current = {};
2121
+ var typeErrorRes = this.recursiveValidate(path, nodes, current);
2122
+ if (typeErrorRes) {
2123
+ return typeErrorRes;
2124
+ }
2125
+ if (Object.keys(current).length > 0) {
2126
+ return current;
2127
+ }
2128
+ return false;
2129
+ }
2130
+ }, {
2131
+ key: "recursiveValidate",
2132
+ value: function recursiveValidate(rootPath, nodes, current) {
2133
+ var addError = function addError(path, message, typeError) {
2134
+ if (!current[path]) {
2135
+ current[path] = [];
2136
+ }
2137
+ current[path].push({
2138
+ message: message,
2139
+ typeError: typeError
2140
+ });
2141
+ };
2142
+ var _iterator = result._createForOfIteratorHelper(nodes),
2143
+ _step;
2144
+ try {
2145
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2146
+ var _this$options$block, _this$options$block2, _this$options$block3, _this$options$block4, _this$options$block5, _this$options$block6, _this$options$block7, _this$options$block8, _this$options$block9, _this$options$block10, _this$options$inline, _this$options$inline2;
2147
+ var node = _step.value;
2148
+ var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
2149
+ if (typeof node === "string") {
2150
+ continue;
2151
+ }
2152
+ if (_typeof(node) !== "object") {
2153
+ return _defineProperty({}, path, [{
2154
+ message: "Expected nodes of type 'object' or 'string', got '".concat(_typeof(node), "'"),
2155
+ typeError: true
2156
+ }]);
2157
+ }
2158
+ if (node === null) {
2159
+ return _defineProperty({}, path, [{
2160
+ message: "Expected nodes of type 'object' or 'string', got 'null'",
2161
+ typeError: true
2162
+ }]);
2163
+ }
2164
+ if (!("tag" in node)) {
2165
+ return _defineProperty({}, path, [{
2166
+ message: "Expected node to either have 'tag' or be of type 'string'",
2167
+ typeError: true
2168
+ }]);
2169
+ }
2170
+ if (typeof node.tag !== "string") {
2171
+ return _defineProperty({}, path, [{
2172
+ message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
2173
+ typeError: true
2174
+ }]);
2175
+ }
2176
+ if (node.tag === "h1" && !((_this$options$block = this.options.block) !== null && _this$options$block !== void 0 && _this$options$block.h1)) {
2177
+ addError(path, "'h' block is not valid", false);
2178
+ }
2179
+ if (node.tag === "h2" && !((_this$options$block2 = this.options.block) !== null && _this$options$block2 !== void 0 && _this$options$block2.h2)) {
2180
+ addError(path, "'h2' block is not valid", false);
2181
+ }
2182
+ if (node.tag === "h3" && !((_this$options$block3 = this.options.block) !== null && _this$options$block3 !== void 0 && _this$options$block3.h3)) {
2183
+ addError(path, "'h3' block is not valid", false);
2184
+ }
2185
+ if (node.tag === "h4" && !((_this$options$block4 = this.options.block) !== null && _this$options$block4 !== void 0 && _this$options$block4.h4)) {
2186
+ addError(path, "'h4' block is not valid", false);
2187
+ }
2188
+ if (node.tag === "h5" && !((_this$options$block5 = this.options.block) !== null && _this$options$block5 !== void 0 && _this$options$block5.h5)) {
2189
+ addError(path, "'h5' block is not valid", false);
2190
+ }
2191
+ if (node.tag === "h6" && !((_this$options$block6 = this.options.block) !== null && _this$options$block6 !== void 0 && _this$options$block6.h6)) {
2192
+ addError(path, "'h6' block is not valid", false);
2193
+ }
2194
+ if (node.tag === "ol" && !((_this$options$block7 = this.options.block) !== null && _this$options$block7 !== void 0 && _this$options$block7.ol)) {
2195
+ addError(path, "'ol' block is not valid", false);
2196
+ }
2197
+ if (node.tag === "ul" && !((_this$options$block8 = this.options.block) !== null && _this$options$block8 !== void 0 && _this$options$block8.ul)) {
2198
+ addError(path, "'ul' block is not valid", false);
2199
+ }
2200
+ if (node.tag === "li" && !((_this$options$block9 = this.options.block) !== null && _this$options$block9 !== void 0 && _this$options$block9.ul) && !((_this$options$block10 = this.options.block) !== null && _this$options$block10 !== void 0 && _this$options$block10.ol)) {
2201
+ addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
2202
+ }
2203
+ if (node.tag === "a" && !((_this$options$inline = this.options.inline) !== null && _this$options$inline !== void 0 && _this$options$inline.a)) {
2204
+ addError(path, "'a' inline is not valid", false);
2205
+ }
2206
+ if (node.tag === "img" && !((_this$options$inline2 = this.options.inline) !== null && _this$options$inline2 !== void 0 && _this$options$inline2.img)) {
2207
+ addError(path, "'img' inline is not valid", false);
2208
+ }
2209
+ if ("styles" in node && node.tag !== "span") {
2210
+ return _defineProperty({}, path, [{
2211
+ message: "Cannot have styles on '".concat(node.tag, "'. This is only allowed on 'span'"),
2212
+ typeError: true
2213
+ }]);
2214
+ }
2215
+ if ("styles" in node) {
2216
+ if (!Array.isArray(node.styles)) {
2217
+ return _defineProperty({}, path, [{
2218
+ message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
2219
+ typeError: true
2220
+ }]);
2221
+ }
2222
+ var stylesPath = unsafeCreateSourcePath(path, "styles");
2223
+ for (var i = 0; i < node.styles.length; i++) {
2224
+ var _this$options$style, _this$options$style2, _this$options$style3;
2225
+ var style = node.styles[i];
2226
+ var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
2227
+ if (typeof style !== "string") {
2228
+ return _defineProperty({}, currentStylePath, [{
2229
+ message: "Expected 'string', got '".concat(_typeof(style), "'"),
2230
+ typeError: true
2231
+ }]);
2232
+ }
2233
+ if (style === "bold" && !((_this$options$style = this.options.style) !== null && _this$options$style !== void 0 && _this$options$style.bold)) {
2234
+ addError(currentStylePath, "Style 'bold' is not valid", false);
2235
+ }
2236
+ if (style === "italic" && !((_this$options$style2 = this.options.style) !== null && _this$options$style2 !== void 0 && _this$options$style2.italic)) {
2237
+ addError(currentStylePath, "Style 'italic' is not valid", false);
2238
+ }
2239
+ if (style === "lineThrough" && !((_this$options$style3 = this.options.style) !== null && _this$options$style3 !== void 0 && _this$options$style3.lineThrough)) {
2240
+ addError(currentStylePath, "Style 'lineThrough' is not valid", false);
2241
+ }
2242
+ }
2243
+ }
2244
+ if ("children" in node) {
2245
+ if (!Array.isArray(node.children)) {
2246
+ return _defineProperty({}, path, [{
2247
+ message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
2248
+ typeError: true
2249
+ }]);
2250
+ }
2251
+ var children = node.children;
2252
+ for (var _i = 0; _i < children.length; _i++) {
2253
+ var child = children[_i];
2254
+ if (_typeof(child) === "object") {
2255
+ var childPath = unsafeCreateSourcePath(path, "children");
2256
+ var res = this.recursiveValidate(childPath, [child], current);
2257
+ if (res) {
2258
+ return res;
2259
+ }
2260
+ } else if (typeof child !== "string") {
2261
+ return _defineProperty({}, path, [{
2262
+ message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
2263
+ typeError: true
2264
+ }]);
2265
+ }
2266
+ }
2267
+ }
2268
+ }
2269
+ } catch (err) {
2270
+ _iterator.e(err);
2271
+ } finally {
2272
+ _iterator.f();
2273
+ }
2111
2274
  return false;
2112
2275
  }
2113
2276
  }, {
@@ -2229,10 +2392,10 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2229
2392
  typeError: true
2230
2393
  });
2231
2394
  } else {
2232
- for (var _i = 0; _i < node.styles.length; _i++) {
2233
- var style = node.styles[_i];
2395
+ for (var _i2 = 0; _i2 < node.styles.length; _i2++) {
2396
+ var style = node.styles[_i2];
2234
2397
  if (typeof style !== "string") {
2235
- var _pathAtError = unsafeCreateSourcePath(path, _i);
2398
+ var _pathAtError = unsafeCreateSourcePath(path, _i2);
2236
2399
  if (!errors[_pathAtError]) {
2237
2400
  errors[_pathAtError] = [];
2238
2401
  }
@@ -3149,6 +3312,21 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3149
3312
  }]);
3150
3313
  }
3151
3314
  }
3315
+ if (serializedSchema.type === "record") {
3316
+ if (typeof src !== "string") {
3317
+ return _defineProperty({}, path, [{
3318
+ message: "Value of keyOf (record) must be 'string'. Found: ".concat(_typeof(src))
3319
+ }]);
3320
+ }
3321
+ return _defineProperty({}, path, [{
3322
+ fixes: ["keyof:check-keys"],
3323
+ message: "Cannot validate keyOf (record) at runtime. This error must be picked up by: keyof:check-keys",
3324
+ value: {
3325
+ key: src,
3326
+ sourcePath: this.sourcePath
3327
+ }
3328
+ }]);
3329
+ }
3152
3330
  return false;
3153
3331
  }
3154
3332
  }, {
@@ -2105,7 +2105,170 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2105
2105
  if (!assertRes.success) {
2106
2106
  return _defineProperty({}, path, assertRes.errors[path]);
2107
2107
  }
2108
- // TODO validate options
2108
+ var nodes = assertRes.data;
2109
+ if (nodes === null && this.opt) {
2110
+ return false;
2111
+ }
2112
+ if (nodes === null) {
2113
+ return _defineProperty({}, path, [{
2114
+ message: "Expected 'array', got 'null'",
2115
+ typeError: true
2116
+ }]);
2117
+ }
2118
+ var current = {};
2119
+ var typeErrorRes = this.recursiveValidate(path, nodes, current);
2120
+ if (typeErrorRes) {
2121
+ return typeErrorRes;
2122
+ }
2123
+ if (Object.keys(current).length > 0) {
2124
+ return current;
2125
+ }
2126
+ return false;
2127
+ }
2128
+ }, {
2129
+ key: "recursiveValidate",
2130
+ value: function recursiveValidate(rootPath, nodes, current) {
2131
+ var addError = function addError(path, message, typeError) {
2132
+ if (!current[path]) {
2133
+ current[path] = [];
2134
+ }
2135
+ current[path].push({
2136
+ message: message,
2137
+ typeError: typeError
2138
+ });
2139
+ };
2140
+ var _iterator = _createForOfIteratorHelper(nodes),
2141
+ _step;
2142
+ try {
2143
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2144
+ var _this$options$block, _this$options$block2, _this$options$block3, _this$options$block4, _this$options$block5, _this$options$block6, _this$options$block7, _this$options$block8, _this$options$block9, _this$options$block10, _this$options$inline, _this$options$inline2;
2145
+ var node = _step.value;
2146
+ var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
2147
+ if (typeof node === "string") {
2148
+ continue;
2149
+ }
2150
+ if (_typeof(node) !== "object") {
2151
+ return _defineProperty({}, path, [{
2152
+ message: "Expected nodes of type 'object' or 'string', got '".concat(_typeof(node), "'"),
2153
+ typeError: true
2154
+ }]);
2155
+ }
2156
+ if (node === null) {
2157
+ return _defineProperty({}, path, [{
2158
+ message: "Expected nodes of type 'object' or 'string', got 'null'",
2159
+ typeError: true
2160
+ }]);
2161
+ }
2162
+ if (!("tag" in node)) {
2163
+ return _defineProperty({}, path, [{
2164
+ message: "Expected node to either have 'tag' or be of type 'string'",
2165
+ typeError: true
2166
+ }]);
2167
+ }
2168
+ if (typeof node.tag !== "string") {
2169
+ return _defineProperty({}, path, [{
2170
+ message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
2171
+ typeError: true
2172
+ }]);
2173
+ }
2174
+ if (node.tag === "h1" && !((_this$options$block = this.options.block) !== null && _this$options$block !== void 0 && _this$options$block.h1)) {
2175
+ addError(path, "'h' block is not valid", false);
2176
+ }
2177
+ if (node.tag === "h2" && !((_this$options$block2 = this.options.block) !== null && _this$options$block2 !== void 0 && _this$options$block2.h2)) {
2178
+ addError(path, "'h2' block is not valid", false);
2179
+ }
2180
+ if (node.tag === "h3" && !((_this$options$block3 = this.options.block) !== null && _this$options$block3 !== void 0 && _this$options$block3.h3)) {
2181
+ addError(path, "'h3' block is not valid", false);
2182
+ }
2183
+ if (node.tag === "h4" && !((_this$options$block4 = this.options.block) !== null && _this$options$block4 !== void 0 && _this$options$block4.h4)) {
2184
+ addError(path, "'h4' block is not valid", false);
2185
+ }
2186
+ if (node.tag === "h5" && !((_this$options$block5 = this.options.block) !== null && _this$options$block5 !== void 0 && _this$options$block5.h5)) {
2187
+ addError(path, "'h5' block is not valid", false);
2188
+ }
2189
+ if (node.tag === "h6" && !((_this$options$block6 = this.options.block) !== null && _this$options$block6 !== void 0 && _this$options$block6.h6)) {
2190
+ addError(path, "'h6' block is not valid", false);
2191
+ }
2192
+ if (node.tag === "ol" && !((_this$options$block7 = this.options.block) !== null && _this$options$block7 !== void 0 && _this$options$block7.ol)) {
2193
+ addError(path, "'ol' block is not valid", false);
2194
+ }
2195
+ if (node.tag === "ul" && !((_this$options$block8 = this.options.block) !== null && _this$options$block8 !== void 0 && _this$options$block8.ul)) {
2196
+ addError(path, "'ul' block is not valid", false);
2197
+ }
2198
+ if (node.tag === "li" && !((_this$options$block9 = this.options.block) !== null && _this$options$block9 !== void 0 && _this$options$block9.ul) && !((_this$options$block10 = this.options.block) !== null && _this$options$block10 !== void 0 && _this$options$block10.ol)) {
2199
+ addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
2200
+ }
2201
+ if (node.tag === "a" && !((_this$options$inline = this.options.inline) !== null && _this$options$inline !== void 0 && _this$options$inline.a)) {
2202
+ addError(path, "'a' inline is not valid", false);
2203
+ }
2204
+ if (node.tag === "img" && !((_this$options$inline2 = this.options.inline) !== null && _this$options$inline2 !== void 0 && _this$options$inline2.img)) {
2205
+ addError(path, "'img' inline is not valid", false);
2206
+ }
2207
+ if ("styles" in node && node.tag !== "span") {
2208
+ return _defineProperty({}, path, [{
2209
+ message: "Cannot have styles on '".concat(node.tag, "'. This is only allowed on 'span'"),
2210
+ typeError: true
2211
+ }]);
2212
+ }
2213
+ if ("styles" in node) {
2214
+ if (!Array.isArray(node.styles)) {
2215
+ return _defineProperty({}, path, [{
2216
+ message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
2217
+ typeError: true
2218
+ }]);
2219
+ }
2220
+ var stylesPath = unsafeCreateSourcePath(path, "styles");
2221
+ for (var i = 0; i < node.styles.length; i++) {
2222
+ var _this$options$style, _this$options$style2, _this$options$style3;
2223
+ var style = node.styles[i];
2224
+ var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
2225
+ if (typeof style !== "string") {
2226
+ return _defineProperty({}, currentStylePath, [{
2227
+ message: "Expected 'string', got '".concat(_typeof(style), "'"),
2228
+ typeError: true
2229
+ }]);
2230
+ }
2231
+ if (style === "bold" && !((_this$options$style = this.options.style) !== null && _this$options$style !== void 0 && _this$options$style.bold)) {
2232
+ addError(currentStylePath, "Style 'bold' is not valid", false);
2233
+ }
2234
+ if (style === "italic" && !((_this$options$style2 = this.options.style) !== null && _this$options$style2 !== void 0 && _this$options$style2.italic)) {
2235
+ addError(currentStylePath, "Style 'italic' is not valid", false);
2236
+ }
2237
+ if (style === "lineThrough" && !((_this$options$style3 = this.options.style) !== null && _this$options$style3 !== void 0 && _this$options$style3.lineThrough)) {
2238
+ addError(currentStylePath, "Style 'lineThrough' is not valid", false);
2239
+ }
2240
+ }
2241
+ }
2242
+ if ("children" in node) {
2243
+ if (!Array.isArray(node.children)) {
2244
+ return _defineProperty({}, path, [{
2245
+ message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
2246
+ typeError: true
2247
+ }]);
2248
+ }
2249
+ var children = node.children;
2250
+ for (var _i = 0; _i < children.length; _i++) {
2251
+ var child = children[_i];
2252
+ if (_typeof(child) === "object") {
2253
+ var childPath = unsafeCreateSourcePath(path, "children");
2254
+ var res = this.recursiveValidate(childPath, [child], current);
2255
+ if (res) {
2256
+ return res;
2257
+ }
2258
+ } else if (typeof child !== "string") {
2259
+ return _defineProperty({}, path, [{
2260
+ message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
2261
+ typeError: true
2262
+ }]);
2263
+ }
2264
+ }
2265
+ }
2266
+ }
2267
+ } catch (err) {
2268
+ _iterator.e(err);
2269
+ } finally {
2270
+ _iterator.f();
2271
+ }
2109
2272
  return false;
2110
2273
  }
2111
2274
  }, {
@@ -2227,10 +2390,10 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2227
2390
  typeError: true
2228
2391
  });
2229
2392
  } else {
2230
- for (var _i = 0; _i < node.styles.length; _i++) {
2231
- var style = node.styles[_i];
2393
+ for (var _i2 = 0; _i2 < node.styles.length; _i2++) {
2394
+ var style = node.styles[_i2];
2232
2395
  if (typeof style !== "string") {
2233
- var _pathAtError = unsafeCreateSourcePath(path, _i);
2396
+ var _pathAtError = unsafeCreateSourcePath(path, _i2);
2234
2397
  if (!errors[_pathAtError]) {
2235
2398
  errors[_pathAtError] = [];
2236
2399
  }
@@ -3147,6 +3310,21 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3147
3310
  }]);
3148
3311
  }
3149
3312
  }
3313
+ if (serializedSchema.type === "record") {
3314
+ if (typeof src !== "string") {
3315
+ return _defineProperty({}, path, [{
3316
+ message: "Value of keyOf (record) must be 'string'. Found: ".concat(_typeof(src))
3317
+ }]);
3318
+ }
3319
+ return _defineProperty({}, path, [{
3320
+ fixes: ["keyof:check-keys"],
3321
+ message: "Cannot validate keyOf (record) at runtime. This error must be picked up by: keyof:check-keys",
3322
+ value: {
3323
+ key: src,
3324
+ sourcePath: this.sourcePath
3325
+ }
3326
+ }]);
3327
+ }
3150
3328
  return false;
3151
3329
  }
3152
3330
  }, {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('./index-47055fcc.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('./index-74936efb.cjs.dev.js');
6
6
  require('./result-bb1f436e.cjs.dev.js');
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('./index-6d63e99d.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('./index-74ab2ec0.cjs.prod.js');
6
6
  require('./result-787e35f6.cjs.prod.js');
7
7
 
8
8
 
@@ -1,2 +1,2 @@
1
- export { A as ArraySchema, B as BooleanSchema, D as DateSchema, F as FATAL_ERROR_TYPES, k as FILE_REF_PROP, l as FILE_REF_SUBTYPE_TAG, t as FileSchema, G as GenericSelector, r as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, q as NumberSchema, O as ObjectSchema, R as RecordSchema, u as RichTextSchema, j as Schema, o as StringSchema, U as UnionSchema, V as VAL_EXTENSION, n as derefPatch, v as deserializeSchema, i as expr, h as initVal, m as modules } from './index-1d65adb5.esm.js';
1
+ export { A as ArraySchema, B as BooleanSchema, D as DateSchema, F as FATAL_ERROR_TYPES, k as FILE_REF_PROP, l as FILE_REF_SUBTYPE_TAG, t as FileSchema, G as GenericSelector, r as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, q as NumberSchema, O as ObjectSchema, R as RecordSchema, u as RichTextSchema, j as Schema, o as StringSchema, U as UnionSchema, V as VAL_EXTENSION, n as derefPatch, v as deserializeSchema, i as expr, h as initVal, m as modules } from './index-bd259784.esm.js';
2
2
  import './result-168dfc1d.esm.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-47055fcc.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-74936efb.cjs.dev.js');
6
6
  require('../../dist/result-bb1f436e.cjs.dev.js');
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-6d63e99d.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-74ab2ec0.cjs.prod.js');
6
6
  require('../../dist/result-787e35f6.cjs.prod.js');
7
7
 
8
8
 
@@ -1,2 +1,2 @@
1
- export { C as Call, E as Expr, N as NilSym, S as StringLiteral, e as StringTemplate, f as Sym, g as evaluate, p as parse } from '../../dist/index-1d65adb5.esm.js';
1
+ export { C as Call, E as Expr, N as NilSym, S as StringLiteral, e as StringTemplate, f as Sym, g as evaluate, p as parse } from '../../dist/index-bd259784.esm.js';
2
2
  import '../../dist/result-168dfc1d.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.72.0",
3
+ "version": "0.72.1",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "scripts": {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-47055fcc.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-74936efb.cjs.dev.js');
6
6
  var result = require('../../dist/result-bb1f436e.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-6d63e99d.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-74ab2ec0.cjs.prod.js');
6
6
  var result = require('../../dist/result-787e35f6.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
8
 
@@ -1,5 +1,5 @@
1
- import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-1d65adb5.esm.js';
2
- export { P as PatchError } from '../../dist/index-1d65adb5.esm.js';
1
+ import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-bd259784.esm.js';
2
+ export { P as PatchError } from '../../dist/index-bd259784.esm.js';
3
3
  import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-168dfc1d.esm.js';
4
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
5
5