@jrmc/adonis-attachment 2.3.1 → 2.3.2

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.
@@ -125,7 +125,7 @@ async function videoExif(input) {
125
125
  dimension: {
126
126
  width: data.streams[0].width,
127
127
  height: data.streams[0].height,
128
- }
128
+ },
129
129
  });
130
130
  });
131
131
  });
@@ -83,7 +83,7 @@ export class Attachment extends AttachmentBase {
83
83
  this.variants.forEach((v) => {
84
84
  v.setOptions({
85
85
  ...this.options,
86
- variants: []
86
+ variants: [],
87
87
  });
88
88
  });
89
89
  }
@@ -65,7 +65,7 @@ export class AttachmentBase {
65
65
  if (this.url) {
66
66
  return {
67
67
  ...this.toObject(),
68
- url: this.url
68
+ url: this.url,
69
69
  };
70
70
  }
71
71
  return this.toObject();
@@ -27,7 +27,7 @@ export default class AutodetectConverter extends Converter {
27
27
  if (converter) {
28
28
  return await converter.handle({
29
29
  input,
30
- options
30
+ options,
31
31
  });
32
32
  }
33
33
  }
@@ -18,7 +18,7 @@ export default class DocumentThumbnailConverter extends Converter {
18
18
  const converter = new ImageConverter();
19
19
  return await converter.handle({
20
20
  input: outputBuffer,
21
- options
21
+ options,
22
22
  });
23
23
  }
24
24
  return outputBuffer;
@@ -36,7 +36,7 @@ export default class DocumentThumbnailConverter extends Converter {
36
36
  childProcessOptions: {
37
37
  timeout: 60 * 1000,
38
38
  },
39
- binaryPaths
39
+ binaryPaths,
40
40
  });
41
41
  if (Buffer.isBuffer(input)) {
42
42
  const output = await libreOfficeFileConverter.convert({
@@ -21,7 +21,7 @@ export default class PdfThumbnailConverter extends Converter {
21
21
  const converter = new ImageConverter();
22
22
  return await converter.handle({
23
23
  input: filePath,
24
- options
24
+ options,
25
25
  });
26
26
  }
27
27
  return filePath;
@@ -20,7 +20,7 @@ export default class VideoThumbnailConvert extends Converter {
20
20
  const converter = new ImageConverter();
21
21
  return await converter.handle({
22
22
  input: filePath,
23
- options
23
+ options,
24
24
  });
25
25
  }
26
26
  else {
@@ -49,8 +49,7 @@ export default class VideoThumbnailConvert extends Converter {
49
49
  count: 1,
50
50
  filename,
51
51
  folder,
52
- })
53
- .on('end', () => {
52
+ }).on('end', () => {
54
53
  resolve(path.join(folder, filename));
55
54
  });
56
55
  });
@@ -16,7 +16,9 @@ export const attachment = (options) => {
16
16
  const defaultOptions = {
17
17
  meta: defaultConfig.meta !== undefined ? defaultConfig.meta : defaultOptionsDecorator.meta,
18
18
  rename: defaultConfig.rename !== undefined ? defaultConfig.rename : defaultOptionsDecorator.rename,
19
- preComputeUrl: defaultConfig.preComputeUrl !== undefined ? defaultConfig.preComputeUrl : defaultOptionsDecorator.preComputeUrl,
19
+ preComputeUrl: defaultConfig.preComputeUrl !== undefined
20
+ ? defaultConfig.preComputeUrl
21
+ : defaultOptionsDecorator.preComputeUrl,
20
22
  };
21
23
  if (!options || options?.meta === undefined) {
22
24
  options.meta = defaultOptions.meta;
@@ -23,11 +23,7 @@ export declare const E_CANNOT_DELETE_FILE: new (args: [key: string], options?: E
23
23
  /**
24
24
  * Unable to set file visibility
25
25
  */
26
- export declare const E_CANNOT_SET_VISIBILITY: new (args: [key: string], options?: ErrorOptions) => import(
27
- /**
28
- * Unable to read file
29
- */
30
- "@adonisjs/core/exceptions").Exception;
26
+ export declare const E_CANNOT_SET_VISIBILITY: new (args: [key: string], options?: ErrorOptions) => import("@adonisjs/core/exceptions").Exception;
31
27
  /**
32
28
  * Unable to generate URL for a file
33
29
  */
@@ -10,9 +10,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
10
10
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
11
  return c > 3 && r && Object.defineProperty(target, key, r), r;
12
12
  };
13
- import { beforeSave, afterSave, beforeDelete, afterFind, afterFetch, afterPaginate } from '@adonisjs/lucid/orm';
14
- import { persistAttachment, commit, rollback, generateVariants, preComputeUrl } from '../utils/actions.js';
15
- import { clone, getAttachmentAttributeNames } from '../utils/helpers.js';
13
+ import { beforeSave, afterSave, beforeDelete, afterFind, afterFetch, afterPaginate, } from '@adonisjs/lucid/orm';
14
+ import { persistAttachment, commit, rollback, generateVariants, preComputeUrl, } from '../utils/actions.js';
15
+ import { clone, getAttachmentAttributeNames, getDirtyAttachmentAttributeNames, } from '../utils/helpers.js';
16
16
  import { defaultStateAttributeMixin } from '../utils/default_values.js';
17
17
  export const Attachmentable = (superclass) => {
18
18
  class ModelWithAttachment extends superclass {
@@ -27,7 +27,7 @@ export const Attachmentable = (superclass) => {
27
27
  await Promise.all(modelInstances.map((row) => this.afterFindHook(row)));
28
28
  }
29
29
  static async beforeSaveHook(modelInstance) {
30
- const attachmentAttributeNames = getAttachmentAttributeNames(modelInstance);
30
+ const attachmentAttributeNames = getDirtyAttachmentAttributeNames(modelInstance);
31
31
  /**
32
32
  * Empty previous $attachments
33
33
  */
@@ -35,11 +35,7 @@ export const Attachmentable = (superclass) => {
35
35
  /**
36
36
  * Set attributes Attachment type modified
37
37
  */
38
- attachmentAttributeNames.forEach((attributeName) => {
39
- if (modelInstance.$dirty[attributeName]) {
40
- modelInstance.$attachments.attributesModified.push(attributeName);
41
- }
42
- });
38
+ attachmentAttributeNames.forEach((attributeName) => modelInstance.$attachments.attributesModified.push(attributeName));
43
39
  /**
44
40
  * Persist attachments before saving the model to the database. This
45
41
  * way if file saving fails we will not write anything to the
@@ -10,7 +10,7 @@ export const defaultOptionsDecorator = {
10
10
  preComputeUrl: false,
11
11
  variants: [],
12
12
  meta: true,
13
- rename: true
13
+ rename: true,
14
14
  };
15
15
  export const defaultStateAttributeMixin = {
16
16
  attached: [],
@@ -8,6 +8,7 @@ import type { LucidOptions } from '../types/attachment.js';
8
8
  import type { Input } from '../types/input.js';
9
9
  import type { ModelWithAttachment } from '../types/mixin.js';
10
10
  export declare function getAttachmentAttributeNames(modelInstance: ModelWithAttachment): string[];
11
+ export declare function getDirtyAttachmentAttributeNames(modelInstance: ModelWithAttachment): string[];
11
12
  export declare function getOptions(modelInstance: ModelWithAttachment, attributeName: string): LucidOptions;
12
13
  export declare function createAttachmentAttributes(input: Input, name?: string): Promise<{
13
14
  originalName: string;
@@ -16,6 +16,10 @@ import { optionsSym } from './symbols.js';
16
16
  export function getAttachmentAttributeNames(modelInstance) {
17
17
  return Object.keys(modelInstance.$attributes).filter((attr) => modelInstance.$attributes[attr] instanceof Attachment);
18
18
  }
19
+ export function getDirtyAttachmentAttributeNames(modelInstance) {
20
+ return Object.keys(modelInstance.$dirty).filter((attr) => modelInstance.$dirty[attr] instanceof Attachment ||
21
+ modelInstance.$original[attr] instanceof Attachment);
22
+ }
19
23
  export function getOptions(modelInstance, attributeName) {
20
24
  return modelInstance.constructor.prototype[optionsSym]?.[attributeName];
21
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrmc/adonis-attachment",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "type": "module",
5
5
  "description": "Turn any field on your Lucid model to an attachment data type",
6
6
  "engines": {
@@ -86,4 +86,4 @@
86
86
  "volta": {
87
87
  "node": "20.17.0"
88
88
  }
89
- }
89
+ }