@valbuild/core 0.87.4 → 0.88.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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @valbuild/core
2
+
3
+ Core library for Val, providing schema definitions and content validation for type-safe, hard-coded content management.
4
+
5
+ See the [documentation](https://val.build/docs) for more information.
@@ -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 ListRecordRender, type ListArrayRender, type ReifiedRender, } from "./render.js";
55
+ export { type ListRecordRender, type ListArrayRender, type ReifiedRender, type CodeLanguage, type CodeRender, } from "./render.js";
56
56
  export type { ValRouter, RouteValidationError } from "./router.js";
57
57
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
58
58
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
@@ -12,12 +12,83 @@ import { record } from "./schema/record.js";
12
12
  import { file } from "./schema/file.js";
13
13
  import { date } from "./schema/date.js";
14
14
  export type InitSchema = {
15
+ /**
16
+ * Define a string.
17
+ *
18
+ * @example
19
+ * const schema = s.string();
20
+ * export default c.define("/example.val.ts", schema, "test");
21
+ *
22
+ */
15
23
  readonly string: typeof string;
24
+ /**
25
+ * Define a boolean.
26
+ *
27
+ * @example
28
+ * const schema = s.boolean();
29
+ * export default c.define("/example.val.ts", schema, true);
30
+ *
31
+ */
16
32
  readonly boolean: typeof boolean;
33
+ /**
34
+ * Define an array.
35
+ *
36
+ * @example
37
+ * const schema = s.array(s.string());
38
+ * export default c.define("/example.val.ts", schema, ["test", "test2"]);
39
+ *
40
+ */
17
41
  readonly array: typeof array;
42
+ /**
43
+ * Define an object.
44
+ *
45
+ * @example
46
+ * const schema = s.object({
47
+ * text: s.string(),
48
+ * });
49
+ * export default c.define("/example.val.ts", schema, { text: "test" });
50
+ */
18
51
  readonly object: typeof object;
52
+ /**
53
+ * Define a number.
54
+ *
55
+ * @example
56
+ * const schema = s.number();
57
+ * export default c.define("/example.val.ts", schema, 1);
58
+ *
59
+ */
19
60
  readonly number: typeof number;
61
+ /**
62
+ * Define a union.
63
+ *
64
+ * @example // union of string literals
65
+ * const schema = s.union(s.literal("test"), s.literal("test2"));
66
+ * export default c.define("/example.val.ts", schema, "test");
67
+ *
68
+ * @example // union of string literals
69
+ * const schema = s.union("type", s.object({
70
+ * type: s.literal("test"),
71
+ * value: s.string()
72
+ * }), s.object({
73
+ * type: s.literal("test2"),
74
+ * value: s.string()
75
+ * }));
76
+ * export default c.define("/example.val.ts", schema, {
77
+ * type: "test",
78
+ * value: "test"
79
+ * });
80
+ *
81
+ */
20
82
  readonly union: typeof union;
83
+ /**
84
+ * Define a rich text.
85
+ *
86
+ * @example
87
+ * const schema = s.richtext();
88
+ * export default c.define("/example.val.ts", schema, [
89
+ * { tag: "h1", children: ["Title 1"] },
90
+ * ]);
91
+ */
21
92
  readonly richtext: typeof richtext;
22
93
  /**
23
94
  * Define an image.
@@ -38,10 +109,52 @@ export type InitSchema = {
38
109
  *
39
110
  */
40
111
  readonly image: typeof image;
112
+ /**
113
+ * Define a literal.
114
+ *
115
+ * @example
116
+ * const schema = s.literal("test");
117
+ * export default c.define("/example.val.ts", schema, "test");
118
+ *
119
+ */
41
120
  readonly literal: typeof literal;
121
+ /**
122
+ * Define a key of.
123
+ *
124
+ * @example
125
+ * const schema = s.keyOf(s.string());
126
+ * export default c.define("/example.val.ts", schema, "test");
127
+ *
128
+ */
42
129
  readonly keyOf: typeof keyOf;
130
+ /**
131
+ * Define a record.
132
+ *
133
+ * @example
134
+ * const schema = s.record(s.string());
135
+ * export default c.define("/example.val.ts", schema, { "test": "test" });
136
+ *
137
+ */
43
138
  readonly record: typeof record;
139
+ /**
140
+ * Define a file.
141
+ *
142
+ * Use `c.file` to create a file source.
143
+ *
144
+ * @example
145
+ * const schema = s.file();
146
+ * export default c.define("/example.val.ts", schema, c.file("/public/val/example.png"));
147
+ *
148
+ */
44
149
  readonly file: typeof file;
150
+ /**
151
+ * Define a date.
152
+ *
153
+ * @example
154
+ * const schema = s.date();
155
+ * export default c.define("/example.val.ts", schema, "2025-01-01");
156
+ *
157
+ */
45
158
  readonly date: typeof date;
46
159
  };
47
160
  export declare function initSchema(): {
@@ -28,7 +28,12 @@ export type ListArrayRender = {
28
28
  export type TextareaRender = {
29
29
  layout: "textarea";
30
30
  };
31
- type RenderTypes = ListRecordRender | ListArrayRender | TextareaRender;
31
+ export type CodeLanguage = "typescript" | "javascript" | "javascriptreact" | "typescriptreact" | "json" | "java" | "html" | "css" | "xml" | "markdown" | "sql" | "python" | "rust" | "php" | "go" | "cpp" | "sass" | "vue" | "angular";
32
+ export type CodeRender = {
33
+ layout: "code";
34
+ language: CodeLanguage;
35
+ };
36
+ type RenderTypes = ListRecordRender | ListArrayRender | TextareaRender | CodeRender;
32
37
  type WithStatus<T> = {
33
38
  status: "error";
34
39
  message: string;
@@ -1,5 +1,5 @@
1
1
  import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
- import { ReifiedRender } from "../render.js";
2
+ import { CodeLanguage, ReifiedRender } from "../render.js";
3
3
  import { ModuleFilePath, SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
5
5
  type StringOptions = {
@@ -36,6 +36,9 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
36
36
  private readonly renderInput;
37
37
  constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], renderInput?: {
38
38
  as: "textarea";
39
+ } | {
40
+ as: "code";
41
+ language: CodeLanguage;
39
42
  } | null);
40
43
  /**
41
44
  * @deprecated Use `minLength` instead
@@ -56,6 +59,9 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
56
59
  protected executeSerialize(): SerializedSchema;
57
60
  render(input: {
58
61
  as: "textarea";
62
+ } | {
63
+ as: "code";
64
+ language: CodeLanguage;
59
65
  }): StringSchema<Src>;
60
66
  protected executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
61
67
  }
@@ -832,6 +832,15 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
832
832
  key: "executeRender",
833
833
  value: function executeRender(sourcePath, src) {
834
834
  if (this.renderInput) {
835
+ if (this.renderInput.as === "code") {
836
+ return _defineProperty({}, sourcePath, {
837
+ status: "success",
838
+ data: {
839
+ layout: this.renderInput.as,
840
+ language: this.renderInput.language
841
+ }
842
+ });
843
+ }
835
844
  return _defineProperty({}, sourcePath, {
836
845
  status: "success",
837
846
  data: {
@@ -834,6 +834,15 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
834
834
  key: "executeRender",
835
835
  value: function executeRender(sourcePath, src) {
836
836
  if (this.renderInput) {
837
+ if (this.renderInput.as === "code") {
838
+ return _defineProperty({}, sourcePath, {
839
+ status: "success",
840
+ data: {
841
+ layout: this.renderInput.as,
842
+ language: this.renderInput.language
843
+ }
844
+ });
845
+ }
837
846
  return _defineProperty({}, sourcePath, {
838
847
  status: "success",
839
848
  data: {
@@ -834,6 +834,15 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
834
834
  key: "executeRender",
835
835
  value: function executeRender(sourcePath, src) {
836
836
  if (this.renderInput) {
837
+ if (this.renderInput.as === "code") {
838
+ return _defineProperty({}, sourcePath, {
839
+ status: "success",
840
+ data: {
841
+ layout: this.renderInput.as,
842
+ language: this.renderInput.language
843
+ }
844
+ });
845
+ }
837
846
  return _defineProperty({}, sourcePath, {
838
847
  status: "success",
839
848
  data: {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-e3cd5eca.cjs.dev.js');
5
+ var dist_valbuildCore = require('./index-eb1a6b1f.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-b20e3bab.cjs.prod.js');
5
+ var dist_valbuildCore = require('./index-34063fba.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-2b6db652.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-11591a0b.esm.js';
2
2
  import './result-daff1cae.esm.js';
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.87.4",
3
+ "version": "0.88.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/valbuild/val.git"
8
+ "url": "git+https://github.com/valbuild/val.git"
9
9
  },
10
10
  "scripts": {
11
11
  "typecheck": "tsc --noEmit",
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('../../dist/index-e3cd5eca.cjs.dev.js');
5
+ var dist_valbuildCore = require('../../dist/index-eb1a6b1f.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-b20e3bab.cjs.prod.js');
5
+ var dist_valbuildCore = require('../../dist/index-34063fba.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-2b6db652.esm.js';
2
- export { P as PatchError } from '../../dist/index-2b6db652.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-11591a0b.esm.js';
2
+ export { P as PatchError } from '../../dist/index-11591a0b.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