@cascateer/database 0.0.6 → 0.0.7

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.6",
3
+ "version": "0.0.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/database.git"
package/src/table.ts CHANGED
@@ -21,6 +21,7 @@ import { defaults } from "./defaults";
21
21
  import { File } from "./file";
22
22
  import { reduceActions } from "./observables/reduceActions";
23
23
  import {
24
+ FileTable,
24
25
  FileTableRecord,
25
26
  TableAction,
26
27
  TableActionCreator,
@@ -266,20 +267,22 @@ export const createTable = memoize(
266
267
  constructor() {
267
268
  super(id, key, records, TableInstance.actions);
268
269
 
269
- TableInstance.actionsSubscription ??= TableInstance.actions
270
- .pipe(
271
- reduceActions(this.applyActions, this.readActions),
272
- mergeMap(async (action) => {
273
- const path = resolve(this.path, `${action.id}.json`);
270
+ TableInstance.actionsSubscription ??=
271
+ (console.log(id, key),
272
+ TableInstance.actions
273
+ .pipe(
274
+ reduceActions(this.applyActions, this.readActions),
275
+ mergeMap(async (action) => {
276
+ const path = resolve(this.path, `${action.id}.json`);
274
277
 
275
- if (!existsSync(path)) {
276
- await writeFile(path, JSON.stringify(action));
277
- }
278
+ if (!existsSync(path)) {
279
+ await writeFile(path, JSON.stringify(action));
280
+ }
278
281
 
279
- return action;
280
- }),
281
- )
282
- .subscribe();
282
+ return action;
283
+ }),
284
+ )
285
+ .subscribe());
283
286
  }
284
287
  },
285
288
  nthArg(0),
@@ -287,13 +290,14 @@ export const createTable = memoize(
287
290
 
288
291
  export const createFileTable = (
289
292
  id: string,
290
- key: "url",
291
293
  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
- }
294
+ ) =>
295
+ class
296
+ extends createTable<FileTableRecord, "url">(id, "url", records)
297
+ implements FileTable
298
+ {
299
+ toFile = (url: string, spinner?: Ora) =>
300
+ this.accessSome([url], spinner).then(([{ name, checksum }]) =>
301
+ new File(name).verified(checksum),
302
+ );
303
+ };
package/src/types.ts CHANGED
@@ -2,6 +2,8 @@ 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 { File } from "./file";
6
+ import { Table } from "./table";
5
7
 
6
8
  interface BaseTableAction<Type> {
7
9
  id: string;
@@ -72,3 +74,7 @@ export interface FileTableRecord {
72
74
  name: string;
73
75
  checksum: string;
74
76
  }
77
+
78
+ export interface FileTable extends Table<FileTableRecord, "url"> {
79
+ toFile: (url: string, spinner?: Ora) => Promise<File>;
80
+ }