@lowdefy/build 4.0.0-rc.5 → 4.0.0-rc.7
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/addKeys.js +48 -0
- package/dist/build/buildRefs/buildRefs.js +1 -1
- package/dist/build/buildRefs/evaluateBuildOperators.js +2 -2
- package/dist/build/buildRefs/getRefsFromFile.js +2 -2
- package/dist/build/buildRefs/makeRefDefinition.js +10 -4
- package/dist/build/buildRefs/recursiveBuild.js +20 -7
- package/dist/build/updateServerPackageJson.js +1 -6
- package/dist/build/writeApp.js +5 -2
- package/dist/build/writeAuth.js +5 -2
- package/dist/build/writeConfig.js +5 -2
- package/dist/build/writeConnections.js +4 -2
- package/dist/build/writeGlobal.js +4 -2
- package/dist/build/writeMaps.js +30 -0
- package/dist/build/writeMenus.js +4 -2
- package/dist/build/writePages.js +5 -2
- package/dist/build/writeRequests.js +5 -2
- package/dist/build/writeTypes.js +5 -2
- package/dist/createContext.js +2 -0
- package/dist/defaultTypesMap.js +357 -388
- package/dist/index.js +10 -0
- package/dist/test/testContext.js +3 -1
- package/dist/utils/makeId.js +20 -0
- package/package.json +38 -39
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 { type } from '@lowdefy/helpers';
|
|
16
|
+
import makeId from '../utils/makeId.js';
|
|
17
|
+
function recAddKeys(object, key, keyMap, parentId) {
|
|
18
|
+
const id = makeId();
|
|
19
|
+
keyMap[id] = {
|
|
20
|
+
key,
|
|
21
|
+
_r_: object._r_,
|
|
22
|
+
_k_parent: parentId
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(object, '_k_', {
|
|
25
|
+
value: id,
|
|
26
|
+
enumerable: false,
|
|
27
|
+
writable: true,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
delete object._r_;
|
|
31
|
+
Object.keys(object).forEach((nextKey)=>{
|
|
32
|
+
if (type.isObject(object[nextKey])) {
|
|
33
|
+
recAddKeys(object[nextKey], `${key}.${nextKey}`, keyMap, id);
|
|
34
|
+
}
|
|
35
|
+
if (type.isArray(object[nextKey])) {
|
|
36
|
+
object[nextKey].forEach((item, index)=>{
|
|
37
|
+
if (type.isObject(item)) {
|
|
38
|
+
recAddKeys(item, `${key}.${nextKey}[${index}:${item.blockId ?? item.menuId ?? item.menuItemId ?? item.requestId ?? item.connectionId ?? item.connectionId ?? item.id}:${item.type}]`, keyMap, id);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function addKeys({ components , context }) {
|
|
45
|
+
const id = makeId();
|
|
46
|
+
recAddKeys(components, 'root', context.keyMap, id);
|
|
47
|
+
}
|
|
48
|
+
export default addKeys;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import makeRefDefinition from './makeRefDefinition.js';
|
|
17
17
|
import evaluateBuildOperators from './evaluateBuildOperators.js';
|
|
18
18
|
async function buildRefs({ context }) {
|
|
19
|
-
const refDef = makeRefDefinition('lowdefy.yaml');
|
|
19
|
+
const refDef = makeRefDefinition('lowdefy.yaml', null, context.refMap);
|
|
20
20
|
let components = await recursiveBuild({
|
|
21
21
|
context,
|
|
22
22
|
refDef,
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import {
|
|
15
|
+
*/ import { BuildParser } from '@lowdefy/operators';
|
|
16
16
|
import operators from '@lowdefy/operators-js/operators/build';
|
|
17
17
|
async function evaluateBuildOperators({ context , input , refDef }) {
|
|
18
|
-
const operatorsParser = new
|
|
18
|
+
const operatorsParser = new BuildParser({
|
|
19
19
|
env: process.env,
|
|
20
20
|
operators
|
|
21
21
|
});
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import makeRefDefinition from './makeRefDefinition.js';
|
|
17
|
-
function getRefsFromFile(fileContent) {
|
|
17
|
+
function getRefsFromFile(fileContent, parentRefDefId, refMap) {
|
|
18
18
|
const foundRefs = [];
|
|
19
19
|
const reviver = (key, value)=>{
|
|
20
20
|
if (type.isObject(value)) {
|
|
21
21
|
if (!type.isUndefined(value._ref)) {
|
|
22
|
-
const def = makeRefDefinition(value._ref);
|
|
22
|
+
const def = makeRefDefinition(value._ref, parentRefDefId, refMap);
|
|
23
23
|
foundRefs.push(def);
|
|
24
24
|
return {
|
|
25
25
|
_ref: def
|
|
@@ -13,14 +13,20 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { get } from '@lowdefy/helpers';
|
|
16
|
-
import { v1 as uuid } from 'uuid';
|
|
17
16
|
import getRefPath from './getRefPath.js';
|
|
18
|
-
|
|
17
|
+
import makeId from '../../utils/makeId.js';
|
|
18
|
+
function makeRefDefinition(refDefinition, parent, refMap) {
|
|
19
|
+
const id = makeId();
|
|
20
|
+
const refDef = {
|
|
21
|
+
parent
|
|
22
|
+
};
|
|
23
|
+
refMap[id] = refDef;
|
|
19
24
|
return {
|
|
20
|
-
|
|
25
|
+
...refDef,
|
|
26
|
+
id,
|
|
27
|
+
key: get(refDefinition, 'key'),
|
|
21
28
|
original: refDefinition,
|
|
22
29
|
path: getRefPath(refDefinition),
|
|
23
|
-
key: get(refDefinition, 'key'),
|
|
24
30
|
resolver: get(refDefinition, 'resolver'),
|
|
25
31
|
transformer: get(refDefinition, 'transformer'),
|
|
26
32
|
vars: get(refDefinition, 'vars', {
|
|
@@ -12,15 +12,16 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import evaluateBuildOperators from './evaluateBuildOperators.js';
|
|
16
17
|
import getKey from './getKey.js';
|
|
17
18
|
import getRefContent from './getRefContent.js';
|
|
18
19
|
import getRefsFromFile from './getRefsFromFile.js';
|
|
19
20
|
import populateRefs from './populateRefs.js';
|
|
20
21
|
import runTransformer from './runTransformer.js';
|
|
21
|
-
async function
|
|
22
|
+
async function recursiveBuild({ context , refDef , count , referencedFrom }) {
|
|
22
23
|
// TODO: Maybe it would be better to detect a cycle, since this is the real issue here?
|
|
23
|
-
if (count >
|
|
24
|
+
if (count > 10000) {
|
|
24
25
|
throw new Error(`Maximum recursion depth of references exceeded.`);
|
|
25
26
|
}
|
|
26
27
|
let fileContent = await getRefContent({
|
|
@@ -28,7 +29,7 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
28
29
|
refDef,
|
|
29
30
|
referencedFrom
|
|
30
31
|
});
|
|
31
|
-
const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent);
|
|
32
|
+
const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent, refDef.id, context.refMap);
|
|
32
33
|
const parsedFiles = {};
|
|
33
34
|
// Since we can have references in the variables of a reference, we need to first parse
|
|
34
35
|
// the deeper nodes, so we can use those parsed files in references higher in the tree.
|
|
@@ -41,7 +42,8 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
41
42
|
parsedFiles,
|
|
42
43
|
refDef
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
+
context.refMap[parsedRefDef.id].path = parsedRefDef.path;
|
|
46
|
+
const parsedFile = await recursiveBuild({
|
|
45
47
|
context,
|
|
46
48
|
refDef: parsedRefDef,
|
|
47
49
|
count: count + 1,
|
|
@@ -58,10 +60,21 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
58
60
|
input: transformedFile,
|
|
59
61
|
refDef: parsedRefDef
|
|
60
62
|
});
|
|
61
|
-
|
|
63
|
+
const withRefKey = getKey({
|
|
62
64
|
input: evaluatedOperators,
|
|
63
65
|
refDef: parsedRefDef
|
|
64
66
|
});
|
|
67
|
+
const reviver = (_, value)=>{
|
|
68
|
+
if (!type.isObject(value)) return value;
|
|
69
|
+
Object.defineProperty(value, '_r_', {
|
|
70
|
+
value: refDef.id,
|
|
71
|
+
enumerable: false,
|
|
72
|
+
writable: true,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
75
|
+
return value;
|
|
76
|
+
};
|
|
77
|
+
parsedFiles[newRefDef.id] = JSON.parse(JSON.stringify(withRefKey), reviver);
|
|
65
78
|
}
|
|
66
79
|
return populateRefs({
|
|
67
80
|
toPopulate: fileContentBuiltRefs,
|
|
@@ -69,4 +82,4 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
69
82
|
refDef
|
|
70
83
|
});
|
|
71
84
|
}
|
|
72
|
-
export default
|
|
85
|
+
export default recursiveBuild;
|
|
@@ -40,11 +40,6 @@ async function updateServerPackageJson({ components , context }) {
|
|
|
40
40
|
packageJson.dependencies[name] = dependencies[name];
|
|
41
41
|
});
|
|
42
42
|
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
|
|
43
|
-
|
|
44
|
-
// be watching the file to trigger reinstalls
|
|
45
|
-
if (newPackageJsonContent !== packageJsonContent) {
|
|
46
|
-
context.logger.warn('Plugin dependencies have changed. Updating "package.json".');
|
|
47
|
-
await writeFile(filePath, newPackageJsonContent);
|
|
48
|
-
}
|
|
43
|
+
await writeFile(filePath, newPackageJsonContent);
|
|
49
44
|
}
|
|
50
45
|
export default updateServerPackageJson;
|
package/dist/build/writeApp.js
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writeApp({ components , context }) {
|
|
17
|
+
await context.writeBuildArtifact('app.json', serializer.serializeToString(components.app ?? {}, {
|
|
18
|
+
space: 2
|
|
19
|
+
}));
|
|
17
20
|
}
|
|
18
21
|
export default writeApp;
|
package/dist/build/writeAuth.js
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writeAuth({ components , context }) {
|
|
17
|
+
await context.writeBuildArtifact('auth.json', serializer.serializeToString(components.auth ?? {}, {
|
|
18
|
+
space: 2
|
|
19
|
+
}));
|
|
17
20
|
}
|
|
18
21
|
export default writeAuth;
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writeConfig({ components , context }) {
|
|
17
|
+
await context.writeBuildArtifact('config.json', serializer.serializeToString(components.config ?? {}, {
|
|
18
|
+
space: 2
|
|
19
|
+
}));
|
|
17
20
|
}
|
|
18
21
|
export default writeConfig;
|
|
@@ -12,14 +12,16 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
15
|
+
*/ import { type, serializer } from '@lowdefy/helpers';
|
|
16
16
|
async function writeConnections({ components , context }) {
|
|
17
17
|
if (type.isNone(components.connections)) return;
|
|
18
18
|
if (!type.isArray(components.connections)) {
|
|
19
19
|
throw new Error(`Connections is not an array.`);
|
|
20
20
|
}
|
|
21
21
|
const writePromises = components.connections.map(async (connection)=>{
|
|
22
|
-
await context.writeBuildArtifact(`connections/${connection.connectionId}.json`,
|
|
22
|
+
await context.writeBuildArtifact(`connections/${connection.connectionId}.json`, serializer.serializeToString(connection, {
|
|
23
|
+
space: 2
|
|
24
|
+
}));
|
|
23
25
|
});
|
|
24
26
|
return Promise.all(writePromises);
|
|
25
27
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
15
|
+
*/ import { type, serializer } from '@lowdefy/helpers';
|
|
16
16
|
async function writeGlobal({ components , context }) {
|
|
17
17
|
if (type.isNone(components.global)) {
|
|
18
18
|
components.global = {};
|
|
@@ -20,6 +20,8 @@ async function writeGlobal({ components , context }) {
|
|
|
20
20
|
if (!type.isObject(components.global)) {
|
|
21
21
|
throw new Error('Global is not an object.');
|
|
22
22
|
}
|
|
23
|
-
await context.writeBuildArtifact('global.json',
|
|
23
|
+
await context.writeBuildArtifact('global.json', serializer.serializeToString(components.global, {
|
|
24
|
+
space: 2
|
|
25
|
+
}));
|
|
24
26
|
}
|
|
25
27
|
export default writeGlobal;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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
|
+
async function writeMaps({ context }) {
|
|
17
|
+
if (!type.isObject(context.keyMap)) {
|
|
18
|
+
throw new Error('keyMap is not an object.');
|
|
19
|
+
}
|
|
20
|
+
if (!type.isObject(context.refMap)) {
|
|
21
|
+
throw new Error('refMap is not an object.');
|
|
22
|
+
}
|
|
23
|
+
await context.writeBuildArtifact('keyMap.json', serializer.serializeToString(context.keyMap, {
|
|
24
|
+
space: 0
|
|
25
|
+
}));
|
|
26
|
+
await context.writeBuildArtifact('refMap.json', serializer.serializeToString(context.refMap, {
|
|
27
|
+
space: 0
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
export default writeMaps;
|
package/dist/build/writeMenus.js
CHANGED
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
15
|
+
*/ import { type, serializer } from '@lowdefy/helpers';
|
|
16
16
|
async function writeMenus({ components , context }) {
|
|
17
17
|
if (!type.isArray(components.menus)) {
|
|
18
18
|
throw new Error('Menus is not an array.');
|
|
19
19
|
}
|
|
20
|
-
await context.writeBuildArtifact('menus.json',
|
|
20
|
+
await context.writeBuildArtifact('menus.json', serializer.serializeToString(components.menus, {
|
|
21
|
+
space: 2
|
|
22
|
+
}));
|
|
21
23
|
}
|
|
22
24
|
export default writeMenus;
|
package/dist/build/writePages.js
CHANGED
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writePage({ page , context }) {
|
|
17
|
+
await context.writeBuildArtifact(`pages/${page.pageId}/${page.pageId}.json`, serializer.serializeToString(page ?? {}, {
|
|
18
|
+
space: 2
|
|
19
|
+
}));
|
|
17
20
|
}
|
|
18
21
|
async function writePages({ components , context }) {
|
|
19
22
|
const writePromises = components.pages.map((page)=>writePage({
|
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writeRequestsOnPage({ page , context }) {
|
|
16
17
|
return Promise.all(page.requests.map(async (request)=>{
|
|
17
|
-
await context.writeBuildArtifact(`pages/${page.pageId}/requests/${request.requestId}.json`,
|
|
18
|
+
await context.writeBuildArtifact(`pages/${page.pageId}/requests/${request.requestId}.json`, serializer.serializeToString(request ?? {}, {
|
|
19
|
+
space: 2
|
|
20
|
+
}));
|
|
18
21
|
delete request.properties;
|
|
19
22
|
delete request.type;
|
|
20
23
|
delete request.connectionId;
|
package/dist/build/writeTypes.js
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
15
|
+
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
+
async function writeTypes({ components , context }) {
|
|
17
|
+
await context.writeBuildArtifact('types.json', serializer.serializeToString(components.types ?? {}, {
|
|
18
|
+
space: 2
|
|
19
|
+
}));
|
|
17
20
|
}
|
|
18
21
|
export default writeTypes;
|
package/dist/createContext.js
CHANGED
|
@@ -20,10 +20,12 @@ import defaultTypesMap from './defaultTypesMap.js';
|
|
|
20
20
|
function createContext({ customTypesMap , directories , logger , refResolver , stage ='prod' }) {
|
|
21
21
|
const context = {
|
|
22
22
|
directories,
|
|
23
|
+
keyMap: {},
|
|
23
24
|
logger,
|
|
24
25
|
readConfigFile: createReadConfigFile({
|
|
25
26
|
directories
|
|
26
27
|
}),
|
|
28
|
+
refMap: {},
|
|
27
29
|
refResolver,
|
|
28
30
|
stage,
|
|
29
31
|
typeCounters: {
|