-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33ac293
commit 7ea72fc
Showing
17 changed files
with
1,096 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["simple-import-sort", "solid"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:solid/typescript" | ||
], | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_" }], | ||
"no-unused-vars": "off", | ||
"simple-import-sort/imports": "error", | ||
"simple-import-sort/exports": "error" | ||
}, | ||
"ignorePatterns": ["dist", "node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"name": "@fireproof/solid-js", | ||
"version": "0.1.0", | ||
"description": "Convenience hooks for using Fireproof in SolidJS applications", | ||
"type": "module", | ||
"module": "./dist/server.js", | ||
"main": "./dist/server.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"browser": { | ||
"./dist/server.js": "./dist/index.js" | ||
}, | ||
"exports": { | ||
"worker": { | ||
"solid": "./dist/server.jsx", | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/server.js" | ||
} | ||
}, | ||
"browser": { | ||
"solid": "./dist/index.jsx", | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"deno": { | ||
"solid": "./dist/server.jsx", | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/server.js" | ||
} | ||
}, | ||
"node": { | ||
"solid": "./dist/server.jsx", | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/server.js" | ||
} | ||
}, | ||
"solid": "./dist/index.jsx", | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"typesVersions": {}, | ||
"author": "Daniel Sanchez", | ||
"license": "Apache-2.0 OR MIT", | ||
"homepage": "https://use-fireproof.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/fireproof-storage/fireproof.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fireproof-storage/fireproof/issues" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "cp ../../README.md . && pnpm build", | ||
"postpublish": "rm README.md", | ||
"build": "tsup", | ||
"build:clean": "rm -rf dist", | ||
"build:watch:solid": "tsup --watch", | ||
"clean": "rm -rf node_modules", | ||
"format:check": "prettier . --check", | ||
"format:fix": "prettier . --write", | ||
"lint:check": "eslint . --ext .ts,.tsx", | ||
"lint:fix": "eslint . --ext .ts,.tsx --fix", | ||
"test": "vitest run", | ||
"test:cov": "vitest run --coverage" | ||
}, | ||
"dependencies": { | ||
"@fireproof/core": "workspace:^", | ||
"deepmerge-ts": "^5.1.0" | ||
}, | ||
"peerDependencies": { | ||
"solid-js": ">=1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@solidjs/router": "^0.10.5", | ||
"@vitest/coverage-istanbul": "^1.1.0", | ||
"buffer": "^6.0.3", | ||
"esbuild": "^0.19.10", | ||
"eslint": "^8.56.0", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-solid": "^0.13.0", | ||
"fake-indexeddb": "^5.0.1", | ||
"prettier": "^3.1.1", | ||
"solid-js": "^1.8.7", | ||
"tsup-preset-solid": "^2.2.0", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12", | ||
"vite-plugin-solid": "^2.9.1", | ||
"vitest": "^1.2.2" | ||
}, | ||
"keywords": [ | ||
"solid", | ||
"database", | ||
"json", | ||
"live", | ||
"sync" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
arrowParens: "always", | ||
bracketSpacing: true, | ||
endOfLine: "lf", | ||
printWidth: 120, | ||
semi: true, | ||
singleQuote: false, | ||
tabWidth: 2, | ||
trailingComma: "es5", | ||
useTabs: false, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "fake-indexeddb/auto"; | ||
|
||
import { Buffer } from "buffer"; | ||
import { TextEncoder } from "util"; | ||
|
||
global.TextEncoder = TextEncoder; | ||
global.Buffer = Buffer; |
114 changes: 114 additions & 0 deletions
114
packages/solid-js/src/__tests__/createFireproof.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { createRoot } from "solid-js"; | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { createFireproof } from "../createFireproof"; | ||
|
||
type TestDoc = { text: string; completed: boolean }; | ||
|
||
const sleepHalfSecond = (ms: number = 500) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
describe("HOOK: createFireproof", () => { | ||
test("can perform all expected actions", async () => { | ||
await createRoot(async (dispose) => { | ||
const { database, createDocument, createLiveQuery } = createFireproof("TestDB"); | ||
const [doc, setDoc, saveDoc] = createDocument<TestDoc>(() => ({ text: "", completed: false })); | ||
const query = createLiveQuery("_id"); | ||
await sleepHalfSecond(); // wait for the initial createDocument effect to finish | ||
|
||
// 1. Can initialize a document | ||
expect(doc()).toEqual({ text: "", completed: false }); | ||
|
||
// 2. Can update the document | ||
setDoc({ text: "hello", completed: true }); | ||
expect(doc()).toEqual({ text: "hello", completed: true }); | ||
expect((await database().allDocs()).rows).toEqual([]); | ||
expect(query().docs).toEqual([]); | ||
|
||
// 3. Can save the document to the database | ||
const { id } = await saveDoc(); | ||
expect(await database().get<TestDoc>(id)).toEqual({ _id: id, text: "hello", completed: true }); | ||
expect(doc()).toEqual({ _id: id, text: "hello", completed: true }); | ||
|
||
await sleepHalfSecond(); | ||
expect(query().docs).toEqual([ | ||
{ | ||
_id: id, | ||
text: "hello", | ||
completed: true, | ||
}, | ||
]); | ||
|
||
// 4. Can locally update the same document (retaining _id info post first save) | ||
setDoc({ text: "world", completed: false }); | ||
expect(doc()).toEqual({ _id: id, text: "world", completed: false }); | ||
expect(await database().get<TestDoc>(id)).toEqual({ _id: id, text: "hello", completed: true }); | ||
expect(query().docs).toEqual([ | ||
{ | ||
_id: id, | ||
text: "hello", | ||
completed: true, | ||
}, | ||
]); | ||
|
||
// 5. Can update the stored document | ||
await saveDoc(); | ||
expect(await database().get<TestDoc>(id)).toEqual({ _id: id, text: "world", completed: false }); | ||
expect(doc()).toEqual({ _id: id, text: "world", completed: false }); | ||
|
||
await sleepHalfSecond(); | ||
expect(query().docs).toEqual([ | ||
{ | ||
_id: id, | ||
text: "world", | ||
completed: false, | ||
}, | ||
]); | ||
|
||
// 6. Can start anew with another document | ||
setDoc(); | ||
expect(doc()).toEqual({ text: "", completed: false }); | ||
|
||
// 7. Can update the new document | ||
setDoc({ text: "foo", completed: true }); | ||
expect(doc()).toEqual({ text: "foo", completed: true }); | ||
|
||
// 8. Can save the new document | ||
const { id: id2 } = await saveDoc(); | ||
expect(doc()).toEqual({ _id: id2, text: "foo", completed: true }); | ||
expect(await database().get<TestDoc>(id2)).toEqual({ _id: id2, text: "foo", completed: true }); | ||
|
||
await sleepHalfSecond(); | ||
expect(query().docs).toEqual([ | ||
{ | ||
_id: id, | ||
text: "world", | ||
completed: false, | ||
}, | ||
{ | ||
_id: id2, | ||
text: "foo", | ||
completed: true, | ||
}, | ||
]); | ||
|
||
// Test cleanup to not keep data in the database across tests | ||
await database().del(id); | ||
await database().del(id2); | ||
|
||
expect( | ||
await database() | ||
.get(id) | ||
.catch(() => null) | ||
).toBeNull(); | ||
|
||
expect( | ||
await database() | ||
.get(id2) | ||
.catch(() => null) | ||
).toBeNull(); | ||
|
||
expect(query().docs).toEqual([]); | ||
dispose(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.