@quatrain/core 0.1.6

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.
Files changed (71) hide show
  1. package/lib/Core.d.ts +16 -0
  2. package/lib/Core.js +30 -0
  3. package/lib/backends/AbstractAdapter.d.ts +49 -0
  4. package/lib/backends/AbstractAdapter.js +30 -0
  5. package/lib/backends/BackendError.d.ts +2 -0
  6. package/lib/backends/BackendError.js +6 -0
  7. package/lib/backends/Filter.d.ts +15 -0
  8. package/lib/backends/Filter.js +14 -0
  9. package/lib/backends/FilterOperators.d.ts +13 -0
  10. package/lib/backends/FilterOperators.js +16 -0
  11. package/lib/backends/Filters.d.ts +10 -0
  12. package/lib/backends/Filters.js +14 -0
  13. package/lib/backends/Limits.d.ts +9 -0
  14. package/lib/backends/Limits.js +10 -0
  15. package/lib/backends/MockAdapter.d.ts +24 -0
  16. package/lib/backends/MockAdapter.js +81 -0
  17. package/lib/backends/Query.d.ts +24 -0
  18. package/lib/backends/Query.js +72 -0
  19. package/lib/backends/SortAndLimit.d.ts +11 -0
  20. package/lib/backends/SortAndLimit.js +11 -0
  21. package/lib/backends/Sorting.d.ts +9 -0
  22. package/lib/backends/Sorting.js +10 -0
  23. package/lib/backends/index.d.ts +10 -0
  24. package/lib/backends/index.js +21 -0
  25. package/lib/common/statuses.d.ts +11 -0
  26. package/lib/common/statuses.js +14 -0
  27. package/lib/components/AbstractObject.d.ts +23 -0
  28. package/lib/components/AbstractObject.js +64 -0
  29. package/lib/components/BaseObject.d.ts +16 -0
  30. package/lib/components/BaseObject.js +73 -0
  31. package/lib/components/BaseObjectProperties.d.ts +15 -0
  32. package/lib/components/BaseObjectProperties.js +82 -0
  33. package/lib/components/DataObject.d.ts +83 -0
  34. package/lib/components/DataObject.js +209 -0
  35. package/lib/components/ObjectUri.d.ts +42 -0
  36. package/lib/components/ObjectUri.js +112 -0
  37. package/lib/components/User.d.ts +6 -0
  38. package/lib/components/User.js +56 -0
  39. package/lib/components/index.d.ts +7 -0
  40. package/lib/components/index.js +16 -0
  41. package/lib/index.d.ts +17 -0
  42. package/lib/index.js +66 -0
  43. package/lib/properties/BaseProperty.d.ts +34 -0
  44. package/lib/properties/BaseProperty.js +57 -0
  45. package/lib/properties/BooleanProperty.d.ts +6 -0
  46. package/lib/properties/BooleanProperty.js +10 -0
  47. package/lib/properties/DateTimeProperty.d.ts +10 -0
  48. package/lib/properties/DateTimeProperty.js +17 -0
  49. package/lib/properties/EnumProperty.d.ts +9 -0
  50. package/lib/properties/EnumProperty.js +18 -0
  51. package/lib/properties/HashProperty.d.ts +20 -0
  52. package/lib/properties/HashProperty.js +48 -0
  53. package/lib/properties/NumberProperty.d.ts +36 -0
  54. package/lib/properties/NumberProperty.js +75 -0
  55. package/lib/properties/ObjectProperty.d.ts +16 -0
  56. package/lib/properties/ObjectProperty.js +25 -0
  57. package/lib/properties/Property.d.ts +16 -0
  58. package/lib/properties/Property.js +49 -0
  59. package/lib/properties/StringProperty.d.ts +27 -0
  60. package/lib/properties/StringProperty.js +73 -0
  61. package/lib/properties/index.d.ts +15 -0
  62. package/lib/properties/index.js +21 -0
  63. package/lib/properties/types/AbstractPropertyType.d.ts +5 -0
  64. package/lib/properties/types/AbstractPropertyType.js +2 -0
  65. package/lib/properties/types/PropertyClassType.d.ts +4 -0
  66. package/lib/properties/types/PropertyClassType.js +2 -0
  67. package/lib/properties/types/PropertyTypes.d.ts +2 -0
  68. package/lib/properties/types/PropertyTypes.js +2 -0
  69. package/lib/statuses.d.ts +10 -0
  70. package/lib/statuses.js +13 -0
  71. package/package.json +28 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringProperty = void 0;
4
+ const Property_1 = require("./Property");
5
+ const BaseProperty_1 = require("./BaseProperty");
6
+ class StringProperty extends BaseProperty_1.BaseProperty {
7
+ constructor(config) {
8
+ super(config);
9
+ this._minLength = 0;
10
+ this._maxLength = 0;
11
+ /**
12
+ * Set to false to bypass some rules
13
+ */
14
+ this._rawValue = true;
15
+ this.minLength = config.minLength || 0;
16
+ this.maxLength = config.maxLength || 0;
17
+ if (this._enable(config.allowSpaces)) {
18
+ this._allows.push(Property_1.Property.ALLOW_SPACES);
19
+ }
20
+ if (this._enable(config.allowDigits)) {
21
+ this._allows.push(Property_1.Property.ALLOW_DIGITS);
22
+ }
23
+ if (this._enable(config.allowLetters)) {
24
+ this._allows.push(Property_1.Property.ALLOW_LETTERS);
25
+ }
26
+ }
27
+ set(value) {
28
+ if (this._allows.includes(Property_1.Property.ALLOW_DIGITS) === false &&
29
+ /\d/.test(value)) {
30
+ throw new Error(`Digits are not allowed in value`);
31
+ }
32
+ if (this._allows.includes(Property_1.Property.ALLOW_SPACES) === false &&
33
+ /\s/g.test(value)) {
34
+ throw new Error(`Spaces are not allowed in value`);
35
+ }
36
+ if (this._allows.includes(Property_1.Property.ALLOW_LETTERS) === false &&
37
+ /[a-zA-Z]/.test(value)) {
38
+ throw new Error(`Letters are not allowed in value`);
39
+ }
40
+ if (this._rawValue && this._minLength > 0 && value.length < this._minLength) {
41
+ throw new Error(`Value is too short`);
42
+ }
43
+ if (this._rawValue && this._maxLength > 0 && value.length > this._maxLength) {
44
+ throw new Error(`${this._name}: value '${value}' is too long`);
45
+ }
46
+ return super.set(value);
47
+ }
48
+ get(transform = undefined) {
49
+ switch (transform) {
50
+ case StringProperty.TRANSFORM_LCASE:
51
+ return this._value && this._value.toLowerCase();
52
+ case StringProperty.TRANSFORM_UCASE:
53
+ return this._value && this._value.toUpperCase();
54
+ default:
55
+ return this._value;
56
+ }
57
+ }
58
+ set minLength(min) {
59
+ this._minLength = min >= 0 ? min : 0;
60
+ }
61
+ get minLength() {
62
+ return this._minLength;
63
+ }
64
+ set maxLength(max) {
65
+ this._maxLength = max >= 0 ? max : 0;
66
+ }
67
+ get maxLength() {
68
+ return this._maxLength;
69
+ }
70
+ }
71
+ exports.StringProperty = StringProperty;
72
+ StringProperty.TRANSFORM_UCASE = 'upper';
73
+ StringProperty.TRANSFORM_LCASE = 'lower';
@@ -0,0 +1,15 @@
1
+ import { Property } from './Property';
2
+ import { BaseProperty, BasePropertyType } from './BaseProperty';
3
+ import { NumberProperty, NumberPropertyType } from './NumberProperty';
4
+ import { StringProperty, StringPropertyType } from './StringProperty';
5
+ import { HashProperty, HashPropertyType } from './HashProperty';
6
+ import { EnumProperty, EnumPropertyType } from './EnumProperty';
7
+ import { BooleanProperty, BooleanPropertyType } from './BooleanProperty';
8
+ import { DateTimeProperty, DateTimePropertyType } from './DateTimeProperty';
9
+ import { ObjectProperty, ObjectPropertyType } from './ObjectProperty';
10
+ import { PropertyTypes } from './types/PropertyTypes';
11
+ export { Property, BaseProperty, BasePropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, };
12
+ declare type BaseType = {
13
+ type: PropertyTypes;
14
+ };
15
+ export declare type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType))[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.BaseProperty = exports.Property = void 0;
4
+ const Property_1 = require("./Property");
5
+ Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
6
+ const BaseProperty_1 = require("./BaseProperty");
7
+ Object.defineProperty(exports, "BaseProperty", { enumerable: true, get: function () { return BaseProperty_1.BaseProperty; } });
8
+ const NumberProperty_1 = require("./NumberProperty");
9
+ Object.defineProperty(exports, "NumberProperty", { enumerable: true, get: function () { return NumberProperty_1.NumberProperty; } });
10
+ const StringProperty_1 = require("./StringProperty");
11
+ Object.defineProperty(exports, "StringProperty", { enumerable: true, get: function () { return StringProperty_1.StringProperty; } });
12
+ const HashProperty_1 = require("./HashProperty");
13
+ Object.defineProperty(exports, "HashProperty", { enumerable: true, get: function () { return HashProperty_1.HashProperty; } });
14
+ const EnumProperty_1 = require("./EnumProperty");
15
+ Object.defineProperty(exports, "EnumProperty", { enumerable: true, get: function () { return EnumProperty_1.EnumProperty; } });
16
+ const BooleanProperty_1 = require("./BooleanProperty");
17
+ Object.defineProperty(exports, "BooleanProperty", { enumerable: true, get: function () { return BooleanProperty_1.BooleanProperty; } });
18
+ const DateTimeProperty_1 = require("./DateTimeProperty");
19
+ Object.defineProperty(exports, "DateTimeProperty", { enumerable: true, get: function () { return DateTimeProperty_1.DateTimeProperty; } });
20
+ const ObjectProperty_1 = require("./ObjectProperty");
21
+ Object.defineProperty(exports, "ObjectProperty", { enumerable: true, get: function () { return ObjectProperty_1.ObjectProperty; } });
@@ -0,0 +1,5 @@
1
+ import { PropertyTypes } from './PropertyTypes';
2
+ export interface AbstractPropertyType {
3
+ name: string;
4
+ type?: PropertyTypes;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface PropertyClassType {
2
+ set(value: any): void;
3
+ val(transform: any): void;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { Property } from '..';
2
+ export declare type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_NUMBER | typeof Property.TYPE_ENUM | typeof Property.TYPE_BOOLEAN | typeof Property.TYPE_OBJECT | typeof Property.TYPE_DATETIME | typeof Property.TYPE_HASH;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ export declare const CREATED = "created";
2
+ export declare const PENDING = "pending";
3
+ export declare const PROCESSING = "processing";
4
+ export declare const ACTIVE = "active";
5
+ export declare const ERROR = "error";
6
+ export declare const DELETABLE = "deletable";
7
+ export declare const DELETED = "deleted";
8
+ export declare const COMPLETED = "completed";
9
+ export declare const DONE = "done";
10
+ export declare const UNKNOWN = "unknown";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNKNOWN = exports.DONE = exports.COMPLETED = exports.DELETED = exports.DELETABLE = exports.ERROR = exports.ACTIVE = exports.PROCESSING = exports.PENDING = exports.CREATED = void 0;
4
+ exports.CREATED = 'created';
5
+ exports.PENDING = 'pending';
6
+ exports.PROCESSING = 'processing';
7
+ exports.ACTIVE = 'active';
8
+ exports.ERROR = 'error';
9
+ exports.DELETABLE = 'deletable';
10
+ exports.DELETED = 'deleted';
11
+ exports.COMPLETED = 'completed';
12
+ exports.DONE = 'done';
13
+ exports.UNKNOWN = 'unknown';
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@quatrain/core",
3
+ "version": "0.1.6",
4
+ "description": "Core objects for business apps",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/",
9
+ "README.md"
10
+ ],
11
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
+ "license": "MIT",
13
+ "devDependencies": {
14
+ "@tsconfig/recommended": "^1.0.1",
15
+ "@types/jest": "^27.0.3",
16
+ "jest": "^27.4.7",
17
+ "jest-node-exports-resolver": "^1.1.6",
18
+ "ts-jest": "^27.1.2",
19
+ "ts-node": "^10.4.0",
20
+ "typescript": "^4.7.4"
21
+ },
22
+ "scripts": {
23
+ "test": "tsc && jest --verbose",
24
+ "build": "tsc --watch",
25
+ "push": "yarn version --patch --no-git-tag-version ; yarn publish --access public",
26
+ "prepublish": "tsc"
27
+ }
28
+ }