@valbuild/core 0.78.0 → 0.78.2

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.
@@ -52,7 +52,7 @@ export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtex
52
52
  export { type SerializedUnionSchema, UnionSchema, type SerializedStringUnionSchema, type SerializedObjectUnionSchema, } from "./schema/union.js";
53
53
  export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
54
54
  export { deserializeSchema } from "./schema/deserialize.js";
55
- export { type ListRecordPreview, type ReifiedPreview } from "./preview.js";
55
+ export { type ListRecordPreview, type ListArrayPreview, type ReifiedPreview, } from "./preview.js";
56
56
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
57
57
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
58
58
  export declare const DEFAULT_CONTENT_HOST = "https://content.val.build";
@@ -47,7 +47,7 @@ export type InitSchema = {
47
47
  export declare function initSchema(): {
48
48
  string: <T extends string>(options?: Record<string, never> | undefined) => import("./schema/string.js").StringSchema<T>;
49
49
  boolean: () => import("./schema/index.js").Schema<boolean>;
50
- array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/index.js").Schema<import("./schema/index.js").SelectorOfSchema<S>[]>;
50
+ array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/array.js").ArraySchema<S, import("./schema/index.js").SelectorOfSchema<S>[]>;
51
51
  object: <Props extends {
52
52
  [key: string]: import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>;
53
53
  } & {
@@ -1,7 +1,10 @@
1
+ import { Schema } from "./schema/index.js";
2
+ import { SelectorSource } from "./selector/index.js";
1
3
  import { ImageSource } from "./source/image.js";
2
4
  import { ModuleFilePath, SourcePath } from "./val/index.js";
3
5
  export type ListRecordPreview = {
4
6
  layout: "list";
7
+ parent: "record";
5
8
  items: [
6
9
  key: string,
7
10
  value: {
@@ -11,6 +14,16 @@ export type ListRecordPreview = {
11
14
  }
12
15
  ][];
13
16
  };
17
+ export type ListArrayPreview = {
18
+ layout: "list";
19
+ parent: "array";
20
+ items: {
21
+ title: string;
22
+ subtitle?: string | null;
23
+ image?: ImageSource | null;
24
+ }[];
25
+ };
26
+ type PreviewTypes = ListRecordPreview | ListArrayPreview;
14
27
  type WithStatus<T> = {
15
28
  status: "error";
16
29
  message: string;
@@ -21,6 +34,6 @@ type WithStatus<T> = {
21
34
  status: "success";
22
35
  data: T;
23
36
  };
24
- type PreviewTypes = ListRecordPreview;
25
37
  export type ReifiedPreview = Record<SourcePath | ModuleFilePath, WithStatus<PreviewTypes>>;
38
+ export type PreviewSelector<T extends Schema<SelectorSource>> = T extends Schema<infer S> ? S : never;
26
39
  export {};
@@ -1,6 +1,7 @@
1
1
  import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
- import { ReifiedPreview } from "../preview.js";
2
+ import { PreviewSelector, ReifiedPreview } from "../preview.js";
3
3
  import { SelectorSource } from "../selector/index.js";
4
+ import { ImageSource } from "../source/image.js";
4
5
  import { ModuleFilePath, SourcePath } from "../val/index.js";
5
6
  import { ValidationErrors } from "./validation/ValidationError.js";
6
7
  export type SerializedArraySchema = {
@@ -16,6 +17,17 @@ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends S
16
17
  assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
17
18
  nullable(): Schema<Src | null>;
18
19
  serialize(): SerializedArraySchema;
20
+ private previewInput;
19
21
  protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
22
+ preview(input: {
23
+ layout: "list";
24
+ prepare: (input: {
25
+ val: PreviewSelector<T>;
26
+ }) => {
27
+ title: string;
28
+ subtitle?: string | null;
29
+ image?: ImageSource | null;
30
+ };
31
+ }): this;
20
32
  }
21
- export declare const array: <S extends Schema<SelectorSource>>(schema: S) => Schema<SelectorOfSchema<S>[]>;
33
+ export declare const array: <S extends Schema<SelectorSource>>(schema: S) => ArraySchema<S, SelectorOfSchema<S>[]>;
@@ -1,5 +1,5 @@
1
1
  import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
- import { ReifiedPreview } from "../preview.js";
2
+ import { PreviewSelector, ReifiedPreview } from "../preview.js";
3
3
  import { SelectorSource } from "../selector/index.js";
4
4
  import { ImageSource } from "../source/image.js";
5
5
  import { ModuleFilePath, SourcePath } from "../val/index.js";
@@ -31,6 +31,4 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, Src extends
31
31
  };
32
32
  }): this;
33
33
  }
34
- type PreviewSelector<T extends Schema<SelectorSource>> = T extends Schema<infer S> ? S : never;
35
34
  export declare const record: <S extends Schema<SelectorSource>>(schema: S) => RecordSchema<S, Record<string, SelectorOfSchema<S>>>;
36
- export {};
@@ -778,6 +778,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
778
778
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
779
779
  _classCallCheck(this, ArraySchema);
780
780
  _this = _callSuper(this, ArraySchema);
781
+ _defineProperty(_this, "previewInput", null);
781
782
  _this.item = item;
782
783
  _this.opt = opt;
783
784
  return _this;
@@ -871,20 +872,65 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
871
872
  if (src === null) {
872
873
  return res;
873
874
  }
874
- for (var i = 0; i < ((src === null || src === void 0 ? void 0 : src.length) || 0); i++) {
875
- var itemSrc = src[i];
876
- if (itemSrc === null) {
875
+ for (var key in src) {
876
+ var itemSrc = src[key];
877
+ if (itemSrc === null || itemSrc === undefined) {
877
878
  continue;
878
879
  }
879
- var subPath = unsafeCreateSourcePath(sourcePath, i);
880
+ var subPath = unsafeCreateSourcePath(sourcePath, key);
880
881
  var itemResult = this.item["executePreview"](subPath, itemSrc);
881
882
  for (var keyS in itemResult) {
882
- var key = keyS;
883
- res[key] = itemResult[key];
883
+ var _key = keyS;
884
+ res[_key] = itemResult[_key];
885
+ }
886
+ }
887
+ if (this.previewInput) {
888
+ var _this$previewInput = this.previewInput,
889
+ prepare = _this$previewInput.prepare,
890
+ layout = _this$previewInput.layout;
891
+ if (layout !== "list") {
892
+ res[sourcePath] = {
893
+ status: "error",
894
+ message: "Unknown layout type: " + layout
895
+ };
896
+ }
897
+ try {
898
+ res[sourcePath] = {
899
+ status: "success",
900
+ data: {
901
+ layout: "list",
902
+ parent: "array",
903
+ items: src.map(function (val) {
904
+ // NB NB: display is actually defined by the user
905
+ var _prepare = prepare({
906
+ val: val
907
+ }),
908
+ title = _prepare.title,
909
+ subtitle = _prepare.subtitle,
910
+ image = _prepare.image;
911
+ return {
912
+ title: title,
913
+ subtitle: subtitle,
914
+ image: image
915
+ };
916
+ })
917
+ }
918
+ };
919
+ } catch (e) {
920
+ res[sourcePath] = {
921
+ status: "error",
922
+ message: e instanceof Error ? e.message : "Unknown error"
923
+ };
884
924
  }
885
925
  }
886
926
  return res;
887
927
  }
928
+ }, {
929
+ key: "preview",
930
+ value: function preview(input) {
931
+ this.previewInput = input;
932
+ return this;
933
+ }
888
934
  }]);
889
935
  }(Schema);
890
936
  var array = function array(schema) {
@@ -2145,6 +2191,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2145
2191
  status: "success",
2146
2192
  data: {
2147
2193
  layout: "list",
2194
+ parent: "record",
2148
2195
  items: Object.entries(src).map(function (_ref6) {
2149
2196
  var _ref7 = _slicedToArray(_ref6, 2),
2150
2197
  key = _ref7[0],
@@ -2182,9 +2229,6 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2182
2229
  }
2183
2230
  }]);
2184
2231
  }(Schema);
2185
-
2186
- // TODO: improve this so that we do not get RawString and string, only string. Are there other things?
2187
-
2188
2232
  var record = function record(schema) {
2189
2233
  return new RecordSchema(schema);
2190
2234
  };
@@ -776,6 +776,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
776
776
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
777
777
  _classCallCheck(this, ArraySchema);
778
778
  _this = _callSuper(this, ArraySchema);
779
+ _defineProperty(_this, "previewInput", null);
779
780
  _this.item = item;
780
781
  _this.opt = opt;
781
782
  return _this;
@@ -869,20 +870,65 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
869
870
  if (src === null) {
870
871
  return res;
871
872
  }
872
- for (var i = 0; i < ((src === null || src === void 0 ? void 0 : src.length) || 0); i++) {
873
- var itemSrc = src[i];
874
- if (itemSrc === null) {
873
+ for (var key in src) {
874
+ var itemSrc = src[key];
875
+ if (itemSrc === null || itemSrc === undefined) {
875
876
  continue;
876
877
  }
877
- var subPath = unsafeCreateSourcePath(sourcePath, i);
878
+ var subPath = unsafeCreateSourcePath(sourcePath, key);
878
879
  var itemResult = this.item["executePreview"](subPath, itemSrc);
879
880
  for (var keyS in itemResult) {
880
- var key = keyS;
881
- res[key] = itemResult[key];
881
+ var _key = keyS;
882
+ res[_key] = itemResult[_key];
883
+ }
884
+ }
885
+ if (this.previewInput) {
886
+ var _this$previewInput = this.previewInput,
887
+ prepare = _this$previewInput.prepare,
888
+ layout = _this$previewInput.layout;
889
+ if (layout !== "list") {
890
+ res[sourcePath] = {
891
+ status: "error",
892
+ message: "Unknown layout type: " + layout
893
+ };
894
+ }
895
+ try {
896
+ res[sourcePath] = {
897
+ status: "success",
898
+ data: {
899
+ layout: "list",
900
+ parent: "array",
901
+ items: src.map(function (val) {
902
+ // NB NB: display is actually defined by the user
903
+ var _prepare = prepare({
904
+ val: val
905
+ }),
906
+ title = _prepare.title,
907
+ subtitle = _prepare.subtitle,
908
+ image = _prepare.image;
909
+ return {
910
+ title: title,
911
+ subtitle: subtitle,
912
+ image: image
913
+ };
914
+ })
915
+ }
916
+ };
917
+ } catch (e) {
918
+ res[sourcePath] = {
919
+ status: "error",
920
+ message: e instanceof Error ? e.message : "Unknown error"
921
+ };
882
922
  }
883
923
  }
884
924
  return res;
885
925
  }
926
+ }, {
927
+ key: "preview",
928
+ value: function preview(input) {
929
+ this.previewInput = input;
930
+ return this;
931
+ }
886
932
  }]);
887
933
  }(Schema);
888
934
  var array = function array(schema) {
@@ -2143,6 +2189,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2143
2189
  status: "success",
2144
2190
  data: {
2145
2191
  layout: "list",
2192
+ parent: "record",
2146
2193
  items: Object.entries(src).map(function (_ref6) {
2147
2194
  var _ref7 = _slicedToArray(_ref6, 2),
2148
2195
  key = _ref7[0],
@@ -2180,9 +2227,6 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2180
2227
  }
2181
2228
  }]);
2182
2229
  }(Schema);
2183
-
2184
- // TODO: improve this so that we do not get RawString and string, only string. Are there other things?
2185
-
2186
2230
  var record = function record(schema) {
2187
2231
  return new RecordSchema(schema);
2188
2232
  };
@@ -778,6 +778,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
778
778
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
779
779
  _classCallCheck(this, ArraySchema);
780
780
  _this = _callSuper(this, ArraySchema);
781
+ _defineProperty(_this, "previewInput", null);
781
782
  _this.item = item;
782
783
  _this.opt = opt;
783
784
  return _this;
@@ -871,20 +872,65 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
871
872
  if (src === null) {
872
873
  return res;
873
874
  }
874
- for (var i = 0; i < ((src === null || src === void 0 ? void 0 : src.length) || 0); i++) {
875
- var itemSrc = src[i];
876
- if (itemSrc === null) {
875
+ for (var key in src) {
876
+ var itemSrc = src[key];
877
+ if (itemSrc === null || itemSrc === undefined) {
877
878
  continue;
878
879
  }
879
- var subPath = unsafeCreateSourcePath(sourcePath, i);
880
+ var subPath = unsafeCreateSourcePath(sourcePath, key);
880
881
  var itemResult = this.item["executePreview"](subPath, itemSrc);
881
882
  for (var keyS in itemResult) {
882
- var key = keyS;
883
- res[key] = itemResult[key];
883
+ var _key = keyS;
884
+ res[_key] = itemResult[_key];
885
+ }
886
+ }
887
+ if (this.previewInput) {
888
+ var _this$previewInput = this.previewInput,
889
+ prepare = _this$previewInput.prepare,
890
+ layout = _this$previewInput.layout;
891
+ if (layout !== "list") {
892
+ res[sourcePath] = {
893
+ status: "error",
894
+ message: "Unknown layout type: " + layout
895
+ };
896
+ }
897
+ try {
898
+ res[sourcePath] = {
899
+ status: "success",
900
+ data: {
901
+ layout: "list",
902
+ parent: "array",
903
+ items: src.map(function (val) {
904
+ // NB NB: display is actually defined by the user
905
+ var _prepare = prepare({
906
+ val: val
907
+ }),
908
+ title = _prepare.title,
909
+ subtitle = _prepare.subtitle,
910
+ image = _prepare.image;
911
+ return {
912
+ title: title,
913
+ subtitle: subtitle,
914
+ image: image
915
+ };
916
+ })
917
+ }
918
+ };
919
+ } catch (e) {
920
+ res[sourcePath] = {
921
+ status: "error",
922
+ message: e instanceof Error ? e.message : "Unknown error"
923
+ };
884
924
  }
885
925
  }
886
926
  return res;
887
927
  }
928
+ }, {
929
+ key: "preview",
930
+ value: function preview(input) {
931
+ this.previewInput = input;
932
+ return this;
933
+ }
888
934
  }]);
889
935
  }(Schema);
890
936
  var array = function array(schema) {
@@ -2145,6 +2191,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2145
2191
  status: "success",
2146
2192
  data: {
2147
2193
  layout: "list",
2194
+ parent: "record",
2148
2195
  items: Object.entries(src).map(function (_ref6) {
2149
2196
  var _ref7 = _slicedToArray(_ref6, 2),
2150
2197
  key = _ref7[0],
@@ -2182,9 +2229,6 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2182
2229
  }
2183
2230
  }]);
2184
2231
  }(Schema);
2185
-
2186
- // TODO: improve this so that we do not get RawString and string, only string. Are there other things?
2187
-
2188
2232
  var record = function record(schema) {
2189
2233
  return new RecordSchema(schema);
2190
2234
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-2ca75670.cjs.dev.js');
5
+ var dist_valbuildCore = require('./index-beacdff9.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 dist_valbuildCore = require('./index-5d34673d.cjs.prod.js');
5
+ var dist_valbuildCore = require('./index-1061d844.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, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, p as RichTextSchema, S as Schema, k as StringSchema, U as UnionSchema, V as VAL_EXTENSION, j as derefPatch, q as deserializeSchema, i as initVal, m as modules } from './index-e30d6317.esm.js';
1
+ export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, p as RichTextSchema, S as Schema, k as StringSchema, U as UnionSchema, V as VAL_EXTENSION, j as derefPatch, q as deserializeSchema, i as initVal, m as modules } from './index-24c8829d.esm.js';
2
2
  import './result-daff1cae.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.78.0",
3
+ "version": "0.78.2",
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 dist_valbuildCore = require('../../dist/index-2ca75670.cjs.dev.js');
5
+ var dist_valbuildCore = require('../../dist/index-beacdff9.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 dist_valbuildCore = require('../../dist/index-5d34673d.cjs.prod.js');
5
+ var dist_valbuildCore = require('../../dist/index-1061d844.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-e30d6317.esm.js';
2
- export { P as PatchError } from '../../dist/index-e30d6317.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-24c8829d.esm.js';
2
+ export { P as PatchError } from '../../dist/index-24c8829d.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-daff1cae.esm.js';
4
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
5
5