Skip to content

Commit

Permalink
memserver/model ORM & serialization tests complete
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jan 29, 2020
1 parent 08ebff2 commit 89a2802
Show file tree
Hide file tree
Showing 6 changed files with 1,302 additions and 13 deletions.
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@
},
"ava": {
"extensions": [
"js"
"ts"
],
"typescript": {
"extensions": [
"ts"
],
"rewritePaths": {
"src/": "dist/"
}
},
"require": [
"ts-node/register"
],
Expand Down
23 changes: 19 additions & 4 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import util from "util";
import chalk from "ansi-colors";
import Inflector from "i";
import { classify, underscore } from "ember-cli-string-utils";
import emberCliStringUtils from "ember-cli-string-utils";
import { primaryKeyTypeSafetyCheck, generateUUID } from "./utils";

const { classify, underscore } = emberCliStringUtils;
const { singularize, pluralize } = Inflector();

// NOTE: probably needs .reset() method;
export default abstract class MemServerModel {
static _DB = {};
static _attributes = {};
static _defaultAttributes = {}; // NOTE: probably a decorator here in future
static _embedReferences = {}; // NOTE: serializer concern

static primaryKey = null; // NOTE: this might be problematic!!

static primaryKey = null;
static get DB() {
if (!this._DB[this.name]) {
this._DB[this.name] = [];
Expand Down Expand Up @@ -46,7 +49,19 @@ export default abstract class MemServerModel {
return this._defaultAttributes;
}

static embedReferences = {}; // NOTE: serializer concern
static set embedReferences(references: Object) {
this._embedReferences[this.name] = references;
}
static get embedReferences() {
// NOTE: serializer concern
if (!this._embedReferences[this.name]) {
this._embedReferences[this.name] = {};

return this._embedReferences[this.name];
}

return this._embedReferences[this.name];
}

static count() {
return this.DB.length;
Expand Down Expand Up @@ -280,7 +295,7 @@ export default abstract class MemServerModel {
);
}

const targetRelationshipModel = relationshipModel; // || targetNamespace.MemServer.Models[classify(singularize(relationshipName))]; // TODO: this is problematic?!
const targetRelationshipModel = relationshipModel || this.embedReferences[relationshipName];
const hasManyRelationship = pluralize(relationshipName) === relationshipName;

if (!targetRelationshipModel) {
Expand Down
1 change: 1 addition & 0 deletions src/test/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "fs-extra";

const CWD = process.cwd();

// TODO: test reset() function, if implementation is required
test.before(async () => {
Object.keys(require.cache).forEach((key) => delete require.cache[key]);

Expand Down
Loading

0 comments on commit 89a2802

Please sign in to comment.