json-rest-api 0.1.1 → 1.0.1

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.
Files changed (50) hide show
  1. package/.claude/settings.local.json +16 -0
  2. package/LICENSE +674 -20
  3. package/README.md +728 -120
  4. package/RELATIONSHIPS.md +1013 -0
  5. package/TODO_rest-api-plugin-extras.js +142 -0
  6. package/connectors_ideas/express-plugin.js +120 -0
  7. package/connectors_ideas/fastify.js +219 -0
  8. package/connectors_ideas/http-plugin.js +138 -0
  9. package/connectors_ideas/koa-plugin.js +113 -0
  10. package/docs/fileUploads.md +722 -0
  11. package/docs/mini-guides/file-uploads-complete.md +159 -0
  12. package/examples/.gitkeep +0 -0
  13. package/examples/express-example.js +262 -0
  14. package/examples/express-plugin.js +366 -0
  15. package/examples/file-upload-example.js +205 -0
  16. package/examples/filename-strategies.js +140 -0
  17. package/examples/knex-basic.js +66 -0
  18. package/index.js +28 -202
  19. package/lib/payload-validators.js +685 -0
  20. package/lib/rest-api-errors.js +58 -0
  21. package/package.json +37 -20
  22. package/payloadValdators.js +686 -0
  23. package/plugins/core/connectors/express-plugin.js +449 -0
  24. package/plugins/core/connectors/http-plugin.js +450 -0
  25. package/plugins/core/file-handling-plugin.js +338 -0
  26. package/plugins/core/lib/busboy-detector.js +167 -0
  27. package/plugins/core/lib/formidable-detector.js +130 -0
  28. package/plugins/core/rest-api-knex-plugin.js +200 -0
  29. package/plugins/core/rest-api-plugin.js +1419 -0
  30. package/plugins/storage/local-storage.js +218 -0
  31. package/plugins/storage/s3-storage.js +125 -0
  32. package/test-examples/package-lock.json +906 -0
  33. package/test-examples/package.json +15 -0
  34. package/test-examples/test-basic-api.js +11 -0
  35. package/test-examples/test-books-resource.js +116 -0
  36. package/test-examples/test-complete-file-upload.js +140 -0
  37. package/test-examples/test-debug.js +28 -0
  38. package/test-examples/test-express-plugin.js +177 -0
  39. package/test-examples/test-express-simple.js +28 -0
  40. package/test-examples/test-express-with-import.js +71 -0
  41. package/test-examples/test-file-upload.js +132 -0
  42. package/test-examples/test-http-plugin.js +159 -0
  43. package/test-examples/test-programmatic-api.js +188 -0
  44. package/test-examples/test-rest-api-plugin.js +13 -0
  45. package/.jshintrc +0 -48
  46. package/.npmignore +0 -15
  47. package/examples/client.js +0 -18
  48. package/examples/client2.js +0 -27
  49. package/examples/server.js +0 -23
  50. package/test.js +0 -101
package/test.js DELETED
@@ -1,101 +0,0 @@
1
- 'use strict';
2
- var JsonRestApi = require('./index');
3
- var request = require('request');
4
- var inspect = require('util').inspect;
5
- var debug = require('debug')('json-rest-api:test');
6
- var assert = require('assert');
7
-
8
- describe('Test1', function() {
9
- var RestApi;
10
- before(function(cb) {
11
- RestApi = new JsonRestApi({port: 8000}, function(err) {
12
- debug('IN CB');
13
- if (err) {
14
- debug('/ping error: '+inspect(err));
15
- return cb(err);
16
- }
17
- // add a route
18
- // A simple health check, common to all derived classes.
19
- RestApi.addRoute('get', '/ping', function(req, res) {
20
- res.json({success: true, pong: 'pong'});
21
- });
22
- cb();
23
- });
24
- });
25
-
26
- it('should fetch test.html', function(cb) {
27
- request({json:true, uri: 'http://localhost:8000/ping'}, function(err, res, json) {
28
- if (err) {
29
- debug('Error: '+inspect(err));
30
- return cb(err);
31
- }
32
- debug('typeof json: '+typeof json);
33
- debug('json: '+inspect(json));
34
- assert.ok(json.success === true);
35
- assert.ok(json.pong === 'pong');
36
- cb();
37
- });
38
- });
39
-
40
- after(function(cb){
41
- RestApi.stop(function(err) {
42
- if (err) return cb(err);
43
- debug('RestApi stopped successfully');
44
- cb();
45
- });
46
- });
47
- });
48
-
49
- describe('Test2', function() {
50
- var RestApi;
51
- before(function(cb) {
52
- RestApi = new JsonRestApi({port: 8000}, function(err) {
53
- debug('IN CB');
54
- if (err) {
55
- debug('/ping error: '+inspect(err));
56
- return cb(err);
57
- }
58
- // add a route
59
- // A simple health check, common to all derived classes.
60
- RestApi.addRoute('get', '/setname', function(req, res, json, qs) {
61
- debug('qs: '+inspect(qs));
62
- res.json({success: true, cmd: 'setname', qs: qs});
63
- });
64
- cb();
65
- });
66
- });
67
-
68
- it('should be able receive a query string', function(cb) {
69
- var qs = {
70
- alpha: 'one',
71
- beta: 2,
72
- gamma: true
73
- };
74
- var opts = {
75
- json: true,
76
- uri: 'http://localhost:8000/setname',
77
- qs: qs
78
- };
79
- request(opts, function(err, res, json) {
80
- if (err) {
81
- debug('Error: '+inspect(err));
82
- return cb(err);
83
- }
84
- debug('typeof json: '+typeof json);
85
- debug('json: '+inspect(json));
86
- assert.ok(json.success === true);
87
- assert.ok(json.cmd === 'setname');
88
- var qsRet = {'alpha': 'one', 'beta': '2', 'gamma': 'true'};
89
- assert.deepEqual(qsRet, json.qs);
90
- cb();
91
- });
92
- });
93
-
94
- after(function(cb){
95
- RestApi.stop(function(err) {
96
- if (err) return cb(err);
97
- debug('RestApi stopped successfully');
98
- cb();
99
- });
100
- });
101
- });