@cedarjs/uploads 8.0.0-canary.3429 → 8.0.0-canary.3433

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/uploads",
3
- "version": "8.0.0-canary.3429",
3
+ "version": "8.0.0-canary.3433",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -43,9 +43,9 @@
43
43
  "test:watch": "vitest watch"
44
44
  },
45
45
  "dependencies": {
46
- "@cedarjs/api": "8.0.0-canary.3429",
47
- "@cedarjs/context": "8.0.0-canary.3429",
48
- "@cedarjs/graphql-server": "8.0.0-canary.3429",
46
+ "@cedarjs/api": "8.0.0-canary.3433",
47
+ "@cedarjs/context": "8.0.0-canary.3433",
48
+ "@cedarjs/graphql-server": "8.0.0-canary.3433",
49
49
  "@fastify/multipart": "9.4.0",
50
50
  "graphql": "16.14.2",
51
51
  "mime-types": "2.1.35"
@@ -53,10 +53,10 @@
53
53
  "devDependencies": {
54
54
  "@apollo/client": "4.3.3",
55
55
  "@arethetypeswrong/cli": "0.18.5",
56
- "@aws-sdk/client-s3": "3.1149.0",
57
- "@aws-sdk/s3-request-presigner": "3.1149.0",
58
- "@cedarjs/framework-tools": "8.0.0-canary.3429",
59
- "@cedarjs/web": "8.0.0-canary.3429",
56
+ "@aws-sdk/client-s3": "3.1150.0",
57
+ "@aws-sdk/s3-request-presigner": "3.1150.0",
58
+ "@cedarjs/framework-tools": "8.0.0-canary.3433",
59
+ "@cedarjs/web": "8.0.0-canary.3433",
60
60
  "@prisma/adapter-better-sqlite3": "7.10.0",
61
61
  "@prisma/client": "7.10.0",
62
62
  "@testing-library/dom": "10.4.2",
@@ -90,7 +90,7 @@
90
90
  "@apollo/client": "4.3.3",
91
91
  "@aws-sdk/client-s3": "^3.0.0",
92
92
  "@aws-sdk/s3-request-presigner": "^3.0.0",
93
- "@cedarjs/web": "8.0.0-canary.3429",
93
+ "@cedarjs/web": "8.0.0-canary.3433",
94
94
  "@uppy/aws-s3": "^6.0.0",
95
95
  "@uppy/core": "^6.0.0",
96
96
  "@uppy/dashboard": "^6.0.0",
@@ -1,212 +0,0 @@
1
- import type { ContentDisposition, StorageProvider, StorageTargets, UploadVariantDatabase, UploadVariantRecord } from './types.js';
2
- /** The file a variant generator returns. */
3
- export interface UploadVariantFile {
4
- /** The derived file's bytes. */
5
- data: Uint8Array;
6
- /** MIME type of `data`, for example `image/webp`. */
7
- mimeType: string;
8
- /**
9
- * Filename for the derived file's `Upload` row. Defaults to the source's
10
- * filename without its extension, plus the variant name and the extension
11
- * of `mimeType`: `photo.jpg` becomes `photo-thumb-164.webp`.
12
- */
13
- filename?: string;
14
- }
15
- /** What a variant generator is called with. */
16
- export interface UploadVariantContext {
17
- /** The source file's `Upload` row, without its inline `data`. */
18
- source: UploadVariantRecord;
19
- /** Name of the variant being made, for example `'thumb-164'`. */
20
- variant: string;
21
- /** Reads the source file's bytes from whichever target holds them. */
22
- readSource(): Promise<Buffer>;
23
- /**
24
- * Reads another variant of the same source, making it first if it does
25
- * not exist yet. Returns `null` when that variant could not be made. This
26
- * is how one derived file is made from another, for example a PDF's
27
- * thumbnail cut from its drawn first page
28
- * (`acquireVariantData('preview')`).
29
- */
30
- acquireVariantData(name: string): Promise<Buffer | null>;
31
- }
32
- /**
33
- * Makes one derived file (variant) from its source: a thumbnail from a
34
- * photo, a preview image from a PDF, a poster frame from a video. This is
35
- * the only part the app writes; the uploads package stores the result,
36
- * links it to its source, and keeps track of it.
37
- *
38
- * Return `null` when this source cannot have this variant (a file type the
39
- * generator does not handle). Both `null` and a thrown error are remembered
40
- * as a failure and not retried until `retryFailedAfter` has passed.
41
- */
42
- export type UploadVariantGenerator = (context: UploadVariantContext) => Promise<UploadVariantFile | null> | UploadVariantFile | null;
43
- /** A variant generator plus where its files are stored. */
44
- export interface UploadVariantDefinition {
45
- generate: UploadVariantGenerator;
46
- /** Storage target for this variant's files. Defaults to the `target` option. */
47
- target?: StorageProvider;
48
- }
49
- export interface DefineUploadVariantsOptions<Name extends string> {
50
- db: UploadVariantDatabase;
51
- /**
52
- * Every configured storage target. Used to read sources and to read and
53
- * delete variants wherever they are stored.
54
- */
55
- targets: StorageTargets;
56
- /** Storage target new variant files are written to, unless a variant names its own. */
57
- target: StorageProvider;
58
- /**
59
- * The variants, by name, each with the function that makes it:
60
- * `{ 'thumb-164': makeThumb, preview: makePdfPreview }`. Names may use
61
- * letters, digits, `.`, `_` and `-`.
62
- */
63
- variants: Record<Name, UploadVariantGenerator | UploadVariantDefinition>;
64
- /**
65
- * How long a variant that could not be made is left alone before the
66
- * next request tries again, in milliseconds. Defaults to one day.
67
- */
68
- retryFailedAfter?: number;
69
- /**
70
- * How long a claim to make a variant is honored, in milliseconds. A
71
- * request that finds a claim older than this assumes its maker died and
72
- * makes the variant itself. Defaults to ten minutes; set it above the
73
- * slowest generator's running time.
74
- */
75
- claimTimeout?: number;
76
- /**
77
- * How often a request waiting for another process to finish making the
78
- * same variant checks again, in milliseconds. Defaults to 250.
79
- */
80
- pollInterval?: number;
81
- /**
82
- * Called when a generator throws or its result cannot be stored. Defaults
83
- * to `console.error`. The failure is remembered either way.
84
- */
85
- onError?: (error: unknown, info: {
86
- sourceId: string;
87
- variant: string;
88
- }) => void;
89
- }
90
- /** What `regenerateVariants()` did. */
91
- export interface RegenerateVariantsResult {
92
- /** Variant files deleted, made or failed alike. */
93
- deleted: number;
94
- /** Variants made again. */
95
- made: number;
96
- /** Variants that could not be made again (remembered as failed). */
97
- failed: number;
98
- /** Variants that could not be deleted; reported through `onError`. */
99
- errors: number;
100
- }
101
- /** A source upload, by id or by its row. */
102
- export type UploadVariantSource = string | {
103
- id: string;
104
- };
105
- /**
106
- * Derived files (variants) of uploads: thumbnails, previews, poster frames.
107
- * Returned by `defineUploadVariants()`.
108
- */
109
- export interface UploadVariants<Name extends string> {
110
- /** The configured variant names. */
111
- names: readonly Name[];
112
- /**
113
- * The variant's `Upload` row, made now if it does not exist yet. Returns
114
- * `null` when it could not be made and `retryFailedAfter` has not passed.
115
- *
116
- * Making a variant happens once: concurrent calls in this process share
117
- * one attempt, and across processes a claim row decides who makes it
118
- * while the others wait for the result.
119
- */
120
- acquireVariant(source: UploadVariantSource, name: Name): Promise<UploadVariantRecord | null>;
121
- /**
122
- * The variant's `Upload` row if it has been made, or `null`. Never makes
123
- * anything; use it where making on demand would be too slow, such as a
124
- * list page.
125
- */
126
- findVariant(source: UploadVariantSource, name: Name): Promise<UploadVariantRecord | null>;
127
- /**
128
- * The made variants of many sources in one query, keyed by source id.
129
- * Sources without that variant are left out. Never makes anything.
130
- */
131
- findVariants(sourceIds: string[], name: Name): Promise<Map<string, UploadVariantRecord>>;
132
- /**
133
- * The variant's row and bytes, made now if it does not exist yet, or
134
- * `null` when it could not be made.
135
- */
136
- acquireVariantData(source: UploadVariantSource, name: Name): Promise<{
137
- upload: UploadVariantRecord;
138
- data: Buffer;
139
- } | null>;
140
- /**
141
- * A URL a browser can load the variant from, made now if it does not
142
- * exist yet: a signed URL for object storage, a `data:` URI for database
143
- * targets. `null` when the variant could not be made.
144
- */
145
- acquireVariantUrl(source: UploadVariantSource, name: Name, options?: {
146
- expiresIn?: number;
147
- disposition?: ContentDisposition;
148
- }): Promise<string | null>;
149
- /**
150
- * Remakes every variant called `name`, for every source that has one
151
- * (made or failed), and leaves other variants alone. Use it after fixing
152
- * a generator. Each old file is deleted, then the variant is made again
153
- * unless `remake` is `false`, in which case it is made the next time it
154
- * is acquired.
155
- */
156
- regenerateVariants(name: Name, options?: {
157
- remake?: boolean;
158
- batchSize?: number;
159
- }): Promise<RegenerateVariantsResult>;
160
- /**
161
- * Deletes all variants of a source, bytes first, then rows. `deleteFile()`
162
- * does this for you when given `targets`.
163
- */
164
- deleteVariants(source: UploadVariantSource): Promise<number>;
165
- }
166
- /**
167
- * Deletes every derived file (variant) of `source`: bytes first, then rows,
168
- * like `deleteFile()`. Returns how many were deleted. `deleteFile()` calls
169
- * this when given `targets`, so a source never goes without its variants.
170
- */
171
- export declare function deleteVariants(source: UploadVariantSource, { db, targets }: {
172
- db: UploadVariantDatabase;
173
- targets: StorageTargets;
174
- }): Promise<number>;
175
- /**
176
- * Declares the derived files (variants) uploads can have, such as
177
- * thumbnails, previews or a video's poster frame, each with the function
178
- * that makes it. **Experimental.**
179
- *
180
- * The app supplies only the generators. The uploads package keeps the
181
- * bookkeeping: each variant is an `Upload` row linked to its source by
182
- * `sourceId` and named by `variant`; it is made the first time it is
183
- * acquired, once even when several requests or processes ask at the same
184
- * moment; a variant that cannot be made is remembered and tried again
185
- * after `retryFailedAfter`; `regenerateVariants()` remakes every variant of
186
- * one name; and `deleteFile()` with `targets` deletes a source's variants
187
- * with it.
188
- *
189
- * Methods that make a variant when it is missing are named `acquire*`;
190
- * `find*` only looks and never makes anything.
191
- *
192
- * The package does not make images or read videos itself. A generator is
193
- * any function from source bytes to new bytes, using sharp, pdf.js, ffmpeg
194
- * or a third-party service as the app sees fit.
195
- *
196
- * @example
197
- * export const uploadVariants = defineUploadVariants({
198
- * db,
199
- * targets,
200
- * target: targets.thumbnails,
201
- * variants: {
202
- * 'thumb-164': async ({ readSource }) => ({
203
- * data: await sharp(await readSource()).resize(164, 164).webp().toBuffer(),
204
- * mimeType: 'image/webp',
205
- * }),
206
- * },
207
- * })
208
- *
209
- * const thumb = await uploadVariants.acquireVariant(photo.uploadId, 'thumb-164')
210
- */
211
- export declare function defineUploadVariants<Name extends string>(options: DefineUploadVariantsOptions<Name>): UploadVariants<Name>;
212
- //# sourceMappingURL=variants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../src/variants.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAWnB,4CAA4C;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