@cascateer/database 0.0.3 → 0.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/database",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/database.git"
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,16 @@ export const createTable = memoize(
282
284
  },
283
285
  nthArg(0),
284
286
  );
287
+
288
+ export const createFileTable = (
289
+ id: string,
290
+ key: "url",
291
+ records: TableRecordCreator<FileTableRecord, "url">,
292
+ ) => createTable<FileTableRecord, "url">(id, key, records);
293
+
294
+ export class FileTable extends Table<FileTableRecord, "url"> {
295
+ toFile = (url: string, spinner?: Ora) =>
296
+ this.accessSome([url], spinner).then(([{ name, checksum }]) =>
297
+ new File(name).verified(checksum),
298
+ );
299
+ }
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;
@@ -69,9 +68,7 @@ export interface TableRecordCreator<R, K extends keyof R> {
69
68
  }
70
69
 
71
70
  export interface FileTableRecord {
72
- originalUrl: string;
71
+ url: string;
73
72
  name: string;
74
73
  checksum: string;
75
74
  }
76
-
77
- export interface FileTable extends Table<FileTableRecord, "originalUrl"> {}