Skip to content

Commit 30d5687

Browse files
committed
wip
1 parent e556d06 commit 30d5687

9 files changed

Lines changed: 591 additions & 140 deletions

jest.config.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
transform: {
4-
'^.+\\.(ts|tsx)?$': 'ts-jest',
5-
'^.+\\.(js|jsx)$': 'babel-jest',
6-
},
7-
"collectCoverage": true,
8-
"maxWorkers": 4,
9-
"bail": true,
10-
"coverageReporters": [
11-
"html",
12-
"lcov",
13-
"text",
14-
"cobertura"
15-
],
16-
"coverageThreshold": {
17-
"global": {
18-
"lines": 85
19-
}
20-
},
21-
"reporters": [
22-
"default",
23-
"jest-junit"
24-
],
25-
"runTestsByPath": true,
26-
"openHandlesTimeout": 0
27-
};
2+
testEnvironment: 'node',
3+
testMatch: ['**/test/**/*.test.js'],
4+
moduleFileExtensions: ['js'],
5+
roots: ['<rootDir>/test'],
6+
moduleDirectories: ['node_modules', 'lib'],
7+
preset: 'ts-jest',
8+
transform: {
9+
'^.+\\.(ts|tsx)?$': 'ts-jest',
10+
'^.+\\.(js|jsx)$': 'babel-jest',
11+
},
12+
collectCoverage: true,
13+
maxWorkers: 4,
14+
bail: true,
15+
coverageReporters: [
16+
"html",
17+
"lcov",
18+
"text",
19+
"cobertura"
20+
],
21+
coverageThreshold: {
22+
"global": {
23+
"lines": 85
24+
}
25+
},
26+
reporters: [
27+
"default",
28+
"jest-junit"
29+
],
30+
runTestsByPath: true,
31+
openHandlesTimeout: 0
32+
};

package-lock.json

Lines changed: 45 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"url": "https://github.com/gregblt/NoSQLax"
3232
},
3333
"dependencies": {
34+
"@apidevtools/json-schema-ref-parser": "^11.9.3",
3435
"ajv": "^8.17.1",
3536
"nano": "^10.1.4"
3637
},

src/core/ActiveRecordEntity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class ActiveRecordEntity extends BaseEntity {
6363
}
6464

6565
async save(): Promise<BaseEntity> {
66-
return await (this.constructor as typeof ActiveRecordEntity).getRepo().save(this)
66+
return await (this.constructor as typeof ActiveRecordEntity).save(this)
6767
}
6868

6969
// 8. Delete a document
@@ -75,7 +75,7 @@ abstract class ActiveRecordEntity extends BaseEntity {
7575
if (!this.id) {
7676
throw new Error("Document does not exist");
7777
}
78-
return await (this.constructor as typeof ActiveRecordEntity).getRepo().delete(this.id);
78+
return await (this.constructor as typeof ActiveRecordEntity).delete(this.id);
7979
}
8080

8181
// Define the extend method to add new query methods

src/core/BaseEntity.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,6 @@ abstract class BaseEntity implements IBaseEntity {
5858

5959
const schemaProperties = schema?.properties || {};
6060

61-
// Dynamically add getters and setters based on schema
62-
Object.keys(schemaProperties).forEach(property => {
63-
Object.defineProperty(this, property, {
64-
get() {
65-
return this.privateData.get(this)[property]; // Retrieve the field value
66-
},
67-
set(value) {
68-
this.privateData.get(this)[property] = value; // Assign value to internal variable
69-
},
70-
enumerable: true,
71-
configurable: true
72-
});
73-
});
74-
75-
// Initialize properties from schema
76-
Object.keys(schemaProperties).forEach(property => {
77-
this.privateData.get(this)[property] = data[property];
78-
});
79-
8061
}
8162

8263
toJSON() {
@@ -86,34 +67,6 @@ abstract class BaseEntity implements IBaseEntity {
8667
return data;
8768
}
8869

89-
static extractFieldMapFromSchema(schemaOrSchemaId: any, ajvOptions: any): Record<string, string> {
90-
91-
const fieldMap: Record<string, string> = {};
92-
93-
// Initialize the AJV instance with options
94-
const ajv = new Ajv(ajvOptions || {});
95-
let schema: any = schemaOrSchemaId;
96-
97-
98-
// If schemaOrSchemaId is a string (schema ID), fetch the schema
99-
if (typeof schemaOrSchemaId === "string") {
100-
schema = ajv.getSchema(schemaOrSchemaId); // Retrieve the schema
101-
if (!schema) {
102-
throw new Error(`Schema with ID ${schemaOrSchemaId} not found.`);
103-
}
104-
}
105-
106-
if (schema && schema.properties) {
107-
// Only consider top-level properties from the schema
108-
for (const key in schema.properties) {
109-
fieldMap[key] = key; // Field name matches property name by default
110-
}
111-
}
112-
113-
return fieldMap;
114-
115-
}
116-
11770

11871
// Getter for id
11972
get id(): string | undefined {

0 commit comments

Comments
 (0)