@degenerate/generic 0.6.0 → 0.7.0
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/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -0
- package/dist/errors/library/library-errors.d.ts +101 -0
- package/dist/errors/library/library-errors.d.ts.map +1 -0
- package/dist/errors/library/library-errors.js +133 -0
- package/dist/errors/share-data/share-data-errors.d.ts +21 -0
- package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
- package/dist/errors/share-data/share-data-errors.js +30 -1
- package/dist/helpers/apply-share-function.d.ts +23 -0
- package/dist/helpers/apply-share-function.d.ts.map +1 -0
- package/dist/helpers/apply-share-function.js +32 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/library/authorize-library.d.ts +17 -0
- package/dist/library/authorize-library.d.ts.map +1 -0
- package/dist/library/authorize-library.js +39 -0
- package/dist/library/build-library.d.ts +49 -0
- package/dist/library/build-library.d.ts.map +1 -0
- package/dist/library/build-library.js +119 -0
- package/dist/library/caching-library-store.d.ts +19 -0
- package/dist/library/caching-library-store.d.ts.map +1 -0
- package/dist/library/caching-library-store.js +56 -0
- package/dist/library/canonical-json.d.ts +12 -0
- package/dist/library/canonical-json.d.ts.map +1 -0
- package/dist/library/canonical-json.js +30 -0
- package/dist/library/compile-rule-source.d.ts +21 -0
- package/dist/library/compile-rule-source.d.ts.map +1 -0
- package/dist/library/compile-rule-source.js +91 -0
- package/dist/library/evaluate-library-rules.d.ts +36 -0
- package/dist/library/evaluate-library-rules.d.ts.map +1 -0
- package/dist/library/evaluate-library-rules.js +47 -0
- package/dist/library/evaluate-library.d.ts +34 -0
- package/dist/library/evaluate-library.d.ts.map +1 -0
- package/dist/library/evaluate-library.js +66 -0
- package/dist/library/in-memory-library-store.d.ts +22 -0
- package/dist/library/in-memory-library-store.d.ts.map +1 -0
- package/dist/library/in-memory-library-store.js +92 -0
- package/dist/library/index.d.ts +18 -0
- package/dist/library/index.d.ts.map +1 -0
- package/dist/library/index.js +33 -0
- package/dist/library/library-hash.d.ts +9 -0
- package/dist/library/library-hash.d.ts.map +1 -0
- package/dist/library/library-hash.js +14 -0
- package/dist/library/library-models.d.ts +134 -0
- package/dist/library/library-models.d.ts.map +1 -0
- package/dist/library/library-models.js +84 -0
- package/dist/library/library-proof.d.ts +40 -0
- package/dist/library/library-proof.d.ts.map +1 -0
- package/dist/library/library-proof.js +44 -0
- package/dist/library/library-reference.d.ts +75 -0
- package/dist/library/library-reference.d.ts.map +1 -0
- package/dist/library/library-reference.js +98 -0
- package/dist/library/library-server.d.ts +17 -0
- package/dist/library/library-server.d.ts.map +1 -0
- package/dist/library/library-server.js +45 -0
- package/dist/library/library-store.d.ts +37 -0
- package/dist/library/library-store.d.ts.map +1 -0
- package/dist/library/library-store.js +2 -0
- package/dist/library/remote-library-models.d.ts +54 -0
- package/dist/library/remote-library-models.d.ts.map +1 -0
- package/dist/library/remote-library-models.js +2 -0
- package/dist/library/remote-library-store.d.ts +15 -0
- package/dist/library/remote-library-store.d.ts.map +1 -0
- package/dist/library/remote-library-store.js +59 -0
- package/dist/library/verify-library.d.ts +21 -0
- package/dist/library/verify-library.d.ts.map +1 -0
- package/dist/library/verify-library.js +86 -0
- package/dist/models/functions/share-data-function-models.d.ts +6 -74
- package/dist/models/functions/share-data-function-models.d.ts.map +1 -1
- package/dist/models/functions/share-data-function-models.js +7 -65
- package/dist/models/share-data/share-data-models.d.ts +12 -0
- package/dist/models/share-data/share-data-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.js +6 -6
- package/dist/sandbox/in-process-executor.d.ts +13 -0
- package/dist/sandbox/in-process-executor.d.ts.map +1 -0
- package/dist/sandbox/in-process-executor.js +31 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +23 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts +12 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-executor.js +49 -0
- package/dist/sandbox/remote-sandbox-models.d.ts +37 -0
- package/dist/sandbox/remote-sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-models.js +2 -0
- package/dist/sandbox/rule-evaluator.d.ts +32 -0
- package/dist/sandbox/rule-evaluator.d.ts.map +1 -0
- package/dist/sandbox/rule-evaluator.js +23 -0
- package/dist/sandbox/run-sandboxed.d.ts +24 -0
- package/dist/sandbox/run-sandboxed.d.ts.map +1 -0
- package/dist/sandbox/run-sandboxed.js +88 -0
- package/dist/sandbox/sandbox-models.d.ts +40 -0
- package/dist/sandbox/sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/sandbox-models.js +2 -0
- package/dist/sandbox/sandbox-server.d.ts +22 -0
- package/dist/sandbox/sandbox-server.d.ts.map +1 -0
- package/dist/sandbox/sandbox-server.js +62 -0
- package/package.json +2 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSandboxServer = void 0;
|
|
4
|
+
const library_models_1 = require("../library/library-models");
|
|
5
|
+
const in_process_executor_1 = require("./in-process-executor");
|
|
6
|
+
const rule_evaluator_1 = require("./rule-evaluator");
|
|
7
|
+
/**
|
|
8
|
+
* The transport-agnostic sandbox server: it receives a {@link RemoteSandboxRequest},
|
|
9
|
+
* runs it through the in-process executor/evaluator, and returns a
|
|
10
|
+
* {@link RemoteSandboxResponse}. The CONSUMER wires this handler to their HTTP
|
|
11
|
+
* server (an Express route, etc.) — the server itself takes no transport dep.
|
|
12
|
+
*
|
|
13
|
+
* The server is the authority on gas: it clamps the requested `gasLimit` to its
|
|
14
|
+
* own cap, so a client cannot ask for more than the server permits.
|
|
15
|
+
*/
|
|
16
|
+
const createSandboxServer = (options = {}) => {
|
|
17
|
+
const cap = Math.min(options.maxGasUnits ?? library_models_1.MAX_GAS_UNITS, library_models_1.MAX_GAS_UNITS);
|
|
18
|
+
const functionExecutor = (0, in_process_executor_1.createInProcessFunctionExecutor)();
|
|
19
|
+
const ruleEvaluator = (0, rule_evaluator_1.createInProcessRuleEvaluator)();
|
|
20
|
+
return {
|
|
21
|
+
async handle(request) {
|
|
22
|
+
const gasLimit = clampGas(request.gasLimit, cap);
|
|
23
|
+
if (request.kind === 'rule') {
|
|
24
|
+
const result = await ruleEvaluator.evaluate({
|
|
25
|
+
source: request.source,
|
|
26
|
+
current: request.current,
|
|
27
|
+
proposed: (request.proposed ?? {}),
|
|
28
|
+
gasLimit,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
ok: result.ok,
|
|
32
|
+
passed: result.passed,
|
|
33
|
+
failure: result.failure,
|
|
34
|
+
error: result.error,
|
|
35
|
+
gasUsed: result.gasUsed,
|
|
36
|
+
executionTime: result.executionTime,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const result = await functionExecutor.execute({
|
|
40
|
+
source: request.source,
|
|
41
|
+
current: request.current,
|
|
42
|
+
input: request.input,
|
|
43
|
+
gasLimit,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
ok: result.ok,
|
|
47
|
+
output: result.output,
|
|
48
|
+
failure: result.failure,
|
|
49
|
+
error: result.error,
|
|
50
|
+
gasUsed: result.gasUsed,
|
|
51
|
+
executionTime: result.executionTime,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.createSandboxServer = createSandboxServer;
|
|
57
|
+
const clampGas = (requested, cap) => {
|
|
58
|
+
if (!Number.isFinite(requested) || requested < 1) {
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
return Math.min(Math.floor(requested), cap);
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/generic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "This contains the generic information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"jsonwebtoken": "^9.0.3",
|
|
45
45
|
"zod": "^4.4.3"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1f747e160c9022863c7b2d7b8a6a157f204be95b",
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^10.0.1",
|
|
50
50
|
"@types/eslint__js": "^8.42.3",
|