@maestro-js/file-storage 1.0.0-alpha.19 → 1.0.0-alpha.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Iso } from 'iso-fns2';
2
2
  import { Readable } from 'node:stream';
3
3
  import { ReadableStream } from 'node:stream/web';
4
+ import { File } from 'node:buffer';
4
5
  import { S3Client } from '@aws-sdk/client-s3';
5
6
 
6
7
  interface Driver<TemporaryUrlParams> {
@@ -30,9 +31,8 @@ interface Driver<TemporaryUrlParams> {
30
31
  removeDirectory(directory: string): Promise<void>;
31
32
  }
32
33
 
33
- declare function createLocalDriver<TemporaryUrlParams>({ pathPrefix, urlPrefix, buildTemporaryUrlsUsing }: {
34
+ declare function createLocalDriver<TemporaryUrlParams>({ pathPrefix, buildTemporaryUrlsUsing }: {
34
35
  pathPrefix?: string;
35
- urlPrefix?: string;
36
36
  buildTemporaryUrlsUsing?(path: string, expiration: Iso.Instant, params?: TemporaryUrlParams): string | Promise<string>;
37
37
  }): Driver<TemporaryUrlParams>;
38
38
 
@@ -43,13 +43,6 @@ declare function createS3Driver({ client, bucket, prefix, url: baseUrl }: {
43
43
  url?: string;
44
44
  }): Driver<void>;
45
45
 
46
- type FileStorageDriver<T = any> = Driver<T>;
47
- interface FileInput {
48
- name: string;
49
- type: string;
50
- stream(): ReadableStream | globalThis.ReadableStream;
51
- }
52
-
53
46
  declare function create(config: FileStorage.Provider.FileStorageServiceConfig): FileStorage.FileStorageService;
54
47
  type KeysWithFallback = keyof FileStorage.Provider.Keys extends never ? {
55
48
  default: unknown;
@@ -76,8 +69,8 @@ declare function provider(key: FileStorage.Provider.Key): {
76
69
  append: (path: string, contents: string | Buffer | Readable | ReadableStream) => Promise<void>;
77
70
  copy: (source: string, destination: string) => Promise<void>;
78
71
  move: (source: string, destination: string) => Promise<void>;
79
- putFileAs: (dir: string, file: FileInput, filename: string) => Promise<string>;
80
- putFile: (dir: string, file: FileInput) => Promise<string>;
72
+ putFileAs: (dir: string, file: File, filename: string) => Promise<string>;
73
+ putFile: (dir: string, file: File) => Promise<string>;
81
74
  remove: (...paths: string[]) => Promise<void>;
82
75
  files: (directory: string) => Promise<string[]>;
83
76
  allFiles: (directory: string) => Promise<string[]>;
@@ -113,8 +106,8 @@ declare const FileStorage: {
113
106
  append: (path: string, contents: string | Buffer | Readable | ReadableStream) => Promise<void>;
114
107
  copy: (source: string, destination: string) => Promise<void>;
115
108
  move: (source: string, destination: string) => Promise<void>;
116
- putFileAs: (dir: string, file: FileInput, filename: string) => Promise<string>;
117
- putFile: (dir: string, file: FileInput) => Promise<string>;
109
+ putFileAs: (dir: string, file: File, filename: string) => Promise<string>;
110
+ putFile: (dir: string, file: File) => Promise<string>;
118
111
  remove: (...paths: string[]) => Promise<void>;
119
112
  files: (directory: string) => Promise<string[]>;
120
113
  allFiles: (directory: string) => Promise<string[]>;
@@ -128,7 +121,7 @@ declare const FileStorage: {
128
121
  };
129
122
  };
130
123
  declare namespace FileStorage {
131
- type Driver<T = any> = FileStorageDriver<T>;
124
+ type Driver<T = any> = Driver<T>;
132
125
  interface FileStorageService {
133
126
  get(path: string): Promise<Buffer>;
134
127
  text(path: string, encoding?: BufferEncoding): Promise<string>;
@@ -151,8 +144,8 @@ declare namespace FileStorage {
151
144
  append(path: string, contents: string | Buffer | Readable | ReadableStream): Promise<void>;
152
145
  copy(source: string, destination: string): Promise<void>;
153
146
  move(source: string, destination: string): Promise<void>;
154
- putFileAs(dir: string, file: FileInput, filename: string): Promise<string>;
155
- putFile(dir: string, file: FileInput): Promise<string>;
147
+ putFileAs(dir: string, file: File, filename: string): Promise<string>;
148
+ putFile(dir: string, file: File): Promise<string>;
156
149
  remove(...paths: string[]): Promise<void>;
157
150
  files(directory: string): Promise<string[]>;
158
151
  allFiles(directory: string): Promise<string[]>;
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import "stream";
9
9
  import "stream/web";
10
10
 
11
11
  // src/index.ts
12
+ import "buffer";
12
13
  import { randomUUID as randomUUID2 } from "crypto";
13
14
  import mimeTypes from "mime-types";
14
15
 
@@ -72,7 +73,6 @@ import stream from "stream";
72
73
  import { lookup } from "mime-types";
73
74
  function createLocalDriver({
74
75
  pathPrefix = "storage",
75
- urlPrefix = "/files",
76
76
  buildTemporaryUrlsUsing
77
77
  }) {
78
78
  return {
@@ -88,7 +88,7 @@ function createLocalDriver({
88
88
  }
89
89
  },
90
90
  url(path) {
91
- return `${urlPrefix}/${path}`;
91
+ return nodePath.join(pathPrefix, path);
92
92
  },
93
93
  async temporaryUrl(path, expiration, params) {
94
94
  if (buildTemporaryUrlsUsing) {
@@ -115,32 +115,24 @@ function createLocalDriver({
115
115
  return nodePath.resolve(nodePath.join(pathPrefix, path));
116
116
  },
117
117
  async put(path, contents) {
118
- const fullPath = nodePath.join(pathPrefix, path);
119
- await fs.mkdir(nodePath.dirname(fullPath), { recursive: true });
120
- await fs.writeFile(fullPath, contents);
118
+ await fs.writeFile(nodePath.join(pathPrefix, path), contents);
121
119
  },
122
120
  async prepend(path, contents) {
123
121
  await prepend(nodePath.join(pathPrefix, path), contents);
124
122
  },
125
123
  async append(path, contents) {
126
- const fullPath = nodePath.join(pathPrefix, path);
127
- await fs.mkdir(nodePath.dirname(fullPath), { recursive: true });
128
124
  if (Buffer.isBuffer(contents) || typeof contents == "string") {
129
- await fs.appendFile(fullPath, contents);
125
+ await fs.appendFile(nodePath.join(pathPrefix, path), contents);
130
126
  } else {
131
- const writeStream2 = createWriteStream(fullPath, { flags: "a" });
127
+ const writeStream2 = createWriteStream(nodePath.join(pathPrefix, path), { flags: "a" });
132
128
  await promiseStream.pipeline(contents, writeStream2);
133
129
  }
134
130
  },
135
131
  async copy(source, destination) {
136
- const destPath = nodePath.join(pathPrefix, destination);
137
- await fs.mkdir(nodePath.dirname(destPath), { recursive: true });
138
- await fs.copyFile(nodePath.join(pathPrefix, source), destPath);
132
+ await fs.copyFile(nodePath.join(pathPrefix, source), nodePath.join(pathPrefix, destination));
139
133
  },
140
134
  async move(source, destination) {
141
- const destPath = nodePath.join(pathPrefix, destination);
142
- await fs.mkdir(nodePath.dirname(destPath), { recursive: true });
143
- await fs.rename(nodePath.join(pathPrefix, source), destPath);
135
+ await fs.rename(nodePath.join(pathPrefix, source), nodePath.join(pathPrefix, destination));
144
136
  },
145
137
  async remove(...paths) {
146
138
  await Promise.all(paths.map((p) => fs.rm(nodePath.join(pathPrefix, p))));
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "default": "./dist/index.js"
8
8
  }
9
9
  },
10
- "version": "1.0.0-alpha.19",
10
+ "version": "1.0.0-alpha.2",
11
11
  "publishConfig": {
12
12
  "access": "restricted"
13
13
  },
@@ -15,17 +15,14 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
+ "@aws-sdk/client-s3": "^3.750.0",
19
+ "@aws-sdk/s3-request-presigner": "^3.750.0",
18
20
  "iso-fns2": "npm:iso-fns@2.0.0-alpha.26",
19
21
  "mime-types": "^2.1.35",
20
- "@maestro-js/service-registry": "1.0.0-alpha.19"
21
- },
22
- "peerDependencies": {
23
- "@aws-sdk/client-s3": "^3.750.0",
24
- "@aws-sdk/s3-request-presigner": "^3.750.0"
22
+ "@maestro-js/service-registry": "1.0.0-alpha.2",
23
+ "@maestro-js/crypt": "1.0.0-alpha.2"
25
24
  },
26
25
  "devDependencies": {
27
- "@aws-sdk/client-s3": "^3.750.0",
28
- "@aws-sdk/s3-request-presigner": "^3.750.0",
29
26
  "@types/node": "^22.19.11",
30
27
  "@types/mime-types": "^2.1.4"
31
28
  },