@cascateer/database 0.0.3 → 0.0.4
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 +1 -1
- package/src/file.ts +0 -7
- package/src/table.ts +9 -0
- package/src/types.ts +0 -3
package/package.json
CHANGED
package/src/file.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
2
|
import { createReadStream } from "fs";
|
|
3
|
-
import { Ora } from "ora";
|
|
4
3
|
import { extname, relative, resolve } from "path";
|
|
5
4
|
import { defaults } from "./defaults";
|
|
6
|
-
import { FileTable } from "./types";
|
|
7
5
|
|
|
8
6
|
export class File {
|
|
9
7
|
static BASE_URL = defaults.FILE_BASE_URL;
|
|
10
8
|
|
|
11
9
|
static fromPath = (path: string) => new File(relative(this.BASE_URL, path));
|
|
12
10
|
|
|
13
|
-
static fromUrl = (table: FileTable, url: string, spinner?: Ora) =>
|
|
14
|
-
table
|
|
15
|
-
.accessSome([url], spinner)
|
|
16
|
-
.then(([{ name, checksum }]) => new File(name).verified(checksum));
|
|
17
|
-
|
|
18
11
|
constructor(public name: string) {}
|
|
19
12
|
|
|
20
13
|
get path() {
|
package/src/table.ts
CHANGED
|
@@ -18,8 +18,10 @@ import { resolve } from "path";
|
|
|
18
18
|
import { mergeMap, NextObserver, Subject, Subscription } from "rxjs";
|
|
19
19
|
import { v4 } from "uuid";
|
|
20
20
|
import { defaults } from "./defaults";
|
|
21
|
+
import { File } from "./file";
|
|
21
22
|
import { reduceActions } from "./observables/reduceActions";
|
|
22
23
|
import {
|
|
24
|
+
FileTableRecord,
|
|
23
25
|
TableAction,
|
|
24
26
|
TableActionCreator,
|
|
25
27
|
TableActionCreatorResult,
|
|
@@ -282,3 +284,10 @@ export const createTable = memoize(
|
|
|
282
284
|
},
|
|
283
285
|
nthArg(0),
|
|
284
286
|
);
|
|
287
|
+
|
|
288
|
+
export class FileTable extends Table<FileTableRecord, "originalUrl"> {
|
|
289
|
+
fromUrl = (url: string, spinner?: Ora) =>
|
|
290
|
+
this.accessSome([url], spinner).then(([{ name, checksum }]) =>
|
|
291
|
+
new File(name).verified(checksum),
|
|
292
|
+
);
|
|
293
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { MaybePromise } from "@cascateer/lib";
|
|
|
2
2
|
import { LazyPromise } from "@cascateer/lib/promises";
|
|
3
3
|
import { Function1 } from "lodash";
|
|
4
4
|
import { Ora } from "ora";
|
|
5
|
-
import { Table } from "./table";
|
|
6
5
|
|
|
7
6
|
interface BaseTableAction<Type> {
|
|
8
7
|
id: string;
|
|
@@ -73,5 +72,3 @@ export interface FileTableRecord {
|
|
|
73
72
|
name: string;
|
|
74
73
|
checksum: string;
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
export interface FileTable extends Table<FileTableRecord, "originalUrl"> {}
|