lemon-model 1.0.5 → 1.1.0

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 CHANGED
@@ -4,9 +4,10 @@ Common shared model definitions for both `backend` and `frontend`.
4
4
 
5
5
  ## Usage
6
6
 
7
- To develop backend-api, use [lemon-core](https://github.com/lemoncloud-io/lemon-core) instead of this.
7
+ !TIP! to develop `backend` api, use [lemon-core](https://github.com/lemoncloud-io/lemon-core) instead of this.
8
8
 
9
9
  ```sh
10
+ # install with npm
10
11
  npm install --save lemon-model
11
12
  ```
12
13
 
@@ -22,10 +23,11 @@ See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md)
22
23
 
23
24
  ----------------
24
25
 
25
- # VERSION INFO
26
+ ## VERSION INFO
26
27
 
27
28
  | Version | Description
28
29
  |-- |--
30
+ | 1.0.6 | optimized `SearchBody` with `knn` support.
29
31
  | 1.0.5 | optimized `NextIdentity` with `authorization`.
30
32
  | 1.0.4 | optimized `NextIdentity` with `referer` and `origin`.
31
33
  | 1.0.3 | optimized `NextIdentityCognito`
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @copyright (C) 2023 LemonCloud Co Ltd. - All Rights Reserved.
10
10
  */
11
- import { CoreModel } from '../types/core-storage';
11
+ import { CoreModel, CoreModifier } from '../types/core-storage';
12
12
  /**
13
13
  * internal type `Model`
14
14
  */
@@ -16,7 +16,7 @@ declare type Model = CoreModel<string>;
16
16
  /**
17
17
  * partial set of `CoreModel`
18
18
  */
19
- export interface Cores {
19
+ export interface Cores extends Partial<CoreModifier> {
20
20
  /**
21
21
  * site-id of model
22
22
  * - inited by `identity-token` if use session
@@ -126,13 +126,13 @@ export declare abstract class AbstractTransformer<MyModel extends Model, MyView
126
126
  * extract only the defined attribute.
127
127
  * ex) `{ a:1, b: undefined }` -> `{ a:1 }`
128
128
  */
129
- onlyDefined: <T extends object>(N: T) => T;
129
+ onlyDefined: <T extends object>(N?: T) => T;
130
130
  /**
131
131
  * transform from model to view
132
132
  *
133
133
  * @see Transformable.modelAsView
134
134
  */
135
- modelAsView(model: MyModel, hasCores?: boolean): MyView;
135
+ modelAsView(model?: MyModel | null, hasCores?: boolean): MyView;
136
136
  /**
137
137
  * transform from body(req-body) to model
138
138
  *
@@ -25,13 +25,15 @@ class AbstractTransformer {
25
25
  * extract only the defined attribute.
26
26
  * ex) `{ a:1, b: undefined }` -> `{ a:1 }`
27
27
  */
28
- this.onlyDefined = (N) => N && typeof N === 'object'
29
- ? Object.entries(N).reduce((N, [k, v]) => {
30
- if (v !== undefined)
31
- N[k] = v;
32
- return N;
33
- }, {})
34
- : null;
28
+ this.onlyDefined = (N) => N === undefined || N === null
29
+ ? N
30
+ : N && typeof N === 'object'
31
+ ? Object.entries(N).reduce((N, [k, v]) => {
32
+ if (v !== undefined)
33
+ N[k] = v;
34
+ return N;
35
+ }, {})
36
+ : null;
35
37
  }
36
38
  /**
37
39
  * transform from model to view
@@ -1 +1 @@
1
- {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../src/cores/transformer.ts"],"names":[],"mappings":";;;AA0HA;;;GAGG;AACH,MAAsB,mBAAmB;IAAzC;QAGI;;;;;WAKG;QACI,WAAM,GAAG,CAAC,GAAW,EAAE,KAAK,GAAG,MAAM,EAAE,EAAE;YAC5C,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;YAC/C,MAAM,EAAE,GAAG,mDAAmD,CAAC;YAC/D,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,gCAAgC,CAAC,CAAC;YACrF,OAAO,GAAG,CAAC;QACf,CAAC,CAAC;QAEF;;;WAGG;QACI,gBAAW,GAAG,CAAmB,CAAI,EAAE,EAAE,CAC5C,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;YACtB,CAAC,CAAC,MAAM,C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AAkB;QACzD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACrD,MAAM,IAAI,GAAS;YACf,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;SAC7B,CAAC;QACF,IAAI,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC1C,IAAI,QAAQ,EAAE;YACV,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAQ;gBAC9B,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,GAAG,EAAE,KAAK,CAAC,GAAG;aACjB,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC,WAAW,CAAS,IAAc,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,IAAkB,EAAE,QAAkB;;QACrD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACnD,MAAM,KAAK,GAAG,EAAa,CAAC;QAE5B,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,MAAK,SAAS;YAAE,KAAK,CAAC,EAAE,GAAG,GAAG,MAAA,IAAI,CAAC,EAAE,mCAAI,EAAE,EAAE,CAAC;QAE1D,OAAO,KAAgB,CAAC;IAC5B,CAAC;CACJ;AApED,kDAoEC"}
@@ -32,11 +32,29 @@ export interface StorageModel extends InternalKey {
32
32
  /** json formated string (or parsed object). */
33
33
  meta?: string | any;
34
34
  }
35
+ /**
36
+ * class: `CoreModifier`
37
+ * - common modifier information for core-model
38
+ */
39
+ export interface CoreModifier {
40
+ /**
41
+ * site-id
42
+ */
43
+ sid?: string;
44
+ /**
45
+ * user-id
46
+ */
47
+ uid?: string;
48
+ /**
49
+ * group-id
50
+ */
51
+ gid?: string;
52
+ }
35
53
  /**
36
54
  * class: `InternalModel`
37
55
  * - common internal properties. (ONLY FOR INTERNAL PROCESSING)
38
56
  */
39
- export interface InternalModel {
57
+ export interface InternalModel extends CoreModifier {
40
58
  /**
41
59
  * internal unique partition-key (valid if using default idName )
42
60
  */
@@ -47,6 +65,11 @@ export interface InternalModel {
47
65
  * - general model out of base Model to support the common usage
48
66
  */
49
67
  export interface CoreModel<ModelType extends string = string> extends StorageModel, InternalModel {
68
+ /**
69
+ * the last modifier info
70
+ * - set automatically when model is created/updated/deleted.
71
+ */
72
+ readonly $?: CoreModifier;
50
73
  /**
51
74
  * namespace
52
75
  */
@@ -14,7 +14,20 @@
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CORE_FIELDS = void 0;
16
16
  //NOTE! - BE WARE TO USE `ts-transformer-keys` DUE TO MISSING `ttypescript`
17
- // export const CORE_FIELDS: string[] = keys<CoreModel>().filter(_ => !_.startsWith('_'));
18
- // _inf(NS, '! CORE_FIELDS =', CORE_FIELDS.join(', ')); // for debugging.
19
- exports.CORE_FIELDS = 'ns,type,stereo,sid,uid,gid,lock,next,meta,createdAt,updatedAt,deletedAt'.split(',');
17
+ exports.CORE_FIELDS = [
18
+ '$',
19
+ 'ns',
20
+ 'type',
21
+ 'stereo',
22
+ 'sid',
23
+ 'uid',
24
+ 'gid',
25
+ 'lock',
26
+ 'next',
27
+ 'meta',
28
+ 'createdAt',
29
+ 'updatedAt',
30
+ 'deletedAt',
31
+ 'error',
32
+ ];
20
33
  //# sourceMappingURL=core-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-storage.js","sourceRoot":"","sources":["../../src/types/core-storage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAgGH,2EAA2E;AAC3E,0FAA0F;AAC1F,yEAAyE;AAC5D,QAAA,WAAW,GAAa,yEAAyE,CAAC,KAAK,CAChH,GAAG,CACN,CAAC"}
1
+ {"version":3,"file":"core-storage.js","sourceRoot":"","sources":["../../src/types/core-storage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAwHH,2EAA2E;AAC9D,QAAA,WAAW,GAAa;IACjC,GAAG;IACH,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,WAAW;IACX,WAAW;IACX,WAAW;IACX,OAAO;CACV,CAAC"}
@@ -9,6 +9,7 @@
9
9
  * @date 2021-12-07 support SearchBody
10
10
  * @date 2024-12-20 optimized `NextIdentityCognito`
11
11
  * @date 2025-05-13 optimized `NextContext` with `Authorization` header
12
+ * @date 2025-06-12 optimized `SearchBody` with `knn` support
12
13
  *
13
14
  * @copyright (C) lemoncloud.io 2019 - All Rights Reserved.
14
15
  */
@@ -295,7 +296,9 @@ export interface QueryResult<T> {
295
296
  last?: any;
296
297
  }
297
298
  /**
298
- * 쿼리의 각 항목의 값들
299
+ * type: `QueryTerm`
300
+ * - query term for search.
301
+ * - it should be compartible with elastic-search.
299
302
  */
300
303
  export declare type QueryTerm = string | number | string[] | number[] | {
301
304
  query: string | number | string[] | number[];
@@ -310,7 +313,9 @@ export declare type QueryTerm = string | number | string[] | number[] | {
310
313
  };
311
314
  };
312
315
  /**
313
- * 정렬(sort)에 쓰이는 항목.
316
+ * type: `SortTerm`
317
+ * - sort term for search.
318
+ * - it should be compartible with elastic-search.
314
319
  */
315
320
  export declare type SortTerm = string | {
316
321
  [key: string]: 'asc' | 'desc';
@@ -321,7 +326,9 @@ export declare type SortTerm = string | {
321
326
  };
322
327
  };
323
328
  /**
324
- * 검색 쿼리 항목.
329
+ * type: `SearchQuery`
330
+ * - search query for elastic-search.
331
+ * - it should be compartible with elastic-search.
325
332
  */
326
333
  export interface SearchQuery {
327
334
  term?: {
@@ -358,6 +365,26 @@ export interface SearchQuery {
358
365
  should?: SearchQuery | SearchQuery[];
359
366
  minimum_should_match?: number;
360
367
  };
368
+ /** required to have mapping type: `knn_vector` */
369
+ knn?: {
370
+ /** field (ex: `vector$.sm3`) to query */
371
+ [field: string]: {
372
+ vector: number[];
373
+ /** The number of nearest neighbors to return */
374
+ k?: number;
375
+ max_distance?: number;
376
+ min_score?: number;
377
+ filter?: SearchQuery;
378
+ method_parameters?: {
379
+ ef_search?: number;
380
+ nprobes?: number;
381
+ };
382
+ rescore?: {
383
+ oversample_factor?: number;
384
+ } | boolean;
385
+ expand_nested_docs?: boolean;
386
+ };
387
+ };
361
388
  query_string?: {
362
389
  query: string;
363
390
  };
@@ -10,6 +10,7 @@
10
10
  * @date 2021-12-07 support SearchBody
11
11
  * @date 2024-12-20 optimized `NextIdentityCognito`
12
12
  * @date 2025-05-13 optimized `NextContext` with `Authorization` header
13
+ * @date 2025-06-12 optimized `SearchBody` with `knn` support
13
14
  *
14
15
  * @copyright (C) lemoncloud.io 2019 - All Rights Reserved.
15
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"core-types.js","sourceRoot":"","sources":["../../src/types/core-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG"}
1
+ {"version":3,"file":"core-types.js","sourceRoot":"","sources":["../../src/types/core-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lemon-model",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "Common shared model definitions for Lemon Micro-Service Platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",