bleam 0.0.5 → 0.0.7

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 (141) hide show
  1. package/dist/ai.cjs +4146 -0
  2. package/dist/ai.d.cts +535 -0
  3. package/dist/ai.d.ts +535 -0
  4. package/dist/ai.js +4102 -0
  5. package/dist/animated.cjs +286 -0
  6. package/dist/animated.d.cts +47 -0
  7. package/dist/animated.d.ts +47 -0
  8. package/dist/animated.js +281 -0
  9. package/dist/app.cjs +92 -0
  10. package/dist/app.d.cts +1 -2
  11. package/dist/app.d.ts +1 -2
  12. package/dist/app.js +93 -2
  13. package/dist/bundler.d.cts +1 -2
  14. package/dist/bundler.d.ts +1 -2
  15. package/dist/cli.cjs +1375 -71
  16. package/dist/cli.d.cts +89 -1
  17. package/dist/cli.d.ts +89 -1
  18. package/dist/cli.js +1373 -74
  19. package/dist/config-Bb6SULnR.cjs +46 -0
  20. package/dist/config-CfWa3q-k.js +28 -0
  21. package/dist/config-Cms0rvqg.d.ts +40 -0
  22. package/dist/config-CufOVJV3.d.cts +40 -0
  23. package/dist/config.cjs +4 -25
  24. package/dist/config.d.cts +2 -28
  25. package/dist/config.d.ts +2 -28
  26. package/dist/config.js +2 -24
  27. package/dist/crypto-BB92-Upx.js +7 -0
  28. package/dist/crypto-CT3VZ7lF.cjs +13 -0
  29. package/dist/crypto.cjs +2 -2
  30. package/dist/crypto.d.cts +6 -1
  31. package/dist/crypto.d.ts +8 -1
  32. package/dist/crypto.js +2 -2
  33. package/dist/dev-protocol.d.cts +16 -3
  34. package/dist/dev-protocol.d.ts +16 -3
  35. package/dist/dev-protocol.js +1 -2
  36. package/dist/files-Bo7h9fik.cjs +468 -0
  37. package/dist/files-Ds1wT8C2.js +445 -0
  38. package/dist/files-DwA7pzr3.d.cts +99 -0
  39. package/dist/files-VrkQlKIT.d.ts +99 -0
  40. package/dist/files.cjs +7 -0
  41. package/dist/files.d.cts +2 -0
  42. package/dist/files.d.ts +2 -0
  43. package/dist/files.js +4 -0
  44. package/dist/index.cjs +4 -5
  45. package/dist/index.d.cts +2 -3
  46. package/dist/index.d.ts +2 -3
  47. package/dist/index.js +2 -4
  48. package/dist/native-runtime-C85Nuc4F.js +10 -0
  49. package/dist/{native-runtime-CdeT0JyQ.cjs → native-runtime-CsXnXkQn.cjs} +1 -14
  50. package/dist/native-sqlite-xcGdamRD.js +64 -0
  51. package/dist/native-sqlite-yQLD5s9i.cjs +66 -0
  52. package/dist/platform.cjs +27 -0
  53. package/dist/platform.d.cts +39 -0
  54. package/dist/platform.d.ts +39 -0
  55. package/dist/platform.js +21 -0
  56. package/dist/runtime.d.cts +1 -7
  57. package/dist/runtime.d.ts +1 -7
  58. package/dist/schema-Bo5Jvqus.js +90 -0
  59. package/dist/schema-DOOjfXvs.d.ts +58 -0
  60. package/dist/schema-ENSMX_1t.d.cts +58 -0
  61. package/dist/schema-rQ13mrpD.cjs +102 -0
  62. package/dist/schema.cjs +4 -0
  63. package/dist/schema.d.cts +2 -0
  64. package/dist/schema.d.ts +2 -0
  65. package/dist/schema.js +3 -0
  66. package/dist/state-Bx0VlTlO.cjs +852 -0
  67. package/dist/state-CAwe-Vw1.js +767 -0
  68. package/dist/state.cjs +19 -0
  69. package/dist/state.d.cts +159 -0
  70. package/dist/state.d.ts +159 -0
  71. package/dist/state.js +6 -0
  72. package/dist/styles.cjs +742 -0
  73. package/dist/styles.d.cts +701 -0
  74. package/dist/styles.d.ts +701 -0
  75. package/dist/styles.js +739 -0
  76. package/dist/ui-1WepaMS4.d.cts +92 -0
  77. package/dist/ui-234Plg7Z.d.cts +92 -0
  78. package/dist/ui-BJmXhz9Q.d.ts +92 -0
  79. package/dist/ui-Dd7SXdbg.d.cts +92 -0
  80. package/dist/ui-Ds88eETu.d.ts +92 -0
  81. package/dist/ui-TaqnB5SP.d.ts +92 -0
  82. package/dist/ui-WQvnXL0W.d.ts +92 -0
  83. package/dist/ui.cjs +364 -0
  84. package/dist/ui.d.cts +2 -0
  85. package/dist/ui.d.ts +2 -0
  86. package/dist/ui.js +357 -0
  87. package/dist/window.cjs +596 -0
  88. package/dist/window.d.cts +63 -0
  89. package/dist/window.d.ts +63 -0
  90. package/dist/window.js +589 -0
  91. package/metro-config.cjs +18 -13
  92. package/package.json +57 -21
  93. package/templates/basic/app/index.tsx +133 -12
  94. package/templates/basic/app.config.ts +4 -2
  95. package/templates/foundation-models/app/index.tsx +32 -0
  96. package/templates/foundation-models/app.config.ts +5 -0
  97. package/templates/image-generation/app/index.tsx +39 -0
  98. package/templates/image-generation/app.config.ts +5 -0
  99. package/templates/state/app/index.tsx +30 -0
  100. package/templates/state/app.config.ts +5 -0
  101. package/dist/app.d.cts.map +0 -1
  102. package/dist/app.d.ts.map +0 -1
  103. package/dist/app.js.map +0 -1
  104. package/dist/bundler.d.cts.map +0 -1
  105. package/dist/bundler.d.ts.map +0 -1
  106. package/dist/cli.js.map +0 -1
  107. package/dist/config.d.cts.map +0 -1
  108. package/dist/config.d.ts.map +0 -1
  109. package/dist/config.js.map +0 -1
  110. package/dist/crypto-BNhWeXMj.cjs +0 -15
  111. package/dist/crypto-Bg8cD8wX.d.cts +0 -8
  112. package/dist/crypto-Bg8cD8wX.d.cts.map +0 -1
  113. package/dist/crypto-CCA_hvao.js +0 -11
  114. package/dist/crypto-CCA_hvao.js.map +0 -1
  115. package/dist/crypto-IOzbNoJD.d.ts +0 -8
  116. package/dist/crypto-IOzbNoJD.d.ts.map +0 -1
  117. package/dist/dev-protocol.d.cts.map +0 -1
  118. package/dist/dev-protocol.d.ts.map +0 -1
  119. package/dist/dev-protocol.js.map +0 -1
  120. package/dist/fs-BK7joD1g.js +0 -13
  121. package/dist/fs-BK7joD1g.js.map +0 -1
  122. package/dist/fs-CEhcjuN6.d.ts +0 -9
  123. package/dist/fs-CEhcjuN6.d.ts.map +0 -1
  124. package/dist/fs-CfE8CHf_.d.cts +0 -9
  125. package/dist/fs-CfE8CHf_.d.cts.map +0 -1
  126. package/dist/fs-DKHYTPua.cjs +0 -18
  127. package/dist/fs.cjs +0 -3
  128. package/dist/fs.d.cts +0 -2
  129. package/dist/fs.d.ts +0 -2
  130. package/dist/fs.js +0 -3
  131. package/dist/native-runtime-BoqybBBf.js +0 -18
  132. package/dist/native-runtime-BoqybBBf.js.map +0 -1
  133. package/dist/native.cjs +0 -132
  134. package/dist/native.d.cts +0 -64
  135. package/dist/native.d.cts.map +0 -1
  136. package/dist/native.d.ts +0 -64
  137. package/dist/native.d.ts.map +0 -1
  138. package/dist/native.js +0 -133
  139. package/dist/native.js.map +0 -1
  140. package/dist/runtime.d.cts.map +0 -1
  141. package/dist/runtime.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import "./native-runtime-BoqybBBf.js";
2
- import { t as crypto } from "./crypto-CCA_hvao.js";
3
- import { t as fs } from "./fs-BK7joD1g.js";
1
+ import { n as createExpoConfig, r as defineConfig, t as appConfig } from "./config-CfWa3q-k.js";
4
2
 
5
- export { crypto, fs };
3
+ export { appConfig, createExpoConfig, defineConfig };
@@ -0,0 +1,10 @@
1
+ import NativeScript from "@nativescript/react-native";
2
+
3
+ //#region src/native-runtime.ts
4
+ NativeScript.init();
5
+ function ensureNativeScript() {
6
+ return NativeScript;
7
+ }
8
+
9
+ //#endregion
10
+ export { ensureNativeScript as t };
@@ -3,15 +3,8 @@ let __nativescript_react_native = require("@nativescript/react-native");
3
3
  __nativescript_react_native = require_chunk.__toESM(__nativescript_react_native);
4
4
 
5
5
  //#region src/native-runtime.ts
6
- let initialized = false;
7
- function globals() {
8
- return globalThis;
9
- }
6
+ __nativescript_react_native.default.init();
10
7
  function ensureNativeScript() {
11
- if (!initialized) {
12
- __nativescript_react_native.default.init();
13
- initialized = true;
14
- }
15
8
  return __nativescript_react_native.default;
16
9
  }
17
10
 
@@ -21,10 +14,4 @@ Object.defineProperty(exports, 'ensureNativeScript', {
21
14
  get: function () {
22
15
  return ensureNativeScript;
23
16
  }
24
- });
25
- Object.defineProperty(exports, 'globals', {
26
- enumerable: true,
27
- get: function () {
28
- return globals;
29
- }
30
17
  });
@@ -0,0 +1,64 @@
1
+ import "./native-runtime-C85Nuc4F.js";
2
+ import { openOrCreate } from "@nativescript-community/sqlite";
3
+
4
+ //#region src/native-sqlite.ts
5
+ const databases = /* @__PURE__ */ new Map();
6
+ function documentsDirectory() {
7
+ const path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.Document, NSSearchPathDomainMask.UserDomain, true).objectAtIndex(0);
8
+ if (!path) throw new Error("Could not resolve documents directory");
9
+ return String(path);
10
+ }
11
+ function ensureDirectory(path) {
12
+ const fileManager = NSFileManager.defaultManager;
13
+ if (fileManager.fileExistsAtPath(path)) return;
14
+ fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null);
15
+ }
16
+ function databasePath(name) {
17
+ const directory = `${documentsDirectory()}/bleam`;
18
+ ensureDirectory(directory);
19
+ return `${directory}/${name}`;
20
+ }
21
+ function toPluginParameters(parameters) {
22
+ return parameters;
23
+ }
24
+ function toSQLiteValue(value) {
25
+ if (typeof value === "string" || typeof value === "number" || value === null) return value;
26
+ throw new Error("SQLite blobs are not supported by Bleam state yet");
27
+ }
28
+ function toSQLiteRow(row) {
29
+ const output = {};
30
+ for (const [key, value] of Object.entries(row)) output[key] = toSQLiteValue(value);
31
+ return output;
32
+ }
33
+ var NativeSQLiteDatabase = class {
34
+ constructor(database) {
35
+ this.database = database;
36
+ }
37
+ execute(query, parameters) {
38
+ return this.database.execute(query, toPluginParameters(parameters));
39
+ }
40
+ async select(query, parameters) {
41
+ return (await this.database.select(query, toPluginParameters(parameters))).map(toSQLiteRow);
42
+ }
43
+ async get(query, parameters) {
44
+ const row = await this.database.get(query, toPluginParameters(parameters));
45
+ return row ? toSQLiteRow(row) : void 0;
46
+ }
47
+ transaction(action) {
48
+ return this.database.transaction(action);
49
+ }
50
+ close() {
51
+ this.database.close();
52
+ }
53
+ };
54
+ function openNativeSQLiteDatabase(name = "bleam.sqlite3") {
55
+ const path = databasePath(name);
56
+ const existing = databases.get(path);
57
+ if (existing) return new NativeSQLiteDatabase(existing);
58
+ const database = openOrCreate(path);
59
+ databases.set(path, database);
60
+ return new NativeSQLiteDatabase(database);
61
+ }
62
+
63
+ //#endregion
64
+ export { NativeSQLiteDatabase, openNativeSQLiteDatabase };
@@ -0,0 +1,66 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ require('./native-runtime-CsXnXkQn.cjs');
3
+ let __nativescript_community_sqlite = require("@nativescript-community/sqlite");
4
+ __nativescript_community_sqlite = require_chunk.__toESM(__nativescript_community_sqlite);
5
+
6
+ //#region src/native-sqlite.ts
7
+ const databases = /* @__PURE__ */ new Map();
8
+ function documentsDirectory() {
9
+ const path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.Document, NSSearchPathDomainMask.UserDomain, true).objectAtIndex(0);
10
+ if (!path) throw new Error("Could not resolve documents directory");
11
+ return String(path);
12
+ }
13
+ function ensureDirectory(path) {
14
+ const fileManager = NSFileManager.defaultManager;
15
+ if (fileManager.fileExistsAtPath(path)) return;
16
+ fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null);
17
+ }
18
+ function databasePath(name) {
19
+ const directory = `${documentsDirectory()}/bleam`;
20
+ ensureDirectory(directory);
21
+ return `${directory}/${name}`;
22
+ }
23
+ function toPluginParameters(parameters) {
24
+ return parameters;
25
+ }
26
+ function toSQLiteValue(value) {
27
+ if (typeof value === "string" || typeof value === "number" || value === null) return value;
28
+ throw new Error("SQLite blobs are not supported by Bleam state yet");
29
+ }
30
+ function toSQLiteRow(row) {
31
+ const output = {};
32
+ for (const [key, value] of Object.entries(row)) output[key] = toSQLiteValue(value);
33
+ return output;
34
+ }
35
+ var NativeSQLiteDatabase = class {
36
+ constructor(database) {
37
+ this.database = database;
38
+ }
39
+ execute(query, parameters) {
40
+ return this.database.execute(query, toPluginParameters(parameters));
41
+ }
42
+ async select(query, parameters) {
43
+ return (await this.database.select(query, toPluginParameters(parameters))).map(toSQLiteRow);
44
+ }
45
+ async get(query, parameters) {
46
+ const row = await this.database.get(query, toPluginParameters(parameters));
47
+ return row ? toSQLiteRow(row) : void 0;
48
+ }
49
+ transaction(action) {
50
+ return this.database.transaction(action);
51
+ }
52
+ close() {
53
+ this.database.close();
54
+ }
55
+ };
56
+ function openNativeSQLiteDatabase(name = "bleam.sqlite3") {
57
+ const path = databasePath(name);
58
+ const existing = databases.get(path);
59
+ if (existing) return new NativeSQLiteDatabase(existing);
60
+ const database = (0, __nativescript_community_sqlite.openOrCreate)(path);
61
+ databases.set(path, database);
62
+ return new NativeSQLiteDatabase(database);
63
+ }
64
+
65
+ //#endregion
66
+ exports.openNativeSQLiteDatabase = openNativeSQLiteDatabase;
@@ -0,0 +1,27 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ let expo = require("expo");
3
+ expo = require_chunk.__toESM(expo);
4
+
5
+ //#region src/platform.ts
6
+ function getHelperStatus() {
7
+ return (0, expo.requireNativeModule)("Platform").helperStatus();
8
+ }
9
+ function downloadPlatformUpdate() {
10
+ return (0, expo.requireNativeModule)("Platform").downloadPlatformUpdate();
11
+ }
12
+ function updateAndRelaunch(releaseId) {
13
+ return (0, expo.requireNativeModule)("Platform").updateAndRelaunch(releaseId);
14
+ }
15
+ function getPermissionState(capability) {
16
+ return (0, expo.requireNativeModule)("Platform").permissionState(capability);
17
+ }
18
+ function getPermissionStates() {
19
+ return (0, expo.requireNativeModule)("Platform").permissionStates();
20
+ }
21
+
22
+ //#endregion
23
+ exports.downloadPlatformUpdate = downloadPlatformUpdate;
24
+ exports.getHelperStatus = getHelperStatus;
25
+ exports.getPermissionState = getPermissionState;
26
+ exports.getPermissionStates = getPermissionStates;
27
+ exports.updateAndRelaunch = updateAndRelaunch;
@@ -0,0 +1,39 @@
1
+ //#region src/platform.d.ts
2
+ type HelperCapability = 'platform-updates';
3
+ type PermissionCapability = 'camera' | 'microphone' | 'photos' | 'contacts' | 'calendars' | 'reminders' | 'location';
4
+ type PermissionStatus = 'not-determined' | 'denied' | 'restricted' | 'limited' | 'granted' | 'unsupported';
5
+ interface PermissionState {
6
+ capability: PermissionCapability;
7
+ status: PermissionStatus;
8
+ granted: boolean;
9
+ canAskAgain: boolean;
10
+ expires: 'never';
11
+ }
12
+ interface HelperStatus {
13
+ healthy: boolean;
14
+ protocolVersion: 1;
15
+ helperVersion: string;
16
+ platformVersion: string;
17
+ capabilities: HelperCapability[];
18
+ updatesSupported: boolean;
19
+ installPath: string;
20
+ reason?: 'reinstall_required';
21
+ }
22
+ interface PlatformDownload {
23
+ releaseId: string;
24
+ appVersion: string;
25
+ buildNumber: string;
26
+ platformVersion: string;
27
+ artifactPath: string;
28
+ appPath: string;
29
+ sizeBytes: number;
30
+ sha256: string;
31
+ verified: true;
32
+ }
33
+ declare function getHelperStatus(): Promise<HelperStatus>;
34
+ declare function downloadPlatformUpdate(): Promise<PlatformDownload>;
35
+ declare function updateAndRelaunch(releaseId: string): Promise<void>;
36
+ declare function getPermissionState(capability: PermissionCapability): Promise<PermissionState>;
37
+ declare function getPermissionStates(): Promise<PermissionState[]>;
38
+ //#endregion
39
+ export { HelperCapability, HelperStatus, PermissionCapability, PermissionState, PermissionStatus, PlatformDownload, downloadPlatformUpdate, getHelperStatus, getPermissionState, getPermissionStates, updateAndRelaunch };
@@ -0,0 +1,39 @@
1
+ //#region src/platform.d.ts
2
+ type HelperCapability = 'platform-updates';
3
+ type PermissionCapability = 'camera' | 'microphone' | 'photos' | 'contacts' | 'calendars' | 'reminders' | 'location';
4
+ type PermissionStatus = 'not-determined' | 'denied' | 'restricted' | 'limited' | 'granted' | 'unsupported';
5
+ interface PermissionState {
6
+ capability: PermissionCapability;
7
+ status: PermissionStatus;
8
+ granted: boolean;
9
+ canAskAgain: boolean;
10
+ expires: 'never';
11
+ }
12
+ interface HelperStatus {
13
+ healthy: boolean;
14
+ protocolVersion: 1;
15
+ helperVersion: string;
16
+ platformVersion: string;
17
+ capabilities: HelperCapability[];
18
+ updatesSupported: boolean;
19
+ installPath: string;
20
+ reason?: 'reinstall_required';
21
+ }
22
+ interface PlatformDownload {
23
+ releaseId: string;
24
+ appVersion: string;
25
+ buildNumber: string;
26
+ platformVersion: string;
27
+ artifactPath: string;
28
+ appPath: string;
29
+ sizeBytes: number;
30
+ sha256: string;
31
+ verified: true;
32
+ }
33
+ declare function getHelperStatus(): Promise<HelperStatus>;
34
+ declare function downloadPlatformUpdate(): Promise<PlatformDownload>;
35
+ declare function updateAndRelaunch(releaseId: string): Promise<void>;
36
+ declare function getPermissionState(capability: PermissionCapability): Promise<PermissionState>;
37
+ declare function getPermissionStates(): Promise<PermissionState[]>;
38
+ //#endregion
39
+ export { HelperCapability, HelperStatus, PermissionCapability, PermissionState, PermissionStatus, PlatformDownload, downloadPlatformUpdate, getHelperStatus, getPermissionState, getPermissionStates, updateAndRelaunch };
@@ -0,0 +1,21 @@
1
+ import { requireNativeModule } from "expo";
2
+
3
+ //#region src/platform.ts
4
+ function getHelperStatus() {
5
+ return requireNativeModule("Platform").helperStatus();
6
+ }
7
+ function downloadPlatformUpdate() {
8
+ return requireNativeModule("Platform").downloadPlatformUpdate();
9
+ }
10
+ function updateAndRelaunch(releaseId) {
11
+ return requireNativeModule("Platform").updateAndRelaunch(releaseId);
12
+ }
13
+ function getPermissionState(capability) {
14
+ return requireNativeModule("Platform").permissionState(capability);
15
+ }
16
+ function getPermissionStates() {
17
+ return requireNativeModule("Platform").permissionStates();
18
+ }
19
+
20
+ //#endregion
21
+ export { downloadPlatformUpdate, getHelperStatus, getPermissionState, getPermissionStates, updateAndRelaunch };
@@ -1,14 +1,8 @@
1
1
  //#region src/runtime.d.ts
2
- interface RuntimeCapability {
3
- name: string;
4
- version?: string;
5
- }
6
2
  interface RuntimeSession {
7
3
  id: string;
8
4
  projectName: string;
9
5
  manifestUrl: string;
10
- capabilities: RuntimeCapability[];
11
6
  }
12
7
  //#endregion
13
- export { RuntimeCapability, RuntimeSession };
14
- //# sourceMappingURL=runtime.d.cts.map
8
+ export { RuntimeSession };
package/dist/runtime.d.ts CHANGED
@@ -1,14 +1,8 @@
1
1
  //#region src/runtime.d.ts
2
- interface RuntimeCapability {
3
- name: string;
4
- version?: string;
5
- }
6
2
  interface RuntimeSession {
7
3
  id: string;
8
4
  projectName: string;
9
5
  manifestUrl: string;
10
- capabilities: RuntimeCapability[];
11
6
  }
12
7
  //#endregion
13
- export { RuntimeCapability, RuntimeSession };
14
- //# sourceMappingURL=runtime.d.ts.map
8
+ export { RuntimeSession };
@@ -0,0 +1,90 @@
1
+ //#region src/schema.ts
2
+ var SchemaError = class extends Error {
3
+ constructor(issues) {
4
+ super(issues.map((issue) => issue.message).join("\n"));
5
+ this.issues = issues;
6
+ this.name = "SchemaError";
7
+ }
8
+ };
9
+ function tokenMatches(token, value) {
10
+ return typeof value === token;
11
+ }
12
+ function issueFor(key, expected) {
13
+ return {
14
+ message: `Expected ${key} to be ${expected}`,
15
+ path: [key]
16
+ };
17
+ }
18
+ function parseShape(shape, value) {
19
+ if (!value || typeof value !== "object" || Array.isArray(value)) return { issues: [{ message: "Expected object" }] };
20
+ const input = value;
21
+ const output = {};
22
+ const issues = [];
23
+ for (const [key, field] of Object.entries(shape)) {
24
+ const inputValue = input[key];
25
+ if (typeof field === "function") {
26
+ const defaultValue = field();
27
+ const expected = typeof defaultValue;
28
+ if (inputValue === void 0) {
29
+ output[key] = defaultValue;
30
+ continue;
31
+ }
32
+ if (tokenMatches(expected, inputValue)) {
33
+ output[key] = inputValue;
34
+ continue;
35
+ }
36
+ issues.push(issueFor(key, expected));
37
+ continue;
38
+ }
39
+ if (inputValue === void 0) continue;
40
+ if (tokenMatches(field, inputValue)) {
41
+ output[key] = inputValue;
42
+ continue;
43
+ }
44
+ issues.push(issueFor(key, field));
45
+ }
46
+ if (issues.length > 0) return { issues };
47
+ return { value: output };
48
+ }
49
+ function createSchema(validate, jsonSchema) {
50
+ return {
51
+ "~standard": {
52
+ version: 1,
53
+ vendor: "bleam",
54
+ validate
55
+ },
56
+ parse(value) {
57
+ const result = validate(value);
58
+ if (result.issues !== void 0) throw new SchemaError(result.issues);
59
+ return result.value;
60
+ },
61
+ safeParse: validate,
62
+ toJSONSchema: jsonSchema,
63
+ transform(transform) {
64
+ return createSchema((value) => {
65
+ const result = validate(value);
66
+ if (result.issues !== void 0) return result;
67
+ return { value: transform(result.value) };
68
+ }, jsonSchema);
69
+ }
70
+ };
71
+ }
72
+ function schema(shape) {
73
+ return createSchema((value) => parseShape(shape, value), () => {
74
+ const properties = {};
75
+ const required = [];
76
+ for (const [key, field] of Object.entries(shape)) {
77
+ if (typeof field === "function") properties[key] = { type: typeof field() };
78
+ else properties[key] = { type: field };
79
+ required.push(key);
80
+ }
81
+ return {
82
+ type: "object",
83
+ properties,
84
+ required
85
+ };
86
+ });
87
+ }
88
+
89
+ //#endregion
90
+ export { schema as n, SchemaError as t };
@@ -0,0 +1,58 @@
1
+ //#region src/schema.d.ts
2
+ type FieldValue = string | number | boolean;
3
+ type FieldToken = 'string' | 'number' | 'boolean';
4
+ type FieldDefault<T extends FieldValue = FieldValue> = () => T;
5
+ type FieldSchema = FieldToken | FieldDefault;
6
+ type SchemaShape = Record<string, FieldSchema>;
7
+ interface SchemaIssue {
8
+ message: string;
9
+ path?: ReadonlyArray<PropertyKey | {
10
+ key: PropertyKey;
11
+ }>;
12
+ }
13
+ type SchemaResult<Output> = {
14
+ value: Output;
15
+ issues?: undefined;
16
+ } | {
17
+ issues: ReadonlyArray<SchemaIssue>;
18
+ };
19
+ interface StandardSchema<Input = unknown, Output = Input> {
20
+ readonly '~standard': {
21
+ readonly version: 1;
22
+ readonly vendor: string;
23
+ readonly validate: (value: unknown) => SchemaResult<Output>;
24
+ readonly types?: {
25
+ readonly input: Input;
26
+ readonly output: Output;
27
+ };
28
+ };
29
+ }
30
+ type TokenValue<T extends FieldToken> = T extends 'string' ? string : T extends 'number' ? number : boolean;
31
+ type DefaultValue<T> = T extends (() => infer Value) ? Value extends FieldValue ? Value : never : never;
32
+ type TokenKeys<Shape extends SchemaShape> = { [Key in keyof Shape]: Shape[Key] extends FieldToken ? Key : never }[keyof Shape];
33
+ type DefaultKeys<Shape extends SchemaShape> = { [Key in keyof Shape]: Shape[Key] extends FieldDefault ? Key : never }[keyof Shape];
34
+ type FieldInput<Field extends FieldSchema> = Field extends FieldToken ? TokenValue<Field> : Field extends FieldDefault ? DefaultValue<Field> : never;
35
+ type SchemaInput<Shape extends SchemaShape> = { [Key in keyof Shape]?: FieldInput<Shape[Key]> };
36
+ type SchemaOutput<Shape extends SchemaShape> = { [Key in TokenKeys<Shape>]?: Shape[Key] extends FieldToken ? TokenValue<Shape[Key]> : never } & { [Key in DefaultKeys<Shape>]: Shape[Key] extends FieldDefault ? DefaultValue<Shape[Key]> : never };
37
+ type InferInput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['input'];
38
+ type InferOutput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['output'];
39
+ declare class SchemaError extends Error {
40
+ readonly issues: ReadonlyArray<SchemaIssue>;
41
+ constructor(issues: ReadonlyArray<SchemaIssue>);
42
+ }
43
+ interface BleamSchema<Input, Output> extends StandardSchema<Input, Output> {
44
+ parse(value: unknown): Output;
45
+ safeParse(value: unknown): SchemaResult<Output>;
46
+ toJSONSchema(): SchemaJSONSchema;
47
+ transform<NextOutput>(transform: (value: Output) => NextOutput): BleamSchema<Input, NextOutput>;
48
+ }
49
+ type SchemaJSONSchema = {
50
+ type: 'object';
51
+ properties: Record<string, {
52
+ type: FieldToken;
53
+ }>;
54
+ required: string[];
55
+ };
56
+ declare function schema<Shape extends SchemaShape>(shape: Shape): BleamSchema<SchemaInput<Shape>, SchemaOutput<Shape>>;
57
+ //#endregion
58
+ export { FieldValue as a, SchemaError as c, SchemaJSONSchema as d, SchemaOutput as f, schema as g, StandardSchema as h, FieldToken as i, SchemaInput as l, SchemaShape as m, FieldDefault as n, InferInput as o, SchemaResult as p, FieldSchema as r, InferOutput as s, BleamSchema as t, SchemaIssue as u };
@@ -0,0 +1,58 @@
1
+ //#region src/schema.d.ts
2
+ type FieldValue = string | number | boolean;
3
+ type FieldToken = 'string' | 'number' | 'boolean';
4
+ type FieldDefault<T extends FieldValue = FieldValue> = () => T;
5
+ type FieldSchema = FieldToken | FieldDefault;
6
+ type SchemaShape = Record<string, FieldSchema>;
7
+ interface SchemaIssue {
8
+ message: string;
9
+ path?: ReadonlyArray<PropertyKey | {
10
+ key: PropertyKey;
11
+ }>;
12
+ }
13
+ type SchemaResult<Output> = {
14
+ value: Output;
15
+ issues?: undefined;
16
+ } | {
17
+ issues: ReadonlyArray<SchemaIssue>;
18
+ };
19
+ interface StandardSchema<Input = unknown, Output = Input> {
20
+ readonly '~standard': {
21
+ readonly version: 1;
22
+ readonly vendor: string;
23
+ readonly validate: (value: unknown) => SchemaResult<Output>;
24
+ readonly types?: {
25
+ readonly input: Input;
26
+ readonly output: Output;
27
+ };
28
+ };
29
+ }
30
+ type TokenValue<T extends FieldToken> = T extends 'string' ? string : T extends 'number' ? number : boolean;
31
+ type DefaultValue<T> = T extends (() => infer Value) ? Value extends FieldValue ? Value : never : never;
32
+ type TokenKeys<Shape extends SchemaShape> = { [Key in keyof Shape]: Shape[Key] extends FieldToken ? Key : never }[keyof Shape];
33
+ type DefaultKeys<Shape extends SchemaShape> = { [Key in keyof Shape]: Shape[Key] extends FieldDefault ? Key : never }[keyof Shape];
34
+ type FieldInput<Field extends FieldSchema> = Field extends FieldToken ? TokenValue<Field> : Field extends FieldDefault ? DefaultValue<Field> : never;
35
+ type SchemaInput<Shape extends SchemaShape> = { [Key in keyof Shape]?: FieldInput<Shape[Key]> };
36
+ type SchemaOutput<Shape extends SchemaShape> = { [Key in TokenKeys<Shape>]?: Shape[Key] extends FieldToken ? TokenValue<Shape[Key]> : never } & { [Key in DefaultKeys<Shape>]: Shape[Key] extends FieldDefault ? DefaultValue<Shape[Key]> : never };
37
+ type InferInput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['input'];
38
+ type InferOutput<Value$1 extends StandardSchema> = NonNullable<Value$1['~standard']['types']>['output'];
39
+ declare class SchemaError extends Error {
40
+ readonly issues: ReadonlyArray<SchemaIssue>;
41
+ constructor(issues: ReadonlyArray<SchemaIssue>);
42
+ }
43
+ interface BleamSchema<Input, Output> extends StandardSchema<Input, Output> {
44
+ parse(value: unknown): Output;
45
+ safeParse(value: unknown): SchemaResult<Output>;
46
+ toJSONSchema(): SchemaJSONSchema;
47
+ transform<NextOutput>(transform: (value: Output) => NextOutput): BleamSchema<Input, NextOutput>;
48
+ }
49
+ type SchemaJSONSchema = {
50
+ type: 'object';
51
+ properties: Record<string, {
52
+ type: FieldToken;
53
+ }>;
54
+ required: string[];
55
+ };
56
+ declare function schema<Shape extends SchemaShape>(shape: Shape): BleamSchema<SchemaInput<Shape>, SchemaOutput<Shape>>;
57
+ //#endregion
58
+ export { FieldValue as a, SchemaError as c, SchemaJSONSchema as d, SchemaOutput as f, schema as g, StandardSchema as h, FieldToken as i, SchemaInput as l, SchemaShape as m, FieldDefault as n, InferInput as o, SchemaResult as p, FieldSchema as r, InferOutput as s, BleamSchema as t, SchemaIssue as u };
@@ -0,0 +1,102 @@
1
+
2
+ //#region src/schema.ts
3
+ var SchemaError = class extends Error {
4
+ constructor(issues) {
5
+ super(issues.map((issue) => issue.message).join("\n"));
6
+ this.issues = issues;
7
+ this.name = "SchemaError";
8
+ }
9
+ };
10
+ function tokenMatches(token, value) {
11
+ return typeof value === token;
12
+ }
13
+ function issueFor(key, expected) {
14
+ return {
15
+ message: `Expected ${key} to be ${expected}`,
16
+ path: [key]
17
+ };
18
+ }
19
+ function parseShape(shape, value) {
20
+ if (!value || typeof value !== "object" || Array.isArray(value)) return { issues: [{ message: "Expected object" }] };
21
+ const input = value;
22
+ const output = {};
23
+ const issues = [];
24
+ for (const [key, field] of Object.entries(shape)) {
25
+ const inputValue = input[key];
26
+ if (typeof field === "function") {
27
+ const defaultValue = field();
28
+ const expected = typeof defaultValue;
29
+ if (inputValue === void 0) {
30
+ output[key] = defaultValue;
31
+ continue;
32
+ }
33
+ if (tokenMatches(expected, inputValue)) {
34
+ output[key] = inputValue;
35
+ continue;
36
+ }
37
+ issues.push(issueFor(key, expected));
38
+ continue;
39
+ }
40
+ if (inputValue === void 0) continue;
41
+ if (tokenMatches(field, inputValue)) {
42
+ output[key] = inputValue;
43
+ continue;
44
+ }
45
+ issues.push(issueFor(key, field));
46
+ }
47
+ if (issues.length > 0) return { issues };
48
+ return { value: output };
49
+ }
50
+ function createSchema(validate, jsonSchema) {
51
+ return {
52
+ "~standard": {
53
+ version: 1,
54
+ vendor: "bleam",
55
+ validate
56
+ },
57
+ parse(value) {
58
+ const result = validate(value);
59
+ if (result.issues !== void 0) throw new SchemaError(result.issues);
60
+ return result.value;
61
+ },
62
+ safeParse: validate,
63
+ toJSONSchema: jsonSchema,
64
+ transform(transform) {
65
+ return createSchema((value) => {
66
+ const result = validate(value);
67
+ if (result.issues !== void 0) return result;
68
+ return { value: transform(result.value) };
69
+ }, jsonSchema);
70
+ }
71
+ };
72
+ }
73
+ function schema(shape) {
74
+ return createSchema((value) => parseShape(shape, value), () => {
75
+ const properties = {};
76
+ const required = [];
77
+ for (const [key, field] of Object.entries(shape)) {
78
+ if (typeof field === "function") properties[key] = { type: typeof field() };
79
+ else properties[key] = { type: field };
80
+ required.push(key);
81
+ }
82
+ return {
83
+ type: "object",
84
+ properties,
85
+ required
86
+ };
87
+ });
88
+ }
89
+
90
+ //#endregion
91
+ Object.defineProperty(exports, 'SchemaError', {
92
+ enumerable: true,
93
+ get: function () {
94
+ return SchemaError;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, 'schema', {
98
+ enumerable: true,
99
+ get: function () {
100
+ return schema;
101
+ }
102
+ });
@@ -0,0 +1,4 @@
1
+ const require_schema = require('./schema-rQ13mrpD.cjs');
2
+
3
+ exports.SchemaError = require_schema.SchemaError;
4
+ exports.schema = require_schema.schema;
@@ -0,0 +1,2 @@
1
+ import { a as FieldValue, c as SchemaError, d as SchemaJSONSchema, f as SchemaOutput, g as schema, h as StandardSchema, i as FieldToken, l as SchemaInput, m as SchemaShape, n as FieldDefault, o as InferInput, p as SchemaResult, r as FieldSchema, s as InferOutput, t as BleamSchema, u as SchemaIssue } from "./schema-ENSMX_1t.cjs";
2
+ export { BleamSchema, FieldDefault, FieldSchema, FieldToken, FieldValue, InferInput, InferOutput, SchemaError, SchemaInput, SchemaIssue, SchemaJSONSchema, SchemaOutput, SchemaResult, SchemaShape, StandardSchema, schema };
@@ -0,0 +1,2 @@
1
+ import { a as FieldValue, c as SchemaError, d as SchemaJSONSchema, f as SchemaOutput, g as schema, h as StandardSchema, i as FieldToken, l as SchemaInput, m as SchemaShape, n as FieldDefault, o as InferInput, p as SchemaResult, r as FieldSchema, s as InferOutput, t as BleamSchema, u as SchemaIssue } from "./schema-DOOjfXvs.js";
2
+ export { BleamSchema, FieldDefault, FieldSchema, FieldToken, FieldValue, InferInput, InferOutput, SchemaError, SchemaInput, SchemaIssue, SchemaJSONSchema, SchemaOutput, SchemaResult, SchemaShape, StandardSchema, schema };
package/dist/schema.js ADDED
@@ -0,0 +1,3 @@
1
+ import { n as schema, t as SchemaError } from "./schema-Bo5Jvqus.js";
2
+
3
+ export { SchemaError, schema };