@wxn0brp/db 0.0.4 → 0.0.6
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/README.md +3 -0
- package/dist/cjs/CollectionManager.d.ts +43 -0
- package/dist/cjs/CollectionManager.js +59 -0
- package/dist/cjs/action.d.ts +71 -0
- package/dist/cjs/action.js +199 -0
- package/dist/cjs/database.d.ts +77 -0
- package/dist/cjs/database.js +118 -0
- package/dist/cjs/executor.d.ts +28 -0
- package/{executor.js → dist/cjs/executor.js} +47 -54
- package/dist/cjs/file/find.d.ts +11 -0
- package/dist/cjs/file/find.js +80 -0
- package/dist/cjs/file/index.d.ts +3 -0
- package/dist/cjs/file/index.js +25 -0
- package/dist/cjs/file/remove.d.ts +7 -0
- package/dist/cjs/file/remove.js +61 -0
- package/dist/cjs/file/update.d.ts +7 -0
- package/dist/cjs/file/update.js +68 -0
- package/dist/cjs/file/utils.d.ts +8 -0
- package/dist/cjs/file/utils.js +23 -0
- package/dist/cjs/format.d.ts +18 -0
- package/dist/cjs/format.js +36 -0
- package/dist/cjs/gen.d.ts +5 -0
- package/dist/cjs/gen.js +78 -0
- package/dist/cjs/graph.d.ts +47 -0
- package/dist/cjs/graph.js +90 -0
- package/{index.d.ts → dist/cjs/index.d.ts} +2 -2
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/relation.d.ts +64 -0
- package/{relation.js → dist/cjs/relation.js} +26 -45
- package/dist/cjs/remote/client/database.d.ts +71 -0
- package/dist/cjs/remote/client/database.js +145 -0
- package/dist/cjs/remote/client/function.d.ts +5 -0
- package/dist/cjs/remote/client/function.js +32 -0
- package/dist/cjs/remote/client/graph.d.ts +54 -0
- package/dist/cjs/remote/client/graph.js +93 -0
- package/dist/cjs/remote/client/remote.d.ts +16 -0
- package/dist/cjs/remote/client/remote.js +2 -0
- package/dist/cjs/remote/server/auth.d.ts +31 -0
- package/dist/cjs/remote/server/auth.js +99 -0
- package/dist/cjs/remote/server/db.d.ts +2 -0
- package/dist/cjs/remote/server/db.js +223 -0
- package/dist/cjs/remote/server/function.d.ts +2 -0
- package/dist/cjs/remote/server/function.js +89 -0
- package/dist/cjs/remote/server/graph.d.ts +2 -0
- package/dist/cjs/remote/server/graph.js +145 -0
- package/dist/cjs/remote/server/index.d.ts +1 -0
- package/dist/cjs/remote/server/index.js +66 -0
- package/dist/cjs/remote/server/initDataBases.d.ts +1 -0
- package/dist/cjs/remote/server/initDataBases.js +25 -0
- package/dist/cjs/remote/server/pathUtils.d.ts +1 -0
- package/dist/cjs/remote/server/pathUtils.js +12 -0
- package/dist/cjs/remote/server/secret.d.ts +1 -0
- package/dist/cjs/remote/server/secret.js +25 -0
- package/dist/cjs/remote/serverMgmt/index.d.ts +1 -0
- package/dist/cjs/remote/serverMgmt/index.js +87 -0
- package/dist/cjs/types/Id.d.ts +3 -0
- package/dist/cjs/types/Id.js +2 -0
- package/dist/cjs/types/arg.d.ts +6 -0
- package/dist/cjs/types/arg.js +2 -0
- package/dist/cjs/types/data.d.ts +4 -0
- package/dist/cjs/types/data.js +2 -0
- package/dist/cjs/types/options.d.ts +12 -0
- package/dist/cjs/types/options.js +2 -0
- package/dist/cjs/types/searchOpts.d.ts +61 -0
- package/dist/cjs/types/searchOpts.js +8 -0
- package/dist/cjs/types/types.d.ts +6 -0
- package/dist/cjs/types/types.js +2 -0
- package/dist/cjs/utils/hasFields.d.ts +8 -0
- package/dist/cjs/utils/hasFields.js +22 -0
- package/dist/cjs/utils/hasFieldsAdvanced.d.ts +5 -0
- package/dist/cjs/utils/hasFieldsAdvanced.js +182 -0
- package/dist/cjs/utils/updateFindObject.d.ts +11 -0
- package/dist/cjs/utils/updateFindObject.js +32 -0
- package/dist/cjs/utils/updateObject.d.ts +8 -0
- package/dist/cjs/utils/updateObject.js +18 -0
- package/dist/esm/CollectionManager.d.ts +43 -0
- package/dist/esm/CollectionManager.js +57 -0
- package/dist/esm/action.d.ts +71 -0
- package/dist/esm/action.js +194 -0
- package/dist/esm/database.d.ts +77 -0
- package/dist/esm/database.js +113 -0
- package/dist/esm/executor.d.ts +28 -0
- package/dist/esm/executor.js +45 -0
- package/dist/esm/file/find.d.ts +11 -0
- package/dist/esm/file/find.js +73 -0
- package/dist/esm/file/index.d.ts +3 -0
- package/{file → dist/esm/file}/index.js +1 -1
- package/dist/esm/file/remove.d.ts +7 -0
- package/dist/esm/file/remove.js +56 -0
- package/dist/esm/file/update.d.ts +7 -0
- package/dist/esm/file/update.js +63 -0
- package/dist/esm/file/utils.d.ts +8 -0
- package/{file → dist/esm/file}/utils.js +3 -11
- package/dist/esm/format.d.ts +18 -0
- package/{format.js → dist/esm/format.js} +29 -29
- package/dist/esm/gen.d.ts +5 -0
- package/dist/esm/gen.js +75 -0
- package/dist/esm/graph.d.ts +47 -0
- package/dist/esm/graph.js +85 -0
- package/dist/esm/index.d.ts +7 -0
- package/{index.js → dist/esm/index.js} +1 -9
- package/dist/esm/relation.d.ts +64 -0
- package/dist/esm/relation.js +65 -0
- package/dist/esm/remote/client/database.d.ts +71 -0
- package/dist/esm/remote/client/database.js +140 -0
- package/dist/esm/remote/client/function.d.ts +5 -0
- package/dist/esm/remote/client/function.js +30 -0
- package/dist/esm/remote/client/graph.d.ts +54 -0
- package/dist/esm/remote/client/graph.js +88 -0
- package/dist/esm/remote/client/remote.d.ts +16 -0
- package/dist/esm/remote/client/remote.js +1 -0
- package/dist/esm/remote/server/auth.d.ts +31 -0
- package/{remote → dist/esm/remote}/server/auth.js +31 -44
- package/dist/esm/remote/server/db.d.ts +2 -0
- package/dist/esm/remote/server/db.js +218 -0
- package/dist/esm/remote/server/function.d.ts +2 -0
- package/dist/esm/remote/server/function.js +87 -0
- package/dist/esm/remote/server/graph.d.ts +2 -0
- package/{remote → dist/esm/remote}/server/graph.js +62 -55
- package/dist/esm/remote/server/gui/css/main.css +130 -0
- package/dist/esm/remote/server/gui/css/scrool.css +81 -0
- package/dist/esm/remote/server/gui/css/style.css +61 -0
- package/dist/esm/remote/server/gui/favicon.svg +12 -0
- package/dist/esm/remote/server/gui/html/data.html +15 -0
- package/dist/esm/remote/server/gui/html/main.html +46 -0
- package/dist/esm/remote/server/gui/html/nav.html +25 -0
- package/dist/esm/remote/server/gui/html/popup.html +51 -0
- package/dist/esm/remote/server/gui/index.html +49 -0
- package/dist/esm/remote/server/gui/js/api.js +166 -0
- package/dist/esm/remote/server/gui/js/index.js +17 -0
- package/dist/esm/remote/server/gui/js/loadHTML.js +16 -0
- package/dist/esm/remote/server/gui/js/popUp.js +72 -0
- package/dist/esm/remote/server/gui/js/queryApi.js +51 -0
- package/dist/esm/remote/server/gui/js/queryDb.js +79 -0
- package/dist/esm/remote/server/gui/js/queryGraph.js +144 -0
- package/dist/esm/remote/server/gui/js/render.js +64 -0
- package/dist/esm/remote/server/gui/js/templates.js +31 -0
- package/dist/esm/remote/server/gui/js/utils.js +36 -0
- package/dist/esm/remote/server/gui/js/vars.js +9 -0
- package/dist/esm/remote/server/gui/libs/core.js +176 -0
- package/dist/esm/remote/server/gui/libs/d3.v7.min.js +2 -0
- package/dist/esm/remote/server/gui/libs/handlebars.min.js +29 -0
- package/dist/esm/remote/server/gui/libs/json5.min.js +1 -0
- package/dist/esm/remote/server/index.d.ts +1 -0
- package/dist/esm/remote/server/index.js +61 -0
- package/dist/esm/remote/server/initDataBases.d.ts +1 -0
- package/dist/esm/remote/server/initDataBases.js +20 -0
- package/dist/esm/remote/server/pathUtils.d.ts +1 -0
- package/{remote → dist/esm/remote}/server/pathUtils.js +2 -3
- package/dist/esm/remote/server/secret.d.ts +1 -0
- package/{remote → dist/esm/remote}/server/secret.js +3 -7
- package/dist/esm/remote/serverMgmt/index.d.ts +1 -0
- package/{remote → dist/esm/remote}/serverMgmt/index.js +27 -31
- package/dist/esm/types/Id.d.ts +3 -0
- package/dist/esm/types/Id.js +1 -0
- package/dist/esm/types/arg.d.ts +6 -0
- package/dist/esm/types/arg.js +1 -0
- package/dist/esm/types/data.d.ts +4 -0
- package/dist/esm/types/data.js +1 -0
- package/dist/esm/types/options.d.ts +12 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/searchOpts.d.ts +61 -0
- package/dist/esm/types/searchOpts.js +7 -0
- package/dist/esm/types/types.d.ts +6 -0
- package/dist/esm/types/types.js +1 -0
- package/dist/esm/utils/hasFields.d.ts +8 -0
- package/{utils → dist/esm/utils}/hasFields.js +4 -4
- package/dist/esm/utils/hasFieldsAdvanced.d.ts +5 -0
- package/dist/esm/utils/hasFieldsAdvanced.js +176 -0
- package/dist/esm/utils/updateFindObject.d.ts +11 -0
- package/{utils → dist/esm/utils}/updateFindObject.js +11 -16
- package/dist/esm/utils/updateObject.d.ts +8 -0
- package/{utils → dist/esm/utils}/updateObject.js +4 -4
- package/package.json +55 -36
- package/CollectionManager.js +0 -119
- package/action.js +0 -258
- package/database.d.ts +0 -44
- package/database.js +0 -203
- package/docs/database.md +0 -140
- package/docs/graph.md +0 -86
- package/docs/relation.md +0 -51
- package/docs/remote.md +0 -30
- package/docs/remote_server.md +0 -35
- package/docs/search_opts.md +0 -227
- package/file/find.js +0 -89
- package/file/remove.js +0 -74
- package/file/update.js +0 -83
- package/gen.d.ts +0 -1
- package/gen.js +0 -97
- package/graph.d.ts +0 -27
- package/graph.js +0 -140
- package/relation.d.ts +0 -23
- package/remote/client/database.d.ts +0 -41
- package/remote/client/database.js +0 -228
- package/remote/client/graph.d.ts +0 -31
- package/remote/client/graph.js +0 -148
- package/remote/server/db.js +0 -197
- package/remote/server/function.js +0 -43
- package/remote/server/index.js +0 -63
- package/remote/server/initDataBases.js +0 -20
- package/test/hasFieldsAdvanced.test.js +0 -70
- package/utils/hasFieldsAdvanced.js +0 -184
- /package/{remote → dist/cjs/remote}/server/gui/css/main.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/css/scrool.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/css/style.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/favicon.svg +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/data.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/main.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/nav.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/popup.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/index.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/api.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/index.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/loadHTML.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/popUp.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryApi.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryDb.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryGraph.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/render.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/templates.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/utils.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/vars.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/core.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/d3.v7.min.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/handlebars.min.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/json5.min.js +0 -0
package/docs/graph.md
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# Graph Database Documentation
|
|
2
|
-
|
|
3
|
-
This documentation provides an overview of the `Graph` class, which represents a graph database built on top of a custom `DataBase` module. The `Graph` class allows for managing graph structures by adding, removing, and querying edges between nodes in the database.
|
|
4
|
-
|
|
5
|
-
## Class: `Graph`
|
|
6
|
-
|
|
7
|
-
### Constructor: `Graph(databaseFolder)`
|
|
8
|
-
Initializes the graph database.
|
|
9
|
-
|
|
10
|
-
- **Parameters:**
|
|
11
|
-
- `databaseFolder` (`string`): The folder where the database is stored.
|
|
12
|
-
|
|
13
|
-
### Method: `async add(collection, nodeA, nodeB)`
|
|
14
|
-
Adds an edge between two nodes in the specified collection.
|
|
15
|
-
|
|
16
|
-
- **Parameters:**
|
|
17
|
-
- `collection` (`string`): The name of the collection.
|
|
18
|
-
- `nodeA` (`string`): The first node.
|
|
19
|
-
- `nodeB` (`string`): The second node.
|
|
20
|
-
- **Returns:**
|
|
21
|
-
- `Promise<Object>`: A promise that resolves with the added edge.
|
|
22
|
-
|
|
23
|
-
### Method: `async remove(collection, nodeA, nodeB)`
|
|
24
|
-
Removes an edge between two nodes in the specified collection.
|
|
25
|
-
|
|
26
|
-
- **Parameters:**
|
|
27
|
-
- `collection` (`string`): The name of the collection.
|
|
28
|
-
- `nodeA` (`string`): The first node.
|
|
29
|
-
- `nodeB` (`string`): The second node.
|
|
30
|
-
- **Returns:**
|
|
31
|
-
- `Promise<boolean>`: A promise that resolves to `true` if the edge is removed, otherwise `false`.
|
|
32
|
-
|
|
33
|
-
### Method: `async find(collection, node)`
|
|
34
|
-
Finds all edges with either node equal to the specified `node`.
|
|
35
|
-
|
|
36
|
-
- **Parameters:**
|
|
37
|
-
- `collection` (`string`): The name of the collection.
|
|
38
|
-
- `node` (`string`): The node to search for.
|
|
39
|
-
- **Returns:**
|
|
40
|
-
- `Promise<Object[]>`: A promise that resolves with an array of edges.
|
|
41
|
-
|
|
42
|
-
### Method: `async findOne(collection, nodeA, nodeB)`
|
|
43
|
-
Finds one edge with either `nodeA` or `nodeB` as nodes.
|
|
44
|
-
|
|
45
|
-
- **Parameters:**
|
|
46
|
-
- `collection` (`string`): The name of the collection.
|
|
47
|
-
- `nodeA` (`string`): The first node.
|
|
48
|
-
- `nodeB` (`string`): The second node.
|
|
49
|
-
- **Returns:**
|
|
50
|
-
- `Promise<Object|null>`: A promise that resolves with the found edge or `null` if no edge is found.
|
|
51
|
-
|
|
52
|
-
### Method: `async getAll(collection)`
|
|
53
|
-
Gets all edges in the specified collection.
|
|
54
|
-
|
|
55
|
-
- **Parameters:**
|
|
56
|
-
- `collection` (`string`): The name of the collection.
|
|
57
|
-
- **Returns:**
|
|
58
|
-
- `Promise<Object[]>`: A promise that resolves with all edges in the collection.
|
|
59
|
-
|
|
60
|
-
### Method: `async getCollections()`
|
|
61
|
-
Returns the names of all available collections in the database.
|
|
62
|
-
|
|
63
|
-
- **Returns:**
|
|
64
|
-
- `Promise<string[]>`: A promise that resolves with an array of collection names.
|
|
65
|
-
|
|
66
|
-
### Method: `async checkCollection(collection)`
|
|
67
|
-
Checks and creates the specified collection if it doesn't exist.
|
|
68
|
-
|
|
69
|
-
- **Parameters:**
|
|
70
|
-
- `collection` (`string`): The name of the collection.
|
|
71
|
-
|
|
72
|
-
### Method: `async issetCollection(collection)`
|
|
73
|
-
Checks if the specified collection exists.
|
|
74
|
-
|
|
75
|
-
- **Parameters:**
|
|
76
|
-
- `collection` (`string`): The name of the collection.
|
|
77
|
-
- **Returns:**
|
|
78
|
-
- `Promise<boolean>`: A promise that resolves to `true` if the collection exists, otherwise `false`.
|
|
79
|
-
|
|
80
|
-
### Method: `removeCollection(collection)`
|
|
81
|
-
Removes the specified collection from the database file system.
|
|
82
|
-
|
|
83
|
-
- **Parameters:**
|
|
84
|
-
- `collection` (`string`): The name of the collection to remove.
|
|
85
|
-
- **Returns:**
|
|
86
|
-
- `void`
|
package/docs/relation.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Relation Class Documentation
|
|
2
|
-
|
|
3
|
-
This documentation provides an overview of the `Relation` class, which is designed to manage and resolve relations between database collections.
|
|
4
|
-
|
|
5
|
-
## Class: `Relation`
|
|
6
|
-
|
|
7
|
-
### Constructor: `Relation(databases)`
|
|
8
|
-
Creates a new instance of the `Relation` class.
|
|
9
|
-
|
|
10
|
-
- **Parameters:**
|
|
11
|
-
- `databases` (`Record<string, Database>`): An object containing database instances, where keys are database names.
|
|
12
|
-
|
|
13
|
-
### Method: `async find(path: string, search: object | Function, relations?: Record<string, any>, options?: object)`
|
|
14
|
-
Finds items with relations based on the provided path and search criteria.
|
|
15
|
-
|
|
16
|
-
- **Parameters:**
|
|
17
|
-
- `path` (`string`): Path in format 'dbName.collectionName'.
|
|
18
|
-
- `search` (`object | Function`): The search query or function to execute.
|
|
19
|
-
- `relations` (`Record<string, any>`, optional): Relations configuration for resolving related data.
|
|
20
|
-
- `options` (`object`, optional): Additional search options.
|
|
21
|
-
- **Returns:**
|
|
22
|
-
- `Promise<Array<object>>`: A promise that resolves with an array of items, each containing resolved relations.
|
|
23
|
-
|
|
24
|
-
### Method: `async findOne(path: string, search: object | Function, relations?: Record<string, any>)`
|
|
25
|
-
Finds one item with relations based on the provided path and search criteria.
|
|
26
|
-
|
|
27
|
-
- **Parameters:**
|
|
28
|
-
- `path` (`string`): Path in format 'dbName.collectionName'.
|
|
29
|
-
- `search` (`object | Function`): The search query or function to execute.
|
|
30
|
-
- `relations` (`Record<string, any>`, optional): Relations configuration for resolving related data.
|
|
31
|
-
- **Returns:**
|
|
32
|
-
- `Promise<object | null>`: A promise that resolves with the found item containing resolved relations or `null` if no match is found.
|
|
33
|
-
|
|
34
|
-
### Method: `private _processItemRelations(item: object, relations: Record<string, any>)`
|
|
35
|
-
Processes relations for a single item.
|
|
36
|
-
|
|
37
|
-
- **Parameters:**
|
|
38
|
-
- `item` (`object`): The item to process relations for.
|
|
39
|
-
- `relations` (`Record<string, any>`): Relations configuration.
|
|
40
|
-
- **Returns:**
|
|
41
|
-
- `Promise<object>`: A promise that resolves with the processed item containing resolved relations.
|
|
42
|
-
|
|
43
|
-
### Private Method: `_resolvePath(path: string)`
|
|
44
|
-
Resolves the relation path in the format 'dbName.collectionName'.
|
|
45
|
-
|
|
46
|
-
- **Parameters:**
|
|
47
|
-
- `path` (`string`): The path to resolve, supporting escaped dots (`\.`).
|
|
48
|
-
- **Returns:**
|
|
49
|
-
- `{ db: Database; collection: string }`: An object containing the resolved database and collection names.
|
|
50
|
-
- **Throws:**
|
|
51
|
-
- `Error`: If the database does not exist or if the path format is invalid.
|
package/docs/remote.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Remote Database and Graph Database Client Documentation
|
|
2
|
-
|
|
3
|
-
## `remote` object structure.
|
|
4
|
-
- `name` (`string`): The name of the database.
|
|
5
|
-
- `url` (`string`): The URL of the remote database.
|
|
6
|
-
- `auth` (`string`): The authentication token for accessing the database.
|
|
7
|
-
|
|
8
|
-
## Class: `DataBaseRemote(remote)`
|
|
9
|
-
`DataBaseRemote` is an extended version of the `DataBase` class, designed to handle API requests. It provides the same functionalities as `DataBase`, but enables remote communication, allowing you to interact with databases through HTTP requests.
|
|
10
|
-
|
|
11
|
-
## Example Usage
|
|
12
|
-
```javascript
|
|
13
|
-
const remoteDB = new DataBaseRemote({
|
|
14
|
-
name: 'myRemoteDB',
|
|
15
|
-
url: 'https://example.com/db',
|
|
16
|
-
auth: 'your-auth-token'
|
|
17
|
-
});
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Class: `GraphRemote(remote)`
|
|
21
|
-
`GraphRemote` is an extension of the `Graph` class, specifically designed for working with graph databases over HTTP. It supports querying and modifying graph data, providing methods tailored for graph operations such as adding nodes, edges, and executing graph queries.
|
|
22
|
-
|
|
23
|
-
## Example Usage
|
|
24
|
-
```javascript
|
|
25
|
-
const remoteGraph = new GraphRemote({
|
|
26
|
-
name: 'myRemoteGraph',
|
|
27
|
-
url: 'https://example.com/db',
|
|
28
|
-
auth: 'your-auth-token'
|
|
29
|
-
});
|
|
30
|
-
```
|
package/docs/remote_server.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Installation
|
|
2
|
-
|
|
3
|
-
Clone the repository and install the necessary development dependencies:
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
git clone https://github.com/wxn0brP/db.git
|
|
7
|
-
cd db
|
|
8
|
-
npm install
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
# Usage
|
|
12
|
-
|
|
13
|
-
To start the server, run:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
node remote/server/index.js
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
# Server Management
|
|
20
|
-
|
|
21
|
-
Manage the server using the following command:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
node remote/serverMgmt/index.js
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Available Parameters:
|
|
28
|
-
|
|
29
|
-
- `help`: Display this help message
|
|
30
|
-
- `add-db <type> <name> <folder> <opts>`: Add a new database
|
|
31
|
-
- `rm-db <name>`: Remove an existing database
|
|
32
|
-
- `list-dbs`: List all databases
|
|
33
|
-
- `add-user <login> <password>`: Create a new user
|
|
34
|
-
- `rm-user <login>`: Delete a user
|
|
35
|
-
- `list-users`: Display all users
|
package/docs/search_opts.md
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# Predefined Search Options Quick Reference
|
|
2
|
-
|
|
3
|
-
## Operators
|
|
4
|
-
|
|
5
|
-
### Logical Operators
|
|
6
|
-
|
|
7
|
-
#### $and
|
|
8
|
-
Checks if all conditions in an array are true.
|
|
9
|
-
```javascript
|
|
10
|
-
{
|
|
11
|
-
$and: [
|
|
12
|
-
{ $gt: { age: 20 } },
|
|
13
|
-
{ $exists: { name: true } }
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
#### $or
|
|
19
|
-
Checks if at least one condition in an array is true.
|
|
20
|
-
```javascript
|
|
21
|
-
{
|
|
22
|
-
$or: [
|
|
23
|
-
{ $lt: { age: 20 } },
|
|
24
|
-
{ $gt: { age: 60 } }
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
#### $not
|
|
30
|
-
Negates a condition.
|
|
31
|
-
```javascript
|
|
32
|
-
{
|
|
33
|
-
$not: { $type: { age: "string" } }
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Comparison Operators
|
|
38
|
-
|
|
39
|
-
#### $gt
|
|
40
|
-
Greater than comparison.
|
|
41
|
-
```javascript
|
|
42
|
-
{ $gt: { age: 18 } }
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
#### $lt
|
|
46
|
-
Less than comparison.
|
|
47
|
-
```javascript
|
|
48
|
-
{ $lt: { score: 100 } }
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
#### $gte
|
|
52
|
-
Greater than or equal comparison.
|
|
53
|
-
```javascript
|
|
54
|
-
{ $gte: { price: 9.99 } }
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
#### $lte
|
|
58
|
-
Less than or equal comparison.
|
|
59
|
-
```javascript
|
|
60
|
-
{ $lte: { quantity: 50 } }
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
#### $in
|
|
64
|
-
Checks if value is in an array.
|
|
65
|
-
```javascript
|
|
66
|
-
{ $in: { status: ["active", "pending"] } }
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
#### $nin
|
|
70
|
-
Checks if value is not in an array.
|
|
71
|
-
```javascript
|
|
72
|
-
{ $nin: { category: ["archived", "deleted"] } }
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
#### $between
|
|
76
|
-
Checks if a number is between two values (inclusive).
|
|
77
|
-
```javascript
|
|
78
|
-
{ $between: { age: [18, 65] } }
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Type and Existence Operators
|
|
82
|
-
|
|
83
|
-
#### $exists
|
|
84
|
-
Checks if a field exists (or doesn't exist).
|
|
85
|
-
```javascript
|
|
86
|
-
{ $exists: { email: true, deletedAt: false } }
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### $type
|
|
90
|
-
Checks the type of a field.
|
|
91
|
-
```javascript
|
|
92
|
-
{ $type: { age: "number", name: "string" } }
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Array Operators
|
|
96
|
-
|
|
97
|
-
#### $arrinc
|
|
98
|
-
Checks if an array includes at least one of the specified values.
|
|
99
|
-
```javascript
|
|
100
|
-
{ $arrinc: { tags: ["developer", "designer"] } }
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### $arrincall
|
|
104
|
-
Checks if an array includes all of the specified values.
|
|
105
|
-
```javascript
|
|
106
|
-
{ $arrincall: { permissions: ["read", "write"] } }
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
#### $size
|
|
110
|
-
Checks the length of an array or string.
|
|
111
|
-
```javascript
|
|
112
|
-
{ $size: { tags: 3 } }
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### String Operators
|
|
116
|
-
|
|
117
|
-
#### $regex
|
|
118
|
-
Tests a string against a regular expression.
|
|
119
|
-
```javascript
|
|
120
|
-
{ $regex: { email: /^[^@]+@[^@]+\.[^@]+$/ } }
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### $startsWith
|
|
124
|
-
Checks if a string starts with a specified value.
|
|
125
|
-
```javascript
|
|
126
|
-
{ $startsWith: { name: "Dr." } }
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
#### $endsWith
|
|
130
|
-
Checks if a string ends with a specified value.
|
|
131
|
-
```javascript
|
|
132
|
-
{ $endsWith: { email: "@example.com" } }
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Other Operators
|
|
136
|
-
|
|
137
|
-
#### $subset
|
|
138
|
-
Allows for skipping advanced validation for specific fields, applying only basic validation. This is useful when validation data may conflict with predefined functions (starting with $), while user data might also contain similar keys. Use this operator as a compromise.
|
|
139
|
-
```javascript
|
|
140
|
-
{ $subset: { $lt: "John Doe" } } // chcek if "$lt" is "John Doe"
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Examples
|
|
144
|
-
|
|
145
|
-
### Complex Validation
|
|
146
|
-
|
|
147
|
-
```javascript
|
|
148
|
-
const criteria = {
|
|
149
|
-
$and: [
|
|
150
|
-
{
|
|
151
|
-
$or: [
|
|
152
|
-
{ $gt: { age: 18 } },
|
|
153
|
-
{ $exists: { guardianConsent: true } }
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
$type: { email: "string" },
|
|
158
|
-
$regex: { email: /^[^@]+@[^@]+\.[^@]+$/ }
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
$arrincall: { roles: ["user"] },
|
|
162
|
-
$not: { $in: { status: ["banned", "suspended"] } }
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const user = {
|
|
168
|
-
age: 16,
|
|
169
|
-
guardianConsent: true,
|
|
170
|
-
email: "john@example.com",
|
|
171
|
-
roles: ["user", "premium"],
|
|
172
|
-
status: "active"
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const isValid = hasFieldsAdvanced(user, criteria); // true
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### Nested Conditions
|
|
179
|
-
|
|
180
|
-
```javascript
|
|
181
|
-
const criteria = {
|
|
182
|
-
$and: [
|
|
183
|
-
{
|
|
184
|
-
$exists: { address: true },
|
|
185
|
-
$type: { address: "object" }
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
$or: [
|
|
189
|
-
{ $exists: { "address.zipCode": true } },
|
|
190
|
-
{
|
|
191
|
-
$and: [
|
|
192
|
-
{ $exists: { "address.city": true } },
|
|
193
|
-
{ $exists: { "address.country": true } }
|
|
194
|
-
]
|
|
195
|
-
}
|
|
196
|
-
]
|
|
197
|
-
}
|
|
198
|
-
]
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const user = {
|
|
202
|
-
address: {
|
|
203
|
-
city: "New York",
|
|
204
|
-
country: "USA"
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const isValid = hasFieldsAdvanced(user, criteria); // true
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## Error Handling
|
|
212
|
-
|
|
213
|
-
The function will throw an error if:
|
|
214
|
-
- The `fields` parameter is not an object
|
|
215
|
-
- The `fields` parameter is null
|
|
216
|
-
|
|
217
|
-
Always wrap the function call in a try-catch block when using with untrusted input:
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
try {
|
|
221
|
-
const isValid = hasFieldsAdvanced(obj, criteria);
|
|
222
|
-
// Handle result
|
|
223
|
-
} catch (error) {
|
|
224
|
-
// Handle error
|
|
225
|
-
console.error('Validation error:', error.message);
|
|
226
|
-
}
|
|
227
|
-
```
|
package/file/find.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises } from "fs";
|
|
2
|
-
import { pathRepair, createRL } from "./utils.js";
|
|
3
|
-
import { parse } from "../format.js";
|
|
4
|
-
import hasFieldsAdvanced from "../utils/hasFieldsAdvanced.js";
|
|
5
|
-
import updateFindObject from "../utils/updateFindObject.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Processes a line of text from a file and checks if it matches the search criteria.
|
|
9
|
-
* @private
|
|
10
|
-
* @param {function|Object} arg - The search criteria. It can be a function or an object.
|
|
11
|
-
* @param {string} line - The line of text from the file.
|
|
12
|
-
* @param {Object} context - The context object (for functions).
|
|
13
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
14
|
-
* @returns {Promise<Object|null>} A Promise that resolves to the matching object or null.
|
|
15
|
-
*/
|
|
16
|
-
async function findProcesLine(arg, line, context={}, findOpts={}){
|
|
17
|
-
const ob = parse(line);
|
|
18
|
-
let res = false;
|
|
19
|
-
|
|
20
|
-
if(typeof arg === "function"){
|
|
21
|
-
if(arg(ob, context)) res = true;
|
|
22
|
-
}else if(typeof arg === "object" && !Array.isArray(arg)){
|
|
23
|
-
if(hasFieldsAdvanced(ob, arg)) res = true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if(res) return updateFindObject(ob, findOpts);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Asynchronously finds entries in a file based on search criteria.
|
|
32
|
-
* @function
|
|
33
|
-
* @param {string} file - The file path to search in.
|
|
34
|
-
* @param {function|Object} arg - The search criteria. It can be a function or an object.
|
|
35
|
-
* @param {Object} context - The context object (for functions).
|
|
36
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
37
|
-
* @returns {Promise<Object[]>} A Promise that resolves to an array of matching objects.
|
|
38
|
-
*/
|
|
39
|
-
export async function find(file, arg, context={}, findOpts={}){
|
|
40
|
-
file = pathRepair(file);
|
|
41
|
-
return await new Promise(async (resolve) => {
|
|
42
|
-
if(!existsSync(file)){
|
|
43
|
-
await promises.writeFile(file, "");
|
|
44
|
-
resolve(false);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const rl = createRL(file);
|
|
48
|
-
const resF = [];
|
|
49
|
-
for await(const line of rl){
|
|
50
|
-
if(line == "" || !line) continue;
|
|
51
|
-
|
|
52
|
-
const res = await findProcesLine(arg, line, context, findOpts);
|
|
53
|
-
if(res) resF.push(res);
|
|
54
|
-
};
|
|
55
|
-
resolve(resF);
|
|
56
|
-
rl.close();
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Asynchronously finds one entry in a file based on search criteria.
|
|
62
|
-
* @function
|
|
63
|
-
* @param {string} file - The file path to search in.
|
|
64
|
-
* @param {function|Object} arg - The search criteria. It can be a function or an object.
|
|
65
|
-
* @param {Object} context - The context object (for functions).
|
|
66
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
67
|
-
* @returns {Promise<Object>} A Promise that resolves to the first matching object found or an empty array.
|
|
68
|
-
*/
|
|
69
|
-
export async function findOne(file, arg, context={}, findOpts={}){
|
|
70
|
-
file = pathRepair(file);
|
|
71
|
-
return await new Promise(async (resolve) => {
|
|
72
|
-
if(!existsSync(file)){
|
|
73
|
-
await promises.writeFile(file, "");
|
|
74
|
-
resolve(false);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const rl = createRL(file);
|
|
78
|
-
for await(const line of rl){
|
|
79
|
-
if(line == "" || !line) continue;
|
|
80
|
-
|
|
81
|
-
const res = await findProcesLine(arg, line, context, findOpts);
|
|
82
|
-
if(res){
|
|
83
|
-
resolve(res);
|
|
84
|
-
rl.close();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
resolve(false);
|
|
88
|
-
});
|
|
89
|
-
}
|
package/file/remove.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises, appendFileSync, readdirSync, cp } from "fs";
|
|
2
|
-
import { pathRepair, createRL } from "./utils.js";
|
|
3
|
-
import { parse } from "../format.js";
|
|
4
|
-
import hasFieldsAdvanced from "../utils/hasFieldsAdvanced.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Removes entries from a file based on search criteria.
|
|
8
|
-
* @private
|
|
9
|
-
* @param {string} file - The file path to remove entries from.
|
|
10
|
-
* @param {function|Object} search - The search criteria. It can be a function or an object.
|
|
11
|
-
* @param {Object} context - The context object (for functions).
|
|
12
|
-
* @param {boolean} [one=false] - Indicates whether to remove only one matching entry (default: false).
|
|
13
|
-
* @returns {Promise<boolean>} A Promise that resolves to `true` if entries were removed, or `false` otherwise.
|
|
14
|
-
*/
|
|
15
|
-
async function removeWorker(file, search, context={}, one=false){
|
|
16
|
-
file = pathRepair(file);
|
|
17
|
-
if(!existsSync(file)){
|
|
18
|
-
await promises.writeFile(file, "");
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
await promises.copyFile(file, file+".tmp");
|
|
22
|
-
await promises.writeFile(file, "");
|
|
23
|
-
|
|
24
|
-
const rl = createRL(file+".tmp");
|
|
25
|
-
|
|
26
|
-
let removed = false;
|
|
27
|
-
for await(let line of rl){
|
|
28
|
-
if(one && removed){
|
|
29
|
-
appendFileSync(file, line+"\n");
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const data = parse(line);
|
|
34
|
-
|
|
35
|
-
if(typeof search === "function"){
|
|
36
|
-
if(search(data, context)){
|
|
37
|
-
removed = true;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}else if(typeof search === "object" && !Array.isArray(search)){
|
|
41
|
-
if(hasFieldsAdvanced(data, search)){
|
|
42
|
-
removed = true;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
appendFileSync(file, line+"\n");
|
|
48
|
-
}
|
|
49
|
-
await promises.writeFile(file+".tmp", "");
|
|
50
|
-
return removed;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Asynchronously removes entries from a file based on search criteria.
|
|
55
|
-
* @function
|
|
56
|
-
* @param {string} cpath - Path to the collection.
|
|
57
|
-
* @param {function|Object} arg - The search criteria. It can be a function or an object.
|
|
58
|
-
* @param {Object} context - The context object (for functions).
|
|
59
|
-
* @param {boolean} one - Indicates whether to remove only one matching entry (default: false).
|
|
60
|
-
* @returns {Promise<boolean>} A Promise that resolves to `true` if entries were removed, or `false` otherwise.
|
|
61
|
-
*/
|
|
62
|
-
async function remove(cpath, arg, context={}, one){
|
|
63
|
-
let files = readdirSync(cpath).filter(file => !/\.tmp$/.test(file));
|
|
64
|
-
files.reverse();
|
|
65
|
-
let remove = false;
|
|
66
|
-
for(const file of files){
|
|
67
|
-
const removed = await removeWorker(cpath + file, arg, context, one);
|
|
68
|
-
if(one && removed) break;
|
|
69
|
-
remove = remove || removed;
|
|
70
|
-
}
|
|
71
|
-
return remove;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default remove;
|
package/file/update.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises, appendFileSync, readdirSync } from "fs";
|
|
2
|
-
import { pathRepair, createRL } from "./utils.js";
|
|
3
|
-
import { parse, stringify } from "../format.js";
|
|
4
|
-
import hasFieldsAdvanced from "../utils/hasFieldsAdvanced.js";
|
|
5
|
-
import updateObject from "../utils/updateObject.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Updates a file based on search criteria and an updater function or object.
|
|
9
|
-
* @private
|
|
10
|
-
* @param {string} file - The file path to update.
|
|
11
|
-
* @param {function|Object} search - The search criteria. It can be a function or an object.
|
|
12
|
-
* @param {function|Object} updater - The updater function or object.
|
|
13
|
-
* @param {Object} context - The context object (for functions).
|
|
14
|
-
* @param {boolean} [one=false] - Indicates whether to update only one matching entry (default: false).
|
|
15
|
-
* @returns {Promise<boolean>} A Promise that resolves to `true` if the file was updated, or `false` otherwise.
|
|
16
|
-
*/
|
|
17
|
-
async function updateWorker(file, search, updater, context={}, one=false){
|
|
18
|
-
file = pathRepair(file);
|
|
19
|
-
if(!existsSync(file)){
|
|
20
|
-
await promises.writeFile(file, "");
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
await promises.copyFile(file, file+".tmp");
|
|
24
|
-
await promises.writeFile(file, "");
|
|
25
|
-
|
|
26
|
-
const rl = createRL(file+".tmp");
|
|
27
|
-
|
|
28
|
-
let updated = false;
|
|
29
|
-
for await(let line of rl){
|
|
30
|
-
if(one && updated){
|
|
31
|
-
appendFileSync(file, line+"\n");
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const data = parse(line);
|
|
36
|
-
let ob = false;
|
|
37
|
-
|
|
38
|
-
if(typeof search === "function"){
|
|
39
|
-
ob = search(data, context) || false;
|
|
40
|
-
}else if(typeof search === "object" && !Array.isArray(search)){
|
|
41
|
-
ob = hasFieldsAdvanced(data, search);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if(ob){
|
|
45
|
-
let updateObj;
|
|
46
|
-
if(typeof updater === "function"){
|
|
47
|
-
updateObj = updater(data, context);
|
|
48
|
-
}else if(typeof updater === "object" && !Array.isArray(updater)){
|
|
49
|
-
updateObj = updateObject(data, updater);
|
|
50
|
-
}
|
|
51
|
-
line = await stringify(updateObj);
|
|
52
|
-
updated = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
appendFileSync(file, line+"\n");
|
|
56
|
-
}
|
|
57
|
-
await promises.writeFile(file+".tmp", "");
|
|
58
|
-
return updated;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
63
|
-
* @function
|
|
64
|
-
* @param {string} cpath - Path to the collection.
|
|
65
|
-
* @param {function|Object} arg - The search criteria. It can be a function or an object.
|
|
66
|
-
* @param {function|Object} obj - The updater function or object.
|
|
67
|
-
* @param {Object} context - The context object (for functions).
|
|
68
|
-
* @param {boolean} one - Indicates whether to update only one matching entry (default: false).
|
|
69
|
-
* @returns {Promise<boolean>} A Promise that resolves to `true` if entries were updated, or `false` otherwise.
|
|
70
|
-
*/
|
|
71
|
-
async function update(cpath, arg, obj, context={}, one){
|
|
72
|
-
let files = readdirSync(cpath).filter(file => !/\.tmp$/.test(file));
|
|
73
|
-
files.reverse();
|
|
74
|
-
let update = false;
|
|
75
|
-
for(const file of files){
|
|
76
|
-
const updated = await updateWorker(cpath + file, arg, obj, context, one);
|
|
77
|
-
if(one && updated) return true;
|
|
78
|
-
update = update || updated;
|
|
79
|
-
}
|
|
80
|
-
return update;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default update;
|
package/gen.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function genId(parts: number | number[], fill?: number): string;
|