@mossbear/protocol 0.1.0-alpha.96 → 0.1.0-alpha.98
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/photos.d.ts +146 -0
- package/dist/photos.d.ts.map +1 -0
- package/dist/photos.js +127 -0
- package/dist/photos.js.map +1 -0
- package/dist/schemas.d.ts +244 -31
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +32 -37
- package/dist/schemas.js.map +1 -1
- package/dist/schemas.test.js +1 -12
- package/dist/schemas.test.js.map +1 -1
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './commentAnchor.js';
|
|
|
11
11
|
export * from './contextKinds.js';
|
|
12
12
|
export * from './markdownSections.js';
|
|
13
13
|
export * from './pairing.js';
|
|
14
|
+
export * from './photos.js';
|
|
14
15
|
export * from './publicModelCatalog.js';
|
|
15
16
|
export * from './schemas.js';
|
|
16
17
|
export * from './steeringOverTime.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './commentAnchor.js';
|
|
|
11
11
|
export * from './contextKinds.js';
|
|
12
12
|
export * from './markdownSections.js';
|
|
13
13
|
export * from './pairing.js';
|
|
14
|
+
export * from './photos.js';
|
|
14
15
|
export * from './publicModelCatalog.js';
|
|
15
16
|
export * from './schemas.js';
|
|
16
17
|
export * from './steeringOverTime.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
|
package/dist/photos.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract for photo capture: the three parts a captured photo is
|
|
3
|
+
* uploaded as, their limits, and the media description an item carries.
|
|
4
|
+
*
|
|
5
|
+
* A photo is one item stored as three blobs. `original` is the file exactly as
|
|
6
|
+
* the picker handed it over — never re-encoded, so it keeps whatever metadata
|
|
7
|
+
* it arrived with. `display` (≤3072px on the long edge) and `thumb` (≤512px)
|
|
8
|
+
* are re-encoded by the client and must carry no metadata at all; the server
|
|
9
|
+
* checks their bytes and refuses one that does. An item never substitutes the
|
|
10
|
+
* original for a missing variant, which is why all three parts are required.
|
|
11
|
+
*
|
|
12
|
+
* Imports nothing but valibot, so `schemas.ts` can depend on it without a
|
|
13
|
+
* cycle.
|
|
14
|
+
*/
|
|
15
|
+
import * as v from 'valibot';
|
|
16
|
+
export declare const PHOTO_ROLES: readonly ["original", "display", "thumb"];
|
|
17
|
+
export type PhotoRole = (typeof PHOTO_ROLES)[number];
|
|
18
|
+
export declare const PhotoRoleSchema: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
|
|
19
|
+
/** Every format any part may be; which ones a role admits is {@link PHOTO_PART_LIMITS}. */
|
|
20
|
+
export declare const PHOTO_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"];
|
|
21
|
+
export type PhotoMediaType = (typeof PHOTO_MEDIA_TYPES)[number];
|
|
22
|
+
/** Formats a re-encoded variant may use: ones every browser renders. */
|
|
23
|
+
export declare const PHOTO_VARIANT_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/webp"];
|
|
24
|
+
type PartLimit = {
|
|
25
|
+
maxBytes: number;
|
|
26
|
+
mediaTypes: readonly PhotoMediaType[];
|
|
27
|
+
/** Longest encoded edge, in pixels. */
|
|
28
|
+
maxEdge: number | null;
|
|
29
|
+
/** Encoded width × height. */
|
|
30
|
+
maxPixels: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Per-part limits. The byte caps bound one upload request each; the pixel caps
|
|
34
|
+
* bound what a reader is asked to decode. A 48-megapixel phone JPEG is about
|
|
35
|
+
* 12–20 MiB, so the original's cap leaves room without admitting RAW.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PHOTO_PART_LIMITS: Record<PhotoRole, PartLimit>;
|
|
38
|
+
/** What an item records about one part — checked against the bytes at upload. */
|
|
39
|
+
export declare const PhotoPartMediaSchema: v.ObjectSchema<{
|
|
40
|
+
readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
|
|
41
|
+
readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
|
|
42
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
43
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
44
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
45
|
+
}, undefined>;
|
|
46
|
+
export type PhotoPartMedia = v.InferOutput<typeof PhotoPartMediaSchema>;
|
|
47
|
+
/** Why a declared part falls outside its role's limits, or `null` when it fits. */
|
|
48
|
+
export declare function photoPartLimitRefusal(part: PhotoPartMedia): string | null;
|
|
49
|
+
/** One declared part of a photo upload: its media plus the hash of its bytes. */
|
|
50
|
+
export declare const PhotoUploadPartSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
51
|
+
readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
52
|
+
readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
|
|
53
|
+
readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
|
|
54
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
55
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
56
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
57
|
+
}, undefined>, v.CheckAction<{
|
|
58
|
+
sha256: string;
|
|
59
|
+
role: "original" | "display" | "thumb";
|
|
60
|
+
mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
|
|
61
|
+
bytes: number;
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
}, "Part is outside its limits">]>;
|
|
65
|
+
export type PhotoUploadPart = v.InferOutput<typeof PhotoUploadPartSchema>;
|
|
66
|
+
/**
|
|
67
|
+
* `POST /api/v1/context/inbox/assets` — begin a photo upload.
|
|
68
|
+
*
|
|
69
|
+
* The idempotency key names this capture across retries: a begin replayed
|
|
70
|
+
* under it, with the same parts, resumes the same attempt or returns the item
|
|
71
|
+
* it already became. Different parts under a used key are refused.
|
|
72
|
+
*/
|
|
73
|
+
export declare const BeginPhotoUploadRequestSchema: v.ObjectSchema<{
|
|
74
|
+
readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
75
|
+
readonly parts: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
76
|
+
readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
77
|
+
readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
|
|
78
|
+
readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
|
|
79
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
80
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
81
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
82
|
+
}, undefined>, v.CheckAction<{
|
|
83
|
+
sha256: string;
|
|
84
|
+
role: "original" | "display" | "thumb";
|
|
85
|
+
mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
|
|
86
|
+
bytes: number;
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
}, "Part is outside its limits">]>, undefined>, v.LengthAction<{
|
|
90
|
+
sha256: string;
|
|
91
|
+
role: "original" | "display" | "thumb";
|
|
92
|
+
mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
|
|
93
|
+
bytes: number;
|
|
94
|
+
width: number;
|
|
95
|
+
height: number;
|
|
96
|
+
}[], 3, undefined>, v.CheckAction<{
|
|
97
|
+
sha256: string;
|
|
98
|
+
role: "original" | "display" | "thumb";
|
|
99
|
+
mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
|
|
100
|
+
bytes: number;
|
|
101
|
+
width: number;
|
|
102
|
+
height: number;
|
|
103
|
+
}[], "A photo needs an original, a display and a thumb part">]>;
|
|
104
|
+
}, undefined>;
|
|
105
|
+
export type BeginPhotoUploadRequest = v.InferInput<typeof BeginPhotoUploadRequestSchema>;
|
|
106
|
+
/**
|
|
107
|
+
* `POST /api/v1/context/inbox/assets/uploads/<attemptId>/commit` — publish the
|
|
108
|
+
* photo once every part has arrived. The name is the client's, typically the
|
|
109
|
+
* picked file's: the server writes no fallback name of its own into the row.
|
|
110
|
+
*/
|
|
111
|
+
export declare const CommitPhotoUploadRequestSchema: v.ObjectSchema<{
|
|
112
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
113
|
+
/** Where it was captured from, as a text capture's `source` says; `app` when omitted. */
|
|
114
|
+
readonly source: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>, undefined>;
|
|
115
|
+
}, undefined>;
|
|
116
|
+
export type CommitPhotoUploadRequest = v.InferInput<typeof CommitPhotoUploadRequestSchema>;
|
|
117
|
+
/**
|
|
118
|
+
* The media description an item carries when it is a photo: one entry per
|
|
119
|
+
* stored part, so a list can lay out a thumbnail and a viewer can size the
|
|
120
|
+
* display variant without fetching either.
|
|
121
|
+
*/
|
|
122
|
+
export declare const PhotoAssetSchema: v.ObjectSchema<{
|
|
123
|
+
readonly parts: v.ArraySchema<v.ObjectSchema<{
|
|
124
|
+
readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
|
|
125
|
+
readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
|
|
126
|
+
readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
127
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
128
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
129
|
+
}, undefined>, undefined>;
|
|
130
|
+
}, undefined>;
|
|
131
|
+
export type PhotoAsset = v.InferOutput<typeof PhotoAssetSchema>;
|
|
132
|
+
/**
|
|
133
|
+
* `GET /api/v1/context/inbox/assets/storage` — whether photo capture is
|
|
134
|
+
* available, and the caller's storage when the caller is the one who pays for
|
|
135
|
+
* it (null otherwise, and when unavailable).
|
|
136
|
+
*/
|
|
137
|
+
export declare const PhotoStorageResponseSchema: v.ObjectSchema<{
|
|
138
|
+
readonly available: v.BooleanSchema<undefined>;
|
|
139
|
+
readonly usage: v.NullableSchema<v.ObjectSchema<{
|
|
140
|
+
readonly usedBytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
141
|
+
readonly capBytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
142
|
+
}, undefined>, undefined>;
|
|
143
|
+
}, undefined>;
|
|
144
|
+
export type PhotoStorageResponse = v.InferOutput<typeof PhotoStorageResponseSchema>;
|
|
145
|
+
export {};
|
|
146
|
+
//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;;;;GAMG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAUxC,CAAA;AACF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAExF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B;;IAEzC,yFAAyF;;aAEzF,CAAA;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAE1F;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;aAE3B,CAAA;AACF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAE/D;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;aAQrC,CAAA;AACF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAAA"}
|
package/dist/photos.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract for photo capture: the three parts a captured photo is
|
|
3
|
+
* uploaded as, their limits, and the media description an item carries.
|
|
4
|
+
*
|
|
5
|
+
* A photo is one item stored as three blobs. `original` is the file exactly as
|
|
6
|
+
* the picker handed it over — never re-encoded, so it keeps whatever metadata
|
|
7
|
+
* it arrived with. `display` (≤3072px on the long edge) and `thumb` (≤512px)
|
|
8
|
+
* are re-encoded by the client and must carry no metadata at all; the server
|
|
9
|
+
* checks their bytes and refuses one that does. An item never substitutes the
|
|
10
|
+
* original for a missing variant, which is why all three parts are required.
|
|
11
|
+
*
|
|
12
|
+
* Imports nothing but valibot, so `schemas.ts` can depend on it without a
|
|
13
|
+
* cycle.
|
|
14
|
+
*/
|
|
15
|
+
import * as v from 'valibot';
|
|
16
|
+
export const PHOTO_ROLES = ['original', 'display', 'thumb'];
|
|
17
|
+
export const PhotoRoleSchema = v.picklist(PHOTO_ROLES);
|
|
18
|
+
/** Every format any part may be; which ones a role admits is {@link PHOTO_PART_LIMITS}. */
|
|
19
|
+
export const PHOTO_MEDIA_TYPES = [
|
|
20
|
+
'image/jpeg',
|
|
21
|
+
'image/png',
|
|
22
|
+
'image/webp',
|
|
23
|
+
'image/gif',
|
|
24
|
+
'image/heic',
|
|
25
|
+
'image/heif',
|
|
26
|
+
];
|
|
27
|
+
/** Formats a re-encoded variant may use: ones every browser renders. */
|
|
28
|
+
export const PHOTO_VARIANT_MEDIA_TYPES = [
|
|
29
|
+
'image/jpeg',
|
|
30
|
+
'image/png',
|
|
31
|
+
'image/webp',
|
|
32
|
+
];
|
|
33
|
+
const MiB = 1024 * 1024;
|
|
34
|
+
/**
|
|
35
|
+
* Per-part limits. The byte caps bound one upload request each; the pixel caps
|
|
36
|
+
* bound what a reader is asked to decode. A 48-megapixel phone JPEG is about
|
|
37
|
+
* 12–20 MiB, so the original's cap leaves room without admitting RAW.
|
|
38
|
+
*/
|
|
39
|
+
export const PHOTO_PART_LIMITS = {
|
|
40
|
+
original: {
|
|
41
|
+
maxBytes: 25 * MiB,
|
|
42
|
+
mediaTypes: PHOTO_MEDIA_TYPES,
|
|
43
|
+
maxEdge: null,
|
|
44
|
+
maxPixels: 100_000_000,
|
|
45
|
+
},
|
|
46
|
+
display: {
|
|
47
|
+
maxBytes: 10 * MiB,
|
|
48
|
+
mediaTypes: PHOTO_VARIANT_MEDIA_TYPES,
|
|
49
|
+
maxEdge: 3072,
|
|
50
|
+
maxPixels: 3072 * 3072,
|
|
51
|
+
},
|
|
52
|
+
thumb: {
|
|
53
|
+
maxBytes: 1 * MiB,
|
|
54
|
+
mediaTypes: PHOTO_VARIANT_MEDIA_TYPES,
|
|
55
|
+
maxEdge: 512,
|
|
56
|
+
maxPixels: 512 * 512,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const PixelsSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1));
|
|
60
|
+
/** What an item records about one part — checked against the bytes at upload. */
|
|
61
|
+
export const PhotoPartMediaSchema = v.object({
|
|
62
|
+
role: PhotoRoleSchema,
|
|
63
|
+
mediaType: v.picklist(PHOTO_MEDIA_TYPES),
|
|
64
|
+
bytes: v.pipe(v.number(), v.safeInteger(), v.minValue(1)),
|
|
65
|
+
width: PixelsSchema,
|
|
66
|
+
height: PixelsSchema,
|
|
67
|
+
});
|
|
68
|
+
/** Why a declared part falls outside its role's limits, or `null` when it fits. */
|
|
69
|
+
export function photoPartLimitRefusal(part) {
|
|
70
|
+
const limit = PHOTO_PART_LIMITS[part.role];
|
|
71
|
+
if (part.bytes > limit.maxBytes)
|
|
72
|
+
return `The ${part.role} part can be at most ${limit.maxBytes} bytes`;
|
|
73
|
+
if (!limit.mediaTypes.includes(part.mediaType))
|
|
74
|
+
return `The ${part.role} part can't be ${part.mediaType}`;
|
|
75
|
+
if (limit.maxEdge !== null && Math.max(part.width, part.height) > limit.maxEdge)
|
|
76
|
+
return `The ${part.role} part can be at most ${limit.maxEdge} pixels on its long edge`;
|
|
77
|
+
if (part.width * part.height > limit.maxPixels)
|
|
78
|
+
return `The ${part.role} part has too many pixels`;
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
/** One declared part of a photo upload: its media plus the hash of its bytes. */
|
|
82
|
+
export const PhotoUploadPartSchema = v.pipe(v.object({
|
|
83
|
+
...PhotoPartMediaSchema.entries,
|
|
84
|
+
sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/)),
|
|
85
|
+
}), v.check((part) => photoPartLimitRefusal(part) === null, 'Part is outside its limits'));
|
|
86
|
+
/**
|
|
87
|
+
* `POST /api/v1/context/inbox/assets` — begin a photo upload.
|
|
88
|
+
*
|
|
89
|
+
* The idempotency key names this capture across retries: a begin replayed
|
|
90
|
+
* under it, with the same parts, resumes the same attempt or returns the item
|
|
91
|
+
* it already became. Different parts under a used key are refused.
|
|
92
|
+
*/
|
|
93
|
+
export const BeginPhotoUploadRequestSchema = v.object({
|
|
94
|
+
idempotencyKey: v.pipe(v.string(), v.regex(/^[A-Za-z0-9_-]{16,128}$/)),
|
|
95
|
+
parts: v.pipe(v.array(PhotoUploadPartSchema), v.length(PHOTO_ROLES.length), v.check((parts) => PHOTO_ROLES.every((role) => parts.some((part) => part.role === role)), 'A photo needs an original, a display and a thumb part')),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* `POST /api/v1/context/inbox/assets/uploads/<attemptId>/commit` — publish the
|
|
99
|
+
* photo once every part has arrived. The name is the client's, typically the
|
|
100
|
+
* picked file's: the server writes no fallback name of its own into the row.
|
|
101
|
+
*/
|
|
102
|
+
export const CommitPhotoUploadRequestSchema = v.object({
|
|
103
|
+
name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(200)),
|
|
104
|
+
/** Where it was captured from, as a text capture's `source` says; `app` when omitted. */
|
|
105
|
+
source: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(64))),
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* The media description an item carries when it is a photo: one entry per
|
|
109
|
+
* stored part, so a list can lay out a thumbnail and a viewer can size the
|
|
110
|
+
* display variant without fetching either.
|
|
111
|
+
*/
|
|
112
|
+
export const PhotoAssetSchema = v.object({
|
|
113
|
+
parts: v.array(PhotoPartMediaSchema),
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* `GET /api/v1/context/inbox/assets/storage` — whether photo capture is
|
|
117
|
+
* available, and the caller's storage when the caller is the one who pays for
|
|
118
|
+
* it (null otherwise, and when unavailable).
|
|
119
|
+
*/
|
|
120
|
+
export const PhotoStorageResponseSchema = v.object({
|
|
121
|
+
available: v.boolean(),
|
|
122
|
+
usage: v.nullable(v.object({
|
|
123
|
+
usedBytes: v.pipe(v.number(), v.minValue(0)),
|
|
124
|
+
capBytes: v.pipe(v.number(), v.minValue(0)),
|
|
125
|
+
})),
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=photos.js.map
|
|
@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