@monorise/base 1.0.4 → 3.0.1
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/dist/index.d.ts +254 -3
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/package.json +10 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -7
- package/dist/types/monorise.type.d.ts +0 -205
- package/dist/types/monorise.type.d.ts.map +0 -1
- package/dist/types/monorise.type.js +0 -7
- package/dist/types/monorise.type.js.map +0 -1
- package/dist/types/mutual.type.d.ts +0 -21
- package/dist/types/mutual.type.d.ts.map +0 -1
- package/dist/types/mutual.type.js +0 -3
- package/dist/types/mutual.type.js.map +0 -1
- package/index.ts +0 -15
- package/tsconfig.json +0 -114
- package/types/monorise.type.ts +0 -242
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,254 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare enum Entity {
|
|
4
|
+
}
|
|
5
|
+
interface EntitySchemaMap {
|
|
6
|
+
[key: string]: Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
type DraftEntity<T extends Entity = Entity> = T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
9
|
+
type CreatedEntity<T extends Entity = Entity> = {
|
|
10
|
+
entityId: string;
|
|
11
|
+
entityType: string;
|
|
12
|
+
data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.
|
|
18
|
+
* This can be served as a single source of truth for the entity configuration.
|
|
19
|
+
* It is used to define the schema, and mutual relationships between this entity and other entities.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const baseSchema = z.object({
|
|
24
|
+
* title: z.string(),
|
|
25
|
+
* }).partial();
|
|
26
|
+
*
|
|
27
|
+
* const createSchema = baseSchema.extend({
|
|
28
|
+
* title: z.string(),
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* const config = createEntityConfig({
|
|
32
|
+
* name: 'learner',
|
|
33
|
+
* displayName: 'Learner',
|
|
34
|
+
* baseSchema,
|
|
35
|
+
* createSchema,
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShape = z.ZodRawShape, C extends z.ZodRawShape = z.ZodRawShape, M extends z.ZodRawShape = z.ZodRawShape, CO extends z.ZodObject<C> | undefined = undefined, MO extends z.ZodObject<M> | undefined = undefined> {
|
|
40
|
+
/**
|
|
41
|
+
* @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities
|
|
42
|
+
*
|
|
43
|
+
* @example `learner`, `learning-activity`
|
|
44
|
+
*/
|
|
45
|
+
name: string | T;
|
|
46
|
+
/**
|
|
47
|
+
* @description Display name of the entity. It is not required to be unique
|
|
48
|
+
*/
|
|
49
|
+
displayName: string;
|
|
50
|
+
/**
|
|
51
|
+
* @description (DEPRECATED) Use `uniqueFields` instead, Monorise should not handle auth mechanism
|
|
52
|
+
* @description (Optional) Specify the authentication method to be used for the entity
|
|
53
|
+
*/
|
|
54
|
+
authMethod?: {
|
|
55
|
+
/**
|
|
56
|
+
* @description Authentication method using email
|
|
57
|
+
*
|
|
58
|
+
* Note: The email used for authentication is unique per entity.
|
|
59
|
+
* For example, if `johndoe@mail.com` is used for `learner` entity,
|
|
60
|
+
* it can be reused again on `admin` entity. However, the same email
|
|
61
|
+
* address cannot be repeated for the same entity.
|
|
62
|
+
*/
|
|
63
|
+
email: {
|
|
64
|
+
/**
|
|
65
|
+
* @description Number of milliseconds before the token expires
|
|
66
|
+
*/
|
|
67
|
+
tokenExpiresIn: number;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @description Base schema for the entity
|
|
72
|
+
*/
|
|
73
|
+
baseSchema: z.ZodObject<B>;
|
|
74
|
+
/**
|
|
75
|
+
* @description Minimal schema required to create an entity
|
|
76
|
+
*/
|
|
77
|
+
createSchema?: CO;
|
|
78
|
+
searchableFields?: (keyof B)[];
|
|
79
|
+
uniqueFields?: (keyof B)[];
|
|
80
|
+
/**
|
|
81
|
+
* @description Define mutual relationship of this entity with other entities
|
|
82
|
+
*/
|
|
83
|
+
mutual?: {
|
|
84
|
+
/**
|
|
85
|
+
* @description Subscribes to update events from specified entities in the array.
|
|
86
|
+
* These events will be used to run prejoin processor.
|
|
87
|
+
*/
|
|
88
|
+
subscribes?: {
|
|
89
|
+
entityType: Entity;
|
|
90
|
+
}[];
|
|
91
|
+
/**
|
|
92
|
+
* @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database
|
|
93
|
+
*/
|
|
94
|
+
mutualSchema: MO;
|
|
95
|
+
/**
|
|
96
|
+
* @description Keys of `mutualFields` are fields defined in `mutualSchema`.
|
|
97
|
+
* Each field is a mutual relationship between this entity and another entity.
|
|
98
|
+
*/
|
|
99
|
+
mutualFields: {
|
|
100
|
+
[key: string]: {
|
|
101
|
+
entityType: Entity;
|
|
102
|
+
toMutualIds?: (context: any) => string[];
|
|
103
|
+
/**
|
|
104
|
+
* @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.
|
|
105
|
+
*
|
|
106
|
+
* @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.
|
|
107
|
+
*/
|
|
108
|
+
mutualDataProcessor?: (mutualIds: string[], currentMutual: any, customContext?: Record<string, any>) => Record<string, any>;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* @description (Optional) Better known as tree processor
|
|
113
|
+
* This is used to prejoin entities that are not directly related as mutual.
|
|
114
|
+
* For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,
|
|
115
|
+
* prejoins can be used to join `learner` and `module` entities.
|
|
116
|
+
* With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,
|
|
117
|
+
* hence reducing the number of queries.
|
|
118
|
+
*
|
|
119
|
+
* DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
prejoins?: {
|
|
123
|
+
mutualField: string;
|
|
124
|
+
targetEntityType: Entity;
|
|
125
|
+
entityPaths: {
|
|
126
|
+
skipCache?: boolean;
|
|
127
|
+
entityType: Entity;
|
|
128
|
+
processor?: (items: any[], context: Record<string, any>) => any;
|
|
129
|
+
}[];
|
|
130
|
+
}[];
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Use this function to perform side effects on the final schema for example refine/superRefine the schema
|
|
134
|
+
*
|
|
135
|
+
* @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)
|
|
136
|
+
* @returns void
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* effect: (schema) => {
|
|
141
|
+
* schema.refine(
|
|
142
|
+
* // refinement logic here
|
|
143
|
+
* )
|
|
144
|
+
* }
|
|
145
|
+
*/
|
|
146
|
+
effect?: (schema: z.ZodObject<z.ZodRawShape>) => z.ZodEffects<z.ZodObject<z.ZodRawShape>>;
|
|
147
|
+
/**
|
|
148
|
+
* @description (Optional) Use tags to create additional access patterns for the entity.
|
|
149
|
+
* Time complexity for retrieving tagged entities is O(1).
|
|
150
|
+
*
|
|
151
|
+
* The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.
|
|
152
|
+
* You would then be able to retrieve all organizations in a specific region by:
|
|
153
|
+
* GET `/core/tag/organization/region?group={region_name}`
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* {
|
|
159
|
+
* name: 'organization',
|
|
160
|
+
* tags: [
|
|
161
|
+
* {
|
|
162
|
+
* name: 'region',
|
|
163
|
+
* processor: (entity) => {
|
|
164
|
+
* return [
|
|
165
|
+
* {
|
|
166
|
+
* group: entity.data.region
|
|
167
|
+
* }
|
|
168
|
+
* ]
|
|
169
|
+
* },
|
|
170
|
+
* }
|
|
171
|
+
* ]
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @description
|
|
176
|
+
*
|
|
177
|
+
* The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.
|
|
178
|
+
* You would then be able to retrieve all users sorted by `dob` by:
|
|
179
|
+
* GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* {
|
|
184
|
+
* name: 'user',
|
|
185
|
+
* tags: [
|
|
186
|
+
* {
|
|
187
|
+
* name: 'dob',
|
|
188
|
+
* processor: (entity) => {
|
|
189
|
+
* return [
|
|
190
|
+
* {
|
|
191
|
+
* sortValue: entity.data.dob
|
|
192
|
+
* }
|
|
193
|
+
* ]
|
|
194
|
+
* },
|
|
195
|
+
* }
|
|
196
|
+
* ]
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
tags?: {
|
|
201
|
+
name: string;
|
|
202
|
+
processor: (entity: CreatedEntity<T>) => {
|
|
203
|
+
group?: string;
|
|
204
|
+
sortValue?: string;
|
|
205
|
+
}[];
|
|
206
|
+
}[];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
declare const createEntityConfig: <T extends Entity, B extends z.ZodRawShape, C extends z.ZodRawShape, M extends z.ZodRawShape, CO extends z.ZodObject<C> | undefined = undefined, MO extends z.ZodObject<M> | undefined = undefined>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) => {
|
|
210
|
+
finalSchema: (CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_3 ? { [k_2 in keyof T_3]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_4 ? { [k_3 in keyof T_4]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_5 ? { [k_4 in keyof T_5]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_6 ? { [k_5 in keyof T_6]: z.baseObjectInputType<B>[k_5]; } : never>) | z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_7 ? { [k in keyof T_7]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_8 ? { [k_1 in keyof T_8]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_9 ? { [k_2 in keyof T_9]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_10 ? { [k_3 in keyof T_10]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_11 ? { [k_4 in keyof T_11]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_12 ? { [k_5 in keyof T_12]: z.baseObjectInputType<B>[k_5]; } : never>, z.output<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_13 ? { [k in keyof T_13]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_14 ? { [k_1 in keyof T_14]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_15 ? { [k_2 in keyof T_15]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_16 ? { [k_3 in keyof T_16]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_17 ? { [k_4 in keyof T_17]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_18 ? { [k_5 in keyof T_18]: z.baseObjectInputType<B>[k_5]; } : never>>, z.input<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & CO["shape"], z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any> extends infer T_19 ? { [k in keyof T_19]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & CO["shape"]>, any>[k]; } : never, z.baseObjectInputType<MO["shape"] & CO["shape"]> extends infer T_20 ? { [k_1 in keyof T_20]: z.baseObjectInputType<MO["shape"] & CO["shape"]>[k_1]; } : never> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO["shape"] & B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any> extends infer T_21 ? { [k_2 in keyof T_21]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<MO["shape"] & B>, any>[k_2]; } : never, z.baseObjectInputType<MO["shape"] & B> extends infer T_22 ? { [k_3 in keyof T_22]: z.baseObjectInputType<MO["shape"] & B>[k_3]; } : never> : z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_23 ? { [k_4 in keyof T_23]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_24 ? { [k_5 in keyof T_24]: z.baseObjectInputType<B>[k_5]; } : never>>>;
|
|
211
|
+
name: string | T;
|
|
212
|
+
displayName: string;
|
|
213
|
+
authMethod?: {
|
|
214
|
+
email: {
|
|
215
|
+
tokenExpiresIn: number;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
baseSchema: z.ZodObject<B, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any> extends infer T_25 ? { [k_4 in keyof T_25]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<B>, any>[k_4]; } : never, z.baseObjectInputType<B> extends infer T_26 ? { [k_5 in keyof T_26]: z.baseObjectInputType<B>[k_5]; } : never>;
|
|
219
|
+
createSchema?: CO | undefined;
|
|
220
|
+
searchableFields?: (keyof B)[] | undefined;
|
|
221
|
+
uniqueFields?: (keyof B)[] | undefined;
|
|
222
|
+
mutual?: {
|
|
223
|
+
subscribes?: {
|
|
224
|
+
entityType: Entity;
|
|
225
|
+
}[];
|
|
226
|
+
mutualSchema: MO;
|
|
227
|
+
mutualFields: {
|
|
228
|
+
[key: string]: {
|
|
229
|
+
entityType: Entity;
|
|
230
|
+
toMutualIds?: (context: any) => string[];
|
|
231
|
+
mutualDataProcessor?: (mutualIds: string[], currentMutual: any, customContext?: Record<string, any>) => Record<string, any>;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
prejoins?: {
|
|
235
|
+
mutualField: string;
|
|
236
|
+
targetEntityType: Entity;
|
|
237
|
+
entityPaths: {
|
|
238
|
+
skipCache?: boolean;
|
|
239
|
+
entityType: Entity;
|
|
240
|
+
processor?: (items: any[], context: Record<string, any>) => any;
|
|
241
|
+
}[];
|
|
242
|
+
}[];
|
|
243
|
+
} | undefined;
|
|
244
|
+
effect?: (schema: z.ZodObject<z.ZodRawShape>) => z.ZodEffects<z.ZodObject<z.ZodRawShape>>;
|
|
245
|
+
tags?: {
|
|
246
|
+
name: string;
|
|
247
|
+
processor: (entity: undefined<T>) => {
|
|
248
|
+
group?: string;
|
|
249
|
+
sortValue?: string;
|
|
250
|
+
}[];
|
|
251
|
+
}[] | undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { type CreatedEntity, type DraftEntity, Entity, type EntitySchemaMap, type MonoriseEntityConfig, createEntityConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// types/monorise.type.ts
|
|
22
|
+
var Entity = /* @__PURE__ */ ((Entity2) => {
|
|
23
|
+
return Entity2;
|
|
24
|
+
})(Entity || {});
|
|
25
|
+
|
|
26
|
+
// utils/index.ts
|
|
27
|
+
import { z } from "zod";
|
|
28
|
+
function makeSchema(config) {
|
|
29
|
+
const { baseSchema, createSchema, mutual, effect } = config;
|
|
30
|
+
const { mutualSchema } = mutual || {};
|
|
31
|
+
const finalSchema = z.object(__spreadValues(__spreadValues(__spreadValues({}, baseSchema.shape), createSchema == null ? void 0 : createSchema.shape), mutualSchema == null ? void 0 : mutualSchema.shape));
|
|
32
|
+
if (effect) {
|
|
33
|
+
return effect(finalSchema);
|
|
34
|
+
}
|
|
35
|
+
return finalSchema;
|
|
36
|
+
}
|
|
37
|
+
var createEntityConfig = (config) => __spreadProps(__spreadValues({}, config), {
|
|
38
|
+
finalSchema: makeSchema(config)
|
|
39
|
+
});
|
|
40
|
+
export {
|
|
41
|
+
Entity,
|
|
42
|
+
createEntityConfig
|
|
43
|
+
};
|
|
6
44
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../types/monorise.type.ts","../utils/index.ts"],"sourcesContent":["import type { z } from 'zod';\n\nexport enum Entity {}\n\nexport interface EntitySchemaMap {\n [key: string]: Record<string, any>;\n}\n\nexport type DraftEntity<T extends Entity = Entity> =\n T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n\nexport type CreatedEntity<T extends Entity = Entity> = {\n entityId: string;\n entityType: string;\n data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;\n createdAt: string;\n updatedAt: string;\n};\n\n/**\n * @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.\n * This can be served as a single source of truth for the entity configuration.\n * It is used to define the schema, and mutual relationships between this entity and other entities.\n *\n * @example\n * ```ts\n * const baseSchema = z.object({\n * title: z.string(),\n * }).partial();\n *\n * const createSchema = baseSchema.extend({\n * title: z.string(),\n * })\n *\n * const config = createEntityConfig({\n * name: 'learner',\n * displayName: 'Learner',\n * baseSchema,\n * createSchema,\n * });\n * ```\n */\nexport interface MonoriseEntityConfig<\n T extends Entity = Entity,\n B extends z.ZodRawShape = z.ZodRawShape,\n C extends z.ZodRawShape = z.ZodRawShape,\n M extends z.ZodRawShape = z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n> {\n /**\n * @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities\n *\n * @example `learner`, `learning-activity`\n */\n name: string | T;\n\n /**\n * @description Display name of the entity. It is not required to be unique\n */\n displayName: string;\n\n /**\n * @description (DEPRECATED) Use `uniqueFields` instead, Monorise should not handle auth mechanism\n * @description (Optional) Specify the authentication method to be used for the entity\n */\n authMethod?: {\n /**\n * @description Authentication method using email\n *\n * Note: The email used for authentication is unique per entity.\n * For example, if `johndoe@mail.com` is used for `learner` entity,\n * it can be reused again on `admin` entity. However, the same email\n * address cannot be repeated for the same entity.\n */\n email: {\n /**\n * @description Number of milliseconds before the token expires\n */\n tokenExpiresIn: number;\n };\n };\n\n /**\n * @description Base schema for the entity\n */\n baseSchema: z.ZodObject<B>;\n\n /**\n * @description Minimal schema required to create an entity\n */\n createSchema?: CO;\n searchableFields?: (keyof B)[];\n uniqueFields?: (keyof B)[];\n\n /**\n * @description Define mutual relationship of this entity with other entities\n */\n mutual?: {\n /**\n * @description Subscribes to update events from specified entities in the array.\n * These events will be used to run prejoin processor.\n */\n subscribes?: { entityType: Entity }[];\n /**\n * @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database\n */\n mutualSchema: MO;\n\n /**\n * @description Keys of `mutualFields` are fields defined in `mutualSchema`.\n * Each field is a mutual relationship between this entity and another entity.\n */\n mutualFields: {\n [key: string]: {\n entityType: Entity;\n toMutualIds?: (context: any) => string[];\n /**\n * @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.\n *\n * @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.\n */\n mutualDataProcessor?: (\n mutualIds: string[],\n currentMutual: any,\n customContext?: Record<string, any>,\n ) => Record<string, any>;\n };\n };\n\n /**\n * @description (Optional) Better known as tree processor\n * This is used to prejoin entities that are not directly related as mutual.\n * For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,\n * prejoins can be used to join `learner` and `module` entities.\n * With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,\n * hence reducing the number of queries.\n *\n * DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html\n *\n */\n prejoins?: {\n mutualField: string;\n targetEntityType: Entity;\n entityPaths: {\n skipCache?: boolean;\n entityType: Entity;\n processor?: (items: any[], context: Record<string, any>) => any;\n }[];\n }[];\n };\n /**\n * Use this function to perform side effects on the final schema for example refine/superRefine the schema\n *\n * @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)\n * @returns void\n *\n * @example\n * ```ts\n * effect: (schema) => {\n * schema.refine(\n * // refinement logic here\n * )\n * }\n */\n effect?: (\n schema: z.ZodObject<z.ZodRawShape>,\n ) => z.ZodEffects<z.ZodObject<z.ZodRawShape>>;\n\n /**\n * @description (Optional) Use tags to create additional access patterns for the entity.\n * Time complexity for retrieving tagged entities is O(1).\n *\n * The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.\n * You would then be able to retrieve all organizations in a specific region by:\n * GET `/core/tag/organization/region?group={region_name}`\n *\n * @example\n *\n * ```ts\n * {\n * name: 'organization',\n * tags: [\n * {\n * name: 'region',\n * processor: (entity) => {\n * return [\n * {\n * group: entity.data.region\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n *\n * @description\n *\n * The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.\n * You would then be able to retrieve all users sorted by `dob` by:\n * GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`\n *\n * @example\n * ```ts\n * {\n * name: 'user',\n * tags: [\n * {\n * name: 'dob',\n * processor: (entity) => {\n * return [\n * {\n * sortValue: entity.data.dob\n * }\n * ]\n * },\n * }\n * ]\n * }\n * ```\n */\n tags?: {\n name: string;\n processor: (entity: CreatedEntity<T>) => {\n group?: string;\n sortValue?: string;\n }[];\n }[];\n}\n","import type { Entity, MonoriseEntityConfig } from '../types/monorise.type';\nimport { z } from 'zod';\n\nfunction makeSchema<\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(config: MonoriseEntityConfig<T, B, C, M, CO, MO>) {\n const { baseSchema, createSchema, mutual, effect } = config;\n const { mutualSchema } = mutual || {};\n\n type FinalSchemaType = CO extends z.AnyZodObject\n ? MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & CO['shape']>\n : CO\n : MO extends z.AnyZodObject\n ? z.ZodObject<MO['shape'] & B>\n : z.ZodObject<B>;\n\n const finalSchema = z.object({\n ...baseSchema.shape,\n ...createSchema?.shape,\n ...mutualSchema?.shape,\n }) as FinalSchemaType;\n\n if (effect) {\n return effect(finalSchema) as z.ZodEffects<FinalSchemaType>;\n }\n\n return finalSchema;\n}\n\nconst createEntityConfig = <\n T extends Entity,\n B extends z.ZodRawShape,\n C extends z.ZodRawShape,\n M extends z.ZodRawShape,\n CO extends z.ZodObject<C> | undefined = undefined,\n MO extends z.ZodObject<M> | undefined = undefined,\n>(\n config: MonoriseEntityConfig<T, B, C, M, CO, MO>,\n) => ({\n ...config,\n finalSchema: makeSchema(config),\n});\n\nexport { createEntityConfig };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEO,IAAK,SAAL,kBAAKA,YAAL;AAAK,SAAAA;AAAA,GAAA;;;ACDZ,SAAS,SAAS;AAElB,SAAS,WAOP,QAAkD;AAClD,QAAM,EAAE,YAAY,cAAc,QAAQ,OAAO,IAAI;AACrD,QAAM,EAAE,aAAa,IAAI,UAAU,CAAC;AAUpC,QAAM,cAAc,EAAE,OAAO,iDACxB,WAAW,QACX,6CAAc,QACd,6CAAc,MAClB;AAED,MAAI,QAAQ;AACV,WAAO,OAAO,WAAW;AAAA,EAC3B;AAEA,SAAO;AACT;AAEA,IAAM,qBAAqB,CAQzB,WACI,iCACD,SADC;AAAA,EAEJ,aAAa,WAAW,MAAM;AAChC;","names":["Entity"]}
|
package/package.json
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monorise/base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"directories": {
|
|
8
9
|
"lib": "lib"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
+
"build": "tsup",
|
|
13
|
+
"dev": "tsup --watch"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [],
|
|
14
16
|
"author": "",
|
|
15
17
|
"license": "ISC",
|
|
16
|
-
"
|
|
17
|
-
"zod": "^3.
|
|
18
|
-
}
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"zod": "^3.25.67"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
]
|
|
19
24
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,MAAM,EACN,eAAe,EACf,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,MAAM,EACN,eAAe,EACf,WAAW,EACX,aAAa,EACb,oBAAoB,GACrB,CAAC"}
|
package/dist/index.esm.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
export declare enum Entity {
|
|
3
|
-
}
|
|
4
|
-
export interface EntitySchemaMap {
|
|
5
|
-
[key: string]: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
export type DraftEntity<T extends Entity = Entity> = T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
8
|
-
export type CreatedEntity<T extends Entity = Entity> = {
|
|
9
|
-
entityId: string;
|
|
10
|
-
entityType: string;
|
|
11
|
-
data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
12
|
-
createdAt: string;
|
|
13
|
-
updatedAt: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.
|
|
17
|
-
* This can be served as a single source of truth for the entity configuration.
|
|
18
|
-
* It is used to define the schema, and mutual relationships between this entity and other entities.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const baseSchema = z.object({
|
|
23
|
-
* title: z.string(),
|
|
24
|
-
* }).partial();
|
|
25
|
-
*
|
|
26
|
-
* const createSchema = baseSchema.extend({
|
|
27
|
-
* title: z.string(),
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* const config = createEntityConfig({
|
|
31
|
-
* name: 'learner',
|
|
32
|
-
* displayName: 'Learner',
|
|
33
|
-
* baseSchema,
|
|
34
|
-
* createSchema,
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export interface MonoriseEntityConfig<T extends Entity = Entity, B extends z.ZodRawShape = z.ZodRawShape, C extends z.ZodRawShape = z.ZodRawShape, M extends z.ZodRawShape = z.ZodRawShape, CO extends z.ZodObject<C> | undefined = undefined, MO extends z.ZodObject<M> | undefined = undefined> {
|
|
39
|
-
/**
|
|
40
|
-
* @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities
|
|
41
|
-
*
|
|
42
|
-
* @example `learner`, `learning-activity`
|
|
43
|
-
*/
|
|
44
|
-
name: string | T;
|
|
45
|
-
/**
|
|
46
|
-
* @description Display name of the entity. It is not required to be unique
|
|
47
|
-
*/
|
|
48
|
-
displayName: string;
|
|
49
|
-
/**
|
|
50
|
-
* @description (Optional) Specify the authentication method to be used for the entity
|
|
51
|
-
*/
|
|
52
|
-
authMethod?: {
|
|
53
|
-
/**
|
|
54
|
-
* @description Authentication method using email
|
|
55
|
-
*
|
|
56
|
-
* Note: The email used for authentication is unique per entity.
|
|
57
|
-
* For example, if `johndoe@mail.com` is used for `learner` entity,
|
|
58
|
-
* it can be reused again on `admin` entity. However, the same email
|
|
59
|
-
* address cannot be repeated for the same entity.
|
|
60
|
-
*/
|
|
61
|
-
email: {
|
|
62
|
-
/**
|
|
63
|
-
* @description Number of milliseconds before the token expires
|
|
64
|
-
*/
|
|
65
|
-
tokenExpiresIn: number;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* @description Base schema for the entity
|
|
70
|
-
*/
|
|
71
|
-
baseSchema: z.ZodObject<B>;
|
|
72
|
-
/**
|
|
73
|
-
* @description Minimal schema required to create an entity
|
|
74
|
-
*/
|
|
75
|
-
createSchema?: CO;
|
|
76
|
-
searchableFields?: (keyof B)[];
|
|
77
|
-
/**
|
|
78
|
-
* @description Define mutual relationship of this entity with other entities
|
|
79
|
-
*/
|
|
80
|
-
mutual?: {
|
|
81
|
-
/**
|
|
82
|
-
* @description Subscribes to update events from specified entities in the array.
|
|
83
|
-
* These events will be used to run prejoin processor.
|
|
84
|
-
*/
|
|
85
|
-
subscribes?: {
|
|
86
|
-
entityType: Entity;
|
|
87
|
-
}[];
|
|
88
|
-
/**
|
|
89
|
-
* @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database
|
|
90
|
-
*/
|
|
91
|
-
mutualSchema: MO;
|
|
92
|
-
/**
|
|
93
|
-
* @description Keys of `mutualFields` are fields defined in `mutualSchema`.
|
|
94
|
-
* Each field is a mutual relationship between this entity and another entity.
|
|
95
|
-
*/
|
|
96
|
-
mutualFields: {
|
|
97
|
-
[key: string]: {
|
|
98
|
-
entityType: Entity;
|
|
99
|
-
toMutualIds?: (context: any) => string[];
|
|
100
|
-
/**
|
|
101
|
-
* @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.
|
|
102
|
-
*
|
|
103
|
-
* @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.
|
|
104
|
-
*/
|
|
105
|
-
mutualDataProcessor?: (mutualIds: string[], currentMutual: any, customContext?: Record<string, any>) => Record<string, any>;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* @description (Optional) Better known as tree processor
|
|
110
|
-
* This is used to prejoin entities that are not directly related as mutual.
|
|
111
|
-
* For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,
|
|
112
|
-
* prejoins can be used to join `learner` and `module` entities.
|
|
113
|
-
* With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,
|
|
114
|
-
* hence reducing the number of queries.
|
|
115
|
-
*
|
|
116
|
-
* DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
|
-
prejoins?: {
|
|
120
|
-
mutualField: string;
|
|
121
|
-
targetEntityType: Entity;
|
|
122
|
-
entityPaths: {
|
|
123
|
-
skipCache?: boolean;
|
|
124
|
-
entityType: Entity;
|
|
125
|
-
processor?: (items: any[], context: Record<string, any>) => any;
|
|
126
|
-
}[];
|
|
127
|
-
}[];
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Use this function to perform side effects on the final schema for example refine/superRefine the schema
|
|
131
|
-
*
|
|
132
|
-
* @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)
|
|
133
|
-
* @returns void
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```ts
|
|
137
|
-
* effect: (schema) => {
|
|
138
|
-
* schema.refine(
|
|
139
|
-
* // refinement logic here
|
|
140
|
-
* )
|
|
141
|
-
* }
|
|
142
|
-
*/
|
|
143
|
-
effect?: (schema: CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO['shape'] & CO['shape']> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO['shape'] & B> : z.ZodObject<B>) => z.ZodEffects<CO extends z.AnyZodObject ? MO extends z.AnyZodObject ? z.ZodObject<MO['shape'] & CO['shape']> : CO : MO extends z.AnyZodObject ? z.ZodObject<MO['shape'] & B> : z.ZodObject<B>>;
|
|
144
|
-
/**
|
|
145
|
-
* @description (Optional) Use tags to create additional access patterns for the entity.
|
|
146
|
-
* Time complexity for retrieving tagged entities is O(1).
|
|
147
|
-
*
|
|
148
|
-
* The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.
|
|
149
|
-
* You would then be able to retrieve all organizations in a specific region by:
|
|
150
|
-
* GET `/core/tag/organization/region?group={region_name}`
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
*
|
|
154
|
-
* ```ts
|
|
155
|
-
* {
|
|
156
|
-
* name: 'organization',
|
|
157
|
-
* tags: [
|
|
158
|
-
* {
|
|
159
|
-
* name: 'region',
|
|
160
|
-
* processor: (entity) => {
|
|
161
|
-
* return [
|
|
162
|
-
* {
|
|
163
|
-
* group: entity.data.region
|
|
164
|
-
* }
|
|
165
|
-
* ]
|
|
166
|
-
* },
|
|
167
|
-
* }
|
|
168
|
-
* ]
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* @description
|
|
173
|
-
*
|
|
174
|
-
* The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.
|
|
175
|
-
* You would then be able to retrieve all users sorted by `dob` by:
|
|
176
|
-
* GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* {
|
|
181
|
-
* name: 'user',
|
|
182
|
-
* tags: [
|
|
183
|
-
* {
|
|
184
|
-
* name: 'dob',
|
|
185
|
-
* processor: (entity) => {
|
|
186
|
-
* return [
|
|
187
|
-
* {
|
|
188
|
-
* sortValue: entity.data.dob
|
|
189
|
-
* }
|
|
190
|
-
* ]
|
|
191
|
-
* },
|
|
192
|
-
* }
|
|
193
|
-
* ]
|
|
194
|
-
* }
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
tags?: {
|
|
198
|
-
name: string;
|
|
199
|
-
processor: (entity: CreatedEntity<T>) => {
|
|
200
|
-
group?: string;
|
|
201
|
-
sortValue?: string;
|
|
202
|
-
}[];
|
|
203
|
-
}[];
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=monorise.type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"monorise.type.d.ts","sourceRoot":"","sources":["../../types/monorise.type.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"monorise.type.js","sourceRoot":"","sources":["../../types/monorise.type.ts"],"names":[],"mappings":";;;AAEA,IAAY,MAAS;AAArB,WAAY,MAAM;AAAE,CAAC,EAAT,MAAM,sBAAN,MAAM,QAAG"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Entity, EntitySchemaMap } from './monorise.type';
|
|
2
|
-
type MutualDataWithIndex = {
|
|
3
|
-
index: number;
|
|
4
|
-
};
|
|
5
|
-
interface MutualDataMapping {
|
|
6
|
-
}
|
|
7
|
-
type MutualData<B extends Entity, T extends Entity> = B extends keyof MutualDataMapping ? T extends keyof MutualDataMapping[B] ? MutualDataMapping[B][T] : Record<string, any> : Record<string, any>;
|
|
8
|
-
type Mutual<B extends Entity = Entity, T extends Entity = Entity> = {
|
|
9
|
-
entityId: string;
|
|
10
|
-
entityType: T;
|
|
11
|
-
byEntityId: string;
|
|
12
|
-
byEntityType: B;
|
|
13
|
-
mutualId: string;
|
|
14
|
-
data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
15
|
-
mutualData: MutualData<B, T> | Record<string, any>;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
updatedAt: string;
|
|
18
|
-
mutualUpdatedAt: string;
|
|
19
|
-
};
|
|
20
|
-
export type { MutualDataWithIndex, MutualDataMapping, MutualData, Mutual };
|
|
21
|
-
//# sourceMappingURL=mutual.type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutual.type.d.ts","sourceRoot":"","sources":["../../types/mutual.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/D,KAAK,mBAAmB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAGF,UAAU,iBAAiB;CAAG;AAE9B,KAAK,UAAU,CACb,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,IACd,CAAC,SAAS,MAAM,iBAAiB,GACjC,CAAC,SAAS,MAAM,iBAAiB,CAAC,CAAC,CAAC,GAClC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,CAAC,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,CAAC,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,CAAC,SAAS,MAAM,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACnE,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutual.type.js","sourceRoot":"","sources":["../../types/mutual.type.ts"],"names":[],"mappings":""}
|
package/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsconfig/node20/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
5
|
-
|
|
6
|
-
/* Projects */
|
|
7
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
8
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
9
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
10
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
11
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
12
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
13
|
-
|
|
14
|
-
/* Language and Environment */
|
|
15
|
-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
-
"jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
-
// "libReplacement": true, /* Enable lib replacement. */
|
|
19
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
20
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
21
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
22
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
23
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
24
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
25
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
26
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
27
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
28
|
-
|
|
29
|
-
/* Modules */
|
|
30
|
-
"module": "commonjs", /* Specify what module code is generated. */
|
|
31
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
32
|
-
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
33
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
34
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
35
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
36
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
37
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
38
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
39
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
40
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
41
|
-
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
42
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
43
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
44
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
45
|
-
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
46
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
47
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
48
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
49
|
-
|
|
50
|
-
/* JavaScript Support */
|
|
51
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
52
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
53
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
54
|
-
|
|
55
|
-
/* Emit */
|
|
56
|
-
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
57
|
-
"declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
58
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
59
|
-
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
60
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
61
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
62
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
63
|
-
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
64
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
65
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
66
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
67
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
68
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
69
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
70
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
71
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
72
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
73
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
74
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
75
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
76
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
77
|
-
|
|
78
|
-
/* Interop Constraints */
|
|
79
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
80
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
81
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
82
|
-
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
|
83
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
84
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
85
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
86
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
87
|
-
|
|
88
|
-
/* Type Checking */
|
|
89
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
90
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
91
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
92
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
93
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
94
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
95
|
-
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
96
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
97
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
98
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
99
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
100
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
101
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
102
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
103
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
104
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
105
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
106
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
107
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
108
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
109
|
-
|
|
110
|
-
/* Completeness */
|
|
111
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
112
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
113
|
-
}
|
|
114
|
-
}
|
package/types/monorise.type.ts
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export enum Entity {}
|
|
4
|
-
|
|
5
|
-
export interface EntitySchemaMap {
|
|
6
|
-
[key: string]: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type DraftEntity<T extends Entity = Entity> =
|
|
10
|
-
T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
11
|
-
|
|
12
|
-
export type CreatedEntity<T extends Entity = Entity> = {
|
|
13
|
-
entityId: string;
|
|
14
|
-
entityType: string;
|
|
15
|
-
data: T extends keyof EntitySchemaMap ? EntitySchemaMap[T] : never;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
updatedAt: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @description Configuration for a monorise entity, a shared configuration that is used across frontend and backend.
|
|
22
|
-
* This can be served as a single source of truth for the entity configuration.
|
|
23
|
-
* It is used to define the schema, and mutual relationships between this entity and other entities.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const baseSchema = z.object({
|
|
28
|
-
* title: z.string(),
|
|
29
|
-
* }).partial();
|
|
30
|
-
*
|
|
31
|
-
* const createSchema = baseSchema.extend({
|
|
32
|
-
* title: z.string(),
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* const config = createEntityConfig({
|
|
36
|
-
* name: 'learner',
|
|
37
|
-
* displayName: 'Learner',
|
|
38
|
-
* baseSchema,
|
|
39
|
-
* createSchema,
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export interface MonoriseEntityConfig<
|
|
44
|
-
T extends Entity = Entity,
|
|
45
|
-
B extends z.ZodRawShape = z.ZodRawShape,
|
|
46
|
-
C extends z.ZodRawShape = z.ZodRawShape,
|
|
47
|
-
M extends z.ZodRawShape = z.ZodRawShape,
|
|
48
|
-
CO extends z.ZodObject<C> | undefined = undefined,
|
|
49
|
-
MO extends z.ZodObject<M> | undefined = undefined,
|
|
50
|
-
> {
|
|
51
|
-
/**
|
|
52
|
-
* @description Name of the entity. Must be in **lower-kebab-case** and **unique** across all entities
|
|
53
|
-
*
|
|
54
|
-
* @example `learner`, `learning-activity`
|
|
55
|
-
*/
|
|
56
|
-
name: string | T;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @description Display name of the entity. It is not required to be unique
|
|
60
|
-
*/
|
|
61
|
-
displayName: string;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @description (Optional) Specify the authentication method to be used for the entity
|
|
65
|
-
*/
|
|
66
|
-
authMethod?: {
|
|
67
|
-
/**
|
|
68
|
-
* @description Authentication method using email
|
|
69
|
-
*
|
|
70
|
-
* Note: The email used for authentication is unique per entity.
|
|
71
|
-
* For example, if `johndoe@mail.com` is used for `learner` entity,
|
|
72
|
-
* it can be reused again on `admin` entity. However, the same email
|
|
73
|
-
* address cannot be repeated for the same entity.
|
|
74
|
-
*/
|
|
75
|
-
email: {
|
|
76
|
-
/**
|
|
77
|
-
* @description Number of milliseconds before the token expires
|
|
78
|
-
*/
|
|
79
|
-
tokenExpiresIn: number;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @description Base schema for the entity
|
|
85
|
-
*/
|
|
86
|
-
baseSchema: z.ZodObject<B>;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @description Minimal schema required to create an entity
|
|
90
|
-
*/
|
|
91
|
-
createSchema?: CO;
|
|
92
|
-
searchableFields?: (keyof B)[];
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @description Define mutual relationship of this entity with other entities
|
|
96
|
-
*/
|
|
97
|
-
mutual?: {
|
|
98
|
-
/**
|
|
99
|
-
* @description Subscribes to update events from specified entities in the array.
|
|
100
|
-
* These events will be used to run prejoin processor.
|
|
101
|
-
*/
|
|
102
|
-
subscribes?: { entityType: Entity }[];
|
|
103
|
-
/**
|
|
104
|
-
* @description Virtual schema for mutual relationship. The schema is only used for validation purpose, but these fields are not stored in the database
|
|
105
|
-
*/
|
|
106
|
-
mutualSchema: MO;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @description Keys of `mutualFields` are fields defined in `mutualSchema`.
|
|
110
|
-
* Each field is a mutual relationship between this entity and another entity.
|
|
111
|
-
*/
|
|
112
|
-
mutualFields: {
|
|
113
|
-
[key: string]: {
|
|
114
|
-
entityType: Entity;
|
|
115
|
-
toMutualIds?: (context: any) => string[];
|
|
116
|
-
/**
|
|
117
|
-
* @description (Optional) Custom function to process `mutualData`. If not provided, `mutualData` will be empty.
|
|
118
|
-
*
|
|
119
|
-
* @returns the final state of `mutualData` to be stored in the mutual record. Must be an object.
|
|
120
|
-
*/
|
|
121
|
-
mutualDataProcessor?: (
|
|
122
|
-
mutualIds: string[],
|
|
123
|
-
currentMutual: any,
|
|
124
|
-
customContext?: Record<string, any>,
|
|
125
|
-
) => Record<string, any>;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @description (Optional) Better known as tree processor
|
|
131
|
-
* This is used to prejoin entities that are not directly related as mutual.
|
|
132
|
-
* For example, if `learner` entity is related to `course` entity, and `course` entity is related to `module` entity,
|
|
133
|
-
* prejoins can be used to join `learner` and `module` entities.
|
|
134
|
-
* With this, the `learner` entity can access the `module` entity without having to go through the `course` entity,
|
|
135
|
-
* hence reducing the number of queries.
|
|
136
|
-
*
|
|
137
|
-
* DynamoDB best practices: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-normalization.html
|
|
138
|
-
*
|
|
139
|
-
*/
|
|
140
|
-
prejoins?: {
|
|
141
|
-
mutualField: string;
|
|
142
|
-
targetEntityType: Entity;
|
|
143
|
-
entityPaths: {
|
|
144
|
-
skipCache?: boolean;
|
|
145
|
-
entityType: Entity;
|
|
146
|
-
processor?: (items: any[], context: Record<string, any>) => any;
|
|
147
|
-
}[];
|
|
148
|
-
}[];
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Use this function to perform side effects on the final schema for example refine/superRefine the schema
|
|
152
|
-
*
|
|
153
|
-
* @param schema The final schema of the entity (the combination of `baseSchema`/`createSchema` and `mutualSchema` if specified)
|
|
154
|
-
* @returns void
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* effect: (schema) => {
|
|
159
|
-
* schema.refine(
|
|
160
|
-
* // refinement logic here
|
|
161
|
-
* )
|
|
162
|
-
* }
|
|
163
|
-
*/
|
|
164
|
-
effect?: (
|
|
165
|
-
schema: CO extends z.AnyZodObject
|
|
166
|
-
? MO extends z.AnyZodObject
|
|
167
|
-
? z.ZodObject<MO['shape'] & CO['shape']>
|
|
168
|
-
: CO
|
|
169
|
-
: MO extends z.AnyZodObject
|
|
170
|
-
? z.ZodObject<MO['shape'] & B>
|
|
171
|
-
: z.ZodObject<B>,
|
|
172
|
-
) => z.ZodEffects<
|
|
173
|
-
CO extends z.AnyZodObject
|
|
174
|
-
? MO extends z.AnyZodObject
|
|
175
|
-
? z.ZodObject<MO['shape'] & CO['shape']>
|
|
176
|
-
: CO
|
|
177
|
-
: MO extends z.AnyZodObject
|
|
178
|
-
? z.ZodObject<MO['shape'] & B>
|
|
179
|
-
: z.ZodObject<B>
|
|
180
|
-
>;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @description (Optional) Use tags to create additional access patterns for the entity.
|
|
184
|
-
* Time complexity for retrieving tagged entities is O(1).
|
|
185
|
-
*
|
|
186
|
-
* The following configuration will create a tag named `region` for the `organization` entity grouped by `region`.
|
|
187
|
-
* You would then be able to retrieve all organizations in a specific region by:
|
|
188
|
-
* GET `/core/tag/organization/region?group={region_name}`
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
*
|
|
192
|
-
* ```ts
|
|
193
|
-
* {
|
|
194
|
-
* name: 'organization',
|
|
195
|
-
* tags: [
|
|
196
|
-
* {
|
|
197
|
-
* name: 'region',
|
|
198
|
-
* processor: (entity) => {
|
|
199
|
-
* return [
|
|
200
|
-
* {
|
|
201
|
-
* group: entity.data.region
|
|
202
|
-
* }
|
|
203
|
-
* ]
|
|
204
|
-
* },
|
|
205
|
-
* }
|
|
206
|
-
* ]
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @description
|
|
211
|
-
*
|
|
212
|
-
* The following configuration will create a tag named `dob` for the `user` entity sorted by `dob`.
|
|
213
|
-
* You would then be able to retrieve all users sorted by `dob` by:
|
|
214
|
-
* GET `/core/tag/user/dob?start=2000-01-01&end=2020-12-31`
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* {
|
|
219
|
-
* name: 'user',
|
|
220
|
-
* tags: [
|
|
221
|
-
* {
|
|
222
|
-
* name: 'dob',
|
|
223
|
-
* processor: (entity) => {
|
|
224
|
-
* return [
|
|
225
|
-
* {
|
|
226
|
-
* sortValue: entity.data.dob
|
|
227
|
-
* }
|
|
228
|
-
* ]
|
|
229
|
-
* },
|
|
230
|
-
* }
|
|
231
|
-
* ]
|
|
232
|
-
* }
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
tags?: {
|
|
236
|
-
name: string;
|
|
237
|
-
processor: (entity: CreatedEntity<T>) => {
|
|
238
|
-
group?: string;
|
|
239
|
-
sortValue?: string;
|
|
240
|
-
}[];
|
|
241
|
-
}[];
|
|
242
|
-
}
|