corebasic 1.0.255 → 1.0.256

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.
Files changed (2) hide show
  1. package/libs/features.ts +6 -6
  2. package/package.json +1 -1
package/libs/features.ts CHANGED
@@ -55,12 +55,12 @@ type FeatureMeta = {
55
55
  version: string,
56
56
  txn: string,
57
57
  // invoiceTxn?: string // TODO: Must also include invoiceTxn
58
- topic: string,
58
+ topic: keyof Schema,
59
59
  date: number,
60
60
  }
61
61
  export type FeatureParams = Record<string, string>
62
- type FeatureMessage<I = unknown> = {
63
- meta: FeatureMeta
62
+ type FeatureMessage<I = unknown, T extends keyof Schema = keyof Schema> = {
63
+ meta: FeatureMeta & { topic: T }
64
64
  data: I
65
65
  params: FeatureParams
66
66
 
@@ -120,7 +120,7 @@ type ExpressApplication = { [Method in HttpMethod]: (path: string, handler: Expr
120
120
  // type Handler = Query | Command
121
121
 
122
122
  declare global {
123
- type Handler<I, O> = (input: FeatureMessage<I>, req?: Req, res?: Res) => Promise<O>
123
+ type Handler<I, O, T extends keyof Schema> = (input: FeatureMessage<I, T>, req?: Req, res?: Res) => Promise<O>
124
124
 
125
125
  interface FeatureTypes {
126
126
  // "privileges.query.check": Handler<{feature: string}, {data: {granted: boolean} }>
@@ -142,7 +142,7 @@ type RemoteFeatureEntry = {
142
142
  headers?: {JWT?: string, service?: boolean, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN?: string}
143
143
  }
144
144
 
145
- type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown> }
145
+ type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema> }
146
146
 
147
147
 
148
148
  let features: Record<string, FeatureEntry> = {}
@@ -191,7 +191,7 @@ export const get = (feature: string) => {
191
191
  }
192
192
 
193
193
 
194
- type HandlerInput<T> = T extends Handler<infer I, any> ? I : never
194
+ type HandlerInput<T> = T extends Handler<infer I, any, keyof Schema> ? I : never
195
195
 
196
196
  export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureMeta>, feature: K, data?: HandlerInput<FeatureTypes[K]>, params?: FeatureParams): Promise<Awaited<ReturnType<FeatureTypes[K]>>> => {
197
197
  const throwError = () => {throw new Error(`Feature ${feature} not found in internal or external list during inter feature call`)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.255",
4
+ "version": "1.0.256",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",