bleam 0.0.11 → 0.0.12

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.
Files changed (51) hide show
  1. package/dist/ai.cjs +2314 -2173
  2. package/dist/ai.d.cts +227 -322
  3. package/dist/ai.d.ts +227 -322
  4. package/dist/ai.js +2309 -2159
  5. package/dist/cli.d.cts +1 -1
  6. package/dist/cli.d.ts +1 -1
  7. package/dist/config.d.cts +1 -1
  8. package/dist/config.d.ts +1 -1
  9. package/dist/{files-Ds1wT8C2.js → files-BXVkPrPN.js} +6 -1
  10. package/dist/{files-Bo7h9fik.cjs → files-DxaQ-Nv0.cjs} +11 -0
  11. package/dist/files.cjs +1 -1
  12. package/dist/files.d.cts +1 -1
  13. package/dist/files.d.ts +1 -1
  14. package/dist/files.js +1 -1
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/schema-B5BfdswF.js +226 -0
  18. package/dist/schema-BnVZOXfu.cjs +286 -0
  19. package/dist/schema-D5eImHxu.d.cts +125 -0
  20. package/dist/schema-SSjokbtw.d.ts +125 -0
  21. package/dist/schema.cjs +10 -2
  22. package/dist/schema.d.cts +2 -2
  23. package/dist/schema.d.ts +2 -2
  24. package/dist/schema.js +2 -2
  25. package/dist/state-Dh3HLixb.js +874 -0
  26. package/dist/state-LssDgpff.cjs +973 -0
  27. package/dist/state.cjs +16 -12
  28. package/dist/state.d.cts +144 -140
  29. package/dist/state.d.ts +145 -140
  30. package/dist/state.js +3 -3
  31. package/dist/{ui-CHc4xEs_.d.ts → ui-D7bRLYee.d.ts} +7 -7
  32. package/dist/ui.d.ts +1 -1
  33. package/dist/window.d.ts +1 -1
  34. package/package.json +3 -1
  35. package/templates/foundation-models/app/index.tsx +77 -15
  36. package/templates/image-generation/app/index.tsx +2 -2
  37. package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +46 -46
  38. package/templates/native/ios/Podfile.lock +173 -173
  39. package/templates/native/modules/bleam-runtime/ios/AIModule.swift +35 -357
  40. package/templates/text-generation/app/index.tsx +81 -50
  41. package/templates/updates/README.md +1 -1
  42. package/dist/schema-Bo5Jvqus.js +0 -90
  43. package/dist/schema-CYh6n8GS.d.ts +0 -58
  44. package/dist/schema-oeOrd3i1.d.cts +0 -58
  45. package/dist/schema-rQ13mrpD.cjs +0 -102
  46. package/dist/state-Bx0VlTlO.cjs +0 -852
  47. package/dist/state-CAwe-Vw1.js +0 -767
  48. /package/dist/{config-Cms0rvqg.d.ts → config-COcRnn5a.d.cts} +0 -0
  49. /package/dist/{config-CufOVJV3.d.cts → config-Chi-flpJ.d.ts} +0 -0
  50. /package/dist/{files-4ZEoAWiv.d.ts → files-DwA7pzr3.d.cts} +0 -0
  51. /package/dist/{files-Dt5mbzLq.d.cts → files-VrkQlKIT.d.ts} +0 -0
package/dist/cli.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as BleamAppearance } from "./config-CufOVJV3.cjs";
2
+ import { t as BleamAppearance } from "./config-COcRnn5a.cjs";
3
3
 
4
4
  //#region src/cli.d.ts
5
5
  interface BuildOptions {
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as BleamAppearance } from "./config-Cms0rvqg.js";
2
+ import { t as BleamAppearance } from "./config-Chi-flpJ.js";
3
3
 
4
4
  //#region src/cli.d.ts
5
5
  interface BuildOptions {
package/dist/config.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-CufOVJV3.cjs";
1
+ import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-COcRnn5a.cjs";
2
2
  export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
package/dist/config.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-Cms0rvqg.js";
1
+ import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-Chi-flpJ.js";
2
2
  export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
@@ -84,6 +84,11 @@ async function nativeRemove(path, recursive) {
84
84
  }
85
85
  fileManager().removeItemAtPathError(path, null);
86
86
  }
87
+ async function nativeCopy(source, destination) {
88
+ ensureDirectory(parentDirectory(destination));
89
+ if (fileManager().fileExistsAtPath(destination)) fileManager().removeItemAtPathError(destination, null);
90
+ if (!fileManager().copyItemAtPathToPathError(source, destination, null)) throw new Error(`Could not copy file from ${source} to ${destination}`);
91
+ }
87
92
  async function nativeReadText(path) {
88
93
  return String(NSString.stringWithContentsOfFileEncodingError(path, NSUTF8StringEncoding, null));
89
94
  }
@@ -442,4 +447,4 @@ const files = {
442
447
  };
443
448
 
444
449
  //#endregion
445
- export { files as i, DownloadTask as n, FileRef as r, DirectoryRef as t };
450
+ export { nativeCopy as a, files as i, DownloadTask as n, FileRef as r, DirectoryRef as t };
@@ -84,6 +84,11 @@ async function nativeRemove(path, recursive) {
84
84
  }
85
85
  fileManager().removeItemAtPathError(path, null);
86
86
  }
87
+ async function nativeCopy(source, destination) {
88
+ ensureDirectory(parentDirectory(destination));
89
+ if (fileManager().fileExistsAtPath(destination)) fileManager().removeItemAtPathError(destination, null);
90
+ if (!fileManager().copyItemAtPathToPathError(source, destination, null)) throw new Error(`Could not copy file from ${source} to ${destination}`);
91
+ }
87
92
  async function nativeReadText(path) {
88
93
  return String(NSString.stringWithContentsOfFileEncodingError(path, NSUTF8StringEncoding, null));
89
94
  }
@@ -465,4 +470,10 @@ Object.defineProperty(exports, 'files', {
465
470
  get: function () {
466
471
  return files;
467
472
  }
473
+ });
474
+ Object.defineProperty(exports, 'nativeCopy', {
475
+ enumerable: true,
476
+ get: function () {
477
+ return nativeCopy;
478
+ }
468
479
  });
package/dist/files.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  require('./native-runtime-CsXnXkQn.cjs');
2
- const require_files = require('./files-Bo7h9fik.cjs');
2
+ const require_files = require('./files-DxaQ-Nv0.cjs');
3
3
 
4
4
  exports.DirectoryRef = require_files.DirectoryRef;
5
5
  exports.DownloadTask = require_files.DownloadTask;
package/dist/files.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-Dt5mbzLq.cjs";
1
+ import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-DwA7pzr3.cjs";
2
2
  export { CreateDirectoryOptions, DirectoryRef, DownloadOptions, DownloadProgress, DownloadTask, FilePaths, FileRef, FileStat, FileType, PickFileType, PickOptions, RemoveOptions, WriteOptions, files };
package/dist/files.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-4ZEoAWiv.js";
1
+ import { a as DownloadTask, c as FileStat, d as PickOptions, f as RemoveOptions, i as DownloadProgress, l as FileType, m as files, n as DirectoryRef, o as FilePaths, p as WriteOptions, r as DownloadOptions, s as FileRef, t as CreateDirectoryOptions, u as PickFileType } from "./files-VrkQlKIT.js";
2
2
  export { CreateDirectoryOptions, DirectoryRef, DownloadOptions, DownloadProgress, DownloadTask, FilePaths, FileRef, FileStat, FileType, PickFileType, PickOptions, RemoveOptions, WriteOptions, files };
package/dist/files.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./native-runtime-C85Nuc4F.js";
2
- import { i as files, n as DownloadTask, r as FileRef, t as DirectoryRef } from "./files-Ds1wT8C2.js";
2
+ import { i as files, n as DownloadTask, r as FileRef, t as DirectoryRef } from "./files-BXVkPrPN.js";
3
3
 
4
4
  export { DirectoryRef, DownloadTask, FileRef, files };
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-CufOVJV3.cjs";
1
+ import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-COcRnn5a.cjs";
2
2
  export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-Cms0rvqg.js";
1
+ import { a as HexColor, c as defineConfig, i as BleamUserInterfaceStyle, n as BleamConfig, o as appConfig, r as BleamInternalExpoConfig, s as createExpoConfig, t as BleamAppearance } from "./config-Chi-flpJ.js";
2
2
  export { BleamAppearance, BleamConfig, BleamInternalExpoConfig, BleamUserInterfaceStyle, HexColor, appConfig, createExpoConfig, defineConfig };
@@ -0,0 +1,226 @@
1
+ //#region src/schema.ts
2
+ var SchemaError = class extends Error {
3
+ constructor(issues) {
4
+ super(issues.map((issue$1) => issue$1.message).join("\n"));
5
+ this.issues = issues;
6
+ this.name = "SchemaError";
7
+ }
8
+ };
9
+ function string(options) {
10
+ return options ? {
11
+ kind: "string",
12
+ hasDefault: true,
13
+ defaultValue: options.default
14
+ } : {
15
+ kind: "string",
16
+ hasDefault: false
17
+ };
18
+ }
19
+ function number(options) {
20
+ if (options && !Number.isFinite(options.default)) throw new TypeError("Number defaults must be finite");
21
+ return options ? {
22
+ kind: "number",
23
+ hasDefault: true,
24
+ defaultValue: options.default
25
+ } : {
26
+ kind: "number",
27
+ hasDefault: false
28
+ };
29
+ }
30
+ function boolean(options) {
31
+ return options ? {
32
+ kind: "boolean",
33
+ hasDefault: true,
34
+ defaultValue: options.default
35
+ } : {
36
+ kind: "boolean",
37
+ hasDefault: false
38
+ };
39
+ }
40
+ function literal(value, options) {
41
+ if (typeof value === "number" && !Number.isFinite(value)) throw new TypeError("Number literals must be finite");
42
+ if (options && options.default !== value) throw new TypeError("A literal default must equal its literal value");
43
+ return options ? {
44
+ kind: "literal",
45
+ hasDefault: true,
46
+ value,
47
+ defaultValue: options.default
48
+ } : {
49
+ kind: "literal",
50
+ hasDefault: false,
51
+ value
52
+ };
53
+ }
54
+ function object(shape, options) {
55
+ return options ? {
56
+ kind: "object",
57
+ hasDefault: true,
58
+ shape,
59
+ defaultFactory: options.default
60
+ } : {
61
+ kind: "object",
62
+ hasDefault: false,
63
+ shape
64
+ };
65
+ }
66
+ function array(item, options) {
67
+ return options ? {
68
+ kind: "array",
69
+ hasDefault: true,
70
+ item,
71
+ defaultFactory: options.default
72
+ } : {
73
+ kind: "array",
74
+ hasDefault: false,
75
+ item
76
+ };
77
+ }
78
+ function pathName(path) {
79
+ return path && path.length > 0 ? path.map(String).join(".") : "value";
80
+ }
81
+ function issue(message, path = []) {
82
+ return {
83
+ message,
84
+ path
85
+ };
86
+ }
87
+ function isPlainObject(value) {
88
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
89
+ const prototype = Object.getPrototypeOf(value);
90
+ return prototype === Object.prototype || prototype === null;
91
+ }
92
+ function parseField(field, value, present, path) {
93
+ if (!present) {
94
+ if (!field.hasDefault) return { present: false };
95
+ try {
96
+ value = field.kind === "object" || field.kind === "array" ? field.defaultFactory?.() : field.defaultValue;
97
+ present = true;
98
+ } catch (error) {
99
+ return { issues: [issue(`Default factory for ${pathName(path)} failed: ${error instanceof Error ? error.message : String(error)}`, path)] };
100
+ }
101
+ }
102
+ if (value === null || value === void 0) return { issues: [issue(`Expected ${pathName(path)} to be ${field.kind}`, path)] };
103
+ if (field.kind === "string" || field.kind === "boolean") return typeof value === field.kind ? {
104
+ present: true,
105
+ value
106
+ } : { issues: [issue(`Expected ${pathName(path)} to be ${field.kind}`, path)] };
107
+ if (field.kind === "number") return typeof value === "number" && Number.isFinite(value) ? {
108
+ present: true,
109
+ value
110
+ } : { issues: [issue(`Expected ${pathName(path)} to be a finite number`, path)] };
111
+ if (field.kind === "literal") return Object.is(value, field.value) ? {
112
+ present: true,
113
+ value: field.value
114
+ } : { issues: [issue(`Expected ${pathName(path)} to equal ${JSON.stringify(field.value)}`, path)] };
115
+ if (field.kind === "object") {
116
+ const result = parseShape(field.shape, value, path);
117
+ return result.issues ? { issues: [...result.issues] } : {
118
+ present: true,
119
+ value: result.value
120
+ };
121
+ }
122
+ if (!Array.isArray(value)) return { issues: [issue(`Expected ${pathName(path)} to be array`, path)] };
123
+ const output = [];
124
+ const issues = [];
125
+ for (let index = 0; index < value.length; index += 1) {
126
+ const result = parseField(field.item, value[index], true, [...path ?? [], index]);
127
+ if ("issues" in result) issues.push(...result.issues);
128
+ else if (result.present) output.push(result.value);
129
+ }
130
+ return issues.length > 0 ? { issues } : {
131
+ present: true,
132
+ value: output
133
+ };
134
+ }
135
+ function parseShape(shape, value, path = []) {
136
+ if (!isPlainObject(value)) return { issues: [issue(`Expected ${pathName(path)} to be object`, path)] };
137
+ const issues = [];
138
+ const output = {};
139
+ for (const key of Reflect.ownKeys(value)) if (typeof key !== "string" || !Object.hasOwn(shape, key)) issues.push(issue(`Unknown field ${pathName([...path ?? [], key])}`, [...path ?? [], key]));
140
+ for (const [key, field] of Object.entries(shape)) {
141
+ const result = parseField(field, value[key], Object.hasOwn(value, key), [...path ?? [], key]);
142
+ if ("issues" in result) issues.push(...result.issues);
143
+ else if (result.present) output[key] = result.value;
144
+ }
145
+ return issues.length > 0 ? { issues } : { value: output };
146
+ }
147
+ function fieldJSONSchema(field) {
148
+ if (field.kind === "literal") return {
149
+ type: typeof field.value,
150
+ const: field.value,
151
+ ...field.hasDefault ? { default: field.defaultValue } : {}
152
+ };
153
+ if (field.kind === "string" || field.kind === "number" || field.kind === "boolean") return {
154
+ type: field.kind,
155
+ ...field.hasDefault ? { default: field.defaultValue } : {}
156
+ };
157
+ if (field.kind === "array") return {
158
+ type: "array",
159
+ items: fieldJSONSchema(field.item)
160
+ };
161
+ return shapeJSONSchema(field.shape);
162
+ }
163
+ function shapeJSONSchema(shape) {
164
+ const properties = {};
165
+ const required = [];
166
+ for (const [key, field] of Object.entries(shape)) {
167
+ properties[key] = fieldJSONSchema(field);
168
+ if (field.hasDefault) required.push(key);
169
+ }
170
+ return {
171
+ type: "object",
172
+ properties,
173
+ required,
174
+ additionalProperties: false
175
+ };
176
+ }
177
+ function createSchema(validate, jsonSchema) {
178
+ return {
179
+ "~standard": {
180
+ version: 1,
181
+ vendor: "bleam",
182
+ validate
183
+ },
184
+ parse(value) {
185
+ const result = validate(value);
186
+ if (result.issues !== void 0) throw new SchemaError(result.issues);
187
+ return result.value;
188
+ },
189
+ safeParse: validate,
190
+ toJSONSchema: jsonSchema,
191
+ transform(transform) {
192
+ return createSchema((value) => {
193
+ const result = validate(value);
194
+ return result.issues !== void 0 ? result : { value: transform(result.value) };
195
+ }, jsonSchema);
196
+ }
197
+ };
198
+ }
199
+ function schema(shape) {
200
+ return createSchema((value) => parseShape(shape, value), () => shapeJSONSchema(shape));
201
+ }
202
+ function getFieldSchema(shape, path) {
203
+ const segments = path.split(".");
204
+ let currentShape = shape;
205
+ let current;
206
+ for (const [index, segment] of segments.entries()) {
207
+ current = currentShape[segment];
208
+ if (!current) throw new Error(`Unknown schema field path "${path}"`);
209
+ if (index < segments.length - 1) {
210
+ if (current.kind !== "object") throw new Error(`Schema field path "${path}" traverses a non-object field`);
211
+ currentShape = current.shape;
212
+ }
213
+ }
214
+ return current;
215
+ }
216
+ function getValueAtPath(value, path) {
217
+ let current = value;
218
+ for (const segment of path.split(".")) {
219
+ if (!isPlainObject(current)) return void 0;
220
+ current = current[segment];
221
+ }
222
+ return current;
223
+ }
224
+
225
+ //#endregion
226
+ export { getValueAtPath as a, object as c, getFieldSchema as i, schema as l, array as n, literal as o, boolean as r, number as s, SchemaError as t, string as u };
@@ -0,0 +1,286 @@
1
+
2
+ //#region src/schema.ts
3
+ var SchemaError = class extends Error {
4
+ constructor(issues) {
5
+ super(issues.map((issue$1) => issue$1.message).join("\n"));
6
+ this.issues = issues;
7
+ this.name = "SchemaError";
8
+ }
9
+ };
10
+ function string(options) {
11
+ return options ? {
12
+ kind: "string",
13
+ hasDefault: true,
14
+ defaultValue: options.default
15
+ } : {
16
+ kind: "string",
17
+ hasDefault: false
18
+ };
19
+ }
20
+ function number(options) {
21
+ if (options && !Number.isFinite(options.default)) throw new TypeError("Number defaults must be finite");
22
+ return options ? {
23
+ kind: "number",
24
+ hasDefault: true,
25
+ defaultValue: options.default
26
+ } : {
27
+ kind: "number",
28
+ hasDefault: false
29
+ };
30
+ }
31
+ function boolean(options) {
32
+ return options ? {
33
+ kind: "boolean",
34
+ hasDefault: true,
35
+ defaultValue: options.default
36
+ } : {
37
+ kind: "boolean",
38
+ hasDefault: false
39
+ };
40
+ }
41
+ function literal(value, options) {
42
+ if (typeof value === "number" && !Number.isFinite(value)) throw new TypeError("Number literals must be finite");
43
+ if (options && options.default !== value) throw new TypeError("A literal default must equal its literal value");
44
+ return options ? {
45
+ kind: "literal",
46
+ hasDefault: true,
47
+ value,
48
+ defaultValue: options.default
49
+ } : {
50
+ kind: "literal",
51
+ hasDefault: false,
52
+ value
53
+ };
54
+ }
55
+ function object(shape, options) {
56
+ return options ? {
57
+ kind: "object",
58
+ hasDefault: true,
59
+ shape,
60
+ defaultFactory: options.default
61
+ } : {
62
+ kind: "object",
63
+ hasDefault: false,
64
+ shape
65
+ };
66
+ }
67
+ function array(item, options) {
68
+ return options ? {
69
+ kind: "array",
70
+ hasDefault: true,
71
+ item,
72
+ defaultFactory: options.default
73
+ } : {
74
+ kind: "array",
75
+ hasDefault: false,
76
+ item
77
+ };
78
+ }
79
+ function pathName(path) {
80
+ return path && path.length > 0 ? path.map(String).join(".") : "value";
81
+ }
82
+ function issue(message, path = []) {
83
+ return {
84
+ message,
85
+ path
86
+ };
87
+ }
88
+ function isPlainObject(value) {
89
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
90
+ const prototype = Object.getPrototypeOf(value);
91
+ return prototype === Object.prototype || prototype === null;
92
+ }
93
+ function parseField(field, value, present, path) {
94
+ if (!present) {
95
+ if (!field.hasDefault) return { present: false };
96
+ try {
97
+ value = field.kind === "object" || field.kind === "array" ? field.defaultFactory?.() : field.defaultValue;
98
+ present = true;
99
+ } catch (error) {
100
+ return { issues: [issue(`Default factory for ${pathName(path)} failed: ${error instanceof Error ? error.message : String(error)}`, path)] };
101
+ }
102
+ }
103
+ if (value === null || value === void 0) return { issues: [issue(`Expected ${pathName(path)} to be ${field.kind}`, path)] };
104
+ if (field.kind === "string" || field.kind === "boolean") return typeof value === field.kind ? {
105
+ present: true,
106
+ value
107
+ } : { issues: [issue(`Expected ${pathName(path)} to be ${field.kind}`, path)] };
108
+ if (field.kind === "number") return typeof value === "number" && Number.isFinite(value) ? {
109
+ present: true,
110
+ value
111
+ } : { issues: [issue(`Expected ${pathName(path)} to be a finite number`, path)] };
112
+ if (field.kind === "literal") return Object.is(value, field.value) ? {
113
+ present: true,
114
+ value: field.value
115
+ } : { issues: [issue(`Expected ${pathName(path)} to equal ${JSON.stringify(field.value)}`, path)] };
116
+ if (field.kind === "object") {
117
+ const result = parseShape(field.shape, value, path);
118
+ return result.issues ? { issues: [...result.issues] } : {
119
+ present: true,
120
+ value: result.value
121
+ };
122
+ }
123
+ if (!Array.isArray(value)) return { issues: [issue(`Expected ${pathName(path)} to be array`, path)] };
124
+ const output = [];
125
+ const issues = [];
126
+ for (let index = 0; index < value.length; index += 1) {
127
+ const result = parseField(field.item, value[index], true, [...path ?? [], index]);
128
+ if ("issues" in result) issues.push(...result.issues);
129
+ else if (result.present) output.push(result.value);
130
+ }
131
+ return issues.length > 0 ? { issues } : {
132
+ present: true,
133
+ value: output
134
+ };
135
+ }
136
+ function parseShape(shape, value, path = []) {
137
+ if (!isPlainObject(value)) return { issues: [issue(`Expected ${pathName(path)} to be object`, path)] };
138
+ const issues = [];
139
+ const output = {};
140
+ for (const key of Reflect.ownKeys(value)) if (typeof key !== "string" || !Object.hasOwn(shape, key)) issues.push(issue(`Unknown field ${pathName([...path ?? [], key])}`, [...path ?? [], key]));
141
+ for (const [key, field] of Object.entries(shape)) {
142
+ const result = parseField(field, value[key], Object.hasOwn(value, key), [...path ?? [], key]);
143
+ if ("issues" in result) issues.push(...result.issues);
144
+ else if (result.present) output[key] = result.value;
145
+ }
146
+ return issues.length > 0 ? { issues } : { value: output };
147
+ }
148
+ function fieldJSONSchema(field) {
149
+ if (field.kind === "literal") return {
150
+ type: typeof field.value,
151
+ const: field.value,
152
+ ...field.hasDefault ? { default: field.defaultValue } : {}
153
+ };
154
+ if (field.kind === "string" || field.kind === "number" || field.kind === "boolean") return {
155
+ type: field.kind,
156
+ ...field.hasDefault ? { default: field.defaultValue } : {}
157
+ };
158
+ if (field.kind === "array") return {
159
+ type: "array",
160
+ items: fieldJSONSchema(field.item)
161
+ };
162
+ return shapeJSONSchema(field.shape);
163
+ }
164
+ function shapeJSONSchema(shape) {
165
+ const properties = {};
166
+ const required = [];
167
+ for (const [key, field] of Object.entries(shape)) {
168
+ properties[key] = fieldJSONSchema(field);
169
+ if (field.hasDefault) required.push(key);
170
+ }
171
+ return {
172
+ type: "object",
173
+ properties,
174
+ required,
175
+ additionalProperties: false
176
+ };
177
+ }
178
+ function createSchema(validate, jsonSchema) {
179
+ return {
180
+ "~standard": {
181
+ version: 1,
182
+ vendor: "bleam",
183
+ validate
184
+ },
185
+ parse(value) {
186
+ const result = validate(value);
187
+ if (result.issues !== void 0) throw new SchemaError(result.issues);
188
+ return result.value;
189
+ },
190
+ safeParse: validate,
191
+ toJSONSchema: jsonSchema,
192
+ transform(transform) {
193
+ return createSchema((value) => {
194
+ const result = validate(value);
195
+ return result.issues !== void 0 ? result : { value: transform(result.value) };
196
+ }, jsonSchema);
197
+ }
198
+ };
199
+ }
200
+ function schema(shape) {
201
+ return createSchema((value) => parseShape(shape, value), () => shapeJSONSchema(shape));
202
+ }
203
+ function getFieldSchema(shape, path) {
204
+ const segments = path.split(".");
205
+ let currentShape = shape;
206
+ let current;
207
+ for (const [index, segment] of segments.entries()) {
208
+ current = currentShape[segment];
209
+ if (!current) throw new Error(`Unknown schema field path "${path}"`);
210
+ if (index < segments.length - 1) {
211
+ if (current.kind !== "object") throw new Error(`Schema field path "${path}" traverses a non-object field`);
212
+ currentShape = current.shape;
213
+ }
214
+ }
215
+ return current;
216
+ }
217
+ function getValueAtPath(value, path) {
218
+ let current = value;
219
+ for (const segment of path.split(".")) {
220
+ if (!isPlainObject(current)) return void 0;
221
+ current = current[segment];
222
+ }
223
+ return current;
224
+ }
225
+
226
+ //#endregion
227
+ Object.defineProperty(exports, 'SchemaError', {
228
+ enumerable: true,
229
+ get: function () {
230
+ return SchemaError;
231
+ }
232
+ });
233
+ Object.defineProperty(exports, 'array', {
234
+ enumerable: true,
235
+ get: function () {
236
+ return array;
237
+ }
238
+ });
239
+ Object.defineProperty(exports, 'boolean', {
240
+ enumerable: true,
241
+ get: function () {
242
+ return boolean;
243
+ }
244
+ });
245
+ Object.defineProperty(exports, 'getFieldSchema', {
246
+ enumerable: true,
247
+ get: function () {
248
+ return getFieldSchema;
249
+ }
250
+ });
251
+ Object.defineProperty(exports, 'getValueAtPath', {
252
+ enumerable: true,
253
+ get: function () {
254
+ return getValueAtPath;
255
+ }
256
+ });
257
+ Object.defineProperty(exports, 'literal', {
258
+ enumerable: true,
259
+ get: function () {
260
+ return literal;
261
+ }
262
+ });
263
+ Object.defineProperty(exports, 'number', {
264
+ enumerable: true,
265
+ get: function () {
266
+ return number;
267
+ }
268
+ });
269
+ Object.defineProperty(exports, 'object', {
270
+ enumerable: true,
271
+ get: function () {
272
+ return object;
273
+ }
274
+ });
275
+ Object.defineProperty(exports, 'schema', {
276
+ enumerable: true,
277
+ get: function () {
278
+ return schema;
279
+ }
280
+ });
281
+ Object.defineProperty(exports, 'string', {
282
+ enumerable: true,
283
+ get: function () {
284
+ return string;
285
+ }
286
+ });