@paroicms/server-image-cache-engine 1.22.5 → 1.23.1

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 (60) hide show
  1. package/ddl/image-cache.ddl.sql +16 -15
  2. package/dist/compute-variant-size.d.ts +4 -9
  3. package/dist/compute-variant-size.js +28 -38
  4. package/dist/compute-variant-size.js.map +1 -1
  5. package/dist/constants.d.ts +3 -0
  6. package/dist/constants.js +8 -0
  7. package/dist/constants.js.map +1 -1
  8. package/dist/db-init/ddl-migration.d.ts +1 -1
  9. package/dist/db-init/ddl-migration.js +1 -1
  10. package/dist/db-init/ddl-migration.js.map +1 -1
  11. package/dist/default-bo-favicon.js +2 -2
  12. package/dist/default-bo-favicon.js.map +1 -1
  13. package/dist/engine-types.d.ts +42 -19
  14. package/dist/image-cache-engine.d.ts +42 -36
  15. package/dist/image-cache-engine.js +107 -138
  16. package/dist/image-cache-engine.js.map +1 -1
  17. package/dist/image-utils.d.ts +6 -0
  18. package/dist/image-utils.js +12 -0
  19. package/dist/image-utils.js.map +1 -0
  20. package/dist/{api.d.ts → index.d.ts} +2 -1
  21. package/dist/{api.js → index.js} +3 -2
  22. package/dist/index.js.map +1 -0
  23. package/dist/internal/engine-context.d.ts +12 -6
  24. package/dist/internal/engine-context.js +1 -2
  25. package/dist/internal/engine-context.js.map +1 -1
  26. package/dist/internal/internal.types.d.ts +36 -16
  27. package/dist/internal/queries.d.ts +64 -38
  28. package/dist/internal/queries.js +246 -106
  29. package/dist/internal/queries.js.map +1 -1
  30. package/dist/internal/resizer.d.ts +6 -6
  31. package/dist/internal/resizer.js +9 -9
  32. package/dist/internal/resizer.js.map +1 -1
  33. package/dist/internal/task-processor.js +37 -34
  34. package/dist/internal/task-processor.js.map +1 -1
  35. package/dist/internal/utils.d.ts +16 -0
  36. package/dist/internal/utils.js +34 -0
  37. package/dist/internal/utils.js.map +1 -0
  38. package/dist/original-images-processing.d.ts +2 -2
  39. package/dist/original-images-processing.js +27 -14
  40. package/dist/original-images-processing.js.map +1 -1
  41. package/dist/owner-transaction/make-t-image-available.d.ts +7 -0
  42. package/dist/owner-transaction/make-t-image-available.js +122 -0
  43. package/dist/owner-transaction/make-t-image-available.js.map +1 -0
  44. package/dist/owner-transaction/owner-batch.d.ts +10 -0
  45. package/dist/owner-transaction/owner-batch.js +85 -0
  46. package/dist/owner-transaction/owner-batch.js.map +1 -0
  47. package/dist/owner-transaction/owner-image-manager.d.ts +11 -0
  48. package/dist/owner-transaction/owner-image-manager.js +44 -0
  49. package/dist/owner-transaction/owner-image-manager.js.map +1 -0
  50. package/dist/owner-transaction/owner-transaction-types.d.ts +12 -0
  51. package/dist/owner-transaction/owner-transaction-types.js +2 -0
  52. package/dist/owner-transaction/owner-transaction-types.js.map +1 -0
  53. package/dist/owner-transaction/owner-transaction.d.ts +13 -0
  54. package/dist/owner-transaction/owner-transaction.js +60 -0
  55. package/dist/owner-transaction/owner-transaction.js.map +1 -0
  56. package/dist/owner-transaction/owner-utils.d.ts +1 -0
  57. package/dist/owner-transaction/owner-utils.js +10 -0
  58. package/dist/owner-transaction/owner-utils.js.map +1 -0
  59. package/package.json +12 -12
  60. package/dist/api.js.map +0 -1
@@ -1,152 +1,121 @@
1
- import { promiseToHandle } from "@paroi/async-lib";
2
- import { generateResourceVersion } from "@paroicms/internal-server-lib";
3
- import { computeVariantSize, findAuthorizedVariantSize } from "./compute-variant-size.js";
4
- import { createVariantEngineContext, } from "./internal/engine-context.js";
5
- import { clearVariantCache, deleteUnusedVariants, deleteVariants, deleteVariantsByDependencies, fetchImageVariant, fetchImageVariantWithBinary, markOneUsedKeyAsUsed, markUsedKeyAsUnused, } from "./internal/queries.js";
1
+ import { createVariantEngineContext } from "./internal/engine-context.js";
2
+ import { clearAll, deleteOrphanVariants, deleteVariants, deleteVariantsByDependencies, fetchImageVariantWithBinary, fetchImageVariantWithBinaryByOwner, fetchUsedRawSizesByMedia, } from "./internal/queries.js";
6
3
  import { processAllPending } from "./internal/task-processor.js";
4
+ import { makeOwnerKey, makeTaskKey } from "./internal/utils.js";
5
+ import { createOwnerTransaction } from "./owner-transaction/owner-transaction.js";
6
+ let pendingSeq = 0;
7
7
  export async function createImageCacheEngine(options) {
8
8
  const { context, isCleared } = await createVariantEngineContext(options);
9
- return {
10
- imageCache: new ImageCacheEngine(context),
11
- isCleared,
12
- };
13
- }
14
- export class ImageCacheEngine {
15
- #processing = false;
16
- #context;
17
- constructor(context) {
18
- this.#context = context;
19
- }
20
- async getImageVariantWithBinary({ imageUid, variantName, }) {
21
- this.#checkStatus();
22
- const taskKey = `${imageUid}:${variantName}`;
23
- const pth = this.#context.pendingTasks.get(taskKey);
24
- if (pth)
25
- return pth.promise;
26
- const found = await fetchImageVariantWithBinary(this.#context, {
27
- imageUid,
28
- variantName,
29
- });
30
- return found ? found.variant : undefined;
31
- }
32
- async resetUsedKey(options) {
33
- await markUsedKeyAsUnused(this.#context, options);
34
- }
35
- async makeImageAvailable(params) {
36
- this.#checkStatus();
37
- const imageUid = params.imageRef.imageUid;
38
- const { width, height, variantName } = computeVariantSize(params);
39
- const found = await fetchImageVariant(this.#context, { imageUid, variantName });
40
- if (found) {
41
- await markOneUsedKeyAsUsed(this.#context, {
42
- imageCacheId: found.id,
43
- usedKey: params.dependsOnUsedKey,
44
- });
45
- return found.variant;
46
- }
47
- const resourceVersion = generateResourceVersion();
48
- const taskKey = `${imageUid}:${variantName}`;
49
- if (!this.#context.pendingTasks.has(taskKey)) {
50
- this.#context.queue.push({
51
- taskKey,
52
- variantName,
53
- imageUid,
54
- imageSize: {
55
- width,
56
- height,
57
- },
58
- mediaType: params.imageRef.mediaType,
59
- changeMediaTypeTo: params.mediaType,
60
- dependsOnUsedKey: params.dependsOnUsedKey,
61
- resourceVersion,
62
- slug: params.slug,
63
- });
64
- this.#context.pendingTasks.set(taskKey, promiseToHandle());
65
- this.#startQueue();
66
- }
67
- return {
68
- width,
69
- height,
70
- variantName,
71
- mediaType: params.mediaType ?? params.imageRef.mediaType,
72
- resourceVersion,
73
- slug: params.slug,
74
- };
75
- }
76
- async getOrCreateImageWithBinary(params) {
77
- this.#checkStatus();
78
- const variant = await this.makeImageAvailable(params);
79
- return await this.getImageVariantWithBinary({
80
- imageUid: params.imageRef.imageUid,
81
- variantName: variant.variantName,
82
- });
83
- }
84
- async conditionallyCreateImageVariantWithBinary(media, options) {
85
- this.#checkStatus();
86
- const authorized = findAuthorizedVariantSize(media, options);
87
- if (!authorized)
88
- return;
89
- const available = await this.makeImageAvailable({
90
- autoCrop: false,
91
- imageSize: authorized.variantName,
92
- imageRef: media,
93
- dependsOnUsedKey: options.dependsOnUsedKey,
94
- slug: options.slug,
95
- });
96
- if (available.variantName !== authorized.variantName) {
97
- throw new Error(`mismatch variants '${available.variantName}' and '${authorized.variantName}'`);
9
+ let processing = false;
10
+ const pendingTransactions = new Map();
11
+ function checkStatus() {
12
+ if (context.status !== "ready") {
13
+ throw new Error(`ImageCacheEngine is ${context.status}`);
98
14
  }
99
- return await this.getImageVariantWithBinary({
100
- imageUid: media.imageUid,
101
- variantName: available.variantName,
102
- });
103
15
  }
104
- async invalidate(options) {
105
- this.#checkStatus();
106
- if ("usedKeys" in options) {
107
- await deleteVariantsByDependencies(this.#context.cn, options);
108
- }
109
- else {
110
- await deleteVariants(this.#context.cn, options);
111
- }
112
- }
113
- /**
114
- * Delete the images that have no usedKey and that have not been used recently.
115
- */
116
- async cleanUnusedValues() {
117
- this.#checkStatus();
118
- const count = await deleteUnusedVariants(this.#context);
119
- if (count !== undefined && count > 0) {
120
- this.#context.logger.debug(`${count} unused cache image were deleted`);
121
- }
122
- }
123
- async clearCache() {
124
- this.#checkStatus();
125
- await clearVariantCache(this.#context);
126
- this.#context.logger.debug("cache is cleared");
127
- }
128
- #startQueue() {
129
- if (this.#processing)
16
+ function startQueue() {
17
+ if (processing)
130
18
  return;
131
- this.#processing = true;
132
- void processAllPending(this.#context)
19
+ processing = true;
20
+ void processAllPending(context)
133
21
  .catch((error) => {
134
- this.#context.logger.error("Error when proccessing =>", error);
22
+ context.logger.error("Error when proccessing =>", error);
135
23
  })
136
24
  .then(() => {
137
- this.#processing = false;
25
+ processing = false;
138
26
  });
139
27
  }
140
- async close() {
141
- if (this.#context.status === "destroyed")
142
- return;
143
- this.#context.status = "destroyed";
144
- await this.#context.cn.destroy();
145
- }
146
- #checkStatus() {
147
- if (this.#context.status !== "ready") {
148
- throw new Error(`ImageCacheEngine is ${this.#context.status}`);
149
- }
28
+ function addPending(closeNow) {
29
+ const pendingId = ++pendingSeq;
30
+ pendingTransactions.set(pendingId, closeNow);
31
+ return () => {
32
+ pendingTransactions.delete(pendingId);
33
+ };
150
34
  }
35
+ const imageCache = {
36
+ async getImageVariantWithBinary({ mediaId, mediaType, rawWidth, rawHeight }) {
37
+ checkStatus();
38
+ const taskKey = makeTaskKey({ mediaId, rawSizeName: `${rawWidth}x${rawHeight}`, mediaType });
39
+ const pth = context.pendingTasks.get(taskKey);
40
+ if (pth)
41
+ return pth.promise;
42
+ const found = await fetchImageVariantWithBinary(context, {
43
+ mediaId,
44
+ mediaType,
45
+ rawWidth,
46
+ rawHeight,
47
+ });
48
+ return found ? found.variant : undefined;
49
+ },
50
+ async getImageVariantWithBinaryByOwner(options) {
51
+ checkStatus();
52
+ const oneOwnerKey = makeOwnerKey(options);
53
+ const pth = context.pendingTaskByOwnerKeys.get(oneOwnerKey);
54
+ if (pth)
55
+ return pth.promise;
56
+ const found = await fetchImageVariantWithBinaryByOwner(context, options);
57
+ return found ? found.variant : undefined;
58
+ },
59
+ async makeImageAvailable({ ownerHandle, isHandleReusable, canBeRetrievedByOwner, ...input }) {
60
+ checkStatus();
61
+ const transaction = createOwnerTransaction({
62
+ engine: { context: context, startQueue, checkStatus, addPending },
63
+ ownerHandle,
64
+ isHandleReusable,
65
+ canBeRetrievedByOwner,
66
+ });
67
+ const [result] = await transaction.makeImageAvailable([input]);
68
+ await transaction.flush();
69
+ await transaction.close();
70
+ return result;
71
+ },
72
+ createOwnerTransaction(ownerHandle) {
73
+ checkStatus();
74
+ return createOwnerTransaction({
75
+ engine: { context: context, startQueue, checkStatus, addPending },
76
+ ownerHandle,
77
+ isHandleReusable: false,
78
+ canBeRetrievedByOwner: false,
79
+ });
80
+ },
81
+ async invalidate(options) {
82
+ checkStatus();
83
+ if ("ownerHandles" in options) {
84
+ await deleteVariantsByDependencies(context, options);
85
+ }
86
+ else {
87
+ await deleteVariants(context, options);
88
+ }
89
+ },
90
+ async cleanUnusedValues() {
91
+ checkStatus();
92
+ const count = await deleteOrphanVariants(context);
93
+ if (count !== undefined && count > 0) {
94
+ context.logger.debug(`${count} unused cache image were deleted`);
95
+ }
96
+ },
97
+ async clearCache() {
98
+ checkStatus();
99
+ await clearAll(context);
100
+ context.logger.debug("cache is cleared");
101
+ },
102
+ async getUsedRawSizesByMedia(mediaId) {
103
+ checkStatus();
104
+ return await fetchUsedRawSizesByMedia(context, mediaId);
105
+ },
106
+ async close() {
107
+ if (context.status === "closed")
108
+ return;
109
+ context.status = "closed";
110
+ for (const closeNow of pendingTransactions.values()) {
111
+ await closeNow();
112
+ }
113
+ await context.cn.destroy();
114
+ },
115
+ };
116
+ return {
117
+ imageCache,
118
+ isCleared,
119
+ };
151
120
  }
152
121
  //# sourceMappingURL=image-cache-engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-cache-engine.js","sourceRoot":"","sources":["../src/image-cache-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAMxE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAS1F,OAAO,EAEL,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,4BAA4B,EAC5B,iBAAiB,EACjB,2BAA2B,EAC3B,oB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here-lib";
2
+ export declare function extensionToMediaType(extension: string): string | undefined;
3
+ export declare function parseSizeName(sizeName: SizeName): {
4
+ width: number;
5
+ height: number;
6
+ };
@@ -0,0 +1,12 @@
1
+ import { mediaTypeByExtensions } from "./constants.js";
2
+ export function extensionToMediaType(extension) {
3
+ return mediaTypeByExtensions[extension === "jpg" ? "jpeg" : extension];
4
+ }
5
+ export function parseSizeName(sizeName) {
6
+ const [width, height] = sizeName.split("x").map(Number);
7
+ if (Number.isNaN(width) || Number.isNaN(height)) {
8
+ throw new Error(`invalid variant name "${sizeName}"`);
9
+ }
10
+ return { width, height };
11
+ }
12
+ //# sourceMappingURL=image-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-utils.js","sourceRoot":"","sources":["../src/image-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,OAAO,qBAAqB,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAkB;IAC9C,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,GAAG,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
@@ -2,5 +2,6 @@ export * from "./compute-variant-size.js";
2
2
  export * from "./default-bo-favicon.js";
3
3
  export * from "./engine-types.js";
4
4
  export * from "./image-cache-engine.js";
5
- export * from "./image-processor-setup.js";
5
+ export { setupImageProcessor, type SetupImageProcessorOptions } from "./image-processor-setup.js";
6
+ export * from "./image-utils.js";
6
7
  export * from "./original-images-processing.js";
@@ -2,6 +2,7 @@ export * from "./compute-variant-size.js";
2
2
  export * from "./default-bo-favicon.js";
3
3
  export * from "./engine-types.js";
4
4
  export * from "./image-cache-engine.js";
5
- export * from "./image-processor-setup.js";
5
+ export { setupImageProcessor } from "./image-processor-setup.js";
6
+ export * from "./image-utils.js";
6
7
  export * from "./original-images-processing.js";
7
- //# sourceMappingURL=api.js.map
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAmC,MAAM,4BAA4B,CAAC;AAClG,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC"}
@@ -1,17 +1,23 @@
1
- import type { PromiseToHandle } from "@paroi/async-lib";
2
1
  import type { BasicAppLogger } from "@paroicms/internal-server-lib";
3
2
  import type { Knex } from "knex";
4
3
  import type { ImageVariantWithBinary } from "../engine-types.js";
5
4
  import type { CreateImageCacheEngineOptions } from "../image-cache-engine.js";
6
- import type { TaskData, TaskKey } from "./internal.types.js";
5
+ import type { OwnerKey, TaskData, TaskKey } from "./internal.types.js";
7
6
  export interface VariantEngineContext extends Omit<CreateImageCacheEngineOptions, "logger"> {
8
- status: "ready" | "destroyed";
7
+ status: "ready" | "closed";
9
8
  logger: BasicAppLogger;
10
- queue: TaskData[];
11
- pendingTasks: Map<TaskKey, PromiseToHandle<ImageVariantWithBinary>>;
9
+ queue: TaskKey[];
10
+ pendingTasks: Map<TaskKey, PendingTask>;
11
+ pendingTaskByOwnerKeys: Map<OwnerKey, PendingTask>;
12
12
  cn: Knex;
13
13
  logNextQuery: (count?: number) => void;
14
- timeToIdleDays?: number;
14
+ }
15
+ export interface PendingTask {
16
+ resolve: (result: ImageVariantWithBinary) => void;
17
+ reject: (error: unknown) => void;
18
+ promise: Promise<ImageVariantWithBinary>;
19
+ task: TaskData;
20
+ ownerKeys: Set<OwnerKey>;
15
21
  }
16
22
  export declare function createVariantEngineContext(options: CreateImageCacheEngineOptions): Promise<{
17
23
  context: VariantEngineContext;
@@ -1,4 +1,3 @@
1
- import { parseTimeWithUnit } from "@paroicms/internal-anywhere-lib";
2
1
  import { createOrOpenConnection } from "../db-init/db-init.js";
3
2
  export async function createVariantEngineContext(options) {
4
3
  const logger = options.logger ?? console;
@@ -12,9 +11,9 @@ export async function createVariantEngineContext(options) {
12
11
  logger,
13
12
  queue: [],
14
13
  pendingTasks: new Map(),
14
+ pendingTaskByOwnerKeys: new Map(),
15
15
  cn,
16
16
  logNextQuery,
17
- timeToIdleDays: options.timeToIdle === undefined ? undefined : parseTimeWithUnit(options.timeToIdle).delay,
18
17
  };
19
18
  return { context, isCleared };
20
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"engine-context.js","sourceRoot":"","sources":["../../src/internal/engine-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAe/D,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAAsC;IAEtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IAEzC,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,MAAM,sBAAsB,CAAC;QACnE,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAChC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,OAAO,GAAyB;QACpC,GAAG,OAAO;QACV,MAAM,EAAE,OAAO;QACf,MAAM;QACN,KAAK,EAAE,EAAE;QACT,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,EAAE;QACF,YAAY;QACZ,cAAc,EACZ,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK;KAC7F,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
1
+ {"version":3,"file":"engine-context.js","sourceRoot":"","sources":["../../src/internal/engine-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAuB/D,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAAsC;IAEtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IAEzC,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,MAAM,sBAAsB,CAAC;QACnE,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAChC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,OAAO,GAAyB;QACpC,GAAG,OAAO;QACV,MAAM,EAAE,OAAO;QACf,MAAM;QACN,KAAK,EAAE,EAAE;QACT,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,sBAAsB,EAAE,IAAI,GAAG,EAAE;QACjC,EAAE;QACF,YAAY;KACb,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
@@ -1,20 +1,40 @@
1
- import type { VariantName } from "@paroicms/public-anywhere-lib";
1
+ import type { ResizeRule, SizeName } from "@paroicms/public-anywhere-lib";
2
+ import type { ImageVariant, RequestedImageVariantWithSize, SourceImageRef } from "../engine-types.js";
2
3
  export interface TaskData {
3
- taskKey: TaskKey;
4
- resourceVersion: string;
5
- imageUid: string;
6
- variantName: VariantName;
7
- imageSize: ImageSize;
8
- mediaType: string;
9
- changeMediaTypeTo?: string;
10
- dependsOnUsedKey: string;
11
- slug?: string;
12
- }
13
- export interface ImageSize {
14
- width: number;
15
- height: number;
4
+ input: CompletedInput;
5
+ variant: ImageVariant;
6
+ /** key: ownerHandle */
7
+ owners: Map<string, ResizeOwner>;
16
8
  }
17
9
  /**
18
- * Format is: {imageUid}:{variantName}
10
+ * Format is: {mediaId}:{rawSizeName}:${mediaType}
19
11
  */
20
- export type TaskKey = `${string}:${VariantName}`;
12
+ export type TaskKey = `${string}:${SizeName}:${string}`;
13
+ /**
14
+ * Format is: {ownerHandle}:{mediaId}:{rawResizeRule}:${mediaType}
15
+ */
16
+ export type OwnerKey = `${string}:${string}:${ResizeRule}:${string}`;
17
+ export interface CompletedInput {
18
+ taskKey: TaskKey;
19
+ sourceImage: SourceImageRef;
20
+ requestedVariant: RequestedImageVariantWithSize;
21
+ rawResizeR: ResizeRule;
22
+ autoCrop?: boolean;
23
+ }
24
+ export interface StoredCacheMetadata {
25
+ imageCacheId: string;
26
+ alreadyOwned: boolean;
27
+ }
28
+ export interface StoredCacheItem extends StoredCacheMetadata {
29
+ variant: ImageVariant;
30
+ }
31
+ export interface TransactionCacheItem {
32
+ variant: ImageVariant;
33
+ stored?: StoredCacheMetadata;
34
+ /** Can be mutated during the transaction. */
35
+ usedBy?: CompletedInput;
36
+ }
37
+ export interface ResizeOwner {
38
+ ownerHandle: string;
39
+ rawResizeR: ResizeRule;
40
+ }
@@ -1,57 +1,83 @@
1
- import type { VariantName } from "@paroicms/public-anywhere-lib";
2
- import type { Knex } from "knex";
3
- import type { ImageVariant, ImageVariantWithBinary } from "../engine-types.js";
4
- import type { VariantEngineContext } from "../internal/engine-context.js";
5
- export declare function insertIntoImageVariant(cn: Knex, data: {
1
+ import type { ResizeRule } from "@paroicms/public-anywhere-lib";
2
+ import type { ImageVariant, ImageVariantWithBinary, UsedRawSize } from "../engine-types.js";
3
+ import type { VariantEngineContext } from "./engine-context.js";
4
+ import type { ResizeOwner, StoredCacheItem } from "./internal.types.js";
5
+ export declare function insertIntoImageVariant(ctx: Pick<VariantEngineContext, "cn">, data: {
6
6
  resourceVersion: string;
7
- imageUid: string;
8
- variantName: VariantName;
9
- slug?: string;
7
+ mediaId: string;
10
8
  mediaType: string;
11
- width: number;
12
- height: number;
9
+ rawWidth: number;
10
+ rawHeight: number;
13
11
  weightB: number;
14
12
  binaryFile: Buffer;
15
- }, usedKey: string): Promise<{
16
- newId: string;
13
+ slug?: string;
14
+ }, owners: ResizeOwner[]): Promise<{
15
+ imageCacheId: string;
17
16
  lastModified: string;
18
17
  }>;
19
- export declare function deleteVariants(cn: Knex, options: {
20
- imageUid: string;
21
- variantName?: string;
22
- } | {
23
- imageUids: string[];
18
+ export declare function insertIntoPaImageCacheOwner(ctx: Pick<VariantEngineContext, "cn">, input: {
19
+ imageCacheId: string;
20
+ owners: ResizeOwner[];
24
21
  }): Promise<void>;
25
- /**
26
- * @returns the list of cache usedKeys that were deleted
27
- */
28
- export declare function deleteVariantsByDependencies(cn: Knex, options: {
29
- usedKeys: string[];
30
- }): Promise<number>;
31
- export declare function fetchImageVariant(ctx: Pick<VariantEngineContext, "cn" | "timeToIdleDays" | "logger">, { imageUid, variantName, }: {
32
- imageUid: string;
33
- variantName: VariantName;
22
+ export declare function fetchImageVariant(ctx: Pick<VariantEngineContext, "cn" | "logger">, input: {
23
+ mediaId: string;
24
+ mediaType: string;
25
+ rawWidth: number;
26
+ rawHeight: number;
34
27
  }): Promise<{
35
28
  id: string;
36
29
  variant: ImageVariant;
37
30
  } | undefined>;
38
- export declare function fetchImageVariantWithBinary(ctx: Pick<VariantEngineContext, "cn" | "timeToIdleDays" | "logger">, { imageUid, variantName, }: {
39
- imageUid: string;
40
- variantName: VariantName;
31
+ export declare function fetchImageVariantWithBinary(ctx: Pick<VariantEngineContext, "cn" | "logger">, input: {
32
+ mediaId: string;
33
+ mediaType: string;
34
+ rawWidth: number;
35
+ rawHeight: number;
41
36
  }): Promise<{
42
37
  variant: ImageVariantWithBinary;
43
38
  id: string;
44
39
  } | undefined>;
40
+ export declare function fetchImageVariantWithBinaryByOwner(ctx: Pick<VariantEngineContext, "cn" | "logger">, input: {
41
+ mediaId: string;
42
+ mediaType: string;
43
+ ownerHandle: string;
44
+ rawResizeR: ResizeRule;
45
+ }): Promise<{
46
+ variant: ImageVariantWithBinary;
47
+ id: string;
48
+ } | undefined>;
49
+ export declare function deleteVariants(ctx: VariantEngineContext, options: {
50
+ mediaId: string;
51
+ } | {
52
+ mediaIds: string[];
53
+ }): Promise<void>;
45
54
  /**
46
- * Delete the images that have no usedKey and that have not been used recently.
47
- * @returns the number of cache identifiers that were deleted
55
+ * @returns the list of cache ownerHandles that were deleted
48
56
  */
49
- export declare function deleteUnusedVariants({ cn, timeToIdleDays, }: VariantEngineContext): Promise<number | undefined>;
50
- export declare function markOneUsedKeyAsUsed(ctx: Pick<VariantEngineContext, "cn">, { imageCacheId, usedKey, }: {
51
- imageCacheId: string;
52
- usedKey: string;
57
+ export declare function deleteVariantsByDependencies(ctx: VariantEngineContext, options: {
58
+ ownerHandles: string[];
53
59
  }): Promise<void>;
54
- export declare function markUsedKeyAsUnused(ctx: Pick<VariantEngineContext, "cn">, { usedKey, }: {
55
- usedKey: string;
60
+ /**
61
+ * Delete the images that have no ownerHandle and that have not been used recently.
62
+ * @returns the number of cache identifiers that were deleted
63
+ */
64
+ export declare function deleteOrphanVariants(ctx: VariantEngineContext): Promise<number | undefined>;
65
+ export declare function associateOwnerToImages(ctx: Pick<VariantEngineContext, "cn" | "logger">, { ownerHandle, cacheImages, isHandleReusable, }: {
66
+ ownerHandle: string;
67
+ cacheImages: {
68
+ imageCacheId: string;
69
+ rawResizeR: ResizeRule;
70
+ }[];
71
+ isHandleReusable: boolean;
56
72
  }): Promise<void>;
57
- export declare function clearVariantCache({ cn }: VariantEngineContext): Promise<void>;
73
+ export declare function fetchStoredCacheItems(ctx: Pick<VariantEngineContext, "cn" | "logger" | "logNextQuery">, ownerHandle: string): Promise<StoredCacheItem[]>;
74
+ export declare function fetchBatchOfStoredCacheItems(ctx: Pick<VariantEngineContext, "cn" | "logger" | "logNextQuery">, groups: {
75
+ requestedVariants: {
76
+ mediaType: string;
77
+ rawWidth: number;
78
+ rawHeight: number;
79
+ }[];
80
+ mediaIds: string[];
81
+ }[], alreadyOwnedBy: string): Promise<StoredCacheItem[]>;
82
+ export declare function clearAll({ cn }: VariantEngineContext): Promise<void>;
83
+ export declare function fetchUsedRawSizesByMedia(ctx: Pick<VariantEngineContext, "cn" | "logger">, mediaId: string): Promise<UsedRawSize[]>;