@jplorg/jpl 1.5.0 → 2.1.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/esm/main.js +3474 -0
- package/dist/types/applyDefaults.d.ts +2 -0
- package/dist/types/builtins/funcContains.d.ts +3 -0
- package/dist/types/builtins/funcEndsWith.d.ts +3 -0
- package/dist/types/builtins/funcError.d.ts +3 -0
- package/dist/types/builtins/funcFromJSON.d.ts +3 -0
- package/dist/types/builtins/funcHas.d.ts +3 -0
- package/dist/types/builtins/funcIn.d.ts +3 -0
- package/dist/types/builtins/funcKeys.d.ts +3 -0
- package/dist/types/builtins/funcLength.d.ts +3 -0
- package/dist/types/builtins/funcNow.d.ts +3 -0
- package/dist/types/builtins/funcStartsWith.d.ts +3 -0
- package/dist/types/builtins/funcToJSON.d.ts +3 -0
- package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
- package/dist/types/builtins/funcToNumber.d.ts +3 -0
- package/dist/types/builtins/funcToString.d.ts +3 -0
- package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
- package/dist/types/builtins/funcTrim.d.ts +3 -0
- package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
- package/dist/types/builtins/funcTrimStart.d.ts +3 -0
- package/dist/types/builtins/funcType.d.ts +3 -0
- package/dist/types/builtins/funcVoid.d.ts +3 -0
- package/dist/types/builtins/index.d.ts +2 -0
- package/dist/types/builtins/internals.d.ts +1 -0
- package/dist/types/builtins/math.d.ts +17 -0
- package/dist/types/createSingleton.d.ts +1 -0
- package/dist/types/interpreter/index.d.ts +21 -0
- package/dist/types/interpreter/parse.d.ts +194 -0
- package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
- package/dist/types/interpreter/system.d.ts +3 -0
- package/dist/types/interpreter/util.d.ts +89 -0
- package/dist/types/library/apply.d.ts +32 -0
- package/dist/types/library/definition.d.ts +79 -0
- package/dist/types/library/errors/adaptErrors.d.ts +6 -0
- package/dist/types/library/errors/enclosure.d.ts +6 -0
- package/dist/types/library/errors/error.d.ts +6 -0
- package/dist/types/library/errors/execution.d.ts +12 -0
- package/dist/types/library/errors/fatal.d.ts +4 -0
- package/dist/types/library/errors/runtime.d.ts +46 -0
- package/dist/types/library/errors/syntax.d.ts +7 -0
- package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
- package/dist/types/library/index.d.ts +18 -0
- package/dist/types/library/mux.d.ts +19 -0
- package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
- package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
- package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
- package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
- package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
- package/dist/types/library/runtimeScope.d.ts +23 -0
- package/dist/types/library/runtimeSignal.d.ts +25 -0
- package/dist/types/library/types.d.ts +97 -0
- package/dist/types/main.d.ts +19 -0
- package/dist/types/program/handler.d.ts +12 -0
- package/dist/types/program/index.d.ts +40 -0
- package/dist/types/program/ops/index.d.ts +5 -0
- package/dist/types/program/ops/opAccess/index.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
- package/dist/types/program/ops/opAnd.d.ts +11 -0
- package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opComparison/index.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
- package/dist/types/program/ops/opConstant.d.ts +11 -0
- package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
- package/dist/types/program/ops/opConstantNull.d.ts +11 -0
- package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
- package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
- package/dist/types/program/ops/opIf.d.ts +11 -0
- package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
- package/dist/types/program/ops/opNegation.d.ts +11 -0
- package/dist/types/program/ops/opNot.d.ts +11 -0
- package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opNumber.d.ts +11 -0
- package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
- package/dist/types/program/ops/opOr.d.ts +11 -0
- package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
- package/dist/types/program/ops/opString.d.ts +11 -0
- package/dist/types/program/ops/opTry.d.ts +11 -0
- package/dist/types/program/ops/opVariable.d.ts +11 -0
- package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
- package/dist/types/program/ops/opVoid.d.ts +11 -0
- package/dist/types/program/ops/utils.d.ts +5 -0
- package/dist/types/program/params.d.ts +68 -0
- package/dist/types/runtime/index.d.ts +83 -0
- package/package.json +66 -49
- package/{repl.js → repl.ts} +85 -39
- package/lib/applyDefaults.js +0 -34
- package/lib/builtins/funcContains.js +0 -25
- package/lib/builtins/funcEndsWith.js +0 -21
- package/lib/builtins/funcError.js +0 -11
- package/lib/builtins/funcFromJSON.js +0 -26
- package/lib/builtins/funcHas.js +0 -24
- package/lib/builtins/funcIn.js +0 -24
- package/lib/builtins/funcKeys.js +0 -20
- package/lib/builtins/funcLength.js +0 -24
- package/lib/builtins/funcNow.js +0 -10
- package/lib/builtins/funcStartsWith.js +0 -21
- package/lib/builtins/funcToJSON.js +0 -10
- package/lib/builtins/funcToLowerCase.js +0 -17
- package/lib/builtins/funcToNumber.js +0 -26
- package/lib/builtins/funcToString.js +0 -10
- package/lib/builtins/funcToUpperCase.js +0 -17
- package/lib/builtins/funcTrim.js +0 -17
- package/lib/builtins/funcTrimEnd.js +0 -17
- package/lib/builtins/funcTrimStart.js +0 -17
- package/lib/builtins/funcType.js +0 -10
- package/lib/builtins/funcVoid.js +0 -10
- package/lib/builtins/index.js +0 -205
- package/lib/builtins/internals.js +0 -8
- package/lib/builtins/math.js +0 -40
- package/lib/builtins/native.js +0 -180
- package/lib/createSingleton.js +0 -14
- package/lib/index.js +0 -79
- package/lib/interpreter/index.js +0 -56
- package/lib/interpreter/parse.js +0 -2377
- package/lib/interpreter/parseFunction.js +0 -24
- package/lib/interpreter/system.js +0 -10
- package/lib/interpreter/util.js +0 -349
- package/lib/library/apply.js +0 -142
- package/lib/library/definition.js +0 -9
- package/lib/library/errors/adaptErrors.js +0 -34
- package/lib/library/errors/enclosure.js +0 -16
- package/lib/library/errors/error.js +0 -18
- package/lib/library/errors/execution.js +0 -20
- package/lib/library/errors/fatal.js +0 -15
- package/lib/library/errors/runtime.js +0 -78
- package/lib/library/errors/syntax.js +0 -17
- package/lib/library/functions.js +0 -82
- package/lib/library/index.js +0 -335
- package/lib/library/mux.js +0 -106
- package/lib/library/ops/index.js +0 -60
- package/lib/library/ops/op.js +0 -180
- package/lib/library/ops/opa.js +0 -41
- package/lib/library/ops/opc.js +0 -59
- package/lib/library/ops/opm.js +0 -50
- package/lib/library/ops/opu.js +0 -77
- package/lib/library/runtimeScope.js +0 -38
- package/lib/library/runtimeSignal.js +0 -72
- package/lib/library/types.js +0 -304
- package/lib/program/index.js +0 -101
- package/lib/program/ops/index.js +0 -61
- package/lib/program/ops/opAccess/index.js +0 -55
- package/lib/program/ops/opAccess/opaField.js +0 -50
- package/lib/program/ops/opAccess/opaFunction.js +0 -50
- package/lib/program/ops/opAccess/opaIter.js +0 -31
- package/lib/program/ops/opAccess/opaSlice.js +0 -44
- package/lib/program/ops/opAnd.js +0 -30
- package/lib/program/ops/opArrayConstructor.js +0 -20
- package/lib/program/ops/opAssignment/index.js +0 -90
- package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
- package/lib/program/ops/opAssignment/opaAssignIter.js +0 -69
- package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -99
- package/lib/program/ops/opAssignment/opuAddition.js +0 -31
- package/lib/program/ops/opAssignment/opuDivision.js +0 -31
- package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
- package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
- package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
- package/lib/program/ops/opAssignment/opuSet.js +0 -19
- package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
- package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
- package/lib/program/ops/opCalculation/index.js +0 -57
- package/lib/program/ops/opCalculation/opmAddition.js +0 -49
- package/lib/program/ops/opCalculation/opmDivision.js +0 -42
- package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
- package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
- package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
- package/lib/program/ops/opComparison/index.js +0 -59
- package/lib/program/ops/opComparison/opcEqual.js +0 -19
- package/lib/program/ops/opComparison/opcGreater.js +0 -19
- package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
- package/lib/program/ops/opComparison/opcLess.js +0 -19
- package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
- package/lib/program/ops/opComparison/opcUnequal.js +0 -19
- package/lib/program/ops/opConstant.js +0 -18
- package/lib/program/ops/opConstantFalse.js +0 -16
- package/lib/program/ops/opConstantNull.js +0 -16
- package/lib/program/ops/opConstantTrue.js +0 -16
- package/lib/program/ops/opFunctionDefinition.js +0 -21
- package/lib/program/ops/opIf.js +0 -38
- package/lib/program/ops/opInterpolatedString.js +0 -24
- package/lib/program/ops/opNegation.js +0 -25
- package/lib/program/ops/opNot.js +0 -16
- package/lib/program/ops/opNullCoalescence.js +0 -34
- package/lib/program/ops/opNumber.js +0 -18
- package/lib/program/ops/opObjectConstructor.js +0 -37
- package/lib/program/ops/opOr.js +0 -30
- package/lib/program/ops/opOutputConcat.js +0 -19
- package/lib/program/ops/opString.js +0 -18
- package/lib/program/ops/opTry.js +0 -37
- package/lib/program/ops/opVariable.js +0 -20
- package/lib/program/ops/opVariableDefinition.js +0 -24
- package/lib/program/ops/opVoid.js +0 -16
- package/lib/program/ops/utils.js +0 -35
- package/lib/runtime/index.js +0 -258
- package/src/applyDefaults.js +0 -35
- package/src/builtins/funcContains.js +0 -27
- package/src/builtins/funcEndsWith.js +0 -21
- package/src/builtins/funcError.js +0 -7
- package/src/builtins/funcFromJSON.js +0 -24
- package/src/builtins/funcHas.js +0 -25
- package/src/builtins/funcIn.js +0 -25
- package/src/builtins/funcKeys.js +0 -20
- package/src/builtins/funcLength.js +0 -26
- package/src/builtins/funcNow.js +0 -5
- package/src/builtins/funcStartsWith.js +0 -21
- package/src/builtins/funcToJSON.js +0 -5
- package/src/builtins/funcToLowerCase.js +0 -20
- package/src/builtins/funcToNumber.js +0 -25
- package/src/builtins/funcToString.js +0 -5
- package/src/builtins/funcToUpperCase.js +0 -20
- package/src/builtins/funcTrim.js +0 -16
- package/src/builtins/funcTrimEnd.js +0 -16
- package/src/builtins/funcTrimStart.js +0 -16
- package/src/builtins/funcType.js +0 -5
- package/src/builtins/funcVoid.js +0 -5
- package/src/builtins/index.js +0 -193
- package/src/builtins/internals.js +0 -9
- package/src/builtins/math.js +0 -44
- package/src/createSingleton.js +0 -9
- package/src/index.js +0 -44
- package/src/interpreter/index.js +0 -48
- package/src/interpreter/parse.js +0 -1473
- package/src/interpreter/system.js +0 -5
- package/src/interpreter/util.js +0 -237
- package/src/library/apply.js +0 -135
- package/src/library/definition.js +0 -3
- package/src/library/errors/adaptErrors.js +0 -28
- package/src/library/errors/enclosure.js +0 -11
- package/src/library/errors/error.js +0 -14
- package/src/library/errors/execution.js +0 -15
- package/src/library/errors/fatal.js +0 -10
- package/src/library/errors/runtime.js +0 -71
- package/src/library/errors/syntax.js +0 -12
- package/src/library/index.js +0 -41
- package/src/library/mux.js +0 -98
- package/src/library/runtimeScope.js +0 -35
- package/src/library/runtimeSignal.js +0 -67
- package/src/library/types.js +0 -299
- package/src/program/index.js +0 -114
- package/src/program/ops/index.js +0 -82
- package/src/program/ops/opAccess/index.js +0 -55
- package/src/program/ops/opAccess/opaField.js +0 -58
- package/src/program/ops/opAccess/opaFunction.js +0 -52
- package/src/program/ops/opAccess/opaIter.js +0 -31
- package/src/program/ops/opAccess/opaSlice.js +0 -58
- package/src/program/ops/opAnd.js +0 -32
- package/src/program/ops/opArrayConstructor.js +0 -16
- package/src/program/ops/opAssignment/index.js +0 -102
- package/src/program/ops/opAssignment/opaAssignField.js +0 -156
- package/src/program/ops/opAssignment/opaAssignIter.js +0 -74
- package/src/program/ops/opAssignment/opaAssignSlice.js +0 -157
- package/src/program/ops/opAssignment/opuAddition.js +0 -29
- package/src/program/ops/opAssignment/opuDivision.js +0 -29
- package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
- package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
- package/src/program/ops/opAssignment/opuRemainder.js +0 -29
- package/src/program/ops/opAssignment/opuSet.js +0 -15
- package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
- package/src/program/ops/opAssignment/opuUpdate.js +0 -15
- package/src/program/ops/opCalculation/index.js +0 -64
- package/src/program/ops/opCalculation/opmAddition.js +0 -63
- package/src/program/ops/opCalculation/opmDivision.js +0 -47
- package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
- package/src/program/ops/opCalculation/opmRemainder.js +0 -49
- package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
- package/src/program/ops/opComparison/index.js +0 -67
- package/src/program/ops/opComparison/opcEqual.js +0 -17
- package/src/program/ops/opComparison/opcGreater.js +0 -17
- package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
- package/src/program/ops/opComparison/opcLess.js +0 -17
- package/src/program/ops/opComparison/opcLessEqual.js +0 -17
- package/src/program/ops/opComparison/opcUnequal.js +0 -17
- package/src/program/ops/opConstant.js +0 -13
- package/src/program/ops/opConstantFalse.js +0 -11
- package/src/program/ops/opConstantNull.js +0 -11
- package/src/program/ops/opConstantTrue.js +0 -11
- package/src/program/ops/opFunctionDefinition.js +0 -17
- package/src/program/ops/opIf.js +0 -44
- package/src/program/ops/opInterpolatedString.js +0 -27
- package/src/program/ops/opNegation.js +0 -26
- package/src/program/ops/opNot.js +0 -11
- package/src/program/ops/opNullCoalescence.js +0 -36
- package/src/program/ops/opNumber.js +0 -13
- package/src/program/ops/opObjectConstructor.js +0 -40
- package/src/program/ops/opOr.js +0 -32
- package/src/program/ops/opOutputConcat.js +0 -17
- package/src/program/ops/opString.js +0 -13
- package/src/program/ops/opTry.js +0 -38
- package/src/program/ops/opVariable.js +0 -17
- package/src/program/ops/opVariableDefinition.js +0 -18
- package/src/program/ops/opVoid.js +0 -11
- package/src/program/ops/utils.js +0 -19
- package/src/runtime/index.js +0 -309
- /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
- /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { applyObject } from './apply';
|
|
2
|
-
import JPLRuntimeSignal from './runtimeSignal';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Runtime scope for managing contextual runtime information.
|
|
6
|
-
*
|
|
7
|
-
* Fields of the scope must not be modified directly.
|
|
8
|
-
* Instead, `JPLRuntimeScope.next` should be used to create a sub scope with the specified modifications.
|
|
9
|
-
*/
|
|
10
|
-
class JPLRuntimeScope {
|
|
11
|
-
constructor(presets = {}) {
|
|
12
|
-
this._state = {
|
|
13
|
-
signal: presets.signal ?? new JPLRuntimeSignal(),
|
|
14
|
-
vars: presets.vars ?? {},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get signal() {
|
|
19
|
-
return this._state.signal;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get vars() {
|
|
23
|
-
return this._state.vars;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Inherit the next scope based on the specified modifications */
|
|
27
|
-
next(modifications) {
|
|
28
|
-
return new JPLRuntimeScope({
|
|
29
|
-
signal: modifications.signal ?? this.signal,
|
|
30
|
-
vars: applyObject(this.vars, Object.entries(modifications.vars ?? {})),
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default JPLRuntimeScope;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import JPLFatalError from './errors/fatal';
|
|
2
|
-
|
|
3
|
-
/** Runtime signal for managing execution lifecycle */
|
|
4
|
-
class JPLRuntimeSignal {
|
|
5
|
-
constructor(parent) {
|
|
6
|
-
this._parent = parent;
|
|
7
|
-
this._exited = false;
|
|
8
|
-
this._subscriptions = {};
|
|
9
|
-
this._nextSubscriptionKey = 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Return the signal's parent */
|
|
13
|
-
get parent() {
|
|
14
|
-
return this._parent;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Check whether the current runtime area has been requested to be exited */
|
|
18
|
-
get exited() {
|
|
19
|
-
this._exited ||= this.parent?.exited ?? false;
|
|
20
|
-
return this._exited;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Check that the current runtime area has not been requested to be exited and throw a fatal error otherwise */
|
|
24
|
-
checkHealth() {
|
|
25
|
-
if (this.exited) throw new JPLFatalError('execution aborted');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Request the current runtime area to be exited.
|
|
30
|
-
* This also involves all child areas (introduced using `JPLRuntimeSignal.next`).
|
|
31
|
-
*/
|
|
32
|
-
exit = () => {
|
|
33
|
-
if (this.exited) return;
|
|
34
|
-
this._exited = true;
|
|
35
|
-
Object.values(this._subscriptions).forEach((subscription) => {
|
|
36
|
-
subscription();
|
|
37
|
-
});
|
|
38
|
-
this._subscriptions = {};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Subscribe for when the current runtime area is requested to be exited.
|
|
43
|
-
* This also involves all parent areas.
|
|
44
|
-
* The function returns an unsubscription hook which must be called when completed in order to prevent memory leaks.
|
|
45
|
-
* If the area has already been exited when subscribing, the callback is called immediately after the current event cycle.
|
|
46
|
-
*/
|
|
47
|
-
subscribe = (cb) => {
|
|
48
|
-
if (this.exited) {
|
|
49
|
-
setTimeout(cb);
|
|
50
|
-
return () => {};
|
|
51
|
-
}
|
|
52
|
-
const key = this._nextSubscriptionKey;
|
|
53
|
-
this._nextSubscriptionKey += 1;
|
|
54
|
-
this._subscriptions[key] = cb;
|
|
55
|
-
const unsubscribeParent = (this.parent?.subscribe ?? (() => () => {}))(cb);
|
|
56
|
-
const unsubscribe = () => {
|
|
57
|
-
delete this._subscriptions[key];
|
|
58
|
-
unsubscribeParent();
|
|
59
|
-
};
|
|
60
|
-
return unsubscribe;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/** Inherit the next child area for the current one */
|
|
64
|
-
next = () => new JPLRuntimeSignal(this);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default JPLRuntimeSignal;
|
package/src/library/types.js
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { applyArray, applyObject } from './apply';
|
|
2
|
-
import adaptErrors, { adaptError } from './errors/adaptErrors';
|
|
3
|
-
import JPLFatalError from './errors/fatal';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generic type for handling special formatting on values.
|
|
7
|
-
*
|
|
8
|
-
* The value accessor should be used in JPL expressions, where type safety may be considered important.
|
|
9
|
-
*
|
|
10
|
-
* The json accessor should be used in program outputs, where the format of the value should be applied and the original type may be ignored.
|
|
11
|
-
*
|
|
12
|
-
* The alter function is called when the value is being changed by an operation.
|
|
13
|
-
* The JPLType is responsible to decide whether the resulting value should be wrapped in a new JPLType or not.
|
|
14
|
-
* It may also return itself if the value did not change.
|
|
15
|
-
* Note that the resulting value may have another type than the original value.
|
|
16
|
-
* Commonly, if multiple values wrapped in JPLTypes are involved in an operation, the leftmost operand should be altered whereas all other operands should be unwrapped using their value accessors, effectively loosing their formatting.
|
|
17
|
-
*
|
|
18
|
-
* However, both accessors should represent the same essential value.
|
|
19
|
-
* For example, a JPLType that applies rounding to numbers with a fixed number of decimal digits, may return the rounded numeric value for its value accessor (e.g. `1`), whereas it may return a formatted string for its JSON accessor (e.g. `"1.00"`).
|
|
20
|
-
* This allows this JPLType to be processed in JPL operations like generic numbers but resolves to formatted strings in the program output.
|
|
21
|
-
*/
|
|
22
|
-
export class JPLType {
|
|
23
|
-
/** Detect whether the provided value is an instance of this JPLType or one of its subclasses */
|
|
24
|
-
static is(value) {
|
|
25
|
-
return value instanceof this;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor(value) {
|
|
29
|
-
this._v = normalizeInternalValue(value);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Resolve the internal value for usage in JPL operations */
|
|
33
|
-
get value() {
|
|
34
|
-
return this._v;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Resolve the JSON value for usage in program outputs */
|
|
38
|
-
get json() {
|
|
39
|
-
return this._v;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Alter the internal value using the specified updater.
|
|
44
|
-
* The result may or may not be wrapped into a new JPLType if desired.
|
|
45
|
-
* The JPLType may return itself if the value did not change.
|
|
46
|
-
*/
|
|
47
|
-
async alter(updater) {
|
|
48
|
-
return normalize(await updater(this.value));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Support for `JSON.stringify` like procedures (see `JPLType.json`).
|
|
53
|
-
*
|
|
54
|
-
* It is generally recommended to override the `get json` member access function instead of this method.
|
|
55
|
-
*/
|
|
56
|
-
toJSON() {
|
|
57
|
-
try {
|
|
58
|
-
return this.json;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
throw adaptError(err);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Normalize the specified external value to be used in a JPLType */
|
|
66
|
-
function normalizeInternalValue(value) {
|
|
67
|
-
if (JPLType.is(value)) return value.value;
|
|
68
|
-
return normalize(value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Normalize the specified external value */
|
|
72
|
-
export function normalize(value) {
|
|
73
|
-
return strip(value, undefined, jplTypedStripper);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Unwrap the specified normalized value */
|
|
77
|
-
export function unwrap(value) {
|
|
78
|
-
if (JPLType.is(value)) return adaptErrors(() => value.value);
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Order which applies when comparing values with different types */
|
|
83
|
-
export const typeOrder = ['null', 'function', 'boolean', 'number', 'string', 'array', 'object'];
|
|
84
|
-
|
|
85
|
-
/** Resolve the type of the specified normalized value */
|
|
86
|
-
export function typeOf(value) {
|
|
87
|
-
const v = unwrap(value);
|
|
88
|
-
if (v === null) return 'null';
|
|
89
|
-
if (Array.isArray(v)) return 'array';
|
|
90
|
-
const t = typeof v;
|
|
91
|
-
switch (t) {
|
|
92
|
-
case 'function':
|
|
93
|
-
case 'boolean':
|
|
94
|
-
case 'number':
|
|
95
|
-
case 'string':
|
|
96
|
-
case 'object':
|
|
97
|
-
return t;
|
|
98
|
-
|
|
99
|
-
default:
|
|
100
|
-
throw new JPLFatalError(`invalid type ${t} (${value})`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Assert the type for the specified unwrapped value */
|
|
105
|
-
export function assertType(value, type) {
|
|
106
|
-
if (JPLType.is(value)) {
|
|
107
|
-
throw new JPLFatalError(
|
|
108
|
-
template('unexpected type: JPLTypes (%*<100v) are not allowed here', value),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
const t = typeOf(value);
|
|
112
|
-
if (t !== type) {
|
|
113
|
-
throw new JPLFatalError(
|
|
114
|
-
template('unexpected type: %s (%*<100v) cannot be used as %s', t, value, type),
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Stringify the specified normalized value */
|
|
121
|
-
export function stringify(value, unescapeString, escapeFunctions) {
|
|
122
|
-
const rawValue = escapeFunctions
|
|
123
|
-
? strip(value, (k, v) => (typeof unwrap(v) === 'function' ? '<function>' : v))
|
|
124
|
-
: strip(value);
|
|
125
|
-
if (unescapeString && typeof rawValue === 'string') return rawValue;
|
|
126
|
-
return JSON.stringify(rawValue);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Format the specified template string.
|
|
131
|
-
* The general form of a format is a percent sign, followed by optional flags, an optional width and a verb.
|
|
132
|
-
*
|
|
133
|
-
* Examples:
|
|
134
|
-
* - `%10s`: Format the next replacement as a string and pads the result at the left with spaces to be at least 10 unicode codepoints long.
|
|
135
|
-
* - `%*<10v`: Format the next replacement as a JSON value and truncates it, if it is longer then 10 unicode codepoints.
|
|
136
|
-
*
|
|
137
|
-
* The width specifies the desired field width and defaults to whatever is necessary to display the full replacement.
|
|
138
|
-
* If the width is specified without any other corresponding flags, it is used for padding the field if necessary.
|
|
139
|
-
*
|
|
140
|
-
* Valid flags:
|
|
141
|
-
*
|
|
142
|
-
* - `*`: Do not pad the value even if it is shorter than the specified width
|
|
143
|
-
* - `-`: Pad the value at the right rather than the left
|
|
144
|
-
* - `<`: Truncate the value at the right if it is too long for the specified width
|
|
145
|
-
*
|
|
146
|
-
* Valid verbs:
|
|
147
|
-
*
|
|
148
|
-
* - `%`: Returns a literal `%`
|
|
149
|
-
* - `s`: Format the next replacement as a string (like JSON, but does not escape strings)
|
|
150
|
-
* - `v`: Format the next replacement as a JSON value
|
|
151
|
-
*/
|
|
152
|
-
export function template(tmpl, ...replacements) {
|
|
153
|
-
let i = 0;
|
|
154
|
-
return displayValue(tmpl).replace(
|
|
155
|
-
/%([*\-<]+)?([1-9][0-9]*)?(.)/g,
|
|
156
|
-
(match, flags, width, verb) => {
|
|
157
|
-
// verbs without replacement
|
|
158
|
-
switch (verb) {
|
|
159
|
-
case '%':
|
|
160
|
-
return '%';
|
|
161
|
-
default:
|
|
162
|
-
}
|
|
163
|
-
// verbs with replacement
|
|
164
|
-
const value = replacements[i] ?? null;
|
|
165
|
-
i += 1;
|
|
166
|
-
let result;
|
|
167
|
-
switch (verb) {
|
|
168
|
-
case 's':
|
|
169
|
-
result = displayValue(value);
|
|
170
|
-
break;
|
|
171
|
-
case 'v':
|
|
172
|
-
result = strictDisplayValue(value);
|
|
173
|
-
break;
|
|
174
|
-
default:
|
|
175
|
-
throw new JPLFatalError(`format ${match} has unknown verb ${verb}`);
|
|
176
|
-
}
|
|
177
|
-
let pad = true;
|
|
178
|
-
let padRight = false;
|
|
179
|
-
let trunc = false;
|
|
180
|
-
[...(flags ?? [])].forEach((flag) => {
|
|
181
|
-
switch (flag) {
|
|
182
|
-
case '*':
|
|
183
|
-
pad = false;
|
|
184
|
-
break;
|
|
185
|
-
case '-':
|
|
186
|
-
padRight = true;
|
|
187
|
-
break;
|
|
188
|
-
case '<':
|
|
189
|
-
trunc = true;
|
|
190
|
-
break;
|
|
191
|
-
default:
|
|
192
|
-
throw new JPLFatalError(`format ${match} has unknown flag ${flag}`);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const w = +(width ?? 0);
|
|
196
|
-
if (w > 0) {
|
|
197
|
-
const rl = [...result].length;
|
|
198
|
-
if (pad && rl < w) {
|
|
199
|
-
const padding = ' '.repeat(w - rl);
|
|
200
|
-
result = padRight ? `${result}${padding}` : `${padding}${result}`;
|
|
201
|
-
} else if (trunc && rl > w) {
|
|
202
|
-
result = `${result.substring(0, w - 1)}…`;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
},
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Format the specified normalized value as a string */
|
|
211
|
-
export function displayValue(value) {
|
|
212
|
-
return stringify(value, true, true);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/** Format the specified normalized value as a string, without removing escaping */
|
|
216
|
-
export function strictDisplayValue(value) {
|
|
217
|
-
return stringify(value, false, true);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Unwrap the specified value similar to `JSON.stringify`.
|
|
222
|
-
* However, unlike with `JSON.stringify`, object member functions `toJSON` are not supported as they could interfere with user defined members.
|
|
223
|
-
* Instead, JPLTypes are being unwrapped by default.
|
|
224
|
-
*
|
|
225
|
-
* A custom stripper can be provided to customize the behavior.
|
|
226
|
-
*/
|
|
227
|
-
export function strip(value, replacer, stripper = jplJSONStripper) {
|
|
228
|
-
const iter = (k, v) => {
|
|
229
|
-
let r = v;
|
|
230
|
-
if (replacer) r = replacer(k ?? '', r);
|
|
231
|
-
return stripper(k, r, iter);
|
|
232
|
-
};
|
|
233
|
-
return iter(null, value);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Stripper that allows JPLTypes and normalized values */
|
|
237
|
-
export function jplTypedStripper(k, v, iter) {
|
|
238
|
-
if (JPLType.is(v)) return v;
|
|
239
|
-
if (typeof v === 'function') return v;
|
|
240
|
-
return rawStripper(k, v, iter);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** Stripper that only allows normalized values and unwraps JPLTypes */
|
|
244
|
-
export function jplStripper(k, v, iter) {
|
|
245
|
-
let r = v;
|
|
246
|
-
if (JPLType.is(r)) r = r.toJSON();
|
|
247
|
-
if (typeof r === 'function') return r;
|
|
248
|
-
return rawStripper(k, r, iter);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** Stripper that allows JSON like values and unwraps JPLTypes */
|
|
252
|
-
export function jplJSONStripper(k, v, iter) {
|
|
253
|
-
let r = v;
|
|
254
|
-
if (JPLType.is(r)) r = r.toJSON();
|
|
255
|
-
return rawStripper(k, r, iter);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Stripper that allows JSON like values and calls `toJSON` similar to `JSON.stringify` */
|
|
259
|
-
export function jsonStripper(k, v, iter) {
|
|
260
|
-
let r = v;
|
|
261
|
-
if (typeof r?.toJSON === 'function') r = r.toJSON();
|
|
262
|
-
return rawStripper(k, r, iter);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** Stripper that allows JSON like values */
|
|
266
|
-
export function rawStripper(k, v, iter) {
|
|
267
|
-
const top = k == null;
|
|
268
|
-
|
|
269
|
-
const t = typeof v;
|
|
270
|
-
switch (t) {
|
|
271
|
-
case 'string':
|
|
272
|
-
case 'boolean':
|
|
273
|
-
return v;
|
|
274
|
-
case 'number':
|
|
275
|
-
if (!Number.isFinite(v)) return null;
|
|
276
|
-
return v;
|
|
277
|
-
case 'undefined':
|
|
278
|
-
case 'function':
|
|
279
|
-
return top ? null : undefined;
|
|
280
|
-
case 'object':
|
|
281
|
-
if (v === null) return null;
|
|
282
|
-
if (Array.isArray(v)) {
|
|
283
|
-
return applyArray(
|
|
284
|
-
v,
|
|
285
|
-
Array.from(new Array(v.length), (_, i) => [i, iter(`${i}`, v[i]) ?? null]),
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
return applyObject(
|
|
289
|
-
v,
|
|
290
|
-
Object.entries(v).map(([i, s]) => {
|
|
291
|
-
const entry = iter(i, s);
|
|
292
|
-
if (entry === undefined) return [i];
|
|
293
|
-
return [i, entry];
|
|
294
|
-
}),
|
|
295
|
-
);
|
|
296
|
-
default:
|
|
297
|
-
throw new JPLFatalError(`unexpected ${t}`);
|
|
298
|
-
}
|
|
299
|
-
}
|
package/src/program/index.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import applyDefaults from '../applyDefaults';
|
|
2
|
-
import {
|
|
3
|
-
DEFINITION_VERSION,
|
|
4
|
-
DEFINITION_VERSION_MAJOR,
|
|
5
|
-
DEFINITION_VERSION_MINOR,
|
|
6
|
-
JPLFatalError,
|
|
7
|
-
} from '../library';
|
|
8
|
-
import JPLRuntime, { applyRuntimeDefaults } from '../runtime';
|
|
9
|
-
import ops from './ops';
|
|
10
|
-
|
|
11
|
-
const defaultOptions = {};
|
|
12
|
-
|
|
13
|
-
export function applyProgramDefaults(options = {}, defaults = {}) {
|
|
14
|
-
return applyDefaults(options, defaults);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function validateDefinition(programDefinition) {
|
|
18
|
-
const version = programDefinition?.version;
|
|
19
|
-
const [, major, minor] =
|
|
20
|
-
typeof version === 'string' ? (/^(\d+)\.(\d+)?$/g.exec(version) ?? []) : [];
|
|
21
|
-
|
|
22
|
-
if (!major || !minor || !Array.isArray(programDefinition.instructions)) {
|
|
23
|
-
throw new JPLFatalError('invalid program definition');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (+major !== DEFINITION_VERSION_MAJOR || +minor > DEFINITION_VERSION_MINOR) {
|
|
27
|
-
throw new JPLFatalError(
|
|
28
|
-
`unsupported program definition v${major}.${minor} - this version of JPL only supports v${DEFINITION_VERSION_MAJOR} (up to v${DEFINITION_VERSION})`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** JPL program */
|
|
34
|
-
class JPLProgram {
|
|
35
|
-
constructor(programDefinition, options) {
|
|
36
|
-
validateDefinition(programDefinition);
|
|
37
|
-
|
|
38
|
-
this._options = applyProgramDefaults(options?.program, defaultOptions);
|
|
39
|
-
this._runtimeOptions = options?.runtime;
|
|
40
|
-
|
|
41
|
-
this._definition = programDefinition;
|
|
42
|
-
this._ops = ops;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Return the program's options */
|
|
46
|
-
get options() {
|
|
47
|
-
return this._options;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Return the program's definition.
|
|
52
|
-
* The definition can be serialized as JSON to be reused in other JPL implementations.
|
|
53
|
-
*/
|
|
54
|
-
get definition() {
|
|
55
|
-
return this._definition;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Return the program's OPs */
|
|
59
|
-
get ops() {
|
|
60
|
-
return this._ops;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Run the program with the provided inputs and runtime options.
|
|
65
|
-
* The program throws a JPLExecutionError (see `JPLExecutionError.is`) for runtime failures.
|
|
66
|
-
* Other errors may be thrown when execution fails.
|
|
67
|
-
*/
|
|
68
|
-
run = async (inputs, options) => {
|
|
69
|
-
const runtime = new JPLRuntime(this, {
|
|
70
|
-
runtime: applyRuntimeDefaults(options?.runtime, this._runtimeOptions),
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const normalizedInputs = runtime.normalizeValues(inputs, 'program inputs');
|
|
74
|
-
|
|
75
|
-
const outputs = await runtime.execute(normalizedInputs);
|
|
76
|
-
return runtime.stripJSON(outputs);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Return a new program with the provided definition's instructions prepended to the program.
|
|
81
|
-
*/
|
|
82
|
-
prepend = (programDefinition) => {
|
|
83
|
-
validateDefinition(programDefinition);
|
|
84
|
-
|
|
85
|
-
const mergedDefinition = {
|
|
86
|
-
version: DEFINITION_VERSION,
|
|
87
|
-
instructions: [...programDefinition.instructions, ...this.definition.instructions],
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return new JPLProgram(mergedDefinition, {
|
|
91
|
-
program: this._options,
|
|
92
|
-
runtime: this._runtimeOptions,
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Return a new program with the provided definition's instructions appended to the program.
|
|
98
|
-
*/
|
|
99
|
-
append = (programDefinition) => {
|
|
100
|
-
validateDefinition(programDefinition);
|
|
101
|
-
|
|
102
|
-
const mergedDefinition = {
|
|
103
|
-
version: DEFINITION_VERSION,
|
|
104
|
-
instructions: [...this.definition.instructions, ...programDefinition.instructions],
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return new JPLProgram(mergedDefinition, {
|
|
108
|
-
program: this._options,
|
|
109
|
-
runtime: this._runtimeOptions,
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default JPLProgram;
|
package/src/program/ops/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OP_ACCESS,
|
|
3
|
-
OP_AND,
|
|
4
|
-
OP_ARRAY_CONSTRUCTOR,
|
|
5
|
-
OP_ASSIGNMENT,
|
|
6
|
-
OP_CALCULATION,
|
|
7
|
-
OP_COMPARISON,
|
|
8
|
-
OP_CONSTANT,
|
|
9
|
-
OP_CONSTANT_FALSE,
|
|
10
|
-
OP_CONSTANT_NULL,
|
|
11
|
-
OP_CONSTANT_TRUE,
|
|
12
|
-
OP_FUNCTION_DEFINITION,
|
|
13
|
-
OP_IF,
|
|
14
|
-
OP_INTERPOLATED_STRING,
|
|
15
|
-
OP_NEGATION,
|
|
16
|
-
OP_NOT,
|
|
17
|
-
OP_NULL_COALESCENCE,
|
|
18
|
-
OP_NUMBER,
|
|
19
|
-
OP_OBJECT_CONSTRUCTOR,
|
|
20
|
-
OP_OR,
|
|
21
|
-
OP_OUTPUT_CONCAT,
|
|
22
|
-
OP_STRING,
|
|
23
|
-
OP_TRY,
|
|
24
|
-
OP_VARIABLE,
|
|
25
|
-
OP_VARIABLE_DEFINITION,
|
|
26
|
-
OP_VOID,
|
|
27
|
-
} from '../../library';
|
|
28
|
-
import opAccess from './opAccess';
|
|
29
|
-
import opAnd from './opAnd';
|
|
30
|
-
import opArrayConstructor from './opArrayConstructor';
|
|
31
|
-
import opAssignment from './opAssignment';
|
|
32
|
-
import opCalculation from './opCalculation';
|
|
33
|
-
import opComparison from './opComparison';
|
|
34
|
-
import opConstant from './opConstant';
|
|
35
|
-
import opConstantFalse from './opConstantFalse';
|
|
36
|
-
import opConstantNull from './opConstantNull';
|
|
37
|
-
import opConstantTrue from './opConstantTrue';
|
|
38
|
-
import opFunctionDefinition from './opFunctionDefinition';
|
|
39
|
-
import opIf from './opIf';
|
|
40
|
-
import opInterpolatedString from './opInterpolatedString';
|
|
41
|
-
import opNegation from './opNegation';
|
|
42
|
-
import opNot from './opNot';
|
|
43
|
-
import opNullCoalescence from './opNullCoalescence';
|
|
44
|
-
import opNumber from './opNumber';
|
|
45
|
-
import opObjectConstructor from './opObjectConstructor';
|
|
46
|
-
import opOr from './opOr';
|
|
47
|
-
import opOutputConcat from './opOutputConcat';
|
|
48
|
-
import opString from './opString';
|
|
49
|
-
import opTry from './opTry';
|
|
50
|
-
import opVariable from './opVariable';
|
|
51
|
-
import opVariableDefinition from './opVariableDefinition';
|
|
52
|
-
import opVoid from './opVoid';
|
|
53
|
-
|
|
54
|
-
const ops = {
|
|
55
|
-
[OP_ACCESS]: opAccess,
|
|
56
|
-
[OP_AND]: opAnd,
|
|
57
|
-
[OP_ARRAY_CONSTRUCTOR]: opArrayConstructor,
|
|
58
|
-
[OP_ASSIGNMENT]: opAssignment,
|
|
59
|
-
[OP_CALCULATION]: opCalculation,
|
|
60
|
-
[OP_COMPARISON]: opComparison,
|
|
61
|
-
[OP_CONSTANT]: opConstant,
|
|
62
|
-
[OP_CONSTANT_FALSE]: opConstantFalse,
|
|
63
|
-
[OP_CONSTANT_NULL]: opConstantNull,
|
|
64
|
-
[OP_CONSTANT_TRUE]: opConstantTrue,
|
|
65
|
-
[OP_FUNCTION_DEFINITION]: opFunctionDefinition,
|
|
66
|
-
[OP_IF]: opIf,
|
|
67
|
-
[OP_INTERPOLATED_STRING]: opInterpolatedString,
|
|
68
|
-
[OP_NEGATION]: opNegation,
|
|
69
|
-
[OP_NOT]: opNot,
|
|
70
|
-
[OP_NULL_COALESCENCE]: opNullCoalescence,
|
|
71
|
-
[OP_NUMBER]: opNumber,
|
|
72
|
-
[OP_OBJECT_CONSTRUCTOR]: opObjectConstructor,
|
|
73
|
-
[OP_OR]: opOr,
|
|
74
|
-
[OP_OUTPUT_CONCAT]: opOutputConcat,
|
|
75
|
-
[OP_STRING]: opString,
|
|
76
|
-
[OP_TRY]: opTry,
|
|
77
|
-
[OP_VARIABLE]: opVariable,
|
|
78
|
-
[OP_VARIABLE_DEFINITION]: opVariableDefinition,
|
|
79
|
-
[OP_VOID]: opVoid,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default ops;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { JPLFatalError, OPA_FIELD, OPA_FUNCTION, OPA_ITER, OPA_SLICE } from '../../../library';
|
|
2
|
-
import { call } from '../utils';
|
|
3
|
-
import opaField from './opaField';
|
|
4
|
-
import opaFunction from './opaFunction';
|
|
5
|
-
import opaIter from './opaIter';
|
|
6
|
-
import opaSlice from './opaSlice';
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
/** { pipe: [op], selectors: [opa] } */
|
|
10
|
-
op(runtime, input, params, scope, next) {
|
|
11
|
-
const iter = async (from, value) => {
|
|
12
|
-
// Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
|
|
13
|
-
await undefined;
|
|
14
|
-
|
|
15
|
-
scope.signal.checkHealth();
|
|
16
|
-
|
|
17
|
-
if (from >= (params.selectors?.length ?? 0)) return next(value, scope);
|
|
18
|
-
|
|
19
|
-
const { op, params: opParams } = params.selectors[from];
|
|
20
|
-
const operator = opas[op];
|
|
21
|
-
if (!operator) throw new JPLFatalError(`invalid OPA '${op}'`);
|
|
22
|
-
|
|
23
|
-
return operator.op(runtime, input, value, opParams ?? {}, scope, (output) =>
|
|
24
|
-
iter(from + 1, output),
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) =>
|
|
29
|
-
iter(0, output),
|
|
30
|
-
);
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/** { pipe: function, selectors: [opa] } */
|
|
34
|
-
map(runtime, params) {
|
|
35
|
-
return {
|
|
36
|
-
pipe: call(params.pipe),
|
|
37
|
-
selectors: runtime.muxOne([params.selectors], ({ op, params: opParams }) => {
|
|
38
|
-
const operator = opas[op];
|
|
39
|
-
if (!operator) throw new JPLFatalError(`invalid OPA '${op}'`);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
op: runtime.assertType(op, 'string'),
|
|
43
|
-
params: operator.map(runtime, opParams),
|
|
44
|
-
};
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const opas = {
|
|
51
|
-
[OPA_FIELD]: opaField,
|
|
52
|
-
[OPA_FUNCTION]: opaFunction,
|
|
53
|
-
[OPA_ITER]: opaIter,
|
|
54
|
-
[OPA_SLICE]: opaSlice,
|
|
55
|
-
};
|