This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
270 lines (256 loc) · 12.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/************************************************************************
* Copyright (c) Crater Dog Technologies(TM). All Rights Reserved. *
************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
* *
* This code is free software; you can redistribute it and/or modify it *
* under the terms of The MIT License (MIT), as published by the Open *
* Source Initiative. (See http://opensource.org/licenses/MIT) *
************************************************************************/
'use strict';
const CachedStorage = require('./src/storage/CachedStorage').CachedStorage;
const ValidatedStorage = require('./src/storage/ValidatedStorage').ValidatedStorage;
const LocalStorage = require('./src/storage/LocalStorage').LocalStorage;
const RemoteStorage = require('./src/storage/RemoteStorage').RemoteStorage;
const S3Storage = require('./src/storage/S3Storage').S3Storage;
const HTMLEngine = require('./src/HTMLEngine').HTMLEngine;
const WebEngine = require('./src/WebEngine').WebEngine;
const DocumentRepository = require('./src/DocumentRepository').DocumentRepository;
/**
* This function initializes a cached storage mechanism. The documents are cached locally in memory
* to increase performance. Since all cached documents are immutable there are no cache consistency
* issues to worry about.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {Object} storage The storage mechanism used to maintain the documents.
* @returns {Object} The new cached storage mechanism instance.
*/
const cached = function(storage, debug) {
return new CachedStorage(storage, debug);
};
exports.cached = cached;
/**
* This function initializes a validated storage mechanism. Each document is validated before being
* stored by the backing storage mechanism and after being retrieved from the backing storage
* mechanism. This is useful when the backing storage mechanism is remote and the documents could be
* modified intentionally or otherwise during transit. The validation is done using a digital notary
* which validates the notary seal on each document using the referenced notary certificate.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} storage The storage mechanism used to maintain the documents.
* @returns {Object} The new validating storage mechanism wrapper.
*/
const validated = function(notary, storage, debug) {
return new ValidatedStorage(notary, storage, debug);
};
exports.validated = validated;
/**
* This function initializes a local filesystem based storage mechanism. It provides no security
* around the filesystem and should ONLY be used for local testing.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {String} directory The top level directory to be used as a local storage mechanism.
* @returns {Object} The new file-based storage mechanism instance.
*/
const local = function(notary, directory, debug) {
return new LocalStorage(notary, directory, debug);
};
exports.local = local;
/**
* This function initializes a remote storage mechanism proxy implementation. It accesses a
* remote storage mechanism service via an HTTPS interface exposed at the specified URI.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Resource} uri A resource that defines the URI for the remote storage.
* @returns {Object} The new remote storage mechanism proxy.
*/
const remote = function(notary, uri, debug) {
return new RemoteStorage(notary, uri, debug);
};
exports.remote = remote;
/**
* This function initializes an AWS S3 based storage mechanism proxy implementation. It stores
* the documents in S3 buckets by type.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} configuration An object containing the configuration for the S3 buckets
* @returns {Object} The new AWS S3-based storage mechanism instance.
*/
const s3 = function(notary, configuration, debug) {
return new S3Storage(notary, configuration, debug);
};
exports.s3 = s3;
/**
* This function initializes a storage mechanism configured with a local, memory-based cache that
* maintains the files in the local filesystem. It should ONLY be used for testing purposes.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {String} directory The top level directory to be used as a local storage mechanism.
* @returns {Object} The new storage mechanism instance.
*/
const test = function(notary, directory, debug) {
return cached(validated(notary, local(notary, directory, debug), debug), debug);
};
exports.test = test;
/**
* This function initializes a storage mechanism configured with a local, memory based cache that
* maintains the documents using a remote storage mechanism. It performs validation on each document
* before storing it and after retrieving it from the remote storage mechanism.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Resource} uri A resource that defines the URI for the remote storage.
* @returns {Object} The new storage mechanism instance.
*/
const client = function(notary, uri, debug) {
return cached(validated(notary, remote(notary, uri, debug), debug), debug);
};
exports.client = client;
/**
* This function initializes a storage mechanism configured with an AWS S3-based storage mechanism.
* It performs validation on each document before storing it and after retrieving it from the S3-based
* storage mechanism.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} configuration An object containing the configuration for the S3-based storage
* mechanism.
* @returns {Object} The new storage mechanism instance.
*/
const service = function(notary, configuration, debug) {
return validated(notary, s3(notary, configuration, debug), debug);
};
exports.service = service;
/**
* This function initializes an HTML engine with a digital notary and a storage mechanism.
* It enforces the symantics for HTTP requests involving HEAD, GET, PUT, POST, and DELETE methods.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} storage The storage mechanism maintaining the documents being managed
* through the HTTP service interface.
* @returns {HTMLEngine} The HTML engine.
*/
const html = function(notary, storage, debug) {
return new HTMLEngine(notary, storage, debug);
};
exports.html = html;
/**
* This function initializes a web service engine with a digital notary and a storage mechanism.
* It enforces the symantics for HTTP requests involving HEAD, GET, PUT, POST, and DELETE methods.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} storage The storage mechanism maintaining the documents being managed
* through the HTTP service interface.
* @returns {WebEngine} The web service engine.
*/
const web = function(notary, storage, debug) {
return new WebEngine(notary, storage, debug);
};
exports.web = web;
/**
* This function initializes a document repository backed by the specified storage mechanism.
*
* An optional debug argument may be specified that controls the level of debugging that
* should be applied during execution. The allowed levels are as follows:
* <pre>
* 0: no debugging is applied (this is the default value and has the best performance)
* 1: log any exceptions to console.error before throwing them
* 2: perform argument validation checks on each call (poor performance)
* 3: log interesting arguments, states and results to console.log
* </pre>
*
* @param {DigitalNotary} notary An object that implements the digital notary API.
* @param {Object} storage The storage mechanism used to maintain the documents.
* @returns {DocumentRepository} The new document repository instance.
*/
const repository = function(notary, storage, debug) {
return new DocumentRepository(notary, storage, debug);
};
exports.repository = repository;