lemon-model 1.1.0 → 1.1.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.
|
@@ -59,7 +59,9 @@ export interface View {
|
|
|
59
59
|
*/
|
|
60
60
|
error?: string;
|
|
61
61
|
/**
|
|
62
|
-
* (optional) internal cores
|
|
62
|
+
* (optional) internal cores modifier info.
|
|
63
|
+
* - present if `hasCores` is true in `modelAsView()`
|
|
64
|
+
* - or can be shown only if model has cores data.
|
|
63
65
|
*/
|
|
64
66
|
readonly $?: Cores;
|
|
65
67
|
}
|
|
@@ -127,6 +129,12 @@ export declare abstract class AbstractTransformer<MyModel extends Model, MyView
|
|
|
127
129
|
* ex) `{ a:1, b: undefined }` -> `{ a:1 }`
|
|
128
130
|
*/
|
|
129
131
|
onlyDefined: <T extends object>(N?: T) => T;
|
|
132
|
+
/**
|
|
133
|
+
* transform the cores data
|
|
134
|
+
* @param cores the cores data to transform
|
|
135
|
+
* @returns transformed cores data or null
|
|
136
|
+
*/
|
|
137
|
+
asCore<T extends Cores>(cores?: T | null): T | null;
|
|
130
138
|
/**
|
|
131
139
|
* transform from model to view
|
|
132
140
|
*
|
|
@@ -35,28 +35,43 @@ class AbstractTransformer {
|
|
|
35
35
|
}, {})
|
|
36
36
|
: null;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* transform the cores data
|
|
40
|
+
* @param cores the cores data to transform
|
|
41
|
+
* @returns transformed cores data or null
|
|
42
|
+
*/
|
|
43
|
+
asCore(cores) {
|
|
44
|
+
if (!cores || typeof cores !== 'object')
|
|
45
|
+
return null;
|
|
46
|
+
const ret = {};
|
|
47
|
+
if (cores.sid !== undefined)
|
|
48
|
+
ret.sid = String(cores.sid);
|
|
49
|
+
if (cores.gid !== undefined)
|
|
50
|
+
ret.gid = String(cores.gid);
|
|
51
|
+
if (cores.uid !== undefined)
|
|
52
|
+
ret.uid = String(cores.uid);
|
|
53
|
+
return this.onlyDefined(ret);
|
|
54
|
+
}
|
|
38
55
|
/**
|
|
39
56
|
* transform from model to view
|
|
40
57
|
*
|
|
41
58
|
* @see Transformable.modelAsView
|
|
42
59
|
*/
|
|
43
60
|
modelAsView(model, hasCores) {
|
|
61
|
+
var _a;
|
|
44
62
|
if (!model || typeof model !== 'object')
|
|
45
63
|
return null;
|
|
46
|
-
const view = {
|
|
64
|
+
const view = this.onlyDefined({
|
|
65
|
+
$: (_a = model === null || model === void 0 ? void 0 : model.$) !== null && _a !== void 0 ? _a : undefined,
|
|
47
66
|
id: model.id,
|
|
48
67
|
createdAt: model.createdAt,
|
|
49
68
|
updatedAt: model.updatedAt,
|
|
50
69
|
deletedAt: model.deletedAt,
|
|
51
|
-
};
|
|
70
|
+
});
|
|
52
71
|
if (model.error)
|
|
53
72
|
view.error = model.error;
|
|
54
73
|
if (hasCores) {
|
|
55
|
-
const $ = this.
|
|
56
|
-
sid: model.sid,
|
|
57
|
-
gid: model.gid,
|
|
58
|
-
uid: model.uid,
|
|
59
|
-
});
|
|
74
|
+
const $ = this.asCore(model);
|
|
60
75
|
Object.assign(view, { $ });
|
|
61
76
|
}
|
|
62
77
|
return this.onlyDefined(view);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../src/cores/transformer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../src/cores/transformer.ts"],"names":[],"mappings":";;;AA4HA;;;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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