@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/esm/src/filterMeta.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
13
|
-
import { getNonArrayModel } from "@akanjs/base";
|
|
14
|
-
import { applyMixins } from "@akanjs/common";
|
|
15
|
-
import {
|
|
16
|
-
getFieldMetaMap
|
|
17
|
-
} from "./scalar";
|
|
18
|
-
const isFilterModel = (filterRef) => {
|
|
19
|
-
return Reflect.getMetadata("filter", filterRef.prototype) !== void 0;
|
|
20
|
-
};
|
|
21
|
-
const getFilterMeta = (filterRef) => {
|
|
22
|
-
const filterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
23
|
-
if (!filterMeta)
|
|
24
|
-
throw new Error("filterMeta is not defined");
|
|
25
|
-
return filterMeta;
|
|
26
|
-
};
|
|
27
|
-
const setFilterMeta = (filterRef, filterMeta) => {
|
|
28
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
29
|
-
if (existingFilterMeta)
|
|
30
|
-
Object.assign(existingFilterMeta, { ...filterMeta, sort: { ...existingFilterMeta.sort, ...filterMeta.sort } });
|
|
31
|
-
else
|
|
32
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
33
|
-
};
|
|
34
|
-
const getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
35
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
36
|
-
return new Map(metadataMap);
|
|
37
|
-
};
|
|
38
|
-
const setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
39
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
40
|
-
};
|
|
41
|
-
const applyFilterKeyMeta = (option) => {
|
|
42
|
-
return (prototype, key, descriptor) => {
|
|
43
|
-
const metadata = { key, ...option, descriptor };
|
|
44
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
45
|
-
metadataMap.set(key, metadata);
|
|
46
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
const makeFilter = (customOption) => (fieldOption) => {
|
|
50
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
51
|
-
};
|
|
52
|
-
const getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
53
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
54
|
-
return filterArgMetas;
|
|
55
|
-
};
|
|
56
|
-
const setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
57
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
58
|
-
};
|
|
59
|
-
const getFilterArgMetas = (filterRef, key) => {
|
|
60
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(filterRef.prototype, key);
|
|
61
|
-
return filterArgMetas;
|
|
62
|
-
};
|
|
63
|
-
const applyFilterArgMeta = (name, returns, argOption) => {
|
|
64
|
-
return (prototype, key, idx) => {
|
|
65
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
66
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
67
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
68
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
69
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
70
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
const getFilterQuery = (filterRef, key) => {
|
|
74
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
75
|
-
const filterKeyMeta = filterKeyMetaMap.get(key);
|
|
76
|
-
if (!filterKeyMeta?.descriptor.value)
|
|
77
|
-
throw new Error(`filterKeyMeta is not defined for key: ${key}`);
|
|
78
|
-
return filterKeyMeta.descriptor.value;
|
|
79
|
-
};
|
|
80
|
-
const getFilterQueryMap = (filterRef) => {
|
|
81
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(filterRef.prototype);
|
|
82
|
-
return filterKeyMetaMap;
|
|
83
|
-
};
|
|
84
|
-
const getFilterSort = (filterRef, key) => {
|
|
85
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
86
|
-
const sort = filterMeta.sort[key];
|
|
87
|
-
return sort;
|
|
88
|
-
};
|
|
89
|
-
const getFilterSortMap = (filterRef) => {
|
|
90
|
-
const filterMeta = getFilterMeta(filterRef);
|
|
91
|
-
return filterMeta.sort;
|
|
92
|
-
};
|
|
93
|
-
const Filter = {
|
|
94
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
95
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
96
|
-
Arg: applyFilterArgMeta
|
|
97
|
-
};
|
|
98
|
-
const sortOf = (modelRef, sort, ...libFilterRefs) => {
|
|
99
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
100
|
-
const statusFieldMeta = fieldMetaMap.get("status");
|
|
101
|
-
if (!statusFieldMeta)
|
|
102
|
-
throw new Error(`No status field meta fount in ${modelRef.name}`);
|
|
103
|
-
class BaseFilter2 {
|
|
104
|
-
latest = { createdAt: -1 };
|
|
105
|
-
oldest = { createdAt: 1 };
|
|
106
|
-
any() {
|
|
107
|
-
return { removedAt: { $exists: false } };
|
|
108
|
-
}
|
|
109
|
-
byStatuses(statuses) {
|
|
110
|
-
return statuses?.length ? { status: { $in: statuses } } : {};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
__decorateClass([
|
|
114
|
-
Filter.Mongo()
|
|
115
|
-
], BaseFilter2.prototype, "any", 1);
|
|
116
|
-
__decorateClass([
|
|
117
|
-
Filter.Mongo(),
|
|
118
|
-
__decorateParam(0, Filter.Arg("statuses", () => [String], { nullable: true, enum: statusFieldMeta?.enum }))
|
|
119
|
-
], BaseFilter2.prototype, "byStatuses", 1);
|
|
120
|
-
Object.assign(BaseFilter2.prototype, sort);
|
|
121
|
-
setFilterMeta(BaseFilter2, {
|
|
122
|
-
refName: "BaseFilter",
|
|
123
|
-
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
124
|
-
});
|
|
125
|
-
applyMixins(BaseFilter2, libFilterRefs);
|
|
126
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(BaseFilter2.prototype);
|
|
127
|
-
libFilterRefs.forEach((libFilterRef) => {
|
|
128
|
-
const libFilterKeyMetaMap = getFilterKeyMetaMapOnPrototype(libFilterRef.prototype);
|
|
129
|
-
libFilterKeyMetaMap.forEach((value, key) => {
|
|
130
|
-
const libFilterArgMetas = getFilterArgMetas(libFilterRef, key);
|
|
131
|
-
filterKeyMetaMap.set(key, value);
|
|
132
|
-
setFilterArgMetasOnPrototype(BaseFilter2.prototype, key, libFilterArgMetas);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
return BaseFilter2;
|
|
136
|
-
};
|
|
137
|
-
function BaseFilter(modelRef, sort) {
|
|
138
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
139
|
-
const statusFieldMeta = fieldMetaMap.get("status");
|
|
140
|
-
if (!statusFieldMeta)
|
|
141
|
-
throw new Error(`No status field meta fount in ${modelRef.name}`);
|
|
142
|
-
class BaseFilter2 {
|
|
143
|
-
latest = { createdAt: -1 };
|
|
144
|
-
oldest = { createdAt: 1 };
|
|
145
|
-
any() {
|
|
146
|
-
return { removedAt: { $exists: false } };
|
|
147
|
-
}
|
|
148
|
-
byStatuses(statuses) {
|
|
149
|
-
return statuses?.length ? { status: { $in: statuses } } : {};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
__decorateClass([
|
|
153
|
-
Filter.Mongo()
|
|
154
|
-
], BaseFilter2.prototype, "any", 1);
|
|
155
|
-
__decorateClass([
|
|
156
|
-
Filter.Mongo(),
|
|
157
|
-
__decorateParam(0, Filter.Arg("statuses", () => [String], { nullable: true, enum: statusFieldMeta?.enum }))
|
|
158
|
-
], BaseFilter2.prototype, "byStatuses", 1);
|
|
159
|
-
Object.assign(BaseFilter2.prototype, sort);
|
|
160
|
-
setFilterMeta(BaseFilter2, {
|
|
161
|
-
refName: "BaseFilter",
|
|
162
|
-
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
163
|
-
});
|
|
164
|
-
return BaseFilter2;
|
|
165
|
-
}
|
|
166
|
-
export {
|
|
167
|
-
BaseFilter,
|
|
168
|
-
Filter,
|
|
169
|
-
getFilterArgMetas,
|
|
170
|
-
getFilterKeyMetaMapOnPrototype,
|
|
171
|
-
getFilterMeta,
|
|
172
|
-
getFilterQuery,
|
|
173
|
-
getFilterQueryMap,
|
|
174
|
-
getFilterSort,
|
|
175
|
-
getFilterSortMap,
|
|
176
|
-
isFilterModel,
|
|
177
|
-
setFilterArgMetasOnPrototype,
|
|
178
|
-
setFilterKeyMetaMapOnPrototype,
|
|
179
|
-
setFilterMeta,
|
|
180
|
-
sortOf
|
|
181
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import type { GetActionObject, GetStateObject, Type } from "@akanjs/base";
|
|
3
|
-
import type { DefaultOf, DocumentModel, FilterType, QueryOf, SortOf } from "./types";
|
|
4
|
-
export declare const getCnstMeta: (refName: string) => ConstantModel<any, any, any, any, any, any>;
|
|
5
|
-
export interface ConstantModel<T extends string, Input, Full, Light, Insight, Filter extends FilterType, _CapitalizedT extends string = Capitalize<T>, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>, _Query = GetActionObject<Filter>, _Sort = SortOf<Filter>> {
|
|
6
|
-
refName: T;
|
|
7
|
-
Input: Type<Input>;
|
|
8
|
-
Full: Type<Full>;
|
|
9
|
-
Light: Type<Light>;
|
|
10
|
-
Insight: Type<Insight>;
|
|
11
|
-
Filter: Type<Filter>;
|
|
12
|
-
_CapitalizedT: _CapitalizedT;
|
|
13
|
-
_Default: _Default;
|
|
14
|
-
_DefaultInput: _DefaultInput;
|
|
15
|
-
_DefaultState: _DefaultState;
|
|
16
|
-
_DefaultStateInput: _DefaultStateInput;
|
|
17
|
-
_Doc: _Doc;
|
|
18
|
-
_DocInput: _DocInput;
|
|
19
|
-
_QueryOfDoc: _QueryOfDoc;
|
|
20
|
-
_Query: _Query;
|
|
21
|
-
_Sort: _Sort;
|
|
22
|
-
}
|
|
23
|
-
export declare const cnstOf: <T extends string, Input, Full, Light, Insight, Filter extends FilterType>(refName: T, Input: Type<Input>, Full: Type<Full>, Light: Type<Light>, Insight: Type<Insight>, Filter: Type<Filter>) => ConstantModel<T, Input, Full, Light, Insight, Filter, Capitalize<T>, DefaultOf<Full>, DefaultOf<Input>, GetStateObject<Full>, GetStateObject<Input>, DocumentModel<Full>, DocumentModel<Input>, QueryOf<DocumentModel<Full>>, GetActionObject<Filter>, SortOf<Filter>>;
|
|
24
|
-
export interface ScalarConstantModel<T extends string, Model, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>> {
|
|
25
|
-
refName: T;
|
|
26
|
-
Model: Type<Model>;
|
|
27
|
-
_Default: _Default;
|
|
28
|
-
_Doc: _Doc;
|
|
29
|
-
}
|
|
30
|
-
export declare const scalarCnstOf: <T extends string, Model>(refName: T, Model: Type<Model>) => ScalarConstantModel<T, Model>;
|
package/src/fieldMeta.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ConstantFieldProps, ReturnType } from "./scalar";
|
|
2
|
-
export declare const Field: {
|
|
3
|
-
Prop: (returns: ReturnType, fieldOption?: Omit<ConstantFieldProps, "fieldType" | "select"> | Omit<ConstantFieldProps, "nullable" | "fieldType" | "select">[]) => PropertyDecorator;
|
|
4
|
-
Hidden: (returns: ReturnType, fieldOption?: Omit<ConstantFieldProps, "fieldType" | "select"> | Omit<ConstantFieldProps, "nullable" | "fieldType" | "select">[]) => PropertyDecorator;
|
|
5
|
-
Secret: (returns: ReturnType, fieldOption?: Omit<ConstantFieldProps, "fieldType" | "select"> | Omit<ConstantFieldProps, "nullable" | "fieldType" | "select">[]) => PropertyDecorator;
|
|
6
|
-
Resolve: (returns: ReturnType, fieldOption?: Omit<ConstantFieldProps, "fieldType" | "select"> | Omit<ConstantFieldProps, "nullable" | "fieldType" | "select">[]) => PropertyDecorator;
|
|
7
|
-
};
|
package/src/filterMeta.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { type MergeAllTypes, type Prettify, type Type } from "@akanjs/base";
|
|
2
|
-
import { type ConstantFilterMeta, type FilterArgMeta, type FilterArgProps, type FilterKeyMeta, type FilterKeyProps, type ReturnType } from "./scalar";
|
|
3
|
-
import type { QueryOf, SortType } from "./types";
|
|
4
|
-
export declare const isFilterModel: (filterRef: Type) => boolean;
|
|
5
|
-
export declare const getFilterMeta: (filterRef: Type) => ConstantFilterMeta;
|
|
6
|
-
export declare const setFilterMeta: (filterRef: Type, filterMeta: ConstantFilterMeta) => void;
|
|
7
|
-
export declare const getFilterKeyMetaMapOnPrototype: (prototype: object) => Map<string, FilterKeyMeta>;
|
|
8
|
-
export declare const setFilterKeyMetaMapOnPrototype: (prototype: object, metadataMap: Map<string, FilterKeyMeta>) => void;
|
|
9
|
-
export declare const setFilterArgMetasOnPrototype: (prototype: object, key: string, filterArgMetas: FilterArgMeta[]) => void;
|
|
10
|
-
export declare const getFilterArgMetas: (filterRef: Type, key: string) => FilterArgMeta[];
|
|
11
|
-
export declare const getFilterQuery: (filterRef: Type, key: string) => (...args: any[]) => QueryOf<any>;
|
|
12
|
-
export declare const getFilterQueryMap: (filterRef: Type) => Map<string, FilterKeyMeta>;
|
|
13
|
-
export declare const getFilterSort: (filterRef: Type, key: string) => {
|
|
14
|
-
[key: string]: number;
|
|
15
|
-
};
|
|
16
|
-
export declare const getFilterSortMap: (filterRef: Type) => SortType;
|
|
17
|
-
export declare const Filter: {
|
|
18
|
-
Mongo: (fieldOption?: Omit<FilterKeyProps, "type">) => (prototype: object, key: string, descriptor: PropertyDescriptor) => void;
|
|
19
|
-
Arg: (name: string, returns: ReturnType, argOption?: FilterArgProps | FilterArgProps[]) => (prototype: object, key: string, idx: number) => void;
|
|
20
|
-
};
|
|
21
|
-
export type BaseFilterKey = "latest" | "oldest" | "any" | "byStatuses";
|
|
22
|
-
export declare const sortOf: <Sort extends SortType, LibFilters extends Type[]>(modelRef: Type, sort: Sort, ...libFilterRefs: LibFilters) => Type<Prettify<MergeAllTypes<LibFilters> & {
|
|
23
|
-
latest: {
|
|
24
|
-
createdAt: number;
|
|
25
|
-
};
|
|
26
|
-
oldest: {
|
|
27
|
-
createdAt: number;
|
|
28
|
-
};
|
|
29
|
-
any(): {
|
|
30
|
-
removedAt: {
|
|
31
|
-
$exists: boolean;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
byStatuses(statuses: string[] | null): {
|
|
35
|
-
status: {
|
|
36
|
-
$in: string[];
|
|
37
|
-
};
|
|
38
|
-
} | {
|
|
39
|
-
status?: undefined;
|
|
40
|
-
};
|
|
41
|
-
} & Sort>>;
|
|
42
|
-
export declare function BaseFilter<Sort extends SortType>(modelRef: Type, sort: Sort): Type<{
|
|
43
|
-
latest: {
|
|
44
|
-
createdAt: number;
|
|
45
|
-
};
|
|
46
|
-
oldest: {
|
|
47
|
-
createdAt: number;
|
|
48
|
-
};
|
|
49
|
-
any(): {
|
|
50
|
-
removedAt: {
|
|
51
|
-
$exists: boolean;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
byStatuses(statuses: string[] | null): {
|
|
55
|
-
status: {
|
|
56
|
-
$in: string[];
|
|
57
|
-
};
|
|
58
|
-
} | {
|
|
59
|
-
status?: undefined;
|
|
60
|
-
};
|
|
61
|
-
} & Sort>;
|