corebasic 1.0.232 → 1.0.234

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/libs/features.ts CHANGED
@@ -58,10 +58,10 @@ export type Req = {
58
58
  params: FeatureParams
59
59
  method: string
60
60
  path: string
61
- url?: string
62
- headers?: Record<string, string | string[] | undefined>
63
- query?: Record<string, unknown>
64
- on?: (event: string, callback: () => void) => void
61
+ url: string
62
+ headers: Record<string, string | string[] | undefined>
63
+ query: Record<string, unknown>
64
+ on: (event: string, callback: () => void) => void
65
65
  }
66
66
 
67
67
  type ResJson = (response: unknown) => void
@@ -174,7 +174,7 @@ export const send = async (meta: Partial<FeatureMeta>, feature: string, data?: u
174
174
  // return (await axios[method](`${service}${url}`, payload, {headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data // Worked Earlier, but issue spotted
175
175
  if (baseFeature) { // Local call
176
176
  let response;
177
- let req: ExpressRequest = { body: payload, params: params ?? {}, method, path: url, url: ''}
177
+ let req: ExpressRequest = { body: payload, params: params ?? {}, method, path: url, url: '', headers: {}, query: {}, on: (_event: string, _callback:()=>void) => {} }
178
178
  req = JSON.parse(JSON.stringify(req))
179
179
  const callback = (payload: unknown): void => { response = payload }
180
180
  const res: ExpressResponse = {
@@ -207,7 +207,7 @@ async function announce() {
207
207
  for (let [key, {api,subscribe}] of Object.entries(features))
208
208
  exp_features[key] = {api, service: SERVICE_ADDRESS, subscribe, topic: ""}
209
209
 
210
- await Messaging.subscribe(`${process.env.REDIS_CHANNEL_PREFIX}_SLYP_FEATURES_LIST`, async (message, channel) => {
210
+ await Messaging.subscribe(`${process.env.REDIS_CHANNEL_PREFIX}_SLYP_FEATURES_LIST`, async (message, _channel) => {
211
211
  let {uid, ...msg} = JSON.parse(message) as Record<string, RemoteFeatureEntry> & {uid: string}
212
212
  if (uid !== appId && !appids[uid]) {
213
213
  appids[uid] = true
@@ -220,7 +220,7 @@ async function announce() {
220
220
  }
221
221
 
222
222
 
223
- function getFeaturelessFeature(req: ExpressRequest) {
223
+ function getFeaturelessFeature(req: ExpressRequest): FeatureEntry | undefined {
224
224
  if (Session.ALLOWED_URLS.includes(req.path)) {
225
225
  for(let key in features) {
226
226
  const feature = features[key]!
@@ -229,6 +229,7 @@ function getFeaturelessFeature(req: ExpressRequest) {
229
229
  }
230
230
  }
231
231
  }
232
+ return undefined
232
233
  }
233
234
 
234
235
  const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
@@ -381,7 +382,7 @@ export const start = async (app: ExpressApplication, url: URL, file: string) =>
381
382
  features = await Utils.fileToJson(url, file) as Record<string, FeatureEntry>
382
383
  await announce()
383
384
 
384
- app.get('/features', async (req: ExpressRequest, res: ExpressResponse) => {
385
+ app.get('/features', async (_req: ExpressRequest, res: ExpressResponse) => {
385
386
  let exp_features: Record<string, RemoteFeatureEntry> = {}
386
387
  for (let [key, {api}] of Object.entries(features))
387
388
  exp_features[key] = {api, service: `${SERVICE_ADDRESS}`, subscribe: '', topic: ''}
@@ -535,7 +536,7 @@ async function subscribe() {
535
536
  kafka_consumer_promise
536
537
  .then(kafka_consumer => {
537
538
  subscribed_consumers[consumer] = kafka_consumer
538
- }).catch(err => {
539
+ }).catch(() => {
539
540
  throw new Error("Error: Remote service to service kafka Feature subscription.")
540
541
  })
541
542
  }
package/libs/kafka.ts CHANGED
@@ -54,7 +54,7 @@ type KafkaStartArg = {
54
54
  username?: string
55
55
  password?: string
56
56
  }
57
- logLevel?: unknown
57
+ logLevel?: KafkaLogLevel
58
58
  }
59
59
 
60
60
 
@@ -114,11 +114,11 @@ const start_consumer = async function<T>(topic: string, groupId: string, callbac
114
114
  autoCommit: false,
115
115
  eachMessage: async ({ topic, partition, message }) => {
116
116
  // callback(topic, message.value.toString(), partition) // toString() returns array so won't parse if json.
117
- let success
117
+
118
118
  try {
119
- success = await callback(topic, JSON.parse(message.value as string), partition)
119
+ await callback(topic, JSON.parse(message.value as string), partition)
120
120
  } catch (ex) {
121
- success = await callback(topic, message.value as T, partition) // NOTE: Beware: Ensure Kafka.receive<T> can handle raw message type that is not json parseable
121
+ await callback(topic, message.value as T, partition) // NOTE: Beware: Ensure Kafka.receive<T> can handle raw message type that is not json parseable
122
122
  }
123
123
 
124
124
  await consumer.commitOffsets([{ topic, partition, offset: (Number(message.offset) + 1).toString() }]);
package/libs/messaging.ts CHANGED
@@ -10,20 +10,22 @@ const url = process.env.REDIS_URL || "redis://localhost:6380"
10
10
 
11
11
  // url: 'redis://alice:foobared@localhost:6380'
12
12
 
13
+ type RedisConsumer = ReturnType<typeof createClient>;
14
+ type RedisPublisher = ReturnType<typeof createClient>;
13
15
 
14
16
  type RedisListener = (message: string, channel: string) => void
15
17
 
16
- type RedisConsumer = {
17
- connect: () => Promise<void>
18
- subscribe: (channel: string, listener: RedisListener) => Promise<void>
19
- unsubscribe: (channel: string, listener: RedisListener) => Promise<void>
20
- on: (event: string, listener: (err: unknown) => void) => void
21
- }
22
-
23
- type RedisPublisher = {
24
- connect: () => Promise<void>
25
- publish: (channel: string, message: string) => Promise<unknown>
26
- }
18
+ // type RedisConsumer = {
19
+ // connect: () => Promise<void>
20
+ // subscribe: (channel: string, listener: RedisListener) => Promise<void>
21
+ // unsubscribe: (channel: string, listener: RedisListener) => Promise<void>
22
+ // on: (event: string, listener: (err: unknown) => void) => void
23
+ // }
24
+ //
25
+ // type RedisPublisher = {
26
+ // connect: () => Promise<void>
27
+ // publish: (channel: string, message: string) => Promise<unknown>
28
+ // }
27
29
 
28
30
  type Request = {
29
31
  body: {
@@ -102,7 +104,7 @@ async function connect({user, req, res, uid}: {user: string, req: Request, res:
102
104
  const listener = (message: string, channel: string) => {
103
105
  if (users_pool[user]) {
104
106
  try {message = JSON.parse(message)} catch {}
105
- for (let {req, res} of users_pool[user].reqres) {
107
+ for (let {res} of users_pool[user].reqres) {
106
108
  res.write(JSON.stringify({message, channel}) + "\n")
107
109
  if (res.flush) // If compression enabled
108
110
  res.flush()
@@ -123,7 +125,7 @@ export async function start(app: ExpressApp) {
123
125
  publisher = createClient({ url });
124
126
  await publisher.connect();
125
127
 
126
- consumer.on('error', err => console.log('Redis Client Error', err));
128
+ consumer.on('error', (err: any) => console.log('Redis Client Error', err));
127
129
 
128
130
  app.get('/messages/:user', async (req, res) => {
129
131
  let uid = req.body.client
package/libs/utils.ts CHANGED
@@ -40,7 +40,7 @@ export function isEmpty(str: undefined | number | string): boolean { // returns
40
40
  export let GLOBAL_META = { company: "GLOBAL", outlet: "GLOBAL" }
41
41
 
42
42
  export function isEmptyJson(json: object): boolean {
43
- for (let i in json)
43
+ for (let _i in json)
44
44
  return false
45
45
  return true
46
46
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.232",
4
+ "version": "1.0.234",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",
package/tsconfig.json CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  // Stricter Typechecking Options
29
29
  "noUncheckedIndexedAccess": true,
30
- "exactOptionalPropertyTypes": false,
30
+ // "exactOptionalPropertyTypes": false,
31
31
 
32
32
  // Style Options
33
33
  // "noImplicitReturns": true,
@@ -45,5 +45,20 @@
45
45
  "noUncheckedSideEffectImports": true,
46
46
  "moduleDetection": "force",
47
47
  "skipLibCheck": true,
48
+
49
+ "noUncheckedIndexedAccess": true,
50
+ "exactOptionalPropertyTypes": true,
51
+ "noImplicitReturns": true,
52
+ "noFallthroughCasesInSwitch": true,
53
+ "noUnusedLocals": true,
54
+ "noUnusedParameters": true,
55
+ "noImplicitOverride": true,
56
+ "allowUnusedLabels": false,
57
+ "allowUnreachableCode": false,
58
+ "noImplicitAny": true,
59
+ // "declaration": true, // generate dist/*.d.ts files
60
+ // "composite": true,
61
+ // "isolatedDeclarations": true,
62
+ // "noPropertyAccessFromIndexSignature": true, // Useless as all obj.foo now has to use obj["foo"]. No added benefit yet negative overall experience
48
63
  }
49
64
  }