From 5a04843ee1f2fa20ca84798210b71133daa34746 Mon Sep 17 00:00:00 2001 From: yasaichi Date: Sun, 10 Mar 2024 21:07:03 +0900 Subject: [PATCH] Make different client implemntation exist at the same time --- deno.jsonc | 2 +- libs/{fake-api => fake-api-kiota}/schema.yaml | 10 ++++++++++ .../src/fake-api-kiota.constants.ts} | 0 .../src/fake-api-kiota.module-definition.ts | 5 +++++ .../src/fake-api-kiota.module.ts} | 4 ++-- .../src/fake-api.module-definition.ts | 2 +- .../src/generated/apiClient.ts | 0 .../src/generated/kiota-lock.json | 0 .../src/generated/models/index.ts | 0 .../src/generated/posts/index.ts | 0 .../src/generated/users/index.ts | 0 .../src/generated/users/item/index.ts | 0 libs/{fake-api => fake-api-kiota}/src/index.ts | 4 ++-- .../fake-api-kiota-module-options.interface.ts} | 0 package.json | 2 +- src/simple-users/simple-users.module.ts | 2 +- src/simple-users/simple-users.service.test.ts | 2 +- src/simple-users/simple-users.service.ts | 5 ++++- 18 files changed, 28 insertions(+), 10 deletions(-) rename libs/{fake-api => fake-api-kiota}/schema.yaml (92%) rename libs/{fake-api/src/fake-api.constants.ts => fake-api-kiota/src/fake-api-kiota.constants.ts} (100%) create mode 100644 libs/fake-api-kiota/src/fake-api-kiota.module-definition.ts rename libs/{fake-api/src/fake-api.module.ts => fake-api-kiota/src/fake-api-kiota.module.ts} (93%) rename libs/{fake-api => fake-api-kiota}/src/fake-api.module-definition.ts (86%) rename libs/{fake-api => fake-api-kiota}/src/generated/apiClient.ts (100%) rename libs/{fake-api => fake-api-kiota}/src/generated/kiota-lock.json (100%) rename libs/{fake-api => fake-api-kiota}/src/generated/models/index.ts (100%) rename libs/{fake-api => fake-api-kiota}/src/generated/posts/index.ts (100%) rename libs/{fake-api => fake-api-kiota}/src/generated/users/index.ts (100%) rename libs/{fake-api => fake-api-kiota}/src/generated/users/item/index.ts (100%) rename libs/{fake-api => fake-api-kiota}/src/index.ts (70%) rename libs/{fake-api/src/interfaces/fake-api-module-options.interface.ts => fake-api-kiota/src/interfaces/fake-api-kiota-module-options.interface.ts} (100%) diff --git a/deno.jsonc b/deno.jsonc index d0bb087..3a50a41 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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/"], diff --git a/libs/fake-api/schema.yaml b/libs/fake-api-kiota/schema.yaml similarity index 92% rename from libs/fake-api/schema.yaml rename to libs/fake-api-kiota/schema.yaml index 698b6be..515feeb 100644 --- a/libs/fake-api/schema.yaml +++ b/libs/fake-api-kiota/schema.yaml @@ -21,6 +21,11 @@ components: type: string body: type: string + required: + - id + - userId + - title + - body user: type: object properties: @@ -33,6 +38,11 @@ components: email: type: string format: email + required: + - id + - name + - username + - email parameters: user-id: name: user-id diff --git a/libs/fake-api/src/fake-api.constants.ts b/libs/fake-api-kiota/src/fake-api-kiota.constants.ts similarity index 100% rename from libs/fake-api/src/fake-api.constants.ts rename to libs/fake-api-kiota/src/fake-api-kiota.constants.ts diff --git a/libs/fake-api-kiota/src/fake-api-kiota.module-definition.ts b/libs/fake-api-kiota/src/fake-api-kiota.module-definition.ts new file mode 100644 index 0000000..3f3348b --- /dev/null +++ b/libs/fake-api-kiota/src/fake-api-kiota.module-definition.ts @@ -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().build(); diff --git a/libs/fake-api/src/fake-api.module.ts b/libs/fake-api-kiota/src/fake-api-kiota.module.ts similarity index 93% rename from libs/fake-api/src/fake-api.module.ts rename to libs/fake-api-kiota/src/fake-api-kiota.module.ts index 2c102eb..3f99a12 100644 --- a/libs/fake-api/src/fake-api.module.ts +++ b/libs/fake-api-kiota/src/fake-api-kiota.module.ts @@ -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 { diff --git a/libs/fake-api/src/fake-api.module-definition.ts b/libs/fake-api-kiota/src/fake-api.module-definition.ts similarity index 86% rename from libs/fake-api/src/fake-api.module-definition.ts rename to libs/fake-api-kiota/src/fake-api.module-definition.ts index 427c690..3f3348b 100644 --- a/libs/fake-api/src/fake-api.module-definition.ts +++ b/libs/fake-api-kiota/src/fake-api.module-definition.ts @@ -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().build(); diff --git a/libs/fake-api/src/generated/apiClient.ts b/libs/fake-api-kiota/src/generated/apiClient.ts similarity index 100% rename from libs/fake-api/src/generated/apiClient.ts rename to libs/fake-api-kiota/src/generated/apiClient.ts diff --git a/libs/fake-api/src/generated/kiota-lock.json b/libs/fake-api-kiota/src/generated/kiota-lock.json similarity index 100% rename from libs/fake-api/src/generated/kiota-lock.json rename to libs/fake-api-kiota/src/generated/kiota-lock.json diff --git a/libs/fake-api/src/generated/models/index.ts b/libs/fake-api-kiota/src/generated/models/index.ts similarity index 100% rename from libs/fake-api/src/generated/models/index.ts rename to libs/fake-api-kiota/src/generated/models/index.ts diff --git a/libs/fake-api/src/generated/posts/index.ts b/libs/fake-api-kiota/src/generated/posts/index.ts similarity index 100% rename from libs/fake-api/src/generated/posts/index.ts rename to libs/fake-api-kiota/src/generated/posts/index.ts diff --git a/libs/fake-api/src/generated/users/index.ts b/libs/fake-api-kiota/src/generated/users/index.ts similarity index 100% rename from libs/fake-api/src/generated/users/index.ts rename to libs/fake-api-kiota/src/generated/users/index.ts diff --git a/libs/fake-api/src/generated/users/item/index.ts b/libs/fake-api-kiota/src/generated/users/item/index.ts similarity index 100% rename from libs/fake-api/src/generated/users/item/index.ts rename to libs/fake-api-kiota/src/generated/users/item/index.ts diff --git a/libs/fake-api/src/index.ts b/libs/fake-api-kiota/src/index.ts similarity index 70% rename from libs/fake-api/src/index.ts rename to libs/fake-api-kiota/src/index.ts index 031cca2..99bac61 100644 --- a/libs/fake-api/src/index.ts +++ b/libs/fake-api-kiota/src/index.ts @@ -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'; diff --git a/libs/fake-api/src/interfaces/fake-api-module-options.interface.ts b/libs/fake-api-kiota/src/interfaces/fake-api-kiota-module-options.interface.ts similarity index 100% rename from libs/fake-api/src/interfaces/fake-api-module-options.interface.ts rename to libs/fake-api-kiota/src/interfaces/fake-api-kiota-module-options.interface.ts diff --git a/package.json b/package.json index c407aa1..f4d7efe 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/simple-users/simple-users.module.ts b/src/simple-users/simple-users.module.ts index a7c31cc..b30cb6e 100644 --- a/src/simple-users/simple-users.module.ts +++ b/src/simple-users/simple-users.module.ts @@ -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'; diff --git a/src/simple-users/simple-users.service.test.ts b/src/simple-users/simple-users.service.test.ts index e61b985..20934ce 100644 --- a/src/simple-users/simple-users.service.test.ts +++ b/src/simple-users/simple-users.service.test.ts @@ -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'; diff --git a/src/simple-users/simple-users.service.ts b/src/simple-users/simple-users.service.ts index 76a5580..f2e2ea6 100644 --- a/src/simple-users/simple-users.service.ts +++ b/src/simple-users/simple-users.service.ts @@ -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()