-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Client] adding nodejs cac and experimentation client wrapper #170
base: main
Are you sure you want to change the base?
Conversation
a4de85d
to
02bdbff
Compare
@namitgoel Can you add a README file that documents how to add the nodeJS clients to a project, and also how to build and run them? |
clients/nodejs/cac-client/client.ts
Outdated
|
||
let file = | ||
platform == "darwin" ? | ||
'../../../target/debug/libcac_client.dylib' : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namitgoel lets avoid relative paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation needed + relative paths pointing to the binaries is an issue
clients/nodejs/cac-client/client.ts
Outdated
this.cacHostName = cacHostName; | ||
} | ||
|
||
public getCACLastErrorMessage(): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return just string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Datron we cannot just return string as the response type that ref-napi libraray is providing has return type string | null
clients/nodejs/cac-client/client.ts
Outdated
this.rustLib.cac_start_polling_update(this.tenant) | ||
} | ||
|
||
public getCACConfig(filterQuery: string, filterPrefix: string): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public getCACConfig(filterQuery: string, filterPrefix: string): string | null { | |
public getCACConfig(filterQuery: string, filterPrefix: string): string | Error { |
clients/nodejs/cac-client/client.ts
Outdated
|
||
let file = | ||
platform == "darwin" ? | ||
'../../../target/debug/libcac_client.dylib' : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that file will be present at this path in case of release build too (its specifically pointing to debug directory)?
clients/nodejs/cac-client/client.ts
Outdated
return this.rustLib.cac_get_last_modified(this.getCACClient()); | ||
} | ||
|
||
public getResolvedConfig(query: string, filterKeys: string, mergeStrategy: string): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return type for all functions is string, I am assuming its a JSON string?
Can we define types for these and de-serialize and send an actual object back?
e14669d
to
5364c56
Compare
8e1f007
to
382aba6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most comments apply to both experimentation and cac file, have not repeated few comments
clients/nodejs/cac-client/client.ts
Outdated
}); | ||
|
||
constructor(tenantName: string, pollingFrequency: number, cacHostName: string) { | ||
if (tenantName == "" || cacHostName == "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets separate the if checks, its returning tenantName cannot be null or empty
error when either tenantName
or cacHostName
is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/cac-client/client.ts
Outdated
return this.rustLib.cac_get_last_modified(this.getCACClient()); | ||
} | ||
|
||
public getResolvedConfig(query: Object, filterKeys: string[] | null, mergeStrategy: string): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mergeStrategy is an enum: MERGE, REPLACE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/cac-client/client.ts
Outdated
return this.rustLib.cac_last_error_message(); | ||
} | ||
|
||
public getCACLastErrorLength(): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid repeating CAC
in every function name, these functions are all scoped to the object of CacClient, so adding CAC again in the function name, makes it somewhat redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/cac-client/client.ts
Outdated
return this.rustLib.cac_get_client(this.tenant); | ||
} | ||
|
||
public createNewCACClient(): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the logic for this should ideally be inside the constructor itself, in haskell we needed a separate function, because that's that does not have any constructor, here since there is a constructor, this logic should be inside that itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/exp-client/client.ts
Outdated
return this.rustLib.expt_last_error_message(); | ||
} | ||
|
||
public createNewExperimentaionClient(): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as CacClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/cac-client/client.ts
Outdated
|
||
public getResolvedConfig(query: Object, filterKeys: string[] | null, mergeStrategy: string): string | null { | ||
let strQuery = JSON.stringify(query); | ||
let strFilterKeys = filterKeys == null ? ref.NULL : ref.allocCString(filterKeys.join(this.delimeter)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently the delimiter being used for this function is "|"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/exp-client/client.ts
Outdated
return this.rustLib.expt_get_running_experiments(clientPtr); | ||
} | ||
|
||
public freeString(str: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed as an exposed function
clients/nodejs/exp-client/client.ts
Outdated
return this.rustLib.expt_last_error_length() | ||
} | ||
|
||
public freeExprementationClient() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed as an exposed function
clients/nodejs/cac-client/client.ts
Outdated
this.getCACClient(), strQuery, strFilterKeys, mergeStrategy | ||
) | ||
} | ||
public getDefaultConfig(filterKeys: string[] | null): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the output of the functions are null, then you should check for the error and then return the error caused during the function call (for all functions returning null
| some_value
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
clients/nodejs/exp-client/client.ts
Outdated
this.rustLib.expt_free_client(this.getExperimentationClient()); | ||
} | ||
|
||
public getFilteredSatisfiedExperiments(context: Object, filterPrefix: string[] | null): string | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
places which take input of the form: some_type
| null
, should ideally take some_type
| undefined
type data
Also, make sure to deallocate the data allocated via after it has been used |
382aba6
to
a52defd
Compare
ae783fd
to
a9b01a6
Compare
Problem
Describe the problem you are trying to solve here
Solution
Provide a brief summary of your solution so that reviewers can understand your code
Environment variable changes
What ENVs need to be added or changed
Pre-deployment activity
Things needed to be done before deploying this change (if any)
Post-deployment activity
Things needed to be done after deploying this change (if any)
API changes
Possible Issues in the future
Describe any possible issues that could occur because of this change