occam-entities 1.0.1

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.
Files changed (62) hide show
  1. package/.swcrc +5 -0
  2. package/README.md +78 -0
  3. package/lib/constants.js +26 -0
  4. package/lib/dependencies.js +114 -0
  5. package/lib/dependency.js +68 -0
  6. package/lib/directory.js +107 -0
  7. package/lib/entries.js +251 -0
  8. package/lib/file.js +155 -0
  9. package/lib/fileNames.js +59 -0
  10. package/lib/files.js +121 -0
  11. package/lib/index.js +79 -0
  12. package/lib/mixins/bnf.js +47 -0
  13. package/lib/mixins/entries.js +103 -0
  14. package/lib/mixins/files.js +41 -0
  15. package/lib/mixins/metaJSON.js +36 -0
  16. package/lib/mixins/pattern.js +47 -0
  17. package/lib/multiplers.js +26 -0
  18. package/lib/project.js +98 -0
  19. package/lib/projects.js +112 -0
  20. package/lib/release.js +148 -0
  21. package/lib/releases.js +112 -0
  22. package/lib/shortenedVersion.js +105 -0
  23. package/lib/types.js +22 -0
  24. package/lib/utilities/content.js +34 -0
  25. package/lib/utilities/filePath.js +63 -0
  26. package/lib/utilities/files.js +85 -0
  27. package/lib/utilities/metaJSON.js +127 -0
  28. package/lib/utilities/name.js +18 -0
  29. package/lib/utilities/query.js +41 -0
  30. package/lib/utilities/version.js +71 -0
  31. package/lib/version.js +160 -0
  32. package/license.txt +48 -0
  33. package/package.json +34 -0
  34. package/src/constants.js +5 -0
  35. package/src/dependencies.js +75 -0
  36. package/src/dependency.js +29 -0
  37. package/src/directory.js +60 -0
  38. package/src/entries.js +217 -0
  39. package/src/file.js +107 -0
  40. package/src/fileNames.js +22 -0
  41. package/src/files.js +78 -0
  42. package/src/index.js +17 -0
  43. package/src/mixins/bnf.js +59 -0
  44. package/src/mixins/entries.js +73 -0
  45. package/src/mixins/files.js +52 -0
  46. package/src/mixins/metaJSON.js +48 -0
  47. package/src/mixins/pattern.js +59 -0
  48. package/src/multiplers.js +5 -0
  49. package/src/project.js +63 -0
  50. package/src/projects.js +66 -0
  51. package/src/release.js +145 -0
  52. package/src/releases.js +66 -0
  53. package/src/shortenedVersion.js +71 -0
  54. package/src/types.js +4 -0
  55. package/src/utilities/content.js +12 -0
  56. package/src/utilities/filePath.js +36 -0
  57. package/src/utilities/files.js +95 -0
  58. package/src/utilities/metaJSON.js +149 -0
  59. package/src/utilities/name.js +13 -0
  60. package/src/utilities/query.js +31 -0
  61. package/src/utilities/version.js +70 -0
  62. package/src/version.js +123 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import { DIRECTORY_TYPE } from "./types";
4
+
5
+ export default class Directory {
6
+ constructor(path) {
7
+ this.path = path;
8
+ }
9
+
10
+ getPath() {
11
+ return this.path;
12
+ }
13
+
14
+ isFile() {
15
+ const file = false;
16
+
17
+ return file;
18
+ }
19
+
20
+ isDirectory() {
21
+ const directory = true;
22
+
23
+ return directory;
24
+ }
25
+
26
+ toJSON() {
27
+ const { type } = Directory,
28
+ path = this.path,
29
+ json = {
30
+ type,
31
+ path
32
+ };
33
+
34
+ return json;
35
+ }
36
+
37
+ static type = DIRECTORY_TYPE;
38
+
39
+ static fromPath(path) {
40
+ const directory = new Directory(path);
41
+
42
+ return directory;
43
+ }
44
+
45
+ static fromJSON(json) {
46
+ let directory = null;
47
+
48
+ if (json !== null) {
49
+ const { type } = json;
50
+
51
+ if (type === DIRECTORY_TYPE) {
52
+ const { path } = json;
53
+
54
+ directory = new Directory(path);
55
+ }
56
+ }
57
+
58
+ return directory;
59
+ }
60
+ }
package/src/entries.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ import { pathUtilities, arrayUtilities } from "necessary";
4
+
5
+ import File from "./file";
6
+ import Files from "./files";
7
+ import Directory from "./directory";
8
+ import bnfMixins from "./mixins/bnf";
9
+ import filesMixins from "./mixins/files";
10
+ import patternMixins from "./mixins/pattern";
11
+ import metaJSONMixins from "./mixins/metaJSON";
12
+
13
+ import { ENTRIES_MAXIMUM_LENGTH } from "./constants";
14
+ import { ENTRIES_MAXIMUM_LENGTH_EXCEEDED_MESSAGE } from "./messages";
15
+
16
+ const { first, filter } = arrayUtilities,
17
+ { topmostDirectoryNameFromPath } = pathUtilities;
18
+
19
+ class Entries {
20
+ constructor(array) {
21
+ this.array = array;
22
+ }
23
+
24
+ getTopmostDirectoryName() {
25
+ let topmostDirectoryName = null;
26
+
27
+ const firstEntry = first(this.array); ///
28
+
29
+ if (firstEntry) { ///
30
+ const firstEntryPath = firstEntry.getPath();
31
+
32
+ topmostDirectoryName = topmostDirectoryNameFromPath(firstEntryPath);
33
+
34
+ if (topmostDirectoryName === null) {
35
+ topmostDirectoryName = firstEntryPath; ///
36
+ }
37
+ }
38
+
39
+ return topmostDirectoryName;
40
+ }
41
+
42
+ removeFileByPath(path) {
43
+ filter(this.array, (entry) => {
44
+ const entryFile = entry.isFile();
45
+
46
+ if (entryFile) {
47
+ const file = entry, ///
48
+ filePath = file.getPath();
49
+
50
+ if (filePath === path) {
51
+ return false;
52
+ }
53
+ }
54
+
55
+ return true;
56
+ });
57
+ }
58
+
59
+ getFile(filePath) {
60
+ const files = this.getFiles(),
61
+ file = files.findFile((file) => {
62
+ const path = file.getPath();
63
+
64
+ if (path === filePath) {
65
+ return true;
66
+ }
67
+ }) || null;
68
+
69
+ return file;
70
+ }
71
+
72
+ getFiles() {
73
+ const files = Files.fromNothing();
74
+
75
+ this.mapEntry((entry) => {
76
+ const entryFile = entry.isFile();
77
+
78
+ if (entryFile) {
79
+ const file = entry; ///
80
+
81
+ files.addFile(file);
82
+ }
83
+ });
84
+
85
+ return files;
86
+ }
87
+
88
+ getFilePaths() {
89
+ const filePaths = this.reduceEntry((filePaths, entry) => {
90
+ const entryFile = entry.isFile();
91
+
92
+ if (entryFile) {
93
+ const file = entry, ///
94
+ filePath = file.getPath();
95
+
96
+ filePaths.push(filePath);
97
+ }
98
+
99
+ return filePaths;
100
+ }, []);
101
+
102
+ return filePaths;
103
+ }
104
+
105
+ getDirectoryPaths() {
106
+ const directoryPaths = this.reduceEntry((directoryPaths, entry) => {
107
+ const entryDirectory = entry.isDirectory();
108
+
109
+ if (entryDirectory) {
110
+ const directory = entry, ///
111
+ directoryPath = directory.getPath();
112
+
113
+ directoryPaths.push(directoryPath);
114
+ }
115
+
116
+ return directoryPaths;
117
+ }, []);
118
+
119
+ return directoryPaths;
120
+ }
121
+
122
+ matchShortenedVersion(shortenedVersion) {
123
+ const version = this.getVersion(),
124
+ versionMatchesShortenedVersion = version.matchShortenedVersion(shortenedVersion);
125
+
126
+ return versionMatchesShortenedVersion;
127
+ }
128
+
129
+ addFile(file) {
130
+ const entry = file; ///
131
+
132
+ this.addEntry(entry);
133
+ }
134
+
135
+ addEntry(entry) {
136
+ this.array.push(entry);
137
+
138
+ const length = this.array.length;
139
+
140
+ if (length > ENTRIES_MAXIMUM_LENGTH) {
141
+ throw new Error(ENTRIES_MAXIMUM_LENGTH_EXCEEDED_MESSAGE)
142
+ }
143
+ }
144
+
145
+ addDirectory(directory) {
146
+ const entry = directory; ///
147
+
148
+ this.addEntry(entry);
149
+ }
150
+
151
+ forEachFile(callback) {
152
+ const files = this.getFiles();
153
+
154
+ files.forEachFile(callback);
155
+ }
156
+
157
+ mapEntry(callback) { return this.array.map(callback); }
158
+
159
+ someEntry(callback) { return this.array.some(callback); }
160
+
161
+ everyEntry(callback) { return this.array.every(callback); }
162
+
163
+ forEachEntry(callback) { this.array.forEach(callback); }
164
+
165
+ reduceEntry(callback, initialValue) { return this.array.reduce(callback, initialValue); }
166
+
167
+ toJSON() {
168
+ const entriesJSON = this.array.map((entry) => {
169
+ const entryJSON = entry.toJSON();
170
+
171
+ return entryJSON;
172
+ }),
173
+ json = entriesJSON; ///
174
+
175
+ return json;
176
+ }
177
+
178
+ static fromJSON(json) {
179
+ const array = [],
180
+ entries = new Entries(array),
181
+ entriesJSON = json; ///
182
+
183
+ entriesJSON.map((entryJSON) => {
184
+ const json = entryJSON, ///
185
+ file = File.fromJSON(json),
186
+ directory = Directory.fromJSON(json),
187
+ entry = file || directory; ///
188
+
189
+ entries.addEntry(entry);
190
+ });
191
+
192
+ return entries;
193
+ }
194
+
195
+ static fromEntry(entry) {
196
+ const array = [
197
+ entry
198
+ ],
199
+ entries = new Entries(array);
200
+
201
+ return entries;
202
+ }
203
+
204
+ static fromNothing() {
205
+ const array = [],
206
+ entries = new Entries(array);
207
+
208
+ return entries;
209
+ }
210
+ }
211
+
212
+ Object.assign(Entries.prototype, bnfMixins);
213
+ Object.assign(Entries.prototype, filesMixins);
214
+ Object.assign(Entries.prototype, patternMixins);
215
+ Object.assign(Entries.prototype, metaJSONMixins);
216
+
217
+ export default Entries;
package/src/file.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ import { FILE_TYPE } from "./types";
4
+ import { convertContentTabsToWhitespace } from "./utilities/content"
5
+
6
+ export default class File {
7
+ constructor(path, content, released) {
8
+ this.path = path;
9
+ this.content = content;
10
+ this.released = released;
11
+ }
12
+
13
+ getPath() {
14
+ return this.path;
15
+ }
16
+
17
+ getContent() {
18
+ return this.content;
19
+ }
20
+
21
+ isReleased() {
22
+ return this.released;
23
+ }
24
+
25
+ isFile() {
26
+ const file = true;
27
+
28
+ return file;
29
+ }
30
+
31
+ isDirectory() {
32
+ const directory = false;
33
+
34
+ return directory;
35
+ }
36
+
37
+ setPath(path) {
38
+ this.path = path;
39
+ }
40
+
41
+ setContent(content) {
42
+ this.content = content;
43
+ }
44
+
45
+ setReleased(released) {
46
+ this.released = released;
47
+ }
48
+
49
+ toJSON() {
50
+ const { type } = File,
51
+ path = this.path,
52
+ content = this.content,
53
+ released = this.released,
54
+ json = {
55
+ type,
56
+ path,
57
+ content,
58
+ released
59
+ };
60
+
61
+ return json;
62
+ }
63
+
64
+ static type = FILE_TYPE;
65
+
66
+ static fromJSON(json) {
67
+ let file = null;
68
+
69
+ if (json !== null) {
70
+ const { type } = json;
71
+
72
+ if (type === FILE_TYPE) {
73
+ let { content } = json;
74
+
75
+ const { path, released } = json;
76
+
77
+ content = convertContentTabsToWhitespace(content); ///
78
+
79
+ file = new File(path, content, released);
80
+ }
81
+ }
82
+
83
+ return file;
84
+ }
85
+
86
+ static fromDocument(document) {
87
+ const filePath = document.getFilePath(),
88
+ released = document.isReleased(),
89
+ path = filePath; ///
90
+
91
+ let content = document.getContent();
92
+
93
+ content = convertContentTabsToWhitespace(content); ///
94
+
95
+ const file = new File(path, content, released);
96
+
97
+ return file;
98
+ }
99
+
100
+ static fromPathContentAndReleased(path, content, released) {
101
+ content = convertContentTabsToWhitespace(content); ///
102
+
103
+ const file = new File(path, content, released);
104
+
105
+ return file;
106
+ }
107
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ export const README_MD_FILE_NAME = "README.md";
4
+ export const META_JSON_FILE_NAME = "meta.json";
5
+
6
+ export const TERM_BNF_FILE_NAME = "term.bnf";
7
+ export const STATEMENT_BNF_FILE_NAME = "statement.bnf";
8
+ export const METASTATEMENT_BNF_FILE_NAME = "metastatement.bnf";
9
+ export const TYPE_PATTERN_FILE_NAME = "type.ptn";
10
+ export const SYMBOL_PATTERN_FILE_NAME = "symbol.ptn";
11
+ export const OPERATOR_PATTERN_FILE_NAME = "operator.ptn";
12
+
13
+ export default {
14
+ README_MD_FILE_NAME,
15
+ META_JSON_FILE_NAME,
16
+ TERM_BNF_FILE_NAME,
17
+ STATEMENT_BNF_FILE_NAME,
18
+ METASTATEMENT_BNF_FILE_NAME,
19
+ TYPE_PATTERN_FILE_NAME,
20
+ SYMBOL_PATTERN_FILE_NAME,
21
+ OPERATOR_PATTERN_FILE_NAME
22
+ };
package/src/files.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ import File from "./file";
4
+
5
+ export default class Files {
6
+ constructor(array) {
7
+ this.array = array;
8
+ }
9
+
10
+ getFilePaths() {
11
+ const filePaths = this.mapFile((file) => {
12
+ const filePath = file.getPath();
13
+
14
+ return filePath;
15
+ });
16
+
17
+ return filePaths;
18
+ }
19
+
20
+ addFile(file) {
21
+ this.array.push(file);
22
+ }
23
+
24
+ mapFile(callback) {
25
+ return this.array.map(callback);
26
+ }
27
+
28
+ someFile(callback) {
29
+ return this.array.some(callback);
30
+ }
31
+
32
+ reduceFile(callback, initialValue) {
33
+ return this.array.reduce(callback, initialValue);
34
+ }
35
+
36
+ forEachFile(callback) {
37
+ this.array.forEach(callback);
38
+ }
39
+
40
+ findFile(callback) {
41
+ return this.array.find(callback) || null; ///
42
+ }
43
+
44
+ toJSON() {
45
+ const filesJSON = this.array.map((file) => {
46
+ const fileJSON = (file !== null) ?
47
+ file.toJSON() :
48
+ null;
49
+
50
+ return fileJSON;
51
+ }),
52
+ json = filesJSON; ///
53
+
54
+ return json;
55
+ }
56
+
57
+ static fromJSON(json) {
58
+ const filesJSON = json, ///
59
+ array = [],
60
+ files = new Files(array);
61
+
62
+ filesJSON.forEach((fileJSON) => {
63
+ const json = fileJSON, ///
64
+ file = File.fromJSON(json);
65
+
66
+ files.addFile(file);
67
+ });
68
+
69
+ return files;
70
+ }
71
+
72
+ static fromNothing() {
73
+ const array = [],
74
+ files = new Files(array);
75
+
76
+ return files;
77
+ }
78
+ }
package/src/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ export { default as File } from "./file";
4
+ export { default as Files } from "./files";
5
+ export { default as Version } from "./version";
6
+ export { default as Entries } from "./entries";
7
+ export { default as Project } from "./project";
8
+ export { default as Release } from "./release";
9
+ export { default as Projects } from "./projects";
10
+ export { default as Releases } from "./releases";
11
+ export { default as fileNames } from "./fileNames";
12
+ export { default as Dependency } from "./dependency";
13
+ export { default as Dependencies } from "./dependencies";
14
+ export { default as ShortenedVersion } from "./shortenedVersion";
15
+ export { default as contentUtilities } from "./utilities/content";
16
+ export { default as filePathUtilities } from "./utilities/filePath";
17
+ export { default as metaJSONUtilities } from "./utilities/metaJSON";
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ import { fileNameFromFilePath } from "../utilities/name";
4
+ import { TERM_BNF_FILE_NAME, STATEMENT_BNF_FILE_NAME, METASTATEMENT_BNF_FILE_NAME } from "../fileNames";
5
+
6
+ function getBNF(bnfFileName) {
7
+ let bnf = null;
8
+
9
+ const customGrammarBNFFiles = this.getCustomGrammarBNFFiles(),
10
+ customGrammarBNFFile = customGrammarBNFFiles.find((customGrammarBNFFile) => {
11
+ const customGrammarBNFFilePath = customGrammarBNFFile.getPath(),
12
+ customGrammarBNFFileName = fileNameFromFilePath(customGrammarBNFFilePath);
13
+
14
+ if (customGrammarBNFFileName === bnfFileName) {
15
+ return true;
16
+ }
17
+ }) || null;
18
+
19
+ if (customGrammarBNFFile !== null) {
20
+ const customGrammarBNFFileContent = customGrammarBNFFile.getContent();
21
+
22
+ bnf = customGrammarBNFFileContent; ///
23
+ }
24
+
25
+ return bnf;
26
+ }
27
+
28
+ function getTermBNF() {
29
+ const fileName = TERM_BNF_FILE_NAME, ///
30
+ bnf = this.getBNF(fileName),
31
+ termBNF = bnf; ///
32
+
33
+ return termBNF;
34
+ }
35
+
36
+ function getStatementBNF() {
37
+ const fileName = STATEMENT_BNF_FILE_NAME, ///
38
+ bnf = this.getBNF(fileName),
39
+ statementBNF = bnf; ///
40
+
41
+ return statementBNF;
42
+ }
43
+
44
+ function getMetastatementBNF() {
45
+ const fileName = METASTATEMENT_BNF_FILE_NAME, ///
46
+ bnf = this.getBNF(fileName),
47
+ metastatementBNF = bnf; ///
48
+
49
+ return metastatementBNF;
50
+ }
51
+
52
+ const bnfMixins = {
53
+ getBNF,
54
+ getTermBNF,
55
+ getStatementBNF,
56
+ getMetastatementBNF
57
+ };
58
+
59
+ export default bnfMixins;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ function forEachFile(callback) { return this.entries.forEachFile(callback); }
4
+
5
+ function getFile(filePath) { return this.entries.getFile(filePath); }
6
+
7
+ function getBNF() { return this.entries.getBNF(); }
8
+
9
+ function getFiles() { return this.entries.getFiles(); }
10
+
11
+ function getTermBNF() { return this.entries.getTermBNF(); }
12
+
13
+ function getVersion() { return this.entries.getVersion(); }
14
+
15
+ function getPattern() { return this.entries.getPattern(); }
16
+
17
+ function getFilePaths() { return this.entries.getFilePaths(); }
18
+
19
+ function getRepository() { return this.entries.getRepository(); }
20
+
21
+ function getReadmeFile() { return this.entries.getReadmeFile(); }
22
+
23
+ function getTypePattern() { return this.entries.getTypePattern(); }
24
+
25
+ function getStatementBNF() { return this.entries.getStatementBNF(); }
26
+
27
+ function getDependencies() { return this.entries.getDependencies(); }
28
+
29
+ function getMetaJSONFile() { return this.entries.getMetaJSONFile(); }
30
+
31
+ function getSymbolPattern() { return this.entries.getSymbolPattern(); }
32
+
33
+ function getFlorenceFiles() { return this.entries.getFlorenceFiles(); }
34
+
35
+ function getDirectoryPaths() { return this.entries.getDirectoryPaths(); }
36
+
37
+ function getOperatorPattern() { return this.entries.getOperatorPattern(); }
38
+
39
+ function getDependencyNames() { return this.entries.getDependencyNames(); }
40
+
41
+ function getMetastatementBNF() { return this.entries.getMetastatementBNF(); }
42
+
43
+ function getCustomGrammarBNFFiles() { return this.entries.getCustomGrammarBNFFiles(); }
44
+
45
+ function getCustomGrammarPatternFiles() { return this.entries.getCustomGrammarPatternFiles(); }
46
+
47
+
48
+ const entriesMixins = {
49
+ forEachFile,
50
+ getFile,
51
+ getBNF,
52
+ getFiles,
53
+ getTermBNF,
54
+ getVersion,
55
+ getPattern,
56
+ getFilePaths,
57
+ getRepository,
58
+ getReadmeFile,
59
+ getTypePattern,
60
+ getStatementBNF,
61
+ getDependencies,
62
+ getMetaJSONFile,
63
+ getSymbolPattern,
64
+ getFlorenceFiles,
65
+ getDirectoryPaths,
66
+ getOperatorPattern,
67
+ getDependencyNames,
68
+ getMetastatementBNF,
69
+ getCustomGrammarBNFFiles,
70
+ getCustomGrammarPatternFiles
71
+ };
72
+
73
+ export default entriesMixins;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ import { readmeFileFromFiles,
4
+ metaJSONFileFromFiles,
5
+ florenceFilesFromFiles,
6
+ customGrammarBNFFilesFromFiles,
7
+ customGrammarPatternFilesFromFiles } from "../utilities/files";
8
+
9
+ function getReadmeFile() {
10
+ const files = this.getFiles(),
11
+ readmeFile = readmeFileFromFiles(files);
12
+
13
+ return readmeFile;
14
+ }
15
+
16
+ function getMetaJSONFile() {
17
+ const files = this.getFiles(),
18
+ metaJSONFile = metaJSONFileFromFiles(files);
19
+
20
+ return metaJSONFile;
21
+ }
22
+
23
+ function getFlorenceFiles() {
24
+ const files = this.getFiles(),
25
+ florenceFiles = florenceFilesFromFiles(files);
26
+
27
+ return florenceFiles;
28
+ }
29
+
30
+ function getCustomGrammarBNFFiles() {
31
+ const files = this.getFiles(),
32
+ customGrammarBNFFiles = customGrammarBNFFilesFromFiles(files);
33
+
34
+ return customGrammarBNFFiles;
35
+ }
36
+
37
+ function getCustomGrammarPatternFiles() {
38
+ const files = this.getFiles(),
39
+ customGrammarPatternFiles = customGrammarPatternFilesFromFiles(files);
40
+
41
+ return customGrammarPatternFiles;
42
+ }
43
+
44
+ const filesMixins = {
45
+ getReadmeFile,
46
+ getMetaJSONFile,
47
+ getFlorenceFiles,
48
+ getCustomGrammarBNFFiles,
49
+ getCustomGrammarPatternFiles
50
+ };
51
+
52
+ export default filesMixins;