@lemoncloud/ssocio-stacks-api 0.23.313

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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @lemoncloud/ssocio-stacks-api
2
+
3
+ - 관리용 서비스 API
4
+
@@ -0,0 +1,175 @@
1
+ /**
2
+ * `abstract-controllers.ts`
3
+ * - pre-coded Model basic CRUD with backend-service and backend-proxy on GeneralWEBController.
4
+ *
5
+ * @author Albert <albert@lemoncloud.io>
6
+ * @date 2022-05-02 initial version
7
+ * @author Steve <steve@lemoncloud.io>
8
+ * @date 2022-06-21 optimized w/ `abstract-services`
9
+ * @date 2022-06-24 fixed some failures.
10
+ * @date 2022-06-28 supports `doGetList` w/ search-id.
11
+ * @date 2022-08-02 use `nextId()` w/ `manager.initialNo`.
12
+ * @date 2022-08-03 improved `transformer` w/ helpers.
13
+ * @date 2022-08-09 opt w/ `session-token` in CRUD.
14
+ * @date 2022-09-21 optimized the model management.
15
+ * @date 2022-11-09 param `isCreate` in `bodyToModel`, and support `GET /<type>/<cmd>/admin`
16
+ * @date 2022-11-11 cleanup and optimized names.
17
+ * @date 2022-12-29 optimized with `lemon-core@3.2.1`
18
+ * @date 2023-01-18 optimized with `lemon-core@3.2.4`
19
+ * @date 2023-01-20 optimized `doSearch()` w/ `SearchParam()`
20
+ * @date 2023-02-09 optimized `doPutBulk()`, and `doPostBulk()`
21
+ * @date 2023-02-13 optimized `doList()` to support `stereo` filter.
22
+ * @date 2023-02-15 optimized with `lemon-core@3.2.5`
23
+ *
24
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
25
+ */
26
+ import { NextContext } from 'lemon-core';
27
+ import { GeneralWEBController, NextHandler, SimpleSet } from 'lemon-core';
28
+ import { CoreModel, AbstractTransformer, View, Body } from 'lemon-model';
29
+ import { BulkBody, ListResult, PaginatedListResult, PaginateParam } from './types';
30
+ import { MyCoreManager, MyCoreService, MyCoreProxy } from './abstract-services';
31
+ export { CoreModel, AbstractTransformer };
32
+ /**
33
+ * type: `CRUDCreationOptions`
34
+ * - options for cunstructor.
35
+ */
36
+ interface CRUDCreationOptions {
37
+ /**
38
+ * (optional) flag to use `session-token` in CRUD
39
+ * - initialize this as `true` if required to use `session-token`
40
+ *
41
+ * @see proxy.getCurrenSession()
42
+ */
43
+ useSession?: boolean;
44
+ }
45
+ /**
46
+ * class: `AbstractCRUDController`
47
+ * - abstract high level class not to create directly.
48
+ */
49
+ export declare abstract class AbstractCRUDController<ModelType extends string, MyModel extends CoreModel<ModelType>, MyView extends View, MyBody extends Body, MyService extends MyCoreService<MyModel, ModelType, MyCoreProxy<ModelType, MyService>>, MyManager extends MyCoreManager<MyModel, ModelType, MyService>, MyTransformer extends AbstractTransformer<MyModel, MyView, MyBody>> extends GeneralWEBController {
50
+ /**
51
+ * service instances
52
+ */
53
+ protected readonly service: MyService;
54
+ /**
55
+ * namespace for log(print)
56
+ */
57
+ protected readonly logNS: string;
58
+ /**
59
+ * my model manager
60
+ */
61
+ protected readonly manager: MyManager;
62
+ /**
63
+ * transformer between model and view.
64
+ */
65
+ protected readonly transformer: MyTransformer;
66
+ /** options in creation */
67
+ protected readonly options?: CRUDCreationOptions;
68
+ /**
69
+ * get the manager's type (= model-type)
70
+ */
71
+ get modelType(): ModelType;
72
+ /**
73
+ * get config of using session.
74
+ */
75
+ get confUseSession(): boolean;
76
+ /**
77
+ * model transformer from model to view
78
+ */
79
+ modelAsView(model: MyModel, useOnlyDefined?: boolean): MyView;
80
+ /**
81
+ * model transformer from body to body
82
+ */
83
+ bodyToModel(body: MyBody, isCreate?: boolean): MyModel;
84
+ /**
85
+ * from `session-token`, make base of model { sid, uid }
86
+ * @param proxy the current proxy.
87
+ * @returns base model
88
+ */
89
+ protected makeModelBase(proxy: MyCoreProxy<ModelType, any>): Promise<MyModel>;
90
+ /** load yml as model list */
91
+ loadMockData<T extends object>(name: string, base?: string): Promise<T[]>;
92
+ /**
93
+ * load mock-model from `.yml` file.
94
+ */
95
+ loadFromFile(file: string): Promise<MyModel & {
96
+ list: any[];
97
+ }>;
98
+ /**
99
+ * public constructor
100
+ *
101
+ * @param type - api controller's type name (ex: tests for `/tests`)
102
+ * @param service - backend service
103
+ * @param manager - my model manager in backend-service
104
+ * @param transformer - GeneralCRUDWEBControllerOptions
105
+ */
106
+ constructor(type: string, service: MyService, manager: MyManager, transformer: MyTransformer, options?: CRUDCreationOptions);
107
+ /**
108
+ * say hello
109
+ */
110
+ hello: () => string;
111
+ /**
112
+ * GET /<typeName>
113
+ * - list types
114
+ *
115
+ * ```sh
116
+ * $ http ':8888/<typeName>'
117
+ */
118
+ doList: NextHandler<PaginateParam & SimpleSet, PaginatedListResult<MyView>>;
119
+ /**
120
+ * list types by id
121
+ * - id means the search(query) id to use.
122
+ *
123
+ * ```sh
124
+ * $ http ':8888/<typeName>/<id>/list'
125
+ */
126
+ doGetList: NextHandler<PaginateParam & SimpleSet, PaginatedListResult<MyView>>;
127
+ /**
128
+ * internal admin command
129
+ */
130
+ doGetAdmin: NextHandler;
131
+ /**
132
+ * read a `MyModel`
133
+ *
134
+ * ```sh
135
+ * $ http ':8888/<typeName>/1'
136
+ */
137
+ doGet: NextHandler<any, MyView>;
138
+ /**
139
+ * create(or insert) a `MyModel`
140
+ * - `id` must be emptry (or '0')
141
+ *
142
+ * ```sh
143
+ * $ http POST ':8888/<typeName>/0' "key"="modelValue"
144
+ */
145
+ doPost(id: string, param: any, body: MyBody, $ctx?: NextContext): Promise<MyView>;
146
+ /**
147
+ * create(or insert) multi `MyModel`
148
+ * - `id` must be emptry (or '0')
149
+ *
150
+ * ```sh
151
+ * $ http POST ':8888/<typeName>/0/bulk' "key"="modelValue"
152
+ */
153
+ doPostBulk: NextHandler<any, MyView[], BulkBody<MyBody> | MyBody[]>;
154
+ /**
155
+ * update a `MyModel`
156
+ *
157
+ * ```sh
158
+ * $ http PUT ':8888/<typeName>/1000002' name="test-update"
159
+ */
160
+ doPut: NextHandler<any, MyView, MyBody>;
161
+ /**
162
+ * delete a `MyModel`
163
+ *
164
+ * ```sh
165
+ * $ http DELETE ':8888/<typeName>/1000003'
166
+ */
167
+ doDelete: NextHandler<any, MyView>;
168
+ /**
169
+ * bulk update a `TypeModel`
170
+ *
171
+ * ```sh
172
+ * $ http PUT ':8888/types/0/bulk'
173
+ */
174
+ doPutBulk: NextHandler<any, ListResult<MyView>, BulkBody<MyBody> | MyBody[]>;
175
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * `abstract-rest-api.ts`
3
+ * - support the rest-api pattern w/ remote service.
4
+ *
5
+ *
6
+ * @author Steve <steve@lemoncloud.io>
7
+ * @date 2022-09-21 optimized w/ `abstract-rest-apis`
8
+ *
9
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
10
+ */
11
+ import { NextContext } from 'lemon-core';
12
+ import { Reversable } from 'lemon-model';
13
+ import { PaginatedListResult, PaginateParam } from './types';
14
+ export { Reversable };
15
+ /**
16
+ * support rest-api from remote service.
17
+ * - useful to use the common CRUD RestAPI.
18
+ */
19
+ export declare class RestAPI<View extends object = any, Body = View, Model = View> {
20
+ readonly context: NextContext;
21
+ readonly endpoint: string;
22
+ readonly _reverser?: Reversable<Model, View, Body>;
23
+ readonly options?: {
24
+ isProd?: boolean;
25
+ };
26
+ constructor(context: NextContext, endpoint: string, _reverser?: Reversable<Model, View, Body>, options?: {
27
+ isProd?: boolean;
28
+ });
29
+ protected asProtocol(id?: string, cmd?: string): {
30
+ hello: () => string;
31
+ asTargetUrl: () => string;
32
+ execute: <T = any>(param?: any, body?: any, mode?: string) => Promise<T>;
33
+ enqueue: <T_1 = any>(param?: any, body?: any, mode?: string, callback?: string, delaySeconds?: number) => Promise<string>;
34
+ notify: (param?: any, body?: any, mode?: string, callback?: string) => Promise<string>;
35
+ };
36
+ /** get the current transform (may throw error) */
37
+ get reverser(): Reversable<Model, View, Body>;
38
+ /** say hello */
39
+ hello: () => string;
40
+ /** list model as view */
41
+ list: <T extends PaginateParam>(param?: T) => Promise<PaginatedListResult<View>>;
42
+ /** read model as view */
43
+ read: (id: string, param?: any) => Promise<View>;
44
+ /** insert model w/ body w/o id */
45
+ insert: (body: Body, param?: any) => Promise<View>;
46
+ /** update model w/ body by id */
47
+ update: (id: string, body: Body, param?: any) => Promise<View>;
48
+ /** delete model by id */
49
+ delete: (id: string, param?: any) => Promise<View>;
50
+ /** enqueue vis SQS */
51
+ enqueue: (params: {
52
+ id?: string;
53
+ cmd?: string;
54
+ mode?: string;
55
+ param?: any;
56
+ body?: any;
57
+ }, delay?: number) => Promise<string>;
58
+ /** execute vis API */
59
+ execute: <T = any>(params: {
60
+ id?: string;
61
+ cmd?: string;
62
+ mode?: string;
63
+ param?: any;
64
+ body?: any;
65
+ }) => Promise<T>;
66
+ /**
67
+ * set by model.
68
+ */
69
+ set: (id: string, model: Model) => Promise<Model>;
70
+ /**
71
+ * get by id
72
+ */
73
+ get: (id: string, throwable?: boolean) => Promise<Model>;
74
+ /**
75
+ * make new (w/ auto id)
76
+ */
77
+ new: (model: Model) => Promise<Model>;
78
+ /**
79
+ * delete (w/ auto id)
80
+ */
81
+ del: (id: string) => Promise<Model>;
82
+ }
83
+ /**
84
+ * rest-api for dummy
85
+ * - save model in memory.
86
+ */
87
+ export declare class DummyRestAPI<View = any, Body = View, Model = View> extends RestAPI {
88
+ readonly context: NextContext;
89
+ readonly endpoint: string;
90
+ readonly _reverser?: Reversable<Model, View, Body>;
91
+ initialNo: number;
92
+ constructor(context: NextContext, endpoint: string, _reverser?: Reversable<Model, View, Body>, initialNo?: number);
93
+ /** say hello */
94
+ hello: () => string;
95
+ /** internal dummy memory */
96
+ protected $buf: {
97
+ [key: string]: any;
98
+ };
99
+ read: (id: string, param?: any) => Promise<View>;
100
+ insert: (body: any, param?: any) => Promise<View>;
101
+ update: (id: string, body: any, param?: any) => Promise<View>;
102
+ delete: (id: string, param?: any) => Promise<View>;
103
+ }
104
+ /**
105
+ * factory to create `rest-api` instance for both real and dummy.
106
+ */
107
+ export declare const $createApi: <View extends object = object, Body_1 = View, Model = View>($context: NextContext, endpoint: string, reversor?: Reversable<Model, View, Body_1>, options?: {
108
+ isProd?: boolean;
109
+ isDummy?: boolean;
110
+ initialNo?: number;
111
+ }) => RestAPI<View, Body_1, Model>;
@@ -0,0 +1,220 @@
1
+ import { CoreManager, CoreModel, CoreService, SearchBody, ManagerProxy, AbstractProxy, NextContext, NextIdentityCognito, SortTerm, SimpleSet, SearchResult } from 'lemon-core';
2
+ import { SessionToken } from '../service/backend-types';
3
+ import { ListResult, PaginateParam } from './types';
4
+ export declare type SearchParam<T> = T & {
5
+ [key: string]: string | number;
6
+ };
7
+ /**
8
+ * class: `MyCoreService`
9
+ * - CoreService의 공통 부분을 채워넣는다.
10
+ */
11
+ export declare abstract class MyCoreService<Model extends CoreModel<ModelType>, ModelType extends string, Proxy extends MyCoreProxy<ModelType, any>> extends CoreService<Model, ModelType> {
12
+ constructor(tableName?: string, ns?: string);
13
+ /**
14
+ * make proxy instance w/ this service.
15
+ */
16
+ abstract createProxy(context: NextContext): Proxy;
17
+ /**
18
+ * make proxy, and use callback to handle.
19
+ * - it will save automatically.
20
+ */
21
+ guardProxy: <T>(context: NextContext, callback: (proxy: Proxy) => Promise<T>) => Promise<T>;
22
+ /**
23
+ * run search
24
+ * - override this to hide `$ES6`
25
+ */
26
+ doSearch<T>(body: SearchBody): Promise<SearchResult<T>>;
27
+ }
28
+ /**
29
+ * class: `CoreManager`
30
+ * - shared core manager for all model
31
+ *
32
+ * @abstract
33
+ */
34
+ export declare abstract class MyCoreManager<Model extends CoreModel<ModelType>, ModelType extends string, Service extends MyCoreService<Model, ModelType, any>> extends CoreManager<Model, ModelType, Service> {
35
+ readonly options?: {
36
+ /** initial next-id number of auto-seq (default 1000000) */
37
+ initialNo?: number;
38
+ };
39
+ /**
40
+ * namespace for log(print)
41
+ */
42
+ protected readonly logNS: string;
43
+ /**
44
+ * constructor
45
+ * @protected
46
+ */
47
+ protected constructor(type: ModelType, parent: Service, fields: string[], uniqueField?: string, options?: {
48
+ /** initial next-id number of auto-seq (default 1000000) */
49
+ initialNo?: number;
50
+ });
51
+ nextId(): Promise<number>;
52
+ /**
53
+ * build default model for creation.
54
+ */
55
+ buildDefault(id: string): Model;
56
+ /**
57
+ * validate the request's model before saving.
58
+ * - `$org`에 따라서, 신규 생성인지 업데이트인지 구분 가능함.
59
+ *
60
+ * @param model request's model
61
+ * @param $org (optional) the origin model (valid ONLY if 업데이트)
62
+ * @returns validatated model.
63
+ */
64
+ validateModel(model: Model, $org?: Model): Promise<Model>;
65
+ /**
66
+ * find lookup-model (improved @2022)
67
+ * - lookup to `auto-id` by key.
68
+ * - if not exits, make the new id (auto-seq) and store the key.
69
+ * - type should be like `#<type>`.
70
+ *
71
+ * NOTE! must to support race condition.
72
+ *
73
+ * @param key any string
74
+ */
75
+ findLookup$(key: string | number, params?: {
76
+ /** rate to reset lock (default 0.9) */
77
+ resetRate?: number;
78
+ /** flag to use sha256 for hash (default true) */
79
+ useSha256?: boolean;
80
+ /** use meta to save lookup info (default false) */
81
+ isUseMeta?: boolean;
82
+ /** throw if lookup is not found (default false) - useful to check if exists of key */
83
+ throwable?: boolean;
84
+ }): Promise<Model>;
85
+ /**
86
+ * build search query from filters
87
+ */
88
+ buildQuery<T extends Model>(param: PaginateParam, model?: SearchParam<T>): SearchBody;
89
+ /**
90
+ * basic ElasticSearch Query.
91
+ * you can override this method for customization.
92
+ *
93
+ * @param limit pagination limit (default 10)
94
+ * @param page page number (starts from 0)
95
+ * @param filters model filters
96
+ * @param param (optional) addtion params
97
+ */
98
+ list($page: PaginateParam, $param?: SearchParam<Model>): Promise<ListResult<Model>>;
99
+ /**
100
+ * list of projection fields
101
+ * - ONLY fields defined in `goods-model`
102
+ * - 모델별 추가 필드목록만 추림
103
+ */
104
+ listProjections(params?: {
105
+ includes?: string[];
106
+ excludes?: string[];
107
+ sorted?: boolean;
108
+ }): string[];
109
+ /**
110
+ * fetch all list of goods for filtering.
111
+ *
112
+ * @override if required.
113
+ */
114
+ buildSearchAll(params?: {
115
+ size?: number;
116
+ }, sort?: SortTerm): SearchBody;
117
+ }
118
+ /**
119
+ * class: `MyCoreProxy`
120
+ * - common parent of proxy.
121
+ */
122
+ export declare class MyCoreProxy<U extends string, MyService extends MyCoreService<CoreModel<U>, U, any>> extends AbstractProxy<U, MyService> {
123
+ readonly managerProxies: {
124
+ [propKey: string]: MyManagerProxy<any, any, MyService>;
125
+ };
126
+ constructor(context: NextContext, service: MyService, cacheScope?: string);
127
+ /**
128
+ * register this.
129
+ */
130
+ register(mgr: MyManagerProxy<any, any, MyService>): number;
131
+ /**
132
+ * add into proxy lookup.
133
+ */
134
+ protected addManagerProxy(modelType: U, proxy: MyManagerProxy<any, any, MyService>): void;
135
+ /**
136
+ * get from lookup table.
137
+ */
138
+ getManagerProxy<Model, ModelManager extends MyCoreManager<Model, U, MyService>>(modelType: U): MyManagerProxy<Model, ModelManager, MyService>;
139
+ /**
140
+ * get the `session-token` from current req-context.
141
+ * - 1차 호출(front에서) 에서는 이 세션이 꼭 필요함.
142
+ * - 2차 호출(protocol이용) 에서는 선택사항으로, 조절가능해야함! (#TODO - 이걸 어떻게 구불할것인가?)
143
+ * - 로컬) 로컬 개발에서는 시뮬레이션 방법은 #TODO
144
+ *
145
+ * @param options.throwable flag to throw (default true)
146
+ */
147
+ getCurrenSession(options?: {
148
+ throwable?: boolean;
149
+ }): SessionToken;
150
+ /**
151
+ * find the current identity-id from context.
152
+ * - or, use env[LOCAL_ACCOUNT]
153
+ */
154
+ asCurrentIdentityId: (context?: NextContext) => string | null;
155
+ /**
156
+ * prepare `next-context` w/ the customized { domain, userAgent }
157
+ * @param identityId the target identity-id
158
+ */
159
+ asNextContext(identityId: string, params?: {
160
+ domain?: string;
161
+ userAgent?: string;
162
+ }): NextContext<NextIdentityCognito<any>>;
163
+ }
164
+ /**
165
+ * class: `MyProxy`
166
+ * - common parent of manager-proxy.
167
+ */
168
+ export declare class MyManagerProxy<MyModel extends CoreModel<ModelType>, MyManager extends MyCoreManager<MyModel, ModelType, MyService>, MyService extends MyCoreService<MyModel, ModelType, any>, ModelType extends string = string> extends ManagerProxy<MyModel, MyManager, ModelType> {
169
+ readonly proxy: MyCoreProxy<ModelType, MyService>;
170
+ constructor(proxy: MyCoreProxy<ModelType, MyService>, mgr: MyManager);
171
+ /**
172
+ * @override the default `normal()` to support _name.
173
+ */
174
+ normal: (N: MyModel) => MyModel;
175
+ /**
176
+ * pack the query parameter for list
177
+ * - `param` has the string values only including '', '!'
178
+ * - `model` has the valid data type. (number | string | ... )
179
+ *
180
+ * ```ts
181
+ * let model = bodyToModel(param)
182
+ * ```
183
+ *
184
+ * @param param the original query parameter.
185
+ * @param model the transformed model from `param`.
186
+ * @param options (optional)
187
+ * @returns
188
+ */
189
+ packSearchParam(param: SimpleSet, model?: MyModel, options?: {
190
+ /** flag to use session-token (default false) */
191
+ useSession?: boolean;
192
+ }): {
193
+ $page: PaginateParam;
194
+ $param: SearchParam<MyModel>;
195
+ };
196
+ /**
197
+ * override this to validate request'body.
198
+ * @param model model from request.
199
+ * @param modelId (optional) modelId if to update the target model.
200
+ * @return validated model to save.
201
+ */
202
+ validateModel<T extends MyModel>(model: T, modelId?: string): Promise<T>;
203
+ /**
204
+ * callback before saving model.
205
+ * - could change field before saving.
206
+ *
207
+ * @param model the last model to save
208
+ * @param $org (optional) original model (null if create)
209
+ */
210
+ onBeforeSave(model: MyModel, $org?: MyModel): Promise<MyModel>;
211
+ /**
212
+ * create new model
213
+ * - use `.id` or `nextId()` for model-id
214
+ * - validate model in seperate way before using this.
215
+ *
216
+ * @param model creation model
217
+ * @param validate (optional) flag to validate (default is true)
218
+ */
219
+ makeModel(model: MyModel, validate?: boolean): Promise<MyModel>;
220
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `commons.ts`
3
+ * - common tools to export.
4
+ *
5
+ * @author Steve <steve@lemoncloud.io>
6
+ * @date 2022-11-01 optimized w/ `commons`
7
+ *
8
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
9
+ */
10
+ import { ListParam, PaginateParam } from './types';
11
+ /**
12
+ * extract only the defined attribute.
13
+ * ex) `{ a:1, b: undefined }` -> `{ a:1 }`
14
+ */
15
+ export declare const onlyDefined: <T>(N: T) => T;
16
+ /**
17
+ * list param parser
18
+ * @param param
19
+ */
20
+ export declare function parseListParam(param?: ListParam, $def?: {
21
+ limit?: number;
22
+ }): Required<ListParam>;
23
+ /**
24
+ * paginate param parser
25
+ */
26
+ export declare function parsePaginateParam(param?: PaginateParam,
27
+ /** default value or conditions */
28
+ options?: {
29
+ noLimit?: boolean;
30
+ limit?: number;
31
+ page?: number;
32
+ }): PaginateParam;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `index.ts`
3
+ * - shared export in `/cores`
4
+ *
5
+ * @author Steve <steve@lemoncloud.io>
6
+ * @date 2022-06-21 optimized w/ `abstract-services`
7
+ *
8
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
9
+ */
10
+ export * from './types';
11
+ export * from './commons';
12
+ export * from './abstract-services';
13
+ export * from './abstract-controllers';
14
+ export * from './abstract-rest-apis';
@@ -0,0 +1,108 @@
1
+ /**
2
+ * `types.ts`
3
+ * - common types used in `/cores`
4
+ *
5
+ * @author Steve <steve@lemoncloud.io>
6
+ * @date 2022-06-21 optimized w/ `abstract-services`
7
+ * @date 2022-06-28 added `Codable` interface for general types.
8
+ * @date 2023-01-18 optimized with `lemon-core@3.2.4`
9
+ * @date 2023-02-15 optimized with `lemon-core@3.2.5`
10
+ *
11
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
12
+ */
13
+ import { CoreModel, View, Body } from 'lemon-model';
14
+ export { CoreModel, View, Body };
15
+ /**
16
+ * type `ListResult`
17
+ */
18
+ export interface ListResult<T, R = string> {
19
+ /**
20
+ * total searched count
21
+ */
22
+ total?: number;
23
+ /**
24
+ * max items count in the page
25
+ */
26
+ limit?: number;
27
+ /**
28
+ * current page number.
29
+ */
30
+ page?: number;
31
+ /**
32
+ * items searched
33
+ */
34
+ list: T[];
35
+ /**
36
+ * (optional) aggr list
37
+ */
38
+ aggr?: R[];
39
+ }
40
+ export interface AggrKeyCount {
41
+ /** name of key(or bucket name) */
42
+ key: string;
43
+ /** number of count */
44
+ val: number;
45
+ }
46
+ /**
47
+ * type `PaginatedListResult`
48
+ */
49
+ export interface PaginatedListResult<T> extends ListResult<T> {
50
+ /**
51
+ * current page
52
+ */
53
+ page: number;
54
+ }
55
+ /**
56
+ * type `ListParam`
57
+ */
58
+ export interface ListParam {
59
+ /**
60
+ * max items count to be fetched
61
+ */
62
+ limit?: number;
63
+ /**
64
+ * (optional) sorting order
65
+ * - 'asc': older first
66
+ * - 'desc': newer first
67
+ * - string: extended sorting features
68
+ */
69
+ sort?: 'asc' | 'desc' | string;
70
+ }
71
+ /**
72
+ * type `PaginateParam`
73
+ */
74
+ export interface PaginateParam extends ListParam {
75
+ /**
76
+ * page # to fetch (0-indexed)
77
+ */
78
+ page?: number;
79
+ /**
80
+ * (optional) flag to filter by uid
81
+ */
82
+ uid?: string;
83
+ }
84
+ /**
85
+ * type `BulkUpdateBody`
86
+ */
87
+ export interface BulkUpdateBody<T> extends BulkBody<T> {
88
+ /**
89
+ * list bulk update model with id
90
+ */
91
+ list: T[];
92
+ }
93
+ /**
94
+ * body data for bulk
95
+ */
96
+ export interface BulkBody<T> {
97
+ list: T[];
98
+ }
99
+ /**
100
+ * list of the selected model-id
101
+ */
102
+ export interface BodyList<T extends {
103
+ id: string;
104
+ } = {
105
+ id: string;
106
+ }> {
107
+ list: T[];
108
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `lib/categories-types.ts`
3
+ * - types for category support
4
+ *
5
+ *
6
+ * @author Steve <steve@lemoncloud.io>
7
+ * @date 2022-10-18 initial version
8
+ *
9
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
10
+ */
11
+ import { GenericNode } from './types';
12
+ /**
13
+ * type: `CategoryNode`
14
+ * - represent a single node of category tree.
15
+ * - node should have single parent's node.
16
+ */
17
+ export interface CategoryNode extends GenericNode {
18
+ /** category-id */
19
+ id?: string;
20
+ /** this name */
21
+ name?: string;
22
+ /** id of parent node */
23
+ parent?: string;
24
+ /** name of parent node */
25
+ parentName?: string;
26
+ /** current depth (= parent.depth + 1) */
27
+ depth?: number;
28
+ /**
29
+ * the node path from root to node
30
+ * - list of [[id, name].join(':'),...]
31
+ */
32
+ paths?: string[];
33
+ }