@ouroboros/body 0.1.3 → 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.
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@ouroboros/body",
3
- "version": "0.1.3",
3
+ "version": "1.0.1",
4
4
  "description": "Classes to communicate with Ouroboros Coding Inc. body services",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
7
  "scripts": {
8
- "test": "echo \"Error: no test specified.\" && exit 1"
9
- },
8
+ "build": "tslint -p tsconfig.json && tsc",
9
+ "clean": "rm src/*.js src/*.d.ts",
10
+ "test": "echo \"Error: no test specified.\" && exit 1"
11
+ },
10
12
  "repository": {
11
13
  "type": "git",
12
14
  "url": "git+https://github.com/ouroboroscoding/body-js.git"
@@ -20,10 +22,11 @@
20
22
  "bugs": {
21
23
  "url": "https://github.com/ouroboroscoding/body-js/issues"
22
24
  },
23
- "devDependencies": {},
24
- "dependencies": {
25
- "@ouroboros/browser": "^0.1.3",
26
- "@ouroboros/events": "^0.1.0",
27
- "@ouroboros/tools": "^0.3.2"
28
- }
29
- }
25
+ "devDependencies": {
26
+ "tslint": "^6.1.3",
27
+ "tslint-config-prettier": "^1.18.0",
28
+ "typescript": "^4.8.3"
29
+ },
30
+ "dependencies": {},
31
+ "peerDependencies": {}
32
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Service
3
+ *
4
+ * Used to extend by modules that want to give direct access to a single service
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ import { onError, onErrorCode, onRequested, onRequesting } from './';
11
+ /**
12
+ * Service
13
+ *
14
+ * Provides calls to create, read, update, and delete on one specific service
15
+ *
16
+ * @name Service
17
+ */
18
+ export default class Service {
19
+ service: string;
20
+ /**
21
+ * Constructor
22
+ *
23
+ * Creates a new instance
24
+ *
25
+ * @name Service
26
+ * @access public
27
+ * @param service The name of the service to make all requests to
28
+ * @returns a new instance
29
+ */
30
+ constructor(service: string);
31
+ /**
32
+ * Create
33
+ *
34
+ * Calls a create (POST) request on the service associated with this
35
+ * instance
36
+ *
37
+ * @name create
38
+ * @access public
39
+ * @param noun The noun to call on the service
40
+ * @param data The data associated with the request
41
+ */
42
+ create(noun: string, data?: any): Promise<any>;
43
+ /**
44
+ * Delete
45
+ *
46
+ * Calls a delete (DELETE) request on the service associated with this
47
+ * instance
48
+ *
49
+ * @name delete
50
+ * @access public
51
+ * @param noun The noun to call on the service
52
+ * @param data The data associated with the request
53
+ */
54
+ delete(noun: string, data?: any): Promise<any>;
55
+ /**
56
+ * On Error
57
+ *
58
+ * Sets callback for whenever body has an error
59
+ *
60
+ * @name onError
61
+ * @access public
62
+ */
63
+ onError(callback: onError): void;
64
+ /**
65
+ * On Error Code
66
+ *
67
+ * Sets callback for whenever an error code isn't handled internally
68
+ *
69
+ * @name onErrorCode
70
+ * @access public
71
+ */
72
+ onErrorCode(callback: onErrorCode): void;
73
+ /**
74
+ * On Requested
75
+ *
76
+ * Sets the callback called after any request is sent out
77
+ *
78
+ * @name onRequesting
79
+ * @access public
80
+ * @param callback The function to call after making requests
81
+ */
82
+ onRequested(callback: onRequested): void;
83
+ /**
84
+ * On Requesting
85
+ *
86
+ * Sets the callback called before any request is send out
87
+ *
88
+ * @name onRequesting
89
+ * @access public
90
+ * @param callback The function to call before making requests
91
+ */
92
+ onRequesting(callback: onRequesting): void;
93
+ /**
94
+ * Read
95
+ *
96
+ * Calls a read (GET) request on the service associated with this instance
97
+ *
98
+ * @name read
99
+ * @access public
100
+ * @param noun The noun to call on the service
101
+ * @param data The data associated with the request
102
+ */
103
+ read(noun: string, data?: any): Promise<any>;
104
+ /**
105
+ * Session
106
+ *
107
+ * Set/Gets the current session token
108
+ *
109
+ * @name session
110
+ * @access public
111
+ * @param token The session to set
112
+ * @returns the session set
113
+ */
114
+ session(token?: string | null): string | null | void;
115
+ /**
116
+ * Update
117
+ *
118
+ * Calls a update (PUT) request on the service associated with this instance
119
+ *
120
+ * @name update
121
+ * @access public
122
+ * @param noun The noun to call on the service
123
+ * @param data The data associated with the request
124
+ */
125
+ update(noun: string, data?: any): Promise<any>;
126
+ }
package/src/Service.js ADDED
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Service
3
+ *
4
+ * Used to extend by modules that want to give direct access to a single service
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ // Local modules
11
+ import body from './';
12
+ /**
13
+ * Service
14
+ *
15
+ * Provides calls to create, read, update, and delete on one specific service
16
+ *
17
+ * @name Service
18
+ */
19
+ export default class Service {
20
+ // The service associated with this instance
21
+ service;
22
+ /**
23
+ * Constructor
24
+ *
25
+ * Creates a new instance
26
+ *
27
+ * @name Service
28
+ * @access public
29
+ * @param service The name of the service to make all requests to
30
+ * @returns a new instance
31
+ */
32
+ constructor(service) {
33
+ this.service = service;
34
+ }
35
+ /**
36
+ * Create
37
+ *
38
+ * Calls a create (POST) request on the service associated with this
39
+ * instance
40
+ *
41
+ * @name create
42
+ * @access public
43
+ * @param noun The noun to call on the service
44
+ * @param data The data associated with the request
45
+ */
46
+ create(noun, data = null) {
47
+ return body.request('create', this.service, noun, data);
48
+ }
49
+ /**
50
+ * Delete
51
+ *
52
+ * Calls a delete (DELETE) request on the service associated with this
53
+ * instance
54
+ *
55
+ * @name delete
56
+ * @access public
57
+ * @param noun The noun to call on the service
58
+ * @param data The data associated with the request
59
+ */
60
+ delete(noun, data = null) {
61
+ return body.request('delete', this.service, noun, data);
62
+ }
63
+ /**
64
+ * On Error
65
+ *
66
+ * Sets callback for whenever body has an error
67
+ *
68
+ * @name onError
69
+ * @access public
70
+ */
71
+ onError(callback) {
72
+ body.onError(callback);
73
+ }
74
+ /**
75
+ * On Error Code
76
+ *
77
+ * Sets callback for whenever an error code isn't handled internally
78
+ *
79
+ * @name onErrorCode
80
+ * @access public
81
+ */
82
+ onErrorCode(callback) {
83
+ body.onErrorCode(callback);
84
+ }
85
+ /**
86
+ * On Requested
87
+ *
88
+ * Sets the callback called after any request is sent out
89
+ *
90
+ * @name onRequesting
91
+ * @access public
92
+ * @param callback The function to call after making requests
93
+ */
94
+ onRequested(callback) {
95
+ return body.onRequested(callback);
96
+ }
97
+ /**
98
+ * On Requesting
99
+ *
100
+ * Sets the callback called before any request is send out
101
+ *
102
+ * @name onRequesting
103
+ * @access public
104
+ * @param callback The function to call before making requests
105
+ */
106
+ onRequesting(callback) {
107
+ return body.onRequesting(callback);
108
+ }
109
+ /**
110
+ * Read
111
+ *
112
+ * Calls a read (GET) request on the service associated with this instance
113
+ *
114
+ * @name read
115
+ * @access public
116
+ * @param noun The noun to call on the service
117
+ * @param data The data associated with the request
118
+ */
119
+ read(noun, data = null) {
120
+ return body.request('read', this.service, noun, data);
121
+ }
122
+ /**
123
+ * Session
124
+ *
125
+ * Set/Gets the current session token
126
+ *
127
+ * @name session
128
+ * @access public
129
+ * @param token The session to set
130
+ * @returns the session set
131
+ */
132
+ session(token) {
133
+ return body.session(token);
134
+ }
135
+ /**
136
+ * Update
137
+ *
138
+ * Calls a update (PUT) request on the service associated with this instance
139
+ *
140
+ * @name update
141
+ * @access public
142
+ * @param noun The noun to call on the service
143
+ * @param data The data associated with the request
144
+ */
145
+ update(noun, data = null) {
146
+ return body.request('update', this.service, noun, data);
147
+ }
148
+ }
package/src/Service.ts ADDED
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Service
3
+ *
4
+ * Used to extend by modules that want to give direct access to a single service
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+
11
+ // Local modules
12
+ import body from './';
13
+
14
+ // Types
15
+ import {
16
+ onError, onErrorCode, onRequested, onRequesting, responseStruct
17
+ } from './';
18
+
19
+ /**
20
+ * Service
21
+ *
22
+ * Provides calls to create, read, update, and delete on one specific service
23
+ *
24
+ * @name Service
25
+ */
26
+ export default class Service {
27
+
28
+ // The service associated with this instance
29
+ service: string;
30
+
31
+ /**
32
+ * Constructor
33
+ *
34
+ * Creates a new instance
35
+ *
36
+ * @name Service
37
+ * @access public
38
+ * @param service The name of the service to make all requests to
39
+ * @returns a new instance
40
+ */
41
+ constructor(service: string) {
42
+ this.service = service;
43
+ }
44
+
45
+ /**
46
+ * Create
47
+ *
48
+ * Calls a create (POST) request on the service associated with this
49
+ * instance
50
+ *
51
+ * @name create
52
+ * @access public
53
+ * @param noun The noun to call on the service
54
+ * @param data The data associated with the request
55
+ */
56
+ create(noun: string, data: any = null): Promise<any> {
57
+ return body.request('create', this.service, noun, data);
58
+ }
59
+
60
+ /**
61
+ * Delete
62
+ *
63
+ * Calls a delete (DELETE) request on the service associated with this
64
+ * instance
65
+ *
66
+ * @name delete
67
+ * @access public
68
+ * @param noun The noun to call on the service
69
+ * @param data The data associated with the request
70
+ */
71
+ delete(noun: string, data: any = null): Promise<any> {
72
+ return body.request('delete', this.service, noun, data);
73
+ }
74
+
75
+ /**
76
+ * On Error
77
+ *
78
+ * Sets callback for whenever body has an error
79
+ *
80
+ * @name onError
81
+ * @access public
82
+ */
83
+ onError(callback: onError): void {
84
+ body.onError(callback);
85
+ }
86
+
87
+ /**
88
+ * On Error Code
89
+ *
90
+ * Sets callback for whenever an error code isn't handled internally
91
+ *
92
+ * @name onErrorCode
93
+ * @access public
94
+ */
95
+ onErrorCode(callback: onErrorCode): void {
96
+ body.onErrorCode(callback);
97
+ }
98
+
99
+ /**
100
+ * On Requested
101
+ *
102
+ * Sets the callback called after any request is sent out
103
+ *
104
+ * @name onRequesting
105
+ * @access public
106
+ * @param callback The function to call after making requests
107
+ */
108
+ onRequested(callback: onRequested): void {
109
+ return body.onRequested(callback);
110
+ }
111
+
112
+ /**
113
+ * On Requesting
114
+ *
115
+ * Sets the callback called before any request is send out
116
+ *
117
+ * @name onRequesting
118
+ * @access public
119
+ * @param callback The function to call before making requests
120
+ */
121
+ onRequesting(callback: onRequesting): void {
122
+ return body.onRequesting(callback);
123
+ }
124
+
125
+ /**
126
+ * Read
127
+ *
128
+ * Calls a read (GET) request on the service associated with this instance
129
+ *
130
+ * @name read
131
+ * @access public
132
+ * @param noun The noun to call on the service
133
+ * @param data The data associated with the request
134
+ */
135
+ read(noun: string, data: any = null): Promise<any> {
136
+ return body.request('read', this.service, noun, data);
137
+ }
138
+
139
+ /**
140
+ * Session
141
+ *
142
+ * Set/Gets the current session token
143
+ *
144
+ * @name session
145
+ * @access public
146
+ * @param token The session to set
147
+ * @returns the session set
148
+ */
149
+ session(token?: string | null): string | null | void {
150
+ return body.session(token);
151
+ }
152
+
153
+ /**
154
+ * Update
155
+ *
156
+ * Calls a update (PUT) request on the service associated with this instance
157
+ *
158
+ * @name update
159
+ * @access public
160
+ * @param noun The noun to call on the service
161
+ * @param data The data associated with the request
162
+ */
163
+ update(noun: string, data: any = null): Promise<any> {
164
+ return body.request('update', this.service, noun, data);
165
+ }
166
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Constants
3
+ *
4
+ * Holds constants
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ export declare const EMPTY_UUID = "00000000-0000-4000-8000-000000000000";
11
+ export declare const SECONDS_HOUR = 3600;
12
+ export declare const SECONDS_DAY = 86400;
13
+ export declare const SECONDS_WEEK = 604800;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Constants
3
+ *
4
+ * Holds constants
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ // Empty UUID
11
+ export const EMPTY_UUID = '00000000-0000-4000-8000-000000000000';
12
+ // Seconds
13
+ export const SECONDS_HOUR = 3600;
14
+ export const SECONDS_DAY = 86400;
15
+ export const SECONDS_WEEK = 604800;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Constants
3
+ *
4
+ * Holds constants
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+
11
+ // Empty UUID
12
+ export const EMPTY_UUID = '00000000-0000-4000-8000-000000000000'
13
+
14
+ // Seconds
15
+ export const SECONDS_HOUR = 3600
16
+ export const SECONDS_DAY = 86400
17
+ export const SECONDS_WEEK = 604800
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Errors
3
+ *
4
+ * Holds constants for error codes
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ export declare const REST_REQUEST_DATA = 100;
11
+ export declare const REST_CONTENT_TYPE = 101;
12
+ export declare const REST_AUTHORIZATION = 102;
13
+ export declare const SERVICE_ACTION = 200;
14
+ export declare const SERVICE_STATUS = 201;
15
+ export declare const SERVICE_CONTENT_TYPE = 202;
16
+ export declare const SERVICE_UNREACHABLE = 203;
17
+ export declare const SERVICE_NOT_REGISTERED = 204;
18
+ export declare const SERVICE_NO_SUCH_NOUN = 205;
19
+ export declare const SERVICE_INTERNAL_KEY = 206;
20
+ export declare const SERVICE_CRASHED = 207;
21
+ export declare const SERVICE_NO_DATA = 208;
22
+ export declare const SERVICE_NO_SESSION = 209;
23
+ export declare const RIGHTS = 1000;
24
+ export declare const DATA_FIELDS = 1001;
25
+ export declare const ALREADY_DONE = 1002;
26
+ export declare const DB_NO_RECORD = 1100;
27
+ export declare const DB_DUPLICATE = 1101;
28
+ export declare const DB_CREATE_FAILED = 1102;
29
+ export declare const DB_DELETE_FAILED = 1103;
30
+ export declare const DB_UPDATE_FAILED = 1104;
31
+ export declare const DB_KEY_BEING_USED = 1105;
32
+ export declare const DB_ARCHIVED = 1106;
package/src/errors.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Errors
3
+ *
4
+ * Holds constants for error codes
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+ // Rest-OC REST related
11
+ export const REST_REQUEST_DATA = 100;
12
+ export const REST_CONTENT_TYPE = 101;
13
+ export const REST_AUTHORIZATION = 102;
14
+ // Rest-OC Service related
15
+ export const SERVICE_ACTION = 200;
16
+ export const SERVICE_STATUS = 201;
17
+ export const SERVICE_CONTENT_TYPE = 202;
18
+ export const SERVICE_UNREACHABLE = 203;
19
+ export const SERVICE_NOT_REGISTERED = 204;
20
+ export const SERVICE_NO_SUCH_NOUN = 205;
21
+ export const SERVICE_INTERNAL_KEY = 206;
22
+ export const SERVICE_CRASHED = 207;
23
+ export const SERVICE_NO_DATA = 208;
24
+ export const SERVICE_NO_SESSION = 209;
25
+ // Body related
26
+ export const RIGHTS = 1000;
27
+ export const DATA_FIELDS = 1001;
28
+ export const ALREADY_DONE = 1002;
29
+ // DB related
30
+ export const DB_NO_RECORD = 1100;
31
+ export const DB_DUPLICATE = 1101;
32
+ export const DB_CREATE_FAILED = 1102;
33
+ export const DB_DELETE_FAILED = 1103;
34
+ export const DB_UPDATE_FAILED = 1104;
35
+ export const DB_KEY_BEING_USED = 1105;
36
+ export const DB_ARCHIVED = 1106;
package/src/errors.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Errors
3
+ *
4
+ * Holds constants for error codes
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2023-03-05
9
+ */
10
+
11
+ // Rest-OC REST related
12
+ export const REST_REQUEST_DATA = 100
13
+ export const REST_CONTENT_TYPE = 101
14
+ export const REST_AUTHORIZATION = 102
15
+
16
+ // Rest-OC Service related
17
+ export const SERVICE_ACTION = 200
18
+ export const SERVICE_STATUS = 201
19
+ export const SERVICE_CONTENT_TYPE = 202
20
+ export const SERVICE_UNREACHABLE = 203
21
+ export const SERVICE_NOT_REGISTERED = 204
22
+ export const SERVICE_NO_SUCH_NOUN = 205
23
+ export const SERVICE_INTERNAL_KEY = 206
24
+ export const SERVICE_CRASHED = 207
25
+ export const SERVICE_NO_DATA = 208
26
+ export const SERVICE_NO_SESSION = 209
27
+
28
+ // Body related
29
+ export const RIGHTS = 1000
30
+ export const DATA_FIELDS = 1001
31
+ export const ALREADY_DONE = 1002
32
+
33
+ // DB related
34
+ export const DB_NO_RECORD = 1100
35
+ export const DB_DUPLICATE = 1101
36
+ export const DB_CREATE_FAILED = 1102
37
+ export const DB_DELETE_FAILED = 1103
38
+ export const DB_UPDATE_FAILED = 1104
39
+ export const DB_KEY_BEING_USED = 1105
40
+ export const DB_ARCHIVED = 1106