bleam 0.0.10 → 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.
- package/dist/ai.cjs +1872 -1182
- package/dist/ai.d.cts +267 -234
- package/dist/ai.d.ts +267 -234
- package/dist/ai.js +1859 -1167
- package/dist/cli.cjs +3 -183
- package/dist/cli.d.cts +3 -47
- package/dist/cli.d.ts +3 -47
- package/dist/cli.js +3 -183
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{files-Ds1wT8C2.js → files-BXVkPrPN.js} +6 -1
- package/dist/{files-Bo7h9fik.cjs → files-DxaQ-Nv0.cjs} +11 -0
- package/dist/files.cjs +1 -1
- package/dist/files.js +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/platform.cjs +1 -13
- package/dist/platform.d.cts +1 -28
- package/dist/platform.d.ts +1 -28
- package/dist/platform.js +1 -10
- package/dist/schema-B5BfdswF.js +226 -0
- package/dist/schema-BnVZOXfu.cjs +286 -0
- package/dist/schema-D5eImHxu.d.cts +125 -0
- package/dist/schema-SSjokbtw.d.ts +125 -0
- package/dist/schema.cjs +10 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/state-Dh3HLixb.js +874 -0
- package/dist/state-LssDgpff.cjs +973 -0
- package/dist/state.cjs +16 -12
- package/dist/state.d.cts +144 -140
- package/dist/state.d.ts +145 -140
- package/dist/state.js +3 -3
- package/dist/{ui-Bg11tvlc.d.ts → ui-1WepaMS4.d.cts} +1 -1
- package/dist/{ui-Dd7SXdbg.d.cts → ui-D7bRLYee.d.ts} +7 -7
- package/dist/ui.d.cts +1 -1
- package/dist/ui.d.ts +1 -1
- package/dist/window.d.cts +1 -1
- package/dist/window.d.ts +1 -1
- package/package.json +3 -1
- package/templates/foundation-models/app/index.tsx +77 -15
- package/templates/image-generation/app/index.tsx +4 -2
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/ModelRegistry.swift +1 -1
- package/templates/native/ios/Bleam/AI/Flux2/Pipeline/FluxImageRunner.swift +7 -2
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextGenerator.swift +46 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextModel.swift +107 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextSnapshotValidator.swift +201 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/GenerationTypes.swift +85 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/ModelCapabilities.swift +21 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/TextKVCache.swift +23 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/TokenSampler.swift +79 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3CheckpointLoader.swift +161 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Configuration.swift +119 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3InferenceSession.swift +84 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Layers.swift +197 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Model.swift +130 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Checkpoint.swift +102 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Configuration.swift +140 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Model.swift +112 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Session.swift +121 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridCache.swift +42 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridFullAttention.swift +57 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridLayers.swift +58 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridLinearAttention.swift +111 -0
- package/templates/native/ios/Bleam/AppDelegate.swift +0 -206
- package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +135 -129
- package/templates/native/ios/GenerationService/BonsaiTextGenerationRunner.swift +103 -0
- package/templates/native/ios/GenerationService/ImageGenerationRunner.swift +19 -7
- package/templates/native/ios/GenerationService/main.swift +174 -48
- package/templates/native/ios/Podfile.lock +173 -173
- package/templates/native/ios/Shared/Generation/GenerationServiceProtocol.swift +3 -0
- package/templates/native/ios/Shared/Generation/GenerationWorkerProtocol.swift +44 -0
- package/templates/native/modules/bleam-runtime/ios/AIModule.swift +239 -341
- package/templates/native/modules/bleam-runtime/ios/GenerationContracts.swift +47 -0
- package/templates/native/modules/bleam-runtime/ios/PlatformModule.swift +0 -191
- package/templates/text-generation/app/index.tsx +124 -0
- package/templates/text-generation/app.config.ts +5 -0
- package/templates/updates/README.md +43 -199
- package/templates/updates/src/index.ts +5 -98
- package/templates/updates/src/schema.ts +18 -173
- package/dist/schema-Bo5Jvqus.js +0 -90
- package/dist/schema-DOOjfXvs.d.ts +0 -58
- package/dist/schema-ENSMX_1t.d.cts +0 -58
- package/dist/schema-rQ13mrpD.cjs +0 -102
- package/dist/state-Bx0VlTlO.cjs +0 -852
- package/dist/state-CAwe-Vw1.js +0 -767
- package/templates/native/ios/PlatformHelper/main.swift +0 -726
- /package/dist/{config-Cms0rvqg.d.ts → config-COcRnn5a.d.cts} +0 -0
- /package/dist/{config-CufOVJV3.d.cts → config-Chi-flpJ.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ArtifactFormat = 'bleam-ota-zip-v1'
|
|
1
|
+
export type ArtifactFormat = 'bleam-ota-zip-v1'
|
|
2
2
|
|
|
3
3
|
export interface StoredArtifact {
|
|
4
4
|
format: ArtifactFormat
|
|
@@ -11,43 +11,24 @@ export interface ResolvedArtifact extends StoredArtifact {
|
|
|
11
11
|
url: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
interface
|
|
14
|
+
export interface OtaRelease {
|
|
15
15
|
schemaVersion: 1
|
|
16
|
+
kind: 'ota'
|
|
16
17
|
bundleIdentifier: string
|
|
17
18
|
teamIdentifier: string
|
|
18
19
|
channel: 'stable'
|
|
19
20
|
releaseId: string
|
|
20
|
-
publishedAt: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface OtaRelease extends ReleaseFields {
|
|
24
|
-
kind: 'ota'
|
|
25
21
|
bundleVersion: string
|
|
26
22
|
runtimeVersion: string
|
|
27
23
|
artifact: StoredArtifact & { format: 'bleam-ota-zip-v1' }
|
|
24
|
+
publishedAt: string
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export
|
|
31
|
-
kind: 'platform'
|
|
32
|
-
appVersion: string
|
|
33
|
-
buildNumber: string
|
|
34
|
-
bleamPlatformVersion: string
|
|
35
|
-
platformFingerprint?: string
|
|
36
|
-
redeploy: boolean
|
|
37
|
-
target: {
|
|
38
|
-
os: 'macos'
|
|
39
|
-
architecture: 'arm64'
|
|
40
|
-
installLocation: 'user-applications'
|
|
41
|
-
minimumMacOSVersion: string
|
|
42
|
-
}
|
|
43
|
-
artifact: StoredArtifact & { format: 'bleam-macos-app-zip-v1' }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type StoredRelease = OtaRelease | PlatformRelease
|
|
27
|
+
export type StoredRelease = OtaRelease
|
|
47
28
|
|
|
48
|
-
export type ResolvedRelease =
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
export type ResolvedRelease = Omit<OtaRelease, 'artifact'> & {
|
|
30
|
+
artifact: ResolvedArtifact
|
|
31
|
+
}
|
|
51
32
|
|
|
52
33
|
export interface DownloadRecord {
|
|
53
34
|
schemaVersion: 1
|
|
@@ -104,23 +85,6 @@ function version(value: unknown, field: string): string {
|
|
|
104
85
|
return result
|
|
105
86
|
}
|
|
106
87
|
|
|
107
|
-
function numericString(value: unknown, field: string): string {
|
|
108
|
-
const result = string(value, field)
|
|
109
|
-
if (!/^\d+$/.test(result)) {
|
|
110
|
-
return invalid(field, 'must contain only decimal digits')
|
|
111
|
-
}
|
|
112
|
-
return result
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function optionalSha256(value: unknown, field: string): string | undefined {
|
|
116
|
-
if (value === undefined) return undefined
|
|
117
|
-
const result = string(value, field)
|
|
118
|
-
if (!/^[a-f0-9]{64}$/.test(result)) {
|
|
119
|
-
return invalid(field, 'must be a lowercase SHA-256 hex digest')
|
|
120
|
-
}
|
|
121
|
-
return result
|
|
122
|
-
}
|
|
123
|
-
|
|
124
88
|
function publishedAt(value: unknown): string {
|
|
125
89
|
const result = string(value, 'publishedAt')
|
|
126
90
|
if (
|
|
@@ -140,44 +104,6 @@ export function isRuntimeVersion(value: string): boolean {
|
|
|
140
104
|
return /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(value)
|
|
141
105
|
}
|
|
142
106
|
|
|
143
|
-
export function compareRuntimeVersions(left: string, right: string) {
|
|
144
|
-
const parse = (value: string) => {
|
|
145
|
-
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([^+]+))?(?:\+.*)?$/.exec(value)
|
|
146
|
-
if (!match) return invalid('runtimeVersion', 'must be a semantic version')
|
|
147
|
-
return {
|
|
148
|
-
core: match.slice(1, 4).map(Number),
|
|
149
|
-
prerelease: match[4]?.split('.'),
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const a = parse(left)
|
|
153
|
-
const b = parse(right)
|
|
154
|
-
for (let index = 0; index < a.core.length; index += 1) {
|
|
155
|
-
if (a.core[index] !== b.core[index]) {
|
|
156
|
-
return (a.core[index] ?? 0) < (b.core[index] ?? 0) ? -1 : 1
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (!a.prerelease && !b.prerelease) return 0
|
|
160
|
-
if (!a.prerelease) return 1
|
|
161
|
-
if (!b.prerelease) return -1
|
|
162
|
-
const length = Math.max(a.prerelease.length, b.prerelease.length)
|
|
163
|
-
for (let index = 0; index < length; index += 1) {
|
|
164
|
-
const aPart = a.prerelease[index]
|
|
165
|
-
const bPart = b.prerelease[index]
|
|
166
|
-
if (aPart === undefined) return -1
|
|
167
|
-
if (bPart === undefined) return 1
|
|
168
|
-
if (aPart === bPart) continue
|
|
169
|
-
const aNumber = /^\d+$/.test(aPart) ? Number(aPart) : undefined
|
|
170
|
-
const bNumber = /^\d+$/.test(bPart) ? Number(bPart) : undefined
|
|
171
|
-
if (aNumber !== undefined && bNumber !== undefined) {
|
|
172
|
-
return aNumber < bNumber ? -1 : 1
|
|
173
|
-
}
|
|
174
|
-
if (aNumber !== undefined) return -1
|
|
175
|
-
if (bNumber !== undefined) return 1
|
|
176
|
-
return aPart < bPart ? -1 : 1
|
|
177
|
-
}
|
|
178
|
-
return 0
|
|
179
|
-
}
|
|
180
|
-
|
|
181
107
|
export function isDownloadId(value: string): boolean {
|
|
182
108
|
return /^[a-z][a-z0-9_-]{2,127}$/.test(value)
|
|
183
109
|
}
|
|
@@ -209,11 +135,9 @@ function teamIdentifier(value: unknown): string {
|
|
|
209
135
|
return result
|
|
210
136
|
}
|
|
211
137
|
|
|
212
|
-
function artifact(value: unknown
|
|
138
|
+
function artifact(value: unknown): StoredArtifact {
|
|
213
139
|
const input = record(value, 'artifact')
|
|
214
|
-
|
|
215
|
-
kind === 'ota' ? 'bleam-ota-zip-v1' : 'bleam-macos-app-zip-v1'
|
|
216
|
-
exactString(input.format, 'artifact.format', expectedFormat)
|
|
140
|
+
exactString(input.format, 'artifact.format', 'bleam-ota-zip-v1')
|
|
217
141
|
|
|
218
142
|
const downloadId = string(input.downloadId, 'artifact.downloadId')
|
|
219
143
|
if (!isDownloadId(downloadId)) {
|
|
@@ -229,113 +153,34 @@ function artifact(value: unknown, kind: StoredRelease['kind']): StoredArtifact {
|
|
|
229
153
|
}
|
|
230
154
|
|
|
231
155
|
return {
|
|
232
|
-
format:
|
|
156
|
+
format: 'bleam-ota-zip-v1',
|
|
233
157
|
downloadId,
|
|
234
158
|
sizeBytes: positiveInteger(input.sizeBytes, 'artifact.sizeBytes'),
|
|
235
159
|
sha256,
|
|
236
160
|
}
|
|
237
161
|
}
|
|
238
162
|
|
|
239
|
-
function
|
|
163
|
+
export function parseStoredRelease(value: unknown): StoredRelease {
|
|
164
|
+
const input = record(value, 'manifest')
|
|
240
165
|
if (input.schemaVersion !== 1) {
|
|
241
166
|
return invalid('schemaVersion', 'must be 1')
|
|
242
167
|
}
|
|
243
|
-
|
|
168
|
+
exactString(input.kind, 'kind', 'ota')
|
|
244
169
|
exactString(input.channel, 'channel', 'stable')
|
|
245
170
|
return {
|
|
246
171
|
schemaVersion: 1,
|
|
172
|
+
kind: 'ota',
|
|
247
173
|
bundleIdentifier: bundleIdentifier(input.bundleIdentifier),
|
|
248
174
|
teamIdentifier: teamIdentifier(input.teamIdentifier),
|
|
249
175
|
channel: 'stable',
|
|
250
176
|
releaseId: releaseId(input.releaseId),
|
|
177
|
+
bundleVersion: string(input.bundleVersion, 'bundleVersion'),
|
|
178
|
+
runtimeVersion: version(input.runtimeVersion, 'runtimeVersion'),
|
|
179
|
+
artifact: artifact(input.artifact),
|
|
251
180
|
publishedAt: publishedAt(input.publishedAt),
|
|
252
181
|
}
|
|
253
182
|
}
|
|
254
183
|
|
|
255
|
-
export function parseStoredRelease(value: unknown): StoredRelease {
|
|
256
|
-
const input = record(value, 'manifest')
|
|
257
|
-
const kind = string(input.kind, 'kind')
|
|
258
|
-
const fields = releaseFields(input)
|
|
259
|
-
|
|
260
|
-
if (kind === 'ota') {
|
|
261
|
-
const parsedArtifact = artifact(input.artifact, kind)
|
|
262
|
-
return {
|
|
263
|
-
...fields,
|
|
264
|
-
kind,
|
|
265
|
-
bundleVersion: string(input.bundleVersion, 'bundleVersion'),
|
|
266
|
-
runtimeVersion: version(input.runtimeVersion, 'runtimeVersion'),
|
|
267
|
-
artifact: {
|
|
268
|
-
...parsedArtifact,
|
|
269
|
-
format: 'bleam-ota-zip-v1',
|
|
270
|
-
},
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (kind === 'platform') {
|
|
275
|
-
const target = record(input.target, 'target')
|
|
276
|
-
exactString(target.os, 'target.os', 'macos')
|
|
277
|
-
exactString(target.architecture, 'target.architecture', 'arm64')
|
|
278
|
-
exactString(
|
|
279
|
-
target.installLocation,
|
|
280
|
-
'target.installLocation',
|
|
281
|
-
'user-applications',
|
|
282
|
-
)
|
|
283
|
-
const minimumMacOSVersion = string(
|
|
284
|
-
target.minimumMacOSVersion,
|
|
285
|
-
'target.minimumMacOSVersion',
|
|
286
|
-
)
|
|
287
|
-
if (!/^\d+(?:\.\d+){0,2}$/.test(minimumMacOSVersion)) {
|
|
288
|
-
return invalid(
|
|
289
|
-
'target.minimumMacOSVersion',
|
|
290
|
-
'must be a macOS version number',
|
|
291
|
-
)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const parsedArtifact = artifact(input.artifact, kind)
|
|
295
|
-
return {
|
|
296
|
-
...fields,
|
|
297
|
-
kind,
|
|
298
|
-
appVersion: version(input.appVersion, 'appVersion'),
|
|
299
|
-
buildNumber: numericString(input.buildNumber, 'buildNumber'),
|
|
300
|
-
bleamPlatformVersion: version(
|
|
301
|
-
input.bleamPlatformVersion,
|
|
302
|
-
'bleamPlatformVersion',
|
|
303
|
-
),
|
|
304
|
-
platformFingerprint: optionalSha256(
|
|
305
|
-
input.platformFingerprint,
|
|
306
|
-
'platformFingerprint',
|
|
307
|
-
),
|
|
308
|
-
redeploy: input.redeploy === true,
|
|
309
|
-
target: {
|
|
310
|
-
os: 'macos',
|
|
311
|
-
architecture: 'arm64',
|
|
312
|
-
installLocation: 'user-applications',
|
|
313
|
-
minimumMacOSVersion,
|
|
314
|
-
},
|
|
315
|
-
artifact: {
|
|
316
|
-
...parsedArtifact,
|
|
317
|
-
format: 'bleam-macos-app-zip-v1',
|
|
318
|
-
},
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return invalid('kind', 'must be "ota" or "platform"')
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function parsePublishedRelease(value: unknown): StoredRelease {
|
|
326
|
-
const release = parseStoredRelease(value)
|
|
327
|
-
if (release.kind !== 'platform') return release
|
|
328
|
-
|
|
329
|
-
const input = record(value, 'manifest')
|
|
330
|
-
if (release.platformFingerprint === undefined) {
|
|
331
|
-
return invalid('platformFingerprint', 'is required')
|
|
332
|
-
}
|
|
333
|
-
if (typeof input.redeploy !== 'boolean') {
|
|
334
|
-
return invalid('redeploy', 'must be a boolean')
|
|
335
|
-
}
|
|
336
|
-
return release
|
|
337
|
-
}
|
|
338
|
-
|
|
339
184
|
export function parseDownloadRecord(value: unknown): DownloadRecord {
|
|
340
185
|
const input = record(value, 'download record')
|
|
341
186
|
if (input.schemaVersion !== 1) {
|
package/dist/schema-Bo5Jvqus.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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 };
|
|
@@ -1,58 +0,0 @@
|
|
|
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 };
|
|
@@ -1,58 +0,0 @@
|
|
|
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 };
|
package/dist/schema-rQ13mrpD.cjs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
});
|