corebasic 1.0.248 → 1.0.250

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.
@@ -15,6 +15,31 @@ import * as Messaging from './messaging.js';
15
15
  import axios from 'axios';
16
16
  // @ts-ignore
17
17
  import jwt from 'jsonwebtoken';
18
+ // ===================================
19
+ function deepFreeze(obj) {
20
+ if (obj && typeof obj === "object" && !Object.isFrozen(obj)) {
21
+ Object.freeze(obj);
22
+ for (const key of Object.keys(obj)) {
23
+ deepFreeze(obj[key]);
24
+ }
25
+ }
26
+ return obj;
27
+ }
28
+ class FMeta {
29
+ // declare staff?: string,
30
+ // declare user?: string,
31
+ // declare app?: string,
32
+ // declare client?: string,
33
+ // declare version?: string,
34
+ // invoiceTxn?: string // TODO: Must also include invoiceTxn
35
+ constructor(obj) {
36
+ Object.assign(this, deepFreeze(obj));
37
+ Object.freeze(this);
38
+ }
39
+ }
40
+ export function noMeta() {
41
+ return new FMeta({});
42
+ }
18
43
  let features = {};
19
44
  let apis = {
20
45
  // <api>: {<feature>: FeatureEntry}
@@ -59,6 +84,7 @@ export const get = (feature) => {
59
84
  let { api, service = SERVICE_ADDRESS, topic } = baseFeature ? baseFeature : (SLYP_FEATURES_LIST[feature] ?? throwError());
60
85
  return { api, service, topic };
61
86
  };
87
+ // export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureMeta>, feature: K, data?: Parameters<FeatureTypes[K]>[0]["data"], params?: FeatureParams): Promise<Awaited<ReturnType<FeatureTypes[K]>>> => {
62
88
  export const send = async (meta, feature, data, params) => {
63
89
  const throwError = () => { throw new Error(`Feature ${feature} not found in internal or external list during inter feature call`); };
64
90
  const baseFeature = getFeature(feature);
package/libs/features.ts CHANGED
@@ -9,6 +9,36 @@ import axios from 'axios'
9
9
  import jwt from 'jsonwebtoken'
10
10
 
11
11
 
12
+ // ===================================
13
+ function deepFreeze(obj: Record<string, any>) {
14
+ if (obj && typeof obj === "object" && !Object.isFrozen(obj)) {
15
+ Object.freeze(obj);
16
+
17
+ for (const key of Object.keys(obj)) {
18
+ deepFreeze(obj[key]);
19
+ }
20
+ }
21
+ return obj;
22
+ }
23
+ class FMeta {
24
+ declare company?: string;
25
+ declare outlet?: string
26
+ // declare staff?: string,
27
+ // declare user?: string,
28
+ // declare app?: string,
29
+ // declare client?: string,
30
+ // declare version?: string,
31
+ // invoiceTxn?: string // TODO: Must also include invoiceTxn
32
+
33
+ constructor(obj: Record<string, unknown>) {
34
+ Object.assign(this, deepFreeze(obj));
35
+ Object.freeze(this);
36
+ }
37
+ }
38
+ export function noMeta(): FMeta {
39
+ return new FMeta({})
40
+ }
41
+
12
42
  // ===================================
13
43
 
14
44
  type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "connect" | "trace"
@@ -157,8 +187,9 @@ export const get = (feature: string) => {
157
187
  }
158
188
 
159
189
 
160
-
161
- export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureMeta>, feature: K, data?: Parameters<FeatureTypes[K]>[0], params?: FeatureParams): Promise<Awaited<ReturnType<FeatureTypes[K]>>> => {
190
+ type HandlerInput<T> = T extends Handler<infer I, any> ? I : never
191
+ // export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureMeta>, feature: K, data?: Parameters<FeatureTypes[K]>[0]["data"], params?: FeatureParams): Promise<Awaited<ReturnType<FeatureTypes[K]>>> => {
192
+ export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureMeta>, feature: K, data?: HandlerInput<FeatureTypes[K]>, params?: FeatureParams): Promise<Awaited<ReturnType<FeatureTypes[K]>>> => {
162
193
  const throwError = () => {throw new Error(`Feature ${feature} not found in internal or external list during inter feature call`)}
163
194
  const baseFeature: FeatureEntry | undefined = getFeature(feature)
164
195
  let {api, service = SERVICE_ADDRESS} = baseFeature ? baseFeature as FeatureEntry & {service: string} : (SLYP_FEATURES_LIST[feature] ?? throwError())
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.248",
4
+ "version": "1.0.250",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",