@nymphjs/nymph 1.0.0-alpha.9 → 1.0.0-beta.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/CHANGELOG.md +161 -0
- package/dist/Entity.d.ts +2 -2
- package/dist/Entity.js +56 -3
- package/dist/Entity.js.map +1 -1
- package/dist/Entity.test.js +1 -0
- package/dist/Entity.test.js.map +1 -1
- package/dist/Entity.types.d.ts +7 -7
- package/dist/Nymph.d.ts +6 -0
- package/dist/Nymph.js +17 -14
- package/dist/Nymph.js.map +1 -1
- package/dist/Nymph.types.d.ts +36 -36
- package/dist/driver/NymphDriver.d.ts +33 -6
- package/dist/driver/NymphDriver.js +36 -12
- package/dist/driver/NymphDriver.js.map +1 -1
- package/dist/driver/index.js +5 -1
- package/dist/driver/index.js.map +1 -1
- package/dist/driver/testArtifacts.js +49 -22
- package/dist/driver/testArtifacts.js.map +1 -1
- package/dist/errors/index.js +5 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/nymphJoiProps.d.ts +4 -4
- package/dist/nymphJoiProps.js +2 -4
- package/dist/nymphJoiProps.js.map +1 -1
- package/dist/testArtifacts.d.ts +1 -1
- package/dist/testArtifacts.js +11 -11
- package/dist/testArtifacts.js.map +1 -1
- package/dist/testMocks.js +2 -2
- package/dist/testMocks.js.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +48 -1
- package/dist/utils.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +12 -16
- package/src/Entity.test.ts +2 -0
- package/src/Entity.ts +85 -5
- package/src/Nymph.ts +19 -8
- package/src/Nymph.types.ts +11 -11
- package/src/driver/NymphDriver.ts +90 -15
- package/src/driver/testArtifacts.ts +71 -22
- package/src/index.ts +0 -3
- package/src/nymphJoiProps.ts +4 -6
- package/src/testMocks.ts +3 -2
- package/src/utils.ts +59 -0
- package/dist/newGUID.d.ts +0 -1
- package/dist/newGUID.js +0 -14
- package/dist/newGUID.js.map +0 -1
- package/src/newGUID.ts +0 -11
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import strtotime from 'locutus/php/datetime/strtotime';
|
|
3
|
+
import { guid } from '@nymphjs/guid';
|
|
3
4
|
|
|
4
5
|
import type Nymph from '../Nymph';
|
|
5
|
-
import newGUID from '../newGUID';
|
|
6
6
|
import { TestBModel, TestModel, TestModelData } from '../testArtifacts';
|
|
7
7
|
|
|
8
8
|
export function QueriesTest(
|
|
@@ -131,7 +131,7 @@ This one's zip code is 92064.`;
|
|
|
131
131
|
expect(testEntity.$is(resultEntity)).toEqual(true);
|
|
132
132
|
|
|
133
133
|
// Testing wrong GUID...
|
|
134
|
-
resultEntity = await nymph.getEntity({ class: TestModel },
|
|
134
|
+
resultEntity = await nymph.getEntity({ class: TestModel }, guid());
|
|
135
135
|
expect(testEntity.$is(resultEntity)).toEqual(false);
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -259,7 +259,7 @@ This one's zip code is 92064.`;
|
|
|
259
259
|
// Retrieving entity by GUID and tags...
|
|
260
260
|
const resultEntity = await nymph.getEntity(
|
|
261
261
|
{ class: TestModel },
|
|
262
|
-
{ type: '|', guid: [testGuid,
|
|
262
|
+
{ type: '|', guid: [testGuid, guid()] }
|
|
263
263
|
);
|
|
264
264
|
expect(testEntity.$is(resultEntity)).toEqual(true);
|
|
265
265
|
});
|
|
@@ -270,7 +270,7 @@ This one's zip code is 92064.`;
|
|
|
270
270
|
// Retrieving entity by GUID and tags...
|
|
271
271
|
const resultEntity = await nymph.getEntity(
|
|
272
272
|
{ class: TestModel },
|
|
273
|
-
{ type: '|', guid: [
|
|
273
|
+
{ type: '|', guid: [guid(), guid()] }
|
|
274
274
|
);
|
|
275
275
|
expect(testEntity.$is(resultEntity)).toEqual(false);
|
|
276
276
|
});
|
|
@@ -281,7 +281,7 @@ This one's zip code is 92064.`;
|
|
|
281
281
|
// Retrieving entity by !GUID...
|
|
282
282
|
const resultEntity = await nymph.getEntities(
|
|
283
283
|
{ class: TestModel },
|
|
284
|
-
{ type: '&', '!guid':
|
|
284
|
+
{ type: '&', '!guid': guid(), tag: 'test' }
|
|
285
285
|
);
|
|
286
286
|
expect(testEntity.$inArray(resultEntity)).toEqual(true);
|
|
287
287
|
});
|
|
@@ -1185,7 +1185,7 @@ This one's zip code is 92064.`;
|
|
|
1185
1185
|
const resultEntity = await nymph.getEntities(
|
|
1186
1186
|
{ class: TestModel },
|
|
1187
1187
|
{ type: '&', tag: 'test' },
|
|
1188
|
-
{ type: '!&', ref: ['reference',
|
|
1188
|
+
{ type: '!&', ref: ['reference', guid()] }
|
|
1189
1189
|
);
|
|
1190
1190
|
expect(testEntity.$inArray(resultEntity)).toEqual(true);
|
|
1191
1191
|
});
|
|
@@ -1196,7 +1196,7 @@ This one's zip code is 92064.`;
|
|
|
1196
1196
|
// Testing wrong reference...
|
|
1197
1197
|
const resultEntity = await nymph.getEntities(
|
|
1198
1198
|
{ class: TestModel },
|
|
1199
|
-
{ type: '&', ref: ['reference',
|
|
1199
|
+
{ type: '&', ref: ['reference', guid()] }
|
|
1200
1200
|
);
|
|
1201
1201
|
expect(testEntity.$inArray(resultEntity)).toEqual(false);
|
|
1202
1202
|
});
|
|
@@ -1222,7 +1222,7 @@ This one's zip code is 92064.`;
|
|
|
1222
1222
|
type: '|',
|
|
1223
1223
|
ref: [
|
|
1224
1224
|
['reference', refGuid],
|
|
1225
|
-
['reference',
|
|
1225
|
+
['reference', guid()],
|
|
1226
1226
|
],
|
|
1227
1227
|
}
|
|
1228
1228
|
);
|
|
@@ -1238,8 +1238,8 @@ This one's zip code is 92064.`;
|
|
|
1238
1238
|
{
|
|
1239
1239
|
type: '|',
|
|
1240
1240
|
ref: [
|
|
1241
|
-
['reference',
|
|
1242
|
-
['reference',
|
|
1241
|
+
['reference', guid()],
|
|
1242
|
+
['reference', guid()],
|
|
1243
1243
|
],
|
|
1244
1244
|
}
|
|
1245
1245
|
);
|
|
@@ -1267,7 +1267,7 @@ This one's zip code is 92064.`;
|
|
|
1267
1267
|
type: '&',
|
|
1268
1268
|
ref: [
|
|
1269
1269
|
['refArray', refGuid],
|
|
1270
|
-
['refArray',
|
|
1270
|
+
['refArray', guid()],
|
|
1271
1271
|
],
|
|
1272
1272
|
}
|
|
1273
1273
|
);
|
|
@@ -1283,8 +1283,8 @@ This one's zip code is 92064.`;
|
|
|
1283
1283
|
{
|
|
1284
1284
|
type: '&',
|
|
1285
1285
|
'!ref': [
|
|
1286
|
-
['refArray',
|
|
1287
|
-
['refArray',
|
|
1286
|
+
['refArray', guid()],
|
|
1287
|
+
['refArray', guid()],
|
|
1288
1288
|
],
|
|
1289
1289
|
'!lte': ['number', 29.99],
|
|
1290
1290
|
},
|
|
@@ -1319,6 +1319,55 @@ This one's zip code is 92064.`;
|
|
|
1319
1319
|
expect(testEntity.$inArray(resultEntity)).toEqual(true);
|
|
1320
1320
|
});
|
|
1321
1321
|
|
|
1322
|
+
it('count return', async () => {
|
|
1323
|
+
await createTestEntities();
|
|
1324
|
+
|
|
1325
|
+
const result = await nymph.getEntities({ class: TestModel });
|
|
1326
|
+
|
|
1327
|
+
// Testing count return...
|
|
1328
|
+
const resultCount = await nymph.getEntities({
|
|
1329
|
+
class: TestModel,
|
|
1330
|
+
return: 'count',
|
|
1331
|
+
});
|
|
1332
|
+
expect(resultCount).toBeGreaterThanOrEqual(1);
|
|
1333
|
+
expect(resultCount).toEqual(result.length);
|
|
1334
|
+
|
|
1335
|
+
const resultSelectors = await nymph.getEntities(
|
|
1336
|
+
{ class: TestModel },
|
|
1337
|
+
{ type: '&', ref: ['reference', refGuid] }
|
|
1338
|
+
);
|
|
1339
|
+
|
|
1340
|
+
// Testing count return with selectors...
|
|
1341
|
+
const resultSelectorsCount = await nymph.getEntities(
|
|
1342
|
+
{ class: TestModel, return: 'count' },
|
|
1343
|
+
{ type: '&', ref: ['reference', refGuid] }
|
|
1344
|
+
);
|
|
1345
|
+
expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
|
|
1346
|
+
expect(resultSelectorsCount).toEqual(resultSelectors.length);
|
|
1347
|
+
|
|
1348
|
+
// Testing count return with limit...
|
|
1349
|
+
const resultSelectorsLimit = await nymph.getEntities({
|
|
1350
|
+
class: TestModel,
|
|
1351
|
+
limit: 1,
|
|
1352
|
+
return: 'count',
|
|
1353
|
+
});
|
|
1354
|
+
expect(resultSelectorsLimit).toEqual(1);
|
|
1355
|
+
|
|
1356
|
+
// Testing count return with limit...
|
|
1357
|
+
const resultSelectorsSingle = await nymph.getEntity({
|
|
1358
|
+
class: TestModel,
|
|
1359
|
+
return: 'count',
|
|
1360
|
+
});
|
|
1361
|
+
expect(resultSelectorsSingle).toEqual(1);
|
|
1362
|
+
|
|
1363
|
+
// Testing empty count...
|
|
1364
|
+
const resultSelectorsEmpty = await nymph.getEntities(
|
|
1365
|
+
{ class: TestModel, return: 'count' },
|
|
1366
|
+
{ type: '&', ref: ['reference', guid()] }
|
|
1367
|
+
);
|
|
1368
|
+
expect(resultSelectorsEmpty).toEqual(0);
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1322
1371
|
it('guid return', async () => {
|
|
1323
1372
|
await createTestEntities();
|
|
1324
1373
|
|
|
@@ -1328,8 +1377,8 @@ This one's zip code is 92064.`;
|
|
|
1328
1377
|
{
|
|
1329
1378
|
type: '&',
|
|
1330
1379
|
'!ref': [
|
|
1331
|
-
['refArray',
|
|
1332
|
-
['refArray',
|
|
1380
|
+
['refArray', guid()],
|
|
1381
|
+
['refArray', guid()],
|
|
1333
1382
|
],
|
|
1334
1383
|
'!lte': ['number', 29.99],
|
|
1335
1384
|
},
|
|
@@ -1373,8 +1422,8 @@ This one's zip code is 92064.`;
|
|
|
1373
1422
|
{
|
|
1374
1423
|
type: '&',
|
|
1375
1424
|
'!ref': [
|
|
1376
|
-
['refArray',
|
|
1377
|
-
['refArray',
|
|
1425
|
+
['refArray', guid()],
|
|
1426
|
+
['refArray', guid()],
|
|
1378
1427
|
],
|
|
1379
1428
|
'!lte': ['number', 29.99],
|
|
1380
1429
|
},
|
|
@@ -1418,8 +1467,8 @@ This one's zip code is 92064.`;
|
|
|
1418
1467
|
{
|
|
1419
1468
|
type: '&',
|
|
1420
1469
|
'!ref': [
|
|
1421
|
-
['refArray',
|
|
1422
|
-
['refArray',
|
|
1470
|
+
['refArray', guid()],
|
|
1471
|
+
['refArray', guid()],
|
|
1423
1472
|
],
|
|
1424
1473
|
'!lte': ['number', 29.99],
|
|
1425
1474
|
},
|
|
@@ -1465,7 +1514,7 @@ This one's zip code is 92064.`;
|
|
|
1465
1514
|
selector: [
|
|
1466
1515
|
{
|
|
1467
1516
|
type: '&',
|
|
1468
|
-
'!ref': ['refArray',
|
|
1517
|
+
'!ref': ['refArray', guid()],
|
|
1469
1518
|
'!lte': ['number', 29.99],
|
|
1470
1519
|
},
|
|
1471
1520
|
{ type: '&', gte: ['number', 16000] },
|
|
@@ -1481,7 +1530,7 @@ This one's zip code is 92064.`;
|
|
|
1481
1530
|
selector: [
|
|
1482
1531
|
{
|
|
1483
1532
|
type: '&',
|
|
1484
|
-
'!ref': ['refArray',
|
|
1533
|
+
'!ref': ['refArray', guid()],
|
|
1485
1534
|
'!lte': ['number', 29.99],
|
|
1486
1535
|
},
|
|
1487
1536
|
{
|
|
@@ -1506,7 +1555,7 @@ This one's zip code is 92064.`;
|
|
|
1506
1555
|
selector: [
|
|
1507
1556
|
{
|
|
1508
1557
|
type: '&',
|
|
1509
|
-
'!ref': ['refArray',
|
|
1558
|
+
'!ref': ['refArray', guid()],
|
|
1510
1559
|
'!lte': ['number', 29.99],
|
|
1511
1560
|
},
|
|
1512
1561
|
{ type: '&', gte: ['number', 16000] },
|
package/src/index.ts
CHANGED
package/src/nymphJoiProps.ts
CHANGED
|
@@ -15,12 +15,10 @@ export default {
|
|
|
15
15
|
.required(),
|
|
16
16
|
tags: Joi.array()
|
|
17
17
|
.items(
|
|
18
|
-
Joi.string()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
.min(1)
|
|
18
|
+
Joi.string().pattern(/[[\x01-\x1F\x7F]]/, {
|
|
19
|
+
name: 'control characters',
|
|
20
|
+
invert: true,
|
|
21
|
+
})
|
|
24
22
|
)
|
|
25
23
|
.required(),
|
|
26
24
|
};
|
package/src/testMocks.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { guid } from '@nymphjs/guid';
|
|
2
|
+
|
|
1
3
|
import type Nymph from './Nymph';
|
|
2
4
|
import { EntityConstructor, EntityInterface, EntityJson } from './Entity.types';
|
|
3
5
|
import { Options, Selector } from './Nymph.types';
|
|
4
|
-
import newGUID from './newGUID';
|
|
5
6
|
import { ClassNotAvailableError } from './errors';
|
|
6
7
|
import Entity from './Entity';
|
|
7
8
|
|
|
@@ -108,7 +109,7 @@ export class MockNymph {
|
|
|
108
109
|
const className = (entity.constructor as any).class as string;
|
|
109
110
|
|
|
110
111
|
if (entity.guid == null) {
|
|
111
|
-
entity.guid =
|
|
112
|
+
entity.guid = guid();
|
|
112
113
|
entity.cdate = Date.now();
|
|
113
114
|
} else if (
|
|
114
115
|
entity.guid in entities &&
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Entity from './Entity';
|
|
2
2
|
import { EntityReference } from './Entity.types';
|
|
3
3
|
import Nymph from './Nymph';
|
|
4
|
+
import { Options, Selector } from './Nymph.types';
|
|
4
5
|
|
|
5
6
|
export function xor(a: any, b: any): boolean {
|
|
6
7
|
return !!(a && !b) || (!a && b);
|
|
@@ -14,6 +15,64 @@ export function uniqueStrings(array: string[]) {
|
|
|
14
15
|
return Object.keys(obj);
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
export function classNamesToEntityConstructors(
|
|
19
|
+
nymph: Nymph,
|
|
20
|
+
selectors: Selector[]
|
|
21
|
+
): Selector[] {
|
|
22
|
+
const newSelectors: Selector[] = [];
|
|
23
|
+
|
|
24
|
+
for (const curSelector of selectors) {
|
|
25
|
+
const newSelector: Selector = { type: curSelector.type };
|
|
26
|
+
|
|
27
|
+
for (const k in curSelector) {
|
|
28
|
+
const key = k as keyof Selector;
|
|
29
|
+
const value = curSelector[key];
|
|
30
|
+
|
|
31
|
+
if (key === 'type') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (key === 'qref' || key === '!qref') {
|
|
40
|
+
const tmpArr = (
|
|
41
|
+
Array.isArray(((value as Selector['qref']) ?? [])[0])
|
|
42
|
+
? value
|
|
43
|
+
: [value]
|
|
44
|
+
) as [string, [Options, ...Selector[]]][];
|
|
45
|
+
for (let i = 0; i < tmpArr.length; i++) {
|
|
46
|
+
const name = tmpArr[i][0];
|
|
47
|
+
const [qrefOptions, ...selectors] = tmpArr[i][1];
|
|
48
|
+
const QrefEntityClass =
|
|
49
|
+
typeof qrefOptions.class === 'string'
|
|
50
|
+
? nymph.getEntityClass(qrefOptions.class)
|
|
51
|
+
: qrefOptions.class ?? nymph.getEntityClass('Entity');
|
|
52
|
+
const options = { ...qrefOptions, class: QrefEntityClass };
|
|
53
|
+
if (!newSelector[key]) {
|
|
54
|
+
newSelector[key] = [];
|
|
55
|
+
}
|
|
56
|
+
(newSelector[key] as [string, [Options, ...Selector[]]][]).push([
|
|
57
|
+
name,
|
|
58
|
+
[options, ...classNamesToEntityConstructors(nymph, selectors)],
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
} else if (key === 'selector' || key === '!selector') {
|
|
62
|
+
const tmpArr = (Array.isArray(value) ? value : [value]) as Selector[];
|
|
63
|
+
newSelector[key] = classNamesToEntityConstructors(nymph, tmpArr);
|
|
64
|
+
} else {
|
|
65
|
+
// @ts-ignore: ts doesn't know what value is here.
|
|
66
|
+
newSelector[key] = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
newSelectors.push(newSelector);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return newSelectors;
|
|
74
|
+
}
|
|
75
|
+
|
|
17
76
|
export function entitiesToReferences(item: any): any {
|
|
18
77
|
if (item instanceof Entity && typeof item.$toReference === 'function') {
|
|
19
78
|
// Convert entities to references.
|
package/dist/newGUID.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function newGUID(): string;
|
package/dist/newGUID.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const nanoid_1 = require("nanoid");
|
|
7
|
-
const luxon_1 = require("luxon");
|
|
8
|
-
const sha1_1 = __importDefault(require("sha1"));
|
|
9
|
-
const nanoid = (0, nanoid_1.customAlphabet)('0123456789abcdef', 20);
|
|
10
|
-
function newGUID() {
|
|
11
|
-
return `${(0, sha1_1.default)(`${luxon_1.DateTime.now().weekYear}${luxon_1.DateTime.now().weekNumber}`).slice(0, 4)}${nanoid()}`;
|
|
12
|
-
}
|
|
13
|
-
exports.default = newGUID;
|
|
14
|
-
//# sourceMappingURL=newGUID.js.map
|
package/dist/newGUID.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"newGUID.js","sourceRoot":"","sources":["../src/newGUID.ts"],"names":[],"mappings":";;;;;AAAA,mCAAwC;AACxC,iCAAiC;AACjC,gDAAwB;AAExB,MAAM,MAAM,GAAG,IAAA,uBAAc,EAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AAEtD,SAAwB,OAAO;IAC7B,OAAO,GAAG,IAAA,cAAI,EACZ,GAAG,gBAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,GAAG,gBAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CACzD,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;AAC7B,CAAC;AAJD,0BAIC"}
|
package/src/newGUID.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { customAlphabet } from 'nanoid';
|
|
2
|
-
import { DateTime } from 'luxon';
|
|
3
|
-
import sha1 from 'sha1';
|
|
4
|
-
|
|
5
|
-
const nanoid = customAlphabet('0123456789abcdef', 20);
|
|
6
|
-
|
|
7
|
-
export default function newGUID() {
|
|
8
|
-
return `${sha1(
|
|
9
|
-
`${DateTime.now().weekYear}${DateTime.now().weekNumber}`
|
|
10
|
-
).slice(0, 4)}${nanoid()}`;
|
|
11
|
-
}
|