Skip to content

Commit fea5bd0

Browse files
committed
refactor(in-memory-db): initial change for migrating in-memory-db to an nx repository
1 parent 5b79f96 commit fea5bd0

File tree

125 files changed

+15624
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+15624
-105
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 2018,
6+
"sourceType": "module",
7+
"project": "./tsconfig.*?.json"
8+
},
9+
"ignorePatterns": ["**/*"],
10+
"plugins": ["@typescript-eslint", "@nrwl/nx"],
11+
"extends": [
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/eslint-recommended",
14+
"plugin:@typescript-eslint/recommended",
15+
"prettier",
16+
"prettier/@typescript-eslint"
17+
],
18+
"rules": {
19+
"@typescript-eslint/explicit-member-accessibility": "off",
20+
"@typescript-eslint/explicit-function-return-type": "off",
21+
"@typescript-eslint/no-parameter-properties": "off",
22+
"@nrwl/nx/enforce-module-boundaries": [
23+
"error",
24+
{
25+
"enforceBuildableLibDependency": true,
26+
"allow": [],
27+
"depConstraints": [
28+
{ "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
29+
]
30+
}
31+
]
32+
},
33+
"overrides": [
34+
{
35+
"files": ["*.tsx"],
36+
"rules": {
37+
"@typescript-eslint/no-unused-vars": "off"
38+
}
39+
}
40+
]
41+
}

.github/workflows/build.yml

Whitespace-only changes.

.gitignore

Lines changed: 39 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,39 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
yarn-error.log
34+
testem.log
35+
/typings
36+
37+
# System Files
38+
.DS_Store
39+
Thumbs.db

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
3+
/dist
4+
/coverage

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "all",
3+
"arrowParens": "always",
4+
"singleQuote": true
5+
}

API.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# API Documentation
2+
3+
## `InMemoryDBService<T extends InMemoryEntity>`
4+
5+
This is the service that provides the in-memory database. All methods interact with a `records` array and implement `generics` to provide type-safety and intellisense based on the `T extends InMemoryEntity` passed in.
6+
7+
### Public Methods
8+
9+
**`public create(record: Partial<T>, getNextId?: () => string): T`**
10+
11+
This method takes in a `Partial<T>` as we do not always know the `id` for a record when we are creating. If we leave off the `id` property the service will automatically generate an `id` for us. Upon successful creation, the method returns the record with the newly generated `id`. An optional parameter of `getNextId` can be used to pass a function that returns a `string` and will be used by the service to get the next id. By default this uses the `uuid` npm package.
12+
13+
Example Usage:
14+
15+
```typescript
16+
const newUser = this.userService.create({
17+
firstName: 'Some',
18+
lastName: 'Person',
19+
});
20+
21+
console.log({ newUser });
22+
23+
// logs out
24+
// {
25+
// newUser: {
26+
// id: 1,
27+
// firstName: 'Some',
28+
// lastName: 'Person,
29+
// }
30+
// }
31+
```
32+
33+
**`public createMany(records: Array<Partial<T>>, getNextId?: () => string): T[]`**
34+
35+
This method takes in an array of `Partial<T>` as we do not always know the `id` for records when we are creating. If we leave off the `id` properties the service will automatically generate `id`s for us. Upon successful creation, the method returns the an array of records with the newly generated `id`s. An optional parameter of `getNextId` can be used to pass a function that returns a `string` and will be used by the service to get the next id. By default this uses the `uuid` npm package.
36+
37+
Example Usage:
38+
39+
```typescript
40+
const recordsToCreate = [
41+
{
42+
firstName: 'Some',
43+
lastName: 'Person',
44+
},
45+
{
46+
firstName: 'Other',
47+
lastName: 'Person',
48+
},
49+
];
50+
51+
const newUsers = this.userService.createMany(recordsToCreate);
52+
53+
console.log({ newUsers });
54+
55+
// logs out
56+
// {
57+
// newUsers: [{
58+
// id: 1,
59+
// firstName: 'Some',
60+
// lastName: 'Person,
61+
// },
62+
// {
63+
// id: 2,
64+
// firstName: 'Other',
65+
// lastName: 'Person,
66+
// }]
67+
// }
68+
```
69+
70+
**`public update(record: T): void`**
71+
72+
This method takes in a `T` record object and updates the record in the `records` array based on the `id` in the object. This method does not return a value.
73+
74+
Example Usage:
75+
76+
```typescript
77+
this.userService.update({
78+
id: 1,
79+
firstName: 'Other',
80+
lastName: 'Person',
81+
});
82+
```
83+
84+
**`public delete(id: string): void`**
85+
86+
This method takes in a `id: string` and deletes the record from the `records` array based on the `id` in the object. This method does not return a value.
87+
88+
Example Usage:
89+
90+
```typescript
91+
this.userService.delete('1');
92+
```
93+
94+
**`public get(id: string): T`**
95+
96+
This method takes in a `id: string` and returns the record from the `records` array based on the `id` in the object.
97+
98+
Example Usage:
99+
100+
```typescript
101+
const foundUser = this.userService.get('1');
102+
103+
console.log({ foundUser });
104+
105+
// logs out
106+
// {
107+
// foundUser: {
108+
// id: '1',
109+
// firstName: 'Some',
110+
// lastName: 'Person'
111+
// }
112+
// }
113+
```
114+
115+
**`public getAll(): T[]`**
116+
117+
This method has no parameters and returns the all from the `records` array.
118+
119+
Example Usage:
120+
121+
```typescript
122+
const allUsers = this.userService.getAll();
123+
124+
console.log({ allUsers });
125+
126+
// logs out
127+
// {
128+
// allUsers: [
129+
// {
130+
// id: '1',
131+
// firstName: 'Some',
132+
// lastName: 'Person'
133+
// },
134+
// {
135+
// id: '2',
136+
// firstName: 'Other',
137+
// lastName: 'Person'
138+
// }
139+
// ];
140+
// }
141+
```
142+
143+
**`public query(predicate: (record: T) => boolean): T[]`**
144+
145+
This method has takes in a `record: T` predicate and returns all from the `records` array that meet that predicate's requirements.
146+
147+
Example Usage:
148+
149+
```typescript
150+
const foundUsers = this.userService.query(
151+
(record) => record.lastName === 'Person',
152+
);
153+
154+
console.log({ foundUsers });
155+
156+
// logs out
157+
// {
158+
// allUsers: [
159+
// {
160+
// id: '1',
161+
// firstName: 'Some',
162+
// lastName: 'Person'
163+
// },
164+
// {
165+
// id: '2',
166+
// firstName: 'Other',
167+
// lastName: 'Person'
168+
// }
169+
// ];
170+
// }
171+
```
172+
173+
### Public Properties
174+
175+
- `records: T[]` - This is the in-memory array used in all crud and read operations for the service. Please access with care.
176+
177+
## `InMemoryDBEntity`
178+
179+
This is an interface used by the `InMemoryDBService` for intellisense and type-safety. Do not use this interface directly. Rather, implement your own `interface` that `extends` this.
180+
181+
```typescript
182+
export interface InMemoryDBEntity {
183+
id: string;
184+
}
185+
```

0 commit comments

Comments
 (0)