@pocket-architect/core 0.1.13 → 0.1.16
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/build/EntityId.d.ts +1 -1
- package/build/EntityId.js +5 -4
- package/build/EntityId.js.map +1 -1
- package/build/EntityId.spec.js +3 -2
- package/build/EntityId.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/EntityId.spec.ts +3 -1
- package/src/EntityId.ts +4 -4
package/build/EntityId.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class EntityId<T> {
|
|
2
2
|
protected _recordId: T | null;
|
|
3
3
|
protected _uuid: string;
|
|
4
|
-
constructor(recordId?: T, uuid?: string);
|
|
4
|
+
constructor(recordId?: T, isHash?: boolean, uuid?: string);
|
|
5
5
|
private createUUID;
|
|
6
6
|
get hashOptions(): [string, number];
|
|
7
7
|
toHash(): string;
|
package/build/EntityId.js
CHANGED
|
@@ -6,12 +6,16 @@ var uuid_by_string_1 = tslib_1.__importDefault(require("uuid-by-string"));
|
|
|
6
6
|
var cuid2_1 = require("@paralleldrive/cuid2");
|
|
7
7
|
var hashids_1 = tslib_1.__importDefault(require("hashids"));
|
|
8
8
|
var EntityId = /** @class */ (function () {
|
|
9
|
-
function EntityId(recordId, uuid) {
|
|
9
|
+
function EntityId(recordId, isHash, uuid) {
|
|
10
10
|
if (recordId === void 0) { recordId = null; }
|
|
11
|
+
if (isHash === void 0) { isHash = false; }
|
|
11
12
|
if (uuid === void 0) { uuid = null; }
|
|
12
13
|
this._recordId = null;
|
|
13
14
|
this._uuid = null;
|
|
14
15
|
this._recordId = recordId ? recordId : null;
|
|
16
|
+
if (isHash) {
|
|
17
|
+
this.fromHash(recordId);
|
|
18
|
+
}
|
|
15
19
|
if (!uuid) {
|
|
16
20
|
this.createUUID();
|
|
17
21
|
}
|
|
@@ -34,9 +38,6 @@ var EntityId = /** @class */ (function () {
|
|
|
34
38
|
return hashids.encode(this.toPrimitive().toString());
|
|
35
39
|
};
|
|
36
40
|
EntityId.prototype.fromHash = function (hash) {
|
|
37
|
-
if (!this._recordId) {
|
|
38
|
-
throw new Error('Cannot hash an empty recordId');
|
|
39
|
-
}
|
|
40
41
|
var hashids = new (hashids_1.default.bind.apply(hashids_1.default, tslib_1.__spreadArray([void 0], this.hashOptions, false)))();
|
|
41
42
|
var num = hashids.decode(hash)[0];
|
|
42
43
|
this._recordId = (typeof this._recordId === 'string' ? num.toString() : num);
|
package/build/EntityId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityId.js","sourceRoot":"","sources":["../src/EntityId.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,8CAA+C;AAC/C,4DAA8B;AAE9B;IAIE,kBAAY,QAAkB,EAAE,IAAmB;
|
|
1
|
+
{"version":3,"file":"EntityId.js","sourceRoot":"","sources":["../src/EntityId.ts"],"names":[],"mappings":";;;;AAAA,0EAAuC;AACvC,8CAA+C;AAC/C,4DAA8B;AAE9B;IAIE,kBAAY,QAAkB,EAAE,MAAsB,EAAE,IAAmB;QAA/D,yBAAA,EAAA,eAAkB;QAAE,uBAAA,EAAA,cAAsB;QAAE,qBAAA,EAAA,WAAmB;QAHjE,cAAS,GAAW,IAAI,CAAC;QACzB,UAAK,GAAW,IAAI,CAAC;QAG7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,CAAC,QAAkB,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAEO,6BAAU,GAAlB;QACE,IAAI,CAAC,KAAK,GAAG,IAAA,wBAAU,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CA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C;AAAD,CAAC,AAjDD,IAiDC;AAjDY,4BAAQ"}
|
package/build/EntityId.spec.js
CHANGED
|
@@ -18,13 +18,15 @@ var Test2Id = /** @class */ (function (_super) {
|
|
|
18
18
|
}(EntityId_1.EntityId));
|
|
19
19
|
describe('ValueObject', function () {
|
|
20
20
|
test('base', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
21
|
-
var id, id2, id3;
|
|
21
|
+
var id, id2, id3, id4;
|
|
22
22
|
return tslib_1.__generator(this, function (_a) {
|
|
23
23
|
id = new TestId(1);
|
|
24
24
|
id2 = new EntityId_1.EntityId('1');
|
|
25
25
|
id3 = new TestId(1);
|
|
26
26
|
expect(id).toEqual(id3);
|
|
27
27
|
expect(id).not.toEqual(id2);
|
|
28
|
+
id4 = new Test2Id('9KdMR', true);
|
|
29
|
+
expect(id4.toPrimitive()).toEqual('123');
|
|
28
30
|
return [2 /*return*/];
|
|
29
31
|
});
|
|
30
32
|
}); });
|
|
@@ -41,7 +43,6 @@ describe('ValueObject', function () {
|
|
|
41
43
|
expect(id2.fromHash('BJejP').toPrimitive()).toEqual(123);
|
|
42
44
|
id3 = new Test2Id();
|
|
43
45
|
expect(function () { return id3.toHash(); }).toThrow('Cannot hash an empty recordId');
|
|
44
|
-
expect(function () { return id3.fromHash('123'); }).toThrow('Cannot hash an empty recordId');
|
|
45
46
|
return [2 /*return*/];
|
|
46
47
|
});
|
|
47
48
|
}); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityId.spec.js","sourceRoot":"","sources":["../src/EntityId.spec.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC;IAAqB,kCAAgB;IAArC;;IACA,CAAC;IAAD,aAAC;AAAD,CAAC,AADD,CAAqB,mBAAQ,GAC5B;AAED;IAAsB,mCAAgB;IAAtC;;IACA,CAAC;IAAD,cAAC;AAAD,CAAC,AADD,CAAsB,mBAAQ,GAC7B;AAED,QAAQ,CAAC,aAAa,EAAE;IACtB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AAC,KAAK,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxD,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACtC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;YAEhE,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAEnD,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,CAAC,cAAM,OAAA,GAAG,CAAC,MAAM,EAAE,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;;;SACrE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/EntityId.spec.ts
CHANGED
|
@@ -13,6 +13,9 @@ describe('ValueObject', () => {
|
|
|
13
13
|
const id3 = new TestId(1);
|
|
14
14
|
expect(id).toEqual(id3);
|
|
15
15
|
expect(id).not.toEqual(id2);
|
|
16
|
+
|
|
17
|
+
const id4 = new Test2Id('9KdMR', true);
|
|
18
|
+
expect(id4.toPrimitive()).toEqual('123')
|
|
16
19
|
});
|
|
17
20
|
|
|
18
21
|
test('toHash', async () => {
|
|
@@ -28,6 +31,5 @@ describe('ValueObject', () => {
|
|
|
28
31
|
|
|
29
32
|
const id3 = new Test2Id();
|
|
30
33
|
expect(() => id3.toHash()).toThrow('Cannot hash an empty recordId');
|
|
31
|
-
expect(() => id3.fromHash('123')).toThrow('Cannot hash an empty recordId');
|
|
32
34
|
});
|
|
33
35
|
});
|
package/src/EntityId.ts
CHANGED
|
@@ -6,8 +6,11 @@ export class EntityId<T> {
|
|
|
6
6
|
protected _recordId: T|null = null;
|
|
7
7
|
protected _uuid: string = null;
|
|
8
8
|
|
|
9
|
-
constructor(recordId: T = null, uuid: string = null) {
|
|
9
|
+
constructor(recordId: T = null, isHash:boolean = false, uuid: string = null) {
|
|
10
10
|
this._recordId = recordId ? recordId : null;
|
|
11
|
+
if (isHash) {
|
|
12
|
+
this.fromHash(recordId as string);
|
|
13
|
+
}
|
|
11
14
|
if (!uuid) {
|
|
12
15
|
this.createUUID();
|
|
13
16
|
}
|
|
@@ -30,9 +33,6 @@ export class EntityId<T> {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
fromHash(hash: string) : EntityId<T> {
|
|
33
|
-
if (!this._recordId) {
|
|
34
|
-
throw new Error('Cannot hash an empty recordId');
|
|
35
|
-
}
|
|
36
36
|
const hashids = new Hashids(...this.hashOptions);
|
|
37
37
|
const num = hashids.decode(hash)[0];
|
|
38
38
|
this._recordId = <T>(typeof this._recordId === 'string' ? num.toString() : num);
|