@akanjs/constant 0.9.56 → 0.9.57

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.
@@ -193,12 +193,12 @@ const extendModelObjects = (inputRef, fieldMap, ...libObjectModelRefs) => {
193
193
  const extendModelInsights = (fieldMap, ...insightModelRefs) => {
194
194
  const baseInsightModelRef = insightModelRefs.at(0);
195
195
  const insightFieldMetaMap = baseInsightModelRef ? (0, import_scalar.getFieldMetaMap)(baseInsightModelRef) : new Map([...baseInsightFieldMetaMap]);
196
- class BaseInsight {
196
+ class BaseInsight2 {
197
197
  }
198
- (0, import_scalar.setFieldMetaMap)(BaseInsight, insightFieldMetaMap);
199
- import_constantInfo.constantInfo.setModelType(BaseInsight, "insight");
198
+ (0, import_scalar.setFieldMetaMap)(BaseInsight2, insightFieldMetaMap);
199
+ import_constantInfo.constantInfo.setModelType(BaseInsight2, "insight");
200
200
  Object.entries(fieldMap).forEach(([key, fieldInfo]) => {
201
- fieldInfo.applyFieldMeta(BaseInsight, key);
201
+ fieldInfo.applyFieldMeta(BaseInsight2, key);
202
202
  });
203
- return BaseInsight;
203
+ return BaseInsight2;
204
204
  };
@@ -49,8 +49,6 @@ const makeDefault = (modelRef, option = {}) => {
49
49
  else if (metadata.default) {
50
50
  if (typeof metadata.default === "function")
51
51
  result[metadata.key] = metadata.default();
52
- else if (metadata.default instanceof import_base.Enum)
53
- result[metadata.key] = [...metadata.default.values];
54
52
  else
55
53
  result[metadata.key] = metadata.default;
56
54
  } else if (metadata.isArray)
@@ -32,10 +32,10 @@ class FieldInfo {
32
32
  constructor(value, option) {
33
33
  this.value = value;
34
34
  const [singleValue, arrDepth] = (0, import_base.getNonArrayModel)(value);
35
- const isEnum = singleValue instanceof import_base.Enum;
36
- const valueType = isEnum ? (0, import_base.arraiedModel)(singleValue.type, arrDepth) : value;
35
+ const isEnumValue = (0, import_base.isEnum)(singleValue);
36
+ const valueType = isEnumValue ? (0, import_base.arraiedModel)(singleValue.type, arrDepth) : value;
37
37
  this.type = valueType;
38
- this.option = { ...option, ...isEnum ? { enum: singleValue } : {} };
38
+ this.option = { ...option, ...isEnumValue ? { enum: singleValue } : {} };
39
39
  }
40
40
  optional() {
41
41
  return new FieldInfo(this.value, { ...this.option, nullable: true });
package/cjs/src/types.js CHANGED
@@ -28,5 +28,6 @@ var import_base = require("@akanjs/base");
28
28
  const DEFAULT_PAGE_SIZE = 20;
29
29
  const unsetDate = (0, import_base.dayjs)(/* @__PURE__ */ new Date("0000"));
30
30
  const MAX_INT = 2147483647;
31
- const Responsive = (0, import_base.enumOf)(["xl", "lg", "md", "sm", "xs"]);
31
+ class Responsive extends (0, import_base.enumOf)("responsive", ["xl", "lg", "md", "sm", "xs"]) {
32
+ }
32
33
  const responsiveWidths = [1200, 992, 768, 576, 0];
@@ -174,14 +174,14 @@ const extendModelObjects = (inputRef, fieldMap, ...libObjectModelRefs) => {
174
174
  const extendModelInsights = (fieldMap, ...insightModelRefs) => {
175
175
  const baseInsightModelRef = insightModelRefs.at(0);
176
176
  const insightFieldMetaMap = baseInsightModelRef ? getFieldMetaMap(baseInsightModelRef) : new Map([...baseInsightFieldMetaMap]);
177
- class BaseInsight {
177
+ class BaseInsight2 {
178
178
  }
179
- setFieldMetaMap(BaseInsight, insightFieldMetaMap);
180
- constantInfo.setModelType(BaseInsight, "insight");
179
+ setFieldMetaMap(BaseInsight2, insightFieldMetaMap);
180
+ constantInfo.setModelType(BaseInsight2, "insight");
181
181
  Object.entries(fieldMap).forEach(([key, fieldInfo]) => {
182
- fieldInfo.applyFieldMeta(BaseInsight, key);
182
+ fieldInfo.applyFieldMeta(BaseInsight2, key);
183
183
  });
184
- return BaseInsight;
184
+ return BaseInsight2;
185
185
  };
186
186
  export {
187
187
  via
@@ -1,4 +1,4 @@
1
- import { Enum, scalarDefaultMap } from "@akanjs/base";
1
+ import { scalarDefaultMap } from "@akanjs/base";
2
2
  import { capitalize } from "@akanjs/common";
3
3
  import { constantInfo } from "./constantInfo";
4
4
  import { getFieldMetas } from "./scalar";
@@ -27,8 +27,6 @@ const makeDefault = (modelRef, option = {}) => {
27
27
  else if (metadata.default) {
28
28
  if (typeof metadata.default === "function")
29
29
  result[metadata.key] = metadata.default();
30
- else if (metadata.default instanceof Enum)
31
- result[metadata.key] = [...metadata.default.values];
32
30
  else
33
31
  result[metadata.key] = metadata.default;
34
32
  } else if (metadata.isArray)
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  arraiedModel,
3
- Enum,
4
3
  getNonArrayModel,
4
+ isEnum,
5
5
  isGqlMap,
6
6
  isGqlScalar
7
7
  } from "@akanjs/base";
@@ -18,10 +18,10 @@ class FieldInfo {
18
18
  constructor(value, option) {
19
19
  this.value = value;
20
20
  const [singleValue, arrDepth] = getNonArrayModel(value);
21
- const isEnum = singleValue instanceof Enum;
22
- const valueType = isEnum ? arraiedModel(singleValue.type, arrDepth) : value;
21
+ const isEnumValue = isEnum(singleValue);
22
+ const valueType = isEnumValue ? arraiedModel(singleValue.type, arrDepth) : value;
23
23
  this.type = valueType;
24
- this.option = { ...option, ...isEnum ? { enum: singleValue } : {} };
24
+ this.option = { ...option, ...isEnumValue ? { enum: singleValue } : {} };
25
25
  }
26
26
  optional() {
27
27
  return new FieldInfo(this.value, { ...this.option, nullable: true });
package/esm/src/types.js CHANGED
@@ -2,7 +2,8 @@ import { dayjs, enumOf } from "@akanjs/base";
2
2
  const DEFAULT_PAGE_SIZE = 20;
3
3
  const unsetDate = dayjs(/* @__PURE__ */ new Date("0000"));
4
4
  const MAX_INT = 2147483647;
5
- const Responsive = enumOf(["xl", "lg", "md", "sm", "xs"]);
5
+ class Responsive extends enumOf("responsive", ["xl", "lg", "md", "sm", "xs"]) {
6
+ }
6
7
  const responsiveWidths = [1200, 992, 768, 576, 0];
7
8
  export {
8
9
  DEFAULT_PAGE_SIZE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/constant",
3
- "version": "0.9.56",
3
+ "version": "0.9.57",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/baseGql.d.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import "reflect-metadata";
2
- import { BaseObject, type MergeAllTypes, type Prettify, Type } from "@akanjs/base";
2
+ import { BaseInsight, BaseObject, type MergeAllTypes, type Prettify, Type } from "@akanjs/base";
3
3
  import { type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, FieldResolver } from "./fieldInfo";
4
4
  import type { NonFunctionalKeys } from "./types";
5
5
  type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
6
6
  type OmitBase<T> = Omit<T, BaseFields>;
7
7
  export declare function via<T extends BaseObject, K extends NonFunctionalKeys<OmitBase<T>>, ResolveField extends (resolve: FieldResolver) => FieldInfoObject, LightModels extends Type[]>(modelRef: Type<T>, fields: readonly K[], resolveField: ResolveField, ...lightModelRefs: LightModels): Type<Prettify<MergeAllTypes<LightModels> & Pick<T, K> & BaseObject & ExtractFieldInfoObject<ReturnType<ResolveField>>>>;
8
8
  export declare function via<BuildField extends (builder: FieldBuilder) => FieldInfoObject, Inputs extends Type[]>(buildField: BuildField, ...extendInputRefs: Inputs): Type<MergeAllTypes<Inputs> & ExtractFieldInfoObject<ReturnType<BuildField>>>;
9
- export declare function via<T extends BaseObject, BuildField extends (builder: FieldBuilder) => FieldInfoObject, Insights extends Type[]>(modelRef: Type<T>, buildField: BuildField, ...extendInsightRefs: Insights): Type<MergeAllTypes<Insights> & {
10
- count: number;
11
- } & ExtractFieldInfoObject<ReturnType<BuildField>>>;
9
+ export declare function via<T extends BaseObject, BuildField extends (builder: FieldBuilder) => FieldInfoObject, Insights extends Type[]>(modelRef: Type<T>, buildField: BuildField, ...extendInsightRefs: Insights): Type<MergeAllTypes<Insights> & BaseInsight & ExtractFieldInfoObject<ReturnType<BuildField>>>;
12
10
  export declare function via<T, BuildField extends (builder: FieldBuilder) => FieldInfoObject, ObjectModels extends Type[]>(inputRef: Type<T>, buildField: BuildField, ...extendObjectRefs: ObjectModels): Type<Prettify<MergeAllTypes<ObjectModels> & T & BaseObject & ExtractFieldInfoObject<ReturnType<BuildField>>>>;
13
11
  export declare function via<T, Light, ResolveField extends (resolve: FieldResolver) => FieldInfoObject, FullModels extends Type[]>(objectRef: Type<T>, lightModelRef: Type<Light>, resolveField: ResolveField, ...fullModelRefs: FullModels): Type<Prettify<MergeAllTypes<FullModels> & T & Light & ExtractFieldInfoObject<ReturnType<ResolveField>>>>;
14
12
  export {};
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { type Enum, type Type } from "@akanjs/base";
2
+ import { type EnumInstance, type Type } from "@akanjs/base";
3
3
  export declare const setExtendRef: (modelRef: Type, extendRef: Type) => void;
4
4
  export declare const getExtendRef: <AllowEmpty extends boolean = false>(modelRef: Type, { allowEmpty }?: {
5
5
  allowEmpty?: AllowEmpty;
@@ -7,6 +7,6 @@ export declare const getExtendRef: <AllowEmpty extends boolean = false>(modelRef
7
7
  export declare const getChildClassRefs: (target: Type) => Type[];
8
8
  export declare const getFieldEnumMetas: (modelRef: Type) => {
9
9
  key: string;
10
- enum: Enum;
10
+ enum: EnumInstance;
11
11
  }[];
12
12
  export declare const hasTextField: (modelRef: Type) => boolean;
@@ -6,7 +6,7 @@ export type ModelType = "input" | "object" | "full" | "light" | "insight" | "fil
6
6
  export declare const constantInfo: {
7
7
  database: Map<string, ConstantModel<any, any, any, any, any, any, DefaultOf<any>, DefaultOf<any>, GetStateObject<any>, GetStateObject<any>, DefaultOf<any>, any, any, any, QueryOf<any>>>;
8
8
  scalar: Map<string, ScalarConstantModel<any, any, any, any, any>>;
9
- modelRefNameMap: Map<Type, string>;
9
+ modelRefNameMap: Map<new (...args: any[]) => any, string>;
10
10
  getRefName<AllowEmpty extends boolean = false>(modelRef: Type, { allowEmpty }?: {
11
11
  allowEmpty?: AllowEmpty;
12
12
  }): AllowEmpty extends true ? string | undefined : string;
@@ -1,9 +1,9 @@
1
- import { type Dayjs, Enum, Float, type GqlScalar, ID, Int, JSON, type Type, type UnType } from "@akanjs/base";
1
+ import { type Dayjs, EnumInstance, Float, type GqlScalar, ID, Int, JSON, type Type, type UnType } from "@akanjs/base";
2
2
  import { ConstantFieldProps } from "./scalar";
3
- export type ParamFieldType = typeof ID | typeof Int | StringConstructor | typeof Date | BooleanConstructor | Enum<string>;
4
- export type ConstantFieldType = ParamFieldType | DateConstructor | typeof Float | typeof JSON | Type | MapConstructor | Enum<number>;
3
+ export type ParamFieldType = typeof ID | typeof Int | StringConstructor | typeof Date | BooleanConstructor | EnumInstance<string, string>;
4
+ export type ConstantFieldType = ParamFieldType | DateConstructor | typeof Float | typeof JSON | Type | MapConstructor | EnumInstance<string, number>;
5
5
  export type ConstantFieldTypeInput = ConstantFieldType | ConstantFieldType[] | ConstantFieldType[][] | ConstantFieldType[][][];
6
- export type FieldToValue<Field, MapValue = any> = Field extends null ? FieldToValue<Exclude<Field, null>> | null : Field extends MapConstructor ? Map<string, FieldToValue<MapValue>> : Field extends (infer F)[] ? FieldToValue<F>[] : Field extends typeof ID ? string : Field extends DateConstructor ? Dayjs : Field extends StringConstructor ? string : Field extends BooleanConstructor ? boolean : Field extends typeof Int ? number : Field extends typeof Float ? number : Field extends typeof JSON ? any : Field extends Type ? UnType<Field> : Field extends Enum<infer V> ? V : never;
6
+ export type FieldToValue<Field, MapValue = any> = Field extends null ? FieldToValue<Exclude<Field, null>> | null : Field extends MapConstructor ? Map<string, FieldToValue<MapValue>> : Field extends (infer F)[] ? FieldToValue<F>[] : Field extends typeof ID ? string : Field extends DateConstructor ? Dayjs : Field extends StringConstructor ? string : Field extends BooleanConstructor ? boolean : Field extends typeof Int ? number : Field extends typeof Float ? number : Field extends typeof JSON ? any : Field extends EnumInstance<string, infer V> ? V : Field extends Type ? UnType<Field> : never;
7
7
  export interface FieldInfoObject {
8
8
  [key: string]: FieldInfo<ConstantFieldTypeInput | null, any>;
9
9
  }
@@ -28,8 +28,8 @@ type FieldOption<Value extends ConstantFieldTypeInput, MapValue = Value extends
28
28
  export type PlainTypeToFieldType<PlainType> = PlainType extends [infer First, ...infer Rest] ? PlainTypeToFieldType<First>[] : PlainType extends number ? typeof Int | typeof Float : PlainType extends string ? StringConstructor : typeof JSON;
29
29
  export declare const field: {
30
30
  <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof Int | typeof import("@akanjs/base").Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<Value, ExplicitType, MapValue>;
31
- secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof Int | typeof import("@akanjs/base").Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<Value | null, ExplicitType, MapValue>;
32
- hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof Int | typeof import("@akanjs/base").Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<Value | null, ExplicitType, MapValue>;
31
+ secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof Int | typeof import("@akanjs/base").Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<Value | null, ExplicitType | null, MapValue>;
32
+ hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof Int | typeof import("@akanjs/base").Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<Value | null, ExplicitType | null, MapValue>;
33
33
  };
34
34
  export declare const resolve: <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? GqlScalar : never>(value: Value, option?: FieldOption<Value, MapValue>) => FieldInfo<Value, ExplicitType, MapValue>;
35
35
  export type FieldBuilder = typeof field;
package/src/purify.d.ts CHANGED
@@ -6,7 +6,7 @@ type Purified<O> = O extends BaseObject ? string : O extends BaseObject[] ? stri
6
6
  type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
7
7
  [K in StateKeys]: Purified<T[K]>;
8
8
  };
9
- export type PurifiedModel<T> = T extends (infer S)[] ? PurifiedModel<S>[] : T extends string | number | boolean | Dayjs | Upload ? T : T extends Map<infer K, infer V> ? Map<K, PurifiedModel<V>> : PurifiedWithObjectToId<T>;
9
+ export type PurifiedModel<T> = T extends Upload[] ? FileList : T extends (infer S)[] ? PurifiedModel<S>[] : T extends string | number | boolean | Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, PurifiedModel<V>> : PurifiedWithObjectToId<T>;
10
10
  export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput = PurifiedModel<Input>> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
11
11
  export declare const makePurify: <I>(modelRef: Type<I>, option?: {
12
12
  overwrite?: any;
package/src/scalar.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { type Enum, Float, type GqlScalar, ID, Int, JSON, type SingleFieldType, type Type, Upload } from "@akanjs/base";
2
+ import { EnumInstance, Float, type GqlScalar, ID, Int, JSON, type SingleFieldType, type Type, Upload } from "@akanjs/base";
3
3
  import type { AccumulatorOperator } from "mongoose";
4
4
  export declare const scalarExampleMap: Map<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor, string | number | boolean | object>;
5
5
  export declare const getScalarExample: (ref: GqlScalar) => string | number | boolean | object | null;
@@ -29,7 +29,7 @@ export interface ConstantFieldProps<FieldValue = any, MapValue = any, Metadata =
29
29
  immutable?: boolean;
30
30
  min?: number;
31
31
  max?: number;
32
- enum?: Enum;
32
+ enum?: EnumInstance;
33
33
  select?: boolean;
34
34
  minlength?: number;
35
35
  maxlength?: number;
package/src/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BaseObject, Dayjs, enumOf, type GetStateObject, Upload } from "@akanjs/base";
1
+ import { type BaseObject, Dayjs, type GetStateObject, Upload } from "@akanjs/base";
2
2
  import type { FilterQuery, HydratedDocument } from "mongoose";
3
3
  export type { FilterQuery as QueryOf };
4
4
  type ObjectToId<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends {
@@ -63,6 +63,7 @@ export interface TextDoc {
63
63
  export type NonFunctionalKeys<T> = keyof T extends (...any: any[]) => any ? never : keyof T;
64
64
  export declare const unsetDate: Dayjs;
65
65
  export declare const MAX_INT = 2147483647;
66
- export declare const Responsive: import("@akanjs/base").Enum<"xl" | "lg" | "md" | "sm" | "xs">;
67
- export type Responsive = enumOf<typeof Responsive>;
66
+ declare const Responsive_base: import("@akanjs/base").EnumInstance<"responsive", "xl" | "lg" | "md" | "sm" | "xs">;
67
+ export declare class Responsive extends Responsive_base {
68
+ }
68
69
  export declare const responsiveWidths: readonly [1200, 992, 768, 576, 0];