@lowdefy/build 4.0.2 → 4.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/buildJs/buildJs.js +43 -0
- package/dist/build/buildJs/generateJsFile.js +30 -0
- package/dist/build/buildJs/jsMapParser.js +46 -0
- package/dist/build/buildJs/writeJs.js +26 -0
- package/dist/createContext.js +1 -0
- package/dist/defaultTypesMap.js +474 -441
- package/dist/index.js +12 -2
- package/dist/test/testContext.js +2 -1
- package/package.json +38 -38
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import jsMapParser from './jsMapParser.js';
|
|
16
|
+
function buildJs({ components, context }) {
|
|
17
|
+
components.pages = components.pages.map((page)=>{
|
|
18
|
+
const pageRequests = [
|
|
19
|
+
...page.requests
|
|
20
|
+
];
|
|
21
|
+
delete page.requests;
|
|
22
|
+
const cleanPage = jsMapParser({
|
|
23
|
+
input: page,
|
|
24
|
+
jsMap: context.jsMap,
|
|
25
|
+
env: 'client'
|
|
26
|
+
});
|
|
27
|
+
const cleanRequests = jsMapParser({
|
|
28
|
+
input: pageRequests,
|
|
29
|
+
jsMap: context.jsMap,
|
|
30
|
+
env: 'server'
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
...cleanPage,
|
|
34
|
+
requests: cleanRequests
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
components.connections = jsMapParser({
|
|
38
|
+
input: components.connections,
|
|
39
|
+
jsMap: context.jsMap,
|
|
40
|
+
env: 'server'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export default buildJs;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { nunjucksFunction } from '@lowdefy/nunjucks';
|
|
16
|
+
const template = `
|
|
17
|
+
export default {
|
|
18
|
+
{% for hash in hashes -%}
|
|
19
|
+
'{{ hash }}': ({{ functionPrototype }}) => { {{ map[hash] | safe }} },
|
|
20
|
+
{% endfor -%}
|
|
21
|
+
};`;
|
|
22
|
+
function generateJsFile({ map, functionPrototype }) {
|
|
23
|
+
const templateFn = nunjucksFunction(template);
|
|
24
|
+
return templateFn({
|
|
25
|
+
hashes: Object.keys(map),
|
|
26
|
+
map,
|
|
27
|
+
functionPrototype
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export default generateJsFile;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { serializer, type } from '@lowdefy/helpers';
|
|
16
|
+
import crypto from 'crypto';
|
|
17
|
+
function makeHash({ jsMap, env, value }) {
|
|
18
|
+
const hash = crypto.createHash('sha1').update(value).digest('base64');
|
|
19
|
+
jsMap[env][hash] = value;
|
|
20
|
+
return {
|
|
21
|
+
_js: hash
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function JsMapParser({ input, jsMap, env }) {
|
|
25
|
+
if (!jsMap[env]) {
|
|
26
|
+
jsMap[env] = {};
|
|
27
|
+
}
|
|
28
|
+
const reviver = (_, value)=>{
|
|
29
|
+
if (!type.isObject(value)) return value;
|
|
30
|
+
if (Object.keys(value).length !== 1) return value;
|
|
31
|
+
const key = Object.keys(value)[0];
|
|
32
|
+
if (key !== '_js') return value;
|
|
33
|
+
if (!type.isString(value[key])) {
|
|
34
|
+
throw new Error('_js operator expects the JavaScript definition as a string.');
|
|
35
|
+
}
|
|
36
|
+
return makeHash({
|
|
37
|
+
jsMap,
|
|
38
|
+
env,
|
|
39
|
+
value: value[key]
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return serializer.copy(input, {
|
|
43
|
+
reviver
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export default JsMapParser;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import generateJsFile from './generateJsFile.js';
|
|
16
|
+
async function writeJs({ context }) {
|
|
17
|
+
await context.writeBuildArtifact('plugins/operators/clientJsMap.js', generateJsFile({
|
|
18
|
+
map: context.jsMap.client,
|
|
19
|
+
functionPrototype: `{ actions, event, input, location, lowdefyGlobal, request, state, urlQuery, user }`
|
|
20
|
+
}));
|
|
21
|
+
await context.writeBuildArtifact('plugins/operators/serverJsMap.js', generateJsFile({
|
|
22
|
+
map: context.jsMap.server,
|
|
23
|
+
functionPrototype: `{ payload, secrets, user }`
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
export default writeJs;
|