@akanjs/constant 0.9.48 → 0.9.50
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 +124 -122
- package/cjs/src/classMeta.js +12 -117
- package/cjs/src/constantInfo.js +145 -0
- package/cjs/src/crystalize.js +89 -0
- package/cjs/src/default.js +67 -0
- package/cjs/src/fieldInfo.js +98 -0
- package/cjs/src/immerify.js +35 -0
- package/cjs/src/index.js +6 -11
- package/cjs/src/purify.js +110 -0
- package/cjs/src/scalar.js +8 -12
- package/cjs/src/serialize.js +116 -0
- package/esm/src/baseGql.js +129 -132
- package/esm/src/classMeta.js +13 -118
- package/esm/src/constantInfo.js +126 -0
- package/esm/src/crystalize.js +78 -0
- package/esm/src/default.js +48 -0
- package/esm/src/fieldInfo.js +88 -0
- package/esm/src/immerify.js +16 -0
- package/esm/src/index.js +6 -7
- package/esm/src/purify.js +99 -0
- package/esm/src/scalar.js +8 -12
- package/esm/src/serialize.js +106 -0
- package/package.json +2 -1
- package/src/baseGql.d.ts +8 -4
- package/src/classMeta.d.ts +5 -21
- package/src/constantInfo.d.ts +69 -0
- package/src/crystalize.d.ts +6 -0
- package/src/default.d.ts +6 -0
- package/src/fieldInfo.d.ts +37 -0
- package/src/immerify.d.ts +2 -0
- package/src/index.d.ts +6 -5
- package/src/purify.d.ts +14 -0
- package/src/scalar.d.ts +16 -46
- package/src/serialize.d.ts +7 -0
- package/src/types.d.ts +3 -23
- package/cjs/src/constantDecorator.js +0 -67
- package/cjs/src/fieldMeta.js +0 -82
- package/cjs/src/filterMeta.js +0 -196
- package/esm/src/constantDecorator.js +0 -48
- package/esm/src/fieldMeta.js +0 -67
- package/esm/src/filterMeta.js +0 -181
- package/src/constantDecorator.d.ts +0 -30
- package/src/fieldMeta.d.ts +0 -7
- package/src/filterMeta.d.ts +0 -61
package/src/scalar.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Enum, Float, type GqlScalar, ID, Int, JSON, type SingleFieldType, type Type, Upload } from "@akanjs/base";
|
|
3
3
|
import type { AccumulatorOperator } from "mongoose";
|
|
4
|
-
|
|
5
|
-
export declare const scalarExampleMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, string | number | boolean | object>;
|
|
4
|
+
export declare const scalarExampleMap: Map<typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor | MapConstructor, string | number | boolean | object>;
|
|
6
5
|
export declare const getScalarExample: (ref: GqlScalar) => string | number | boolean | object | null;
|
|
7
6
|
export declare const getGqlTypeStr: (ref: GqlScalar) => string;
|
|
8
7
|
export interface ConstantClassMeta {
|
|
@@ -12,65 +11,38 @@ export interface ConstantClassMeta {
|
|
|
12
11
|
modelType: "data" | "ephemeral" | "insight";
|
|
13
12
|
hasTextField: boolean;
|
|
14
13
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export interface FilterKeyProps {
|
|
20
|
-
type?: "mongo" | "meili";
|
|
21
|
-
}
|
|
22
|
-
export interface FilterKeyMeta extends FilterKeyProps {
|
|
23
|
-
key: string;
|
|
24
|
-
descriptor: PropertyDescriptor;
|
|
25
|
-
}
|
|
26
|
-
export interface FilterArgProps {
|
|
27
|
-
nullable?: boolean;
|
|
28
|
-
ref?: string;
|
|
29
|
-
default?: string | number | boolean | object | null | (() => string | number | boolean | object | null);
|
|
30
|
-
renderOption?: (value: any) => string;
|
|
31
|
-
enum?: Enum<string | number>;
|
|
32
|
-
}
|
|
33
|
-
export interface FilterArgMeta extends FilterArgProps {
|
|
34
|
-
name: string;
|
|
35
|
-
modelRef: Type;
|
|
36
|
-
arrDepth: number;
|
|
37
|
-
isArray: boolean;
|
|
38
|
-
optArrDepth: number;
|
|
39
|
-
}
|
|
40
|
-
export declare const fieldTypes: readonly ["email", "password", "url"];
|
|
41
|
-
export type FieldType = (typeof fieldTypes)[number];
|
|
42
|
-
export type ReturnType<T extends SingleFieldType = SingleFieldType> = (of?: any) => T | [T] | [[T]] | Map<string, any>;
|
|
43
|
-
export interface ConstantFieldProps<Metadata extends {
|
|
44
|
-
[key: string]: any;
|
|
45
|
-
} = {
|
|
14
|
+
export declare const fieldPresets: readonly ["email", "password", "url"];
|
|
15
|
+
export type FieldPreset = (typeof fieldPresets)[number];
|
|
16
|
+
export type GqlReturn<T extends SingleFieldType = SingleFieldType> = (of?: any) => T | [T] | [[T]] | Map<string, any>;
|
|
17
|
+
export interface ConstantFieldProps<FieldValue = any, MapValue = any, Metadata = {
|
|
46
18
|
[key: string]: any;
|
|
47
19
|
}> {
|
|
48
20
|
nullable?: boolean;
|
|
49
21
|
ref?: string;
|
|
50
22
|
refPath?: string;
|
|
51
23
|
refType?: "child" | "parent" | "relation";
|
|
52
|
-
default?:
|
|
53
|
-
|
|
24
|
+
default?: FieldValue | ((doc: {
|
|
25
|
+
id: string;
|
|
26
|
+
}) => FieldValue);
|
|
27
|
+
type?: FieldPreset;
|
|
54
28
|
fieldType?: "property" | "hidden" | "resolve";
|
|
55
29
|
immutable?: boolean;
|
|
56
30
|
min?: number;
|
|
57
31
|
max?: number;
|
|
58
|
-
enum?: Enum
|
|
32
|
+
enum?: Enum;
|
|
59
33
|
select?: boolean;
|
|
60
34
|
minlength?: number;
|
|
61
35
|
maxlength?: number;
|
|
62
36
|
accumulate?: AccumulatorOperator;
|
|
63
|
-
example?:
|
|
64
|
-
of?:
|
|
65
|
-
validate?: (value:
|
|
37
|
+
example?: FieldValue;
|
|
38
|
+
of?: MapValue;
|
|
39
|
+
validate?: (value: FieldValue, model: any) => boolean;
|
|
66
40
|
text?: "search" | "filter";
|
|
67
41
|
meta?: Metadata;
|
|
68
42
|
}
|
|
69
|
-
export type ConstantFieldMeta<Metadata
|
|
70
|
-
[key: string]: any;
|
|
71
|
-
} = {
|
|
43
|
+
export type ConstantFieldMeta<FieldValue = any, MapValue = any, Metadata = {
|
|
72
44
|
[key: string]: any;
|
|
73
|
-
}> = ConstantFieldProps<Metadata> & {
|
|
45
|
+
}> = ConstantFieldProps<FieldValue, MapValue, Metadata> & {
|
|
74
46
|
nullable: boolean;
|
|
75
47
|
default: any;
|
|
76
48
|
fieldType: "property" | "hidden" | "resolve";
|
|
@@ -78,7 +50,6 @@ export type ConstantFieldMeta<Metadata extends {
|
|
|
78
50
|
select: boolean;
|
|
79
51
|
} & {
|
|
80
52
|
key: string;
|
|
81
|
-
name: string;
|
|
82
53
|
isClass: boolean;
|
|
83
54
|
isScalar: boolean;
|
|
84
55
|
modelRef: Type;
|
|
@@ -88,7 +59,6 @@ export type ConstantFieldMeta<Metadata extends {
|
|
|
88
59
|
isMap: boolean;
|
|
89
60
|
meta: Metadata;
|
|
90
61
|
};
|
|
91
|
-
export declare const getClassMeta: (modelRef: Type) => ConstantClassMeta;
|
|
92
62
|
export declare const getFieldMetas: (modelRef: Type) => ConstantFieldMeta[];
|
|
93
63
|
export declare const isConstantModel: (modelRef: Type) => boolean;
|
|
94
64
|
export declare const getFieldMetaMap: (modelRef: Type) => Map<string, ConstantFieldMeta>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Type } from "@akanjs/base";
|
|
2
|
+
export declare const serializeArg: (argRef: Type, arrDepth: number, value: any, { nullable }: {
|
|
3
|
+
nullable?: boolean;
|
|
4
|
+
}) => object[] | null;
|
|
5
|
+
export declare const deserializeArg: (argRef: Type, arrDepth: number, value: any, { nullable }: {
|
|
6
|
+
nullable?: boolean;
|
|
7
|
+
}) => object[] | null;
|
package/src/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type BaseObject, Dayjs, enumOf, type GetStateObject } from "@akanjs/base";
|
|
2
|
-
import type { FilterQuery, HydratedDocument
|
|
1
|
+
import { type BaseObject, Dayjs, enumOf, type GetStateObject, Upload } from "@akanjs/base";
|
|
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 {
|
|
5
5
|
[key: string]: any;
|
|
@@ -9,33 +9,13 @@ type NullToUndefinedWithObjectToId<T, StateKeys extends keyof GetStateObject<T>
|
|
|
9
9
|
} & {
|
|
10
10
|
[K in StateKeys as null extends T[K] ? K : never]?: ObjectToId<Exclude<T[K], null>> | undefined;
|
|
11
11
|
};
|
|
12
|
-
export type DocumentModel<T> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string | number | boolean | Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V>> : NullToUndefinedWithObjectToId<T>;
|
|
12
|
+
export type DocumentModel<T> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string | number | boolean | Dayjs | Upload ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V>> : NullToUndefinedWithObjectToId<T>;
|
|
13
13
|
export type FieldState<T> = T extends {
|
|
14
14
|
id: string;
|
|
15
15
|
} ? T | null : T;
|
|
16
16
|
export type DefaultOf<S> = {
|
|
17
17
|
[K in keyof S]: FieldState<S[K]>;
|
|
18
18
|
};
|
|
19
|
-
export interface SortType {
|
|
20
|
-
[key: string]: {
|
|
21
|
-
[key: string]: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export type SortOf<Filter> = keyof GetStateObject<Filter>;
|
|
25
|
-
export type FilterType = Record<string, any>;
|
|
26
|
-
export interface ListQueryOption<Sort, Obj> {
|
|
27
|
-
skip?: number | null;
|
|
28
|
-
limit?: number | null;
|
|
29
|
-
sort?: Sort | null;
|
|
30
|
-
sample?: number;
|
|
31
|
-
select?: ProjectionType<Obj>;
|
|
32
|
-
}
|
|
33
|
-
export interface FindQueryOption<Sort, Obj> {
|
|
34
|
-
skip?: number | null;
|
|
35
|
-
sort?: Sort | null;
|
|
36
|
-
sample?: boolean;
|
|
37
|
-
select?: ProjectionType<Obj>;
|
|
38
|
-
}
|
|
39
19
|
export type GetPlainObject<T, O extends string> = Omit<{
|
|
40
20
|
[K in keyof T as T[K] extends (...args: any) => any ? never : K extends keyof HydratedDocument<any> ? never : K]: T[K];
|
|
41
21
|
}, O>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var constantDecorator_exports = {};
|
|
19
|
-
__export(constantDecorator_exports, {
|
|
20
|
-
cnstOf: () => cnstOf,
|
|
21
|
-
getCnstMeta: () => getCnstMeta,
|
|
22
|
-
scalarCnstOf: () => scalarCnstOf
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(constantDecorator_exports);
|
|
25
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
26
|
-
class CnstStorage {
|
|
27
|
-
}
|
|
28
|
-
const setCnstMeta = (refName, cnst) => {
|
|
29
|
-
Reflect.defineMetadata(refName, cnst, CnstStorage.prototype);
|
|
30
|
-
};
|
|
31
|
-
const getCnstMeta = (refName) => {
|
|
32
|
-
const cnst = Reflect.getMetadata(refName, CnstStorage.prototype);
|
|
33
|
-
if (!cnst)
|
|
34
|
-
throw new Error(`No cnst meta for ${refName}`);
|
|
35
|
-
return cnst;
|
|
36
|
-
};
|
|
37
|
-
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
38
|
-
const cnst = {
|
|
39
|
-
refName,
|
|
40
|
-
Input,
|
|
41
|
-
Full,
|
|
42
|
-
Light,
|
|
43
|
-
Insight,
|
|
44
|
-
Filter,
|
|
45
|
-
_CapitalizedT: null,
|
|
46
|
-
_Default: null,
|
|
47
|
-
_DefaultInput: null,
|
|
48
|
-
_DefaultState: null,
|
|
49
|
-
_DefaultStateInput: null,
|
|
50
|
-
_Doc: null,
|
|
51
|
-
_DocInput: null,
|
|
52
|
-
_QueryOfDoc: null,
|
|
53
|
-
_Query: null,
|
|
54
|
-
_Sort: null
|
|
55
|
-
};
|
|
56
|
-
setCnstMeta(refName, cnst);
|
|
57
|
-
return cnst;
|
|
58
|
-
};
|
|
59
|
-
const scalarCnstOf = (refName, Model) => {
|
|
60
|
-
const cnst = {
|
|
61
|
-
refName,
|
|
62
|
-
Model,
|
|
63
|
-
_Default: null,
|
|
64
|
-
_Doc: null
|
|
65
|
-
};
|
|
66
|
-
return cnst;
|
|
67
|
-
};
|
package/cjs/src/fieldMeta.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var fieldMeta_exports = {};
|
|
19
|
-
__export(fieldMeta_exports, {
|
|
20
|
-
Field: () => Field
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(fieldMeta_exports);
|
|
23
|
-
var import_base = require("@akanjs/base");
|
|
24
|
-
var import_scalar = require("./scalar");
|
|
25
|
-
const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
26
|
-
const isArray = arrDepth > 0;
|
|
27
|
-
const isClass = !(0, import_base.isGqlScalar)(modelRef);
|
|
28
|
-
const isMap = (0, import_base.isGqlMap)(modelRef);
|
|
29
|
-
const { refName, type } = isClass ? (0, import_scalar.getClassMeta)(modelRef) : { refName: "", type: "scalar" };
|
|
30
|
-
const name = isClass ? refName : import_base.scalarNameMap.get(modelRef) ?? "Unknown";
|
|
31
|
-
if (isMap && !option.of)
|
|
32
|
-
throw new Error("Map type must have 'of' option");
|
|
33
|
-
return (prototype, key) => {
|
|
34
|
-
const metadata = {
|
|
35
|
-
nullable: option.nullable ?? false,
|
|
36
|
-
ref: option.ref,
|
|
37
|
-
refPath: option.refPath,
|
|
38
|
-
refType: option.refType,
|
|
39
|
-
default: option.default ?? (isArray ? [] : null),
|
|
40
|
-
type: option.type,
|
|
41
|
-
fieldType: option.fieldType ?? "property",
|
|
42
|
-
immutable: option.immutable ?? false,
|
|
43
|
-
min: option.min,
|
|
44
|
-
max: option.max,
|
|
45
|
-
enum: option.enum,
|
|
46
|
-
select: option.select ?? true,
|
|
47
|
-
minlength: option.minlength,
|
|
48
|
-
maxlength: option.maxlength,
|
|
49
|
-
accumulate: option.accumulate,
|
|
50
|
-
example: option.example,
|
|
51
|
-
validate: option.validate,
|
|
52
|
-
key,
|
|
53
|
-
name,
|
|
54
|
-
isClass,
|
|
55
|
-
isScalar: type === "scalar",
|
|
56
|
-
modelRef,
|
|
57
|
-
arrDepth,
|
|
58
|
-
isArray,
|
|
59
|
-
optArrDepth: optionArrDepth,
|
|
60
|
-
isMap,
|
|
61
|
-
of: option.of,
|
|
62
|
-
text: option.text,
|
|
63
|
-
meta: option.meta ?? {}
|
|
64
|
-
};
|
|
65
|
-
const metadataMap = (0, import_scalar.getFieldMetaMapOnPrototype)(prototype);
|
|
66
|
-
metadataMap.set(key, metadata);
|
|
67
|
-
(0, import_scalar.setFieldMetaMapOnPrototype)(prototype, metadataMap);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
const makeField = (customOption) => (returns, fieldOption) => {
|
|
71
|
-
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(returns());
|
|
72
|
-
if (!fieldOption)
|
|
73
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
74
|
-
const [opt, optArrDepth] = (0, import_base.getNonArrayModel)(fieldOption);
|
|
75
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
76
|
-
};
|
|
77
|
-
const Field = {
|
|
78
|
-
Prop: makeField({ fieldType: "property" }),
|
|
79
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
80
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
81
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
82
|
-
};
|
package/cjs/src/filterMeta.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
-
if (decorator = decorators[i])
|
|
22
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
-
if (kind && result)
|
|
24
|
-
__defProp(target, key, result);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
28
|
-
var filterMeta_exports = {};
|
|
29
|
-
__export(filterMeta_exports, {
|
|
30
|
-
BaseFilter: () => BaseFilter,
|
|
31
|
-
Filter: () => Filter,
|
|
32
|
-
getFilterArgMetas: () => getFilterArgMetas,
|
|
33
|
-
getFilterKeyMetaMapOnPrototype: () => getFilterKeyMetaMapOnPrototype,
|
|
34
|
-
getFilterMeta: () => getFilterMeta,
|
|
35
|
-
getFilterQuery: () => getFilterQuery,
|
|
36
|
-
getFilterQueryMap: () => getFilterQueryMap,
|
|
37
|
-
getFilterSort: () => getFilterSort,
|
|
38
|
-
getFilterSortMap: () => getFilterSortMap,
|
|
39
|
-
isFilterModel: () => isFilterModel,
|
|
40
|
-
setFilterArgMetasOnPrototype: () => setFilterArgMetasOnPrototype,
|
|
41
|
-
setFilterKeyMetaMapOnPrototype: () => setFilterKeyMetaMapOnPrototype,
|
|
42
|
-
setFilterMeta: () => setFilterMeta,
|
|
43
|
-
sortOf: () => sortOf
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(filterMeta_exports);
|
|
46
|
-
var import_base = require("@akanjs/base");
|
|
47
|
-
var import_common = require("@akanjs/common");
|
|
48
|
-
var import_scalar = require("./scalar");
|
|
49
|
-
const isFilterModel = (filterRef) => {
|
|
50
|
-
return Reflect.getMetadata("filter", filterRef.prototype) !== void 0;
|
|
51
|
-
};
|
|
52
|
-
const getFilterMeta = (filterRef) => {
|
|
53
|
-
const filterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
54
|
-
if (!filterMeta)
|
|
55
|
-
throw new Error("filterMeta is not defined");
|
|
56
|
-
return filterMeta;
|
|
57
|
-
};
|
|
58
|
-
const setFilterMeta = (filterRef, filterMeta) => {
|
|
59
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
60
|
-
if (existingFilterMeta)
|
|
61
|
-
Object.assign(existingFilterMeta, { ...filterMeta, sort: { ...existingFilterMeta.sort, ...filterMeta.sort } });
|
|
62
|
-
else
|
|
63
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
64
|
-
};
|
|
65
|
-
const getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
66
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
67
|
-
return new Map(metadataMap);
|
|
68
|
-
};
|
|
69
|
-
const setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
70
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
71
|
-
};
|
|
72
|
-
const applyFilterKeyMeta = (option) => {
|
|
73
|
-
return (prototype, key, descriptor) => {
|
|
74
|
-
const metadata = { key, ...option, descriptor };
|
|
75
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
76
|
-
metadataMap.set(key, metadata);
|
|
77
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const makeFilter = (customOption) => (fieldOption) => {
|
|
81
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
82
|
-
};
|
|
83
|
-
const getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
84
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
85
|
-
return filterArgMetas;
|
|
86
|
-
};
|
|
87
|
-
const setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
88
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
89
|
-
};
|
|
90
|
-
const getFilterArgMetas = (filterRef, key) => {
|
|
91
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(filterRef.prototype, key);
|
|
92
|
-
return filterArgMetas;
|
|
93
|
-
};
|
|
94
|
-
const applyFilterArgMeta = (name, returns, argOption) => {
|
|
95
|
-
return (prototype, key, idx) => {
|
|
96
|
-
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(returns());
|
|
97
|
-
const [opt, optArrDepth] = (0, import_base.getNonArrayModel)(argOption ?? {});
|
|
98
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
99
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
100
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
101
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
const getFilterQuery = (filterRef, key) => {
|
|
105
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
106
|
-
const filterKeyMeta = filterKeyMetaMap.get(key);
|
|
107
|
-
if (!filterKeyMeta?.descriptor.value)
|
|
108
|
-
throw new Error(`filterKeyMeta is not defined for key: ${key}`);
|
|
109
|
-
return filterKeyMeta.descriptor.value;
|
|
110
|
-
};
|
|
111
|
-
const getFilterQueryMap = (filterRef) => {
|
|
112
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
113
|
-
return filterKeyMetaMap;
|
|
114
|
-
};
|
|
115
|
-
const getFilterSort = (filterRef, key) => {
|
|
116
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
117
|
-
const sort = filterMeta.sort[key];
|
|
118
|
-
return sort;
|
|
119
|
-
};
|
|
120
|
-
const getFilterSortMap = (filterRef) => {
|
|
121
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
122
|
-
return filterMeta.sort;
|
|
123
|
-
};
|
|
124
|
-
const Filter = {
|
|
125
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
126
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
127
|
-
Arg: applyFilterArgMeta
|
|
128
|
-
};
|
|
129
|
-
const sortOf = (modelRef, sort, ...libFilterRefs) => {
|
|
130
|
-
const fieldMetaMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
131
|
-
const statusFieldMeta = fieldMetaMap.get("status");
|
|
132
|
-
if (!statusFieldMeta)
|
|
133
|
-
throw new Error(`No status field meta fount in ${modelRef.name}`);
|
|
134
|
-
class BaseFilter2 {
|
|
135
|
-
latest = { createdAt: -1 };
|
|
136
|
-
oldest = { createdAt: 1 };
|
|
137
|
-
any() {
|
|
138
|
-
return { removedAt: { $exists: false } };
|
|
139
|
-
}
|
|
140
|
-
byStatuses(statuses) {
|
|
141
|
-
return statuses?.length ? { status: { $in: statuses } } : {};
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
__decorateClass([
|
|
145
|
-
Filter.Mongo()
|
|
146
|
-
], BaseFilter2.prototype, "any", 1);
|
|
147
|
-
__decorateClass([
|
|
148
|
-
Filter.Mongo(),
|
|
149
|
-
__decorateParam(0, Filter.Arg("statuses", () => [String], { nullable: true, enum: statusFieldMeta?.enum }))
|
|
150
|
-
], BaseFilter2.prototype, "byStatuses", 1);
|
|
151
|
-
Object.assign(BaseFilter2.prototype, sort);
|
|
152
|
-
setFilterMeta(BaseFilter2, {
|
|
153
|
-
refName: "BaseFilter",
|
|
154
|
-
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
155
|
-
});
|
|
156
|
-
(0, import_common.applyMixins)(BaseFilter2, libFilterRefs);
|
|
157
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(BaseFilter2.prototype);
|
|
158
|
-
libFilterRefs.forEach((libFilterRef) => {
|
|
159
|
-
const libFilterKeyMetaMap = getFilterKeyMetaMapOnPrototype(libFilterRef.prototype);
|
|
160
|
-
libFilterKeyMetaMap.forEach((value, key) => {
|
|
161
|
-
const libFilterArgMetas = getFilterArgMetas(libFilterRef, key);
|
|
162
|
-
filterKeyMetaMap.set(key, value);
|
|
163
|
-
setFilterArgMetasOnPrototype(BaseFilter2.prototype, key, libFilterArgMetas);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
return BaseFilter2;
|
|
167
|
-
};
|
|
168
|
-
function BaseFilter(modelRef, sort) {
|
|
169
|
-
const fieldMetaMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
170
|
-
const statusFieldMeta = fieldMetaMap.get("status");
|
|
171
|
-
if (!statusFieldMeta)
|
|
172
|
-
throw new Error(`No status field meta fount in ${modelRef.name}`);
|
|
173
|
-
class BaseFilter2 {
|
|
174
|
-
latest = { createdAt: -1 };
|
|
175
|
-
oldest = { createdAt: 1 };
|
|
176
|
-
any() {
|
|
177
|
-
return { removedAt: { $exists: false } };
|
|
178
|
-
}
|
|
179
|
-
byStatuses(statuses) {
|
|
180
|
-
return statuses?.length ? { status: { $in: statuses } } : {};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
__decorateClass([
|
|
184
|
-
Filter.Mongo()
|
|
185
|
-
], BaseFilter2.prototype, "any", 1);
|
|
186
|
-
__decorateClass([
|
|
187
|
-
Filter.Mongo(),
|
|
188
|
-
__decorateParam(0, Filter.Arg("statuses", () => [String], { nullable: true, enum: statusFieldMeta?.enum }))
|
|
189
|
-
], BaseFilter2.prototype, "byStatuses", 1);
|
|
190
|
-
Object.assign(BaseFilter2.prototype, sort);
|
|
191
|
-
setFilterMeta(BaseFilter2, {
|
|
192
|
-
refName: "BaseFilter",
|
|
193
|
-
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
194
|
-
});
|
|
195
|
-
return BaseFilter2;
|
|
196
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
class CnstStorage {
|
|
3
|
-
}
|
|
4
|
-
const setCnstMeta = (refName, cnst) => {
|
|
5
|
-
Reflect.defineMetadata(refName, cnst, CnstStorage.prototype);
|
|
6
|
-
};
|
|
7
|
-
const getCnstMeta = (refName) => {
|
|
8
|
-
const cnst = Reflect.getMetadata(refName, CnstStorage.prototype);
|
|
9
|
-
if (!cnst)
|
|
10
|
-
throw new Error(`No cnst meta for ${refName}`);
|
|
11
|
-
return cnst;
|
|
12
|
-
};
|
|
13
|
-
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
14
|
-
const cnst = {
|
|
15
|
-
refName,
|
|
16
|
-
Input,
|
|
17
|
-
Full,
|
|
18
|
-
Light,
|
|
19
|
-
Insight,
|
|
20
|
-
Filter,
|
|
21
|
-
_CapitalizedT: null,
|
|
22
|
-
_Default: null,
|
|
23
|
-
_DefaultInput: null,
|
|
24
|
-
_DefaultState: null,
|
|
25
|
-
_DefaultStateInput: null,
|
|
26
|
-
_Doc: null,
|
|
27
|
-
_DocInput: null,
|
|
28
|
-
_QueryOfDoc: null,
|
|
29
|
-
_Query: null,
|
|
30
|
-
_Sort: null
|
|
31
|
-
};
|
|
32
|
-
setCnstMeta(refName, cnst);
|
|
33
|
-
return cnst;
|
|
34
|
-
};
|
|
35
|
-
const scalarCnstOf = (refName, Model) => {
|
|
36
|
-
const cnst = {
|
|
37
|
-
refName,
|
|
38
|
-
Model,
|
|
39
|
-
_Default: null,
|
|
40
|
-
_Doc: null
|
|
41
|
-
};
|
|
42
|
-
return cnst;
|
|
43
|
-
};
|
|
44
|
-
export {
|
|
45
|
-
cnstOf,
|
|
46
|
-
getCnstMeta,
|
|
47
|
-
scalarCnstOf
|
|
48
|
-
};
|
package/esm/src/fieldMeta.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { getNonArrayModel, isGqlMap, isGqlScalar, scalarNameMap } from "@akanjs/base";
|
|
2
|
-
import {
|
|
3
|
-
getClassMeta,
|
|
4
|
-
getFieldMetaMapOnPrototype,
|
|
5
|
-
setFieldMetaMapOnPrototype
|
|
6
|
-
} from "./scalar";
|
|
7
|
-
const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
8
|
-
const isArray = arrDepth > 0;
|
|
9
|
-
const isClass = !isGqlScalar(modelRef);
|
|
10
|
-
const isMap = isGqlMap(modelRef);
|
|
11
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
12
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
13
|
-
if (isMap && !option.of)
|
|
14
|
-
throw new Error("Map type must have 'of' option");
|
|
15
|
-
return (prototype, key) => {
|
|
16
|
-
const metadata = {
|
|
17
|
-
nullable: option.nullable ?? false,
|
|
18
|
-
ref: option.ref,
|
|
19
|
-
refPath: option.refPath,
|
|
20
|
-
refType: option.refType,
|
|
21
|
-
default: option.default ?? (isArray ? [] : null),
|
|
22
|
-
type: option.type,
|
|
23
|
-
fieldType: option.fieldType ?? "property",
|
|
24
|
-
immutable: option.immutable ?? false,
|
|
25
|
-
min: option.min,
|
|
26
|
-
max: option.max,
|
|
27
|
-
enum: option.enum,
|
|
28
|
-
select: option.select ?? true,
|
|
29
|
-
minlength: option.minlength,
|
|
30
|
-
maxlength: option.maxlength,
|
|
31
|
-
accumulate: option.accumulate,
|
|
32
|
-
example: option.example,
|
|
33
|
-
validate: option.validate,
|
|
34
|
-
key,
|
|
35
|
-
name,
|
|
36
|
-
isClass,
|
|
37
|
-
isScalar: type === "scalar",
|
|
38
|
-
modelRef,
|
|
39
|
-
arrDepth,
|
|
40
|
-
isArray,
|
|
41
|
-
optArrDepth: optionArrDepth,
|
|
42
|
-
isMap,
|
|
43
|
-
of: option.of,
|
|
44
|
-
text: option.text,
|
|
45
|
-
meta: option.meta ?? {}
|
|
46
|
-
};
|
|
47
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
48
|
-
metadataMap.set(key, metadata);
|
|
49
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const makeField = (customOption) => (returns, fieldOption) => {
|
|
53
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
54
|
-
if (!fieldOption)
|
|
55
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
56
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
57
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
58
|
-
};
|
|
59
|
-
const Field = {
|
|
60
|
-
Prop: makeField({ fieldType: "property" }),
|
|
61
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
62
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
63
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
64
|
-
};
|
|
65
|
-
export {
|
|
66
|
-
Field
|
|
67
|
-
};
|