@nymphjs/server 1.0.0-beta.3 → 1.0.0-beta.30

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,6 +1,8 @@
1
1
  import { Entity as EntityServer, EntityInvalidDataError } from '@nymphjs/nymph';
2
2
  import { Entity } from '@nymphjs/client';
3
3
 
4
+ import { HttpError } from './HttpError';
5
+
4
6
  export type EmployeeBaseData<T> = {
5
7
  name?: string;
6
8
  id?: number;
@@ -34,6 +36,8 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
34
36
  '$testMethodStateless',
35
37
  '$testMethod',
36
38
  '$throwError',
39
+ '$throwHttpError',
40
+ '$throwHttpErrorWithDescription',
37
41
  ];
38
42
  public static clientEnabledStaticMethods = ['testStatic', 'throwErrorStatic'];
39
43
  protected $protectedTags = ['employee'];
@@ -80,10 +84,10 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
80
84
  public async $save() {
81
85
  // Validate employee data.
82
86
  const error = new EntityInvalidDataError('Invalid entity data.');
83
- if (this.$data.name == null || this.$data.name == '') {
87
+ if (this.$data.name == null || this.$data.name === '') {
84
88
  error.addField('name');
85
89
  }
86
- if (this.$data.title == null || this.$data.title == '') {
90
+ if (this.$data.title == null || this.$data.title === '') {
87
91
  error.addField('title');
88
92
  }
89
93
  if (this.$data.startDate == null) {
@@ -121,6 +125,14 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
121
125
  throw new BadFunctionCallError('This function only throws errors.');
122
126
  }
123
127
 
128
+ public $throwHttpError() {
129
+ throw new HttpError('A 501 HTTP error.', 501);
130
+ }
131
+
132
+ public $throwHttpErrorWithDescription() {
133
+ throw new HttpError('A 512 HTTP error.', 512, 'Some Error');
134
+ }
135
+
124
136
  public static inaccessibleMethod() {
125
137
  return true;
126
138
  }
@@ -169,17 +181,183 @@ export class Employee extends Entity<EmployeeData> {
169
181
  return this.$serverCall('$throwError', []);
170
182
  }
171
183
 
184
+ $throwHttpError() {
185
+ return this.$serverCall('$throwHttpError', []);
186
+ }
187
+
188
+ $throwHttpErrorWithDescription() {
189
+ return this.$serverCall('$throwHttpErrorWithDescription', []);
190
+ }
191
+
172
192
  static testStatic(value: number) {
173
- return Employee.serverCallStatic('testStatic', [value]);
193
+ return this.serverCallStatic('testStatic', [value]);
174
194
  }
175
195
 
176
196
  static throwErrorStatic() {
177
- return Employee.serverCallStatic('throwErrorStatic', []);
197
+ return this.serverCallStatic('throwErrorStatic', []);
178
198
  }
179
199
 
180
200
  static inaccessibleMethod() {
181
- return Employee.serverCallStatic('inaccessibleMethod', []);
201
+ return this.serverCallStatic('inaccessibleMethod', []);
182
202
  }
183
203
  }
184
204
 
185
- export default Employee;
205
+ export type RestrictedModelData = {
206
+ name: string;
207
+ };
208
+
209
+ /**
210
+ * This class is a test class that extends the Entity class.
211
+ */
212
+ export class RestrictedModel extends EntityServer<RestrictedModelData> {
213
+ static ETYPE = 'restricted';
214
+ static class = 'Restricted';
215
+
216
+ public static restEnabled = false;
217
+
218
+ static async factory(
219
+ guid?: string
220
+ ): Promise<RestrictedModel & RestrictedModelData> {
221
+ return (await super.factory(guid)) as RestrictedModel & RestrictedModelData;
222
+ }
223
+
224
+ static factorySync(guid?: string): RestrictedModel & RestrictedModelData {
225
+ return super.factorySync(guid) as RestrictedModel & RestrictedModelData;
226
+ }
227
+
228
+ constructor(guid?: string) {
229
+ super(guid);
230
+
231
+ if (this.guid == null) {
232
+ this.$data.name = '';
233
+ }
234
+ }
235
+
236
+ public async $save() {
237
+ // Validate entity data.
238
+ const error = new EntityInvalidDataError('Invalid entity data.');
239
+ if (this.$data.name == null || this.$data.name === '') {
240
+ error.addField('name');
241
+ }
242
+ if (error.getFields().length) {
243
+ throw error;
244
+ }
245
+ return await super.$save();
246
+ }
247
+
248
+ $testMethod(value: string) {
249
+ return value;
250
+ }
251
+
252
+ public static testStatic(value: number) {
253
+ return value;
254
+ }
255
+ }
256
+
257
+ export type RestrictedData = {
258
+ name: string;
259
+ };
260
+
261
+ export class Restricted extends Entity<RestrictedData> {
262
+ // The name of the server class
263
+ public static class = 'Restricted';
264
+
265
+ constructor(guid?: string) {
266
+ super(guid);
267
+
268
+ if (guid == null) {
269
+ this.$data.name = '';
270
+ }
271
+ }
272
+
273
+ static async factory(guid?: string): Promise<Restricted & RestrictedData> {
274
+ return (await super.factory(guid)) as Restricted & RestrictedData;
275
+ }
276
+
277
+ static factorySync(guid?: string): Restricted & RestrictedData {
278
+ return super.factorySync(guid) as Restricted & RestrictedData;
279
+ }
280
+
281
+ $testMethod(value: number) {
282
+ return this.$serverCall('$testMethod', [value]);
283
+ }
284
+
285
+ static testStatic(value: number) {
286
+ return this.serverCallStatic('testStatic', [value]);
287
+ }
288
+ }
289
+
290
+ export type PubSubDisabledModelData = {
291
+ name: string;
292
+ };
293
+
294
+ /**
295
+ * This class is a test class that extends the Entity class.
296
+ */
297
+ export class PubSubDisabledModel extends EntityServer<PubSubDisabledModelData> {
298
+ static ETYPE = 'pubsub_disabled';
299
+ static class = 'PubSubDisabled';
300
+
301
+ public static pubSubEnabled = false;
302
+
303
+ static async factory(
304
+ guid?: string
305
+ ): Promise<PubSubDisabledModel & PubSubDisabledModelData> {
306
+ return (await super.factory(guid)) as PubSubDisabledModel &
307
+ PubSubDisabledModelData;
308
+ }
309
+
310
+ static factorySync(
311
+ guid?: string
312
+ ): PubSubDisabledModel & PubSubDisabledModelData {
313
+ return super.factorySync(guid) as PubSubDisabledModel &
314
+ PubSubDisabledModelData;
315
+ }
316
+
317
+ constructor(guid?: string) {
318
+ super(guid);
319
+
320
+ if (guid == null) {
321
+ this.$data.name = '';
322
+ }
323
+ }
324
+
325
+ public async $save() {
326
+ // Validate entity data.
327
+ const error = new EntityInvalidDataError('Invalid entity data.');
328
+ if (this.$data.name == null || this.$data.name === '') {
329
+ error.addField('name');
330
+ }
331
+ if (error.getFields().length) {
332
+ throw error;
333
+ }
334
+ return await super.$save();
335
+ }
336
+ }
337
+
338
+ export type PubSubDisabledData = {
339
+ name: string;
340
+ };
341
+
342
+ export class PubSubDisabled extends Entity<PubSubDisabledData> {
343
+ // The name of the server class
344
+ public static class = 'PubSubDisabled';
345
+
346
+ constructor(guid?: string) {
347
+ super(guid);
348
+
349
+ if (guid == null) {
350
+ this.$data.name = '';
351
+ }
352
+ }
353
+
354
+ static async factory(
355
+ guid?: string
356
+ ): Promise<PubSubDisabled & PubSubDisabledData> {
357
+ return (await super.factory(guid)) as PubSubDisabled & PubSubDisabledData;
358
+ }
359
+
360
+ static factorySync(guid?: string): PubSubDisabled & PubSubDisabledData {
361
+ return super.factorySync(guid) as PubSubDisabled & PubSubDisabledData;
362
+ }
363
+ }