@fgv/ts-http-storage 5.1.0-19 → 5.1.0-20
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/package.json +5 -5
- package/.rush/temp/6a0c03e499df249785541cca1357e0ac8db48297.tar.log +0 -61
- package/.rush/temp/chunked-rush-logs/ts-http-storage.build.chunks.jsonl +0 -9
- package/.rush/temp/operation/build/all.log +0 -9
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -656
- package/config/api-extractor.json +0 -36
- package/config/rig.json +0 -10
- package/config/typedoc.json +0 -7
- package/docs/README.md +0 -298
- package/docs/classes/FsStorageProvider.createDirectory.md +0 -20
- package/docs/classes/FsStorageProvider.deleteFile.md +0 -20
- package/docs/classes/FsStorageProvider.getChildren.md +0 -20
- package/docs/classes/FsStorageProvider.getFile.md +0 -20
- package/docs/classes/FsStorageProvider.getItem.md +0 -20
- package/docs/classes/FsStorageProvider.md +0 -147
- package/docs/classes/FsStorageProvider.saveFile.md +0 -22
- package/docs/classes/FsStorageProvider.sync.md +0 -13
- package/docs/classes/FsStorageProviderFactory.forNamespace.md +0 -20
- package/docs/classes/FsStorageProviderFactory.md +0 -69
- package/docs/classes/HttpStorageService.createDirectory.md +0 -20
- package/docs/classes/HttpStorageService.deleteFile.md +0 -20
- package/docs/classes/HttpStorageService.getChildren.md +0 -20
- package/docs/classes/HttpStorageService.getFile.md +0 -20
- package/docs/classes/HttpStorageService.getItem.md +0 -20
- package/docs/classes/HttpStorageService.md +0 -145
- package/docs/classes/HttpStorageService.saveFile.md +0 -20
- package/docs/classes/HttpStorageService.sync.md +0 -20
- package/docs/functions/createStorageRoutes.md +0 -11
- package/docs/functions/normalizeRequestPath.md +0 -11
- package/docs/functions/sanitizeNamespace.md +0 -11
- package/docs/interfaces/ICreateStorageRoutesOptions.logger.md +0 -9
- package/docs/interfaces/ICreateStorageRoutesOptions.md +0 -61
- package/docs/interfaces/ICreateStorageRoutesOptions.providers.md +0 -9
- package/docs/interfaces/IFsStorageProviderFactoryOptions.md +0 -44
- package/docs/interfaces/IFsStorageProviderFactoryOptions.rootPath.md +0 -9
- package/docs/interfaces/IHttpStorageProvider.createDirectory.md +0 -20
- package/docs/interfaces/IHttpStorageProvider.deleteFile.md +0 -20
- package/docs/interfaces/IHttpStorageProvider.getChildren.md +0 -20
- package/docs/interfaces/IHttpStorageProvider.getFile.md +0 -20
- package/docs/interfaces/IHttpStorageProvider.getItem.md +0 -20
- package/docs/interfaces/IHttpStorageProvider.md +0 -115
- package/docs/interfaces/IHttpStorageProvider.saveFile.md +0 -22
- package/docs/interfaces/IHttpStorageProvider.sync.md +0 -13
- package/docs/interfaces/IHttpStorageProviderFactory.forNamespace.md +0 -20
- package/docs/interfaces/IHttpStorageProviderFactory.md +0 -36
- package/docs/interfaces/IStorageFileResponse.contentType.md +0 -9
- package/docs/interfaces/IStorageFileResponse.contents.md +0 -9
- package/docs/interfaces/IStorageFileResponse.md +0 -78
- package/docs/interfaces/IStorageFileResponse.path.md +0 -9
- package/docs/interfaces/IStoragePathRequest.md +0 -61
- package/docs/interfaces/IStoragePathRequest.namespace.md +0 -9
- package/docs/interfaces/IStoragePathRequest.path.md +0 -9
- package/docs/interfaces/IStorageSyncRequest.md +0 -44
- package/docs/interfaces/IStorageSyncRequest.namespace.md +0 -9
- package/docs/interfaces/IStorageSyncResponse.md +0 -44
- package/docs/interfaces/IStorageSyncResponse.synced.md +0 -9
- package/docs/interfaces/IStorageTreeChildrenResponse.children.md +0 -9
- package/docs/interfaces/IStorageTreeChildrenResponse.md +0 -61
- package/docs/interfaces/IStorageTreeChildrenResponse.path.md +0 -9
- package/docs/interfaces/IStorageTreeItem.md +0 -78
- package/docs/interfaces/IStorageTreeItem.name.md +0 -9
- package/docs/interfaces/IStorageTreeItem.path.md +0 -9
- package/docs/interfaces/IStorageTreeItem.type.md +0 -9
- package/docs/interfaces/IStorageWriteFileRequest.contentType.md +0 -9
- package/docs/interfaces/IStorageWriteFileRequest.contents.md +0 -9
- package/docs/interfaces/IStorageWriteFileRequest.md +0 -97
- package/docs/type-aliases/StorageItemType.md +0 -11
- package/docs/type-aliases/StorageNamespace.md +0 -11
- package/docs/variables/storageFileResponse.md +0 -9
- package/docs/variables/storagePathRequest.md +0 -9
- package/docs/variables/storageSyncRequest.md +0 -9
- package/docs/variables/storageTreeChildrenResponse.md +0 -9
- package/docs/variables/storageTreeItem.md +0 -9
- package/docs/variables/storageWriteFileRequest.md +0 -9
- package/etc/ts-http-storage.api.md +0 -184
- package/lib/test/unit/storage/fsProvider.test.d.ts +0 -2
- package/lib/test/unit/storage/fsProvider.test.d.ts.map +0 -1
- package/lib/test/unit/storage/fsProvider.test.js +0 -106
- package/lib/test/unit/storage/fsProvider.test.js.map +0 -1
- package/lib/test/unit/storage/routes.test.d.ts +0 -2
- package/lib/test/unit/storage/routes.test.d.ts.map +0 -1
- package/lib/test/unit/storage/routes.test.js +0 -124
- package/lib/test/unit/storage/routes.test.js.map +0 -1
- package/lib/test/unit/storage/service.test.d.ts +0 -2
- package/lib/test/unit/storage/service.test.d.ts.map +0 -1
- package/lib/test/unit/storage/service.test.js +0 -67
- package/lib/test/unit/storage/service.test.js.map +0 -1
- package/rush-logs/ts-http-storage.build.cache.log +0 -3
- package/rush-logs/ts-http-storage.build.log +0 -9
- package/src/index.ts +0 -28
- package/src/packlets/storage/converters.ts +0 -100
- package/src/packlets/storage/fsProvider.ts +0 -263
- package/src/packlets/storage/index.ts +0 -33
- package/src/packlets/storage/model.ts +0 -113
- package/src/packlets/storage/provider.ts +0 -33
- package/src/packlets/storage/routes.ts +0 -215
- package/src/packlets/storage/service.ts +0 -114
- package/src/test/unit/storage/fsProvider.test.ts +0 -129
- package/src/test/unit/storage/routes.test.ts +0 -165
- package/src/test/unit/storage/service.test.ts +0 -95
- package/temp/build/typescript/ts_l9Fw4VUO.json +0 -1
- package/temp/ts-http-storage.api.json +0 -3103
- package/temp/ts-http-storage.api.md +0 -184
- package/tsconfig.json +0 -7
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
[Home](../README.md) > IStorageWriteFileRequest
|
|
2
|
-
|
|
3
|
-
# Interface: IStorageWriteFileRequest
|
|
4
|
-
|
|
5
|
-
Request for writing file contents.
|
|
6
|
-
|
|
7
|
-
**Extends:** [`IStoragePathRequest`](IStoragePathRequest.md)
|
|
8
|
-
|
|
9
|
-
## Properties
|
|
10
|
-
|
|
11
|
-
<table><thead><tr><th>
|
|
12
|
-
|
|
13
|
-
Property
|
|
14
|
-
|
|
15
|
-
</th><th>
|
|
16
|
-
|
|
17
|
-
Modifiers
|
|
18
|
-
|
|
19
|
-
</th><th>
|
|
20
|
-
|
|
21
|
-
Type
|
|
22
|
-
|
|
23
|
-
</th><th>
|
|
24
|
-
|
|
25
|
-
Description
|
|
26
|
-
|
|
27
|
-
</th></tr></thead>
|
|
28
|
-
<tbody>
|
|
29
|
-
<tr><td>
|
|
30
|
-
|
|
31
|
-
[contents](./IStorageWriteFileRequest.contents.md)
|
|
32
|
-
|
|
33
|
-
</td><td>
|
|
34
|
-
|
|
35
|
-
`readonly`
|
|
36
|
-
|
|
37
|
-
</td><td>
|
|
38
|
-
|
|
39
|
-
string
|
|
40
|
-
|
|
41
|
-
</td><td>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
</td></tr>
|
|
46
|
-
<tr><td>
|
|
47
|
-
|
|
48
|
-
[contentType](./IStorageWriteFileRequest.contentType.md)
|
|
49
|
-
|
|
50
|
-
</td><td>
|
|
51
|
-
|
|
52
|
-
`readonly`
|
|
53
|
-
|
|
54
|
-
</td><td>
|
|
55
|
-
|
|
56
|
-
string
|
|
57
|
-
|
|
58
|
-
</td><td>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
</td></tr>
|
|
63
|
-
<tr><td>
|
|
64
|
-
|
|
65
|
-
[path](./IStoragePathRequest.path.md)
|
|
66
|
-
|
|
67
|
-
</td><td>
|
|
68
|
-
|
|
69
|
-
`readonly`
|
|
70
|
-
|
|
71
|
-
</td><td>
|
|
72
|
-
|
|
73
|
-
string
|
|
74
|
-
|
|
75
|
-
</td><td>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
</td></tr>
|
|
80
|
-
<tr><td>
|
|
81
|
-
|
|
82
|
-
[namespace](./IStoragePathRequest.namespace.md)
|
|
83
|
-
|
|
84
|
-
</td><td>
|
|
85
|
-
|
|
86
|
-
`readonly`
|
|
87
|
-
|
|
88
|
-
</td><td>
|
|
89
|
-
|
|
90
|
-
string
|
|
91
|
-
|
|
92
|
-
</td><td>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
</td></tr>
|
|
97
|
-
</tbody></table>
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
## API Report File for "@fgv/ts-http-storage"
|
|
2
|
-
|
|
3
|
-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
|
|
7
|
-
import { Converter } from '@fgv/ts-utils';
|
|
8
|
-
import { Hono } from 'hono';
|
|
9
|
-
import type { Logging } from '@fgv/ts-utils';
|
|
10
|
-
import { Result } from '@fgv/ts-utils';
|
|
11
|
-
|
|
12
|
-
// @public
|
|
13
|
-
export function createStorageRoutes(options: ICreateStorageRoutesOptions): Hono;
|
|
14
|
-
|
|
15
|
-
// @public
|
|
16
|
-
export class FsStorageProvider implements IHttpStorageProvider {
|
|
17
|
-
constructor(rootPath: string);
|
|
18
|
-
// (undocumented)
|
|
19
|
-
createDirectory(itemPath: string): Promise<Result<IStorageTreeItem>>;
|
|
20
|
-
// (undocumented)
|
|
21
|
-
deleteFile(itemPath: string): Promise<Result<boolean>>;
|
|
22
|
-
// (undocumented)
|
|
23
|
-
getChildren(itemPath: string): Promise<Result<ReadonlyArray<IStorageTreeItem>>>;
|
|
24
|
-
// (undocumented)
|
|
25
|
-
getFile(itemPath: string): Promise<Result<IStorageFileResponse>>;
|
|
26
|
-
// (undocumented)
|
|
27
|
-
getItem(itemPath: string): Promise<Result<IStorageTreeItem>>;
|
|
28
|
-
// (undocumented)
|
|
29
|
-
saveFile(itemPath: string, contents: string, contentType?: string): Promise<Result<IStorageFileResponse>>;
|
|
30
|
-
// (undocumented)
|
|
31
|
-
sync(): Promise<Result<IStorageSyncResponse>>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// @public
|
|
35
|
-
export class FsStorageProviderFactory implements IHttpStorageProviderFactory {
|
|
36
|
-
constructor(options: IFsStorageProviderFactoryOptions);
|
|
37
|
-
// (undocumented)
|
|
38
|
-
forNamespace(namespace?: string): Result<IHttpStorageProvider>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// @public
|
|
42
|
-
export class HttpStorageService {
|
|
43
|
-
constructor(providers: IHttpStorageProviderFactory);
|
|
44
|
-
// (undocumented)
|
|
45
|
-
createDirectory(request: IStoragePathRequest): Promise<Result<IStorageTreeItem>>;
|
|
46
|
-
// (undocumented)
|
|
47
|
-
deleteFile(request: IStoragePathRequest): Promise<Result<boolean>>;
|
|
48
|
-
// (undocumented)
|
|
49
|
-
getChildren(request: IStoragePathRequest): Promise<Result<IStorageTreeChildrenResponse>>;
|
|
50
|
-
// (undocumented)
|
|
51
|
-
getFile(request: IStoragePathRequest): Promise<Result<IStorageFileResponse>>;
|
|
52
|
-
// (undocumented)
|
|
53
|
-
getItem(request: IStoragePathRequest): Promise<Result<IStorageTreeItem>>;
|
|
54
|
-
// (undocumented)
|
|
55
|
-
saveFile(request: IStorageWriteFileRequest): Promise<Result<IStorageFileResponse>>;
|
|
56
|
-
// (undocumented)
|
|
57
|
-
sync(request: IStorageSyncRequest): Promise<Result<IStorageSyncResponse>>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// @public
|
|
61
|
-
export interface ICreateStorageRoutesOptions {
|
|
62
|
-
// (undocumented)
|
|
63
|
-
readonly logger?: Logging.ILogger;
|
|
64
|
-
// (undocumented)
|
|
65
|
-
readonly providers: IHttpStorageProviderFactory;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// @public
|
|
69
|
-
export interface IFsStorageProviderFactoryOptions {
|
|
70
|
-
// (undocumented)
|
|
71
|
-
readonly rootPath: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// @public
|
|
75
|
-
export interface IHttpStorageProvider {
|
|
76
|
-
// (undocumented)
|
|
77
|
-
createDirectory(path: string): Promise<Result<IStorageTreeItem>>;
|
|
78
|
-
// (undocumented)
|
|
79
|
-
deleteFile(path: string): Promise<Result<boolean>>;
|
|
80
|
-
// (undocumented)
|
|
81
|
-
getChildren(path: string): Promise<Result<ReadonlyArray<IStorageTreeItem>>>;
|
|
82
|
-
// (undocumented)
|
|
83
|
-
getFile(path: string): Promise<Result<IStorageFileResponse>>;
|
|
84
|
-
// (undocumented)
|
|
85
|
-
getItem(path: string): Promise<Result<IStorageTreeItem>>;
|
|
86
|
-
// (undocumented)
|
|
87
|
-
saveFile(path: string, contents: string, contentType?: string): Promise<Result<IStorageFileResponse>>;
|
|
88
|
-
// (undocumented)
|
|
89
|
-
sync(): Promise<Result<IStorageSyncResponse>>;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// @public
|
|
93
|
-
export interface IHttpStorageProviderFactory {
|
|
94
|
-
// (undocumented)
|
|
95
|
-
forNamespace(namespace?: StorageNamespace): Result<IHttpStorageProvider>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// @public
|
|
99
|
-
export interface IStorageFileResponse {
|
|
100
|
-
// (undocumented)
|
|
101
|
-
readonly contents: string;
|
|
102
|
-
// (undocumented)
|
|
103
|
-
readonly contentType?: string;
|
|
104
|
-
// (undocumented)
|
|
105
|
-
readonly path: string;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// @public
|
|
109
|
-
export interface IStoragePathRequest {
|
|
110
|
-
// (undocumented)
|
|
111
|
-
readonly namespace?: StorageNamespace;
|
|
112
|
-
// (undocumented)
|
|
113
|
-
readonly path: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// @public
|
|
117
|
-
export interface IStorageSyncRequest {
|
|
118
|
-
// (undocumented)
|
|
119
|
-
readonly namespace?: StorageNamespace;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// @public
|
|
123
|
-
export interface IStorageSyncResponse {
|
|
124
|
-
// (undocumented)
|
|
125
|
-
readonly synced: number;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// @public
|
|
129
|
-
export interface IStorageTreeChildrenResponse {
|
|
130
|
-
// (undocumented)
|
|
131
|
-
readonly children: ReadonlyArray<IStorageTreeItem>;
|
|
132
|
-
// (undocumented)
|
|
133
|
-
readonly path: string;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// @public
|
|
137
|
-
export interface IStorageTreeItem {
|
|
138
|
-
// (undocumented)
|
|
139
|
-
readonly name: string;
|
|
140
|
-
// (undocumented)
|
|
141
|
-
readonly path: string;
|
|
142
|
-
// (undocumented)
|
|
143
|
-
readonly type: StorageItemType;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// @public
|
|
147
|
-
export interface IStorageWriteFileRequest extends IStoragePathRequest {
|
|
148
|
-
// (undocumented)
|
|
149
|
-
readonly contents: string;
|
|
150
|
-
// (undocumented)
|
|
151
|
-
readonly contentType?: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// @public
|
|
155
|
-
export function normalizeRequestPath(requestPath: string): string;
|
|
156
|
-
|
|
157
|
-
// @public
|
|
158
|
-
export function sanitizeNamespace(namespace?: string): Result<string>;
|
|
159
|
-
|
|
160
|
-
// @public
|
|
161
|
-
export const storageFileResponse: Converter<IStorageFileResponse>;
|
|
162
|
-
|
|
163
|
-
// @public
|
|
164
|
-
export type StorageItemType = 'file' | 'directory';
|
|
165
|
-
|
|
166
|
-
// @public
|
|
167
|
-
export type StorageNamespace = string;
|
|
168
|
-
|
|
169
|
-
// @public
|
|
170
|
-
export const storagePathRequest: Converter<IStoragePathRequest>;
|
|
171
|
-
|
|
172
|
-
// @public
|
|
173
|
-
export const storageSyncRequest: Converter<IStorageSyncRequest>;
|
|
174
|
-
|
|
175
|
-
// @public
|
|
176
|
-
export const storageTreeChildrenResponse: Converter<IStorageTreeChildrenResponse>;
|
|
177
|
-
|
|
178
|
-
// @public
|
|
179
|
-
export const storageTreeItem: Converter<IStorageTreeItem>;
|
|
180
|
-
|
|
181
|
-
// @public
|
|
182
|
-
export const storageWriteFileRequest: Converter<IStorageWriteFileRequest>;
|
|
183
|
-
|
|
184
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fsProvider.test.d.ts","sourceRoot":"","sources":["../../../../src/test/unit/storage/fsProvider.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const storage_1 = require("../../../packlets/storage");
|
|
10
|
-
describe('sanitizeNamespace', () => {
|
|
11
|
-
test('returns default when namespace is empty', () => {
|
|
12
|
-
expect((0, storage_1.sanitizeNamespace)(undefined).isSuccess()).toBe(true);
|
|
13
|
-
expect((0, storage_1.sanitizeNamespace)(' ').isSuccess()).toBe(true);
|
|
14
|
-
expect((0, storage_1.sanitizeNamespace)(' ').orThrow()).toBe('default');
|
|
15
|
-
});
|
|
16
|
-
test('accepts valid namespace values', () => {
|
|
17
|
-
const result = (0, storage_1.sanitizeNamespace)('team.alpha_01-dev');
|
|
18
|
-
expect(result.isSuccess()).toBe(true);
|
|
19
|
-
expect(result.orThrow()).toBe('team.alpha_01-dev');
|
|
20
|
-
});
|
|
21
|
-
test('rejects invalid namespace characters', () => {
|
|
22
|
-
const result = (0, storage_1.sanitizeNamespace)('../escape');
|
|
23
|
-
expect(result.isFailure()).toBe(true);
|
|
24
|
-
expect(result.message).toContain('only [a-zA-Z0-9._-] allowed');
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe('FsStorageProvider', () => {
|
|
28
|
-
let rootPath;
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
rootPath = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'ts-http-storage-test-'));
|
|
31
|
-
});
|
|
32
|
-
afterEach(() => {
|
|
33
|
-
fs_1.default.rmSync(rootPath, { recursive: true, force: true });
|
|
34
|
-
});
|
|
35
|
-
test('saves and loads files', async () => {
|
|
36
|
-
const provider = new storage_1.FsStorageProvider(rootPath);
|
|
37
|
-
const saveResult = await provider.saveFile('/data/example.txt', 'hello');
|
|
38
|
-
expect(saveResult.isSuccess()).toBe(true);
|
|
39
|
-
const fileResult = await provider.getFile('/data/example.txt');
|
|
40
|
-
expect(fileResult.isSuccess()).toBe(true);
|
|
41
|
-
expect(fileResult.orThrow()).toEqual({
|
|
42
|
-
path: '/data/example.txt',
|
|
43
|
-
contents: 'hello'
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
test('lists children in a directory', async () => {
|
|
47
|
-
const provider = new storage_1.FsStorageProvider(rootPath);
|
|
48
|
-
await provider.saveFile('/data/one.txt', 'one');
|
|
49
|
-
await provider.saveFile('/data/two.txt', 'two');
|
|
50
|
-
const childrenResult = await provider.getChildren('/data');
|
|
51
|
-
expect(childrenResult.isSuccess()).toBe(true);
|
|
52
|
-
const childNames = childrenResult
|
|
53
|
-
.orThrow()
|
|
54
|
-
.map((child) => child.name)
|
|
55
|
-
.sort();
|
|
56
|
-
expect(childNames).toEqual(['one.txt', 'two.txt']);
|
|
57
|
-
});
|
|
58
|
-
test('normalizes traversal-like request paths under storage root', async () => {
|
|
59
|
-
const provider = new storage_1.FsStorageProvider(rootPath);
|
|
60
|
-
const result = await provider.getItem('../../etc/passwd');
|
|
61
|
-
expect(result.isFailure()).toBe(true);
|
|
62
|
-
expect(result.message).toContain('ENOENT');
|
|
63
|
-
expect(result.message).toContain(path_1.default.join(rootPath, 'etc/passwd'));
|
|
64
|
-
});
|
|
65
|
-
test('deletes an existing file', async () => {
|
|
66
|
-
const provider = new storage_1.FsStorageProvider(rootPath);
|
|
67
|
-
await provider.saveFile('/data/delete-me.txt', 'temporary');
|
|
68
|
-
const deleteResult = await provider.deleteFile('/data/delete-me.txt');
|
|
69
|
-
expect(deleteResult.isSuccess()).toBe(true);
|
|
70
|
-
expect(deleteResult.orThrow()).toBe(true);
|
|
71
|
-
const readResult = await provider.getFile('/data/delete-me.txt');
|
|
72
|
-
expect(readResult.isFailure()).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe('FsStorageProviderFactory', () => {
|
|
76
|
-
let rootPath;
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
rootPath = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'ts-http-storage-factory-'));
|
|
79
|
-
});
|
|
80
|
-
afterEach(() => {
|
|
81
|
-
fs_1.default.rmSync(rootPath, { recursive: true, force: true });
|
|
82
|
-
});
|
|
83
|
-
test('creates namespace-scoped providers', async () => {
|
|
84
|
-
const factory = new storage_1.FsStorageProviderFactory({ rootPath });
|
|
85
|
-
const providerResult = factory.forNamespace('team-a');
|
|
86
|
-
expect(providerResult.isSuccess()).toBe(true);
|
|
87
|
-
const provider = providerResult.orThrow();
|
|
88
|
-
const saveResult = await provider.saveFile('/notes.txt', 'namespaced');
|
|
89
|
-
expect(saveResult.isSuccess()).toBe(true);
|
|
90
|
-
const expectedPath = path_1.default.join(rootPath, 'team-a', 'notes.txt');
|
|
91
|
-
expect(fs_1.default.existsSync(expectedPath)).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
test('fails for invalid namespace', () => {
|
|
94
|
-
const factory = new storage_1.FsStorageProviderFactory({ rootPath });
|
|
95
|
-
const result = factory.forNamespace('bad/name');
|
|
96
|
-
expect(result.isFailure()).toBe(true);
|
|
97
|
-
expect(result.message).toContain('only [a-zA-Z0-9._-] allowed');
|
|
98
|
-
});
|
|
99
|
-
test('rejects namespace that resolves outside root', () => {
|
|
100
|
-
const factory = new storage_1.FsStorageProviderFactory({ rootPath });
|
|
101
|
-
const result = factory.forNamespace('..');
|
|
102
|
-
expect(result.isFailure()).toBe(true);
|
|
103
|
-
expect(result.message).toContain('outside root');
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
//# sourceMappingURL=fsProvider.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fsProvider.test.js","sourceRoot":"","sources":["../../../../src/test/unit/storage/fsProvider.test.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAExB,uDAA2G;AAE3G,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,IAAA,2BAAiB,EAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,MAAM,CAAC,IAAA,2BAAiB,EAAC,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,CAAC,IAAA,2BAAiB,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE;QAC1C,MAAM,MAAM,GAAG,IAAA,2BAAiB,EAAC,mBAAmB,C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ACxD,MAAM,OAAO,GAAG,IAAI,kCAAwB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE1C,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import fs from 'fs';\nimport os from 'os';\nimport path from 'path';\n\nimport { FsStorageProvider, FsStorageProviderFactory, sanitizeNamespace } from '../../../packlets/storage';\n\ndescribe('sanitizeNamespace', () => {\n test('returns default when namespace is empty', () => {\n expect(sanitizeNamespace(undefined).isSuccess()).toBe(true);\n expect(sanitizeNamespace(' ').isSuccess()).toBe(true);\n expect(sanitizeNamespace(' ').orThrow()).toBe('default');\n });\n\n test('accepts valid namespace values', () => {\n const result = sanitizeNamespace('team.alpha_01-dev');\n expect(result.isSuccess()).toBe(true);\n expect(result.orThrow()).toBe('team.alpha_01-dev');\n });\n\n test('rejects invalid namespace characters', () => {\n const result = sanitizeNamespace('../escape');\n expect(result.isFailure()).toBe(true);\n expect(result.message).toContain('only [a-zA-Z0-9._-] allowed');\n });\n});\n\ndescribe('FsStorageProvider', () => {\n let rootPath: string;\n\n beforeEach(() => {\n rootPath = fs.mkdtempSync(path.join(os.tmpdir(), 'ts-http-storage-test-'));\n });\n\n afterEach(() => {\n fs.rmSync(rootPath, { recursive: true, force: true });\n });\n\n test('saves and loads files', async () => {\n const provider = new FsStorageProvider(rootPath);\n\n const saveResult = await provider.saveFile('/data/example.txt', 'hello');\n expect(saveResult.isSuccess()).toBe(true);\n\n const fileResult = await provider.getFile('/data/example.txt');\n expect(fileResult.isSuccess()).toBe(true);\n expect(fileResult.orThrow()).toEqual({\n path: '/data/example.txt',\n contents: 'hello'\n });\n });\n\n test('lists children in a directory', async () => {\n const provider = new FsStorageProvider(rootPath);\n await provider.saveFile('/data/one.txt', 'one');\n await provider.saveFile('/data/two.txt', 'two');\n\n const childrenResult = await provider.getChildren('/data');\n expect(childrenResult.isSuccess()).toBe(true);\n\n const childNames = childrenResult\n .orThrow()\n .map((child) => child.name)\n .sort();\n expect(childNames).toEqual(['one.txt', 'two.txt']);\n });\n\n test('normalizes traversal-like request paths under storage root', async () => {\n const provider = new FsStorageProvider(rootPath);\n\n const result = await provider.getItem('../../etc/passwd');\n expect(result.isFailure()).toBe(true);\n expect(result.message).toContain('ENOENT');\n expect(result.message).toContain(path.join(rootPath, 'etc/passwd'));\n });\n\n test('deletes an existing file', async () => {\n const provider = new FsStorageProvider(rootPath);\n await provider.saveFile('/data/delete-me.txt', 'temporary');\n\n const deleteResult = await provider.deleteFile('/data/delete-me.txt');\n expect(deleteResult.isSuccess()).toBe(true);\n expect(deleteResult.orThrow()).toBe(true);\n\n const readResult = await provider.getFile('/data/delete-me.txt');\n expect(readResult.isFailure()).toBe(true);\n });\n});\n\ndescribe('FsStorageProviderFactory', () => {\n let rootPath: string;\n\n beforeEach(() => {\n rootPath = fs.mkdtempSync(path.join(os.tmpdir(), 'ts-http-storage-factory-'));\n });\n\n afterEach(() => {\n fs.rmSync(rootPath, { recursive: true, force: true });\n });\n\n test('creates namespace-scoped providers', async () => {\n const factory = new FsStorageProviderFactory({ rootPath });\n\n const providerResult = factory.forNamespace('team-a');\n expect(providerResult.isSuccess()).toBe(true);\n\n const provider = providerResult.orThrow();\n const saveResult = await provider.saveFile('/notes.txt', 'namespaced');\n expect(saveResult.isSuccess()).toBe(true);\n\n const expectedPath = path.join(rootPath, 'team-a', 'notes.txt');\n expect(fs.existsSync(expectedPath)).toBe(true);\n });\n\n test('fails for invalid namespace', () => {\n const factory = new FsStorageProviderFactory({ rootPath });\n const result = factory.forNamespace('bad/name');\n\n expect(result.isFailure()).toBe(true);\n expect(result.message).toContain('only [a-zA-Z0-9._-] allowed');\n });\n\n test('rejects namespace that resolves outside root', () => {\n const factory = new FsStorageProviderFactory({ rootPath });\n const result = factory.forNamespace('..');\n\n expect(result.isFailure()).toBe(true);\n expect(result.message).toContain('outside root');\n });\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.test.d.ts","sourceRoot":"","sources":["../../../../src/test/unit/storage/routes.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ts_utils_1 = require("@fgv/ts-utils");
|
|
4
|
-
const storage_1 = require("../../../packlets/storage");
|
|
5
|
-
class InMemoryProvider {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._files = new Map();
|
|
8
|
-
}
|
|
9
|
-
_basename(path) {
|
|
10
|
-
var _a;
|
|
11
|
-
const parts = path.split('/');
|
|
12
|
-
return (_a = parts[parts.length - 1]) !== null && _a !== void 0 ? _a : '';
|
|
13
|
-
}
|
|
14
|
-
async getItem(path) {
|
|
15
|
-
if (this._files.has(path)) {
|
|
16
|
-
return (0, ts_utils_1.succeed)({ path, name: this._basename(path), type: 'file' });
|
|
17
|
-
}
|
|
18
|
-
return (0, ts_utils_1.fail)(`${path}: not found`);
|
|
19
|
-
}
|
|
20
|
-
async getChildren(path) {
|
|
21
|
-
const children = [];
|
|
22
|
-
for (const filePath of this._files.keys()) {
|
|
23
|
-
if (filePath.startsWith(`${path}/`)) {
|
|
24
|
-
const name = filePath.substring(path.length + 1);
|
|
25
|
-
if (!name.includes('/')) {
|
|
26
|
-
children.push({ path: filePath, name, type: 'file' });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return (0, ts_utils_1.succeed)(children);
|
|
31
|
-
}
|
|
32
|
-
async getFile(path) {
|
|
33
|
-
const contents = this._files.get(path);
|
|
34
|
-
if (contents === undefined) {
|
|
35
|
-
return (0, ts_utils_1.fail)(`${path}: not found`);
|
|
36
|
-
}
|
|
37
|
-
return (0, ts_utils_1.succeed)({ path, contents });
|
|
38
|
-
}
|
|
39
|
-
async saveFile(path, contents) {
|
|
40
|
-
this._files.set(path, contents);
|
|
41
|
-
return (0, ts_utils_1.succeed)({ path, contents });
|
|
42
|
-
}
|
|
43
|
-
async deleteFile(path) {
|
|
44
|
-
if (!this._files.has(path)) {
|
|
45
|
-
return (0, ts_utils_1.fail)(`${path}: not found`);
|
|
46
|
-
}
|
|
47
|
-
this._files.delete(path);
|
|
48
|
-
return (0, ts_utils_1.succeed)(true);
|
|
49
|
-
}
|
|
50
|
-
async createDirectory(path) {
|
|
51
|
-
return (0, ts_utils_1.succeed)({ path, name: this._basename(path), type: 'directory' });
|
|
52
|
-
}
|
|
53
|
-
async sync() {
|
|
54
|
-
return (0, ts_utils_1.succeed)({ synced: this._files.size });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
class TestProviderFactory {
|
|
58
|
-
constructor(provider) {
|
|
59
|
-
this._provider = provider;
|
|
60
|
-
}
|
|
61
|
-
forNamespace() {
|
|
62
|
-
return (0, ts_utils_1.succeed)(this._provider);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
describe('createStorageRoutes', () => {
|
|
66
|
-
test('writes then reads a file', async () => {
|
|
67
|
-
const provider = new InMemoryProvider();
|
|
68
|
-
const app = (0, storage_1.createStorageRoutes)({ providers: new TestProviderFactory(provider) });
|
|
69
|
-
const putResponse = await app.request(new Request('http://localhost/file', {
|
|
70
|
-
method: 'PUT',
|
|
71
|
-
headers: { 'Content-Type': 'application/json' },
|
|
72
|
-
body: JSON.stringify({ path: '/data/demo.txt', contents: 'hello' })
|
|
73
|
-
}));
|
|
74
|
-
expect(putResponse.status).toBe(200);
|
|
75
|
-
const getResponse = await app.request(new Request('http://localhost/file?path=/data/demo.txt'));
|
|
76
|
-
expect(getResponse.status).toBe(200);
|
|
77
|
-
await expect(getResponse.json()).resolves.toEqual({ path: '/data/demo.txt', contents: 'hello' });
|
|
78
|
-
});
|
|
79
|
-
test('returns 400 for invalid put body', async () => {
|
|
80
|
-
const provider = new InMemoryProvider();
|
|
81
|
-
const app = (0, storage_1.createStorageRoutes)({ providers: new TestProviderFactory(provider) });
|
|
82
|
-
const response = await app.request(new Request('http://localhost/file', {
|
|
83
|
-
method: 'PUT',
|
|
84
|
-
headers: { 'Content-Type': 'application/json' },
|
|
85
|
-
body: '{ not-json'
|
|
86
|
-
}));
|
|
87
|
-
expect(response.status).toBe(400);
|
|
88
|
-
const payload = (await response.json());
|
|
89
|
-
expect(payload.error).toContain('invalid JSON body');
|
|
90
|
-
});
|
|
91
|
-
test('returns sync payload from provider', async () => {
|
|
92
|
-
const provider = new InMemoryProvider();
|
|
93
|
-
const app = (0, storage_1.createStorageRoutes)({ providers: new TestProviderFactory(provider) });
|
|
94
|
-
await app.request(new Request('http://localhost/file', {
|
|
95
|
-
method: 'PUT',
|
|
96
|
-
headers: { 'Content-Type': 'application/json' },
|
|
97
|
-
body: JSON.stringify({ path: '/alpha.txt', contents: 'a' })
|
|
98
|
-
}));
|
|
99
|
-
const response = await app.request(new Request('http://localhost/sync', {
|
|
100
|
-
method: 'POST',
|
|
101
|
-
headers: { 'Content-Type': 'application/json' },
|
|
102
|
-
body: JSON.stringify({})
|
|
103
|
-
}));
|
|
104
|
-
expect(response.status).toBe(200);
|
|
105
|
-
await expect(response.json()).resolves.toEqual({ synced: 1 });
|
|
106
|
-
});
|
|
107
|
-
test('deletes a file through DELETE /file', async () => {
|
|
108
|
-
const provider = new InMemoryProvider();
|
|
109
|
-
const app = (0, storage_1.createStorageRoutes)({ providers: new TestProviderFactory(provider) });
|
|
110
|
-
await app.request(new Request('http://localhost/file', {
|
|
111
|
-
method: 'PUT',
|
|
112
|
-
headers: { 'Content-Type': 'application/json' },
|
|
113
|
-
body: JSON.stringify({ path: '/data/remove-me.txt', contents: 'gone soon' })
|
|
114
|
-
}));
|
|
115
|
-
const deleteResponse = await app.request(new Request('http://localhost/file?path=/data/remove-me.txt', {
|
|
116
|
-
method: 'DELETE'
|
|
117
|
-
}));
|
|
118
|
-
expect(deleteResponse.status).toBe(200);
|
|
119
|
-
await expect(deleteResponse.json()).resolves.toEqual({ deleted: true });
|
|
120
|
-
const getResponse = await app.request(new Request('http://localhost/file?path=/data/remove-me.txt'));
|
|
121
|
-
expect(getResponse.status).toBe(404);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
//# sourceMappingURL=routes.test.js.map
|