@quatrain/core 0.1.6 → 0.1.10

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,23 @@
1
+ # Quatrain Core
2
+
3
+ ## Why
4
+
5
+ Quatrain Core is an abstraction layer designed to accelerate and simplify the development
6
+ of applications using many models and various data stores, being database or APIs.
7
+
8
+ With Quatrain Core and peer packages, one may develop robust applications based on
9
+ Oriented Object Programming with a clear separation of concerns between logic, data
10
+ and storage.
11
+
12
+ ## How to install
13
+
14
+ ```javascript
15
+ yarn install @quatrain/core
16
+ ```
17
+
18
+ Quatrain Core comes with a built-in Mock backend adapter. Other adapters are available in
19
+ different packages. For example, a Google Firestore adapter is available:
20
+
21
+ ```javascript
22
+ yarn install @quatrain/backend-firestore
23
+ ```
@@ -0,0 +1,19 @@
1
+ import { BaseProperty, BasePropertyType } from './BaseProperty';
2
+ export interface ArrayPropertyType extends BasePropertyType {
3
+ minLength?: number;
4
+ maxLength?: number;
5
+ allowNumbers?: boolean;
6
+ allowStrings?: boolean;
7
+ }
8
+ export declare class ArrayProperty extends BaseProperty {
9
+ protected _value: Array<any> | undefined;
10
+ protected _minLength: number;
11
+ protected _maxLength: number;
12
+ constructor(config: ArrayPropertyType);
13
+ set minLength(min: number);
14
+ get minLength(): number;
15
+ set maxLength(max: number);
16
+ get maxLength(): number;
17
+ set(value: Array<any>): this;
18
+ toJSON(): any[] | undefined;
19
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayProperty = void 0;
4
+ const Property_1 = require("./Property");
5
+ const BaseProperty_1 = require("./BaseProperty");
6
+ class ArrayProperty extends BaseProperty_1.BaseProperty {
7
+ constructor(config) {
8
+ super(config);
9
+ this._value = undefined;
10
+ this._minLength = 0;
11
+ this._maxLength = 0;
12
+ this.minLength = config.minLength || 0;
13
+ this.maxLength = config.maxLength || 0;
14
+ if (this._enable(config.allowNumbers)) {
15
+ this._allows.push(Property_1.Property.ALLOW_NUMBERS);
16
+ }
17
+ if (this._enable(config.allowStrings)) {
18
+ this._allows.push(Property_1.Property.ALLOW_STRINGS);
19
+ }
20
+ }
21
+ set minLength(min) {
22
+ this._minLength = min >= 0 ? min : 0;
23
+ }
24
+ get minLength() {
25
+ return this._minLength;
26
+ }
27
+ set maxLength(max) {
28
+ this._maxLength = max >= 0 ? max : 0;
29
+ }
30
+ get maxLength() {
31
+ return this._maxLength;
32
+ }
33
+ set(value) {
34
+ if (!Array.isArray(value)) {
35
+ throw new Error(`value ${JSON.stringify(value)} is not an array`);
36
+ }
37
+ // TODO add controls over allowed values
38
+ return super.set(value);
39
+ }
40
+ toJSON() {
41
+ return this._value;
42
+ }
43
+ }
44
+ exports.ArrayProperty = ArrayProperty;
@@ -12,5 +12,7 @@ export declare class Property {
12
12
  static ALLOW_SPACES: string;
13
13
  static ALLOW_LETTERS: string;
14
14
  static ALLOW_DIGITS: string;
15
+ static ALLOW_STRINGS: string;
16
+ static ALLOW_NUMBERS: string;
15
17
  static factory<P extends BasePropertyType>(params: P, parent: DataObject): BaseProperty;
16
18
  }
@@ -47,3 +47,5 @@ Property.TYPE_DATETIME = 'datetime';
47
47
  Property.ALLOW_SPACES = 'spaces';
48
48
  Property.ALLOW_LETTERS = 'letters';
49
49
  Property.ALLOW_DIGITS = 'digits';
50
+ Property.ALLOW_STRINGS = 'strings';
51
+ Property.ALLOW_NUMBERS = 'numbers';
@@ -1,5 +1,6 @@
1
1
  import { Property } from './Property';
2
2
  import { BaseProperty, BasePropertyType } from './BaseProperty';
3
+ import { ArrayProperty, ArrayPropertyType } from './ArrayProperty';
3
4
  import { NumberProperty, NumberPropertyType } from './NumberProperty';
4
5
  import { StringProperty, StringPropertyType } from './StringProperty';
5
6
  import { HashProperty, HashPropertyType } from './HashProperty';
@@ -8,7 +9,7 @@ import { BooleanProperty, BooleanPropertyType } from './BooleanProperty';
8
9
  import { DateTimeProperty, DateTimePropertyType } from './DateTimeProperty';
9
10
  import { ObjectProperty, ObjectPropertyType } from './ObjectProperty';
10
11
  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
+ export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, };
12
13
  declare type BaseType = {
13
14
  type: PropertyTypes;
14
15
  };
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
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;
3
+ exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.ArrayProperty = exports.BaseProperty = exports.Property = void 0;
4
4
  const Property_1 = require("./Property");
5
5
  Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
6
6
  const BaseProperty_1 = require("./BaseProperty");
7
7
  Object.defineProperty(exports, "BaseProperty", { enumerable: true, get: function () { return BaseProperty_1.BaseProperty; } });
8
+ const ArrayProperty_1 = require("./ArrayProperty");
9
+ Object.defineProperty(exports, "ArrayProperty", { enumerable: true, get: function () { return ArrayProperty_1.ArrayProperty; } });
8
10
  const NumberProperty_1 = require("./NumberProperty");
9
11
  Object.defineProperty(exports, "NumberProperty", { enumerable: true, get: function () { return NumberProperty_1.NumberProperty; } });
10
12
  const StringProperty_1 = require("./StringProperty");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.10",
4
4
  "description": "Core objects for business apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",