Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup, expand README, fix some minor bugs #20

Merged
merged 31 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8c4e5d8
various fixes (read changelog)
3vorp Apr 14, 2024
ae8d871
update dependencies
3vorp Apr 14, 2024
2f5896d
more changes, read changelog
3vorp Apr 16, 2024
0193afa
fix lockfile problems
3vorp Apr 16, 2024
9b745d2
grammar
3vorp Apr 16, 2024
bd7af19
fix public/private class conflict
3vorp Apr 16, 2024
0f6565b
remove trailing whitespace
3vorp Apr 17, 2024
7b21d15
fix array-splice conflicts, typos, style
3vorp Apr 17, 2024
17c4776
quick type fix
3vorp Apr 18, 2024
3966df3
fix platform-specific nested key issue
3vorp Apr 19, 2024
7f32430
optional JSONDatabase constructor, shuffle readme
3vorp Apr 20, 2024
3944c63
quick fix to delete $props
3vorp Apr 20, 2024
1fd6b92
quick readme fix
3vorp Apr 20, 2024
cefdf0a
"advanced" readme section
3vorp Apr 21, 2024
945865a
clean up jsdoc
3vorp Apr 22, 2024
298f2b3
move around a few sections
3vorp Apr 22, 2024
b702ed2
refactor php to be cleaner and more readable
3vorp Apr 22, 2024
1fa5907
add more tests to collection.values()
3vorp Apr 22, 2024
e07e526
fix posix end of file stuff
3vorp Apr 22, 2024
38af96b
rename concernedField to field
3vorp Apr 23, 2024
9474723
don't start a method with double underscores
3vorp Apr 24, 2024
31a2fb8
run php formatter
3vorp Apr 28, 2024
e1ab419
add some utility methods, fix remove() error
3vorp Apr 28, 2024
c0d41e4
revert sec() and token changes
3vorp Apr 30, 2024
f21ef49
Merge branch 'TheRolfFR:main' into main
3vorp Apr 30, 2024
d2c06aa
array-contains-none
3vorp Apr 30, 2024
2cde398
better browser check, last-minute readme changes
3vorp May 1, 2024
dd17eda
readRaw(original = false)
3vorp May 3, 2024
a39b98f
fix many editField problems
3vorp May 4, 2024
6dd4aa2
editField operations return confirmations
3vorp May 7, 2024
ab42fe8
fix unknown operation message, jsdoc
3vorp May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
php/tokens.php
php/config.php
files/*
node_modules
*.log
.vscode/

# NPM RC WITH SENSIBLE INFOS
# NPM RC WITH SENSITIVE INFO
\.npmrc

### Node ###
Expand Down Expand Up @@ -129,5 +127,5 @@ dist
.pnp.*

#jsdoc
docs/
.DS_Store
docs/
.DS_Store
41 changes: 38 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,42 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.12.0]
## Unreleased

### Added

- Exposed `Collection.collectionName` as a readonly property for TypeScript usage.
- TypeScript overview to the README.
- Optional replacement argument for `array-splice` edit fields.
- `array-contains-none` option for array fields.
- Optional constructor for the `JSONDatabase` PHP class to reduce repetitive code.
- "Advanced" section to the README for previously undocumented features.
- `original` option for `readRaw` to not insert ID fields, for easier non-relational collection usage.

### Changed

- Rejected incorrect parameters are now `TypeError`s instead of regular `Error`s.
- Deprecated `firestorm.table(name)` method, since `firestorm.collection(name)` does exactly the same thing.
- Reformatted the repository and improved README.md to make it easier to set up Firestorm.
- Clean up and standardize JSDoc comments.
- `editField` and `editFieldBulk` now return confirmations like all other write methods.
- `editField` and `editFieldBulk` now reject with a descriptive error message on failure rather than silently failing.

### Fixed

- PHP-level errors not being rejected properly in GET requests.
- Certain write commands mutating data internally and affecting parameters outside Firestorm.
- `Collection.searchKeys` and `Collection.values` not returning proper `Error` objects sometimes.
- `files.upload` not allowing the `form-data` package's typing of `FormData` in TypeScript.
- Inconsistent use of indentation and formatting in PHP files.
- Various typos in PHP files.
- `Collection` class being exported in TypeScript despite the actual class being private.
- `array-splice` edit fields being incorrectly typed as `array-slice`.
- Platform-specific PHP error when searching nested keys.
- `Collection.remove` rejecting numeric keys, despite `Collection.removeBulk` not doing so.
- `editField` and `editFieldBulk` validation issues.

## [1.12.0] - 2024-02-22

### Added

Expand All @@ -14,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Refactored JavaScript part to be less verbose and reuse existing code better.
- Use JSDoc `{@link }` properties.
- Added JSDoc `{@link }` properties.
- Cleaned up and clarified README.md.
- Renamed `AllCriteria` to `AnyCriteria` to be more accurate.
- Replaced broken `NoMethods<T>` type with a more generalized `RemoveMethods<T>` type.
Expand Down Expand Up @@ -76,4 +111,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- crypto module as it is now deprecated and a built-in node package
- `crypto` module as it is now deprecated and a built-in node package
479 changes: 320 additions & 159 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"keyword": "firebase,firestore,db,api,php,micro-operations,bulk"
},
"menu": {
"Github repo": {
"Repository": {
"href": "https://github.com/TheRolfFR/firestorm",
"target": "_blank",
"class": "menu-item",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"full": "npm run php_stop ; npm run php_start && npm run test ; npm run php_stop",
"local_tests": "sudo act -P ubuntu-latest=shivammathur/node:latest -j js-wrapper-test",
"jsdoc": "jsdoc src/index.js -c jsdoc.json -R README.md -t ./node_modules/docdash -d out",
"nodemon_jsdoc": "nodemon -x npm run jsdoc --watch src/index.js --watch jsdoc.json",
"nodemon_jsdoc": "nodemon -x npm run jsdoc --watch src/index.js --watch jsdoc.json --watch README.md",
"types": "npx tsc",
"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"
Expand Down Expand Up @@ -39,19 +39,19 @@
"typings/index.d.ts"
],
"dependencies": {
"axios": "^1.6.7"
"axios": "^1.6.8",
"form-data": "^4.0.0"
},
"devDependencies": {
"chai": "^4.4.1",
"docdash": "^2.0.2",
"form-data": "^4.0.0",
"glob": "^10.3.10",
"glob": "^10.3.12",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.1",
"mocha": "^10.3.0",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"prettier": "^3.2.5",
"recursive-copy": "^2.0.14",
"typescript": "^5.3.3"
"typescript": "^5.4.5"
}
}
File renamed without changes.
61 changes: 61 additions & 0 deletions php/classes/FileAccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

class FileAccess {
public static function read($filepath, $waitLock = false, $default = null) {
$fileObj = array('filepath' => $filepath, 'content' => '');
// open file as binary
$file = fopen($filepath, 'rb');

// exit if couldn't find file
if ($file === false) {
if ($default == null)
throw new Exception("Could not open file: $filepath");

// set default value
$fileObj['content'] = $default;
}

// if no file, puts default value inside
if ($file === false) {
file_put_contents($fileObj['filepath'], $fileObj['content'], LOCK_EX);
$file = fopen($filepath, 'rb');
}

$fileObj['fd'] = $file;

// if want the lock, we wait for the shared lock
if ($waitLock) {
$lock = flock($file, LOCK_SH);
if (!$lock) {
fclose($file);
throw new Exception('Failed to lock file');
}
}

// read file content
$string = '';
while (!feof($file)) {
$string .= fread($file, 8192);
}

$fileObj['content'] = $string;

// if no wait you can close the file
if (!$waitLock)
fclose($file);

return $fileObj;
}
public static function write($fileObj) {
// lock and close
flock($fileObj['fd'], LOCK_UN);
fclose($fileObj['fd']);

if (!is_writable($fileObj['filepath'])) {
throw new HTTPException("PHP script can't write to file. Check permission, group and owner.", 400);
}

$ret = file_put_contents($fileObj['filepath'], $fileObj['content'], LOCK_EX);
return $ret;
}
}
23 changes: 23 additions & 0 deletions php/classes/HTTPException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class HTTPException extends Exception {
// custom message
public function __construct($message, $code = 400, Throwable $previous = null) {
$type_message = gettype($message);

if ($type_message != 'string')
throw new Exception("Incorrect message type for HTTPException constructor, expected string, got $type_message");

$type_code = gettype($code);
if ($type_code != 'integer')
throw new Exception("Incorrect code type for HTTPException constructor, expected string, got $type_code");

// assign everything
parent::__construct($message, $code, $previous);
}

// prettier representation
public function __toString(): string {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
}
Loading
Loading