entropic-bond 1.49.0 → 1.50.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/.github/workflows/release.yml +26 -0
- package/CHANGELOG.md +1151 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +94 -0
- package/docs/classes/Auth.md +391 -0
- package/docs/classes/AuthMock.md +278 -0
- package/docs/classes/AuthService.md +188 -0
- package/docs/classes/CloudFunctions.md +123 -0
- package/docs/classes/CloudFunctionsMock.md +97 -0
- package/docs/classes/CloudStorage.md +215 -0
- package/docs/classes/DataSource.md +248 -0
- package/docs/classes/EntropicComponent.md +666 -0
- package/docs/classes/JsonDataSource.md +328 -0
- package/docs/classes/MockCloudStorage.md +279 -0
- package/docs/classes/Model.md +274 -0
- package/docs/classes/Observable.md +120 -0
- package/docs/classes/Persistent.md +420 -0
- package/docs/classes/ServerAuth.md +211 -0
- package/docs/classes/ServerAuthMock.md +176 -0
- package/docs/classes/ServerAuthService.md +130 -0
- package/docs/classes/Store.md +218 -0
- package/docs/classes/StoredFile.md +636 -0
- package/docs/enums/StoredFileEvent.md +41 -0
- package/docs/interfaces/AuthError.md +30 -0
- package/docs/interfaces/CloudFunctionsService.md +69 -0
- package/docs/interfaces/Collection.md +13 -0
- package/docs/interfaces/CustomCredentials.md +7 -0
- package/docs/interfaces/DocumentReference.md +49 -0
- package/docs/interfaces/JsonRawData.md +7 -0
- package/docs/interfaces/SignData.md +63 -0
- package/docs/interfaces/StoreParams.md +52 -0
- package/docs/interfaces/StoredFileChange.md +41 -0
- package/docs/interfaces/UploadControl.md +90 -0
- package/docs/interfaces/UserCredentials.md +113 -0
- package/docs/interfaces/Values.md +17 -0
- package/docs/modules.md +1273 -0
- package/package.json +23 -19
- package/src/auth/auth-mock.spec.ts +168 -0
- package/src/auth/auth-mock.ts +129 -0
- package/src/auth/auth.ts +185 -0
- package/src/auth/user-auth-types.ts +21 -0
- package/src/cloud-functions/cloud-functions-mock.spec.ts +136 -0
- package/src/cloud-functions/cloud-functions-mock.ts +23 -0
- package/src/cloud-functions/cloud-functions.ts +83 -0
- package/src/cloud-storage/cloud-storage.spec.ts +207 -0
- package/src/cloud-storage/cloud-storage.ts +60 -0
- package/src/cloud-storage/mock-cloud-storage.ts +72 -0
- package/src/cloud-storage/stored-file.ts +102 -0
- package/src/index.ts +19 -0
- package/src/observable/observable.spec.ts +105 -0
- package/src/observable/observable.ts +67 -0
- package/src/persistent/entropic-component.spec.ts +143 -0
- package/src/persistent/entropic-component.ts +135 -0
- package/src/persistent/persistent.spec.ts +828 -0
- package/src/persistent/persistent.ts +650 -0
- package/src/server-auth/server-auth-mock.spec.ts +53 -0
- package/src/server-auth/server-auth-mock.ts +45 -0
- package/src/server-auth/server-auth.ts +49 -0
- package/src/store/data-source.ts +186 -0
- package/src/store/json-data-source.spec.ts +100 -0
- package/src/store/json-data-source.ts +256 -0
- package/src/store/mocks/mock-data.json +155 -0
- package/src/store/mocks/test-user.ts +122 -0
- package/src/store/model.spec.ts +659 -0
- package/src/store/model.ts +462 -0
- package/src/store/store.spec.ts +30 -0
- package/src/store/store.ts +113 -0
- package/src/types/utility-types.spec.ts +117 -0
- package/src/types/utility-types.ts +116 -0
- package/src/utils/test-utils/test-person.ts +44 -0
- package/src/utils/utils.spec.ts +95 -0
- package/{lib/utils/utils.d.ts → src/utils/utils.ts} +34 -10
- package/tsconfig-build.json +7 -0
- package/tsconfig-cjs.json +9 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +22 -0
- package/lib/auth/auth-mock.d.ts +0 -22
- package/lib/auth/auth-mock.js +0 -111
- package/lib/auth/auth-mock.js.map +0 -1
- package/lib/auth/auth.d.ts +0 -131
- package/lib/auth/auth.js +0 -149
- package/lib/auth/auth.js.map +0 -1
- package/lib/auth/user-auth-types.d.ts +0 -19
- package/lib/auth/user-auth-types.js +0 -3
- package/lib/auth/user-auth-types.js.map +0 -1
- package/lib/cloud-functions/cloud-functions-mock.d.ts +0 -11
- package/lib/cloud-functions/cloud-functions-mock.js +0 -19
- package/lib/cloud-functions/cloud-functions-mock.js.map +0 -1
- package/lib/cloud-functions/cloud-functions.d.ts +0 -19
- package/lib/cloud-functions/cloud-functions.js +0 -64
- package/lib/cloud-functions/cloud-functions.js.map +0 -1
- package/lib/cloud-storage/cloud-storage.d.ts +0 -24
- package/lib/cloud-storage/cloud-storage.js +0 -37
- package/lib/cloud-storage/cloud-storage.js.map +0 -1
- package/lib/cloud-storage/mock-cloud-storage.d.ts +0 -20
- package/lib/cloud-storage/mock-cloud-storage.js +0 -68
- package/lib/cloud-storage/mock-cloud-storage.js.map +0 -1
- package/lib/cloud-storage/stored-file.d.ts +0 -39
- package/lib/cloud-storage/stored-file.js +0 -106
- package/lib/cloud-storage/stored-file.js.map +0 -1
- package/lib/index.d.ts +0 -19
- package/lib/index.js +0 -36
- package/lib/index.js.map +0 -1
- package/lib/observable/observable.d.ts +0 -52
- package/lib/observable/observable.js +0 -66
- package/lib/observable/observable.js.map +0 -1
- package/lib/persistent/entropic-component.d.ts +0 -76
- package/lib/persistent/entropic-component.js +0 -109
- package/lib/persistent/entropic-component.js.map +0 -1
- package/lib/persistent/persistent.d.ts +0 -281
- package/lib/persistent/persistent.js +0 -539
- package/lib/persistent/persistent.js.map +0 -1
- package/lib/server-auth/server-auth-mock.d.ts +0 -12
- package/lib/server-auth/server-auth-mock.js +0 -39
- package/lib/server-auth/server-auth-mock.js.map +0 -1
- package/lib/server-auth/server-auth.d.ts +0 -24
- package/lib/server-auth/server-auth.js +0 -36
- package/lib/server-auth/server-auth.js.map +0 -1
- package/lib/store/data-source.d.ts +0 -137
- package/lib/store/data-source.js +0 -62
- package/lib/store/data-source.js.map +0 -1
- package/lib/store/json-data-source.d.ts +0 -68
- package/lib/store/json-data-source.js +0 -199
- package/lib/store/json-data-source.js.map +0 -1
- package/lib/store/mocks/test-user.d.ts +0 -49
- package/lib/store/mocks/test-user.js +0 -135
- package/lib/store/mocks/test-user.js.map +0 -1
- package/lib/store/model.d.ts +0 -238
- package/lib/store/model.js +0 -417
- package/lib/store/model.js.map +0 -1
- package/lib/store/store.d.ts +0 -62
- package/lib/store/store.js +0 -102
- package/lib/store/store.js.map +0 -1
- package/lib/types/utility-types.d.ts +0 -45
- package/lib/types/utility-types.js +0 -3
- package/lib/types/utility-types.js.map +0 -1
- package/lib/utils/test-utils/test-person.d.ts +0 -33
- package/lib/utils/test-utils/test-person.js +0 -25
- package/lib/utils/test-utils/test-person.js.map +0 -1
- package/lib/utils/utils.js +0 -76
- package/lib/utils/utils.js.map +0 -1
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.requiredWithValidator = exports.required = exports.searchableArray = exports.registerLegacyClassName = exports.registerPersistentClass = exports.persistentParser = exports.persistentPureReferenceWithPersistentProps = exports.persistentPureReference = exports.persistentReferenceWithPersistentProps = exports.persistentReference = exports.persistentReferenceAt = exports.persistent = exports.Persistent = void 0;
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
/**
|
|
12
|
-
* A class that provides several methods to serialize and deserialize objects.
|
|
13
|
-
*/
|
|
14
|
-
class Persistent {
|
|
15
|
-
/**
|
|
16
|
-
* Registers a class to be used by the persistence engine.
|
|
17
|
-
* @param className the name of the class to be registered
|
|
18
|
-
* @param factory the constructor of the registered class
|
|
19
|
-
* @param annotation an annotation associated with the class
|
|
20
|
-
*/
|
|
21
|
-
static registerFactory(className, factory, annotation) {
|
|
22
|
-
this._factoryMap[className] = { factory, annotation };
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Returns the constructor of a registered class
|
|
26
|
-
* @param className the name of the class to be retrieved
|
|
27
|
-
* @returns the constructor of the class
|
|
28
|
-
* @throws an error if the class is not registered
|
|
29
|
-
* @see registerFactory
|
|
30
|
-
* @see registeredClasses
|
|
31
|
-
* @see classesExtending
|
|
32
|
-
* @see annotations
|
|
33
|
-
*/
|
|
34
|
-
static classFactory(className) {
|
|
35
|
-
if (!className)
|
|
36
|
-
throw new Error(`You should provide a class name.`);
|
|
37
|
-
if (!this._factoryMap[className])
|
|
38
|
-
throw new Error(`You should register class ${className} prior to use.`);
|
|
39
|
-
return this._factoryMap[className].factory;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the names of all registered classes
|
|
43
|
-
* @returns the names of all registered classes
|
|
44
|
-
* @see registerFactory
|
|
45
|
-
* @see classFactory
|
|
46
|
-
*/
|
|
47
|
-
static registeredClasses() {
|
|
48
|
-
return Object.keys(this._factoryMap);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns the names of all registered classes that extend a given class
|
|
52
|
-
* @param derivedFrom the class to be extended
|
|
53
|
-
* @returns the names of all registered classes that extend the given class
|
|
54
|
-
* @see registerFactory
|
|
55
|
-
* @see classFactory
|
|
56
|
-
*/
|
|
57
|
-
static classesExtending(derivedFrom) {
|
|
58
|
-
return Object.entries(this._factoryMap)
|
|
59
|
-
.filter(([, obj]) => new (obj.factory) instanceof derivedFrom)
|
|
60
|
-
.map(([className]) => className);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns the annotation associated with a registered class
|
|
64
|
-
* @param className the name of the class to be retrieved
|
|
65
|
-
* @returns the annotation associated with the class
|
|
66
|
-
* @throws an error if the class is not registered
|
|
67
|
-
* @see registerFactory
|
|
68
|
-
*/
|
|
69
|
-
static annotations(className) {
|
|
70
|
-
if (className instanceof Persistent)
|
|
71
|
-
className = className.className;
|
|
72
|
-
else if (typeof className === 'string')
|
|
73
|
-
className;
|
|
74
|
-
else
|
|
75
|
-
className = new className().className;
|
|
76
|
-
if (!this._factoryMap[className])
|
|
77
|
-
throw new Error(`You should register class ${className} prior to use.`);
|
|
78
|
-
return this._factoryMap[className].annotation;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Returns a new instance of Persistent class.
|
|
82
|
-
* @param className the initial id of this instance. If not provided, a new id will be generated
|
|
83
|
-
*/
|
|
84
|
-
constructor(id = (0, uuid_1.v4)()) {
|
|
85
|
-
this._id = id;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Gets the class name of this instance.
|
|
89
|
-
*/
|
|
90
|
-
get className() {
|
|
91
|
-
return this['__className'];
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sets the id of this instance.
|
|
95
|
-
* @param value the id of this instance
|
|
96
|
-
*/
|
|
97
|
-
setId(value) {
|
|
98
|
-
this._id = value;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Returns the id of this instance.
|
|
102
|
-
* @returns the id of this instance
|
|
103
|
-
*/
|
|
104
|
-
get id() {
|
|
105
|
-
return this._id;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* This method is called by the persistence engine when the instance has been
|
|
109
|
-
* just serialized. It is called after the properties are initialized with
|
|
110
|
-
* serialized data.
|
|
111
|
-
*/
|
|
112
|
-
afterDeserialize() { }
|
|
113
|
-
/**
|
|
114
|
-
* This method is called by the persistence engine before the instance is
|
|
115
|
-
* serialized.
|
|
116
|
-
*/
|
|
117
|
-
beforeSerialize() { }
|
|
118
|
-
/**
|
|
119
|
-
* Returns an array of the persistent properties of this instance.
|
|
120
|
-
* @returns an array of the persistent properties of this instance
|
|
121
|
-
*/
|
|
122
|
-
getPersistentProperties() {
|
|
123
|
-
if (!this._persistentProperties)
|
|
124
|
-
return [];
|
|
125
|
-
return this._persistentProperties.map(prop => ({
|
|
126
|
-
...prop,
|
|
127
|
-
name: prop.name.slice(1)
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Get the property information of this instance
|
|
132
|
-
* @param propName the persistent property name
|
|
133
|
-
* @returns the property information
|
|
134
|
-
*/
|
|
135
|
-
getPropInfo(propName) {
|
|
136
|
-
const propInfo = this.getPersistentProperties().find(prop => prop.name === propName);
|
|
137
|
-
if (!propInfo)
|
|
138
|
-
throw new Error(`Property "${propName}" has not been registered.`);
|
|
139
|
-
return propInfo;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Query if the property is required
|
|
143
|
-
* To mark a property as required, use the @required decorator
|
|
144
|
-
* @param propName the persistent property name
|
|
145
|
-
* @returns true if the property is required
|
|
146
|
-
* @see required
|
|
147
|
-
*/
|
|
148
|
-
isRequired(propName) {
|
|
149
|
-
const validator = this.getPropInfo(propName).validator;
|
|
150
|
-
return validator !== undefined && validator !== null;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Query if the property value is valid
|
|
154
|
-
* Define the validator function using the @required decorator
|
|
155
|
-
* @param propName the persistent property name
|
|
156
|
-
* @returns true if the property value is valid using the validator function
|
|
157
|
-
* passed to the @required decorator
|
|
158
|
-
* @see required
|
|
159
|
-
*/
|
|
160
|
-
isPropValueValid(propName) {
|
|
161
|
-
const propInfo = this.getPropInfo(propName);
|
|
162
|
-
if (!propInfo.validator)
|
|
163
|
-
return true;
|
|
164
|
-
return propInfo.validator(this[propInfo.name], propInfo, this);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Copy the persistent properties of the given instance to this instance.
|
|
168
|
-
* The property `id` will be ignored.
|
|
169
|
-
* Only the properties that are not null or undefined will be copied.
|
|
170
|
-
* @param instance the instance to be copied
|
|
171
|
-
* @returns this instance
|
|
172
|
-
* @see fromObject
|
|
173
|
-
* @see toObject
|
|
174
|
-
*/
|
|
175
|
-
clone(instance) {
|
|
176
|
-
const obj = instance.toObject();
|
|
177
|
-
delete obj['id'];
|
|
178
|
-
return this.fromObject(obj);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Initializes the persistent properties of this instance from the properties
|
|
182
|
-
* of given object.
|
|
183
|
-
* @param obj the object to be copied
|
|
184
|
-
* @returns this instance
|
|
185
|
-
* @see clone
|
|
186
|
-
* @see toObject
|
|
187
|
-
*/
|
|
188
|
-
fromObject(obj) {
|
|
189
|
-
this.fromObj(obj);
|
|
190
|
-
this.afterDeserialize();
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
fromObj(obj) {
|
|
194
|
-
if (!this._persistentProperties)
|
|
195
|
-
return this;
|
|
196
|
-
this._persistentProperties.forEach(prop => {
|
|
197
|
-
const propName = this.removeUnderscore(prop);
|
|
198
|
-
const value = obj[propName];
|
|
199
|
-
if (value !== undefined && value !== null) {
|
|
200
|
-
this[prop.name] = this.fromDeepObject(value);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Returns a plain object representation of this instance.
|
|
207
|
-
* Only the properties that are not null or undefined will be copied.
|
|
208
|
-
* @returns a plain object representation of this instance
|
|
209
|
-
* @see fromObject
|
|
210
|
-
* @see clone
|
|
211
|
-
*/
|
|
212
|
-
toObject() {
|
|
213
|
-
const rootCollections = {};
|
|
214
|
-
const obj = this.toObj(rootCollections);
|
|
215
|
-
this.pushDocument(rootCollections, this.className, obj);
|
|
216
|
-
return {
|
|
217
|
-
...obj,
|
|
218
|
-
__rootCollections: rootCollections
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
toObj(rootCollections) {
|
|
222
|
-
if (!this._persistentProperties)
|
|
223
|
-
return {};
|
|
224
|
-
this.beforeSerialize();
|
|
225
|
-
const obj = {};
|
|
226
|
-
if (!this.className)
|
|
227
|
-
throw new Error('You should register this class prior to streaming it.');
|
|
228
|
-
this._persistentProperties.forEach(prop => {
|
|
229
|
-
const propValue = this[prop.name];
|
|
230
|
-
const propName = this.removeUnderscore(prop);
|
|
231
|
-
if (propValue !== undefined && propValue !== null) {
|
|
232
|
-
if (prop.isReference) {
|
|
233
|
-
obj[propName] = this.toReferenceObj(prop, rootCollections);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
obj[propName] = this.toDeepObj(propValue, rootCollections);
|
|
237
|
-
}
|
|
238
|
-
if (prop.searchableArray) {
|
|
239
|
-
obj[Persistent.searchableArrayNameFor(propName)] = propValue.map((value) => value.id);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
obj['__className'] = this.className;
|
|
244
|
-
return obj;
|
|
245
|
-
}
|
|
246
|
-
static searchableArrayNameFor(propName) {
|
|
247
|
-
return `__${propName}_searchable`;
|
|
248
|
-
}
|
|
249
|
-
fromDeepObject(value) {
|
|
250
|
-
if (value === undefined || value === null)
|
|
251
|
-
return value;
|
|
252
|
-
if (Array.isArray(value)) {
|
|
253
|
-
return value.map(item => this.fromDeepObject(item));
|
|
254
|
-
}
|
|
255
|
-
if (value['__documentReference']) {
|
|
256
|
-
const ref = value;
|
|
257
|
-
const emptyInstance = Persistent.createInstance(ref);
|
|
258
|
-
// emptyInstance._id = ref.id
|
|
259
|
-
emptyInstance['__documentReference'] = value['__documentReference'];
|
|
260
|
-
return emptyInstance;
|
|
261
|
-
}
|
|
262
|
-
if (value['__className']) {
|
|
263
|
-
return Persistent.createInstance(value);
|
|
264
|
-
}
|
|
265
|
-
if (typeof value === 'object') {
|
|
266
|
-
const newObject = {};
|
|
267
|
-
Object.entries(value).forEach(([key, value]) => newObject[key] = this.fromDeepObject(value));
|
|
268
|
-
return newObject;
|
|
269
|
-
}
|
|
270
|
-
return value;
|
|
271
|
-
}
|
|
272
|
-
toDeepObj(value, rootCollections) {
|
|
273
|
-
if (value === null || value === undefined) {
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
if (Array.isArray(value)) {
|
|
277
|
-
return value.map(item => this.toDeepObj(item, rootCollections));
|
|
278
|
-
}
|
|
279
|
-
if (value['__documentReference'])
|
|
280
|
-
return value;
|
|
281
|
-
if (value instanceof Persistent) {
|
|
282
|
-
return value.toObj(rootCollections);
|
|
283
|
-
}
|
|
284
|
-
if (typeof value === 'object') {
|
|
285
|
-
const newObject = {};
|
|
286
|
-
Object.entries(value).forEach(([key, val]) => newObject[key] = this.toDeepObj(val, rootCollections));
|
|
287
|
-
return newObject;
|
|
288
|
-
}
|
|
289
|
-
return value;
|
|
290
|
-
}
|
|
291
|
-
toReferenceObj(prop, rootCollections) {
|
|
292
|
-
const propValue = this[prop.name];
|
|
293
|
-
const collectionPath = (value) => {
|
|
294
|
-
let storeInCollection;
|
|
295
|
-
if (typeof prop.storeInCollection === 'function') {
|
|
296
|
-
storeInCollection = prop.storeInCollection(value, prop);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
storeInCollection = prop.storeInCollection || value.className;
|
|
300
|
-
}
|
|
301
|
-
return storeInCollection;
|
|
302
|
-
};
|
|
303
|
-
if (Array.isArray(propValue)) {
|
|
304
|
-
return propValue.map(item => {
|
|
305
|
-
if (!prop.isPureReference) {
|
|
306
|
-
this.pushDocument(rootCollections, collectionPath(item), item);
|
|
307
|
-
}
|
|
308
|
-
return this.buildRefObject(item, collectionPath(item), prop.forcedPersistentProps);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
if (!prop.isPureReference) {
|
|
313
|
-
this.pushDocument(rootCollections, collectionPath(propValue), propValue);
|
|
314
|
-
}
|
|
315
|
-
return this.buildRefObject(propValue, collectionPath(propValue), prop.forcedPersistentProps);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
buildRefObject(value, storeInCollection, forcedPersistentProps) {
|
|
319
|
-
const forcedObject = forcedPersistentProps?.reduce((obj, propName) => {
|
|
320
|
-
if (value[propName] !== undefined)
|
|
321
|
-
obj[propName] = value[propName];
|
|
322
|
-
return obj;
|
|
323
|
-
}, {});
|
|
324
|
-
return {
|
|
325
|
-
id: value.id,
|
|
326
|
-
__className: value.className || value['__className'],
|
|
327
|
-
__documentReference: {
|
|
328
|
-
storedInCollection: storeInCollection
|
|
329
|
-
},
|
|
330
|
-
...forcedObject
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
pushDocument(collections, collectionName, value) {
|
|
334
|
-
if ('__documentReference' in value && value.__documentReference)
|
|
335
|
-
return;
|
|
336
|
-
if (!collections[collectionName])
|
|
337
|
-
collections[collectionName] = [];
|
|
338
|
-
const document = this.toDeepObj(value, collections);
|
|
339
|
-
collections[collectionName].push(document);
|
|
340
|
-
}
|
|
341
|
-
removeUnderscore(prop) {
|
|
342
|
-
return prop.name.slice(1);
|
|
343
|
-
}
|
|
344
|
-
static createReference(obj) {
|
|
345
|
-
const instance = Persistent.createInstance(obj);
|
|
346
|
-
instance['__documentReference'] = obj['__documentReference'] || { storedInCollection: instance.className };
|
|
347
|
-
return instance;
|
|
348
|
-
}
|
|
349
|
-
static createInstance(obj) {
|
|
350
|
-
if (typeof obj === 'string') {
|
|
351
|
-
return new (Persistent.classFactory(obj));
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
try {
|
|
355
|
-
const instance = new (Persistent.classFactory(obj.__className));
|
|
356
|
-
return instance.fromObject(obj);
|
|
357
|
-
}
|
|
358
|
-
catch (e) {
|
|
359
|
-
const stringifiedObj = Object.entries(obj)
|
|
360
|
-
.filter(([_key, value]) => value !== undefined && value !== null && typeof value !== 'function')
|
|
361
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
362
|
-
.join(',\n\t');
|
|
363
|
-
throw new Error(`${e}\n-----> Class name not found in object:\n{\n\t ${stringifiedObj} \n}\n`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
static propInfo(registeredClassName, propName) {
|
|
368
|
-
const inst = Persistent.createInstance(registeredClassName);
|
|
369
|
-
return inst.getPropInfo(propName);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
exports.Persistent = Persistent;
|
|
373
|
-
Persistent._factoryMap = {};
|
|
374
|
-
__decorate([
|
|
375
|
-
persistent
|
|
376
|
-
], Persistent.prototype, "_id", void 0);
|
|
377
|
-
/**
|
|
378
|
-
* Decorator for a property that you want to persist.
|
|
379
|
-
*/
|
|
380
|
-
function persistent(target, property) {
|
|
381
|
-
return persistentParser()(target, property);
|
|
382
|
-
}
|
|
383
|
-
exports.persistent = persistent;
|
|
384
|
-
/**
|
|
385
|
-
* Decorator for a property that is a reference to a persistent object and should be stored
|
|
386
|
-
* in a specific collection.
|
|
387
|
-
* @param collectionPath the path to the collection where the reference should be stored.
|
|
388
|
-
* @returns
|
|
389
|
-
*/
|
|
390
|
-
function persistentReferenceAt(collectionPath) {
|
|
391
|
-
return function (target, property) {
|
|
392
|
-
return persistentParser({
|
|
393
|
-
storeInCollection: collectionPath,
|
|
394
|
-
isReference: true
|
|
395
|
-
})(target, property);
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
exports.persistentReferenceAt = persistentReferenceAt;
|
|
399
|
-
/**
|
|
400
|
-
* Decorator for a property that is a reference to a persistent object.
|
|
401
|
-
* The reference content is automatically stored in a collection. The collection
|
|
402
|
-
* is determined by the class name of the decorated property.
|
|
403
|
-
* @see persistentPureReference
|
|
404
|
-
*/
|
|
405
|
-
function persistentReference(target, property) {
|
|
406
|
-
return persistentParser({ isReference: true })(target, property);
|
|
407
|
-
}
|
|
408
|
-
exports.persistentReference = persistentReference;
|
|
409
|
-
/**
|
|
410
|
-
* Decorator to declare a persistent reference (see @persistentReference) that stores
|
|
411
|
-
* the values in forcedPersistentProps as values in the reference object. This is useful
|
|
412
|
-
* when you are not able to wait for population of referenced properties.
|
|
413
|
-
* @param forcedPersistentProps the properties whose values should be stored in the reference object
|
|
414
|
-
* @param storedInCollection indicates the path of the collection where this reference is stored
|
|
415
|
-
*/
|
|
416
|
-
function persistentReferenceWithPersistentProps(forcedPersistentProps, storeInCollection) {
|
|
417
|
-
return function (target, property) {
|
|
418
|
-
const persistentProps = {
|
|
419
|
-
isReference: true,
|
|
420
|
-
forcedPersistentProps: forcedPersistentProps,
|
|
421
|
-
storeInCollection: storeInCollection
|
|
422
|
-
};
|
|
423
|
-
return persistentParser(persistentProps)(target, property);
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
exports.persistentReferenceWithPersistentProps = persistentReferenceWithPersistentProps;
|
|
427
|
-
/**
|
|
428
|
-
* Decorator for a property that is a reference to a persistent object.
|
|
429
|
-
* In this case, and contrary to the @persistentReference decorator, the reference
|
|
430
|
-
* contents is not stored even it has been changed. Only the reference information
|
|
431
|
-
* is stored.
|
|
432
|
-
* @see persistentReference
|
|
433
|
-
*/
|
|
434
|
-
function persistentPureReference(target, property, storeInCollection) {
|
|
435
|
-
return persistentParser({ isReference: true, isPureReference: true, storeInCollection })(target, property);
|
|
436
|
-
}
|
|
437
|
-
exports.persistentPureReference = persistentPureReference;
|
|
438
|
-
/**
|
|
439
|
-
* Decorator to declare a persistent property as a pure reference (see @persistentPureReference) that stores
|
|
440
|
-
* the values of the properties listed in forcedPersistentProps as values in the reference object. This is useful
|
|
441
|
-
* when you only need a few properties to be available without needing to populate the referenced property.
|
|
442
|
-
* @param forcedPersistentProps the properties whose values should be stored in the reference object
|
|
443
|
-
* @param storedInCollection indicates the path of the collection where this reference is stored
|
|
444
|
-
* @see persistentReferenceWithPersistentProps
|
|
445
|
-
* @see persistentPureReference
|
|
446
|
-
* @sample
|
|
447
|
-
* class User extends Persistent {
|
|
448
|
-
* @persistentPureReferenceWithPersistentProps( ['name', 'email'] ) private _friend: User
|
|
449
|
-
* }
|
|
450
|
-
* // the reference object will contain the properties name and email of the referenced user
|
|
451
|
-
* // without having to populate the _friend property
|
|
452
|
-
*/
|
|
453
|
-
function persistentPureReferenceWithPersistentProps(forcedPersistentProps, storeInCollection) {
|
|
454
|
-
return function (target, property) {
|
|
455
|
-
return persistentParser({ isReference: true, isPureReference: true, forcedPersistentProps: forcedPersistentProps, storeInCollection })(target, property);
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
exports.persistentPureReferenceWithPersistentProps = persistentPureReferenceWithPersistentProps;
|
|
459
|
-
function persistentParser(options) {
|
|
460
|
-
return function (target, property) {
|
|
461
|
-
// from: https://stackoverflow.com/questions/43912168/typescript-decorators-with-inheritance
|
|
462
|
-
// should work like this in order to avoid propagation of persistent properties from one class to others
|
|
463
|
-
if (!Object.getOwnPropertyDescriptor(target, '_persistentProperties')) {
|
|
464
|
-
if (target['_persistentProperties']) {
|
|
465
|
-
target['_persistentProperties'] = [...target['_persistentProperties']];
|
|
466
|
-
}
|
|
467
|
-
else
|
|
468
|
-
target['_persistentProperties'] = [];
|
|
469
|
-
}
|
|
470
|
-
const propInfo = target['_persistentProperties'].find(prop => prop.name === property);
|
|
471
|
-
if (propInfo) {
|
|
472
|
-
Object.assign(propInfo, options);
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
target['_persistentProperties'].push({
|
|
476
|
-
name: property,
|
|
477
|
-
...options
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
exports.persistentParser = persistentParser;
|
|
483
|
-
/**
|
|
484
|
-
* Decorator to register a persistent class. Entropic Bond needs that you register
|
|
485
|
-
* all persistent classes that you want to use in any persistent stream.
|
|
486
|
-
* @param className the name of the class
|
|
487
|
-
* @param annotation an optional annotation that can be used to store additional information
|
|
488
|
-
*/
|
|
489
|
-
function registerPersistentClass(className, annotation) {
|
|
490
|
-
return (constructor) => {
|
|
491
|
-
Persistent.registerFactory(className, constructor, annotation);
|
|
492
|
-
constructor.prototype.__className = className;
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
exports.registerPersistentClass = registerPersistentClass;
|
|
496
|
-
/**
|
|
497
|
-
* Decorator to register a legacy name for a persistent class. This is useful when you want to
|
|
498
|
-
* be able to load old data that was stored with a different class name.
|
|
499
|
-
* @param legacyName the legacy name of the class
|
|
500
|
-
*/
|
|
501
|
-
function registerLegacyClassName(legacyName) {
|
|
502
|
-
return (constructor) => {
|
|
503
|
-
Persistent.registerFactory(legacyName, constructor);
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
exports.registerLegacyClassName = registerLegacyClassName;
|
|
507
|
-
/**
|
|
508
|
-
* Decorator to make a `Persistent` array property searchable by the
|
|
509
|
-
* persistance engine.
|
|
510
|
-
* When a property is marked as searchable, the persistance engine will
|
|
511
|
-
* generate internally a new property with the same name but with the suffix `_searchable`
|
|
512
|
-
* and prefixed with the `_` character. This new property will contain an array
|
|
513
|
-
* with the `id` of the persistent elements in the original array.
|
|
514
|
-
*/
|
|
515
|
-
function searchableArray(target, property) {
|
|
516
|
-
return persistentParser({ searchableArray: true })(target, property);
|
|
517
|
-
}
|
|
518
|
-
exports.searchableArray = searchableArray;
|
|
519
|
-
/**
|
|
520
|
-
* Decorator to mark the property as required.
|
|
521
|
-
* @see requiredWithValidator
|
|
522
|
-
*/
|
|
523
|
-
function required(target, property) {
|
|
524
|
-
return persistentParser({ validator: (value) => value !== undefined && value !== null })(target, property);
|
|
525
|
-
}
|
|
526
|
-
exports.required = required;
|
|
527
|
-
/**
|
|
528
|
-
* Decorator to mark the property as required.
|
|
529
|
-
* @param validator a function that returns true if the property value is valid.
|
|
530
|
-
* By default, the property is valid if it is not undefined and not null.
|
|
531
|
-
* @see required
|
|
532
|
-
*/
|
|
533
|
-
function requiredWithValidator(validator = (value) => value !== undefined && value !== null) {
|
|
534
|
-
return function (target, property) {
|
|
535
|
-
return persistentParser({ validator: validator })(target, property);
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
exports.requiredWithValidator = requiredWithValidator;
|
|
539
|
-
//# sourceMappingURL=persistent.js.map
|
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AAE,IAAI,EAAE,CAAC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAAA;AACvE,CAAC;AAFD,0CAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAE,MAAkB,EAAE,QAAgB;IAC7D,OAAO,gBAAgB,CAAC,EAAE,SAAS,EAAE,CAAE,KAAU,EAAG,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAAA;AACpH,CAAC;AAFD,4BAEC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAqD,YAAqC,CAAE,KAAW,EAAG,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;IACtL,OAAO,UAAU,MAAS,EAAE,QAA4B;QACvD,OAAO,gBAAgB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAAA;IACtE,CAAC,CAAA;AACF,CAAC;AAJD,sDAIC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { UserCredentials } from '../auth/user-auth-types';
|
|
2
|
-
import { Collection } from '../types/utility-types';
|
|
3
|
-
import { ServerAuthService, CustomCredentials } from './server-auth';
|
|
4
|
-
export declare class ServerAuthMock extends ServerAuthService {
|
|
5
|
-
constructor(userCredentials: Collection<UserCredentials<{}>>);
|
|
6
|
-
getUser<T extends CustomCredentials>(userId: string): Promise<UserCredentials<T> | undefined>;
|
|
7
|
-
setCustomCredentials<T extends CustomCredentials>(userId: string, customCredentials: T): Promise<void>;
|
|
8
|
-
updateUser<T extends CustomCredentials>(userId: string, credentials: Partial<UserCredentials<T>>): Promise<UserCredentials<T>>;
|
|
9
|
-
deleteUser(userId: string): Promise<void>;
|
|
10
|
-
get userCredentials(): Collection<UserCredentials<{}>>;
|
|
11
|
-
private _userCredentials;
|
|
12
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServerAuthMock = void 0;
|
|
4
|
-
const server_auth_1 = require("./server-auth");
|
|
5
|
-
class ServerAuthMock extends server_auth_1.ServerAuthService {
|
|
6
|
-
constructor(userCredentials) {
|
|
7
|
-
super();
|
|
8
|
-
this._userCredentials = userCredentials;
|
|
9
|
-
}
|
|
10
|
-
getUser(userId) {
|
|
11
|
-
if (!this._userCredentials[userId])
|
|
12
|
-
Promise.resolve(undefined);
|
|
13
|
-
return Promise.resolve(this._userCredentials[userId]);
|
|
14
|
-
}
|
|
15
|
-
setCustomCredentials(userId, customCredentials) {
|
|
16
|
-
const userCredentials = this._userCredentials[userId];
|
|
17
|
-
if (!userCredentials)
|
|
18
|
-
throw new Error(`User ${userId} not found in the auth system`);
|
|
19
|
-
userCredentials.customData = { ...customCredentials };
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
updateUser(userId, credentials) {
|
|
23
|
-
this._userCredentials[userId] = {
|
|
24
|
-
...this._userCredentials,
|
|
25
|
-
...credentials,
|
|
26
|
-
id: userId
|
|
27
|
-
};
|
|
28
|
-
return Promise.resolve(this._userCredentials[userId]);
|
|
29
|
-
}
|
|
30
|
-
deleteUser(userId) {
|
|
31
|
-
delete this._userCredentials[userId];
|
|
32
|
-
return Promise.resolve();
|
|
33
|
-
}
|
|
34
|
-
get userCredentials() {
|
|
35
|
-
return this._userCredentials;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.ServerAuthMock = ServerAuthMock;
|
|
39
|
-
//# sourceMappingURL=server-auth-mock.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-auth-mock.js","sourceRoot":"","sources":["../../src/server-auth/server-auth-mock.ts"],"names":[],"mappings":";;;AAEA,+CAAoE;AAEpE,MAAa,cAAe,SAAQ,+BAAiB;IACpD,YAAa,eAAgD;QAC5D,KAAK,EAAE,CAAA;QACP,IAA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-
export declare abstract class ServerAuthService {
|
|
6
|
-
abstract setCustomCredentials<T extends CustomCredentials>(userId: string, customCredentials: T): Promise<void>;
|
|
7
|
-
abstract getUser<T extends CustomCredentials>(userId: string): Promise<UserCredentials<T> | undefined>;
|
|
8
|
-
abstract updateUser<T extends CustomCredentials>(userId: string, credentials: Partial<UserCredentials<T>>): Promise<UserCredentials<T>>;
|
|
9
|
-
abstract deleteUser(userId: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare class ServerAuth extends ServerAuthService {
|
|
12
|
-
static error: {
|
|
13
|
-
shouldBeRegistered: string;
|
|
14
|
-
};
|
|
15
|
-
protected constructor();
|
|
16
|
-
static useServerAuthService(authService: ServerAuthService): void;
|
|
17
|
-
static get instance(): ServerAuth;
|
|
18
|
-
getUser<T extends CustomCredentials>(userId: string): Promise<UserCredentials<T> | undefined>;
|
|
19
|
-
updateUser<T extends CustomCredentials>(userId: string, credentials: Partial<UserCredentials<T>>): Promise<UserCredentials<T>>;
|
|
20
|
-
setCustomCredentials<T extends CustomCredentials>(userId: string, customCredentials: T): Promise<void>;
|
|
21
|
-
deleteUser(userId: string): Promise<void>;
|
|
22
|
-
private static _instance;
|
|
23
|
-
private static _authService;
|
|
24
|
-
}
|