Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Make different client implemntation exist at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
yasaichi committed Mar 10, 2024
1 parent fe97c9f commit 5a04843
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"singleQuote": true
},
"imports": {
"@app/fake-api": "./libs/fake-api/src/index.ts"
"@app/fake-api-kiota": "./libs/fake-api-kiota/src/index.ts"
},
"lint": {
"include": ["src/", "apps/", "libs/", "test/"],
Expand Down
10 changes: 10 additions & 0 deletions libs/fake-api/schema.yaml → libs/fake-api-kiota/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ components:
type: string
body:
type: string
required:
- id
- userId
- title
- body
user:
type: object
properties:
Expand All @@ -33,6 +38,11 @@ components:
email:
type: string
format: email
required:
- id
- name
- username
- email
parameters:
user-id:
name: user-id
Expand Down
5 changes: 5 additions & 0 deletions libs/fake-api-kiota/src/fake-api-kiota.module-definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ConfigurableModuleBuilder } from '@nestjs/common';
import { type FakeApiModuleOptions } from './interfaces/fake-api-kiota-module-options.interface.ts';

export const { ConfigurableModuleClass, OPTIONS_TYPE } =
new ConfigurableModuleBuilder<FakeApiModuleOptions>().build();
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AnonymousAuthenticationProvider } from '@microsoft/kiota-abstractions';
import { FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibrary';
import { DynamicModule } from '@nestjs/common';
import { FAKE_API_SERVICE_TOKEN } from './fake-api.constants.ts';
import { FAKE_API_SERVICE_TOKEN } from './fake-api-kiota.constants.ts';
import {
ConfigurableModuleClass,
OPTIONS_TYPE,
} from './fake-api.module-definition.ts';
} from './fake-api-kiota.module-definition.ts';
import { createApiClient } from './generated/apiClient.ts';

export class FakeApiModule extends ConfigurableModuleClass {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigurableModuleBuilder } from '@nestjs/common';
import { type FakeApiModuleOptions } from './interfaces/fake-api-module-options.interface.ts';
import { type FakeApiModuleOptions } from './interfaces/fake-api-kiota-module-options.interface.ts';

export const { ConfigurableModuleClass, OPTIONS_TYPE } =
new ConfigurableModuleBuilder<FakeApiModuleOptions>().build();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { type RequestAdapter } from '@microsoft/kiota-abstractions';
export * from './fake-api.constants.ts';
export * from './fake-api.module.ts';
export * from './fake-api-kiota.constants.ts';
export * from './fake-api-kiota.module.ts';
export { type ApiClient as FakeApiService } from './generated/apiClient.ts';
export { type Post, type User } from './generated/models/index.ts';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"codegen:fake-api": "kiota generate --co -l typescript -d ./libs/fake-api/schema.yaml -o ./libs/fake-api/src/generated/ && ls && find ./libs/fake-api/src/generated/ -type f -exec sed -i '' -E \"s/from '\\.(.+)\\/';/from '.\\1\\/index.ts';/g\" {} +",
"codegen:kiota": "kiota generate --co -l typescript -d ./libs/fake-api-kiota/schema.yaml -o ./libs/fake-api-kiota/src/generated/ && ls && find ./libs/fake-api-kiota/src/generated/ -type f -exec sed -i '' -E \"s/from '\\.(.+)\\/';/from '.\\1\\/index.ts';/g\" {} +",
"format": "deno fmt",
"start": "deno run --allow-env --allow-net --allow-read=. src/main.ts",
"start:dev": "deno run --allow-env --allow-net --allow-read=. --watch src/main.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/simple-users/simple-users.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FakeApiModule } from '@app/fake-api';
import { FakeApiModule } from '@app/fake-api-kiota';
import { Module } from '@nestjs/common';
import { SimpleUsersController } from './simple-users.controller.ts';
import { SimpleUsersService } from './simple-users.service.ts';
Expand Down
2 changes: 1 addition & 1 deletion src/simple-users/simple-users.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type Post,
type RequestAdapter,
type User,
} from '@app/fake-api';
} from '@app/fake-api-kiota';
import { Test, TestingModule } from '@nestjs/testing';
import { beforeEach, describe, it } from '@std/testing/bdd';
import assert from 'node:assert';
Expand Down
5 changes: 4 additions & 1 deletion src/simple-users/simple-users.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { FAKE_API_SERVICE_TOKEN, type FakeApiService } from '@app/fake-api';
import {
FAKE_API_SERVICE_TOKEN,
type FakeApiService,
} from '@app/fake-api-kiota';
import { Inject, Injectable } from '@nestjs/common';

@Injectable()
Expand Down

0 comments on commit 5a04843

Please sign in to comment.