@lowdefy/build 6.0.0 → 6.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/build/buildApi/buildApi.js +2 -2
- package/dist/build/buildApi/buildEndpoint.js +3 -3
- package/dist/build/buildApi/resolveEndpointSchedules.js +12 -9
- package/dist/build/buildApi/validateEndpoint.js +9 -9
- package/dist/build/buildAppMeta.js +9 -1
- package/dist/build/buildEnvironments.js +261 -0
- package/dist/build/buildLogger.js +22 -6
- package/dist/build/jit/shallowBuild.js +3 -2
- package/dist/build/validateConfig.js +5 -4
- package/dist/build/validateEnvironmentGuards.js +69 -0
- package/dist/build/writeApi.js +59 -19
- package/dist/defaultTypesMap.js +444 -422
- package/dist/index.js +3 -2
- package/dist/lowdefySchema.js +142 -34
- package/dist/test-utils/runBuild.js +3 -0
- package/dist/test-utils/runBuildForSnapshots.js +3 -0
- package/dist/utils/{getCronEnvironmentNames.js → getEnvironmentNames.js} +5 -4
- package/package.json +58 -58
- package/dist/build/validateCronConfig.js +0 -110
package/dist/build/writeApi.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type, serializer } from '@lowdefy/helpers';
|
|
16
|
-
import
|
|
16
|
+
import getEnvironmentNames from '../utils/getEnvironmentNames.js';
|
|
17
17
|
async function writeEndpoint({ endpoint, context }) {
|
|
18
18
|
await context.writeBuildArtifact(`api/${endpoint.endpointId}.json`, serializer.serializeToString(endpoint ?? {}));
|
|
19
19
|
}
|
|
@@ -21,18 +21,23 @@ async function writeEndpoint({ endpoint, context }) {
|
|
|
21
21
|
// generate the `crons` array in config.json. The runtime reads schedules off the endpoint artifact
|
|
22
22
|
// directly, so it does not depend on this file.
|
|
23
23
|
//
|
|
24
|
-
// With config.
|
|
25
|
-
// `environment` names it and `forward` is true for environments
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
|
|
24
|
+
// With config.environments declared there is one entry per registered environment and schedule:
|
|
25
|
+
// `environment` names it and `forward` is true for environments this deployment forwards to.
|
|
26
|
+
// Vercel fires crons only on production, so:
|
|
27
|
+
// - the current environment registers its own schedules;
|
|
28
|
+
// - an environment with a cron.secret is forwarded to, so its own crons never fire it; any other
|
|
29
|
+
// current environment is the one Vercel fires crons on and also registers every forwarded
|
|
30
|
+
// environment's schedules;
|
|
31
|
+
// - without a current environment only the `default` schedules are registered;
|
|
32
|
+
// - cron.enabled: false registers nothing for that environment.
|
|
33
|
+
function getSchedules({ endpoint, key }) {
|
|
29
34
|
if (type.isArray(endpoint.schedules)) return endpoint.schedules;
|
|
30
|
-
return endpoint.schedules?.[
|
|
35
|
+
return endpoint.schedules?.[key] ?? [];
|
|
31
36
|
}
|
|
32
|
-
function
|
|
37
|
+
function toManifestEntries({ endpoint, key, environment, forward }) {
|
|
33
38
|
return getSchedules({
|
|
34
39
|
endpoint,
|
|
35
|
-
|
|
40
|
+
key
|
|
36
41
|
}).map((schedule)=>({
|
|
37
42
|
endpointId: endpoint.endpointId,
|
|
38
43
|
cron: schedule.cron,
|
|
@@ -43,24 +48,59 @@ function pushSchedules({ endpoint, environment, forward }) {
|
|
|
43
48
|
}
|
|
44
49
|
}));
|
|
45
50
|
}
|
|
51
|
+
function isCronEnabled(environment) {
|
|
52
|
+
return environment.cron?.enabled !== false;
|
|
53
|
+
}
|
|
54
|
+
function isForwardTarget(environment) {
|
|
55
|
+
return !type.isUndefined(environment.cron?.secret);
|
|
56
|
+
}
|
|
57
|
+
function getRegisteredEnvironments({ environments, current }) {
|
|
58
|
+
const registered = [];
|
|
59
|
+
if (isCronEnabled(environments[current])) {
|
|
60
|
+
registered.push({
|
|
61
|
+
name: current,
|
|
62
|
+
forward: false
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (isForwardTarget(environments[current])) return registered;
|
|
66
|
+
getEnvironmentNames(environments).forEach((name)=>{
|
|
67
|
+
const environment = environments[name];
|
|
68
|
+
if (name === current || !isForwardTarget(environment) || !isCronEnabled(environment)) return;
|
|
69
|
+
registered.push({
|
|
70
|
+
name,
|
|
71
|
+
forward: true
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return registered;
|
|
75
|
+
}
|
|
46
76
|
async function writeSchedulesManifest({ components, context }) {
|
|
47
|
-
const
|
|
48
|
-
const
|
|
77
|
+
const { environments, environment: current } = components.config ?? {};
|
|
78
|
+
const declared = getEnvironmentNames(environments).length > 0;
|
|
79
|
+
const registered = declared && !type.isUndefined(current) ? getRegisteredEnvironments({
|
|
80
|
+
environments,
|
|
81
|
+
current
|
|
82
|
+
}) : [];
|
|
49
83
|
const schedules = [];
|
|
50
84
|
(components.api ?? []).forEach((endpoint)=>{
|
|
51
|
-
if (
|
|
52
|
-
schedules.push(...
|
|
85
|
+
if (!declared) {
|
|
86
|
+
schedules.push(...toManifestEntries({
|
|
53
87
|
endpoint
|
|
54
88
|
}));
|
|
55
89
|
return;
|
|
56
90
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (config.enabled === false) return;
|
|
60
|
-
schedules.push(...pushSchedules({
|
|
91
|
+
if (type.isUndefined(current)) {
|
|
92
|
+
schedules.push(...toManifestEntries({
|
|
61
93
|
endpoint,
|
|
62
|
-
|
|
63
|
-
|
|
94
|
+
key: 'default'
|
|
95
|
+
}));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
registered.forEach(({ name, forward })=>{
|
|
99
|
+
schedules.push(...toManifestEntries({
|
|
100
|
+
endpoint,
|
|
101
|
+
key: name,
|
|
102
|
+
environment: name,
|
|
103
|
+
forward
|
|
64
104
|
}));
|
|
65
105
|
});
|
|
66
106
|
});
|