masquerade-orm 0.8.1 → 0.8.3
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 +17 -17
- package/bin/universalTsInit.js +59 -59
- package/docs/deletion.md +4 -4
- package/docs/find.md +274 -264
- package/docs/getting-started-javascript.md +13 -4
- package/docs/getting-started-typescript.md +6 -4
- package/docs/in-depth-class-definitions.md +7 -7
- package/docs/jsdoc-ux-tips.md +251 -16
- package/docs/managing-the-database.md +1 -1
- package/index.d.ts +7 -7
- package/package.json +1 -1
- package/src/changeLogger/changeLogger.js +2 -2
- package/src/entity/entity.js +3 -3
- package/src/entity/find/find.js +7 -7
- package/src/entity/find/scopeProxies.js +2 -2
- package/src/entity/find/where/{relationalWhere.js → templateWhere.js} +18 -18
- package/src/entity/find/where/where.js +4 -4
- package/src/misc/classes.js +59 -5
- package/src/misc/ormStore.js +3 -0
- package/src/misc/types.d.ts +2 -2
- package/src/proxies/instanceProxy.js +42 -78
- package/src/webpack/masquerade-loader.js +16 -14
- package/src/webpack/plugin.js +42 -43
- package/testing/postgres.test.js +2 -2
- package/testing/sqlite.test.js +1 -2
- package/testing/testInit.js +34 -0
- package/testing/testing-classes.js +2 -2
package/README.md
CHANGED
|
@@ -37,21 +37,22 @@ npm install masquerade-orm
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
# Features
|
|
40
|
-
- **Effortless setup** -
|
|
41
|
-
- **Zero schema planning** -
|
|
42
|
-
- **Powerful IntelliSense** -
|
|
43
|
-
- **Minimal memory usage** -
|
|
44
|
-
- **Optimized querying** -
|
|
45
|
-
- **
|
|
46
|
-
- **
|
|
47
|
-
- **
|
|
48
|
-
- **
|
|
49
|
-
- **
|
|
50
|
-
- **
|
|
51
|
-
- **Abstract and non-abstract inheritance** -
|
|
40
|
+
- **Effortless setup** - No ORM-specific structures; just use your classes.
|
|
41
|
+
- **Zero schema planning** - Tables and schema are generated automatically.
|
|
42
|
+
- **Powerful IntelliSense** - Confidently build complex queries with real-time IDE guidance and warnings when something’s wrong.
|
|
43
|
+
- **Minimal memory usage** - One class instance per database row, minimizing memory usage and avoiding duplicates through smart state management.
|
|
44
|
+
- **Optimized querying** - Fewer queries through intelligent transaction grouping without sacrificing data integrity.
|
|
45
|
+
- **Expressive template-literal WHERE clauses** - Write complex, readable conditions such as LIKE, ≥, nested property access, array element matching (and more) by using IntelliSense-enabled tagged template literals. Any SQL WHERE logic can be expressed through this API.
|
|
46
|
+
- **Cross-column conditions** - Easily write WHERE clauses that compare two columns (within the same table or across joined tables).
|
|
47
|
+
- **Powerful relation capabilities** - Full support for eager & lazy loading, unidirectional / bidirectional / self-referencing relationships, and modifying associations even when they are not loaded.
|
|
48
|
+
- **SQL injection protection** - All queries are parameterized.
|
|
49
|
+
- **Minimal data transfer size** - Improves performance in client-server setups (not applicable for embedded databases like SQLite).
|
|
50
|
+
- **Soft + hard deletion support**
|
|
51
|
+
- **Abstract and non-abstract inheritance** - Enables the use of abstract classes, even in JavaScript.
|
|
52
|
+
- **Strong typing even in JavaScript** - Powered by JSDoc, no compile step required.
|
|
53
|
+
- **Smart schema cleanup** - Automatically detect and easily remove unused tables and columns, reducing database bloat and improving performance.
|
|
54
|
+
- **Lightweight** - Minimal dependencies.
|
|
52
55
|
- **Combines the convenience of embedded SQLite with the strict typing of RDBMS**
|
|
53
|
-
- **Eager and lazy relations**
|
|
54
|
-
- **Unidirectional, bidirectional, and self-referenced relations**
|
|
55
56
|
|
|
56
57
|
|
|
57
58
|
# Example Code Implementation
|
|
@@ -134,13 +135,12 @@ user.friendList.pop()
|
|
|
134
135
|
|
|
135
136
|
- **[Getting Started - Javascript](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/getting-started-javascript.md#class-definitions)**
|
|
136
137
|
- **[Getting Started - Typescript](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/getting-started-typescript.md#class-definitions)**
|
|
138
|
+
- **[Defining Classes: In-Depth](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/in-depth-class-definitions.md)** **(important read)**
|
|
137
139
|
- **[Find Method](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/find.md#find)**
|
|
138
140
|
- **[Saving to Database](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/saving-to-database.md#saving-to-the-database)**
|
|
139
141
|
- **[Deleting Instances from the Database](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/deletion.md)**
|
|
140
142
|
- **[Managing Database Tables](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/managing-the-database.md)**
|
|
141
|
-
- **[
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
- **[JSDoc – UX Tips](https://github.com/MasqueradeORM/MasqueradeORM/blob/master/docs/jsdoc-ux-tips.md)**
|
|
144
144
|
|
|
145
145
|
<br>
|
|
146
146
|
<div align="center">
|
package/bin/universalTsInit.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import ts from "typescript"
|
|
4
|
-
import fs from "fs"
|
|
5
|
-
import path from "path"
|
|
6
|
-
import { createSourceFile, SyntaxKind, ScriptKind, ScriptTarget } from "typescript"
|
|
7
|
-
import { nodeArr2ClassDict } from "../src/ORM/bootOrm.js"
|
|
8
|
-
|
|
9
|
-
const configPath = ts.findConfigFile(
|
|
10
|
-
"./",
|
|
11
|
-
ts.sys.fileExists,
|
|
12
|
-
"tsconfig.json"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
if (!configPath) {
|
|
16
|
-
throw new Error("tsconfig.json not found")
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const configFile = ts.readConfigFile(
|
|
20
|
-
configPath,
|
|
21
|
-
ts.sys.readFile
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
25
|
-
configFile.config,
|
|
26
|
-
ts.sys,
|
|
27
|
-
"./"
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const program = ts.createProgram({
|
|
31
|
-
rootNames: parsed.fileNames,
|
|
32
|
-
options: parsed.options
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const classNodesArr = []
|
|
36
|
-
|
|
37
|
-
for (const sourceFile of program.getSourceFiles()) {
|
|
38
|
-
if (sourceFile.isDeclarationFile) continue
|
|
39
|
-
const fileText = sourceFile.getFullText()
|
|
40
|
-
const fileNodesArr = createSourceFile('', fileText, ScriptTarget.Latest, true, ScriptKind.TSX).statements
|
|
41
|
-
|
|
42
|
-
for (const node of fileNodesArr) {
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && node.heritageClauses)
|
|
45
|
-
classNodesArr.push(node)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const classDict = nodeArr2ClassDict(classNodesArr)
|
|
50
|
-
const filePath = path.join(
|
|
51
|
-
process.cwd(),
|
|
52
|
-
"ormTypeScriptSetup.js"
|
|
53
|
-
)
|
|
54
|
-
const content = `export function UniversalTsSetup() {globalThis.masqueradeClassDict_ = ${JSON.stringify(classDict)};\n}`
|
|
55
|
-
fs.writeFileSync(filePath, content, "utf8")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import ts from "typescript"
|
|
4
|
+
import fs from "fs"
|
|
5
|
+
import path from "path"
|
|
6
|
+
import { createSourceFile, SyntaxKind, ScriptKind, ScriptTarget } from "typescript"
|
|
7
|
+
import { nodeArr2ClassDict } from "../src/ORM/bootOrm.js"
|
|
8
|
+
|
|
9
|
+
const configPath = ts.findConfigFile(
|
|
10
|
+
"./",
|
|
11
|
+
ts.sys.fileExists,
|
|
12
|
+
"tsconfig.json"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
if (!configPath) {
|
|
16
|
+
throw new Error("tsconfig.json not found")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const configFile = ts.readConfigFile(
|
|
20
|
+
configPath,
|
|
21
|
+
ts.sys.readFile
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
25
|
+
configFile.config,
|
|
26
|
+
ts.sys,
|
|
27
|
+
"./"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const program = ts.createProgram({
|
|
31
|
+
rootNames: parsed.fileNames,
|
|
32
|
+
options: parsed.options
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const classNodesArr = []
|
|
36
|
+
|
|
37
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
38
|
+
if (sourceFile.isDeclarationFile) continue
|
|
39
|
+
const fileText = sourceFile.getFullText()
|
|
40
|
+
const fileNodesArr = createSourceFile('', fileText, ScriptTarget.Latest, true, ScriptKind.TSX).statements
|
|
41
|
+
|
|
42
|
+
for (const node of fileNodesArr) {
|
|
43
|
+
//@ts-ignore
|
|
44
|
+
if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && node.heritageClauses)
|
|
45
|
+
classNodesArr.push(node)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const classDict = nodeArr2ClassDict(classNodesArr)
|
|
50
|
+
const filePath = path.join(
|
|
51
|
+
process.cwd(),
|
|
52
|
+
"ormTypeScriptSetup.js"
|
|
53
|
+
)
|
|
54
|
+
const content = `export function UniversalTsSetup() {globalThis.masqueradeClassDict_ = ${JSON.stringify(classDict)};\n}`
|
|
55
|
+
fs.writeFileSync(filePath, content, "utf8")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
package/docs/deletion.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Deleting Instances from the Database
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Soft Deletion
|
|
4
4
|
The ORM does not support soft deletion by default. To implement soft deletion, just create an abstract class like so:
|
|
5
5
|
|
|
6
6
|
**TypeScript**
|
|
@@ -69,10 +69,10 @@ const softDelUser = new SoftDeletableUser('JohnDoe', 'JohnDoe@gmail.com', 'hashe
|
|
|
69
69
|
|
|
70
70
|
**Note:** Unlike `Entity`, the `SoftDel` classes need to be passed into the `ORM.boot` method that is being called to init the ORM.
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
## Hard Deletion
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
|
-
import { sql } from "masquerade"
|
|
75
|
+
import { sql } from "masquerade-orm"
|
|
76
76
|
const twoYearsAgo = new Date().setFullYear(new Date().getFullYear() - 2)
|
|
77
77
|
|
|
78
78
|
// finds all instances that haven't been mutated in over two years
|
|
@@ -91,7 +91,7 @@ The `delete` method hard-deletes the instance from the database; the instance ca
|
|
|
91
91
|
</div>
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
## Pre-Deletion Step
|
|
94
|
+
## Pre-Deletion Step for Hard Deletion
|
|
95
95
|
|
|
96
96
|
### When is a pre-deletion step required?
|
|
97
97
|
A pre-deletion step is required when the class instance has **dependents**.
|