@quatrain/core 1.1.2 → 1.1.4

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.
@@ -1,14 +1,15 @@
1
1
  export declare const CREATED = "created";
2
+ export declare const DOWNLOADING = "downloading";
3
+ export declare const DOWNLOADED = "downloaded";
2
4
  export declare const PENDING = "pending";
3
- export declare const QUEUED = "queued";
5
+ export declare const PROCESSING = "processing";
4
6
  export declare const ACTIVE = "active";
5
- export declare const COMPLETED = "completed";
6
7
  export declare const ERROR = "error";
7
- export declare const TEST = "test";
8
- export declare const SUSPENDED = "suspended";
9
8
  export declare const DELETABLE = "deletable";
10
9
  export declare const DELETED = "deleted";
10
+ export declare const COMPLETED = "completed";
11
+ export declare const QUEUED = "queued";
11
12
  export declare const DISABLED = "disabled";
12
13
  export declare const DONE = "done";
13
- export declare const MAINTENANCE = "maintenance";
14
+ export declare const KO = "ko";
14
15
  export declare const UNKNOWN = "unknown";
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UNKNOWN = exports.MAINTENANCE = exports.DONE = exports.DISABLED = exports.DELETED = exports.DELETABLE = exports.SUSPENDED = exports.TEST = exports.ERROR = exports.COMPLETED = exports.ACTIVE = exports.QUEUED = exports.PENDING = exports.CREATED = void 0;
3
+ exports.UNKNOWN = exports.KO = exports.DONE = exports.DISABLED = exports.QUEUED = exports.COMPLETED = exports.DELETED = exports.DELETABLE = exports.ERROR = exports.ACTIVE = exports.PROCESSING = exports.PENDING = exports.DOWNLOADED = exports.DOWNLOADING = exports.CREATED = void 0;
4
4
  exports.CREATED = 'created';
5
+ exports.DOWNLOADING = 'downloading';
6
+ exports.DOWNLOADED = 'downloaded';
5
7
  exports.PENDING = 'pending';
6
- exports.QUEUED = 'queued';
8
+ exports.PROCESSING = 'processing';
7
9
  exports.ACTIVE = 'active';
8
- exports.COMPLETED = 'completed';
9
10
  exports.ERROR = 'error';
10
- exports.TEST = 'test';
11
- exports.SUSPENDED = 'suspended';
12
11
  exports.DELETABLE = 'deletable';
13
12
  exports.DELETED = 'deleted';
13
+ exports.COMPLETED = 'completed';
14
+ exports.QUEUED = 'queued';
14
15
  exports.DISABLED = 'disabled';
15
16
  exports.DONE = 'done';
16
- exports.MAINTENANCE = 'maintenance';
17
+ exports.KO = 'ko';
17
18
  exports.UNKNOWN = 'unknown';
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.BaseObjectProperties = void 0;
27
- const statuses = __importStar(require("../statuses"));
27
+ const statuses = __importStar(require("../common/statuses"));
28
28
  const StringProperty_1 = require("../properties/StringProperty");
29
29
  const ObjectProperty_1 = require("../properties/ObjectProperty");
30
30
  const EnumProperty_1 = require("../properties/EnumProperty");
@@ -3,6 +3,7 @@ export interface EnumPropertyType extends BasePropertyType {
3
3
  values?: string[];
4
4
  }
5
5
  export declare class EnumProperty extends BaseProperty {
6
+ static WILDCARD: string;
6
7
  static TYPE: string;
7
8
  protected _values: string[];
8
9
  constructor(config: EnumPropertyType);
@@ -9,7 +9,9 @@ class EnumProperty extends BaseProperty_1.BaseProperty {
9
9
  this._values = config.values || [];
10
10
  }
11
11
  set(value, setChanged = true) {
12
- if (value !== null && !this._values.includes(value)) {
12
+ if (value !== null &&
13
+ !this._values.includes(EnumProperty.WILDCARD) &&
14
+ !this._values.includes(value)) {
13
15
  throw new Error(`Value '${value}' is not acceptable`);
14
16
  }
15
17
  return super.set(value, setChanged);
@@ -19,4 +21,5 @@ class EnumProperty extends BaseProperty_1.BaseProperty {
19
21
  }
20
22
  }
21
23
  exports.EnumProperty = EnumProperty;
24
+ EnumProperty.WILDCARD = '*';
22
25
  EnumProperty.TYPE = 'enum';
@@ -2,7 +2,7 @@ import { AbstractPropertyType } from './AbstractPropertyType';
2
2
  export interface PropertyClassType {
3
3
  id?: string;
4
4
  name: string;
5
- set(value: any, setCahnged?: boolean): AbstractPropertyType;
5
+ set(value: any, setChanged?: boolean): AbstractPropertyType;
6
6
  val(transform?: any): any;
7
7
  toJSON(): any;
8
8
  clone(): PropertyClassType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/core",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Core objects for business apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,34 +0,0 @@
1
- import { ObjectUri, DataObjectClass, DataObject } from '../';
2
- import { BaseObjectType } from './types/BaseObjectType';
3
- import { AbstractObject } from './AbstractObject';
4
- export declare class BaseObjectCore extends AbstractObject {
5
- static PROPS_DEFINITION: any;
6
- static getProperty(key: string): any;
7
- static fillProperties(child?: any): DataObject;
8
- static daoFactory(src?: string | ObjectUri | DataObjectClass<any> | undefined, child?: any): Promise<DataObjectClass<any>>;
9
- /**
10
- * Instantiates from an object
11
- * @param src
12
- * @param child
13
- * @returns
14
- */
15
- static fromObject<T extends BaseObjectType>(src: T, child?: any): any;
16
- static factory(src?: string | ObjectUri | BaseObjectType | undefined, child?: any): Promise<any>;
17
- /**
18
- * Fetches an object from its backend path
19
- * @param path
20
- * @returns
21
- */
22
- static fromBackend<T>(path: string): Promise<T>;
23
- /**
24
- * Instantiates from a DataObject
25
- * @param dao
26
- * @returns
27
- */
28
- static fromDataObject<T extends BaseObjectType>(dao: DataObjectClass<any>): any;
29
- /**
30
- * Wrap instance into proxy to get access to properties
31
- * @returns Proxy
32
- */
33
- asReference(): any;
34
- }
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BaseObjectCore = void 0;
13
- const __1 = require("../");
14
- const BaseObjectProperties_1 = require("./BaseObjectProperties");
15
- const AbstractObject_1 = require("./AbstractObject");
16
- class BaseObjectCore extends AbstractObject_1.AbstractObject {
17
- static getProperty(key) {
18
- return BaseObjectCore.PROPS_DEFINITION.find((prop) => prop.name === key);
19
- }
20
- static fillProperties(child = this) {
21
- // merge base properties with additional or redefined ones
22
- const base = [...BaseObjectCore.PROPS_DEFINITION];
23
- child.PROPS_DEFINITION.forEach((property) => {
24
- // manage parent properties potential redeclaration
25
- const found = base.findIndex((el) => el.name === property.name);
26
- if (found !== -1) {
27
- base[found] = property;
28
- }
29
- else {
30
- base.push(property);
31
- }
32
- });
33
- const dao = __1.DataObject.factory({
34
- properties: base,
35
- parentProp: this.PARENT_PROP,
36
- });
37
- dao.uri.class = child;
38
- return dao;
39
- }
40
- static daoFactory(src = undefined, child = this) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const dao = this.fillProperties(child);
43
- if (src instanceof __1.ObjectUri) {
44
- dao.uri = src;
45
- yield dao.read();
46
- }
47
- else if (typeof src == 'string') {
48
- dao.uri.path = src;
49
- yield dao.read();
50
- }
51
- return dao;
52
- });
53
- }
54
- /**
55
- * Instantiates from an object
56
- * @param src
57
- * @param child
58
- * @returns
59
- */
60
- static fromObject(src, child = this) {
61
- const dao = this.fillProperties(child);
62
- dao.uri = new __1.ObjectUri(`${this.COLLECTION}${__1.ObjectUri.DEFAULT}`, Reflect.get(src, 'name'));
63
- dao.uri.class = child;
64
- dao.populateFromData(src);
65
- const obj = new this(dao);
66
- return obj;
67
- }
68
- static factory(src = undefined, child = this) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- try {
71
- if (typeof src == 'object' && !(src instanceof __1.ObjectUri)) {
72
- return this.fromObject(src);
73
- }
74
- const dao = yield this.daoFactory(src, child);
75
- const constructedObject = Reflect.construct(this, [dao]);
76
- return constructedObject;
77
- }
78
- catch (err) {
79
- throw new Error(`Unable to build instance for '${this.name}': ${err.message}`);
80
- }
81
- });
82
- }
83
- /**
84
- * Fetches an object from its backend path
85
- * @param path
86
- * @returns
87
- */
88
- static fromBackend(path) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- if (!path.includes('/')) {
91
- return this.factory(`${this.COLLECTION}/${path}`);
92
- }
93
- return this.factory(path);
94
- });
95
- }
96
- /**
97
- * Instantiates from a DataObject
98
- * @param dao
99
- * @returns
100
- */
101
- static fromDataObject(dao) {
102
- const obj = new this(dao);
103
- return obj; //.toProxy()
104
- }
105
- /**
106
- * Wrap instance into proxy to get access to properties
107
- * @returns Proxy
108
- */
109
- // protected toProxy<T extends BaseObject>() {
110
- // return new ProxyConstructor<this, Proxy<T>>(this, {
111
- // get: (target, prop) => {
112
- // if (prop === 'uid') {
113
- // return target.uid
114
- // }
115
- // if (prop === 'uri') {
116
- // return target.uri
117
- // }
118
- // if (prop == 'toJSON') {
119
- // return target.toJSON
120
- // }
121
- // if (prop == 'save') {
122
- // return target.save
123
- // }
124
- // if (prop == 'constructor') {
125
- // return target.constructor
126
- // }
127
- // if (prop === 'core') {
128
- // return target
129
- // }
130
- // // i don't know why and i shouldn't have to wonder why
131
- // // but everything crashes unless we do this terribleness
132
- // if (prop == 'then') {
133
- // return
134
- // }
135
- // return target.val(prop as string)
136
- // },
137
- // set(target, prop, newValue) {
138
- // if (prop === 'uid' || prop === 'core') {
139
- // throw new Error(`Property '${prop}' is readonly`)
140
- // }
141
- // target.set(prop as string, newValue)
142
- // return true
143
- // },
144
- // })
145
- // }
146
- asReference() {
147
- return this._dataObject.toReference();
148
- }
149
- }
150
- exports.BaseObjectCore = BaseObjectCore;
151
- // implements BaseObjectClass {
152
- BaseObjectCore.PROPS_DEFINITION = BaseObjectProperties_1.BaseObjectProperties;
@@ -1,28 +0,0 @@
1
- import { PropertyClassType } from '../../properties/types/PropertyClassType';
2
- import { ObjectUri } from '../ObjectUri';
3
- import { toJSONParams } from './toJSONParams';
4
- export interface DataObjectClass<T extends DataObjectClass<any>> {
5
- uri: ObjectUri;
6
- uid: any;
7
- backend: any;
8
- path: any;
9
- class: any;
10
- properties: any;
11
- parentProp: string | undefined;
12
- setProperties(properties: any): void;
13
- getProperties(type: any): any;
14
- addProperty(property: PropertyClassType): void;
15
- populate(data?: any): Promise<T>;
16
- isPopulated(): boolean;
17
- has(key: string): boolean;
18
- get(key: string): any;
19
- set(key: string, val: any): any;
20
- val(key: string): any;
21
- clone(data?: any): Promise<T>;
22
- toReference(): any;
23
- toJSON(params?: boolean | toJSONParams): any;
24
- populateFromData(data: {
25
- [x: string]: unknown;
26
- }): this;
27
- asProxy(): any;
28
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });