@jrmc/adonis-attachment 2.1.0 → 2.1.1-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.
@@ -7,7 +7,7 @@
7
7
  import type { LoggerService } from '@adonisjs/core/types';
8
8
  import type { DriveService } from '@adonisjs/drive/types';
9
9
  import type { MultipartFile } from '@adonisjs/core/bodyparser';
10
- import type { AttachmentBase } from './types/attachment.js';
10
+ import type { AttachmentBase, Attachment as AttachmentType } from './types/attachment.js';
11
11
  import type { ResolvedAttachmentConfig } from './types/config.js';
12
12
  import { Attachment } from './attachments/attachment.js';
13
13
  import Converter from './converters/converter.js';
@@ -19,6 +19,7 @@ export declare class AttachmentManager {
19
19
  createFromFile(file: MultipartFile): Promise<Attachment>;
20
20
  createFromBuffer(buffer: Buffer, name?: string): Promise<Attachment>;
21
21
  getConverter(key: string): Promise<void | Converter>;
22
+ computeUrl(attachment: AttachmentType): Promise<void>;
22
23
  save(attachment: AttachmentBase): Promise<void>;
23
24
  delete(attachment: AttachmentBase): Promise<void>;
24
25
  }
@@ -58,6 +58,31 @@ export class AttachmentManager {
58
58
  }
59
59
  }
60
60
  }
61
+ async computeUrl(attachment) {
62
+ if (attachment.options?.preComputeUrl === false) {
63
+ return;
64
+ }
65
+ const disk = attachment.getDisk();
66
+ const fileVisibility = await disk.getVisibility(attachment.path);
67
+ if (fileVisibility === 'private') {
68
+ attachment.url = await attachment.getSignedUrl();
69
+ }
70
+ else {
71
+ attachment.url = await attachment.getUrl();
72
+ }
73
+ if (attachment.variants) {
74
+ for (const key in attachment.variants) {
75
+ if (Object.prototype.hasOwnProperty.call(attachment.variants, key)) {
76
+ if (fileVisibility === 'private') {
77
+ attachment.variants[key].url = await attachment.getSignedUrl(attachment.variants[key].key);
78
+ }
79
+ else {
80
+ attachment.variants[key].url = await attachment.getUrl(attachment.variants[key].key);
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
61
86
  async save(attachment) {
62
87
  const destinationPath = attachment.path;
63
88
  if (attachment.options?.meta) {
@@ -19,5 +19,5 @@ export declare class Attachment extends AttachmentBase implements AttachmentInte
19
19
  getSignedUrl(variantNameOrOptions?: string | SignedURLOptions, signedUrlOptions?: SignedURLOptions): Promise<string>;
20
20
  setOptions(options: LucidOptions): this;
21
21
  toObject(): AttachmentAttributes;
22
- toJSON(): Promise<Object>;
22
+ toJSON(): Object;
23
23
  }
@@ -89,7 +89,7 @@ export class Attachment extends AttachmentBase {
89
89
  variants,
90
90
  };
91
91
  }
92
- async toJSON() {
92
+ toJSON() {
93
93
  const data = {
94
94
  name: this.name,
95
95
  originalName: this.originalName,
@@ -97,16 +97,16 @@ export class Attachment extends AttachmentBase {
97
97
  extname: this.extname,
98
98
  mimetype: this.mimeType,
99
99
  meta: this.meta,
100
- url: await this.getUrl(),
101
- signedUrl: await this.getSignedUrl(),
102
100
  };
103
- if (this.variants) {
104
- await Promise.allSettled(this.variants.map(async (v) => {
105
- data[v.key] = {
106
- url: await this.getUrl(v.key),
107
- signedUrl: await this.getSignedUrl(v.key)
108
- };
109
- }));
101
+ if (this.url) {
102
+ data.url = this.url;
103
+ if (this.variants) {
104
+ this.variants.map(async (v) => {
105
+ data[v.key] = {
106
+ url: v.url,
107
+ };
108
+ });
109
+ }
110
110
  }
111
111
  return data;
112
112
  }
@@ -17,6 +17,7 @@ export declare class AttachmentBase implements AttachmentBaseInterface {
17
17
  meta?: Exif;
18
18
  folder?: string;
19
19
  path?: string;
20
+ url?: string;
20
21
  options?: LucidOptions;
21
22
  constructor(drive: DriveService, attributes: AttachmentBaseAttributes, input?: Input);
22
23
  getDisk(): import("flydrive").Disk;
@@ -24,5 +25,5 @@ export declare class AttachmentBase implements AttachmentBaseInterface {
24
25
  getSignedUrl(signedUrlOptions?: SignedURLOptions): Promise<string>;
25
26
  setOptions(options: LucidOptions): this;
26
27
  toObject(): AttachmentBaseAttributes;
27
- toJSON(): Promise<Object>;
28
+ toJSON(): Object;
28
29
  }
@@ -16,6 +16,7 @@ export class AttachmentBase {
16
16
  meta;
17
17
  folder;
18
18
  path;
19
+ url;
19
20
  options;
20
21
  constructor(drive, attributes, input) {
21
22
  this.input = input;
@@ -60,11 +61,13 @@ export class AttachmentBase {
60
61
  path: this.path,
61
62
  };
62
63
  }
63
- async toJSON() {
64
- return {
65
- ...this.toObject(),
66
- url: await this.getUrl(),
67
- signedUrl: await this.getSignedUrl(),
68
- };
64
+ toJSON() {
65
+ if (this.url) {
66
+ return {
67
+ ...this.toObject(),
68
+ url: this.url
69
+ };
70
+ }
71
+ return this.toObject();
69
72
  }
70
73
  }
@@ -42,7 +42,7 @@ export const attachment = (options) => {
42
42
  }
43
43
  },
44
44
  prepare: (value) => (value ? JSON.stringify(value.toObject()) : null),
45
- serialize: async (value) => (value ? await value.toJSON() : null),
45
+ serialize: (value) => (value ? value.toJSON() : null),
46
46
  ...columnOptions,
47
47
  });
48
48
  };
@@ -68,6 +68,126 @@ export declare const Attachmentable: <Model extends NormalizeConstructor<typeof
68
68
  toJSON(): import("@adonisjs/lucid/types/model").ModelObject;
69
69
  related<Name_2 extends undefined>(relation: Name_2): any[Name_2] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? any[Name_2]["client"] : never;
70
70
  };
71
+ afterFindHook(modelInstance: {
72
+ $attachments: AttributeOfModelWithAttachment;
73
+ $attributes: import("@adonisjs/lucid/types/model").ModelObject;
74
+ $extras: import("@adonisjs/lucid/types/model").ModelObject;
75
+ $original: import("@adonisjs/lucid/types/model").ModelObject;
76
+ $preloaded: {
77
+ [relation: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
78
+ };
79
+ $columns: undefined;
80
+ $sideloaded: import("@adonisjs/lucid/types/model").ModelObject;
81
+ $primaryKeyValue?: number | string;
82
+ $isPersisted: boolean;
83
+ $isNew: boolean;
84
+ $isLocal: boolean;
85
+ $dirty: import("@adonisjs/lucid/types/model").ModelObject;
86
+ $isDirty: boolean;
87
+ $isDeleted: boolean;
88
+ $options?: import("@adonisjs/lucid/types/model").ModelOptions;
89
+ $trx?: import("@adonisjs/lucid/types/database").TransactionClientContract;
90
+ $setOptionsAndTrx(options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions): void;
91
+ useTransaction(trx: import("@adonisjs/lucid/types/database").TransactionClientContract): any;
92
+ useConnection(connection: string): any;
93
+ $getQueryFor(action: "insert", client: import("@adonisjs/lucid/types/database").QueryClientContract): ReturnType<import("@adonisjs/lucid/types/database").QueryClientContract["insertQuery"]>;
94
+ $getQueryFor(action: "update" | "delete" | "refresh", client: import("@adonisjs/lucid/types/database").QueryClientContract): import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel>;
95
+ $setAttribute(key: string, value: any): void;
96
+ $getAttribute(key: string): any;
97
+ $getAttributeFromCache(key: string, callback: import("@adonisjs/lucid/types/model").CacheNode["getter"]): any;
98
+ $hasRelated(key: string): boolean;
99
+ $setRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
100
+ $pushRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
101
+ $getRelated(key: string, defaultValue?: any): import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | undefined | null;
102
+ $consumeAdapterResult(adapterResult: import("@adonisjs/lucid/types/model").ModelObject, sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject): void;
103
+ $hydrateOriginals(): void;
104
+ fill(value: Partial<{
105
+ $attachments: AttributeOfModelWithAttachment;
106
+ }>, allowExtraProperties?: boolean): any;
107
+ merge(value: Partial<{
108
+ $attachments: AttributeOfModelWithAttachment;
109
+ }>, allowExtraProperties?: boolean): any;
110
+ enableForceUpdate(): any;
111
+ save(): Promise<any>;
112
+ lockForUpdate<T>(callback: (user: any) => T | Promise<T>): Promise<T>;
113
+ delete(): Promise<void>;
114
+ refresh(): Promise<any>;
115
+ load: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
116
+ preload: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
117
+ loadAggregate: <Self extends any, Name extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self>, RelatedBuilder = Self[Name] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self[Name]["subQuery"] : never>(name: Name, callback: (builder: RelatedBuilder) => void) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self>;
118
+ loadCount: <Self extends any, Name_1 extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self>, RelatedBuilder_1 = Self[Name_1] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self[Name_1]["subQuery"] : never>(name: Name_1, callback?: ((builder: RelatedBuilder_1) => void) | undefined) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self>;
119
+ serializeAttributes(fields?: import("@adonisjs/lucid/types/model").CherryPickFields, raw?: boolean): import("@adonisjs/lucid/types/model").ModelObject;
120
+ serializeComputed(fields?: import("@adonisjs/lucid/types/model").CherryPickFields): import("@adonisjs/lucid/types/model").ModelObject;
121
+ serializeRelations(fields: undefined, raw: true): {
122
+ [key: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
123
+ };
124
+ serializeRelations(cherryPick: import("@adonisjs/lucid/types/model").CherryPick["relations"] | undefined, raw: false | undefined): import("@adonisjs/lucid/types/model").ModelObject;
125
+ serializeRelations(cherryPick?: import("@adonisjs/lucid/types/model").CherryPick["relations"], raw?: boolean): import("@adonisjs/lucid/types/model").ModelObject;
126
+ serialize(cherryPick?: import("@adonisjs/lucid/types/model").CherryPick): import("@adonisjs/lucid/types/model").ModelObject;
127
+ toObject(): import("@adonisjs/lucid/types/model").ModelObject;
128
+ toJSON(): import("@adonisjs/lucid/types/model").ModelObject;
129
+ related<Name_2 extends undefined>(relation: Name_2): any[Name_2] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? any[Name_2]["client"] : never;
130
+ }): Promise<void>;
131
+ afterFetchHook(modelInstances: {
132
+ $attachments: AttributeOfModelWithAttachment;
133
+ $attributes: import("@adonisjs/lucid/types/model").ModelObject;
134
+ $extras: import("@adonisjs/lucid/types/model").ModelObject;
135
+ $original: import("@adonisjs/lucid/types/model").ModelObject;
136
+ $preloaded: {
137
+ [relation: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
138
+ };
139
+ $columns: undefined;
140
+ $sideloaded: import("@adonisjs/lucid/types/model").ModelObject;
141
+ $primaryKeyValue?: number | string;
142
+ $isPersisted: boolean;
143
+ $isNew: boolean;
144
+ $isLocal: boolean;
145
+ $dirty: import("@adonisjs/lucid/types/model").ModelObject;
146
+ $isDirty: boolean;
147
+ $isDeleted: boolean;
148
+ $options?: import("@adonisjs/lucid/types/model").ModelOptions;
149
+ $trx?: import("@adonisjs/lucid/types/database").TransactionClientContract;
150
+ $setOptionsAndTrx(options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions): void;
151
+ useTransaction(trx: import("@adonisjs/lucid/types/database").TransactionClientContract): any;
152
+ useConnection(connection: string): any;
153
+ $getQueryFor(action: "insert", client: import("@adonisjs/lucid/types/database").QueryClientContract): ReturnType<import("@adonisjs/lucid/types/database").QueryClientContract["insertQuery"]>;
154
+ $getQueryFor(action: "update" | "delete" | "refresh", client: import("@adonisjs/lucid/types/database").QueryClientContract): import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel>;
155
+ $setAttribute(key: string, value: any): void;
156
+ $getAttribute(key: string): any;
157
+ $getAttributeFromCache(key: string, callback: import("@adonisjs/lucid/types/model").CacheNode["getter"]): any;
158
+ $hasRelated(key: string): boolean;
159
+ $setRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
160
+ $pushRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
161
+ $getRelated(key: string, defaultValue?: any): import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | undefined | null;
162
+ $consumeAdapterResult(adapterResult: import("@adonisjs/lucid/types/model").ModelObject, sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject): void;
163
+ $hydrateOriginals(): void;
164
+ fill(value: Partial<{
165
+ $attachments: AttributeOfModelWithAttachment;
166
+ }>, allowExtraProperties?: boolean): any;
167
+ merge(value: Partial<{
168
+ $attachments: AttributeOfModelWithAttachment;
169
+ }>, allowExtraProperties?: boolean): any;
170
+ enableForceUpdate(): any;
171
+ save(): Promise<any>;
172
+ lockForUpdate<T>(callback: (user: any) => T | Promise<T>): Promise<T>;
173
+ delete(): Promise<void>;
174
+ refresh(): Promise<any>;
175
+ load: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
176
+ preload: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
177
+ loadAggregate: <Self extends any, Name extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self>, RelatedBuilder = Self[Name] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self[Name]["subQuery"] : never>(name: Name, callback: (builder: RelatedBuilder) => void) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self>;
178
+ loadCount: <Self extends any, Name_1 extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self>, RelatedBuilder_1 = Self[Name_1] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self[Name_1]["subQuery"] : never>(name: Name_1, callback?: ((builder: RelatedBuilder_1) => void) | undefined) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self>;
179
+ serializeAttributes(fields?: import("@adonisjs/lucid/types/model").CherryPickFields, raw?: boolean): import("@adonisjs/lucid/types/model").ModelObject;
180
+ serializeComputed(fields?: import("@adonisjs/lucid/types/model").CherryPickFields): import("@adonisjs/lucid/types/model").ModelObject;
181
+ serializeRelations(fields: undefined, raw: true): {
182
+ [key: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
183
+ };
184
+ serializeRelations(cherryPick: import("@adonisjs/lucid/types/model").CherryPick["relations"] | undefined, raw: false | undefined): import("@adonisjs/lucid/types/model").ModelObject;
185
+ serializeRelations(cherryPick?: import("@adonisjs/lucid/types/model").CherryPick["relations"], raw?: boolean): import("@adonisjs/lucid/types/model").ModelObject;
186
+ serialize(cherryPick?: import("@adonisjs/lucid/types/model").CherryPick): import("@adonisjs/lucid/types/model").ModelObject;
187
+ toObject(): import("@adonisjs/lucid/types/model").ModelObject;
188
+ toJSON(): import("@adonisjs/lucid/types/model").ModelObject;
189
+ related<Name_2 extends undefined>(relation: Name_2): any[Name_2] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? any[Name_2]["client"] : never;
190
+ }[]): Promise<void>;
71
191
  beforeSaveHook(modelInstance: {
72
192
  $attachments: AttributeOfModelWithAttachment;
73
193
  $attributes: import("@adonisjs/lucid/types/model").ModelObject;
@@ -10,13 +10,22 @@ 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 } from '@adonisjs/lucid/orm';
14
- import { persistAttachment, commit, rollback, generateVariants } from '../utils/actions.js';
13
+ import { beforeSave, afterSave, beforeDelete, afterFind, afterFetch, afterPaginate } from '@adonisjs/lucid/orm';
14
+ import { persistAttachment, commit, rollback, generateVariants, computeUrl } from '../utils/actions.js';
15
15
  import { clone, getAttachmentAttributeNames } 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 {
19
19
  $attachments = clone(defaultStateAttributeMixin);
20
+ static async afterFindHook(modelInstance) {
21
+ const attachmentAttributeNames = getAttachmentAttributeNames(modelInstance);
22
+ await Promise.all(attachmentAttributeNames.map((attributeName) => {
23
+ return computeUrl(modelInstance, attributeName);
24
+ }));
25
+ }
26
+ static async afterFetchHook(modelInstances) {
27
+ await Promise.all(modelInstances.map((row) => this.afterFindHook(row)));
28
+ }
20
29
  static async beforeSaveHook(modelInstance) {
21
30
  const attachmentAttributeNames = getAttachmentAttributeNames(modelInstance);
22
31
  /**
@@ -85,6 +94,13 @@ export const Attachmentable = (superclass) => {
85
94
  }
86
95
  }
87
96
  }
97
+ __decorate([
98
+ afterFind()
99
+ ], ModelWithAttachment, "afterFindHook", null);
100
+ __decorate([
101
+ afterFetch(),
102
+ afterPaginate()
103
+ ], ModelWithAttachment, "afterFetchHook", null);
88
104
  __decorate([
89
105
  beforeSave()
90
106
  ], ModelWithAttachment, "beforeSaveHook", null);
@@ -18,13 +18,14 @@ export type AttachmentBase = {
18
18
  meta?: Exif;
19
19
  folder?: string;
20
20
  path?: string;
21
+ url?: string;
21
22
  options?: LucidOptions;
22
23
  getDisk(): Disk;
23
24
  getUrl(): Promise<string>;
24
25
  getSignedUrl(signedUrlOptions?: SignedURLOptions): Promise<string>;
25
26
  setOptions(options: LucidOptions): AttachmentBase;
26
27
  toObject(): AttachmentBaseAttributes;
27
- toJSON(): Promise<Object>;
28
+ toJSON(): Object;
28
29
  };
29
30
  export type Attachment = AttachmentBase & {
30
31
  originalName: string;
@@ -43,6 +44,7 @@ export type Variant = AttachmentBase & {
43
44
  export type LucidOptions = {
44
45
  disk?: string;
45
46
  folder?: string;
47
+ preComputeUrl?: boolean;
46
48
  variants?: string[];
47
49
  rename?: boolean;
48
50
  meta?: boolean;
@@ -14,9 +14,10 @@ export declare function commit(modelInstance: ModelWithAttachment): Promise<void
14
14
  */
15
15
  export declare function rollback(modelInstance: ModelWithAttachment): Promise<void>;
16
16
  /**
17
- * Persist attachment for a given attachment property
17
+ * Persist attachment for a given attachment attributeName
18
18
  */
19
- export declare function persistAttachment(modelInstance: ModelWithAttachment, property: string): Promise<void>;
19
+ export declare function persistAttachment(modelInstance: ModelWithAttachment, attributeName: string): Promise<void>;
20
+ export declare function computeUrl(modelInstance: ModelWithAttachment, attributeName: string): Promise<void>;
20
21
  /**
21
22
  * Launch converter by variant option
22
23
  */
@@ -20,14 +20,14 @@ export async function rollback(modelInstance) {
20
20
  await Promise.allSettled(modelInstance.$attachments.attached.map((attachment) => attachmentManager.delete(attachment)));
21
21
  }
22
22
  /**
23
- * Persist attachment for a given attachment property
23
+ * Persist attachment for a given attachment attributeName
24
24
  */
25
- export async function persistAttachment(modelInstance, property) {
26
- const existingFile = modelInstance.$original[property];
27
- const newFile = modelInstance.$attributes[property];
28
- const options = getOptions(modelInstance, property);
25
+ export async function persistAttachment(modelInstance, attributeName) {
26
+ const existingFile = modelInstance.$original[attributeName];
27
+ const newFile = modelInstance.$attributes[attributeName];
28
+ const options = getOptions(modelInstance, attributeName);
29
29
  /**
30
- * Skip when the attachment property hasn't been updated
30
+ * Skip when the attachment attributeName hasn't been updated
31
31
  */
32
32
  if (existingFile === newFile) {
33
33
  return;
@@ -62,6 +62,12 @@ export async function persistAttachment(modelInstance, property) {
62
62
  await attachmentManager.save(newFile);
63
63
  }
64
64
  }
65
+ export async function computeUrl(modelInstance, attributeName) {
66
+ const attachment = modelInstance.$attributes[attributeName];
67
+ const options = getOptions(modelInstance, attributeName);
68
+ attachment.setOptions(options);
69
+ return attachmentManager.computeUrl(attachment);
70
+ }
65
71
  /**
66
72
  * Launch converter by variant option
67
73
  */
@@ -7,6 +7,7 @@
7
7
  export declare const defaultOptionsDecorator: {
8
8
  disk: undefined;
9
9
  folder: string;
10
+ preComputeUrl: boolean;
10
11
  variants: never[];
11
12
  rename: boolean;
12
13
  meta: boolean;
@@ -7,6 +7,7 @@
7
7
  export const defaultOptionsDecorator = {
8
8
  disk: undefined,
9
9
  folder: 'uploads',
10
+ preComputeUrl: false,
10
11
  variants: [],
11
12
  rename: true,
12
13
  meta: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrmc/adonis-attachment",
3
- "version": "2.1.0",
3
+ "version": "2.1.1-1",
4
4
  "type": "module",
5
5
  "description": "Turn any field on your Lucid model to an attachment data type",
6
6
  "engines": {
@@ -82,7 +82,7 @@
82
82
  "prettier": "@adonisjs/prettier-config",
83
83
  "publishConfig": {
84
84
  "access": "public",
85
- "tag": "latest"
85
+ "tag": "beta"
86
86
  },
87
87
  "volta": {
88
88
  "node": "20.17.0"