create-flink-app 0.12.1-alpha.4 → 0.12.1-alpha.40
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/dist/default/gitignore +37 -0
- package/dist/default/nodemon.json +7 -0
- package/dist/default/spec/Pet.spec.ts +44 -0
- package/dist/default/spec/support/jasmine.json +7 -0
- package/dist/default/spec/support/runner.ts +32 -0
- package/dist/default/src/Ctx.ts +11 -0
- package/dist/default/src/handlers/GetPet.ts +28 -0
- package/dist/default/src/handlers/PostPet.ts +19 -0
- package/dist/default/src/index.ts +17 -0
- package/dist/default/src/repos/PetRepo.ts +7 -0
- package/dist/default/src/schemas/Pet.ts +21 -0
- package/dist/default/src/schemas/PostPetReq.ts +7 -0
- package/dist/default/tsconfig.json +21 -0
- package/dist/index.js +463 -0
- package/package.json +5 -4
- package/readme.md +285 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/*/**/node_modules
|
|
6
|
+
/.pnp
|
|
7
|
+
.pnp.js
|
|
8
|
+
|
|
9
|
+
# testing
|
|
10
|
+
/coverage
|
|
11
|
+
|
|
12
|
+
# production
|
|
13
|
+
/build
|
|
14
|
+
|
|
15
|
+
# misc
|
|
16
|
+
.DS_Store
|
|
17
|
+
*.pem
|
|
18
|
+
|
|
19
|
+
# debug
|
|
20
|
+
npm-debug.log*
|
|
21
|
+
yarn-debug.log*
|
|
22
|
+
yarn-error.log*
|
|
23
|
+
|
|
24
|
+
# local env files
|
|
25
|
+
.env.local
|
|
26
|
+
.env.development.local
|
|
27
|
+
.env.test.local
|
|
28
|
+
.env.production.local
|
|
29
|
+
|
|
30
|
+
# VSCode
|
|
31
|
+
.vscode
|
|
32
|
+
|
|
33
|
+
# Generated schemas etc
|
|
34
|
+
/.flink
|
|
35
|
+
|
|
36
|
+
# Generated bundle
|
|
37
|
+
/dist
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
2
|
+
import * as testUtils from "@flink-app/test-utils";
|
|
3
|
+
import { Ctx } from "../src/Ctx";
|
|
4
|
+
import { Pet } from "../src/schemas/Pet";
|
|
5
|
+
|
|
6
|
+
describe("Pet", () => {
|
|
7
|
+
let flinkApp: FlinkApp<Ctx>;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
flinkApp = new FlinkApp({
|
|
11
|
+
name: "Test",
|
|
12
|
+
db: {
|
|
13
|
+
uri: "mongodb://localhost:27017/my-flink-app-test",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
testUtils.init(await flinkApp.start());
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("get pet", () => {
|
|
21
|
+
let aPet: Pet;
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
aPet = await flinkApp.ctx.repos.petRepo.create({
|
|
25
|
+
age: 12,
|
|
26
|
+
created: new Date(),
|
|
27
|
+
name: "Buster",
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should get 404", async () => {
|
|
32
|
+
const nonExistingPetId = "5349b4ddd2781d08c09890f3";
|
|
33
|
+
const { status } = await testUtils.get(`/pet/${nonExistingPetId}`);
|
|
34
|
+
expect(status).toBe(404);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should get pet", async () => {
|
|
38
|
+
const { status, data } = await testUtils.get<Pet>(`/pet/${aPet._id}`);
|
|
39
|
+
expect(status).toBe(200);
|
|
40
|
+
expect(data!._id).toEqual(aPet._id);
|
|
41
|
+
expect(new Date(data!.created)).toEqual(aPet.created);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Jasmine from "jasmine";
|
|
2
|
+
import {
|
|
3
|
+
DisplayProcessor,
|
|
4
|
+
SpecReporter,
|
|
5
|
+
StacktraceOption,
|
|
6
|
+
} from "jasmine-spec-reporter";
|
|
7
|
+
import SuiteInfo = jasmine.SuiteInfo;
|
|
8
|
+
|
|
9
|
+
const jasmine = new Jasmine({});
|
|
10
|
+
|
|
11
|
+
jasmine.loadConfigFile("spec/support/jasmine.json");
|
|
12
|
+
jasmine.configureDefaultReporter({
|
|
13
|
+
showColors: false,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
class CustomProcessor extends DisplayProcessor {
|
|
17
|
+
public displayJasmineStarted(info: SuiteInfo, log: string): string {
|
|
18
|
+
return `TypeScript ${log}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
jasmine.clearReporters();
|
|
23
|
+
jasmine.addReporter(
|
|
24
|
+
new SpecReporter({
|
|
25
|
+
spec: {
|
|
26
|
+
displayStacktrace: StacktraceOption.NONE,
|
|
27
|
+
},
|
|
28
|
+
customProcessors: [CustomProcessor],
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
jasmine.execute();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FlinkContext } from "@flink-app/flink";
|
|
2
|
+
import PetRepo from "./repos/PetRepo";
|
|
3
|
+
|
|
4
|
+
// Pass any plugin types as generic argument
|
|
5
|
+
// Example: FlinkContext<ApiDocsPlugin & FirbasePlugin>
|
|
6
|
+
|
|
7
|
+
export interface Ctx extends FlinkContext {
|
|
8
|
+
repos: {
|
|
9
|
+
petRepo: PetRepo;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GetHandler, notFound, RouteProps } from "@flink-app/flink";
|
|
2
|
+
import { Ctx } from "../Ctx";
|
|
3
|
+
import { Pet } from "../schemas/Pet";
|
|
4
|
+
|
|
5
|
+
export const Route: RouteProps = {
|
|
6
|
+
path: "/pet/:id",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type Params = {
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const GetPet: GetHandler<Ctx, Pet, Params> = async ({ ctx, req }) => {
|
|
14
|
+
const { id } = req.params;
|
|
15
|
+
const { petRepo } = ctx.repos;
|
|
16
|
+
|
|
17
|
+
const pet = await petRepo.getById(id);
|
|
18
|
+
|
|
19
|
+
if (!pet) {
|
|
20
|
+
return notFound(`Pet with id ${id} could not be found`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
data: pet,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default GetPet;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Handler, notFound, RouteProps } from "@flink-app/flink";
|
|
2
|
+
import { Ctx } from "../Ctx";
|
|
3
|
+
import { Pet } from "../schemas/Pet";
|
|
4
|
+
import { PostPetReq } from "../schemas/PostPetReq";
|
|
5
|
+
|
|
6
|
+
export const Route: RouteProps = {
|
|
7
|
+
path: "/pet",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const PostPet: Handler<Ctx, PostPetReq, Pet> = async ({ ctx, req }) => {
|
|
11
|
+
const { petRepo } = ctx.repos;
|
|
12
|
+
const pet = await petRepo.create({ ...req.body, created: new Date() });
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
data: pet,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default PostPet;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
2
|
+
import { Ctx } from "./Ctx";
|
|
3
|
+
|
|
4
|
+
function start() {
|
|
5
|
+
new FlinkApp<Ctx>({
|
|
6
|
+
name: "My flink app",
|
|
7
|
+
debug: true,
|
|
8
|
+
db: {
|
|
9
|
+
uri: "mongodb://localhost:27017/my-flink-app",
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
// Add any plugins here
|
|
13
|
+
],
|
|
14
|
+
}).start();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
start();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface Pet {
|
|
2
|
+
/**
|
|
3
|
+
* Id of pet, is generated by db
|
|
4
|
+
*/
|
|
5
|
+
_id: string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Name of pet, i.e "Bob the dog"
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Age in years
|
|
14
|
+
*/
|
|
15
|
+
age: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Date when pet was created
|
|
19
|
+
*/
|
|
20
|
+
created: Date;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": ["esnext", "es2016"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"experimentalDecorators": true,
|
|
17
|
+
"checkJs": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["./src/**/*.ts", "./spec/**/*"],
|
|
20
|
+
"exclude": ["./node_modules/*"]
|
|
21
|
+
}
|