@proteinjs/db-file 1.1.0
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/.eslintrc.js +20 -0
- package/.prettierignore +4 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/dist/generated/index.d.ts +10 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +42 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/src/DbFileStorageDriver.d.ts +14 -0
- package/dist/src/DbFileStorageDriver.d.ts.map +1 -0
- package/dist/src/DbFileStorageDriver.js +143 -0
- package/dist/src/DbFileStorageDriver.js.map +1 -0
- package/dist/src/FileStorage.d.ts +70 -0
- package/dist/src/FileStorage.d.ts.map +1 -0
- package/dist/src/FileStorage.js +210 -0
- package/dist/src/FileStorage.js.map +1 -0
- package/dist/src/FileStorageDriver.d.ts +9 -0
- package/dist/src/FileStorageDriver.d.ts.map +1 -0
- package/dist/src/FileStorageDriver.js +3 -0
- package/dist/src/FileStorageDriver.js.map +1 -0
- package/dist/src/routes/getFile.d.ts +3 -0
- package/dist/src/routes/getFile.d.ts.map +1 -0
- package/dist/src/routes/getFile.js +86 -0
- package/dist/src/routes/getFile.js.map +1 -0
- package/dist/src/routes/getFileRoute.d.ts +5 -0
- package/dist/src/routes/getFileRoute.d.ts.map +1 -0
- package/dist/src/routes/getFileRoute.js +5 -0
- package/dist/src/routes/getFileRoute.js.map +1 -0
- package/dist/src/services/FileStorageService.d.ts +13 -0
- package/dist/src/services/FileStorageService.d.ts.map +1 -0
- package/dist/src/services/FileStorageService.js +6 -0
- package/dist/src/services/FileStorageService.js.map +1 -0
- package/dist/src/tables/FileDataTable.d.ts +23 -0
- package/dist/src/tables/FileDataTable.d.ts.map +1 -0
- package/dist/src/tables/FileDataTable.js +45 -0
- package/dist/src/tables/FileDataTable.js.map +1 -0
- package/dist/src/tables/FileTable.d.ts +26 -0
- package/dist/src/tables/FileTable.d.ts.map +1 -0
- package/dist/src/tables/FileTable.js +51 -0
- package/dist/src/tables/FileTable.js.map +1 -0
- package/dist/src/tables/tables.d.ts +8 -0
- package/dist/src/tables/tables.d.ts.map +1 -0
- package/dist/src/tables/tables.js +10 -0
- package/dist/src/tables/tables.js.map +1 -0
- package/generated/index.ts +35 -0
- package/index.ts +14 -0
- package/jest.config.js +9 -0
- package/package.json +48 -0
- package/src/DbFileStorageDriver.ts +67 -0
- package/src/FileStorage.ts +128 -0
- package/src/FileStorageDriver.ts +9 -0
- package/src/routes/getFile.ts +33 -0
- package/src/routes/getFileRoute.ts +1 -0
- package/src/services/FileStorageService.ts +14 -0
- package/src/tables/FileDataTable.ts +26 -0
- package/src/tables/FileTable.ts +32 -0
- package/src/tables/tables.ts +8 -0
- package/tsconfig.json +19 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
5
|
+
root: true,
|
|
6
|
+
ignorePatterns: ['**/dist/*', '**/node_modules/*', '*.md'],
|
|
7
|
+
|
|
8
|
+
rules: {
|
|
9
|
+
'prettier/prettier': ['warn'],
|
|
10
|
+
curly: ['warn'],
|
|
11
|
+
'eol-last': ['warn', 'always'],
|
|
12
|
+
'keyword-spacing': ['warn', { before: true }],
|
|
13
|
+
'no-undef': 'off',
|
|
14
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
15
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
16
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
17
|
+
'@typescript-eslint/prefer-as-const': 'off',
|
|
18
|
+
'@typescript-eslint/ban-types': 'off',
|
|
19
|
+
},
|
|
20
|
+
};
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0 (2024-07-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* `getFile` should only work for authenticated users ([97a6e22](https://github.com/proteinjs/db/commit/97a6e22c289c2acb64b31c8c8800fa1b933f5c40))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* added `TableWatcher` api ([1544e28](https://github.com/proteinjs/db/commit/1544e284ad712e2606c82606f2501041f34517cb))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Brent Bahry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Load Dependency Source Graphs */
|
|
2
|
+
import '@proteinjs/db';
|
|
3
|
+
import '@proteinjs/reflection';
|
|
4
|
+
import '@proteinjs/server-api';
|
|
5
|
+
import '@proteinjs/service';
|
|
6
|
+
import '@proteinjs/user';
|
|
7
|
+
import '@proteinjs/util';
|
|
8
|
+
import 'moment';
|
|
9
|
+
export * from '../index';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,eAAe,CAAC;AACvB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AA6BhB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Load Dependency Source Graphs */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
require("@proteinjs/db");
|
|
19
|
+
require("@proteinjs/reflection");
|
|
20
|
+
require("@proteinjs/server-api");
|
|
21
|
+
require("@proteinjs/service");
|
|
22
|
+
require("@proteinjs/user");
|
|
23
|
+
require("@proteinjs/util");
|
|
24
|
+
require("moment");
|
|
25
|
+
/** Generate Source Graph */
|
|
26
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-file/DefaultFileStorageDriverFactory\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"DefaultFileStorageDriverFactory\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/FileStorage.ts\",\"qualifiedName\":\"@proteinjs/db-file/DefaultFileStorageDriverFactory\",\"properties\":[],\"methods\":[{\"name\":\"getDriver\",\"returnType\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageDriver\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-file/FileStorageDriver\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"@proteinjs/db-file/FileStorage\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorage\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/FileStorage.ts\",\"qualifiedName\":\"@proteinjs/db-file/FileStorage\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"defaultDriver\",\"type\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageDriver\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-file/FileStorageDriver\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"driver\",\"type\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageDriver\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-file/FileStorageDriver\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"logger\",\"type\":{\"packageName\":\"@proteinjs/util\",\"name\":\"Logger\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/util/Logger\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceMetadata\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getDefaultDriver\",\"returnType\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageDriver\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-file/FileStorageDriver\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"createFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<File>\",\"filePath\":null,\"qualifiedName\":\"/Promise<File>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileMetaData\",\"type\":{\"packageName\":\"\",\"name\":\"Omit<File, keyof ScopedRecord>\",\"filePath\":null,\"qualifiedName\":\"/Omit<File, keyof ScopedRecord>\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"fileData\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<File>\",\"filePath\":null,\"qualifiedName\":\"/Promise<File>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFileData\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<string>\",\"filePath\":null,\"qualifiedName\":\"/Promise<string>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updateFileData\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"data\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updateFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"file\",\"type\":{\"packageName\":\"\",\"name\":\"Omit<File, keyof ScopedRecord>\",\"filePath\":null,\"qualifiedName\":\"/Omit<File, keyof ScopedRecord>\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"deleteFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageService\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-file/FileStorageService\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/db-file/FileStorageService\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileStorageService\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/services/FileStorageService.ts\",\"qualifiedName\":\"@proteinjs/db-file/FileStorageService\",\"properties\":[],\"methods\":[{\"name\":\"createFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<File>\",\"filePath\":null,\"qualifiedName\":\"/Promise<File>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileMetaData\",\"type\":{\"packageName\":\"\",\"name\":\"Omit<File, keyof ScopedRecord>\",\"filePath\":null,\"qualifiedName\":\"/Omit<File, keyof ScopedRecord>\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"fileData\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<File>\",\"filePath\":null,\"qualifiedName\":\"/Promise<File>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"getFileData\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<string>\",\"filePath\":null,\"qualifiedName\":\"/Promise<string>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updateFileData\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"data\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"updateFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"file\",\"type\":{\"packageName\":\"\",\"name\":\"Omit<File, keyof ScopedRecord>\",\"filePath\":null,\"qualifiedName\":\"/Omit<File, keyof ScopedRecord>\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"deleteFile\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fileId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db-file/getFile\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"getFile\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/routes/getFile.ts\",\"qualifiedName\":\"@proteinjs/db-file/getFile\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/server-api/Route\"},{\"v\":\"@proteinjs/service/Service\"},{\"v\":\"@proteinjs/db-file/FileData\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileData\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/tables/FileDataTable.ts\",\"qualifiedName\":\"@proteinjs/db-file/FileData\",\"properties\":[{\"name\":\"file\",\"type\":{\"packageName\":\"\",\"name\":\"Reference<File>\",\"filePath\":null,\"qualifiedName\":\"/Reference<File>\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"order\",\"type\":{\"packageName\":\"\",\"name\":\"number\",\"filePath\":null,\"qualifiedName\":\"/number\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"data\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/user/ScopedRecord\"},{\"v\":\"@proteinjs/db-file/FileDataTable\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileDataTable\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/tables/FileDataTable.ts\",\"qualifiedName\":\"@proteinjs/db-file/FileDataTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"auth\",\"type\":{\"packageName\":\"\",\"name\":\"Table<FileData>['auth']\",\"filePath\":null,\"qualifiedName\":\"/Table<FileData>['auth']\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/db-file/FileData\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"},{\"v\":\"@proteinjs/db-file/File\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"File\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/tables/FileTable.ts\",\"qualifiedName\":\"@proteinjs/db-file/File\",\"properties\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"type\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"size\",\"type\":{\"packageName\":\"\",\"name\":\"number\",\"filePath\":null,\"qualifiedName\":\"/number\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db-file/FileTable\",\"value\":{\"packageName\":\"@proteinjs/db-file\",\"name\":\"FileTable\",\"filePath\":\"/home/runner/work/db/db/packages/file/src/tables/FileTable.ts\",\"qualifiedName\":\"@proteinjs/db-file/FileTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"auth\",\"type\":{\"packageName\":\"\",\"name\":\"Table<File>['auth']\",\"filePath\":null,\"qualifiedName\":\"/Table<File>['auth']\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"cascadeDeleteReferences\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/db-file/File\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}}],\"edges\":[{\"v\":\"@proteinjs/db-file/DefaultFileStorageDriverFactory\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-file/FileStorage\",\"w\":\"@proteinjs/db-file/FileStorageService\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/db-file/getFile\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"has type\"},{\"v\":\"@proteinjs/db-file/FileStorageService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-file/FileData\",\"w\":\"@proteinjs/user/ScopedRecord\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-file/FileDataTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/db-file/File\",\"w\":\"@proteinjs/user/ScopedRecord\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-file/FileTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
|
|
27
|
+
/** Generate Source Links */
|
|
28
|
+
var FileStorage_1 = require("../src/FileStorage");
|
|
29
|
+
var getFile_1 = require("../src/routes/getFile");
|
|
30
|
+
var FileDataTable_1 = require("../src/tables/FileDataTable");
|
|
31
|
+
var FileTable_1 = require("../src/tables/FileTable");
|
|
32
|
+
var sourceLinks = {
|
|
33
|
+
'@proteinjs/db-file/FileStorage': FileStorage_1.FileStorage,
|
|
34
|
+
'@proteinjs/db-file/getFile': getFile_1.getFile,
|
|
35
|
+
'@proteinjs/db-file/FileDataTable': FileDataTable_1.FileDataTable,
|
|
36
|
+
'@proteinjs/db-file/FileTable': FileTable_1.FileTable,
|
|
37
|
+
};
|
|
38
|
+
/** Load Source Graph and Links */
|
|
39
|
+
var reflection_1 = require("@proteinjs/reflection");
|
|
40
|
+
reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
|
|
41
|
+
__exportStar(require("../index"), exports);
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,yBAAuB;AACvB,iCAA+B;AAC/B,iCAA+B;AAC/B,8BAA4B;AAC5B,2BAAyB;AACzB,2BAAyB;AACzB,kBAAgB;AAGhB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,2miBAA2miB,CAAC;AAGhoiB,4BAA4B;AAE5B,kDAAiD;AACjD,iDAAgD;AAChD,6DAA4D;AAC5D,qDAAoD;AAEpD,IAAM,WAAW,GAAG;IACnB,gCAAgC,EAAE,yBAAW;IAC7C,4BAA4B,EAAE,iBAAO;IACrC,kCAAkC,EAAE,6BAAa;IACjD,8BAA8B,EAAE,qBAAS;CACzC,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './src/FileStorage';
|
|
2
|
+
export * from './src/tables/tables';
|
|
3
|
+
export * from './src/tables/FileTable';
|
|
4
|
+
export * from './src/tables/FileDataTable';
|
|
5
|
+
export * from './src/services/FileStorageService';
|
|
6
|
+
export * from './src/routes/getFileRoute';
|
|
7
|
+
export * from './src/FileStorageDriver';
|
|
8
|
+
export * from './src/DbFileStorageDriver';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,mBAAmB,CAAC;AAElC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,mCAAmC,CAAC;AAElD,cAAc,2BAA2B,CAAC;AAE1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/FileStorage"), exports);
|
|
18
|
+
__exportStar(require("./src/tables/tables"), exports);
|
|
19
|
+
__exportStar(require("./src/tables/FileTable"), exports);
|
|
20
|
+
__exportStar(require("./src/tables/FileDataTable"), exports);
|
|
21
|
+
__exportStar(require("./src/services/FileStorageService"), exports);
|
|
22
|
+
__exportStar(require("./src/routes/getFileRoute"), exports);
|
|
23
|
+
__exportStar(require("./src/FileStorageDriver"), exports);
|
|
24
|
+
__exportStar(require("./src/DbFileStorageDriver"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,oDAAkC;AAElC,sDAAoC;AACpC,yDAAuC;AACvC,6DAA2C;AAE3C,oEAAkD;AAElD,4DAA0C;AAE1C,0DAAwC;AACxC,4DAA0C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { File } from './tables/FileTable';
|
|
2
|
+
import { FileStorageDriver } from './FileStorageDriver';
|
|
3
|
+
export declare class DbFileStorageDriver implements FileStorageDriver {
|
|
4
|
+
private chunkSize;
|
|
5
|
+
/**
|
|
6
|
+
* @param chunkSize the size, in bytes, to be stored in each `FileDataTable` record; default is 1mb
|
|
7
|
+
*/
|
|
8
|
+
constructor(chunkSize?: number);
|
|
9
|
+
createFile(file: File, fileData: string): Promise<void>;
|
|
10
|
+
private splitIntoChunks;
|
|
11
|
+
getFileData(fileId: string): Promise<string>;
|
|
12
|
+
updateFileData(fileId: string, data: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=DbFileStorageDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbFileStorageDriver.d.ts","sourceRoot":"","sources":["../../src/DbFileStorageDriver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,mBAAoB,YAAW,iBAAiB;IAC3D,OAAO,CAAC,SAAS,CAAW;IAE5B;;OAEG;gBACS,SAAS,CAAC,EAAE,MAAM;IAMxB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa7D,OAAO,CAAC,eAAe;IAQjB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5C,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBlE"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DbFileStorageDriver = void 0;
|
|
40
|
+
var user_1 = require("@proteinjs/user");
|
|
41
|
+
var db_1 = require("@proteinjs/db");
|
|
42
|
+
var tables_1 = require("./tables/tables");
|
|
43
|
+
var DbFileStorageDriver = /** @class */ (function () {
|
|
44
|
+
/**
|
|
45
|
+
* @param chunkSize the size, in bytes, to be stored in each `FileDataTable` record; default is 1mb
|
|
46
|
+
*/
|
|
47
|
+
function DbFileStorageDriver(chunkSize) {
|
|
48
|
+
this.chunkSize = 1048576; // Max length of data written to `FileData.data` (1mb)
|
|
49
|
+
if (chunkSize != undefined) {
|
|
50
|
+
this.chunkSize = chunkSize;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
DbFileStorageDriver.prototype.createFile = function (file, fileData) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var db, chunks, index, chunk;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
db = (0, user_1.getScopedDb)();
|
|
60
|
+
chunks = this.splitIntoChunks(fileData);
|
|
61
|
+
index = 0;
|
|
62
|
+
_a.label = 1;
|
|
63
|
+
case 1:
|
|
64
|
+
if (!(index < chunks.length)) return [3 /*break*/, 4];
|
|
65
|
+
chunk = chunks[index];
|
|
66
|
+
return [4 /*yield*/, db.insert(tables_1.tables.FileData, {
|
|
67
|
+
file: new db_1.Reference(tables_1.tables.FileData.name, file.id),
|
|
68
|
+
order: index,
|
|
69
|
+
data: chunk,
|
|
70
|
+
})];
|
|
71
|
+
case 2:
|
|
72
|
+
_a.sent();
|
|
73
|
+
_a.label = 3;
|
|
74
|
+
case 3:
|
|
75
|
+
index++;
|
|
76
|
+
return [3 /*break*/, 1];
|
|
77
|
+
case 4: return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
DbFileStorageDriver.prototype.splitIntoChunks = function (data) {
|
|
83
|
+
var chunks = [];
|
|
84
|
+
for (var i = 0; i < data.length; i += this.chunkSize) {
|
|
85
|
+
chunks.push(data.substring(i, i + this.chunkSize));
|
|
86
|
+
}
|
|
87
|
+
return chunks;
|
|
88
|
+
};
|
|
89
|
+
DbFileStorageDriver.prototype.getFileData = function (fileId) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var db, qb, fileDataRecords;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
db = (0, user_1.getScopedDb)();
|
|
96
|
+
qb = new db_1.QueryBuilderFactory()
|
|
97
|
+
.getQueryBuilder(tables_1.tables.FileData, { file: fileId })
|
|
98
|
+
.sort([{ field: 'order', desc: false }]);
|
|
99
|
+
return [4 /*yield*/, db.query(tables_1.tables.FileData, qb)];
|
|
100
|
+
case 1:
|
|
101
|
+
fileDataRecords = _a.sent();
|
|
102
|
+
return [2 /*return*/, fileDataRecords.map(function (record) { return record.data; }).join('')];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
DbFileStorageDriver.prototype.updateFileData = function (fileId, data) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var db, deleteQuery, chunks, index, chunk;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
db = (0, user_1.getScopedDb)();
|
|
114
|
+
deleteQuery = new db_1.QueryBuilderFactory().getQueryBuilder(tables_1.tables.FileData, { file: fileId });
|
|
115
|
+
return [4 /*yield*/, db.delete(tables_1.tables.FileData, deleteQuery)];
|
|
116
|
+
case 1:
|
|
117
|
+
_a.sent();
|
|
118
|
+
chunks = this.splitIntoChunks(data);
|
|
119
|
+
index = 0;
|
|
120
|
+
_a.label = 2;
|
|
121
|
+
case 2:
|
|
122
|
+
if (!(index < chunks.length)) return [3 /*break*/, 5];
|
|
123
|
+
chunk = chunks[index];
|
|
124
|
+
return [4 /*yield*/, db.insert(tables_1.tables.FileData, {
|
|
125
|
+
file: new db_1.Reference(tables_1.tables.FileData.name, fileId),
|
|
126
|
+
order: index,
|
|
127
|
+
data: chunk,
|
|
128
|
+
})];
|
|
129
|
+
case 3:
|
|
130
|
+
_a.sent();
|
|
131
|
+
_a.label = 4;
|
|
132
|
+
case 4:
|
|
133
|
+
index++;
|
|
134
|
+
return [3 /*break*/, 2];
|
|
135
|
+
case 5: return [2 /*return*/];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
return DbFileStorageDriver;
|
|
141
|
+
}());
|
|
142
|
+
exports.DbFileStorageDriver = DbFileStorageDriver;
|
|
143
|
+
//# sourceMappingURL=DbFileStorageDriver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbFileStorageDriver.js","sourceRoot":"","sources":["../../src/DbFileStorageDriver.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ScopedRecord } from '@proteinjs/user';
|
|
2
|
+
import { File } from './tables/FileTable';
|
|
3
|
+
import { FileStorageService } from './services/FileStorageService';
|
|
4
|
+
import { FileStorageDriver } from './FileStorageDriver';
|
|
5
|
+
import { Loadable } from '@proteinjs/reflection';
|
|
6
|
+
/**
|
|
7
|
+
* A convenience factory function so code using this is portable (can be used in server or browser).
|
|
8
|
+
* @returns an instance of the `FileStorageService` when called from the browser, and an instance of `FileStorage` otherwise
|
|
9
|
+
* */
|
|
10
|
+
export declare const getFileStorage: () => FileStorage;
|
|
11
|
+
/**
|
|
12
|
+
* A convenience factory to provide a default `FileStorageDriver`
|
|
13
|
+
*/
|
|
14
|
+
export interface DefaultFileStorageDriverFactory extends Loadable {
|
|
15
|
+
getDriver(): FileStorageDriver;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A simple api for file storage.
|
|
19
|
+
* File metadata is stored in the `FileTable`.
|
|
20
|
+
* File data is stored by the `FileStorageDriver`.
|
|
21
|
+
*/
|
|
22
|
+
export declare class FileStorage implements FileStorageService {
|
|
23
|
+
private static defaultDriver;
|
|
24
|
+
private driver;
|
|
25
|
+
private logger;
|
|
26
|
+
serviceMetadata: {
|
|
27
|
+
auth: {
|
|
28
|
+
allUsers: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
constructor(driver?: FileStorageDriver);
|
|
32
|
+
private getDefaultDriver;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new file record and its associated data chunks.
|
|
35
|
+
* @param fileMetaData - The file metadata (name, type, size).
|
|
36
|
+
* @param fileData - The file data as a string.
|
|
37
|
+
* @returns The created file record.
|
|
38
|
+
*/
|
|
39
|
+
createFile(fileMetaData: Omit<File, keyof ScopedRecord>, fileData: string): Promise<File>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves the metadata of a given file.
|
|
42
|
+
* @param fileId - The `id` of the file.
|
|
43
|
+
* @returns The file metadata.
|
|
44
|
+
*/
|
|
45
|
+
getFile(fileId: string): Promise<File>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the data chunks associated with a given file.
|
|
48
|
+
* @param fileId - The `id` of the file.
|
|
49
|
+
* @returns The file data as a single string.
|
|
50
|
+
*/
|
|
51
|
+
getFileData(fileId: string): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Updates the data chunks associated with a given file.
|
|
54
|
+
* @param fileId - The `id` of the file.
|
|
55
|
+
* @param data - The new data string to replace the existing data.
|
|
56
|
+
*/
|
|
57
|
+
updateFileData(fileId: string, data: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Updates the metadata of a given file.
|
|
60
|
+
* @param file - The updated file to persist.
|
|
61
|
+
*/
|
|
62
|
+
updateFile(file: Omit<File, keyof ScopedRecord>): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes a file and its data.
|
|
65
|
+
* The file data is deleted by a cascade delete rule defined on the `FileTable`
|
|
66
|
+
* @param fileId - The `id` of the file to delete.
|
|
67
|
+
*/
|
|
68
|
+
deleteFile(fileId: string): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=FileStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileStorage.d.ts","sourceRoot":"","sources":["../../src/FileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAyB,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAInE;;;KAGK;AACL,eAAO,MAAM,cAAc,mBACiE,CAAC;AAE7F;;GAEG;AACH,MAAM,WAAW,+BAAgC,SAAQ,QAAQ;IAC/D,SAAS,IAAI,iBAAiB,CAAC;CAChC;AAED;;;;GAIG;AACH,qBAAa,WAAY,YAAW,kBAAkB;IACpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAoB;IAChD,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAA6C;IAEpD,eAAe;;;;MAIpB;gBAEU,MAAM,CAAC,EAAE,iBAAiB;IAItC,OAAO,CAAC,gBAAgB;IAgBxB;;;;;OAKG;IACG,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO/F;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5C;;;;OAIG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE;;;OAGG;IACG,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASrE;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQhD"}
|