@smartsoft001/models 1.1.90 → 2.21.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
@@ -1,7 +1,11 @@
1
- # shared-models
1
+ # models
2
2
 
3
3
  This library was generated with [Nx](https://nx.dev).
4
4
 
5
+ ## Building
6
+
7
+ Run `nx build models` to build the library.
8
+
5
9
  ## Running unit tests
6
10
 
7
- Run `nx test shared-models` to execute the unit tests.
11
+ Run `nx test models` to execute the unit tests via [Jest](https://jestjs.io).
package/index.cjs ADDED
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/shared/models/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Field: () => Field,
34
+ FieldDecorator: () => FieldDecorator,
35
+ FieldType: () => FieldType,
36
+ FieldTypeDef: () => FieldTypeDef,
37
+ Model: () => Model,
38
+ ModelDecorator: () => ModelDecorator,
39
+ SYMBOL_FIELD: () => SYMBOL_FIELD,
40
+ SYMBOL_MODEL: () => SYMBOL_MODEL,
41
+ castModel: () => castModel,
42
+ getInvalidFields: () => getInvalidFields,
43
+ getModelFieldKeys: () => getModelFieldKeys,
44
+ getModelFieldOptions: () => getModelFieldOptions,
45
+ getModelFieldsWithOptions: () => getModelFieldsWithOptions,
46
+ getModelOptions: () => getModelOptions,
47
+ isModel: () => isModel
48
+ });
49
+ module.exports = __toCommonJS(src_exports);
50
+
51
+ // packages/shared/models/src/lib/symbols.ts
52
+ var SYMBOL_MODEL = Symbol.for("smartsoft:model");
53
+ var SYMBOL_FIELD = Symbol.for("smartsoft:field");
54
+
55
+ // packages/shared/models/src/lib/interfaces.ts
56
+ var FieldTypeDef = /* @__PURE__ */ ((FieldTypeDef2) => {
57
+ FieldTypeDef2["address"] = "address";
58
+ FieldTypeDef2["currency"] = "currency";
59
+ FieldTypeDef2["date"] = "date";
60
+ FieldTypeDef2["dateTime"] = "dateTime";
61
+ FieldTypeDef2["dateWithEdit"] = "dateWithEdit";
62
+ FieldTypeDef2["email"] = "email";
63
+ FieldTypeDef2["enum"] = "enum";
64
+ FieldTypeDef2["file"] = "file";
65
+ FieldTypeDef2["flag"] = "flag";
66
+ FieldTypeDef2["int"] = "int";
67
+ FieldTypeDef2["nip"] = "nip";
68
+ FieldTypeDef2["object"] = "object";
69
+ FieldTypeDef2["array"] = "array";
70
+ FieldTypeDef2["password"] = "password";
71
+ FieldTypeDef2["radio"] = "radio";
72
+ FieldTypeDef2["text"] = "text";
73
+ FieldTypeDef2["strings"] = "strings";
74
+ FieldTypeDef2["ints"] = "ints";
75
+ FieldTypeDef2["longText"] = "longText";
76
+ FieldTypeDef2["color"] = "color";
77
+ FieldTypeDef2["logo"] = "logo";
78
+ FieldTypeDef2["check"] = "check";
79
+ FieldTypeDef2["phoneNumber"] = "phoneNumber";
80
+ FieldTypeDef2["phoneNumberPl"] = "phoneNumberPl";
81
+ FieldTypeDef2["pesel"] = "pesel";
82
+ FieldTypeDef2["pdf"] = "pdf";
83
+ FieldTypeDef2["video"] = "video";
84
+ FieldTypeDef2["attachment"] = "attachment";
85
+ FieldTypeDef2["dateRange"] = "dateRange";
86
+ FieldTypeDef2["image"] = "image";
87
+ FieldTypeDef2["float"] = "float";
88
+ return FieldTypeDef2;
89
+ })(FieldTypeDef || {});
90
+ var FieldType = FieldTypeDef;
91
+
92
+ // packages/shared/models/src/lib/decorators/model/model.decorator.ts
93
+ var import_reflect_metadata = require("reflect-metadata");
94
+ var Model = ModelDecorator;
95
+ function ModelDecorator(options) {
96
+ return function(target) {
97
+ options = options ? { ...options } : {};
98
+ Reflect.defineMetadata(SYMBOL_MODEL, options, target);
99
+ target.prototype.toJSON = function() {
100
+ const result = { ...this };
101
+ if (this.constructor["__properties"]) {
102
+ Object.keys(this.constructor["__properties"]).forEach((protoKey) => {
103
+ result[protoKey] = this["_" + protoKey];
104
+ });
105
+ }
106
+ return result;
107
+ };
108
+ };
109
+ }
110
+
111
+ // packages/shared/models/src/lib/decorators/field/field.decorator.ts
112
+ var import_reflect_metadata2 = require("reflect-metadata");
113
+
114
+ // packages/shared/utils/src/lib/services/password/password.service.ts
115
+ var md5_ = __toESM(require("md5"));
116
+
117
+ // packages/shared/utils/src/lib/services/object/object.service.ts
118
+ var import_flatted = require("flatted");
119
+ var ObjectService = class {
120
+ /***
121
+ * Create object with data
122
+ * @param data {object} - data to set
123
+ * @param type {type} - new type
124
+ * @return - new type object
125
+ */
126
+ static createByType(data, type) {
127
+ if (!data)
128
+ return data;
129
+ try {
130
+ if (data instanceof type)
131
+ return data;
132
+ } catch (e) {
133
+ console.warn(e);
134
+ }
135
+ const result = new type();
136
+ Object.keys(data).forEach((key) => {
137
+ result[key] = data[key];
138
+ });
139
+ return result;
140
+ }
141
+ /***
142
+ * Remove object type from data
143
+ * @param obj {object} - object
144
+ * @return - object without type
145
+ */
146
+ static removeTypes(obj) {
147
+ if (!obj)
148
+ return obj;
149
+ const result = {};
150
+ Object.keys(obj).forEach((key) => {
151
+ if (obj[key] && obj[key].constructor && !(obj[key] instanceof Date)) {
152
+ let stringValue = "";
153
+ try {
154
+ stringValue = JSON.stringify(obj[key]);
155
+ } catch (e) {
156
+ console.warn("can't stringify without circular package");
157
+ stringValue = (0, import_flatted.stringify)(obj[key]);
158
+ }
159
+ result[key] = JSON.parse(stringValue);
160
+ } else {
161
+ result[key] = obj[key];
162
+ }
163
+ });
164
+ return result;
165
+ }
166
+ };
167
+
168
+ // packages/shared/utils/src/lib/services/guid/guid.service.ts
169
+ var import_guid_typescript = require("guid-typescript");
170
+
171
+ // packages/shared/utils/src/lib/services/array/array.service.ts
172
+ var _ = __toESM(require("lodash"));
173
+
174
+ // packages/shared/models/src/lib/decorators/field/field.decorator.ts
175
+ var Field = FieldDecorator;
176
+ function FieldDecorator(options) {
177
+ return (target, key) => {
178
+ options = options ? { ...options } : {};
179
+ if (!target.constructor["__fields"]) {
180
+ target.constructor["__fields"] = {};
181
+ }
182
+ target.constructor["__fields"][key] = true;
183
+ if (!options.type && key === "password") {
184
+ options.type = FieldType.password;
185
+ } else if (!options.type) {
186
+ options.type = FieldType.text;
187
+ }
188
+ if (options.classType) {
189
+ target["_" + key] = target[key];
190
+ delete target[key];
191
+ Object.defineProperty(target, key, {
192
+ get: function() {
193
+ if (!this["_" + key] && options?.type === FieldType.array) {
194
+ this["_" + key] = [];
195
+ }
196
+ return this["_" + key];
197
+ },
198
+ set: function(v) {
199
+ this["_" + key] = options?.type === FieldType.array && v ? v.map((i) => ObjectService.createByType(i, options?.classType)) : ObjectService.createByType(v, options?.classType);
200
+ },
201
+ enumerable: true,
202
+ configurable: true
203
+ });
204
+ if (!target.constructor["__properties"]) {
205
+ target.constructor["__properties"] = {};
206
+ }
207
+ target.constructor["__properties"][key] = true;
208
+ }
209
+ Reflect.defineMetadata(SYMBOL_FIELD, options, target, key);
210
+ };
211
+ }
212
+
213
+ // packages/shared/models/src/lib/utils.ts
214
+ function getModelFieldKeys(type) {
215
+ if (!type["__fields"])
216
+ return [];
217
+ return Object.keys(type["__fields"]);
218
+ }
219
+ function getModelFieldOptions(instance, fieldKey) {
220
+ return Reflect.getMetadata(SYMBOL_FIELD, instance, fieldKey);
221
+ }
222
+ function getModelFieldsWithOptions(instance) {
223
+ const keys = getModelFieldKeys(instance.constructor);
224
+ return keys.map((item) => {
225
+ return {
226
+ key: item,
227
+ options: getModelFieldOptions(instance, item)
228
+ };
229
+ });
230
+ }
231
+ function getModelOptions(type) {
232
+ return Reflect.getMetadata(SYMBOL_MODEL, type);
233
+ }
234
+ function isModel(instance) {
235
+ if (!instance || !instance.constructor)
236
+ return false;
237
+ return Reflect.hasMetadata(SYMBOL_MODEL, instance.constructor);
238
+ }
239
+ function getInvalidFields(instance, mode, permissions) {
240
+ const result = [];
241
+ getModelFieldsWithOptions(instance).forEach(({ key, options }) => {
242
+ let required = options.required;
243
+ if ((mode === "create" || mode === "update") && options[mode] && options[mode]?.constructor) {
244
+ required = options[mode].required;
245
+ if (required && permissions && options[mode].permissions) {
246
+ required = options[mode]?.permissions?.some(
247
+ (op) => permissions.some((p) => p === op)
248
+ );
249
+ }
250
+ }
251
+ if (required && (instance[key] === null || instance[key] === void 0 || instance[key] === ""))
252
+ result.push(key);
253
+ });
254
+ return result;
255
+ }
256
+ function castModel(instance, mode, permissions) {
257
+ if (!isModel(instance))
258
+ return;
259
+ const fieldsWithOptions = getModelFieldsWithOptions(instance);
260
+ Object.keys(instance).filter((key) => key !== "id").forEach((key) => {
261
+ const fieldWidthOptions = fieldsWithOptions.find((f) => f.key === key);
262
+ if (!fieldWidthOptions) {
263
+ delete instance[key];
264
+ return;
265
+ }
266
+ if ((mode === "create" || mode === "update") && (!fieldWidthOptions.options[mode] || permissions && fieldWidthOptions.options[mode].permissions && !fieldWidthOptions.options[mode]?.permissions?.some(
267
+ (op) => permissions.some((p) => op === p)
268
+ ))) {
269
+ delete instance[key];
270
+ return;
271
+ } else if (mode !== "create" && mode !== "update" && (!fieldWidthOptions.options.customs || !fieldWidthOptions.options.customs.some((c) => c.mode === mode))) {
272
+ delete instance[key];
273
+ return;
274
+ }
275
+ });
276
+ }
277
+ // Annotate the CommonJS export names for ESM import in node:
278
+ 0 && (module.exports = {
279
+ Field,
280
+ FieldDecorator,
281
+ FieldType,
282
+ FieldTypeDef,
283
+ Model,
284
+ ModelDecorator,
285
+ SYMBOL_FIELD,
286
+ SYMBOL_MODEL,
287
+ castModel,
288
+ getInvalidFields,
289
+ getModelFieldKeys,
290
+ getModelFieldOptions,
291
+ getModelFieldsWithOptions,
292
+ getModelOptions,
293
+ isModel
294
+ });
package/package.json CHANGED
@@ -1,21 +1,17 @@
1
1
  {
2
2
  "name": "@smartsoft001/models",
3
- "version": "1.1.90",
3
+ "type": "commonjs",
4
4
  "dependencies": {
5
- "@angular/common": "16.1.3",
6
- "@angular/core": "16.1.3",
7
- "flatted": "^3.2.4",
8
- "guid-typescript": "1.0.9",
9
- "lodash": "^4.17.20",
10
- "md5": "2.3.0",
11
- "reflect-metadata": "0.1.13",
12
- "rxjs": "7.8.1"
5
+ "@smartsoft001/utils": "2.21.0",
6
+ "flatted": "3.2.9",
7
+ "guid-typescript": "^1.0.9",
8
+ "lodash": "4.17.21",
9
+ "md5": "^2.3.0",
10
+ "reflect-metadata": "^0.2.1",
11
+ "rxjs": "^7.8.1",
12
+ "tslib": "^2.3.0"
13
13
  },
14
- "peerDependencies": {
15
- "@smartsoft001/utils": "1.1.90",
16
- "util": "0.12.5",
17
- "tslib": "2.5.3"
18
- },
19
- "main": "./src/index.js",
20
- "types": "./src/index.d.ts"
14
+ "version": "2.21.0",
15
+ "main": "./index.cjs",
16
+ "typings": "./src/index.d.ts"
21
17
  }
package/src/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./lib/symbols";
2
- export * from './lib/interfaces';
3
- export * from './lib/decorators';
4
- export * from './lib/utils';
package/src/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/symbols"), exports);
5
- tslib_1.__exportStar(require("./lib/interfaces"), exports);
6
- tslib_1.__exportStar(require("./lib/decorators"), exports);
7
- tslib_1.__exportStar(require("./lib/utils"), exports);
8
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/shared/models/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,2DAAiC;AACjC,2DAAiC;AAEjC,sDAA4B"}
@@ -1,4 +0,0 @@
1
- import 'reflect-metadata';
2
- import { IFieldOptions } from "../../interfaces";
3
- export declare const Field: typeof FieldDecorator;
4
- export declare function FieldDecorator(options?: IFieldOptions): <T>(target: T, key: string) => void;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FieldDecorator = exports.Field = void 0;
4
- require("reflect-metadata");
5
- const utils_1 = require("@smartsoft001/utils");
6
- const symbols = require("../../symbols");
7
- const interfaces_1 = require("../../interfaces");
8
- exports.Field = FieldDecorator;
9
- function FieldDecorator(options) {
10
- return (target, key) => {
11
- options = options ? Object.assign({}, options) : {};
12
- if (!target.constructor['__fields']) {
13
- target.constructor['__fields'] = {};
14
- }
15
- target.constructor['__fields'][key] = true;
16
- if (!options.type && key === 'password') {
17
- options.type = interfaces_1.FieldType.password;
18
- }
19
- else if (!options.type) {
20
- options.type = interfaces_1.FieldType.text;
21
- }
22
- if (options.classType) {
23
- target['_' + key] = target[key];
24
- delete target[key];
25
- Object.defineProperty(target, key, {
26
- get: function () {
27
- if (!this['_' + key] && options.type === interfaces_1.FieldType.array) {
28
- this['_' + key] = [];
29
- }
30
- return this['_' + key];
31
- },
32
- set: function (v) {
33
- this['_' + key] = options.type === interfaces_1.FieldType.array && v ?
34
- v.map(i => utils_1.ObjectService.createByType(i, options.classType))
35
- : utils_1.ObjectService.createByType(v, options.classType);
36
- },
37
- enumerable: true,
38
- configurable: true
39
- });
40
- if (!target.constructor['__properties']) {
41
- target.constructor['__properties'] = {};
42
- }
43
- target.constructor['__properties'][key] = true;
44
- }
45
- Reflect.defineMetadata(symbols.SYMBOL_FIELD, options, target, key);
46
- };
47
- }
48
- exports.FieldDecorator = FieldDecorator;
49
- //# sourceMappingURL=field.decorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field.decorator.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/models/src/lib/decorators/field/field.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,+CAAkD;AAElD,yCAAyC;AACzC,iDAA0D;AAE7C,QAAA,KAAK,GAAG,cAAc,CAAC;AACpC,SAAgB,cAAc,CAAC,OAAuB;IAClD,OAAO,CAAI,MAAS,EAAE,GAAW,EAAE,EAAE;QAEjC,OAAO,GAAG,OAAO,CAAC,CAAC,mBAAM,OAAO,EAAG,CAAC,CAAC,EAAE,CAAC;QAExC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE;YACjC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;SACvC;QAED,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QAE3C,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,KAAK,UAAU,EAAE;YACrC,OAAO,CAAC,IAAI,GAAG,sBAAS,CAAC,QAAQ,CAAC;SACrC;aAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACtB,OAAO,CAAC,IAAI,GAAG,sBAAS,CAAC,IAAI,CAAC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vE,CAAC,CAAA;AACL,CAAC;AA9CD,wCA8CC"}
@@ -1,2 +0,0 @@
1
- export * from './model/model.decorator';
2
- export * from './field/field.decorator';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./model/model.decorator"), exports);
5
- tslib_1.__exportStar(require("./field/field.decorator"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/models/src/lib/decorators/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,kEAAwC"}
@@ -1,4 +0,0 @@
1
- import 'reflect-metadata';
2
- import { IModelOptions } from "../../interfaces";
3
- export declare const Model: typeof ModelDecorator;
4
- export declare function ModelDecorator(options?: IModelOptions): <T>(target: any) => void;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelDecorator = exports.Model = void 0;
4
- require("reflect-metadata");
5
- const symbols = require("../../symbols");
6
- exports.Model = ModelDecorator;
7
- function ModelDecorator(options) {
8
- return function (target) {
9
- options = options ? Object.assign({}, options) : {};
10
- Reflect.defineMetadata(symbols.SYMBOL_MODEL, options, target);
11
- target.prototype.toJSON = function () {
12
- const result = Object.assign({}, this);
13
- if (this.constructor['__properties']) {
14
- Object.keys(this.constructor['__properties']).forEach(protoKey => {
15
- result[protoKey] = this['_' + protoKey];
16
- });
17
- }
18
- return result;
19
- };
20
- };
21
- }
22
- exports.ModelDecorator = ModelDecorator;
23
- //# sourceMappingURL=model.decorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.decorator.js","sourceRoot":"","sources":["../../../../../../../../libs/shared/models/src/lib/decorators/model/model.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,yCAAyC;AAG5B,QAAA,KAAK,GAAG,cAAc,CAAC;AACpC,SAAgB,cAAc,CAAC,OAAuB;IACpD,OAAO,UAAY,MAAW;QAC5B,OAAO,GAAG,OAAO,CAAC,CAAC,mBAAM,OAAO,EAAG,CAAC,CAAC,EAAE,CAAC;QAExC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE9D,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;YACxB,MAAM,MAAM,qBAAQ,IAAI,CAAE,CAAC;YAE3B,IAAI,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE;gBACpC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;oBAC/D,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC;gBAC1C,CAAC,CAAC,CAAC;aACJ;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,CAAA;AACH,CAAC;AAlBD,wCAkBC"}
@@ -1,141 +0,0 @@
1
- import { Observable } from "rxjs";
2
- export declare enum FieldTypeDef {
3
- address = "address",
4
- currency = "currency",
5
- date = "date",
6
- dateTime = "dateTime",
7
- dateWithEdit = "dateWithEdit",
8
- email = "email",
9
- enum = "enum",
10
- file = "file",
11
- flag = "flag",
12
- int = "int",
13
- nip = "nip",
14
- object = "object",
15
- array = "array",
16
- password = "password",
17
- radio = "radio",
18
- text = "text",
19
- strings = "strings",
20
- ints = "ints",
21
- longText = "longText",
22
- color = "color",
23
- logo = "logo",
24
- check = "check",
25
- phoneNumber = "phoneNumber",
26
- phoneNumberPl = "phoneNumberPl",
27
- pesel = "pesel",
28
- pdf = "pdf",
29
- video = "video",
30
- attachment = "attachment",
31
- dateRange = "dateRange",
32
- image = "image",
33
- float = "float"
34
- }
35
- export declare const FieldType: typeof FieldTypeDef;
36
- export interface ISpecification {
37
- criteria: any;
38
- }
39
- export interface IModelFilter {
40
- label?: string;
41
- fieldType?: FieldTypeDef;
42
- key: string;
43
- type: '=' | '!=' | '>=' | '<=' | '<' | '>' | '~=';
44
- possibilities$?: Observable<{
45
- id: any;
46
- text: string;
47
- }[]>;
48
- }
49
- export interface IModelStep {
50
- number: number;
51
- name: string;
52
- }
53
- export interface IModelMetadata {
54
- titleKey?: string;
55
- permissions?: Array<string>;
56
- filters?: Array<IModelFilter>;
57
- }
58
- export interface IFieldMetadata extends IFieldModifyMetadata {
59
- type?: FieldTypeDef;
60
- classType?: any;
61
- possibilities?: Array<any> | any;
62
- }
63
- export interface IFieldModifyMetadata {
64
- required?: boolean;
65
- focused?: boolean;
66
- confirm?: boolean;
67
- permissions?: Array<string>;
68
- unique?: boolean | IFieldUniqueMetadata;
69
- defaltValue?: () => any;
70
- enabled?: ISpecification;
71
- hide?: boolean;
72
- /**
73
- * @desc - Model step configuration
74
- */
75
- step?: IModelStep;
76
- }
77
- export interface IFieldEditMetadata extends IFieldModifyMetadata {
78
- multi?: boolean;
79
- }
80
- export interface IFieldListMetadata {
81
- order?: number;
82
- filter?: boolean;
83
- permissions?: Array<string>;
84
- /**
85
- * Configuration for dynamic list table data
86
- * @param {string} dynamic.headerKey - column header object key
87
- * @param {string} dynamic.rowKey - column row value object key
88
- */
89
- dynamic?: {
90
- headerKey: string;
91
- rowKey: string;
92
- };
93
- }
94
- export interface IFieldDetailsMetadata {
95
- order?: number;
96
- permissions?: Array<string>;
97
- enabled?: ISpecification;
98
- }
99
- export interface IModelOptions {
100
- titleKey?: string;
101
- filters?: Array<IModelFilter>;
102
- create?: IModelModeOptions;
103
- update?: IModelModeOptions;
104
- list?: IModelModeOptions;
105
- details?: IModelModeOptions;
106
- remove?: IModelModeOptions;
107
- customs?: Array<IModelModeOptionsCustom>;
108
- /**
109
- * @desc - Allow export field data
110
- */
111
- export?: boolean;
112
- /**
113
- * @desc - Allow import field data
114
- */
115
- import?: boolean;
116
- }
117
- export interface IModelModeOptions {
118
- permissions?: Array<string>;
119
- enabled?: ISpecification;
120
- }
121
- export interface IModelModeOptionsCustom extends IModelModeOptions {
122
- mode: string;
123
- }
124
- export interface IFieldOptions extends IFieldMetadata {
125
- create?: IFieldModifyMetadata | boolean;
126
- update?: IFieldEditMetadata | boolean;
127
- list?: IFieldListMetadata | boolean;
128
- details?: IFieldDetailsMetadata | boolean;
129
- customs?: Array<IModelMetadataCustom>;
130
- search?: boolean;
131
- info?: string;
132
- }
133
- export interface IModelMetadataCustom extends IModelMetadata {
134
- mode: string;
135
- }
136
- export interface IFieldUniqueMetadata {
137
- withFields?: Array<string>;
138
- }
139
- export interface IFieldCustomMetadata extends IFieldModifyMetadata, IFieldListMetadata {
140
- mode: string;
141
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FieldType = exports.FieldTypeDef = void 0;
4
- var FieldTypeDef;
5
- (function (FieldTypeDef) {
6
- FieldTypeDef["address"] = "address";
7
- FieldTypeDef["currency"] = "currency";
8
- FieldTypeDef["date"] = "date";
9
- FieldTypeDef["dateTime"] = "dateTime";
10
- FieldTypeDef["dateWithEdit"] = "dateWithEdit";
11
- FieldTypeDef["email"] = "email";
12
- FieldTypeDef["enum"] = "enum";
13
- FieldTypeDef["file"] = "file";
14
- FieldTypeDef["flag"] = "flag";
15
- FieldTypeDef["int"] = "int";
16
- FieldTypeDef["nip"] = "nip";
17
- FieldTypeDef["object"] = "object";
18
- FieldTypeDef["array"] = "array";
19
- FieldTypeDef["password"] = "password";
20
- FieldTypeDef["radio"] = "radio";
21
- FieldTypeDef["text"] = "text";
22
- FieldTypeDef["strings"] = "strings";
23
- FieldTypeDef["ints"] = "ints";
24
- FieldTypeDef["longText"] = "longText";
25
- FieldTypeDef["color"] = "color";
26
- FieldTypeDef["logo"] = "logo";
27
- FieldTypeDef["check"] = "check";
28
- FieldTypeDef["phoneNumber"] = "phoneNumber";
29
- FieldTypeDef["phoneNumberPl"] = "phoneNumberPl";
30
- FieldTypeDef["pesel"] = "pesel";
31
- FieldTypeDef["pdf"] = "pdf";
32
- FieldTypeDef["video"] = "video";
33
- FieldTypeDef["attachment"] = "attachment";
34
- FieldTypeDef["dateRange"] = "dateRange";
35
- FieldTypeDef["image"] = "image";
36
- FieldTypeDef["float"] = "float";
37
- })(FieldTypeDef || (exports.FieldTypeDef = FieldTypeDef = {}));
38
- exports.FieldType = FieldTypeDef;
39
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../../libs/shared/models/src/lib/interfaces.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAgCX;AAhCD,WAAY,YAAY;IACpB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,6BAAa,CAAA;IACb,qCAAqB,CAAA;IACrB,6CAA6B,CAAA;IAC7B,+BAAe,CAAA;IACf,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,qCAAqB,CAAA;IACrB,+BAAe,CAAA;IACf,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,6BAAa,CAAA;IACb,qCAAqB,CAAA;IACrB,+BAAe,CAAA;IACf,6BAAa,CAAA;IACb,+BAAe,CAAA;IACf,2CAA2B,CAAA;IAC3B,+CAA+B,CAAA;IAC/B,+BAAe,CAAA;IACf,2BAAW,CAAA;IACX,+BAAe,CAAA;IACf,yCAAyB,CAAA;IACzB,uCAAuB,CAAA;IACvB,+BAAe,CAAA;IACf,+BAAe,CAAA;AACnB,CAAC,EAhCW,YAAY,4BAAZ,YAAY,QAgCvB;AACY,QAAA,SAAS,GAAwB,YAAY,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const SYMBOL_MODEL: unique symbol;
2
- export declare const SYMBOL_FIELD: unique symbol;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SYMBOL_FIELD = exports.SYMBOL_MODEL = void 0;
4
- exports.SYMBOL_MODEL = Symbol.for('smartsoft:model');
5
- exports.SYMBOL_FIELD = Symbol.for('smartsoft:field');
6
- //# sourceMappingURL=symbols.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../../../../../libs/shared/models/src/lib/symbols.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC7C,QAAA,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC"}
@@ -1,11 +0,0 @@
1
- import { IFieldOptions, IModelOptions } from "./interfaces";
2
- export declare function getModelFieldKeys<T>(type: T): Array<string>;
3
- export declare function getModelFieldOptions<T>(instance: T, fieldKey: string): IFieldOptions;
4
- export declare function getModelFieldsWithOptions<T>(instance: T): Array<{
5
- key: string;
6
- options: IFieldOptions;
7
- }>;
8
- export declare function getModelOptions(type: any): IModelOptions;
9
- export declare function isModel<T>(instance: T): boolean;
10
- export declare function getInvalidFields<T>(instance: T, mode: "create" | "update" | string, permissions: Array<string>): Array<string>;
11
- export declare function castModel<T>(instance: T, mode: "create" | "update" | string, permissions: Array<string>): void;
package/src/lib/utils.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.castModel = exports.getInvalidFields = exports.isModel = exports.getModelOptions = exports.getModelFieldsWithOptions = exports.getModelFieldOptions = exports.getModelFieldKeys = void 0;
4
- const symbols_1 = require("./symbols");
5
- function getModelFieldKeys(type) {
6
- if (!type["__fields"])
7
- return [];
8
- return Object.keys(type["__fields"]);
9
- }
10
- exports.getModelFieldKeys = getModelFieldKeys;
11
- function getModelFieldOptions(instance, fieldKey) {
12
- return Reflect.getMetadata(symbols_1.SYMBOL_FIELD, instance, fieldKey);
13
- }
14
- exports.getModelFieldOptions = getModelFieldOptions;
15
- function getModelFieldsWithOptions(instance) {
16
- const keys = getModelFieldKeys(instance.constructor);
17
- return keys.map((item) => {
18
- return {
19
- key: item,
20
- options: getModelFieldOptions(instance, item),
21
- };
22
- });
23
- }
24
- exports.getModelFieldsWithOptions = getModelFieldsWithOptions;
25
- function getModelOptions(type) {
26
- return Reflect.getMetadata(symbols_1.SYMBOL_MODEL, type);
27
- }
28
- exports.getModelOptions = getModelOptions;
29
- function isModel(instance) {
30
- if (!instance || !instance.constructor)
31
- return false;
32
- return Reflect.hasMetadata(symbols_1.SYMBOL_MODEL, instance.constructor);
33
- }
34
- exports.isModel = isModel;
35
- function getInvalidFields(instance, mode, permissions) {
36
- const result = [];
37
- getModelFieldsWithOptions(instance).forEach(({ key, options }) => {
38
- let required = options.required;
39
- if ((mode === "create" || mode === "update") &&
40
- options[mode] &&
41
- options[mode].constructor) {
42
- required = options[mode].required;
43
- if (required &&
44
- permissions &&
45
- options[mode].permissions) {
46
- required = options[mode].permissions.some((op) => permissions.some((p) => p === op));
47
- }
48
- }
49
- if (required && (instance[key] === null || instance[key] === undefined || instance[key] === ''))
50
- result.push(key);
51
- });
52
- return result;
53
- }
54
- exports.getInvalidFields = getInvalidFields;
55
- function castModel(instance, mode, permissions) {
56
- if (!isModel(instance))
57
- return;
58
- const fieldsWithOptions = getModelFieldsWithOptions(instance);
59
- Object.keys(instance)
60
- .filter((key) => key !== "id")
61
- .forEach((key) => {
62
- const fieldWidthOptions = fieldsWithOptions.find((f) => f.key === key);
63
- if (!fieldWidthOptions) {
64
- delete instance[key];
65
- return;
66
- }
67
- if ((mode === "create" || mode === "update") &&
68
- (!fieldWidthOptions.options[mode] ||
69
- (permissions &&
70
- fieldWidthOptions.options[mode].permissions &&
71
- !fieldWidthOptions.options[mode].permissions.some((op) => permissions.some((p) => op === p))))) {
72
- delete instance[key];
73
- return;
74
- }
75
- else if (mode !== "create" &&
76
- mode !== "update" &&
77
- (!fieldWidthOptions.options.customs ||
78
- !fieldWidthOptions.options.customs.some((c) => c.mode === mode))) {
79
- delete instance[key];
80
- return;
81
- }
82
- });
83
- }
84
- exports.castModel = castModel;
85
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../libs/shared/models/src/lib/utils.ts"],"names":[],"mappings":";;;AACA,uCAAuD;AAEvD,SAAgB,iBAAiB,CAAI,IAAO;IAC1C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AACvC,CAAC;AAHD,8CAGC;AAED,SAAgB,oBAAoB,CAClC,QAAW,EACX,QAAgB;IAEhB,OAAO,OAAO,CAAC,WAAW,CAAC,sBAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/D,CAAC;AALD,oDAKC;AAED,SAAgB,yBAAyB,CACvC,QAAW;IAEX,MAAM,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAErD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACvB,OAAO;YACL,GAAG,EAAE,IAAI;YACT,OAAO,EAAE,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC;SAC9C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAXD,8DAWC;AAED,SAAgB,eAAe,CAAC,IAAS;IACvC,OAAO,OAAO,CAAC,WAAW,CAAC,sBAAY,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC;AAFD,0CAEC;AAED,SAAgB,OAAO,CAAI,QAAW;IACpC,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IACrD,OAAO,OAAO,CAAC,WAAW,CAAC,sBAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;AACjE,CAAC;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@ -1 +0,0 @@
1
- //# sourceMappingURL=test-setup.js.map
package/test-setup.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../libs/shared/models/test-setup.ts"],"names":[],"mappings":""}