@nymphjs/server 1.0.0-beta.9 → 1.0.0-beta.90
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 +353 -0
- package/README.md +75 -3
- package/dist/HttpError.d.ts +5 -0
- package/dist/HttpError.js +11 -0
- package/dist/HttpError.js.map +1 -0
- package/dist/cache.test.js +14 -18
- package/dist/cache.test.js.map +1 -1
- package/dist/createServer.d.ts +17 -0
- package/dist/createServer.js +902 -0
- package/dist/createServer.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -715
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +137 -25
- package/dist/index.test.js.map +1 -1
- package/dist/statusDescriptions.d.ts +6 -0
- package/dist/statusDescriptions.js +69 -0
- package/dist/statusDescriptions.js.map +1 -0
- package/dist/testArtifacts.d.ts +59 -7
- package/dist/testArtifacts.js +171 -69
- package/dist/testArtifacts.js.map +1 -1
- package/jest.config.js +11 -2
- package/package.json +20 -20
- package/src/HttpError.ts +12 -0
- package/src/cache.test.ts +5 -5
- package/src/createServer.ts +976 -0
- package/src/index.test.ts +163 -28
- package/src/index.ts +5 -793
- package/src/statusDescriptions.ts +68 -0
- package/src/testArtifacts.ts +186 -39
- package/tsconfig.json +5 -3
- package/typedoc.json +4 -0
package/dist/testArtifacts.js
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const nymph_1 = require("@nymphjs/nymph");
|
|
5
|
-
const client_1 = require("@nymphjs/client");
|
|
1
|
+
import { Entity as EntityServer, EntityInvalidDataError } from '@nymphjs/nymph';
|
|
2
|
+
import { Entity } from '@nymphjs/client';
|
|
3
|
+
import { HttpError } from './HttpError.js';
|
|
6
4
|
const IS_MANAGER = true;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
static
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
5
|
+
/**
|
|
6
|
+
* This class is a test class that extends the Entity class.
|
|
7
|
+
*/
|
|
8
|
+
export class EmployeeModel extends EntityServer {
|
|
9
|
+
static ETYPE = 'employee';
|
|
10
|
+
static class = 'Employee';
|
|
11
|
+
$clientEnabledMethods = [
|
|
12
|
+
'$testMethodStateless',
|
|
13
|
+
'$testMethod',
|
|
14
|
+
'$throwError',
|
|
15
|
+
'$throwHttpError',
|
|
16
|
+
'$throwHttpErrorWithDescription',
|
|
17
|
+
];
|
|
18
|
+
static clientEnabledStaticMethods = [
|
|
19
|
+
'testStatic',
|
|
20
|
+
'testStaticIterable',
|
|
21
|
+
'testStaticIterableAbort',
|
|
22
|
+
'throwErrorStatic',
|
|
23
|
+
'throwErrorStaticIterable',
|
|
24
|
+
];
|
|
25
|
+
$protectedTags = ['employee'];
|
|
26
|
+
$allowlistTags = ['boss', 'bigcheese'];
|
|
27
|
+
$allowlistData = [
|
|
28
|
+
'name',
|
|
29
|
+
'id',
|
|
30
|
+
'title',
|
|
31
|
+
'department',
|
|
32
|
+
'subordinates',
|
|
33
|
+
'salary',
|
|
34
|
+
'current',
|
|
35
|
+
'startDate',
|
|
36
|
+
'endDate',
|
|
37
|
+
'phone',
|
|
38
|
+
'manager',
|
|
39
|
+
'building',
|
|
40
|
+
];
|
|
41
|
+
constructor() {
|
|
42
|
+
super();
|
|
43
|
+
this.$addTag('employee');
|
|
44
|
+
this.$data.current = true;
|
|
45
|
+
this.$data.startDate = Date.now();
|
|
46
|
+
this.$data.subordinates = [];
|
|
47
|
+
if (!IS_MANAGER) {
|
|
48
|
+
this.$privateData.push('salary');
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
async $save() {
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
// Validate employee data.
|
|
53
|
+
const error = new EntityInvalidDataError('Invalid entity data.');
|
|
54
|
+
if (this.$data.name == null || this.$data.name === '') {
|
|
50
55
|
error.addField('name');
|
|
51
56
|
}
|
|
52
|
-
if (this.$data.title == null || this.$data.title
|
|
57
|
+
if (this.$data.title == null || this.$data.title === '') {
|
|
53
58
|
error.addField('title');
|
|
54
59
|
}
|
|
55
60
|
if (this.$data.startDate == null) {
|
|
@@ -58,6 +63,7 @@ class EmployeeModel extends nymph_1.Entity {
|
|
|
58
63
|
if (error.getFields().length) {
|
|
59
64
|
throw error;
|
|
60
65
|
}
|
|
66
|
+
// Generate employee ID.
|
|
61
67
|
if (this.$data.id == null) {
|
|
62
68
|
this.$data.id = (await this.$nymph.newUID('employee')) ?? undefined;
|
|
63
69
|
}
|
|
@@ -74,41 +80,51 @@ class EmployeeModel extends nymph_1.Entity {
|
|
|
74
80
|
static testStatic(value) {
|
|
75
81
|
return value * 2;
|
|
76
82
|
}
|
|
83
|
+
static *testStaticIterable(value) {
|
|
84
|
+
yield value + 1;
|
|
85
|
+
yield value + 2;
|
|
86
|
+
yield value + 3;
|
|
87
|
+
}
|
|
88
|
+
static *testStaticIterableAbort() {
|
|
89
|
+
let aborted = yield 1;
|
|
90
|
+
if (!aborted) {
|
|
91
|
+
throw new Error("testStaticIterableAbort wasn't aborted after the first iteration.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
77
94
|
static throwErrorStatic() {
|
|
78
95
|
throw new BadFunctionCallError('This function only throws errors.');
|
|
79
96
|
}
|
|
97
|
+
static *throwErrorStaticIterable() {
|
|
98
|
+
yield 1;
|
|
99
|
+
throw new BadFunctionCallError('This function throws errors after the first iteration.');
|
|
100
|
+
}
|
|
80
101
|
$throwError() {
|
|
81
102
|
throw new BadFunctionCallError('This function only throws errors.');
|
|
82
103
|
}
|
|
104
|
+
$throwHttpError() {
|
|
105
|
+
throw new HttpError('A 501 HTTP error.', 501);
|
|
106
|
+
}
|
|
107
|
+
$throwHttpErrorWithDescription() {
|
|
108
|
+
throw new HttpError('A 512 HTTP error.', 512, 'Some Error');
|
|
109
|
+
}
|
|
83
110
|
static inaccessibleMethod() {
|
|
84
111
|
return true;
|
|
85
112
|
}
|
|
86
113
|
}
|
|
87
|
-
|
|
88
|
-
EmployeeModel.ETYPE = 'employee';
|
|
89
|
-
EmployeeModel.class = 'Employee';
|
|
90
|
-
EmployeeModel.clientEnabledStaticMethods = ['testStatic', 'throwErrorStatic'];
|
|
91
|
-
class BadFunctionCallError extends Error {
|
|
114
|
+
export class BadFunctionCallError extends Error {
|
|
92
115
|
constructor(message) {
|
|
93
116
|
super(message);
|
|
94
117
|
this.name = 'BadFunctionCallError';
|
|
95
118
|
}
|
|
96
119
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
static async factory(guid) {
|
|
108
|
-
return (await super.factory(guid));
|
|
109
|
-
}
|
|
110
|
-
static factorySync(guid) {
|
|
111
|
-
return super.factorySync(guid);
|
|
120
|
+
export class Employee extends Entity {
|
|
121
|
+
// The name of the server class
|
|
122
|
+
static class = 'Employee';
|
|
123
|
+
constructor() {
|
|
124
|
+
super();
|
|
125
|
+
this.$addTag('employee');
|
|
126
|
+
this.$data.current = true;
|
|
127
|
+
this.$data.subordinates = [];
|
|
112
128
|
}
|
|
113
129
|
$testMethod(value) {
|
|
114
130
|
return this.$serverCall('$testMethod', [value]);
|
|
@@ -119,17 +135,103 @@ class Employee extends client_1.Entity {
|
|
|
119
135
|
$throwError() {
|
|
120
136
|
return this.$serverCall('$throwError', []);
|
|
121
137
|
}
|
|
138
|
+
$throwHttpError() {
|
|
139
|
+
return this.$serverCall('$throwHttpError', []);
|
|
140
|
+
}
|
|
141
|
+
$throwHttpErrorWithDescription() {
|
|
142
|
+
return this.$serverCall('$throwHttpErrorWithDescription', []);
|
|
143
|
+
}
|
|
122
144
|
static testStatic(value) {
|
|
123
145
|
return this.serverCallStatic('testStatic', [value]);
|
|
124
146
|
}
|
|
147
|
+
static testStaticIterable(value) {
|
|
148
|
+
return this.serverCallStaticIterator('testStaticIterable', [value]);
|
|
149
|
+
}
|
|
150
|
+
static testStaticIterableAbort() {
|
|
151
|
+
return this.serverCallStaticIterator('testStaticIterableAbort', []);
|
|
152
|
+
}
|
|
125
153
|
static throwErrorStatic() {
|
|
126
154
|
return this.serverCallStatic('throwErrorStatic', []);
|
|
127
155
|
}
|
|
156
|
+
static throwErrorStaticIterable() {
|
|
157
|
+
return this.serverCallStaticIterator('throwErrorStaticIterable', []);
|
|
158
|
+
}
|
|
128
159
|
static inaccessibleMethod() {
|
|
129
160
|
return this.serverCallStatic('inaccessibleMethod', []);
|
|
130
161
|
}
|
|
131
162
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
/**
|
|
164
|
+
* This class is a test class that extends the Entity class.
|
|
165
|
+
*/
|
|
166
|
+
export class RestrictedModel extends EntityServer {
|
|
167
|
+
static ETYPE = 'restricted';
|
|
168
|
+
static class = 'Restricted';
|
|
169
|
+
static restEnabled = false;
|
|
170
|
+
constructor() {
|
|
171
|
+
super();
|
|
172
|
+
this.$data.name = '';
|
|
173
|
+
}
|
|
174
|
+
async $save() {
|
|
175
|
+
// Validate entity data.
|
|
176
|
+
const error = new EntityInvalidDataError('Invalid entity data.');
|
|
177
|
+
if (this.$data.name == null || this.$data.name === '') {
|
|
178
|
+
error.addField('name');
|
|
179
|
+
}
|
|
180
|
+
if (error.getFields().length) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
return await super.$save();
|
|
184
|
+
}
|
|
185
|
+
$testMethod(value) {
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
static testStatic(value) {
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export class Restricted extends Entity {
|
|
193
|
+
// The name of the server class
|
|
194
|
+
static class = 'Restricted';
|
|
195
|
+
constructor() {
|
|
196
|
+
super();
|
|
197
|
+
this.$data.name = '';
|
|
198
|
+
}
|
|
199
|
+
$testMethod(value) {
|
|
200
|
+
return this.$serverCall('$testMethod', [value]);
|
|
201
|
+
}
|
|
202
|
+
static testStatic(value) {
|
|
203
|
+
return this.serverCallStatic('testStatic', [value]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* This class is a test class that extends the Entity class.
|
|
208
|
+
*/
|
|
209
|
+
export class PubSubDisabledModel extends EntityServer {
|
|
210
|
+
static ETYPE = 'pubsub_disabled';
|
|
211
|
+
static class = 'PubSubDisabled';
|
|
212
|
+
static pubSubEnabled = false;
|
|
213
|
+
constructor() {
|
|
214
|
+
super();
|
|
215
|
+
this.$data.name = '';
|
|
216
|
+
}
|
|
217
|
+
async $save() {
|
|
218
|
+
// Validate entity data.
|
|
219
|
+
const error = new EntityInvalidDataError('Invalid entity data.');
|
|
220
|
+
if (this.$data.name == null || this.$data.name === '') {
|
|
221
|
+
error.addField('name');
|
|
222
|
+
}
|
|
223
|
+
if (error.getFields().length) {
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
return await super.$save();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
export class PubSubDisabled extends Entity {
|
|
230
|
+
// The name of the server class
|
|
231
|
+
static class = 'PubSubDisabled';
|
|
232
|
+
constructor() {
|
|
233
|
+
super();
|
|
234
|
+
this.$data.name = '';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
135
237
|
//# sourceMappingURL=testArtifacts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testArtifacts.js","sourceRoot":"","sources":["../src/testArtifacts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testArtifacts.js","sourceRoot":"","sources":["../src/testArtifacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAsB3C,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAA+B;IAChE,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC;IAC1B,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC;IAEhB,qBAAqB,GAAG;QAChC,sBAAsB;QACtB,aAAa;QACb,aAAa;QACb,iBAAiB;QACjB,gCAAgC;KACjC,CAAC;IACK,MAAM,CAAC,0BAA0B,GAAG;QACzC,YAAY;QACZ,oBAAoB;QACpB,yBAAyB;QACzB,kBAAkB;QAClB,0BAA0B;KAC3B,CAAC;IACQ,cAAc,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,cAAc,GAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACxC,cAAc,GAAI;QAC1B,MAAM;QACN,IAAI;QACJ,OAAO;QACP,YAAY;QACZ,cAAc;QACd,QAAQ;QACR,SAAS;QACT,WAAW;QACX,SAAS;QACT,OAAO;QACP,SAAS;QACT,UAAU;KACX,CAAC;IAEF;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAClC,IAAI,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CAAC,IAAI,GAAG,EAAE,CAAC;IACvB,CAAC"}
|
package/jest.config.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { createDefaultEsmPreset } from 'ts-jest';
|
|
2
|
+
|
|
3
|
+
const presetConfig = createDefaultEsmPreset();
|
|
4
|
+
|
|
1
5
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
|
|
3
|
-
|
|
6
|
+
const jestConfig = {
|
|
7
|
+
...presetConfig,
|
|
4
8
|
testEnvironment: 'node',
|
|
5
9
|
rootDir: 'src/',
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
'^(\\.|\\.\\.)\\/(.+)\\.js': '$1/$2',
|
|
12
|
+
},
|
|
6
13
|
};
|
|
14
|
+
|
|
15
|
+
export default jestConfig;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymphjs/server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "
|
|
3
|
+
"version": "1.0.0-beta.90",
|
|
4
|
+
"description": "Nymph.js - REST Server",
|
|
5
|
+
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"keywords": [
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"clean": "test -d dist && rm -r dist || true",
|
|
15
15
|
"build": "tsc",
|
|
16
16
|
"watch": "tsc --watch",
|
|
17
|
-
"
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"test:watch": "jest --watch"
|
|
17
|
+
"prepublish": "npm run clean && npm run build",
|
|
18
|
+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
|
|
19
|
+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nymphjs/nymph": "^1.0.0-beta.
|
|
35
|
-
"cookie-parser": "^1.4.
|
|
36
|
-
"express": "^4.
|
|
34
|
+
"@nymphjs/nymph": "^1.0.0-beta.90",
|
|
35
|
+
"cookie-parser": "^1.4.7",
|
|
36
|
+
"express": "^4.21.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nymphjs/client": "^1.0.0-beta.
|
|
40
|
-
"@nymphjs/
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/
|
|
45
|
-
"
|
|
46
|
-
"jest": "^29.
|
|
47
|
-
"ts-
|
|
48
|
-
"typescript": "^
|
|
39
|
+
"@nymphjs/client": "^1.0.0-beta.90",
|
|
40
|
+
"@nymphjs/driver-sqlite3": "^1.0.0-beta.90",
|
|
41
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
42
|
+
"@types/cookie-parser": "^1.4.8",
|
|
43
|
+
"@types/express": "^5.0.0",
|
|
44
|
+
"@types/jest": "^29.5.14",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"ts-jest": "^29.2.5",
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
|
+
"typescript": "^5.7.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "334f610ea98e67320dce40688adf0e8503b9b7a4"
|
|
51
51
|
}
|
package/src/HttpError.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class HttpError extends Error {
|
|
2
|
+
status?: number;
|
|
3
|
+
statusText?: string;
|
|
4
|
+
|
|
5
|
+
constructor(message: string, status?: number, statusText?: string) {
|
|
6
|
+
super(message);
|
|
7
|
+
|
|
8
|
+
this.name = 'HttpError';
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.statusText = statusText;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/cache.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import SQLite3Driver from '@nymphjs/driver-sqlite3';
|
|
3
3
|
import { Nymph as NymphServer } from '@nymphjs/nymph';
|
|
4
|
-
import { Nymph } from '@nymphjs/client
|
|
4
|
+
import { Nymph } from '@nymphjs/client';
|
|
5
5
|
|
|
6
|
-
import createServer from './index';
|
|
6
|
+
import createServer from './index.js';
|
|
7
7
|
import {
|
|
8
8
|
EmployeeModel as EmployeeModelClass,
|
|
9
9
|
Employee as EmployeeClass,
|
|
10
|
-
} from './testArtifacts';
|
|
10
|
+
} from './testArtifacts.js';
|
|
11
11
|
|
|
12
12
|
const sqliteConfig = {
|
|
13
13
|
filename: ':memory:',
|
|
@@ -48,7 +48,7 @@ describe('Nymph REST Server and Client with Client Weak Ref Cache', () => {
|
|
|
48
48
|
// @ts-ignore TS doesn't know about WeakRef.
|
|
49
49
|
if (typeof WeakRef === 'undefined') {
|
|
50
50
|
throw new Error(
|
|
51
|
-
'You must run this test in an environment that includes WeakRef.'
|
|
51
|
+
'You must run this test in an environment that includes WeakRef.',
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -61,7 +61,7 @@ describe('Nymph REST Server and Client with Client Weak Ref Cache', () => {
|
|
|
61
61
|
const checkA = await Employee.factory(employee.guid);
|
|
62
62
|
const checkB = await nymph.getEntity(
|
|
63
63
|
{ class: Employee },
|
|
64
|
-
{ type: '&', guid: employee.guid }
|
|
64
|
+
{ type: '&', guid: employee.guid },
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
if (!checkB) {
|