@nymphjs/server 1.0.0-alpha.21 → 1.0.0-alpha.25

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 CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.25](https://github.com/sciactive/nymphjs/compare/v1.0.0-alpha.24...v1.0.0-alpha.25) (2021-12-30)
7
+
8
+ **Note:** Version bump only for package @nymphjs/server
9
+
10
+ # [1.0.0-alpha.24](https://github.com/sciactive/nymphjs/compare/v1.0.0-alpha.23...v1.0.0-alpha.24) (2021-12-30)
11
+
12
+ **Note:** Version bump only for package @nymphjs/server
13
+
14
+ # [1.0.0-alpha.23](https://github.com/sciactive/nymphjs/compare/v1.0.0-alpha.22...v1.0.0-alpha.23) (2021-12-30)
15
+
16
+ ### Features
17
+
18
+ - add optional weakly referenced cache to client lib ([fbb184c](https://github.com/sciactive/nymphjs/commit/fbb184c6a721968bb92cc9b05c328594618554ed))
19
+
20
+ # [1.0.0-alpha.22](https://github.com/sciactive/nymphjs/compare/v1.0.0-alpha.21...v1.0.0-alpha.22) (2021-12-14)
21
+
22
+ ### Features
23
+
24
+ - update smui to latest versions ([912873b](https://github.com/sciactive/nymphjs/commit/912873b863d1ae5d51c359a3c0558bff38ce85cd))
25
+
6
26
  # [1.0.0-alpha.21](https://github.com/sciactive/nymphjs/compare/v1.0.0-alpha.20...v1.0.0-alpha.21) (2021-11-29)
7
27
 
8
28
  **Note:** Version bump only for package @nymphjs/server
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const express_1 = __importDefault(require("express"));
16
+ const driver_sqlite3_1 = __importDefault(require("@nymphjs/driver-sqlite3"));
17
+ const nymph_1 = require("@nymphjs/nymph");
18
+ const client_node_1 = require("@nymphjs/client-node");
19
+ const index_1 = __importDefault(require("./index"));
20
+ const testArtifacts_1 = require("./testArtifacts");
21
+ const sqliteConfig = {
22
+ filename: ':memory:',
23
+ };
24
+ const nymphServer = new nymph_1.Nymph({}, new driver_sqlite3_1.default(sqliteConfig));
25
+ nymphServer.addEntityClass(testArtifacts_1.EmployeeModel);
26
+ const app = (0, express_1.default)();
27
+ app.use('/test', (0, index_1.default)(nymphServer));
28
+ const server = app.listen(5081);
29
+ const nymph = new client_node_1.Nymph({
30
+ restUrl: 'http://localhost:5081/test/',
31
+ weakCache: true,
32
+ });
33
+ nymph.addEntityClass(testArtifacts_1.Employee);
34
+ describe('Nymph REST Server and Client with Client Weak Ref Cache', () => {
35
+ function createJane() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const jane = yield testArtifacts_1.Employee.factory();
38
+ jane.name = 'Jane Doe';
39
+ jane.current = true;
40
+ jane.salary = 8000000;
41
+ jane.startDate = Date.now();
42
+ jane.subordinates = [];
43
+ jane.title = 'Seniorer Person';
44
+ try {
45
+ yield jane.$save();
46
+ }
47
+ catch (e) {
48
+ console.error('Error creating entity: ', e);
49
+ throw e;
50
+ }
51
+ return jane;
52
+ });
53
+ }
54
+ it('change an entity and check weakCache', () => __awaiter(void 0, void 0, void 0, function* () {
55
+ if (typeof WeakRef === 'undefined') {
56
+ throw new Error('You must run this test in an environment that includes WeakRef.');
57
+ }
58
+ const employee = yield createJane();
59
+ if (employee.guid == null) {
60
+ throw new Error('Entity is null.');
61
+ }
62
+ const checkA = yield testArtifacts_1.Employee.factory(employee.guid);
63
+ const checkB = yield nymph.getEntity({ class: testArtifacts_1.Employee }, { type: '&', guid: employee.guid });
64
+ if (!checkB) {
65
+ throw new Error("Couldn't fetch entity.");
66
+ }
67
+ employee.current = false;
68
+ expect(checkA.current).toEqual(false);
69
+ expect(checkB.current).toEqual(false);
70
+ }));
71
+ afterAll(() => {
72
+ server.close();
73
+ });
74
+ });
75
+ //# sourceMappingURL=cache.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.test.js","sourceRoot":"","sources":["../src/cache.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,6EAAoD;AACpD,0CAAsD;AACtD,sDAA6C;AAE7C,oDAAmC;AACnC,mDAA0D;AAE1D,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,aAAW,CAAC,EAAE,EAAE,IAAI,wBAAa,CAAC,YAAY,CAAC,CAAC,CAAC;AACzE,WAAW,CAAC,cAAc,CAAC,6BAAa,CAAC,CAAC;AAE1C,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,IAAA,eAAY,EAAC,WAAW,CAAC,CAAC,CAAC;AAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEhC,MAAM,KAAK,GAAG,IAAI,mBAAK,CAAC;IACtB,OAAO,EAAE,6BAA6B;IACtC,SAAS,EAAE,IAAI;CAChB,CAAC,CAAC;AACH,KAAK,CAAC,cAAc,CAAC,wBAAQ,CAAC,CAAC;AAE/B,QAAQ,CAAC,yDAAyD,EAAE,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,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;QAEzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAA,CAAC,CAAC;IAEH,QAAQ,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nymphjs/server",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.25",
4
4
  "description": "NymphJS - REST Server",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -31,21 +31,21 @@
31
31
  },
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
- "@nymphjs/nymph": "^1.0.0-alpha.21",
34
+ "@nymphjs/nymph": "^1.0.0-alpha.25",
35
35
  "cookie-parser": "^1.4.6",
36
36
  "express": "^4.17.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@nymphjs/client": "^1.0.0-alpha.21",
40
- "@nymphjs/client-node": "^1.0.0-alpha.21",
41
- "@nymphjs/driver-sqlite3": "^1.0.0-alpha.21",
39
+ "@nymphjs/client": "^1.0.0-alpha.25",
40
+ "@nymphjs/client-node": "^1.0.0-alpha.25",
41
+ "@nymphjs/driver-sqlite3": "^1.0.0-alpha.25",
42
42
  "@tsconfig/recommended": "^1.0.1",
43
43
  "@types/cookie-parser": "^1.4.2",
44
44
  "@types/express": "^4.17.13",
45
- "@types/jest": "^27.0.2",
46
- "jest": "^27.3.1",
47
- "ts-jest": "^27.0.7",
48
- "typescript": "^4.5.2"
45
+ "@types/jest": "^27.0.3",
46
+ "jest": "^27.4.5",
47
+ "ts-jest": "^27.1.1",
48
+ "typescript": "^4.5.4"
49
49
  },
50
- "gitHead": "db58c2bc56d03bca2d0a77d29feda01872e6a627"
50
+ "gitHead": "d3f18365bd97b8cdfc934e48d6ef57f8d89d4a05"
51
51
  }
@@ -0,0 +1,77 @@
1
+ import express from 'express';
2
+ import SQLite3Driver from '@nymphjs/driver-sqlite3';
3
+ import { Nymph as NymphServer } from '@nymphjs/nymph';
4
+ import { Nymph } from '@nymphjs/client-node';
5
+
6
+ import createServer from './index';
7
+ import { EmployeeModel, Employee } from './testArtifacts';
8
+
9
+ const sqliteConfig = {
10
+ filename: ':memory:',
11
+ };
12
+
13
+ const nymphServer = new NymphServer({}, new SQLite3Driver(sqliteConfig));
14
+ nymphServer.addEntityClass(EmployeeModel);
15
+
16
+ const app = express();
17
+ app.use('/test', createServer(nymphServer));
18
+ const server = app.listen(5081);
19
+
20
+ const nymph = new Nymph({
21
+ restUrl: 'http://localhost:5081/test/',
22
+ weakCache: true,
23
+ });
24
+ nymph.addEntityClass(Employee);
25
+
26
+ describe('Nymph REST Server and Client with Client Weak Ref Cache', () => {
27
+ async function createJane() {
28
+ const jane = await Employee.factory();
29
+ jane.name = 'Jane Doe';
30
+ jane.current = true;
31
+ jane.salary = 8000000;
32
+ jane.startDate = Date.now();
33
+ jane.subordinates = [];
34
+ jane.title = 'Seniorer Person';
35
+ try {
36
+ await jane.$save();
37
+ } catch (e: any) {
38
+ console.error('Error creating entity: ', e);
39
+ throw e;
40
+ }
41
+ return jane;
42
+ }
43
+
44
+ it('change an entity and check weakCache', async () => {
45
+ // @ts-ignore TS doesn't know about WeakRef.
46
+ if (typeof WeakRef === 'undefined') {
47
+ throw new Error(
48
+ 'You must run this test in an environment that includes WeakRef.'
49
+ );
50
+ }
51
+
52
+ const employee = await createJane();
53
+
54
+ if (employee.guid == null) {
55
+ throw new Error('Entity is null.');
56
+ }
57
+
58
+ const checkA = await Employee.factory(employee.guid);
59
+ const checkB = await nymph.getEntity(
60
+ { class: Employee },
61
+ { type: '&', guid: employee.guid }
62
+ );
63
+
64
+ if (!checkB) {
65
+ throw new Error("Couldn't fetch entity.");
66
+ }
67
+
68
+ employee.current = false;
69
+
70
+ expect(checkA.current).toEqual(false);
71
+ expect(checkB.current).toEqual(false);
72
+ });
73
+
74
+ afterAll(() => {
75
+ server.close(); // avoid jest open handle error
76
+ });
77
+ });