@orion-js/file-manager 3.7.4 → 3.7.6
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/globalConfig.json +1 -0
- package/jest.config.js +10 -0
- package/lib/File/index.d.ts +2 -1
- package/lib/File/index.js +7 -5
- package/lib/File/index.test.d.ts +1 -0
- package/lib/File/index.test.js +109 -0
- package/lib/File/resolvers/index.d.ts +1 -1
- package/lib/File/resolvers/url.d.ts +3 -1
- package/lib/File/resolvers/url.js +12 -7
- package/lib/File/schema.d.ts +13 -3
- package/lib/File/schema.js +63 -44
- package/lib/Files/index.d.ts +3 -2
- package/lib/Files/index.js +4 -1
- package/lib/credentials.d.ts +3 -3
- package/lib/credentials.js +5 -3
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5 -3
- package/lib/resolvers/completeUpload.d.ts +1 -1
- package/lib/resolvers/completeUpload.js +3 -3
- package/lib/resolvers/fileManagerFile.d.ts +1 -1
- package/lib/resolvers/fileManagerFile.js +2 -2
- package/lib/resolvers/fileManagerFiles.js +2 -2
- package/lib/resolvers/generateUploadCredentials.d.ts +1 -1
- package/lib/resolvers/generateUploadCredentials.js +2 -2
- package/lib/resolvers/index.d.ts +3 -3
- package/lib/tests/setup.d.ts +1 -0
- package/lib/tests/setup.js +19 -0
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mongoUri":"mongodb://127.0.0.1:53531/"}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: '@shelf/jest-mongodb',
|
|
3
|
+
roots: ['./src'],
|
|
4
|
+
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
|
|
5
|
+
transform: {
|
|
6
|
+
'^.+\\.(ts|tsx)$': 'ts-jest'
|
|
7
|
+
},
|
|
8
|
+
setupFilesAfterEnv: ['./src/tests/setup.ts'],
|
|
9
|
+
verbose: true
|
|
10
|
+
}
|
package/lib/File/index.d.ts
CHANGED
package/lib/File/index.js
CHANGED
|
@@ -4,23 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const models_1 = require("@orion-js/models");
|
|
7
|
-
const Files_1 =
|
|
7
|
+
const Files_1 = require("../Files");
|
|
8
8
|
const pick_1 = __importDefault(require("lodash/pick"));
|
|
9
9
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
10
|
-
const schema_1 =
|
|
10
|
+
const schema_1 = require("./schema");
|
|
11
|
+
const typed_model_1 = require("@orion-js/typed-model");
|
|
12
|
+
const schema = (0, typed_model_1.getModelForClass)(schema_1.FileSchema).getSchema();
|
|
11
13
|
exports.default = (0, models_1.createModel)({
|
|
12
14
|
name: 'File',
|
|
13
|
-
schema:
|
|
15
|
+
schema: schema,
|
|
14
16
|
resolvers: () => require('./resolvers'),
|
|
15
17
|
// this is only called when its child
|
|
16
18
|
async clean(value) {
|
|
17
19
|
if (!value)
|
|
18
20
|
return null;
|
|
19
21
|
const fileId = value._id;
|
|
20
|
-
const file = await Files_1.
|
|
22
|
+
const file = await Files_1.Files.findOne({ _id: fileId });
|
|
21
23
|
if (!file)
|
|
22
24
|
return null;
|
|
23
|
-
const keys = Object.keys((0, omit_1.default)(
|
|
25
|
+
const keys = Object.keys((0, omit_1.default)(schema, 'createdBy', 'createdAt', 'status'));
|
|
24
26
|
const data = (0, pick_1.default)(file, keys);
|
|
25
27
|
return data;
|
|
26
28
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const _1 = __importDefault(require("."));
|
|
16
|
+
const Files_1 = require("../Files");
|
|
17
|
+
const models_1 = require("@orion-js/models");
|
|
18
|
+
const typed_model_1 = require("@orion-js/typed-model");
|
|
19
|
+
const schema_1 = require("./schema");
|
|
20
|
+
describe('File model', () => {
|
|
21
|
+
it('should correctly clean on a simple file input', async () => {
|
|
22
|
+
await Files_1.Files.insertOne({
|
|
23
|
+
_id: '1',
|
|
24
|
+
externalUrl: 'https://example.com/file.jpg'
|
|
25
|
+
});
|
|
26
|
+
const input = {
|
|
27
|
+
name: 'test',
|
|
28
|
+
image: {
|
|
29
|
+
_id: '1'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const model = (0, models_1.createModel)({
|
|
33
|
+
name: 'Test',
|
|
34
|
+
schema: {
|
|
35
|
+
name: {
|
|
36
|
+
type: String
|
|
37
|
+
},
|
|
38
|
+
image: {
|
|
39
|
+
type: _1.default
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const cleaned = await model.clean(input);
|
|
44
|
+
expect(cleaned).toEqual({
|
|
45
|
+
name: 'test',
|
|
46
|
+
image: {
|
|
47
|
+
_id: '1',
|
|
48
|
+
externalUrl: 'https://example.com/file.jpg'
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should correctly clean the file input on a complex schema', async () => {
|
|
53
|
+
await Files_1.Files.insertOne({
|
|
54
|
+
_id: '2',
|
|
55
|
+
externalUrl: 'https://example.com/file.jpg'
|
|
56
|
+
});
|
|
57
|
+
let Banner = class Banner {
|
|
58
|
+
};
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, typed_model_1.Prop)({
|
|
61
|
+
type: _1.default
|
|
62
|
+
}),
|
|
63
|
+
__metadata("design:type", schema_1.FileSchema)
|
|
64
|
+
], Banner.prototype, "image", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typed_model_1.Prop)(),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], Banner.prototype, "name", void 0);
|
|
69
|
+
Banner = __decorate([
|
|
70
|
+
(0, typed_model_1.TypedSchema)()
|
|
71
|
+
], Banner);
|
|
72
|
+
const cleanedBanner = await (0, typed_model_1.getModelForClass)(Banner).clean({
|
|
73
|
+
name: 'test',
|
|
74
|
+
image: {
|
|
75
|
+
_id: '2'
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
expect(cleanedBanner).toEqual({
|
|
79
|
+
name: 'test',
|
|
80
|
+
image: {
|
|
81
|
+
_id: '2',
|
|
82
|
+
externalUrl: 'https://example.com/file.jpg'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
let Config = class Config {
|
|
86
|
+
};
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, typed_model_1.Prop)({ type: [(0, typed_model_1.getModelForClass)(Banner)] }),
|
|
89
|
+
__metadata("design:type", Array)
|
|
90
|
+
], Config.prototype, "banners", void 0);
|
|
91
|
+
Config = __decorate([
|
|
92
|
+
(0, typed_model_1.TypedSchema)()
|
|
93
|
+
], Config);
|
|
94
|
+
const cleaned = await (0, typed_model_1.getModelForClass)(Config).cleanAndValidate({
|
|
95
|
+
banners: [cleanedBanner]
|
|
96
|
+
});
|
|
97
|
+
expect(cleaned).toEqual({
|
|
98
|
+
banners: [
|
|
99
|
+
{
|
|
100
|
+
name: 'test',
|
|
101
|
+
image: {
|
|
102
|
+
_id: '2',
|
|
103
|
+
externalUrl: 'https://example.com/file.jpg'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
url: import("@orion-js/resolvers").ModelResolver<(file: any
|
|
2
|
+
url: import("@orion-js/resolvers").ModelResolver<(file: any) => Promise<string>>;
|
|
3
3
|
genericType: import("@orion-js/resolvers").ModelResolver<(file: any, viewer: any) => Promise<"unknown" | "image" | "pdf">>;
|
|
4
4
|
};
|
|
5
5
|
export default _default;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { FileSchema } from '../schema';
|
|
2
|
+
export declare function getFileURL(file: FileSchema): string;
|
|
3
|
+
declare const _default: import("@orion-js/resolvers").ModelResolver<(file: any) => Promise<string>>;
|
|
2
4
|
export default _default;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileURL = void 0;
|
|
3
4
|
const resolvers_1 = require("@orion-js/resolvers");
|
|
4
5
|
const credentials_1 = require("../../credentials");
|
|
6
|
+
function getFileURL(file) {
|
|
7
|
+
if (file.externalUrl)
|
|
8
|
+
return file.externalUrl;
|
|
9
|
+
const options = (0, credentials_1.getAWSCredentials)();
|
|
10
|
+
if (options.getFileURL)
|
|
11
|
+
return options.getFileURL(file);
|
|
12
|
+
return `https://s3.amazonaws.com/${file.bucket}/${encodeURIComponent(file.key)}`;
|
|
13
|
+
}
|
|
14
|
+
exports.getFileURL = getFileURL;
|
|
5
15
|
exports.default = (0, resolvers_1.modelResolver)({
|
|
6
16
|
returns: String,
|
|
7
|
-
async resolve(file
|
|
8
|
-
|
|
9
|
-
return file.externalUrl;
|
|
10
|
-
const options = (0, credentials_1.getAWSCredentials)();
|
|
11
|
-
if (options.getFileURL)
|
|
12
|
-
return options.getFileURL(file);
|
|
13
|
-
return `https://s3.amazonaws.com/${file.bucket}/${encodeURIComponent(file.key)}`;
|
|
17
|
+
async resolve(file) {
|
|
18
|
+
return getFileURL(file);
|
|
14
19
|
}
|
|
15
20
|
});
|
package/lib/File/schema.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare class FileSchema {
|
|
2
|
+
_id: string;
|
|
3
|
+
hash?: string;
|
|
4
|
+
externalUrl?: string;
|
|
5
|
+
key?: string;
|
|
6
|
+
bucket?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
size?: number;
|
|
10
|
+
status?: string;
|
|
11
|
+
createdBy?: string;
|
|
12
|
+
createdAt?: Date;
|
|
13
|
+
}
|
package/lib/File/schema.js
CHANGED
|
@@ -1,49 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
exports.FileSchema = void 0;
|
|
13
|
+
const typed_model_1 = require("@orion-js/typed-model");
|
|
14
|
+
let FileSchema = class FileSchema {
|
|
15
|
+
};
|
|
16
|
+
__decorate([
|
|
17
|
+
(0, typed_model_1.Prop)({ type: 'ID' }),
|
|
18
|
+
__metadata("design:type", String)
|
|
19
|
+
], FileSchema.prototype, "_id", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, typed_model_1.Prop)({
|
|
9
22
|
optional: true
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
}),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], FileSchema.prototype, "hash", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typed_model_1.Prop)({
|
|
13
28
|
optional: true,
|
|
14
29
|
private: true
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
type
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
}),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], FileSchema.prototype, "externalUrl", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], FileSchema.prototype, "key", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], FileSchema.prototype, "bucket", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], FileSchema.prototype, "name", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], FileSchema.prototype, "type", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], FileSchema.prototype, "size", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], FileSchema.prototype, "status", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], FileSchema.prototype, "createdBy", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typed_model_1.Prop)({ optional: true }),
|
|
63
|
+
__metadata("design:type", Date)
|
|
64
|
+
], FileSchema.prototype, "createdAt", void 0);
|
|
65
|
+
FileSchema = __decorate([
|
|
66
|
+
(0, typed_model_1.TypedSchema)()
|
|
67
|
+
], FileSchema);
|
|
68
|
+
exports.FileSchema = FileSchema;
|
package/lib/Files/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Collection } from '@orion-js/mongodb';
|
|
2
|
+
import { FileSchema } from '../File/schema';
|
|
3
|
+
export declare const Files: Collection<FileSchema>;
|
package/lib/Files/index.js
CHANGED
|
@@ -3,11 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Files = void 0;
|
|
6
7
|
const mongodb_1 = require("@orion-js/mongodb");
|
|
7
8
|
const File_1 = __importDefault(require("../File"));
|
|
8
|
-
|
|
9
|
+
const schema_1 = require("../File/schema");
|
|
10
|
+
exports.Files = (0, mongodb_1.createCollection)({
|
|
9
11
|
name: 'filemanager_files',
|
|
10
12
|
model: File_1.default,
|
|
13
|
+
schema: schema_1.FileSchema,
|
|
11
14
|
indexes: [
|
|
12
15
|
{
|
|
13
16
|
keys: {
|
package/lib/credentials.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface FileManagerOptions {
|
|
2
2
|
accessKeyId: string;
|
|
3
3
|
secretAccessKey: string;
|
|
4
4
|
region: string;
|
|
@@ -9,5 +9,5 @@ export interface Credentials {
|
|
|
9
9
|
endpoint?: string;
|
|
10
10
|
s3ForcePathStyle?: boolean;
|
|
11
11
|
}
|
|
12
|
-
export declare const setupFileManager: (options:
|
|
13
|
-
export declare const getAWSCredentials: () => Partial<
|
|
12
|
+
export declare const setupFileManager: (options: FileManagerOptions) => void;
|
|
13
|
+
export declare const getAWSCredentials: () => Partial<FileManagerOptions>;
|
package/lib/credentials.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAWSCredentials = exports.setupFileManager = void 0;
|
|
4
|
-
let
|
|
5
|
-
const setupFileManager = options =>
|
|
4
|
+
let savedOptions = {};
|
|
5
|
+
const setupFileManager = (options) => {
|
|
6
|
+
savedOptions = options;
|
|
7
|
+
};
|
|
6
8
|
exports.setupFileManager = setupFileManager;
|
|
7
|
-
const getAWSCredentials = () =>
|
|
9
|
+
const getAWSCredentials = () => savedOptions;
|
|
8
10
|
exports.getAWSCredentials = getAWSCredentials;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import resolvers from './resolvers';
|
|
2
2
|
import { setupFileManager, getAWSCredentials } from './credentials';
|
|
3
3
|
import File from './File';
|
|
4
|
-
import Files from './Files';
|
|
5
|
-
|
|
4
|
+
import { Files } from './Files';
|
|
5
|
+
import { getFileURL } from './File/resolvers/url';
|
|
6
|
+
export { resolvers, setupFileManager, getAWSCredentials, File, Files, getFileURL };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Files = exports.File = exports.getAWSCredentials = exports.setupFileManager = exports.resolvers = void 0;
|
|
6
|
+
exports.getFileURL = exports.Files = exports.File = exports.getAWSCredentials = exports.setupFileManager = exports.resolvers = void 0;
|
|
7
7
|
const resolvers_1 = __importDefault(require("./resolvers"));
|
|
8
8
|
exports.resolvers = resolvers_1.default;
|
|
9
9
|
const credentials_1 = require("./credentials");
|
|
@@ -11,5 +11,7 @@ Object.defineProperty(exports, "setupFileManager", { enumerable: true, get: func
|
|
|
11
11
|
Object.defineProperty(exports, "getAWSCredentials", { enumerable: true, get: function () { return credentials_1.getAWSCredentials; } });
|
|
12
12
|
const File_1 = __importDefault(require("./File"));
|
|
13
13
|
exports.File = File_1.default;
|
|
14
|
-
const Files_1 =
|
|
15
|
-
exports
|
|
14
|
+
const Files_1 = require("./Files");
|
|
15
|
+
Object.defineProperty(exports, "Files", { enumerable: true, get: function () { return Files_1.Files; } });
|
|
16
|
+
const url_1 = require("./File/resolvers/url");
|
|
17
|
+
Object.defineProperty(exports, "getFileURL", { enumerable: true, get: function () { return url_1.getFileURL; } });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<
|
|
1
|
+
declare const _default: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<import("../File/schema").FileSchema>, undefined>;
|
|
2
2
|
export default _default;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const resolvers_1 = require("@orion-js/resolvers");
|
|
7
7
|
const File_1 = __importDefault(require("../File"));
|
|
8
|
-
const Files_1 =
|
|
8
|
+
const Files_1 = require("../Files");
|
|
9
9
|
exports.default = (0, resolvers_1.resolver)({
|
|
10
10
|
params: {
|
|
11
11
|
fileId: {
|
|
@@ -15,8 +15,8 @@ exports.default = (0, resolvers_1.resolver)({
|
|
|
15
15
|
returns: File_1.default,
|
|
16
16
|
mutation: true,
|
|
17
17
|
async resolve({ fileId }, viewer) {
|
|
18
|
-
const file = await Files_1.
|
|
19
|
-
await Files_1.
|
|
18
|
+
const file = await Files_1.Files.findOne({ createdBy: viewer.userId, _id: fileId });
|
|
19
|
+
await Files_1.Files.updateOne(file, { $set: { status: 'uploaded' } });
|
|
20
20
|
return file;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("@orion-js/resolvers").Resolver<({ fileId }: any) => Promise<
|
|
1
|
+
declare const _default: import("@orion-js/resolvers").Resolver<({ fileId }: any) => Promise<import("../File/schema").FileSchema>, undefined>;
|
|
2
2
|
export default _default;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const resolvers_1 = require("@orion-js/resolvers");
|
|
7
7
|
const File_1 = __importDefault(require("../File"));
|
|
8
|
-
const Files_1 =
|
|
8
|
+
const Files_1 = require("../Files");
|
|
9
9
|
exports.default = (0, resolvers_1.resolver)({
|
|
10
10
|
params: {
|
|
11
11
|
fileId: {
|
|
@@ -14,6 +14,6 @@ exports.default = (0, resolvers_1.resolver)({
|
|
|
14
14
|
},
|
|
15
15
|
returns: File_1.default,
|
|
16
16
|
async resolve({ fileId }) {
|
|
17
|
-
return await Files_1.
|
|
17
|
+
return await Files_1.Files.findOne(fileId);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const paginated_mongodb_1 = require("@orion-js/paginated-mongodb");
|
|
7
7
|
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
|
8
8
|
const File_1 = __importDefault(require("../File"));
|
|
9
|
-
const Files_1 =
|
|
9
|
+
const Files_1 = require("../Files");
|
|
10
10
|
const fileManagerFiles = (0, paginated_mongodb_1.paginatedResolver)({
|
|
11
11
|
params: {
|
|
12
12
|
filter: {
|
|
@@ -21,7 +21,7 @@ const fileManagerFiles = (0, paginated_mongodb_1.paginatedResolver)({
|
|
|
21
21
|
if (filter) {
|
|
22
22
|
query.name = { $regex: new RegExp(`^${(0, escape_string_regexp_1.default)(filter)}`) };
|
|
23
23
|
}
|
|
24
|
-
return Files_1.
|
|
24
|
+
return Files_1.Files.find(query);
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
exports.default = fileManagerFiles;
|
|
@@ -8,7 +8,7 @@ const helpers_1 = require("@orion-js/helpers");
|
|
|
8
8
|
const models_1 = require("@orion-js/models");
|
|
9
9
|
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
10
10
|
const credentials_1 = require("../credentials");
|
|
11
|
-
const Files_1 =
|
|
11
|
+
const Files_1 = require("../Files");
|
|
12
12
|
exports.default = (0, resolvers_1.resolver)({
|
|
13
13
|
params: {
|
|
14
14
|
name: {
|
|
@@ -53,7 +53,7 @@ exports.default = (0, resolvers_1.resolver)({
|
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
55
|
const key = `${basePath}/${(0, helpers_1.generateId)()}-${params.name}`;
|
|
56
|
-
const fileId = await Files_1.
|
|
56
|
+
const fileId = await Files_1.Files.insertOne({
|
|
57
57
|
key,
|
|
58
58
|
bucket,
|
|
59
59
|
name: params.name,
|
package/lib/resolvers/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
fileManagerFile: import("@orion-js/resolvers").Resolver<({ fileId }: any) => Promise<
|
|
2
|
+
fileManagerFile: import("@orion-js/resolvers").Resolver<({ fileId }: any) => Promise<import("../File/schema").FileSchema>, undefined>;
|
|
3
3
|
fileManagerFiles: import("@orion-js/resolvers").Resolver<Function, undefined>;
|
|
4
|
-
completeUpload: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<
|
|
4
|
+
completeUpload: import("@orion-js/resolvers").Resolver<({ fileId }: any, viewer: any) => Promise<import("../File/schema").FileSchema>, undefined>;
|
|
5
5
|
generateUploadCredentials: import("@orion-js/resolvers").Resolver<(params: any, viewer: any) => Promise<{
|
|
6
6
|
key: string;
|
|
7
|
-
fileId:
|
|
7
|
+
fileId: string;
|
|
8
8
|
}>, undefined>;
|
|
9
9
|
};
|
|
10
10
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mongodb_1 = require("@orion-js/mongodb");
|
|
4
|
+
const url = `${global.__MONGO_URI__}jest`;
|
|
5
|
+
process.env.MONGO_URL = url;
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
const connection = (0, mongodb_1.getMongoConnection)({ name: 'main' });
|
|
8
|
+
await connection.connectionPromise;
|
|
9
|
+
});
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
/**
|
|
12
|
+
* We need to wait on indexes promises to be resolved to close all the handlers
|
|
13
|
+
*/
|
|
14
|
+
await Promise.all(mongodb_1.createIndexesPromises);
|
|
15
|
+
for (const connectionName in mongodb_1.connections) {
|
|
16
|
+
const connection = mongodb_1.connections[connectionName];
|
|
17
|
+
await connection.client.close();
|
|
18
|
+
}
|
|
19
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/file-manager",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "jest",
|
|
9
9
|
"prepare": "yarn run build",
|
|
10
10
|
"clean": "rm -rf ./lib",
|
|
11
11
|
"build": "yarn run clean && tsc",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@orion-js/helpers": "^3.7.4",
|
|
16
|
-
"@orion-js/models": "^3.7.
|
|
17
|
-
"@orion-js/mongodb": "^3.7.
|
|
18
|
-
"@orion-js/paginated-mongodb": "^3.7.
|
|
16
|
+
"@orion-js/models": "^3.7.6",
|
|
17
|
+
"@orion-js/mongodb": "^3.7.6",
|
|
18
|
+
"@orion-js/paginated-mongodb": "^3.7.6",
|
|
19
19
|
"@orion-js/resolvers": "^3.7.4",
|
|
20
20
|
"@orion-js/schema": "^3.7.4",
|
|
21
21
|
"aws-sdk": "^2.1367.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "c1bb048206f0309f38d32796b0ca5729a2052ec6"
|
|
42
42
|
}
|