@akanjs/base 0.9.48 → 0.9.49

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/cjs/src/base.js CHANGED
@@ -23,14 +23,25 @@ __export(base_exports, {
23
23
  logo: () => logo
24
24
  });
25
25
  module.exports = __toCommonJS(base_exports);
26
+ var import_scalar = require("./scalar");
26
27
  class Enum {
27
28
  constructor(values) {
28
29
  this.values = values;
29
30
  this.valueMap = new Map(values.map((value, idx) => [value, idx]));
31
+ const firstValue = values.at(0);
32
+ if (firstValue === void 0)
33
+ throw new Error("Enum values are empty");
34
+ if (typeof firstValue === "string")
35
+ this.type = String;
36
+ else if (values.every((value) => value % 1 === 0))
37
+ this.type = import_scalar.Int;
38
+ else
39
+ this.type = import_scalar.Float;
30
40
  }
31
41
  value;
32
42
  // for type
33
43
  valueMap;
44
+ type;
34
45
  has(value) {
35
46
  return this.valueMap.has(value);
36
47
  }
package/cjs/src/scalar.js CHANGED
@@ -38,6 +38,7 @@ __export(scalar_exports, {
38
38
  arraiedModel: () => arraiedModel,
39
39
  dayjs: () => dayjs,
40
40
  getNonArrayModel: () => getNonArrayModel,
41
+ gqlScalarMap: () => gqlScalarMap,
41
42
  gqlScalarNames: () => gqlScalarNames,
42
43
  gqlScalars: () => gqlScalars,
43
44
  isGqlClass: () => isGqlClass,
@@ -99,6 +100,17 @@ const applyFnToArrayObjects = (arraiedData, fn) => {
99
100
  const gqlScalars = [String, Boolean, Date, ID, Int, Float, Upload, JSON, Map];
100
101
  const gqlScalarNames = ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"];
101
102
  const scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
103
+ const gqlScalarMap = /* @__PURE__ */ new Map([
104
+ ["ID", ID],
105
+ ["Int", Int],
106
+ ["Float", Float],
107
+ ["String", String],
108
+ ["Boolean", Boolean],
109
+ ["Date", Date],
110
+ ["Upload", Upload],
111
+ ["JSON", JSON],
112
+ ["Map", Map]
113
+ ]);
102
114
  const scalarNameMap = /* @__PURE__ */ new Map([
103
115
  [ID, "ID"],
104
116
  [Int, "Int"],
package/esm/src/base.js CHANGED
@@ -1,11 +1,22 @@
1
+ import { Float, Int } from "./scalar";
1
2
  class Enum {
2
3
  constructor(values) {
3
4
  this.values = values;
4
5
  this.valueMap = new Map(values.map((value, idx) => [value, idx]));
6
+ const firstValue = values.at(0);
7
+ if (firstValue === void 0)
8
+ throw new Error("Enum values are empty");
9
+ if (typeof firstValue === "string")
10
+ this.type = String;
11
+ else if (values.every((value) => value % 1 === 0))
12
+ this.type = Int;
13
+ else
14
+ this.type = Float;
5
15
  }
6
16
  value;
7
17
  // for type
8
18
  valueMap;
19
+ type;
9
20
  has(value) {
10
21
  return this.valueMap.has(value);
11
22
  }
package/esm/src/scalar.js CHANGED
@@ -48,6 +48,17 @@ const applyFnToArrayObjects = (arraiedData, fn) => {
48
48
  const gqlScalars = [String, Boolean, Date, ID, Int, Float, Upload, JSON, Map];
49
49
  const gqlScalarNames = ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"];
50
50
  const scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
51
+ const gqlScalarMap = /* @__PURE__ */ new Map([
52
+ ["ID", ID],
53
+ ["Int", Int],
54
+ ["Float", Float],
55
+ ["String", String],
56
+ ["Boolean", Boolean],
57
+ ["Date", Date],
58
+ ["Upload", Upload],
59
+ ["JSON", JSON],
60
+ ["Map", Map]
61
+ ]);
51
62
  const scalarNameMap = /* @__PURE__ */ new Map([
52
63
  [ID, "ID"],
53
64
  [Int, "Int"],
@@ -93,6 +104,7 @@ export {
93
104
  arraiedModel,
94
105
  dayjs,
95
106
  getNonArrayModel,
107
+ gqlScalarMap,
96
108
  gqlScalarNames,
97
109
  gqlScalars,
98
110
  isGqlClass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/base",
3
- "version": "0.9.48",
3
+ "version": "0.9.49",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/base.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export declare class Enum<T> {
2
- readonly values: T[];
1
+ import { Float, Int } from "./scalar";
2
+ export declare class Enum<T = string | number> {
3
+ readonly values: readonly T[];
3
4
  readonly value: T;
4
5
  readonly valueMap: Map<T, number>;
5
- constructor(values: T[]);
6
+ readonly type: StringConstructor | typeof Int | typeof Float;
7
+ constructor(values: readonly T[]);
6
8
  has(value: T): boolean;
7
9
  indexOf(value: T): number;
8
10
  find(callback: (value: T, index: number, array: T[]) => boolean): T;
@@ -11,7 +13,7 @@ export declare class Enum<T> {
11
13
  map<R>(callback: (value: T, index: number, array: T[]) => R): R[];
12
14
  forEach(callback: (value: T, index: number, array: T[]) => void): void;
13
15
  }
14
- export declare const enumOf: <T>(values: T[]) => Enum<T>;
16
+ export declare const enumOf: <V>(values: readonly V[]) => Enum<V>;
15
17
  export type enumOf<E> = E extends Enum<infer T> ? T : never;
16
18
  export type EnumType<E> = E extends Enum<infer T> ? T : never;
17
19
  export declare class DataList<Light extends {
package/src/scalar.d.ts CHANGED
@@ -30,17 +30,18 @@ export declare class JSON {
30
30
  __Scalar__: "json";
31
31
  }
32
32
  export type SingleFieldType = Int | Float | StringConstructor | BooleanConstructor | ID | DateConstructor | JSON | Type | GraphQLJSON | GraphQLUpload;
33
- export declare const getNonArrayModel: <T = Type>(arraiedModel: T | T[]) => [T, number];
33
+ export declare const getNonArrayModel: <T>(arraiedModel: T | T[]) => [T, number];
34
34
  export declare const arraiedModel: <T = any>(modelRef: T, arrDepth?: number) => T | T[];
35
35
  export declare const applyFnToArrayObjects: (arraiedData: any, fn: (arg: any) => any) => any[];
36
36
  export declare const gqlScalars: readonly [StringConstructor, BooleanConstructor, DateConstructor, typeof ID, typeof Int, typeof Float, typeof Upload, typeof JSON, MapConstructor];
37
37
  export type GqlScalar = (typeof gqlScalars)[number];
38
38
  export declare const gqlScalarNames: readonly ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"];
39
39
  export type GqlScalarName = (typeof gqlScalarNames)[number];
40
- export declare const scalarSet: Set<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor>;
41
- export declare const scalarNameMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, "ID" | "Int" | "Float" | "String" | "Boolean" | "Date" | "Upload" | "JSON" | "Map">;
42
- export declare const scalarArgMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, any>;
43
- export declare const scalarDefaultMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, any>;
40
+ export declare const scalarSet: Set<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor>;
41
+ export declare const gqlScalarMap: Map<"ID" | "Int" | "Float" | "String" | "Boolean" | "Date" | "Upload" | "JSON" | "Map", typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor>;
42
+ export declare const scalarNameMap: Map<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor, "ID" | "Int" | "Float" | "String" | "Boolean" | "Date" | "Upload" | "JSON" | "Map">;
43
+ export declare const scalarArgMap: Map<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor, any>;
44
+ export declare const scalarDefaultMap: Map<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor, any>;
44
45
  export declare const isGqlClass: (modelRef: Type) => boolean;
45
46
  export declare const isGqlScalar: (modelRef: Type) => boolean;
46
47
  export declare const isGqlMap: (modelRef: any) => boolean;
package/src/types.d.ts CHANGED
@@ -70,9 +70,20 @@ export type MergeAllKeyOfTypes<T extends Type<{
70
70
  infer First extends Type,
71
71
  ...infer Rest extends Type[]
72
72
  ] ? Rest extends [] ? UnType<First>[Key] : MergeAllKeyOfTypes<Rest, Key> & UnType<First>[Key] : unknown;
73
+ export type MergeAllKeyOfObjects<T extends {
74
+ [key: string]: any;
75
+ }[], Key extends string> = T extends [
76
+ infer First extends {
77
+ [key: string]: any;
78
+ },
79
+ ...infer Rest extends {
80
+ [key: string]: any;
81
+ }[]
82
+ ] ? Rest extends [] ? First[Key] : MergeAllKeyOfObjects<Rest, Key> & First[Key] : unknown;
73
83
  export type Primitive = string | number | boolean | null | undefined;
74
84
  export type NestedKeysWithAllowed<T, Allowed = Primitive> = T extends Primitive ? never : T extends any[] ? never : T extends (...args: any[]) => any ? never : {
75
85
  [K in keyof T & string]: T[K] extends Allowed ? K : T[K] extends Dayjs ? never : T[K] extends {
76
86
  [key: string]: any;
77
87
  } ? K | `${K}.${NestedKeysWithAllowed<T[K], Allowed>}` : never;
78
88
  }[keyof T & string];
89
+ export type SingleValue<Value> = Value extends (infer V)[] ? SingleValue<V> : Value;