Skip to content

Commit

Permalink
Fix incorrect method injection types, prettier for TypeScript, incorr…
Browse files Browse the repository at this point in the history
…ect stuff in the script itself (#15)

* fix Exception instead of Error

* fix prettier for typescript, attempt fix for #14

* fix tests and use generics properly

* recursive keyof (thanks @Juknum ) and fix files

* technically more accurate file type

since it's not technically an instantiable class this is the next closest thing

* tons of fixes, compiles on faithful api now

- remove really outdated jsdoc types (they're already inline)
- fix casing style to use standard PascalCase everywhere instead of random snake_case criteria
- remove unnecessary collection method generics
- removed Addable<T> and Raw<T> in favor of their generic typescript counterparts
- add Writable<T> as a shorthand for removing methods and the id field for setting or adding items
- use lowercase types in jsdoc (better practice)

* update dependencies and remove itself as dependency

* use es6 style function notation and objects

you're already using let and const which are es6 keywords so it's not like you're doing this for legacy compatibility

* BREAKING CHANGE: camelCase read_raw and write_raw

still support old ones through aliasing, but this should probably be a version bump

* Revert package.json changes
  • Loading branch information
3vorp authored Dec 17, 2023
1 parent 56113be commit 7b76283
Show file tree
Hide file tree
Showing 10 changed files with 531 additions and 490 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The JavaScript [index.js](./src/index.js) file is just an [Axios](https://www.np

## How to use it

First, you need to configure the address of the API, and your token if needed:
First, you need to configure your API address, and your token if needed:

```js
require("dotenv").config(); // add some env variables
Expand All @@ -49,7 +49,7 @@ const userCollection = firestorm.collection("users");

// all methods return promises
userCollection
.read_raw()
.readRaw()
.then((res) => console.log(res))
.catch((err) => console.error(err));
```
Expand All @@ -58,8 +58,8 @@ userCollection

A collection takes one required argument and one optional argument:

- The name of the collection as a `String`.
- The method adder, which allows to inject methods to the get methods results. This would be a `Function` taking the element as an argument.
- The name of the collection as a `String`.
- The method adder, which allows to inject methods to the get methods results. This would be a `Function` taking the element as an argument.

```js
const firestorm = require("firestorm-db");
Expand Down Expand Up @@ -92,9 +92,9 @@ Available methods for a collection:
| select(selectOption) | selectOption: `{ field: String[] }` | Improved read_raw with field selection |
| random(max, seed, offset) | max?: `Integer >= -1` seed?: `Integer` offset?:`Integer >= 0` | Reads random entries of collection |

Search method can take one or more options to filter entries in a collection. A search option studies a `field` with a `criteria` and compares it to a `value`. On string values you can now use the boolean `ignoreCase` option.
The search method can take one or more options to filter entries in a collection. A search option studies a `field` with a `criteria` and compares it to a `value`. You can also use the boolean `ignoreCase` option for string values.

Not all criterias are available depending the field type. There are more options available than the firestore `where` command, allowing you to get better and faster search results.
Not all criteria are available depending the field type. There are more options available than the firestore `where` command, allowing you to get better and faster search results.

### All search options available

Expand Down Expand Up @@ -203,12 +203,12 @@ $authorized_file_extension = array('.txt', '.png');
$STORAGE_LOCATION = dirname($_SERVER['SCRIPT_FILENAME']) . '/uploads/';
```

You can now use the wrapper functions in order to upload, get and delete a file.
You can use the wrapper functions in order to upload, get and delete a file.
If the folder is accessible from server url, you can directly type its address.

### File rights

The PHP scripts creates folders and files. So if the PHP user doesn't have the rights to write, the script will fail.
The PHP scripts create folders and files, so the script will fail if the PHP user doesn't have write permissions.
You can give rights to a folder with the following command:

```
Expand Down Expand Up @@ -254,8 +254,8 @@ firestorm.address("ADDRESS_VALUE");
const getPromise = firestorm.files.get("/quote.txt");

getPromise
.then((filecontent) => {
console.log(filecontent); // 'but your kids are gonna love it.
.then((fileContent) => {
console.log(fileContent); // 'but your kids are gonna love it.
})
.catch((err) => {
console.error(err);
Expand Down Expand Up @@ -299,7 +299,7 @@ memory_limit = 256M

## API endpoints

All Firestorm methods correspond to an equivalent Axios request. Read requests are GET request and write requests are POST requests with a JSON data.
All Firestorm methods correspond to an equivalent Axios request. Read requests are GET request and write requests are POST requests with provided JSON data.

You always have the same first keys and the one key per method:

Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"jsdoc": "jsdoc -a all -c jsdoc.json -R README.md src/index.js -d docs/jsdoc",
"nodemon_jsdoc": "nodemon -x npm run jsdoc --watch src/index.js --watch jsdoc.json",
"types": "npx tsc",
"prettier": "prettier \"{,!(node_modules)/**/}*.js\" --config .prettierrc --write",
"prettier": "prettier \"{,!(node_modules)/**/}*.{js,ts}\" --config .prettierrc --write",
"cov": "npm run php_stop ; npm run php_start && nyc --reporter=text mocha tests/**/*.spec.js; npm run php_stop"
},
"repository": {
Expand All @@ -39,9 +39,7 @@
"typings/index.d.ts"
],
"dependencies": {
"axios": "^1.6.0",
"firestorm-db": "^1.10.2",
"type-fest": "^4.6.0"
"axios": "^1.6.2"
},
"devDependencies": {
"chai": "^4.3.10",
Expand All @@ -52,8 +50,9 @@
"jsdoc-to-markdown": "^8.0.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"prettier": "^3.1.1",
"recursive-copy": "^2.0.14",
"typescript": "^5.2.2"
"type-fest": "^4.8.3",
"typescript": "^5.3.3"
}
}
61 changes: 18 additions & 43 deletions pnpm-lock.yaml

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

Loading

0 comments on commit 7b76283

Please sign in to comment.