occam-languages 3.0.4 → 3.0.8
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/lib/context/file.js +10 -15
- package/lib/context/release.js +10 -14
- package/lib/element.js +3 -3
- package/lib/pass/continuation.js +23 -28
- package/lib/pass/continuationZip.js +31 -38
- package/lib/utilities/breakPoint.js +4 -4
- package/lib/utilities/continuation.js +68 -115
- package/lib/utilities/verification.js +69 -67
- package/lib/utilities/verify.js +5 -5
- package/package.json +2 -3
- package/src/context/file.js +9 -17
- package/src/context/release.js +9 -15
- package/src/element.js +2 -2
- package/src/pass/continuation.js +31 -31
- package/src/pass/continuationZip.js +46 -53
- package/src/utilities/breakPoint.js +4 -3
- package/src/utilities/continuation.js +88 -164
- package/src/utilities/verification.js +84 -77
- package/src/utilities/verify.js +4 -4
- package/lib/utilities/async.js +0 -66
- package/src/utilities/async.js +0 -61
|
@@ -4,25 +4,25 @@ import { Dependency } from "occam-model";
|
|
|
4
4
|
import { arrayUtilities } from "necessary";
|
|
5
5
|
|
|
6
6
|
import { every } from "../utilities/continuation";
|
|
7
|
-
import { asyncEvery } from "../utilities/async";
|
|
8
7
|
import { SINGLE_SPACE } from "../constants";
|
|
9
8
|
|
|
10
9
|
const { last } = arrayUtilities;
|
|
11
10
|
|
|
12
|
-
export
|
|
13
|
-
let releaseContextsCreated = false;
|
|
14
|
-
|
|
11
|
+
export function createReleaseContexts(dependencyName, context, fail, succeed) {
|
|
15
12
|
const name = dependencyName, ///
|
|
16
13
|
dependency = Dependency.fromName(name),
|
|
17
14
|
dependentNames = [],
|
|
18
|
-
dependentReleased = false
|
|
19
|
-
releaseContextCreated = await createReleaseContext(dependency, dependentNames, dependentReleased, context);
|
|
15
|
+
dependentReleased = false;
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
releaseContextsCreated =
|
|
23
|
-
|
|
17
|
+
return createReleaseContext(dependency, dependentNames, dependentReleased, context, fail, (releaseContextCreated) => {
|
|
18
|
+
let releaseContextsCreated = false;
|
|
19
|
+
|
|
20
|
+
if (releaseContextCreated) {
|
|
21
|
+
releaseContextsCreated = true;
|
|
22
|
+
}
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
return succeed(releaseContextsCreated);
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function initialiseReleaseContexts(context) {
|
|
@@ -33,10 +33,12 @@ export function initialiseReleaseContexts(context) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function verifyReleaseContexts(context,
|
|
37
|
-
const { releaseContexts } = context
|
|
36
|
+
export function verifyReleaseContexts(context, fail, succeed) {
|
|
37
|
+
const { releaseContexts } = context,
|
|
38
|
+
back = fail, ///
|
|
39
|
+
forward = succeed; ///
|
|
38
40
|
|
|
39
|
-
return every(releaseContexts, verifyReleaseContext, context,
|
|
41
|
+
return every(releaseContexts, verifyReleaseContext, context, back, forward);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export default {
|
|
@@ -45,14 +47,12 @@ export default {
|
|
|
45
47
|
verifyReleaseContexts
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
function verifyReleaseContext(releaseContext, context,
|
|
50
|
+
function verifyReleaseContext(releaseContext, context, back, forward) {
|
|
49
51
|
const released = releaseContext.isReleased(),
|
|
50
52
|
verified = releaseContext.hasVerified();
|
|
51
53
|
|
|
52
54
|
if (released || verified) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return contiunation(releaseContextVerifies, context);
|
|
55
|
+
return forward();
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const { log } = context,
|
|
@@ -61,85 +61,78 @@ function verifyReleaseContext(releaseContext, context, contiunation) {
|
|
|
61
61
|
|
|
62
62
|
log.info(`Verifying the '${releaseName}' project...`);
|
|
63
63
|
|
|
64
|
-
return releaseContext.verify((
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (verifies) {
|
|
68
|
-
log.info(`...verified the '${releaseName}' project.`);
|
|
69
|
-
|
|
70
|
-
releaseContextVerifies = true;
|
|
71
|
-
}
|
|
64
|
+
return releaseContext.verify(back, () => {
|
|
65
|
+
log.info(`...verified the '${releaseName}' project.`);
|
|
72
66
|
|
|
73
|
-
return
|
|
67
|
+
return forward();
|
|
74
68
|
});
|
|
75
69
|
}
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
let releaseContextCreated = false;
|
|
79
|
-
|
|
71
|
+
function createReleaseContext(dependency, dependentNames, dependentReleased, context, fail, succeed) {
|
|
80
72
|
const { log } = context,
|
|
81
|
-
|
|
73
|
+
releaseContext = findReleaseContext(dependency, context);
|
|
82
74
|
|
|
83
|
-
|
|
75
|
+
if (releaseContext !== null) {
|
|
76
|
+
const releaseContextCreated = true;
|
|
84
77
|
|
|
85
|
-
|
|
78
|
+
return succeed(releaseContextCreated);
|
|
79
|
+
}
|
|
86
80
|
|
|
87
|
-
const
|
|
81
|
+
const dependencyName = dependency.getName(),
|
|
82
|
+
dependentNamesLength = dependentNames.length;
|
|
88
83
|
|
|
89
|
-
if (
|
|
90
|
-
|
|
84
|
+
if (dependentNamesLength === 0) {
|
|
85
|
+
log.info(`Creating the '${dependencyName}' package context...`);
|
|
86
|
+
} else {
|
|
87
|
+
const lastDependentName = last(dependentNames),
|
|
88
|
+
dependentName = lastDependentName, ///
|
|
91
89
|
dependencyString = dependency.asString();
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} else {
|
|
96
|
-
const lastDependentName = last(dependentNames),
|
|
97
|
-
dependentName = lastDependentName; ///
|
|
91
|
+
log.info(`Creating the '${dependencyName}' package context given the '${dependentName}' dependant's '${dependencyString}' dependency...`);
|
|
92
|
+
}
|
|
98
93
|
|
|
99
|
-
|
|
100
|
-
}
|
|
94
|
+
const { releaseContextFromDependency } = context;
|
|
101
95
|
|
|
102
|
-
|
|
96
|
+
releaseContextFromDependency(dependency, context, fail, (releaseContext) => {
|
|
97
|
+
let releaseContextCreated = false;
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
const releatePresent = checkReleasePresent(releaseContext, dependencyName, context);
|
|
100
|
+
|
|
101
|
+
if (!releatePresent) {
|
|
102
|
+
return succeed(releaseContextCreated);
|
|
103
|
+
}
|
|
106
104
|
|
|
107
|
-
if (releaseContext === null) {
|
|
108
|
-
log.warning(`The '${dependencyName}' package context could not be created. Perhaps the 'meta.json' file is missing or invalid.`);
|
|
109
|
-
} else {
|
|
110
105
|
const projectDependencyOfPackage = checkProjectDependencyOfPackage(releaseContext, dependentReleased, dependentNames, context);
|
|
111
106
|
|
|
112
|
-
if (
|
|
113
|
-
|
|
107
|
+
if (projectDependencyOfPackage) {
|
|
108
|
+
return succeed(releaseContextCreated);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const releaseMatchesDependency = checkReleaseMatchesDependency(releaseContext, dependency, dependentNames, context);
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} else {
|
|
119
|
-
const dependencyReleaseContextsCreated = await createDependencyReleaseContexts(releaseContext, dependency, dependentNames, context);
|
|
113
|
+
if (!releaseMatchesDependency) {
|
|
114
|
+
return succeed(releaseContextCreated);
|
|
115
|
+
}
|
|
120
116
|
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
return createDependencyReleaseContexts(releaseContext, dependency, dependentNames, context, fail, (dependencyReleaseContextsCreated) => {
|
|
118
|
+
if (dependencyReleaseContextsCreated) {
|
|
119
|
+
releaseContextCreated = true;
|
|
120
|
+
}
|
|
123
121
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
122
|
+
if (releaseContextCreated) {
|
|
123
|
+
addReleaseContext(releaseContext, context);
|
|
127
124
|
}
|
|
128
|
-
}
|
|
129
125
|
|
|
130
|
-
if (!releaseContextFound) {
|
|
131
126
|
releaseContextCreated ?
|
|
132
127
|
log.debug(`...created the '${dependencyName}' package context.`) :
|
|
133
128
|
log.warning(`...unable to create the '${dependencyName}' package context.`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
129
|
|
|
137
|
-
|
|
130
|
+
return succeed(releaseContextCreated);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
138
133
|
}
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
let dependencyReleaseContextsCreated;
|
|
142
|
-
|
|
135
|
+
function createDependencyReleaseContexts(releaseContext, dependency, dependentNames, context, fail, succeed) {
|
|
143
136
|
const name = releaseContext.getName(),
|
|
144
137
|
released = releaseContext.isReleased(),
|
|
145
138
|
dependencies = releaseContext.getDependencies(),
|
|
@@ -150,19 +143,19 @@ async function createDependencyReleaseContexts(releaseContext, dependency, depen
|
|
|
150
143
|
|
|
151
144
|
const array = dependencies.getArray();
|
|
152
145
|
|
|
153
|
-
|
|
146
|
+
return every(array, (dependency, back, forward) => {
|
|
154
147
|
const cyclicDependencyPresent = checkCyclicDependencyPresent(dependency, dependentNames, context);
|
|
155
148
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (releaseContextCreated) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
149
|
+
if (cyclicDependencyPresent) {
|
|
150
|
+
return back();
|
|
162
151
|
}
|
|
163
|
-
});
|
|
164
152
|
|
|
165
|
-
|
|
153
|
+
return createReleaseContext(dependency, dependentNames, dependentReleased, context, fail, (releaseContextCreated) => {
|
|
154
|
+
return (releaseContextCreated) ?
|
|
155
|
+
forward() :
|
|
156
|
+
back();
|
|
157
|
+
});
|
|
158
|
+
}, () => succeed(false), () => succeed(true));
|
|
166
159
|
}
|
|
167
160
|
|
|
168
161
|
function addReleaseContext(releaseContext, context) {
|
|
@@ -185,6 +178,20 @@ function findReleaseContext(dependency, context) {
|
|
|
185
178
|
return releaseContext;
|
|
186
179
|
}
|
|
187
180
|
|
|
181
|
+
function checkReleasePresent(releaseContext, dependencyName, context) {
|
|
182
|
+
let releasePresent = true;
|
|
183
|
+
|
|
184
|
+
if (releaseContext === null) {
|
|
185
|
+
const { log } = context;
|
|
186
|
+
|
|
187
|
+
log.warning(`The '${dependencyName}' package context could not be created. Perhaps the 'meta.json' file is missing or invalid.`);
|
|
188
|
+
|
|
189
|
+
releasePresent = false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return releasePresent;
|
|
193
|
+
}
|
|
194
|
+
|
|
188
195
|
function retrieveReleaseContexts(releaseContext, context, releaseContexts = []) {
|
|
189
196
|
const releaseContextsIncludesReleaseContext = releaseContexts.includes(releaseContext);
|
|
190
197
|
|
package/src/utilities/verify.js
CHANGED
|
@@ -6,10 +6,10 @@ import { resolve } from "../utilities/continuation";
|
|
|
6
6
|
|
|
7
7
|
const { first, filter, compress } = arrayUtilities;
|
|
8
8
|
|
|
9
|
-
export function verifyFileContexts(fileContexts, verifiedFileContexts,
|
|
10
|
-
return resolve(fileContexts, verifiedFileContexts, (fileContext,
|
|
11
|
-
return fileContext.verify(
|
|
12
|
-
},
|
|
9
|
+
export function verifyFileContexts(fileContexts, verifiedFileContexts, back, forward) {
|
|
10
|
+
return resolve(fileContexts, verifiedFileContexts, (fileContext, back, forward) => {
|
|
11
|
+
return fileContext.verify(back, forward);
|
|
12
|
+
}, back, forward);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function verifyTypePrefixes(typePrefixes, releaseContext) {
|
package/lib/utilities/async.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get asyncEvery () {
|
|
13
|
-
return asyncEvery;
|
|
14
|
-
},
|
|
15
|
-
get asyncForEach () {
|
|
16
|
-
return asyncForEach;
|
|
17
|
-
},
|
|
18
|
-
get asyncReduce () {
|
|
19
|
-
return asyncReduce;
|
|
20
|
-
},
|
|
21
|
-
get asyncSome () {
|
|
22
|
-
return asyncSome;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
async function asyncSome(array, callback) {
|
|
26
|
-
let result = false;
|
|
27
|
-
const length = array.length;
|
|
28
|
-
for(let index = 0; index < length; index += 1){
|
|
29
|
-
const element = array[index];
|
|
30
|
-
result = !!await callback(element, index, array);
|
|
31
|
-
if (result) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
async function asyncEvery(array, callback) {
|
|
38
|
-
let result = true;
|
|
39
|
-
const length = array.length;
|
|
40
|
-
for(let index = 0; index < length; index += 1){
|
|
41
|
-
const element = array[index];
|
|
42
|
-
result = !!await callback(element, index, array);
|
|
43
|
-
if (!result) {
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
async function asyncReduce(array, callback, initialValue) {
|
|
50
|
-
let value = initialValue; ///
|
|
51
|
-
const length = array.length;
|
|
52
|
-
for(let index = 0; index < length; index += 1){
|
|
53
|
-
const element = array[index];
|
|
54
|
-
value = await callback(value, element, index, array);
|
|
55
|
-
}
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
async function asyncForEach(array, callback) {
|
|
59
|
-
const length = array.length;
|
|
60
|
-
for(let index = 0; index < length; index += 1){
|
|
61
|
-
const element = array[index];
|
|
62
|
-
await callback(element, index, array);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvYXN5bmMuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c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QztBQUNGIn0=
|
package/src/utilities/async.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
export async function asyncSome(array, callback) {
|
|
4
|
-
let result = false;
|
|
5
|
-
|
|
6
|
-
const length = array.length;
|
|
7
|
-
|
|
8
|
-
for (let index = 0; index < length; index += 1) {
|
|
9
|
-
const element = array[index];
|
|
10
|
-
|
|
11
|
-
result = !!await callback(element, index, array);
|
|
12
|
-
|
|
13
|
-
if (result) {
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function asyncEvery(array, callback) {
|
|
22
|
-
let result = true;
|
|
23
|
-
|
|
24
|
-
const length = array.length;
|
|
25
|
-
|
|
26
|
-
for (let index = 0; index < length; index += 1) {
|
|
27
|
-
const element = array[index];
|
|
28
|
-
|
|
29
|
-
result = !!await callback(element, index, array);
|
|
30
|
-
|
|
31
|
-
if (!result) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function asyncReduce(array, callback, initialValue) {
|
|
40
|
-
let value = initialValue; ///
|
|
41
|
-
|
|
42
|
-
const length = array.length;
|
|
43
|
-
|
|
44
|
-
for (let index = 0; index < length; index += 1) {
|
|
45
|
-
const element = array[index];
|
|
46
|
-
|
|
47
|
-
value = await callback(value, element, index, array);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function asyncForEach(array, callback) {
|
|
54
|
-
const length = array.length;
|
|
55
|
-
|
|
56
|
-
for (let index = 0; index < length; index += 1) {
|
|
57
|
-
const element = array[index];
|
|
58
|
-
|
|
59
|
-
await callback(element, index, array);
|
|
60
|
-
}
|
|
61
|
-
}
|