Skip to content

Commit

Permalink
Merge pull request #27 from join-com/service-deprecation
Browse files Browse the repository at this point in the history
[JOIN-11593] feat: mark service deprecated methods
  • Loading branch information
castarco authored Apr 23, 2021
2 parents fe5730c + 30f4854 commit f2b0f88
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 66 deletions.
32 changes: 31 additions & 1 deletion internal/generator/runer_generate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func (r *Runner) generateTypescriptServiceDefinitionMethod(generatedFileStream *
}

func (r *Runner) generateTypescriptClientInterface(generatedFileStream *protogen.GeneratedFile, serviceSpec *descriptorpb.ServiceDescriptorProto) {
serviceOptions := serviceSpec.GetOptions()
if serviceOptions != nil {
if serviceOptions.GetDeprecated() {
r.P(generatedFileStream, "/**\n * @deprecated\n */")
}
}
r.P(
generatedFileStream,
"export interface I"+strcase.ToCamel(serviceSpec.GetName())+"Client",
Expand All @@ -105,6 +111,13 @@ func (r *Runner) generateTypescriptClientInterface(generatedFileStream *protogen
}

func (r *Runner) generateTypescriptClientInterfaceMethod(generatedFileStream *protogen.GeneratedFile, serviceSpec *descriptorpb.ServiceDescriptorProto, methodSpec *descriptorpb.MethodDescriptorProto) {
methodOptions := methodSpec.GetOptions()
if methodOptions != nil {
if methodOptions.GetDeprecated() {
r.P(generatedFileStream, "/**\n * @deprecated\n */")
}
}

// Function's Signature
methodName := strcase.ToCamel(methodSpec.GetName())
r.P(generatedFileStream, methodName+"(")
Expand Down Expand Up @@ -139,10 +152,16 @@ func (r *Runner) generateTypescriptClientInterfaceMethod(generatedFileStream *pr
}

r.indentLevel -= 2
r.P(generatedFileStream, "): "+returnType)
r.P(generatedFileStream, "): "+returnType+"\n")
}

func (r *Runner) generateTypescriptClient(generatedFileStream *protogen.GeneratedFile, serviceSpec *descriptorpb.ServiceDescriptorProto) {
serviceOptions := serviceSpec.GetOptions()
if serviceOptions != nil {
if serviceOptions.GetDeprecated() {
r.P(generatedFileStream, "/**\n * @deprecated\n */")
}
}
r.P(
generatedFileStream,
"export class "+strcase.ToCamel(serviceSpec.GetName())+"Client",
Expand All @@ -168,6 +187,13 @@ func (r *Runner) generateTypescriptClient(generatedFileStream *protogen.Generate
}

func (r *Runner) generateTypescriptClientMethod(generatedFileStream *protogen.GeneratedFile, serviceSpec *descriptorpb.ServiceDescriptorProto, methodSpec *descriptorpb.MethodDescriptorProto) {
methodOptions := methodSpec.GetOptions()
isDeprecated := methodOptions != nil && methodOptions.GetDeprecated()

if isDeprecated {
r.P(generatedFileStream, "/**\n * @deprecated\n */")
}

// Function's Signature
methodName := strcase.ToCamel(methodSpec.GetName())
r.P(generatedFileStream, "public "+methodName+"(")
Expand Down Expand Up @@ -205,6 +231,10 @@ func (r *Runner) generateTypescriptClientMethod(generatedFileStream *protogen.Ge
r.P(generatedFileStream, "): "+returnType+" {")
r.indentLevel += 2

if isDeprecated {
r.P(generatedFileStream, "this.logger?.warn('using deprecated service method \\'"+strcase.ToCamel(serviceSpec.GetName())+"Client."+methodName+"\\'')")
}

if clientStream && serverStrean {
r.P(generatedFileStream, "return this.makeBidiStreamRequest('"+methodName+"', metadata, options)")
} else if !clientStream && !serverStrean {
Expand Down
10 changes: 10 additions & 0 deletions tests/__tests__/generated/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,20 +503,26 @@ export namespace Foo {

export interface IUsersClient
extends joinGRPC.IExtendedClient<IUsersServiceImplementation, 'foo.Users'> {
/**
* @deprecated
*/
Find(
request: IRequest,
metadata?: Record<string, string>,
options?: grpc.CallOptions
): joinGRPC.IUnaryRequest<Common_Common.IOtherPkgMessage>

FindClientStream(
metadata?: Record<string, string>,
options?: grpc.CallOptions
): joinGRPC.IClientStreamRequest<IRequest, Common_Common.IOtherPkgMessage>

FindServerStream(
request: IRequest,
metadata?: Record<string, string>,
options?: grpc.CallOptions
): grpc.ClientReadableStream<Common_Common.IOtherPkgMessage>

FindBidiStream(
metadata?: Record<string, string>,
options?: grpc.CallOptions
Expand All @@ -532,11 +538,15 @@ export namespace Foo {
super(config, 'foo.Users')
}

/**
* @deprecated
*/
public Find(
request: IRequest,
metadata?: Record<string, string>,
options?: grpc.CallOptions
): joinGRPC.IUnaryRequest<Common_Common.IOtherPkgMessage> {
this.logger?.warn("using deprecated service method 'UsersClient.Find'")
return this.makeUnaryRequest('Find', request, metadata, options)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"dependencies": {
"@join-com/gcloud-logger-trace": "^0.1.17",
"@join-com/grpc": "^0.2.1",
"@join-com/grpc": "^0.3.3",
"@join-com/grpc-ts": "^2.0.2",
"grpc": "^1.24.6",
"grpc": "^1.24.7",
"protobufjs": "^6.10.2"
},
"devDependencies": {
Expand Down
84 changes: 21 additions & 63 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@
dependencies:
grpc "^1.24.5"

"@join-com/grpc@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@join-com/grpc/-/grpc-0.2.1.tgz#8d993c0f1a38f01993ed32c1b2efe9220aeff29c"
integrity sha512-wEM3WSWsM6CznW99v8VT9z47+Il7+91XWew8/6GVNhngNnomxQRHI40MC9L0Vpb3G+GRjgOA/w4UO7KEj2xZRw==
"@join-com/grpc@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@join-com/grpc/-/grpc-0.3.3.tgz#9efdb8b57d941dc2b9288362b1c21cec3026096d"
integrity sha512-LrkOlKH9iH74CN0kpSZ9efScf+xG9tpXU5+4z1YCIe2fKPLlfnQ9Io/lu8eld2iu2cQGVWB2IoXaKDrv8Y8jYQ==
dependencies:
"@grpc/grpc-js" "^1.2.12"
protobufjs "^6.10.2"
Expand Down Expand Up @@ -1276,13 +1276,13 @@ browser-process-hrtime@^1.0.0:
integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==

browserslist@^4.14.5:
version "4.16.4"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.4.tgz#7ebf913487f40caf4637b892b268069951c35d58"
integrity sha512-d7rCxYV8I9kj41RH8UKYnvDYCRENUlHRgyXy/Rhr/1BaeLGfiCptEdFE8MIrvGfWbBFNjVYx76SQWvNX1j+/cQ==
version "4.16.5"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.5.tgz#952825440bca8913c62d0021334cbe928ef062ae"
integrity sha512-C2HAjrM1AI/djrpAUU/tr4pml1DqLIzJKSLDBXBrNErl9ZCCTXdhwxdJjYc16953+mBWf7Lw+uUJgpgb8cN71A==
dependencies:
caniuse-lite "^1.0.30001208"
caniuse-lite "^1.0.30001214"
colorette "^1.2.2"
electron-to-chromium "^1.3.712"
electron-to-chromium "^1.3.719"
escalade "^3.1.1"
node-releases "^1.1.71"

Expand Down Expand Up @@ -1332,14 +1332,6 @@ cache-base@^1.0.1:
union-value "^1.0.0"
unset-value "^1.0.0"

call-bind@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==
dependencies:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"

callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
Expand All @@ -1360,7 +1352,7 @@ camelcase@^6.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==

caniuse-lite@^1.0.30001208:
caniuse-lite@^1.0.30001214:
version "1.0.30001214"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001214.tgz#70f153c78223515c6d37a9fde6cd69250da9d872"
integrity sha512-O2/SCpuaU3eASWVaesQirZv1MSjUNOvmugaD8zNSJqw6Vv5SGwoOpA9LJs3pNPfM745nxqPvfZY3MQKY4AKHYg==
Expand Down Expand Up @@ -1735,10 +1727,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.712:
version "1.3.719"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.719.tgz#87166fee347a46a2557f19aadb40a1d68241e61c"
integrity sha512-heM78GKSqrIzO9Oz0/y22nTBN7bqSP1Pla2SyU9DiSnQD+Ea9SyyN5RWWlgqsqeBLNDkSlE9J9EHFmdMPzxB/g==
electron-to-chromium@^1.3.719:
version "1.3.720"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.720.tgz#f5d66df8754d993006b7b2ded15ff7738c58bd94"
integrity sha512-B6zLTxxaOFP4WZm6DrvgRk8kLFYWNhQ5TrHMC0l5WtkMXhU5UbnvWoTfeEwqOruUSlNMhVLfYak7REX6oC5Yfw==

emittery@^0.7.1:
version "0.7.2"
Expand Down Expand Up @@ -2252,15 +2244,6 @@ get-caller-file@^2.0.1:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

get-intrinsic@^1.0.2:
version "1.1.1"
resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6"
integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==
dependencies:
function-bind "^1.1.1"
has "^1.0.3"
has-symbols "^1.0.1"

get-package-type@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/get-package-type/-/get-package-type-0.1.0.tgz#8de2d803cff44df3bc6c456e6668b36c3926e11a"
Expand Down Expand Up @@ -2374,10 +2357,10 @@ growly@^1.3.0:
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=

grpc@^1.24.5, grpc@^1.24.6:
version "1.24.6"
resolved "https://registry.yarnpkg.com/grpc/-/grpc-1.24.6.tgz#1862a9d990f79cfa20b962d77f090000d915469c"
integrity sha512-BtifKdClMYU0ZEo0Pdr2WV9ZH54AoEdIcp2BfJkh87g2R3HoNPLYKHRYefw/ByxrCdVDTAy3hkraFISpqsRcrw==
grpc@^1.24.5, grpc@^1.24.7:
version "1.24.7"
resolved "https://registry.yarnpkg.com/grpc/-/grpc-1.24.7.tgz#58d8eb2a8a9c11ccd678f27403ba54ee4ea3d895"
integrity sha512-AFWychfq60LBUrelOWgT5PWk05n98z7/C8qCgeNAJ4YvK8khVNSlbEHMLaCu7COqbX1JwJxSbzw9B9YhnzKeYQ==
dependencies:
"@types/bytebuffer" "^5.0.40"
lodash.camelcase "^4.3.0"
Expand Down Expand Up @@ -2418,11 +2401,6 @@ has-flag@^4.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-symbols@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423"
integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==

has-unicode@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
Expand Down Expand Up @@ -2592,13 +2570,6 @@ is-arrayish@^0.2.1:
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=

is-boolean-object@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.0.tgz#e2aaad3a3a8fca34c28f6eee135b156ed2587ff0"
integrity sha512-a7Uprx8UtD+HWdyYwnD1+ExtTgqQtD2k/1yJgtXP6wnMm8byhkoTZRl+95LLThpzNZJ5aEvi46cdH+ayMFRwmA==
dependencies:
call-bind "^1.0.0"

is-buffer@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
Expand Down Expand Up @@ -2701,11 +2672,6 @@ is-glob@^4.0.0, is-glob@^4.0.1:
dependencies:
is-extglob "^2.1.1"

is-number-object@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.4.tgz#36ac95e741cf18b283fc1ddf5e83da798e3ec197"
integrity sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw==

is-number@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"
Expand Down Expand Up @@ -2740,11 +2706,6 @@ is-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==

is-string@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6"
integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==

is-typedarray@^1.0.0, is-typedarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
Expand Down Expand Up @@ -4798,14 +4759,11 @@ symbol-tree@^3.2.4:
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

table@^6.0.4:
version "6.3.2"
resolved "https://registry.yarnpkg.com/table/-/table-6.3.2.tgz#afa86bee5cfe305f9328f89bb3e5454132cdea28"
integrity sha512-I9/Ca6Huf2oxFag7crD0DhA+arIdfLtWunSn0NIXSzjtUlDgIBGVZY7SsMkNPNT3Psd/z4gza0nuEpmra9eRbg==
version "6.3.4"
resolved "https://registry.yarnpkg.com/table/-/table-6.3.4.tgz#5d8a7fa1c887bd1ef08741751ec36246255a80b6"
integrity sha512-fhKcZ3+oAYG/ld3seJEZ9+fGSsy+yeoPzLQUrwbOzNYdhrU+6TzObhJ2Sp76ZfUGIrDTrxsXz5NSCZJIUOJb4Q==
dependencies:
ajv "^8.0.1"
is-boolean-object "^1.1.0"
is-number-object "^1.0.4"
is-string "^1.0.5"
lodash.clonedeep "^4.5.0"
lodash.flatten "^4.4.0"
lodash.truncate "^4.4.2"
Expand Down

0 comments on commit f2b0f88

Please sign in to comment.