@cedarjs/uploads 8.0.0-canary.3427 → 8.0.0-canary.3429
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/README.md +3 -3
- package/dist/variants.d.ts +18 -13
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js +16 -14
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ File uploads and storage for CedarJS apps.
|
|
|
17
17
|
- **Derived files (variants)**, experimental: thumbnails, previews, a video's
|
|
18
18
|
poster frame. `defineUploadVariants()` takes one generator function per
|
|
19
19
|
variant name and keeps the bookkeeping: variants are `Upload` rows linked
|
|
20
|
-
to their source, made once
|
|
21
|
-
remembered with a retry-after,
|
|
22
|
-
and deletion with the source.
|
|
20
|
+
to their source, made once when first acquired (`acquireVariant()`) even
|
|
21
|
+
under concurrency, failures remembered with a retry-after,
|
|
22
|
+
`regenerateVariants()` to remake one name, and deletion with the source.
|
|
23
23
|
- **Content detection** (`detectContentType`, `acceptedContentType`) that
|
|
24
24
|
checks what an uploaded file really is from its bytes, not from its name or
|
|
25
25
|
the type the browser claimed: images, PDF, audio/video, and OpenDocument and
|
package/dist/variants.d.ts
CHANGED
|
@@ -24,9 +24,10 @@ export interface UploadVariantContext {
|
|
|
24
24
|
* Reads another variant of the same source, making it first if it does
|
|
25
25
|
* not exist yet. Returns `null` when that variant could not be made. This
|
|
26
26
|
* is how one derived file is made from another, for example a PDF's
|
|
27
|
-
* thumbnail cut from its drawn first page
|
|
27
|
+
* thumbnail cut from its drawn first page
|
|
28
|
+
* (`acquireVariantData('preview')`).
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
acquireVariantData(name: string): Promise<Buffer | null>;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Makes one derived file (variant) from its source: a thumbnail from a
|
|
@@ -116,7 +117,7 @@ export interface UploadVariants<Name extends string> {
|
|
|
116
117
|
* one attempt, and across processes a claim row decides who makes it
|
|
117
118
|
* while the others wait for the result.
|
|
118
119
|
*/
|
|
119
|
-
|
|
120
|
+
acquireVariant(source: UploadVariantSource, name: Name): Promise<UploadVariantRecord | null>;
|
|
120
121
|
/**
|
|
121
122
|
* The variant's `Upload` row if it has been made, or `null`. Never makes
|
|
122
123
|
* anything; use it where making on demand would be too slow, such as a
|
|
@@ -132,7 +133,7 @@ export interface UploadVariants<Name extends string> {
|
|
|
132
133
|
* The variant's row and bytes, made now if it does not exist yet, or
|
|
133
134
|
* `null` when it could not be made.
|
|
134
135
|
*/
|
|
135
|
-
|
|
136
|
+
acquireVariantData(source: UploadVariantSource, name: Name): Promise<{
|
|
136
137
|
upload: UploadVariantRecord;
|
|
137
138
|
data: Buffer;
|
|
138
139
|
} | null>;
|
|
@@ -141,7 +142,7 @@ export interface UploadVariants<Name extends string> {
|
|
|
141
142
|
* exist yet: a signed URL for object storage, a `data:` URI for database
|
|
142
143
|
* targets. `null` when the variant could not be made.
|
|
143
144
|
*/
|
|
144
|
-
|
|
145
|
+
acquireVariantUrl(source: UploadVariantSource, name: Name, options?: {
|
|
145
146
|
expiresIn?: number;
|
|
146
147
|
disposition?: ContentDisposition;
|
|
147
148
|
}): Promise<string | null>;
|
|
@@ -149,7 +150,8 @@ export interface UploadVariants<Name extends string> {
|
|
|
149
150
|
* Remakes every variant called `name`, for every source that has one
|
|
150
151
|
* (made or failed), and leaves other variants alone. Use it after fixing
|
|
151
152
|
* a generator. Each old file is deleted, then the variant is made again
|
|
152
|
-
* unless `remake` is `false`, in which case it is made
|
|
153
|
+
* unless `remake` is `false`, in which case it is made the next time it
|
|
154
|
+
* is acquired.
|
|
153
155
|
*/
|
|
154
156
|
regenerateVariants(name: Name, options?: {
|
|
155
157
|
remake?: boolean;
|
|
@@ -177,12 +179,15 @@ export declare function deleteVariants(source: UploadVariantSource, { db, target
|
|
|
177
179
|
*
|
|
178
180
|
* The app supplies only the generators. The uploads package keeps the
|
|
179
181
|
* bookkeeping: each variant is an `Upload` row linked to its source by
|
|
180
|
-
* `sourceId` and named by `variant`; it is made
|
|
181
|
-
* when several requests or processes ask at the same
|
|
182
|
-
* that cannot be made is remembered and tried again
|
|
183
|
-
* `retryFailedAfter`; `regenerateVariants()` remakes every variant of
|
|
184
|
-
* name; and `deleteFile()` with `targets` deletes a source's variants
|
|
185
|
-
* it.
|
|
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.
|
|
186
191
|
*
|
|
187
192
|
* The package does not make images or read videos itself. A generator is
|
|
188
193
|
* any function from source bytes to new bytes, using sharp, pdf.js, ffmpeg
|
|
@@ -201,7 +206,7 @@ export declare function deleteVariants(source: UploadVariantSource, { db, target
|
|
|
201
206
|
* },
|
|
202
207
|
* })
|
|
203
208
|
*
|
|
204
|
-
* const thumb = await uploadVariants.
|
|
209
|
+
* const thumb = await uploadVariants.acquireVariant(photo.uploadId, 'thumb-164')
|
|
205
210
|
*/
|
|
206
211
|
export declare function defineUploadVariants<Name extends string>(options: DefineUploadVariantsOptions<Name>): UploadVariants<Name>;
|
|
207
212
|
//# sourceMappingURL=variants.d.ts.map
|
package/dist/variants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAC5C,MAAM,WAAW,iBAAiB;IAChC,gCAAgC;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;;GAmCG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,MAAM,EACtD,OAAO,EAAE,2BAA2B,CAAC,IAAI,CAAC,GACzC,cAAc,CAAC,IAAI,CAAC,CAomBtB"}
|
package/dist/variants.js
CHANGED
|
@@ -167,7 +167,7 @@ function defineUploadVariants(options) {
|
|
|
167
167
|
if (source.sourceId) {
|
|
168
168
|
throw new UploadError(
|
|
169
169
|
"NOT_SUPPORTED",
|
|
170
|
-
`Upload '${sourceId}' is itself a variant. Variants are made from original uploads only; use \`
|
|
170
|
+
`Upload '${sourceId}' is itself a variant. Variants are made from original uploads only; use \`acquireVariantData()\` in a generator to make one variant from another.`
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
return source;
|
|
@@ -193,7 +193,7 @@ function defineUploadVariants(options) {
|
|
|
193
193
|
source,
|
|
194
194
|
variant: name,
|
|
195
195
|
readSource: () => readBytes(db, targets, source),
|
|
196
|
-
|
|
196
|
+
acquireVariantData: async (other) => {
|
|
197
197
|
const made = await obtainFor(
|
|
198
198
|
keyOf(source.id, name),
|
|
199
199
|
source.id,
|
|
@@ -369,7 +369,7 @@ function defineUploadVariants(options) {
|
|
|
369
369
|
attempt.then(forget, forget);
|
|
370
370
|
return attempt;
|
|
371
371
|
};
|
|
372
|
-
const
|
|
372
|
+
const acquireVariant = (source, name) => obtain(idOf(source), name, []);
|
|
373
373
|
const findVariant = async (source, name) => {
|
|
374
374
|
definitionOf(name);
|
|
375
375
|
return db.upload.findFirst({
|
|
@@ -395,15 +395,15 @@ function defineUploadVariants(options) {
|
|
|
395
395
|
}
|
|
396
396
|
return bySource;
|
|
397
397
|
};
|
|
398
|
-
const
|
|
399
|
-
const upload = await
|
|
398
|
+
const acquireVariantData = async (source, name) => {
|
|
399
|
+
const upload = await acquireVariant(source, name);
|
|
400
400
|
if (!upload) {
|
|
401
401
|
return null;
|
|
402
402
|
}
|
|
403
403
|
return { upload, data: await readBytes(db, targets, upload) };
|
|
404
404
|
};
|
|
405
|
-
const
|
|
406
|
-
const upload = await
|
|
405
|
+
const acquireVariantUrl = async (source, name, urlOptions = {}) => {
|
|
406
|
+
const upload = await acquireVariant(source, name);
|
|
407
407
|
if (!upload) {
|
|
408
408
|
return null;
|
|
409
409
|
}
|
|
@@ -464,10 +464,12 @@ function defineUploadVariants(options) {
|
|
|
464
464
|
}
|
|
465
465
|
if (remake) {
|
|
466
466
|
await inFlight.get(keyOf(sourceId, name))?.catch(() => null);
|
|
467
|
-
const made = await
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
const made = await acquireVariant(sourceId, name).catch(
|
|
468
|
+
(e) => {
|
|
469
|
+
onError(e, { sourceId, variant: name });
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
);
|
|
471
473
|
if (made) {
|
|
472
474
|
result.made += 1;
|
|
473
475
|
} else {
|
|
@@ -483,11 +485,11 @@ function defineUploadVariants(options) {
|
|
|
483
485
|
};
|
|
484
486
|
return {
|
|
485
487
|
names,
|
|
486
|
-
|
|
488
|
+
acquireVariant,
|
|
487
489
|
findVariant,
|
|
488
490
|
findVariants,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
+
acquireVariantData,
|
|
492
|
+
acquireVariantUrl,
|
|
491
493
|
regenerateVariants,
|
|
492
494
|
deleteVariants: (source) => deleteVariants(source, { db, targets })
|
|
493
495
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/uploads",
|
|
3
|
-
"version": "8.0.0-canary.
|
|
3
|
+
"version": "8.0.0-canary.3429",
|
|
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.
|
|
47
|
-
"@cedarjs/context": "8.0.0-canary.
|
|
48
|
-
"@cedarjs/graphql-server": "8.0.0-canary.
|
|
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",
|
|
49
49
|
"@fastify/multipart": "9.4.0",
|
|
50
50
|
"graphql": "16.14.2",
|
|
51
51
|
"mime-types": "2.1.35"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@arethetypeswrong/cli": "0.18.5",
|
|
56
56
|
"@aws-sdk/client-s3": "3.1149.0",
|
|
57
57
|
"@aws-sdk/s3-request-presigner": "3.1149.0",
|
|
58
|
-
"@cedarjs/framework-tools": "8.0.0-canary.
|
|
59
|
-
"@cedarjs/web": "8.0.0-canary.
|
|
58
|
+
"@cedarjs/framework-tools": "8.0.0-canary.3429",
|
|
59
|
+
"@cedarjs/web": "8.0.0-canary.3429",
|
|
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.
|
|
93
|
+
"@cedarjs/web": "8.0.0-canary.3429",
|
|
94
94
|
"@uppy/aws-s3": "^6.0.0",
|
|
95
95
|
"@uppy/core": "^6.0.0",
|
|
96
96
|
"@uppy/dashboard": "^6.0.0",
|