@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.
- package/cjs/src/baseGql.js +5 -5
- package/cjs/src/default.js +0 -2
- package/cjs/src/fieldInfo.js +3 -3
- package/cjs/src/types.js +2 -1
- package/esm/src/baseGql.js +5 -5
- package/esm/src/default.js +1 -3
- package/esm/src/fieldInfo.js +4 -4
- package/esm/src/types.js +2 -1
- package/package.json +1 -1
- package/src/baseGql.d.ts +2 -4
- package/src/classMeta.d.ts +2 -2
- package/src/constantInfo.d.ts +1 -1
- package/src/fieldInfo.d.ts +6 -6
- package/src/purify.d.ts +1 -1
- package/src/scalar.d.ts +2 -2
- package/src/types.d.ts +4 -3
package/cjs/src/baseGql.js
CHANGED
|
@@ -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
|
|
196
|
+
class BaseInsight2 {
|
|
197
197
|
}
|
|
198
|
-
(0, import_scalar.setFieldMetaMap)(
|
|
199
|
-
import_constantInfo.constantInfo.setModelType(
|
|
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(
|
|
201
|
+
fieldInfo.applyFieldMeta(BaseInsight2, key);
|
|
202
202
|
});
|
|
203
|
-
return
|
|
203
|
+
return BaseInsight2;
|
|
204
204
|
};
|
package/cjs/src/default.js
CHANGED
|
@@ -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)
|
package/cjs/src/fieldInfo.js
CHANGED
|
@@ -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
|
|
36
|
-
const valueType =
|
|
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, ...
|
|
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
|
-
|
|
31
|
+
class Responsive extends (0, import_base.enumOf)("responsive", ["xl", "lg", "md", "sm", "xs"]) {
|
|
32
|
+
}
|
|
32
33
|
const responsiveWidths = [1200, 992, 768, 576, 0];
|
package/esm/src/baseGql.js
CHANGED
|
@@ -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
|
|
177
|
+
class BaseInsight2 {
|
|
178
178
|
}
|
|
179
|
-
setFieldMetaMap(
|
|
180
|
-
constantInfo.setModelType(
|
|
179
|
+
setFieldMetaMap(BaseInsight2, insightFieldMetaMap);
|
|
180
|
+
constantInfo.setModelType(BaseInsight2, "insight");
|
|
181
181
|
Object.entries(fieldMap).forEach(([key, fieldInfo]) => {
|
|
182
|
-
fieldInfo.applyFieldMeta(
|
|
182
|
+
fieldInfo.applyFieldMeta(BaseInsight2, key);
|
|
183
183
|
});
|
|
184
|
-
return
|
|
184
|
+
return BaseInsight2;
|
|
185
185
|
};
|
|
186
186
|
export {
|
|
187
187
|
via
|
package/esm/src/default.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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)
|
package/esm/src/fieldInfo.js
CHANGED
|
@@ -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
|
|
22
|
-
const valueType =
|
|
21
|
+
const isEnumValue = isEnum(singleValue);
|
|
22
|
+
const valueType = isEnumValue ? arraiedModel(singleValue.type, arrDepth) : value;
|
|
23
23
|
this.type = valueType;
|
|
24
|
-
this.option = { ...option, ...
|
|
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
|
-
|
|
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
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 {};
|
package/src/classMeta.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { type
|
|
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:
|
|
10
|
+
enum: EnumInstance;
|
|
11
11
|
}[];
|
|
12
12
|
export declare const hasTextField: (modelRef: Type) => boolean;
|
package/src/constantInfo.d.ts
CHANGED
|
@@ -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<
|
|
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;
|
package/src/fieldInfo.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Dayjs,
|
|
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 |
|
|
4
|
-
export type ConstantFieldType = ParamFieldType | DateConstructor | typeof Float | typeof JSON | Type | MapConstructor |
|
|
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
|
|
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
|
|
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 {
|
|
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?:
|
|
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,
|
|
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
|
-
|
|
67
|
-
export
|
|
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];
|