@sdeverywhere/build 0.3.13 → 0.3.15
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/index.cjs +37 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -69
- package/dist/index.d.ts +36 -69
- package/dist/index.js +28 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ModelSpec as ModelSpec$1 } from '@sdeverywhere/compile';
|
|
1
2
|
import { Result } from 'neverthrow';
|
|
2
3
|
|
|
3
4
|
type LogLevel = 'error' | 'info' | 'verbose';
|
|
@@ -40,10 +41,33 @@ interface OutputSpec {
|
|
|
40
41
|
varName: VarName;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* The model spec properties that are shared with (and passed through unchanged to) the
|
|
45
|
+
* `ModelSpec` type from the compile package.
|
|
46
|
+
*
|
|
47
|
+
* The `inputVarNames` and `outputVarNames` properties are excluded because this package
|
|
48
|
+
* declares higher-level `inputs` and `outputs` properties in their place, which accept
|
|
49
|
+
* richer `InputSpec` and `OutputSpec` forms in addition to plain variable names. The
|
|
50
|
+
* deprecated and derived properties from the compile package are excluded because a
|
|
51
|
+
* `sde.config.js` file should only use the preferred names.
|
|
52
|
+
*/
|
|
53
|
+
type CommonModelSpecProps = Omit<ModelSpec$1, 'inputVarNames' | 'outputVarNames' | 'externalDatfiles' | 'inputVars' | 'outputVars' | 'name'>;
|
|
54
|
+
/**
|
|
55
|
+
* The `CommonModelSpecProps` properties that are filled in with a default value when a
|
|
56
|
+
* `ModelSpec` is resolved, and are therefore always defined in a `ResolvedModelSpec`.
|
|
57
|
+
* These are redeclared in `ResolvedModelSpec` so that they can be documented in terms of
|
|
58
|
+
* the resolved (non-optional) values.
|
|
59
|
+
*/
|
|
60
|
+
type ResolvedModelSpecProps = Omit<CommonModelSpecProps, 'datFiles' | 'bundleListing' | 'customConstants' | 'customLookups' | 'customOutputs'>;
|
|
61
|
+
/**
|
|
62
|
+
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
44
63
|
* that should be included in the model generated by SDEverywhere.
|
|
64
|
+
*
|
|
65
|
+
* Aside from the `inputs` and `outputs` properties (which allow for richer `InputSpec`
|
|
66
|
+
* and `OutputSpec` forms here), the properties of this interface are shared with the
|
|
67
|
+
* `ModelSpec` type from the compile package, which describes the `spec.json` file format
|
|
68
|
+
* used by the lower-level `sde` commands.
|
|
45
69
|
*/
|
|
46
|
-
interface ModelSpec {
|
|
70
|
+
interface ModelSpec extends CommonModelSpecProps {
|
|
47
71
|
/**
|
|
48
72
|
* The input variables for the model. This can either be a simple array of
|
|
49
73
|
* input variable names, or an array of `InputSpec` instances.
|
|
@@ -58,78 +82,25 @@ interface ModelSpec {
|
|
|
58
82
|
*/
|
|
59
83
|
outputs: VarName[] | OutputSpec[];
|
|
60
84
|
/**
|
|
61
|
-
*
|
|
62
|
-
* model.
|
|
63
|
-
*/
|
|
64
|
-
datFiles?: string[];
|
|
65
|
-
/**
|
|
66
|
-
* Whether to bundle a model listing with the generated model.
|
|
67
|
-
*
|
|
68
|
-
* If undefined, defaults to false.
|
|
69
|
-
*
|
|
70
|
-
* When this is true, a model listing will be bundled with the generated
|
|
71
|
-
* model to allow the `runtime` package to resolve variables that are
|
|
72
|
-
* referenced by name or identifier. This listing will increase the size
|
|
73
|
-
* of the generated model, so it is recommended to set this to true only
|
|
74
|
-
* if it is needed.
|
|
75
|
-
*/
|
|
76
|
-
bundleListing?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Whether to allow constants to be overridden at runtime using `setConstant`.
|
|
79
|
-
*
|
|
80
|
-
* If undefined or false, the generated model will implement `setConstant`
|
|
81
|
-
* as a no-op, meaning that constants cannot be overridden at runtime.
|
|
82
|
-
*
|
|
83
|
-
* If true, all constants in the generated model will be available to be
|
|
84
|
-
* overridden.
|
|
85
|
-
*
|
|
86
|
-
* If an array is provided, only those variable names in the array will
|
|
87
|
-
* be available to be overridden.
|
|
88
|
-
*/
|
|
89
|
-
customConstants?: boolean | VarName[];
|
|
90
|
-
/**
|
|
91
|
-
* Whether to allow lookups to be overridden at runtime using `setLookup`.
|
|
92
|
-
*
|
|
93
|
-
* If undefined or false, the generated model will implement `setLookup`
|
|
94
|
-
* as a no-op, meaning that lookups cannot be overridden at runtime.
|
|
85
|
+
* Additional properties to include in the generated `spec.json` file.
|
|
95
86
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
customLookups?: boolean | VarName[];
|
|
103
|
-
/**
|
|
104
|
-
* Whether to allow for capturing the data for arbitrary variables at
|
|
105
|
-
* runtime (including variables that are not configured in the `outputs`
|
|
106
|
-
* array).
|
|
107
|
-
*
|
|
108
|
-
* If undefined or false, the generated model will implement `storeOutput`
|
|
109
|
-
* as a no-op, meaning that the data for arbitrary variables cannot be
|
|
110
|
-
* captured at runtime.
|
|
111
|
-
*
|
|
112
|
-
* If true, all variables in the generated model will be available to be
|
|
113
|
-
* captured at runtime.
|
|
114
|
-
*
|
|
115
|
-
* If an array is provided, only those variable names in the array will
|
|
116
|
-
* be available to be captured at runtime.
|
|
87
|
+
* @deprecated All properties that are supported in a `spec.json` file are now declared
|
|
88
|
+
* directly on this interface, so it is no longer necessary to use this escape hatch.
|
|
89
|
+
* Any properties provided here will be merged into the resolved model spec (a property
|
|
90
|
+
* that is configured directly on this interface takes precedence over the same property
|
|
91
|
+
* provided here), but this property will be removed in a future release.
|
|
117
92
|
*/
|
|
118
|
-
|
|
119
|
-
/** Additional options included with the SDE `spec.json` file. */
|
|
120
|
-
options?: {
|
|
121
|
-
[key: string]: any;
|
|
122
|
-
};
|
|
93
|
+
options?: ModelSpec$1;
|
|
123
94
|
}
|
|
124
95
|
/**
|
|
125
|
-
* Describes a model (e.g., a Vensim mdl file) and the input/output variables
|
|
96
|
+
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
126
97
|
* that should be included in the model generated by SDEverywhere. This is
|
|
127
98
|
* largely the same as the `ModelSpec` interface, except this one has been
|
|
128
99
|
* fully resolved (paths have been validated, input and output variables have
|
|
129
100
|
* been checked, etc). This is the spec object that will be passed to plugin
|
|
130
101
|
* functions.
|
|
131
102
|
*/
|
|
132
|
-
interface ResolvedModelSpec {
|
|
103
|
+
interface ResolvedModelSpec extends ResolvedModelSpecProps {
|
|
133
104
|
/**
|
|
134
105
|
* The input variable names for the model. This will be defined regardless
|
|
135
106
|
* of whether `ModelSpec.inputs` was defined as an array of variable names
|
|
@@ -156,7 +127,7 @@ interface ResolvedModelSpec {
|
|
|
156
127
|
* The dat files that provide the data for exogenous data variables in the
|
|
157
128
|
* model.
|
|
158
129
|
*/
|
|
159
|
-
datFiles:
|
|
130
|
+
datFiles: NonNullable<ModelSpec$1['datFiles']>;
|
|
160
131
|
/**
|
|
161
132
|
* Whether to bundle a model listing with the generated model.
|
|
162
133
|
*
|
|
@@ -209,10 +180,6 @@ interface ResolvedModelSpec {
|
|
|
209
180
|
* be available to be captured at runtime.
|
|
210
181
|
*/
|
|
211
182
|
customOutputs: boolean | VarName[];
|
|
212
|
-
/** Additional options included with the SDE `spec.json` file. */
|
|
213
|
-
options?: {
|
|
214
|
-
[key: string]: any;
|
|
215
|
-
};
|
|
216
183
|
}
|
|
217
184
|
|
|
218
185
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ModelSpec as ModelSpec$1 } from '@sdeverywhere/compile';
|
|
1
2
|
import { Result } from 'neverthrow';
|
|
2
3
|
|
|
3
4
|
type LogLevel = 'error' | 'info' | 'verbose';
|
|
@@ -40,10 +41,33 @@ interface OutputSpec {
|
|
|
40
41
|
varName: VarName;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* The model spec properties that are shared with (and passed through unchanged to) the
|
|
45
|
+
* `ModelSpec` type from the compile package.
|
|
46
|
+
*
|
|
47
|
+
* The `inputVarNames` and `outputVarNames` properties are excluded because this package
|
|
48
|
+
* declares higher-level `inputs` and `outputs` properties in their place, which accept
|
|
49
|
+
* richer `InputSpec` and `OutputSpec` forms in addition to plain variable names. The
|
|
50
|
+
* deprecated and derived properties from the compile package are excluded because a
|
|
51
|
+
* `sde.config.js` file should only use the preferred names.
|
|
52
|
+
*/
|
|
53
|
+
type CommonModelSpecProps = Omit<ModelSpec$1, 'inputVarNames' | 'outputVarNames' | 'externalDatfiles' | 'inputVars' | 'outputVars' | 'name'>;
|
|
54
|
+
/**
|
|
55
|
+
* The `CommonModelSpecProps` properties that are filled in with a default value when a
|
|
56
|
+
* `ModelSpec` is resolved, and are therefore always defined in a `ResolvedModelSpec`.
|
|
57
|
+
* These are redeclared in `ResolvedModelSpec` so that they can be documented in terms of
|
|
58
|
+
* the resolved (non-optional) values.
|
|
59
|
+
*/
|
|
60
|
+
type ResolvedModelSpecProps = Omit<CommonModelSpecProps, 'datFiles' | 'bundleListing' | 'customConstants' | 'customLookups' | 'customOutputs'>;
|
|
61
|
+
/**
|
|
62
|
+
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
44
63
|
* that should be included in the model generated by SDEverywhere.
|
|
64
|
+
*
|
|
65
|
+
* Aside from the `inputs` and `outputs` properties (which allow for richer `InputSpec`
|
|
66
|
+
* and `OutputSpec` forms here), the properties of this interface are shared with the
|
|
67
|
+
* `ModelSpec` type from the compile package, which describes the `spec.json` file format
|
|
68
|
+
* used by the lower-level `sde` commands.
|
|
45
69
|
*/
|
|
46
|
-
interface ModelSpec {
|
|
70
|
+
interface ModelSpec extends CommonModelSpecProps {
|
|
47
71
|
/**
|
|
48
72
|
* The input variables for the model. This can either be a simple array of
|
|
49
73
|
* input variable names, or an array of `InputSpec` instances.
|
|
@@ -58,78 +82,25 @@ interface ModelSpec {
|
|
|
58
82
|
*/
|
|
59
83
|
outputs: VarName[] | OutputSpec[];
|
|
60
84
|
/**
|
|
61
|
-
*
|
|
62
|
-
* model.
|
|
63
|
-
*/
|
|
64
|
-
datFiles?: string[];
|
|
65
|
-
/**
|
|
66
|
-
* Whether to bundle a model listing with the generated model.
|
|
67
|
-
*
|
|
68
|
-
* If undefined, defaults to false.
|
|
69
|
-
*
|
|
70
|
-
* When this is true, a model listing will be bundled with the generated
|
|
71
|
-
* model to allow the `runtime` package to resolve variables that are
|
|
72
|
-
* referenced by name or identifier. This listing will increase the size
|
|
73
|
-
* of the generated model, so it is recommended to set this to true only
|
|
74
|
-
* if it is needed.
|
|
75
|
-
*/
|
|
76
|
-
bundleListing?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Whether to allow constants to be overridden at runtime using `setConstant`.
|
|
79
|
-
*
|
|
80
|
-
* If undefined or false, the generated model will implement `setConstant`
|
|
81
|
-
* as a no-op, meaning that constants cannot be overridden at runtime.
|
|
82
|
-
*
|
|
83
|
-
* If true, all constants in the generated model will be available to be
|
|
84
|
-
* overridden.
|
|
85
|
-
*
|
|
86
|
-
* If an array is provided, only those variable names in the array will
|
|
87
|
-
* be available to be overridden.
|
|
88
|
-
*/
|
|
89
|
-
customConstants?: boolean | VarName[];
|
|
90
|
-
/**
|
|
91
|
-
* Whether to allow lookups to be overridden at runtime using `setLookup`.
|
|
92
|
-
*
|
|
93
|
-
* If undefined or false, the generated model will implement `setLookup`
|
|
94
|
-
* as a no-op, meaning that lookups cannot be overridden at runtime.
|
|
85
|
+
* Additional properties to include in the generated `spec.json` file.
|
|
95
86
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
customLookups?: boolean | VarName[];
|
|
103
|
-
/**
|
|
104
|
-
* Whether to allow for capturing the data for arbitrary variables at
|
|
105
|
-
* runtime (including variables that are not configured in the `outputs`
|
|
106
|
-
* array).
|
|
107
|
-
*
|
|
108
|
-
* If undefined or false, the generated model will implement `storeOutput`
|
|
109
|
-
* as a no-op, meaning that the data for arbitrary variables cannot be
|
|
110
|
-
* captured at runtime.
|
|
111
|
-
*
|
|
112
|
-
* If true, all variables in the generated model will be available to be
|
|
113
|
-
* captured at runtime.
|
|
114
|
-
*
|
|
115
|
-
* If an array is provided, only those variable names in the array will
|
|
116
|
-
* be available to be captured at runtime.
|
|
87
|
+
* @deprecated All properties that are supported in a `spec.json` file are now declared
|
|
88
|
+
* directly on this interface, so it is no longer necessary to use this escape hatch.
|
|
89
|
+
* Any properties provided here will be merged into the resolved model spec (a property
|
|
90
|
+
* that is configured directly on this interface takes precedence over the same property
|
|
91
|
+
* provided here), but this property will be removed in a future release.
|
|
117
92
|
*/
|
|
118
|
-
|
|
119
|
-
/** Additional options included with the SDE `spec.json` file. */
|
|
120
|
-
options?: {
|
|
121
|
-
[key: string]: any;
|
|
122
|
-
};
|
|
93
|
+
options?: ModelSpec$1;
|
|
123
94
|
}
|
|
124
95
|
/**
|
|
125
|
-
* Describes a model (e.g., a Vensim mdl file) and the input/output variables
|
|
96
|
+
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
126
97
|
* that should be included in the model generated by SDEverywhere. This is
|
|
127
98
|
* largely the same as the `ModelSpec` interface, except this one has been
|
|
128
99
|
* fully resolved (paths have been validated, input and output variables have
|
|
129
100
|
* been checked, etc). This is the spec object that will be passed to plugin
|
|
130
101
|
* functions.
|
|
131
102
|
*/
|
|
132
|
-
interface ResolvedModelSpec {
|
|
103
|
+
interface ResolvedModelSpec extends ResolvedModelSpecProps {
|
|
133
104
|
/**
|
|
134
105
|
* The input variable names for the model. This will be defined regardless
|
|
135
106
|
* of whether `ModelSpec.inputs` was defined as an array of variable names
|
|
@@ -156,7 +127,7 @@ interface ResolvedModelSpec {
|
|
|
156
127
|
* The dat files that provide the data for exogenous data variables in the
|
|
157
128
|
* model.
|
|
158
129
|
*/
|
|
159
|
-
datFiles:
|
|
130
|
+
datFiles: NonNullable<ModelSpec$1['datFiles']>;
|
|
160
131
|
/**
|
|
161
132
|
* Whether to bundle a model listing with the generated model.
|
|
162
133
|
*
|
|
@@ -209,10 +180,6 @@ interface ResolvedModelSpec {
|
|
|
209
180
|
* be available to be captured at runtime.
|
|
210
181
|
*/
|
|
211
182
|
customOutputs: boolean | VarName[];
|
|
212
|
-
/** Additional options included with the SDE `spec.json` file. */
|
|
213
|
-
options?: {
|
|
214
|
-
[key: string]: any;
|
|
215
|
-
};
|
|
216
183
|
}
|
|
217
184
|
|
|
218
185
|
/**
|
package/dist/index.js
CHANGED
|
@@ -661,8 +661,10 @@ async function generateCode(context, sdeDir, sdeCmdPath, prepDir) {
|
|
|
661
661
|
}
|
|
662
662
|
|
|
663
663
|
// src/build/impl/hash-files.ts
|
|
664
|
-
import {
|
|
665
|
-
import {
|
|
664
|
+
import { createHash } from "crypto";
|
|
665
|
+
import { createReadStream } from "fs";
|
|
666
|
+
import { basename as basename2, join as joinPath4 } from "path";
|
|
667
|
+
import { pipeline } from "stream/promises";
|
|
666
668
|
import { glob } from "tinyglobby";
|
|
667
669
|
async function computeInputFilesHash(config) {
|
|
668
670
|
const inputFiles = [];
|
|
@@ -682,11 +684,16 @@ async function computeInputFilesHash(config) {
|
|
|
682
684
|
}
|
|
683
685
|
let hash = "";
|
|
684
686
|
for (const inputFile of inputFiles) {
|
|
685
|
-
|
|
686
|
-
hash += result.hash;
|
|
687
|
+
hash += await hashFile(inputFile);
|
|
687
688
|
}
|
|
688
689
|
return hash;
|
|
689
690
|
}
|
|
691
|
+
async function hashFile(file) {
|
|
692
|
+
const hash = createHash("sha1");
|
|
693
|
+
hash.update(basename2(file));
|
|
694
|
+
await pipeline(createReadStream(file), hash);
|
|
695
|
+
return hash.digest("base64");
|
|
696
|
+
}
|
|
690
697
|
|
|
691
698
|
// src/build/impl/build-once.ts
|
|
692
699
|
async function buildOnce(config, userConfig, plugins, options) {
|
|
@@ -708,12 +715,15 @@ async function buildOnce(config, userConfig, plugins, options) {
|
|
|
708
715
|
const specJson = {
|
|
709
716
|
inputVarNames: modelSpec.inputVarNames,
|
|
710
717
|
outputVarNames: modelSpec.outputVarNames,
|
|
711
|
-
|
|
718
|
+
datFiles: modelSpec.datFiles,
|
|
712
719
|
bundleListing: modelSpec.bundleListing,
|
|
713
|
-
customConstants: modelSpec.customConstants
|
|
714
|
-
customLookups: modelSpec.customLookups
|
|
715
|
-
customOutputs: modelSpec.customOutputs
|
|
716
|
-
|
|
720
|
+
customConstants: modelSpec.customConstants,
|
|
721
|
+
customLookups: modelSpec.customLookups,
|
|
722
|
+
customOutputs: modelSpec.customOutputs,
|
|
723
|
+
directData: modelSpec.directData,
|
|
724
|
+
dimensionFamilies: modelSpec.dimensionFamilies,
|
|
725
|
+
specialSeparationDims: modelSpec.specialSeparationDims,
|
|
726
|
+
separateAllVarsWithDims: modelSpec.separateAllVarsWithDims
|
|
717
727
|
};
|
|
718
728
|
const specPath = joinPath5(config.prepDir, "spec.json");
|
|
719
729
|
await writeFile2(specPath, JSON.stringify(specJson, null, 2));
|
|
@@ -766,7 +776,9 @@ async function buildOnce(config, userConfig, plugins, options) {
|
|
|
766
776
|
}
|
|
767
777
|
return ok2(succeeded);
|
|
768
778
|
}
|
|
769
|
-
function resolveModelSpec(
|
|
779
|
+
function resolveModelSpec(userModelSpec) {
|
|
780
|
+
const { options, ...configuredProps } = userModelSpec;
|
|
781
|
+
const modelSpec = { ...options, ...configuredProps };
|
|
770
782
|
let inputVarNames;
|
|
771
783
|
let inputSpecs;
|
|
772
784
|
if (modelSpec.inputs.length > 0) {
|
|
@@ -824,6 +836,9 @@ function resolveModelSpec(modelSpec) {
|
|
|
824
836
|
customOutputs = false;
|
|
825
837
|
}
|
|
826
838
|
return {
|
|
839
|
+
// Carry through the properties (for example, `directData` and `specialSeparationDims`)
|
|
840
|
+
// that are shared with the compile package and don't need to be resolved here
|
|
841
|
+
...modelSpec,
|
|
827
842
|
inputVarNames,
|
|
828
843
|
inputs: inputSpecs,
|
|
829
844
|
outputVarNames,
|
|
@@ -832,13 +847,12 @@ function resolveModelSpec(modelSpec) {
|
|
|
832
847
|
bundleListing: modelSpec.bundleListing === true,
|
|
833
848
|
customConstants,
|
|
834
849
|
customLookups,
|
|
835
|
-
customOutputs
|
|
836
|
-
options: modelSpec.options
|
|
850
|
+
customOutputs
|
|
837
851
|
};
|
|
838
852
|
}
|
|
839
853
|
|
|
840
854
|
// src/build/impl/watch.ts
|
|
841
|
-
import { basename as
|
|
855
|
+
import { basename as basename3 } from "path";
|
|
842
856
|
|
|
843
857
|
// src/build/impl/watch-paths.ts
|
|
844
858
|
import chokidar from "chokidar";
|
|
@@ -909,7 +923,7 @@ function watch(config, userConfig, plugins) {
|
|
|
909
923
|
function performBuild() {
|
|
910
924
|
clearOverlay();
|
|
911
925
|
for (const path of changedPaths) {
|
|
912
|
-
log("info", `Input file ${
|
|
926
|
+
log("info", `Input file ${basename3(path)} has been changed`);
|
|
913
927
|
}
|
|
914
928
|
changedPaths.clear();
|
|
915
929
|
if (currentBuildState) {
|