@nymphjs/server 1.0.0-beta.11 → 1.0.0-beta.111

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.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * HTTP status code to status text map.
3
+ */
4
+ export const statusDescriptions: { [k: number]: string } = {
5
+ 100: 'Continue',
6
+ 101: 'Switching Protocols',
7
+ 102: 'Processing',
8
+ 103: 'Early Hints',
9
+ 200: 'OK',
10
+ 201: 'Created',
11
+ 202: 'Accepted',
12
+ 203: 'Non-Authoritative Information',
13
+ 204: 'No Content',
14
+ 205: 'Reset Content',
15
+ 206: 'Partial Content',
16
+ 207: 'Multi-Status',
17
+ 208: 'Already Reported',
18
+ 226: 'IM Used',
19
+ 300: 'Multiple Choices',
20
+ 301: 'Moved Permanently',
21
+ 302: 'Found',
22
+ 303: 'See Other',
23
+ 304: 'Not Modified',
24
+ 305: 'Use Proxy',
25
+ 306: 'Switch Proxy',
26
+ 307: 'Temporary Redirect',
27
+ 308: 'Permanent Redirect',
28
+ 400: 'Bad Request',
29
+ 401: 'Unauthorized',
30
+ 402: 'Payment Required',
31
+ 403: 'Forbidden',
32
+ 404: 'Not Found',
33
+ 405: 'Method Not Allowed',
34
+ 406: 'Not Acceptable',
35
+ 407: 'Proxy Authentication Required',
36
+ 408: 'Request Timeout',
37
+ 409: 'Conflict',
38
+ 410: 'Gone',
39
+ 411: 'Length Required',
40
+ 412: 'Precondition Failed',
41
+ 413: 'Payload Too Large',
42
+ 414: 'URI Too Long',
43
+ 415: 'Unsupported Media Type',
44
+ 416: 'Range Not Satisfiable',
45
+ 417: 'Expectation Failed',
46
+ 418: "I'm a teapot",
47
+ 421: 'Misdirected Request',
48
+ 422: 'Unprocessable Entity',
49
+ 423: 'Locked',
50
+ 424: 'Failed Dependency',
51
+ 425: 'Too Early',
52
+ 426: 'Upgrade Required',
53
+ 428: 'Precondition Required',
54
+ 429: 'Too Many Requests',
55
+ 431: 'Request Header Fields Too Large',
56
+ 451: 'Unavailable For Legal Reasons',
57
+ 500: 'Internal Server Error',
58
+ 501: 'Not Implemented',
59
+ 502: 'Bad Gateway',
60
+ 503: 'Service Unavailable',
61
+ 504: 'Gateway Timeout',
62
+ 505: 'HTTP Version Not Supported',
63
+ 506: 'Variant Also Negotiates',
64
+ 507: 'Insufficient Storage',
65
+ 508: 'Loop Detected',
66
+ 510: 'Not Extended',
67
+ 511: 'Network Authentication Required',
68
+ };
@@ -1,8 +1,10 @@
1
- import { Entity as EntityServer, EntityInvalidDataError } from '@nymphjs/nymph';
1
+ import {
2
+ Entity as EntityServer,
3
+ EntityInvalidDataError,
4
+ HttpError,
5
+ } from '@nymphjs/nymph';
2
6
  import { Entity } from '@nymphjs/client';
3
7
 
4
- import { HttpError } from './HttpError';
5
-
6
8
  export type EmployeeBaseData<T> = {
7
9
  name?: string;
8
10
  id?: number;
@@ -39,7 +41,13 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
39
41
  '$throwHttpError',
40
42
  '$throwHttpErrorWithDescription',
41
43
  ];
42
- public static clientEnabledStaticMethods = ['testStatic', 'throwErrorStatic'];
44
+ public static clientEnabledStaticMethods = [
45
+ 'testStatic',
46
+ 'testStaticIterable',
47
+ 'testStaticIterableAbort',
48
+ 'throwErrorStatic',
49
+ 'throwErrorStaticIterable',
50
+ ];
43
51
  protected $protectedTags = ['employee'];
44
52
  protected $allowlistTags? = ['boss', 'bigcheese'];
45
53
  protected $allowlistData? = [
@@ -57,37 +65,25 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
57
65
  'building',
58
66
  ];
59
67
 
60
- static async factory(
61
- guid?: string
62
- ): Promise<EmployeeModel & EmployeeModelData> {
63
- return (await super.factory(guid)) as EmployeeModel & EmployeeModelData;
64
- }
65
-
66
- static factorySync(guid?: string): EmployeeModel & EmployeeModelData {
67
- return super.factorySync(guid) as EmployeeModel & EmployeeModelData;
68
- }
69
-
70
- constructor(guid?: string) {
71
- super(guid);
68
+ constructor() {
69
+ super();
72
70
 
73
- if (this.guid == null) {
74
- this.$addTag('employee');
75
- this.$data.current = true;
76
- this.$data.startDate = Date.now();
77
- this.$data.subordinates = [];
78
- if (!IS_MANAGER) {
79
- this.$privateData.push('salary');
80
- }
71
+ this.$addTag('employee');
72
+ this.$data.current = true;
73
+ this.$data.startDate = Date.now();
74
+ this.$data.subordinates = [];
75
+ if (!IS_MANAGER) {
76
+ this.$privateData.push('salary');
81
77
  }
82
78
  }
83
79
 
84
80
  public async $save() {
85
81
  // Validate employee data.
86
82
  const error = new EntityInvalidDataError('Invalid entity data.');
87
- if (this.$data.name == null || this.$data.name == '') {
83
+ if (this.$data.name == null || this.$data.name === '') {
88
84
  error.addField('name');
89
85
  }
90
- if (this.$data.title == null || this.$data.title == '') {
86
+ if (this.$data.title == null || this.$data.title === '') {
91
87
  error.addField('title');
92
88
  }
93
89
  if (this.$data.startDate == null) {
@@ -117,10 +113,33 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
117
113
  return value * 2;
118
114
  }
119
115
 
116
+ public static *testStaticIterable(value: number) {
117
+ yield value + 1;
118
+ yield value + 2;
119
+ yield value + 3;
120
+ }
121
+
122
+ public static *testStaticIterableAbort(): Iterator<number, void, boolean> {
123
+ let aborted = yield 1;
124
+
125
+ if (!aborted) {
126
+ throw new Error(
127
+ "testStaticIterableAbort wasn't aborted after the first iteration.",
128
+ );
129
+ }
130
+ }
131
+
120
132
  public static throwErrorStatic() {
121
133
  throw new BadFunctionCallError('This function only throws errors.');
122
134
  }
123
135
 
136
+ public static *throwErrorStaticIterable() {
137
+ yield 1;
138
+ throw new BadFunctionCallError(
139
+ 'This function throws errors after the first iteration.',
140
+ );
141
+ }
142
+
124
143
  public $throwError() {
125
144
  throw new BadFunctionCallError('This function only throws errors.');
126
145
  }
@@ -151,22 +170,12 @@ export class Employee extends Entity<EmployeeData> {
151
170
  // The name of the server class
152
171
  public static class = 'Employee';
153
172
 
154
- constructor(guid?: string) {
155
- super(guid);
156
-
157
- if (guid == null) {
158
- this.$addTag('employee');
159
- this.$data.current = true;
160
- this.$data.subordinates = [];
161
- }
162
- }
163
-
164
- static async factory(guid?: string): Promise<Employee & EmployeeData> {
165
- return (await super.factory(guid)) as Employee & EmployeeData;
166
- }
173
+ constructor() {
174
+ super();
167
175
 
168
- static factorySync(guid?: string): Employee & EmployeeData {
169
- return super.factorySync(guid) as Employee & EmployeeData;
176
+ this.$addTag('employee');
177
+ this.$data.current = true;
178
+ this.$data.subordinates = [];
170
179
  }
171
180
 
172
181
  $testMethod(value: number) {
@@ -193,13 +202,133 @@ export class Employee extends Entity<EmployeeData> {
193
202
  return this.serverCallStatic('testStatic', [value]);
194
203
  }
195
204
 
205
+ static testStaticIterable(value: number) {
206
+ return this.serverCallStaticIterator('testStaticIterable', [value]);
207
+ }
208
+
209
+ static testStaticIterableAbort() {
210
+ return this.serverCallStaticIterator('testStaticIterableAbort', []);
211
+ }
212
+
196
213
  static throwErrorStatic() {
197
214
  return this.serverCallStatic('throwErrorStatic', []);
198
215
  }
199
216
 
217
+ static throwErrorStaticIterable() {
218
+ return this.serverCallStaticIterator('throwErrorStaticIterable', []);
219
+ }
220
+
200
221
  static inaccessibleMethod() {
201
222
  return this.serverCallStatic('inaccessibleMethod', []);
202
223
  }
203
224
  }
204
225
 
205
- export default Employee;
226
+ export type RestrictedModelData = {
227
+ name: string;
228
+ };
229
+
230
+ /**
231
+ * This class is a test class that extends the Entity class.
232
+ */
233
+ export class RestrictedModel extends EntityServer<RestrictedModelData> {
234
+ static ETYPE = 'restricted';
235
+ static class = 'Restricted';
236
+
237
+ public static restEnabled = false;
238
+
239
+ constructor() {
240
+ super();
241
+
242
+ this.$data.name = '';
243
+ }
244
+
245
+ public async $save() {
246
+ // Validate entity data.
247
+ const error = new EntityInvalidDataError('Invalid entity data.');
248
+ if (this.$data.name == null || this.$data.name === '') {
249
+ error.addField('name');
250
+ }
251
+ if (error.getFields().length) {
252
+ throw error;
253
+ }
254
+ return await super.$save();
255
+ }
256
+
257
+ $testMethod(value: string) {
258
+ return value;
259
+ }
260
+
261
+ public static testStatic(value: number) {
262
+ return value;
263
+ }
264
+ }
265
+
266
+ export type RestrictedData = {
267
+ name: string;
268
+ };
269
+
270
+ export class Restricted extends Entity<RestrictedData> {
271
+ // The name of the server class
272
+ public static class = 'Restricted';
273
+
274
+ constructor() {
275
+ super();
276
+
277
+ this.$data.name = '';
278
+ }
279
+
280
+ $testMethod(value: number) {
281
+ return this.$serverCall('$testMethod', [value]);
282
+ }
283
+
284
+ static testStatic(value: number) {
285
+ return this.serverCallStatic('testStatic', [value]);
286
+ }
287
+ }
288
+
289
+ export type PubSubDisabledModelData = {
290
+ name: string;
291
+ };
292
+
293
+ /**
294
+ * This class is a test class that extends the Entity class.
295
+ */
296
+ export class PubSubDisabledModel extends EntityServer<PubSubDisabledModelData> {
297
+ static ETYPE = 'pubsub_disabled';
298
+ static class = 'PubSubDisabled';
299
+
300
+ public static pubSubEnabled = false;
301
+
302
+ constructor() {
303
+ super();
304
+
305
+ this.$data.name = '';
306
+ }
307
+
308
+ public async $save() {
309
+ // Validate entity data.
310
+ const error = new EntityInvalidDataError('Invalid entity data.');
311
+ if (this.$data.name == null || this.$data.name === '') {
312
+ error.addField('name');
313
+ }
314
+ if (error.getFields().length) {
315
+ throw error;
316
+ }
317
+ return await super.$save();
318
+ }
319
+ }
320
+
321
+ export type PubSubDisabledData = {
322
+ name: string;
323
+ };
324
+
325
+ export class PubSubDisabled extends Entity<PubSubDisabledData> {
326
+ // The name of the server class
327
+ public static class = 'PubSubDisabled';
328
+
329
+ constructor() {
330
+ super();
331
+
332
+ this.$data.name = '';
333
+ }
334
+ }
package/tsconfig.json CHANGED
@@ -2,10 +2,12 @@
2
2
  "extends": "@tsconfig/recommended/tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
- "lib": ["ES2021"],
6
- "target": "ES2021",
5
+ "module": "ES2022",
6
+ "moduleResolution": "node",
7
+ "lib": ["ES2022"],
8
+ "target": "ES2022",
7
9
  "noImplicitAny": true,
8
- "removeComments": true,
10
+ "removeComments": false,
9
11
  "sourceMap": true,
10
12
  "outDir": "dist",
11
13
  "resolveJsonModule": true,
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../../typedoc.base.json"],
3
+ "entryPoints": ["src/index.ts"]
4
+ }
@@ -1,5 +0,0 @@
1
- export declare class HttpError extends Error {
2
- status?: number;
3
- statusText?: string;
4
- constructor(message: string, status?: number, statusText?: string);
5
- }
package/dist/HttpError.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpError = void 0;
4
- class HttpError extends Error {
5
- constructor(message, status, statusText) {
6
- super(message);
7
- this.name = 'HttpError';
8
- this.status = status;
9
- this.statusText = statusText;
10
- }
11
- }
12
- exports.HttpError = HttpError;
13
- //# sourceMappingURL=HttpError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAAY,OAAe,EAAE,MAAe,EAAE,UAAmB;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAXD,8BAWC"}
package/src/HttpError.ts DELETED
@@ -1,12 +0,0 @@
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
- }