Skip to content

Commit

Permalink
Merge pull request #4 from jrfso/next
Browse files Browse the repository at this point in the history
v0.2.0 Simplify generic types, export mutative helpers
  • Loading branch information
waynesbrain authored Oct 5, 2024
2 parents 393c15c + c7fa52a commit 18b8925
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 181 deletions.
4 changes: 2 additions & 2 deletions labs/demo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"start-win": "nodemon",
"start-bin": "node bin/jrfs-demo-server.cjs",
"test": "echo 'Sorry, no tests yet!'",
"watch": "tsc -w --noEmit --pretty --skipLibCheck --project tsconfig.eslint.json",
"watch-build": "node --watch-path=./src --watch-path=../../node_modules/@jrfs ../../scripts/build-esm.mjs"
"watch": "node --watch-path=./src --watch-path=../../node_modules/@jrfs ../../scripts/build-esm.mjs",
"watch-ts": "tsc -w --noEmit --pretty --skipLibCheck --project tsconfig.eslint.json"
},
"nodemonConfig": {
"delay": "250ms",
Expand Down
1 change: 0 additions & 1 deletion labs/demo-server/src/api/project/repo/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { apply } from "mutative";
// Local
import { Maybe, Tags, Type, Static, apiController, define } from "@/common/api";
import { Entry, TransactionOutParams } from "@jrfs/node";
Expand Down
2 changes: 1 addition & 1 deletion labs/demo-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint-fix": "eslint . --ext .ts --fix",
"lint-ts": "tsc --noEmit --pretty --project ./tsconfig.eslint.json",
"rm-build": "shx rm -rf lib/*",
"watch-build": "node --watch-path=./src --watch-path=../../node_modules/@jrfs ../../scripts/build-esm.mjs lib --tsconfig tsconfig.prod.json"
"watch": "node --watch-path=./src --watch-path=../../node_modules/@jrfs ../../scripts/build-esm.mjs lib --tsconfig tsconfig.prod.json"
},
"dependencies": {
"nanoid": "^5.0.7"
Expand Down
77 changes: 47 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jrfs/core",
"version": "0.1.0",
"version": "0.2.0",
"description": "JRFS core library.",
"repository": "github:jrfso/jrfs",
"homepage": "https://github.com/jrfso/jrfs/tree/master/packages/core",
Expand Down Expand Up @@ -32,7 +32,7 @@
"lint-fix": "eslint . --ext .ts --fix",
"lint-ts": "tsc --noEmit --pretty --project ./tsconfig.eslint.json",
"rm-build": "shx rm -rf lib/*",
"watch-build": "node --watch-path=./src ../../scripts/build-esm.mjs lib --tsconfig tsconfig.prod.json"
"watch": "node --watch-path=./src ../../scripts/build-esm.mjs lib --tsconfig tsconfig.prod.json"
},
"dependencies": {
"mutative": "1.0.11"
Expand Down
36 changes: 15 additions & 21 deletions packages/core/src/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import type {
Entry,
FileTree,
FileTypeProvider,
FileTypes,
MutativePatches,
} from "@/index";
import { type CreateShortIdFunction } from "@/helpers";
import { INTERNAL } from "@/internal/types";
import { WritableFileTree } from "@/WritableFileTree";

/** Base JRFS driver class. */
export abstract class Driver<FT extends FileTypes<FT>> {
#fileTree: WritableFileTree;
#fileTypes: FileTypeProvider<FT>;
export abstract class Driver {
#createShortId: CreateShortIdFunction;
#fileTree = null! as WritableFileTree;
#fileTypes: FileTypeProvider<any>;
/** `true` if {@link open}, `false` if {@link close}d */
#opened = false;

constructor(props: DriverProps<FT>) {
this.#fileTree = WritableFileTree[INTERNAL].create(
props.fileTree,
props.createShortId,
);
constructor(props: DriverProps) {
this.#createShortId = props.createShortId;
this.#fileTypes = props.fileTypes;
}

Expand Down Expand Up @@ -63,11 +60,15 @@ export abstract class Driver<FT extends FileTypes<FT>> {
/** Handles opening the repo. */
protected abstract onOpen(): Promise<void>;

async open() {
async open(fileTree: FileTree) {
const opened = this.#opened;
if (opened) {
throw new Error(`Driver has already opened ${this}`);
}
this.#fileTree = WritableFileTree[INTERNAL].create(
fileTree,
this.#createShortId,
);
await this.onOpen();
// Save state.
this.#opened = true;
Expand Down Expand Up @@ -164,15 +165,11 @@ export interface TransactionParams {
}

/** Callback to create a driver. */
export type DriverFactory = <FT extends FileTypes<FT>>(
props: DriverProps<FT>,
options: any,
) => Driver<FT>;
export type DriverFactory = (props: DriverProps, options: any) => Driver;

export interface DriverProps<FT extends FileTypes<FT>> {
export interface DriverProps {
createShortId: CreateShortIdFunction;
fileTypes: FileTypeProvider<FT>;
fileTree: FileTree;
fileTypes: FileTypeProvider<any>;
}
/**
* Interface to declare a driver options types onto.
Expand All @@ -187,9 +184,6 @@ export interface DriverTypeOptions {
// e.g. ["fs"]: FsDriverOptions;
}
/** Interface to declare driver types onto. */
export interface DriverTypes<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
FT extends FileTypes<FT>,
> {
export interface DriverTypes {
// e.g. ["fs"]: FsDriver;
}
Loading

0 comments on commit 18b8925

Please sign in to comment.