@akanjs/constant 1.0.5 → 1.0.6

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.
@@ -1,15 +1,13 @@
1
1
  import {
2
2
  arraiedModel,
3
3
  getNonArrayModel,
4
+ ID,
5
+ Int,
4
6
  isEnum,
5
7
  isGqlMap,
6
8
  isGqlScalar
7
9
  } from "@akanjs/base";
8
10
  import { constantInfo } from "./constantInfo";
9
- import {
10
- getFieldMetaMapOnPrototype,
11
- setFieldMetaMapOnPrototype
12
- } from "./scalar";
13
11
  class FieldInfo {
14
12
  value;
15
13
  type;
@@ -29,15 +27,81 @@ class FieldInfo {
29
27
  this.option.meta = meta;
30
28
  return this;
31
29
  }
32
- applyFieldMeta(target, key) {
33
- const [modelRef, arrDepth] = getNonArrayModel(this.type);
34
- const [option, optArrDepth] = getNonArrayModel(this.option);
30
+ toField() {
31
+ return ConstantField.fromFieldInfo(this);
32
+ }
33
+ }
34
+ class ConstantField {
35
+ static getBaseModelField() {
36
+ return {
37
+ id: field(ID).toField(),
38
+ createdAt: field(Date).toField(),
39
+ updatedAt: field(Date).toField(),
40
+ removedAt: field(Date).optional().toField()
41
+ };
42
+ }
43
+ static getBaseInsightField() {
44
+ return {
45
+ count: field(Int, { default: 0, accumulate: { $sum: 1 } }).toField()
46
+ };
47
+ }
48
+ nullable;
49
+ ref;
50
+ refPath;
51
+ refType;
52
+ default;
53
+ type;
54
+ fieldType;
55
+ immutable;
56
+ min;
57
+ max;
58
+ enum;
59
+ select;
60
+ minlength;
61
+ maxlength;
62
+ accumulate;
63
+ example;
64
+ of;
65
+ // for Map type fields
66
+ validate;
67
+ text;
68
+ modelRef;
69
+ arrDepth;
70
+ optArrDepth;
71
+ meta;
72
+ constructor(props) {
73
+ this.nullable = props.nullable;
74
+ this.ref = props.ref;
75
+ this.refPath = props.refPath;
76
+ this.refType = props.refType;
77
+ this.default = props.default;
78
+ this.type = props.type;
79
+ this.fieldType = props.fieldType;
80
+ this.immutable = props.immutable;
81
+ this.min = props.min;
82
+ this.max = props.max;
83
+ this.enum = props.enum;
84
+ this.select = props.select;
85
+ this.minlength = props.minlength;
86
+ this.maxlength = props.maxlength;
87
+ this.accumulate = props.accumulate;
88
+ this.example = props.example;
89
+ this.of = props.of;
90
+ this.validate = props.validate;
91
+ this.text = props.text;
92
+ this.modelRef = props.modelRef;
93
+ this.arrDepth = props.arrDepth;
94
+ this.optArrDepth = props.optArrDepth;
95
+ this.meta = props.meta;
96
+ }
97
+ static fromFieldInfo(fieldInfo) {
98
+ const [modelRef, arrDepth] = getNonArrayModel(fieldInfo.type);
99
+ const [option, optArrDepth] = getNonArrayModel(fieldInfo.option);
35
100
  const isArray = arrDepth > 0;
36
- const isClass = !isGqlScalar(modelRef);
37
101
  const isMap = isGqlMap(modelRef);
38
102
  if (isMap && !option.of)
39
103
  throw new Error("Map type must have 'of' option");
40
- const metadata = {
104
+ return new ConstantField({
41
105
  nullable: option.nullable ?? (option.default === "" ? true : false),
42
106
  ref: option.ref,
43
107
  refPath: option.refPath,
@@ -54,22 +118,57 @@ class FieldInfo {
54
118
  maxlength: option.maxlength,
55
119
  accumulate: option.accumulate,
56
120
  example: option.example,
121
+ of: option.of,
57
122
  validate: option.validate,
58
- key,
59
- isClass,
60
- isScalar: constantInfo.isScalar(modelRef),
123
+ text: option.text,
61
124
  modelRef,
62
125
  arrDepth,
63
- isArray,
64
126
  optArrDepth,
65
- isMap,
66
- of: option.of,
67
- text: option.text,
68
127
  meta: option.meta ?? {}
128
+ });
129
+ }
130
+ get isClass() {
131
+ return !isGqlScalar(this.modelRef);
132
+ }
133
+ get isScalar() {
134
+ return constantInfo.isScalar(this.modelRef) || isGqlScalar(this.modelRef);
135
+ }
136
+ get isArray() {
137
+ return this.arrDepth > 0;
138
+ }
139
+ get isMap() {
140
+ return isGqlMap(this.modelRef);
141
+ }
142
+ getProps() {
143
+ return {
144
+ nullable: this.nullable,
145
+ ref: this.ref,
146
+ refPath: this.refPath,
147
+ refType: this.refType,
148
+ default: this.default,
149
+ type: this.type,
150
+ fieldType: this.fieldType,
151
+ immutable: this.immutable,
152
+ min: this.min,
153
+ max: this.max,
154
+ enum: this.enum,
155
+ select: this.select,
156
+ minlength: this.minlength,
157
+ maxlength: this.maxlength,
158
+ accumulate: this.accumulate,
159
+ example: this.example,
160
+ of: this.of,
161
+ validate: this.validate,
162
+ text: this.text,
163
+ modelRef: this.modelRef,
164
+ arrDepth: this.arrDepth,
165
+ optArrDepth: this.optArrDepth,
166
+ meta: this.meta,
167
+ isClass: this.isClass,
168
+ isScalar: this.isScalar,
169
+ isArray: this.isArray,
170
+ isMap: this.isMap
69
171
  };
70
- const metadataMap = getFieldMetaMapOnPrototype(target.prototype);
71
- metadataMap.set(key, metadata);
72
- setFieldMetaMapOnPrototype(target.prototype, metadataMap);
73
172
  }
74
173
  }
75
174
  const field = (value, option = {}) => new FieldInfo(value, { ...option, fieldType: "property" });
@@ -82,6 +181,7 @@ field.hidden = (value, option = {}) => new FieldInfo(value, {
82
181
  });
83
182
  const resolve = (value, option = {}) => new FieldInfo(value, { ...option, fieldType: "resolve" });
84
183
  export {
184
+ ConstantField,
85
185
  field,
86
186
  resolve
87
187
  };
@@ -1,14 +1,12 @@
1
1
  import { immerable } from "immer";
2
- import { getFieldMetas } from ".";
3
2
  const immerify = (modelRef, objOrArr) => {
4
3
  if (Array.isArray(objOrArr))
5
4
  return objOrArr.map((val) => immerify(modelRef, val));
6
- const fieldMetas = getFieldMetas(modelRef);
7
5
  const immeredObj = Object.assign({}, objOrArr, { [immerable]: true });
8
6
  const objRecord = objOrArr;
9
- fieldMetas.forEach((fieldMeta) => {
10
- if (fieldMeta.isScalar && fieldMeta.isClass && !!objRecord[fieldMeta.key])
11
- immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objRecord[fieldMeta.key]);
7
+ Object.entries(modelRef.field).forEach(([key, field]) => {
8
+ if (field.isScalar && field.isClass && !!objRecord[key])
9
+ immeredObj[key] = immerify(field.modelRef, objRecord[key]);
12
10
  });
13
11
  return immeredObj;
14
12
  };
package/esm/src/purify.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  JSON as GqlJSON
9
9
  } from "@akanjs/base";
10
10
  import { Logger } from "@akanjs/common";
11
- import { constantInfo, getFieldMetas } from ".";
11
+ import { constantInfo } from ".";
12
12
  class PurifyStorage {
13
13
  }
14
14
  const scalarPurifyMap = /* @__PURE__ */ new Map([
@@ -24,65 +24,53 @@ const getPurifyFn = (modelRef) => {
24
24
  const [valueRef] = getNonArrayModel(modelRef);
25
25
  return scalarPurifyMap.get(valueRef) ?? ((value) => value);
26
26
  };
27
- const purify = (metadata, value, self) => {
28
- if (metadata.nullable && (value === null || value === void 0 || typeof value === "number" && isNaN(value) || typeof value === "string" && !value.length))
27
+ const purify = (field, key, value, self) => {
28
+ if (field.nullable && (value === null || value === void 0 || typeof value === "number" && isNaN(value) || typeof value === "string" && !value.length))
29
29
  return null;
30
- if (metadata.isArray) {
30
+ if (field.isArray) {
31
31
  if (!Array.isArray(value))
32
- throw new Error(`Invalid Array Value in ${metadata.key} for value ${value}`);
33
- if (metadata.minlength && value.length < metadata.minlength)
34
- throw new Error(`Invalid Array Length (Min) in ${metadata.key} for value ${value}`);
35
- else if (metadata.maxlength && value.length > metadata.maxlength)
36
- throw new Error(`Invalid Array Length (Max) in ${metadata.key} for value ${value}`);
37
- else if (metadata.optArrDepth === 0 && metadata.validate && !metadata.validate(value, self))
38
- throw new Error(`Invalid Array Value (Failed to pass validation) in ${metadata.key} for value ${value}`);
39
- return value.map((v) => purify({ ...metadata, isArray: false }, v, v));
32
+ throw new Error(`Invalid Array Value in ${key} for value ${value}`);
33
+ if (field.minlength && value.length < field.minlength)
34
+ throw new Error(`Invalid Array Length (Min) in ${key} for value ${value}`);
35
+ else if (field.maxlength && value.length > field.maxlength)
36
+ throw new Error(`Invalid Array Length (Max) in ${key} for value ${value}`);
37
+ else if (field.optArrDepth === 0 && field.validate && !field.validate(value, self))
38
+ throw new Error(`Invalid Array Value (Failed to pass validation) in ${key} for value ${value}`);
39
+ return value.map((v) => purify({ ...field, isArray: false }, key, v, v));
40
40
  }
41
- if (metadata.isMap && metadata.of) {
42
- const purifyFn2 = getPurifyFn(metadata.of);
41
+ if (field.isMap && field.of) {
42
+ const purifyFn2 = getPurifyFn(field.of);
43
43
  return Object.fromEntries(
44
- [...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, purifyFn2)])
44
+ [...value.entries()].map(([key2, val]) => [key2, applyFnToArrayObjects(val, purifyFn2)])
45
45
  );
46
46
  }
47
- if (metadata.isClass)
48
- return makePurify(metadata.modelRef)(value, true);
49
- if (metadata.modelRef === Date && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
50
- throw new Error(`Invalid Date Value (Default) in ${metadata.key} for value ${value}`);
51
- if ([String, ID].includes(metadata.modelRef) && (value === "" || !value))
52
- throw new Error(`Invalid String Value (Default) in ${metadata.key} for value ${value}`);
53
- if (metadata.validate && !metadata.validate(value, self))
54
- throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${metadata.key}`);
55
- if (!metadata.nullable && !value && value !== 0 && value !== false)
56
- throw new Error(`Invalid Value (Nullable) in ${metadata.key} for value ${value}`);
57
- const purifyFn = getPurifyFn(metadata.modelRef);
47
+ if (field.isClass)
48
+ return makePurify(field.modelRef)(value, true);
49
+ if (field.modelRef === Date && dayjs(value).isBefore(dayjs(/* @__PURE__ */ new Date("0000"))))
50
+ throw new Error(`Invalid Date Value (Default) in ${key} for value ${value}`);
51
+ if ([String, ID].includes(field.modelRef) && (value === "" || !value))
52
+ throw new Error(`Invalid String Value (Default) in ${key} for value ${value}`);
53
+ if (field.validate && !field.validate(value, self))
54
+ throw new Error(`Invalid Value (Failed to pass validation) / ${value} in ${key}`);
55
+ if (!field.nullable && !value && value !== 0 && value !== false)
56
+ throw new Error(`Invalid Value (Nullable) in ${key} for value ${value}`);
57
+ const purifyFn = getPurifyFn(field.modelRef);
58
58
  return purifyFn(value);
59
59
  };
60
- const getPredefinedPurifyFn = (refName) => {
61
- const purify2 = Reflect.getMetadata(refName, PurifyStorage.prototype);
62
- return purify2;
63
- };
64
- const setPredefinedPurifyFn = (refName, purify2) => {
65
- Reflect.defineMetadata(refName, purify2, PurifyStorage.prototype);
66
- };
67
- const makePurify = (modelRef, option = {}) => {
68
- const refName = constantInfo.getRefName(modelRef);
69
- const purifyFn = getPredefinedPurifyFn(refName);
70
- if (purifyFn && !option.overwrite)
71
- return purifyFn;
72
- const metadatas = getFieldMetas(modelRef);
60
+ const makePurify = (modelRef) => {
73
61
  const fn = (self, isChild) => {
74
62
  try {
75
63
  if (isChild && !constantInfo.isScalar(modelRef)) {
76
64
  const id = self.id;
77
65
  if (!id)
78
- throw new Error(`Invalid Value (No ID) for id ${refName}`);
66
+ throw new Error(`Invalid Value (No ID) for id ${modelRef}`);
79
67
  return id;
80
68
  }
81
69
  const result = {};
82
- for (const metadata of metadatas) {
83
- const value = self[metadata.key];
84
- result[metadata.key] = purify(metadata, value, self);
85
- }
70
+ Object.entries(modelRef.field).forEach(([key, field]) => {
71
+ const value = self[key];
72
+ result[key] = purify(field.getProps(), key, value, self);
73
+ });
86
74
  return result;
87
75
  } catch (err) {
88
76
  if (isChild)
@@ -91,7 +79,6 @@ const makePurify = (modelRef, option = {}) => {
91
79
  return null;
92
80
  }
93
81
  };
94
- setPredefinedPurifyFn(refName, fn);
95
82
  return fn;
96
83
  };
97
84
  export {
package/esm/src/scalar.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import "reflect-metadata";
2
2
  import {
3
3
  Float,
4
- getNonArrayModel,
5
4
  ID,
6
5
  Int,
7
6
  JSON,
@@ -24,42 +23,13 @@ const scalarExampleMap = /* @__PURE__ */ new Map([
24
23
  const getScalarExample = (ref) => scalarExampleMap.get(ref) ?? null;
25
24
  const getGqlTypeStr = (ref) => scalarNameMap.get(ref) ?? `${constantInfo.isLight(ref) ? "Light" : ""}${capitalize(constantInfo.getRefName(ref))}${constantInfo.isInsight(ref) ? "Insight" : ""}`;
26
25
  const fieldPresets = ["email", "password", "url"];
27
- const getFieldMetas = (modelRef) => {
28
- const [target] = getNonArrayModel(modelRef);
29
- const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
30
- const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
31
- return [...metadataMap.values()].sort(
32
- (a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0)
33
- );
34
- };
35
26
  const isConstantModel = (modelRef) => {
36
27
  return Reflect.getMetadata("class", modelRef.prototype) !== void 0;
37
28
  };
38
- const getFieldMetaMap = (modelRef) => {
39
- const [target] = getNonArrayModel(modelRef);
40
- const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
41
- return metadataMap;
42
- };
43
- const setFieldMetaMap = (modelRef, metadataMap) => {
44
- const [target] = getNonArrayModel(modelRef);
45
- Reflect.defineMetadata("fields", metadataMap, target.prototype);
46
- };
47
- const getFieldMetaMapOnPrototype = (prototype) => {
48
- const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
49
- return metadataMap;
50
- };
51
- const setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
52
- Reflect.defineMetadata("fields", metadataMap, prototype);
53
- };
54
29
  export {
55
30
  fieldPresets,
56
- getFieldMetaMap,
57
- getFieldMetaMapOnPrototype,
58
- getFieldMetas,
59
31
  getGqlTypeStr,
60
32
  getScalarExample,
61
33
  isConstantModel,
62
- scalarExampleMap,
63
- setFieldMetaMap,
64
- setFieldMetaMapOnPrototype
34
+ scalarExampleMap
65
35
  };
@@ -8,7 +8,7 @@ import {
8
8
  isGqlScalar,
9
9
  JSON as GqlJSON
10
10
  } from "@akanjs/base";
11
- import { constantInfo, getFieldMetas } from ".";
11
+ import { constantInfo } from ".";
12
12
  const scalarSerializeMap = /* @__PURE__ */ new Map([
13
13
  [Date, (value) => dayjs(value).toDate()],
14
14
  [String, (value) => value],
@@ -42,9 +42,9 @@ const serializeInput = (value, inputRef, arrDepth) => {
42
42
  return value;
43
43
  else
44
44
  return Object.fromEntries(
45
- getFieldMetas(inputRef).map((fieldMeta) => [
46
- fieldMeta.key,
47
- serializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
45
+ Object.entries(inputRef.field).map(([key, field]) => [
46
+ key,
47
+ serializeInput(value[key], field.modelRef, field.arrDepth)
48
48
  ])
49
49
  );
50
50
  };
@@ -87,9 +87,9 @@ const deserializeInput = (value, inputRef, arrDepth) => {
87
87
  return value;
88
88
  else
89
89
  return Object.fromEntries(
90
- getFieldMetas(inputRef).map((fieldMeta) => [
91
- fieldMeta.key,
92
- deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
90
+ Object.entries(inputRef.field).map(([key, field]) => [
91
+ key,
92
+ deserializeInput(value[key], field.modelRef, field.arrDepth)
93
93
  ])
94
94
  );
95
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/constant",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/baseGql.d.ts CHANGED
@@ -1,12 +1,33 @@
1
1
  import "reflect-metadata";
2
- import { BaseInsight, BaseObject, type MergeAllTypes, type Prettify, Type } from "@akanjs/base";
3
- import { type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, FieldResolver } from "./fieldInfo";
4
- import type { NonFunctionalKeys } from "./types";
2
+ import { BaseInsight, BaseObject, type MergeAllTypes, Type } from "@akanjs/base";
3
+ import { type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, FieldObject, FieldResolver } from "./fieldInfo";
4
+ import { type PurifyFunc } from "./purify";
5
+ import type { DefaultOf, NonFunctionalKeys } from "./types";
5
6
  type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
6
7
  type OmitBase<T> = Omit<T, BaseFields>;
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
- 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> & BaseInsight & ExtractFieldInfoObject<ReturnType<BuildField>>>;
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>>>>;
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>>>>;
8
+ export interface ConstantMethods<Schema = any> {
9
+ set: (obj: Partial<Schema>) => this;
10
+ }
11
+ export interface ConstantStatics<Schema = any> {
12
+ field: FieldObject;
13
+ default: DefaultOf<Schema>;
14
+ purify: PurifyFunc<Schema>;
15
+ }
16
+ export type Crystal<Schema = any> = Schema & ConstantMethods<Schema>;
17
+ export type Cnst<Schema = any> = (new (obj?: Partial<Schema>) => Crystal<Schema>) & ConstantStatics<Schema>;
18
+ declare global {
19
+ interface DateConstructor extends ConstantStatics<unknown> {
20
+ }
21
+ interface StringConstructor extends ConstantStatics<unknown> {
22
+ }
23
+ interface BooleanConstructor extends ConstantStatics<unknown> {
24
+ }
25
+ interface MapConstructor extends ConstantStatics<unknown> {
26
+ }
27
+ }
28
+ export declare function via<T extends BaseObject, K extends NonFunctionalKeys<OmitBase<T>>, ResolveField extends (resolve: FieldResolver) => FieldInfoObject, LightModels extends Type[], _Schema = MergeAllTypes<LightModels> & Pick<T, K> & BaseObject & ExtractFieldInfoObject<ReturnType<ResolveField>>>(modelRef: Type<T>, fields: readonly K[], resolveField: ResolveField, ...lightModelRefs: LightModels): Cnst<_Schema>;
29
+ export declare function via<BuildField extends (builder: FieldBuilder) => FieldInfoObject, Inputs extends Type[], _Schema = MergeAllTypes<Inputs> & ExtractFieldInfoObject<ReturnType<BuildField>>>(buildField: BuildField, ...extendInputRefs: Inputs): Cnst<_Schema>;
30
+ export declare function via<T extends BaseObject, BuildField extends (builder: FieldBuilder) => FieldInfoObject, Insights extends Type[], _Schema = MergeAllTypes<Insights> & BaseInsight & ExtractFieldInfoObject<ReturnType<BuildField>>>(modelRef: Type<T>, buildField: BuildField, ...extendInsightRefs: Insights): Cnst<_Schema>;
31
+ export declare function via<T, BuildField extends (builder: FieldBuilder) => FieldInfoObject, ObjectModels extends Type[], _Schema = MergeAllTypes<ObjectModels> & T & BaseObject & ExtractFieldInfoObject<ReturnType<BuildField>>>(inputRef: Type<T>, buildField: BuildField, ...extendObjectRefs: ObjectModels): Cnst<_Schema>;
32
+ export declare function via<T, Light, ResolveField extends (resolve: FieldResolver) => FieldInfoObject, FullModels extends Type[], _Schema = MergeAllTypes<FullModels> & T & Light & ExtractFieldInfoObject<ReturnType<ResolveField>>>(objectRef: Type<T>, lightModelRef: Type<Light>, resolveField: ResolveField, ...fullModelRefs: FullModels): Cnst<_Schema>;
12
33
  export {};
@@ -1,12 +1,9 @@
1
1
  import "reflect-metadata";
2
- import { type EnumInstance, type Type } from "@akanjs/base";
3
- export declare const setExtendRef: (modelRef: Type, extendRef: Type) => void;
4
- export declare const getExtendRef: <AllowEmpty extends boolean = false>(modelRef: Type, { allowEmpty }?: {
5
- allowEmpty?: AllowEmpty;
6
- }) => AllowEmpty extends true ? Type | undefined : Type;
7
- export declare const getChildClassRefs: (target: Type) => Type[];
8
- export declare const getFieldEnumMetas: (modelRef: Type) => {
2
+ import { type EnumInstance } from "@akanjs/base";
3
+ import { Cnst } from "./baseGql";
4
+ export declare const getChildClassRefs: (target: Cnst) => Cnst[];
5
+ export declare const getFieldEnumMetas: (modelRef: Cnst) => {
9
6
  key: string;
10
7
  enum: EnumInstance;
11
8
  }[];
12
- export declare const hasTextField: (modelRef: Type) => boolean;
9
+ export declare const hasTextField: (modelRef: Cnst) => boolean;
@@ -1,10 +1,16 @@
1
1
  import "reflect-metadata";
2
2
  import { type GetStateObject, GqlScalar, type Type } from "@akanjs/base";
3
- import { CrystalizeFunc, PurifiedModel, PurifyFunc } from ".";
3
+ import { Cnst, PurifiedModel } from ".";
4
4
  import type { DefaultOf, DocumentModel, QueryOf } from "./types";
5
5
  export type ModelType = "input" | "object" | "full" | "light" | "insight" | "filter" | "scalar";
6
6
  export declare const constantInfo: {
7
- database: Map<string, ConstantModel<string, any, any, any, any, any, Capitalize<string>, DefaultOf<any>, DefaultOf<any>, GetStateObject<any>, GetStateObject<any>, DefaultOf<any>, any, any, any, QueryOf<any>>>;
7
+ database: Map<string, ConstantModel<string, any, any, any, any, any, Capitalize<string>, GetStateObject<{
8
+ [x: string]: any;
9
+ }>, GetStateObject<{
10
+ [x: string]: any;
11
+ }>, GetStateObject<any>, GetStateObject<any>, GetStateObject<{
12
+ [x: string]: any;
13
+ }>, any, any, any, QueryOf<any>>>;
8
14
  scalar: Map<string, ScalarConstantModel<any, any, any, any, any>>;
9
15
  modelRefNameMap: Map<new (...args: any[]) => any, string>;
10
16
  getRefName<AllowEmpty extends boolean = false>(modelRef: Type, { allowEmpty }?: {
@@ -23,26 +29,20 @@ export declare const constantInfo: {
23
29
  setDatabase(refName: string, cnst: ConstantModel<string, any, any, any, any, any>): void;
24
30
  getDatabase<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
25
31
  allowEmpty?: AllowEmpty;
26
- }): AllowEmpty extends true ? ConstantModel<string, any, any, any, any, any> | undefined : ConstantModel<string, any, any, any, any, any>;
27
- setScalar(refName: string, cnst: ScalarConstantModel<string, any, any, any, any>): void;
32
+ }): AllowEmpty extends true ? ConstantModel<string, unknown, unknown, unknown, unknown, unknown> | undefined : ConstantModel<string, unknown, unknown, unknown, unknown, unknown>;
33
+ setScalar(refName: string, cnst: ScalarConstantModel<string, unknown, unknown, unknown, unknown>): void;
28
34
  getScalar<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
29
35
  allowEmpty?: AllowEmpty;
30
- }): AllowEmpty extends true ? ScalarConstantModel<string, any, any, any, any> | undefined : ScalarConstantModel<string, any, any, any, any>;
36
+ }): AllowEmpty extends true ? ScalarConstantModel<string, unknown, unknown, unknown, unknown> | undefined : ScalarConstantModel<string, unknown, unknown, unknown, unknown>;
31
37
  getModelRef(refName: string, modelType: "input" | "object" | "full" | "light" | "insight" | "scalar"): Type | GqlScalar;
32
38
  };
33
39
  export interface ConstantModel<T extends string, Input, Obj, Full, Light, Insight, _CapitalizedT extends string = Capitalize<T>, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _DefaultInsight = DefaultOf<Insight>, _PurifiedInput = PurifiedModel<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>> {
34
40
  refName: T;
35
- input: Type<Input>;
36
- object: Type<Obj>;
37
- full: Type<Full>;
38
- light: Type<Light>;
39
- insight: Type<Insight>;
40
- crystalize: CrystalizeFunc<Full>;
41
- lightCrystalize: CrystalizeFunc<Light>;
42
- crystalizeInsight: CrystalizeFunc<Insight>;
43
- purify: PurifyFunc<Input, _DefaultInput, _PurifiedInput>;
44
- getDefault: () => _Default;
45
- getDefaultInsight: () => _DefaultInsight;
41
+ input: Cnst<Input>;
42
+ object: Cnst<Obj>;
43
+ full: Cnst<Full>;
44
+ light: Cnst<Light>;
45
+ insight: Cnst<Insight>;
46
46
  _CapitalizedT: _CapitalizedT;
47
47
  _Default: _Default;
48
48
  _DefaultInput: _DefaultInput;
@@ -54,15 +54,10 @@ export interface ConstantModel<T extends string, Input, Obj, Full, Light, Insigh
54
54
  _DocInput: _DocInput;
55
55
  _QueryOfDoc: _QueryOfDoc;
56
56
  }
57
- export declare const cnstOf: <T extends string, Input, Obj, Full, Light, Insight>(refName: T, inputRef: Type<Input>, objectRef: Type<Obj>, fullRef: Type<Full>, lightRef: Type<Light>, insightRef: Type<Insight>, option?: {
58
- overwrite?: any;
59
- }) => ConstantModel<T, Input, Obj, Full, Light, Insight, Capitalize<T>, DefaultOf<Full>, DefaultOf<Input>, GetStateObject<Full>, GetStateObject<Input>, DefaultOf<Insight>, PurifiedModel<Input>, DocumentModel<Full>, DocumentModel<Input>, QueryOf<DocumentModel<Full>>>;
57
+ export declare const cnstOf: <T extends string, Input, Obj, Full, Light, Insight>(refName: T, inputRef: Type<Input>, objectRef: Type<Obj>, fullRef: Type<Full>, lightRef: Type<Light>, insightRef: Type<Insight>) => ConstantModel<T, Input, Obj, Full, Light, Insight, Capitalize<T>, DefaultOf<Full>, DefaultOf<Input>, GetStateObject<Full>, GetStateObject<Input>, DefaultOf<Insight>, PurifiedModel<Input>, DocumentModel<Full>, DocumentModel<Input>, QueryOf<DocumentModel<Full>>>;
60
58
  export interface ScalarConstantModel<T extends string, Model, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>, _PurifiedInput = PurifiedModel<Model>> {
61
59
  refName: T;
62
- model: Type<Model>;
63
- crystalize: CrystalizeFunc<Model>;
64
- purify: PurifyFunc<Model, _Default, _PurifiedInput>;
65
- getDefault: () => _Default;
60
+ model: Cnst<Model>;
66
61
  _Default: _Default;
67
62
  _Doc: _Doc;
68
63
  _PurifiedInput: _PurifiedInput;
@@ -1,6 +1,9 @@
1
1
  import { GetStateObject, Type } from "@akanjs/base";
2
+ import { FieldObject, FieldProps } from ".";
2
3
  export type CrystalizeFunc<Model> = (self: GetStateObject<Model>, isChild?: boolean) => Model;
3
- export declare const makeCrystalize: <M>(modelRef: Type<M>, option?: {
4
- overwrite?: any;
4
+ export declare const crystalize: (field: FieldProps, value: any) => any;
5
+ export declare const makeCrystalize: <M>(modelRef: Type<M, {
6
+ field: FieldObject;
7
+ }>, option?: {
5
8
  partial?: string[];
6
9
  }) => CrystalizeFunc<M>;
package/src/default.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { Type } from "@akanjs/base";
1
+ import { FieldObject } from ".";
2
2
  import { DefaultOf } from "./types";
3
- export declare const makeDefault: <T>(modelRef: Type<T>, option?: {
4
- isChild?: boolean;
5
- overwrite?: any;
6
- }) => DefaultOf<T>;
3
+ export declare const makeDefault: <T>(fieldObj: FieldObject) => DefaultOf<T>;