@cepharum/concrete-db 0.1.1-alpha.1 → 0.2.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/LICENSE +1 -1
- package/concrete-db.d.ts +72 -2
- package/cure.mjs +39 -33
- package/lib/collector.mjs +32 -36
- package/lib/cure.mjs +1 -29
- package/lib/{default.shape.yml → default.shape.yaml} +2 -0
- package/lib/defaults.mjs +2 -30
- package/lib/generator.mjs +22 -31
- package/lib/helper.mjs +8 -31
- package/lib/index.mjs +0 -28
- package/lib/meta.cjs +0 -28
- package/lib/options.mjs +3 -0
- package/lib/shaper.mjs +740 -132
- package/lib/term-functions.mjs +84 -28
- package/package.json +16 -12
package/LICENSE
CHANGED
package/concrete-db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (c)
|
|
2
|
+
* (c) 2022 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
3
|
*
|
|
4
4
|
* The MIT License (MIT)
|
|
5
5
|
*
|
|
@@ -32,6 +32,13 @@ declare module "concrete-db" {
|
|
|
32
32
|
* Selects base folder for writing files of resulting concrete-db.
|
|
33
33
|
*/
|
|
34
34
|
outputFolder?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Lists custom functions to expose in simple terms used in shape
|
|
38
|
+
* processing. For security reasons, you cannot replace regular term
|
|
39
|
+
* functions this way by intention.
|
|
40
|
+
*/
|
|
41
|
+
library?: { [functionName: string]: () => any };
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
export interface CollectorOptions {
|
|
@@ -65,6 +72,11 @@ declare module "concrete-db" {
|
|
|
65
72
|
*/
|
|
66
73
|
records: Map<string, CollectedRecord[]>
|
|
67
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Exposes local shapes of processed folders in order of processing.
|
|
77
|
+
*/
|
|
78
|
+
localShapes: Shape[];
|
|
79
|
+
|
|
68
80
|
/**
|
|
69
81
|
* Collects sources from provided folders.
|
|
70
82
|
*
|
|
@@ -83,8 +95,9 @@ declare module "concrete-db" {
|
|
|
83
95
|
* with associated data to expose.
|
|
84
96
|
*
|
|
85
97
|
* @param records
|
|
98
|
+
* @param localShapes local shapes of folders records have been collected from in same order as folders processed
|
|
86
99
|
*/
|
|
87
|
-
transform( records: CollectedSources ): Promise<Database>;
|
|
100
|
+
transform( records: CollectedSources, localShapes: Shape[] ): Promise<Database>;
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
/**
|
|
@@ -144,6 +157,42 @@ declare module "concrete-db" {
|
|
|
144
157
|
shape: Shape;
|
|
145
158
|
}
|
|
146
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Describes a model's item processed during shaping stage.
|
|
162
|
+
*/
|
|
163
|
+
export interface ModelItem {
|
|
164
|
+
/**
|
|
165
|
+
* Lists segments of relative path of file this item's originating
|
|
166
|
+
* record has been read from.
|
|
167
|
+
*/
|
|
168
|
+
$segments: string[];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Refers to record this item is based on.
|
|
172
|
+
*/
|
|
173
|
+
$original: CollectedRecord;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Exposes shape of item's model in context of its originating record.
|
|
177
|
+
*/
|
|
178
|
+
$shape: ShapeModel;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Names this item's model.
|
|
182
|
+
*/
|
|
183
|
+
$model: string;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Uniquely identifies the item in context of its model.
|
|
187
|
+
*/
|
|
188
|
+
$id: string;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* item's properties
|
|
192
|
+
*/
|
|
193
|
+
[name: string]: any;
|
|
194
|
+
}
|
|
195
|
+
|
|
147
196
|
/**
|
|
148
197
|
* Lists default values for properties of a single model's item.
|
|
149
198
|
*/
|
|
@@ -156,6 +205,22 @@ declare module "concrete-db" {
|
|
|
156
205
|
* of model or an such an item's representation in a collection).
|
|
157
206
|
*/
|
|
158
207
|
export interface ShapeProperties {
|
|
208
|
+
/**
|
|
209
|
+
* Provides term computed to get the name of a record's model.
|
|
210
|
+
*/
|
|
211
|
+
$model?: string;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Provides term computed to get ID of item described by a record.
|
|
215
|
+
*/
|
|
216
|
+
$id?: string;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Provides term computed to get ID of selected item's variant described
|
|
220
|
+
* by record.
|
|
221
|
+
*/
|
|
222
|
+
$variant?: string;
|
|
223
|
+
|
|
159
224
|
[propertyName: string]: any;
|
|
160
225
|
}
|
|
161
226
|
|
|
@@ -202,6 +267,11 @@ declare module "concrete-db" {
|
|
|
202
267
|
defaults: ShapePropertyDefaults;
|
|
203
268
|
properties: ShapeProperties;
|
|
204
269
|
collections: ShapeCollections;
|
|
270
|
+
contributions: {
|
|
271
|
+
[contributedModelName: string]: {
|
|
272
|
+
[targetPropertyName: string]: string;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
205
275
|
}
|
|
206
276
|
|
|
207
277
|
export interface Shape {
|
package/cure.mjs
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
4
|
-
*
|
|
5
|
-
* The MIT License (MIT)
|
|
6
|
-
*
|
|
7
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
* in the Software without restriction, including without limitation the rights
|
|
12
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
15
|
-
*
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
18
|
-
*
|
|
19
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
-
* SOFTWARE.
|
|
26
|
-
*
|
|
27
|
-
* @author: cepharum
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
2
|
import File from "fs";
|
|
31
3
|
import Path from "path";
|
|
32
4
|
|
|
@@ -36,6 +8,7 @@ import YAML from "yaml";
|
|
|
36
8
|
import meta from "./lib/meta.cjs";
|
|
37
9
|
import { cure } from "./lib/index.mjs";
|
|
38
10
|
import { ShapeFileName } from "./lib/defaults.mjs";
|
|
11
|
+
import { YAMLParserOptions } from "./lib/options.mjs";
|
|
39
12
|
|
|
40
13
|
|
|
41
14
|
const args = minimist( process.argv.slice( 2 ) );
|
|
@@ -49,10 +22,15 @@ Processes current folder by default.
|
|
|
49
22
|
|
|
50
23
|
Supported options are:
|
|
51
24
|
|
|
52
|
-
-h / --help
|
|
53
|
-
-V / --version
|
|
54
|
-
-
|
|
55
|
-
|
|
25
|
+
-h / --help showing this information
|
|
26
|
+
-V / --version showing version of this package
|
|
27
|
+
-v / --verbose be verbose about the progress of curing database
|
|
28
|
+
--debug be extra verbose
|
|
29
|
+
-s / --shape=file selects global shape controlling transformation
|
|
30
|
+
-o / --output=folder selects folder resulting files are written to
|
|
31
|
+
-c / --clean remove all existing files from output folder
|
|
32
|
+
-l / --library=file selects file exposing custom term functions to use
|
|
33
|
+
in addition to regular ones
|
|
56
34
|
` );
|
|
57
35
|
process.exit( 0 );
|
|
58
36
|
}
|
|
@@ -67,12 +45,40 @@ if ( args.V || args.version ) {
|
|
|
67
45
|
( async() => {
|
|
68
46
|
const options = {
|
|
69
47
|
outputFolder: args.o || args.output || process.cwd(),
|
|
48
|
+
verbose: args.debug ? 2 : args.v || args.verbose ? 1 : 0,
|
|
49
|
+
clean: Boolean( args.c || args.clean ),
|
|
70
50
|
};
|
|
71
51
|
|
|
72
52
|
const globalShapeFile = args.s || args.shape || Path.resolve( process.cwd(), ShapeFileName );
|
|
73
53
|
|
|
54
|
+
const libraries = Array.isArray( args.l ) ? args.l : args.l ? [args.l] : [];
|
|
55
|
+
libraries.splice( libraries.length, 0, ...Array.isArray( args.library ) ? args.library : args.library ? [args.library] : [] );
|
|
56
|
+
|
|
57
|
+
options.library = {};
|
|
58
|
+
for ( const library of libraries ) {
|
|
59
|
+
let pathname = Path.resolve( ".", library );
|
|
60
|
+
|
|
61
|
+
if ( options.verbose ) {
|
|
62
|
+
console.error( `including library ${pathname}` );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ( /^[a-z]:/i.test( pathname ) ) {
|
|
66
|
+
pathname = "file://" + pathname.replace( /\//g, "%2F" );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const functions = await import( pathname ); // eslint-disable-line no-await-in-loop
|
|
70
|
+
|
|
71
|
+
for ( const name of Object.keys( functions ) ) {
|
|
72
|
+
if ( options.verbose > 1 ) {
|
|
73
|
+
console.error( ` - ${name}` );
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
options.library[name] = functions[name];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
try {
|
|
75
|
-
options.shape = Object.freeze( YAML.parse( await File.promises.readFile( globalShapeFile, { encoding: "utf8" } ) ) );
|
|
81
|
+
options.shape = Object.freeze( YAML.parse( await File.promises.readFile( globalShapeFile, { encoding: "utf8" } ), YAMLParserOptions ) );
|
|
76
82
|
} catch ( cause ) {
|
|
77
83
|
if ( cause.code !== "ENOENT" ) {
|
|
78
84
|
throw cause;
|
package/lib/collector.mjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import File from "fs";
|
|
30
2
|
import Path from "path";
|
|
31
3
|
import EventEmitter from "events";
|
|
@@ -35,13 +7,13 @@ import FileEssentials from "file-essentials";
|
|
|
35
7
|
import YAML from "yaml";
|
|
36
8
|
import merge from "lodash.merge";
|
|
37
9
|
|
|
38
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ShapeFileName,
|
|
12
|
+
DefaultCollectorOptions,
|
|
13
|
+
DefaultShape
|
|
14
|
+
} from "./defaults.mjs";
|
|
39
15
|
import { deepFreeze } from "./helper.mjs";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const YAMLParserOptions = {
|
|
43
|
-
version: "1.1",
|
|
44
|
-
};
|
|
16
|
+
import { YAMLParserOptions } from "./options.mjs";
|
|
45
17
|
|
|
46
18
|
|
|
47
19
|
/**
|
|
@@ -58,8 +30,12 @@ export class Collector extends EventEmitter {
|
|
|
58
30
|
super();
|
|
59
31
|
|
|
60
32
|
Object.defineProperties( this, {
|
|
61
|
-
options: {
|
|
33
|
+
options: {
|
|
34
|
+
value: { ...DefaultCollectorOptions, ...options },
|
|
35
|
+
enumerable: true
|
|
36
|
+
},
|
|
62
37
|
records: { value: new Map(), enumerable: true },
|
|
38
|
+
localShapes: { value: [], enumerable: true },
|
|
63
39
|
} );
|
|
64
40
|
}
|
|
65
41
|
|
|
@@ -97,10 +73,19 @@ export class Collector extends EventEmitter {
|
|
|
97
73
|
* @returns {Promise<Collector>} promises collector having collected records from folders
|
|
98
74
|
*/
|
|
99
75
|
async fromFolders( folders ) {
|
|
76
|
+
const spinner = "⠁⠂⠄⡀⢀⠠⠐⠈";
|
|
100
77
|
const { pattern, nameToKey } = this.options;
|
|
101
78
|
|
|
102
|
-
await PromiseEssentials.each( folders || [], async folder => {
|
|
79
|
+
await PromiseEssentials.each( folders || [], async( folder, index ) => {
|
|
80
|
+
if ( this.options.verbose ) {
|
|
81
|
+
process.stderr.write( `collecting records from folder ${folder} [${index + 1}/${folders.length}] ... ` );
|
|
82
|
+
}
|
|
83
|
+
|
|
103
84
|
const localShape = await this.getLocalShape( folder );
|
|
85
|
+
let total = 0;
|
|
86
|
+
let additional = 0;
|
|
87
|
+
|
|
88
|
+
this.localShapes.push( localShape );
|
|
104
89
|
|
|
105
90
|
await FileEssentials.find( folder, {
|
|
106
91
|
filter: ( localPath, fullPath, stat ) => {
|
|
@@ -130,15 +115,26 @@ export class Collector extends EventEmitter {
|
|
|
130
115
|
|
|
131
116
|
if ( this.records.has( name ) ) {
|
|
132
117
|
this.records.get( name ).push( record );
|
|
118
|
+
additional++;
|
|
133
119
|
} else {
|
|
134
120
|
this.records.set( name, [record] );
|
|
135
121
|
}
|
|
122
|
+
|
|
123
|
+
total++;
|
|
124
|
+
|
|
125
|
+
if ( this.options.verbose ) {
|
|
126
|
+
process.stderr.write( `${spinner[Math.floor( total / 10 ) % spinner.length]}\x08` );
|
|
127
|
+
}
|
|
136
128
|
}
|
|
137
129
|
|
|
138
130
|
return undefined;
|
|
139
131
|
},
|
|
140
132
|
waitForConverter: true,
|
|
141
133
|
} );
|
|
134
|
+
|
|
135
|
+
if ( this.options.verbose ) {
|
|
136
|
+
process.stderr.write( `${total} records (${additional} overlays)\n` );
|
|
137
|
+
}
|
|
142
138
|
} );
|
|
143
139
|
|
|
144
140
|
return this;
|
package/lib/cure.mjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import { Collector } from "./collector.mjs";
|
|
30
2
|
import { Shaper } from "./shaper.mjs";
|
|
31
3
|
import { Generator } from "./generator.mjs";
|
|
@@ -59,6 +31,6 @@ export async function cure( folders, options = {}, stages = {} ) {
|
|
|
59
31
|
}
|
|
60
32
|
|
|
61
33
|
const collector = await _stages.collector.fromFolders( sources );
|
|
62
|
-
const database = await _stages.shaper.transform( collector.records );
|
|
34
|
+
const database = await _stages.shaper.transform( collector.records, collector.localShapes );
|
|
63
35
|
await _stages.generator.writeDatabase( database );
|
|
64
36
|
}
|
package/lib/defaults.mjs
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import { readFileSync } from "fs";
|
|
30
2
|
import { dirname, resolve } from "path";
|
|
31
3
|
import { fileURLToPath } from "url";
|
|
32
4
|
|
|
33
5
|
import YAML from "yaml";
|
|
34
6
|
|
|
35
|
-
export const ShapeFileName = ".concrete-db.shape.
|
|
7
|
+
export const ShapeFileName = ".concrete-db.shape.yaml";
|
|
36
8
|
|
|
37
9
|
/**
|
|
38
10
|
* @type {CollectorOptions}
|
|
@@ -68,4 +40,4 @@ export const DefaultGeneratorOptions = {};
|
|
|
68
40
|
/**
|
|
69
41
|
* @type {Shape}
|
|
70
42
|
*/
|
|
71
|
-
export const DefaultShape = YAML.parse( readFileSync( resolve( dirname( fileURLToPath( import.meta.url ) ), "default.shape.
|
|
43
|
+
export const DefaultShape = YAML.parse( readFileSync( resolve( dirname( fileURLToPath( import.meta.url ) ), "default.shape.yaml" ), { encoding: "utf8" } ) );
|
package/lib/generator.mjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import EventEmitter from "events";
|
|
30
2
|
import File from "fs";
|
|
31
3
|
import Path from "path";
|
|
@@ -68,6 +40,10 @@ export class Generator extends EventEmitter {
|
|
|
68
40
|
await FileEssentials.mkdir( "/", subfolder );
|
|
69
41
|
|
|
70
42
|
if ( this.options.clean ) {
|
|
43
|
+
if ( this.options.verbose ) {
|
|
44
|
+
console.error( `cleaning output folder ${subfolder} ...` );
|
|
45
|
+
}
|
|
46
|
+
|
|
71
47
|
await FileEssentials.find( subfolder, {
|
|
72
48
|
depthFirst: true,
|
|
73
49
|
filter: ( localPath, fullPath, stat ) => {
|
|
@@ -77,11 +53,11 @@ export class Generator extends EventEmitter {
|
|
|
77
53
|
|
|
78
54
|
return stat.isFile();
|
|
79
55
|
},
|
|
80
|
-
converter: ( localPath, fullPath ) => {
|
|
56
|
+
converter: ( localPath, fullPath, stat ) => {
|
|
81
57
|
const name = fullPath.replace( /\.json$/, "" );
|
|
82
58
|
|
|
83
59
|
if ( !database.hasOwnProperty( name ) ) {
|
|
84
|
-
return File.promises.unlink( fullPath );
|
|
60
|
+
return stat.isDirectory() ? File.promises.rmdir( fullPath ) : File.promises.unlink( fullPath );
|
|
85
61
|
}
|
|
86
62
|
|
|
87
63
|
return undefined;
|
|
@@ -90,14 +66,29 @@ export class Generator extends EventEmitter {
|
|
|
90
66
|
} );
|
|
91
67
|
}
|
|
92
68
|
|
|
93
|
-
|
|
69
|
+
const keys = Object.keys( endpoints );
|
|
70
|
+
let index = 0;
|
|
71
|
+
|
|
72
|
+
if ( this.options.verbose ) {
|
|
73
|
+
console.error( `writing ${keys.length} files` );
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await PromiseEssentials.each( keys, key => {
|
|
94
77
|
const name = key.endsWith( ".json" ) ? key : key + ".json";
|
|
95
78
|
const path = name.indexOf( "/" ) > -1 ? name.replace( /\/[^/]*?$/, "" ) : undefined;
|
|
96
79
|
|
|
80
|
+
if ( this.options.verbose ) {
|
|
81
|
+
process.stderr.write( `\r[${++index}/${keys.length}]` );
|
|
82
|
+
}
|
|
83
|
+
|
|
97
84
|
return FileEssentials.mkdir( folder, path )
|
|
98
85
|
.then( () => File.promises.writeFile( Path.resolve( folder, name ), JSON.stringify( endpoints[key] ), { encoding: "utf8" } ) );
|
|
99
86
|
} );
|
|
100
87
|
|
|
88
|
+
if ( this.options.verbose ) {
|
|
89
|
+
process.stderr.write( "\n" );
|
|
90
|
+
}
|
|
91
|
+
|
|
101
92
|
return this;
|
|
102
93
|
}
|
|
103
94
|
}
|
package/lib/helper.mjs
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
1
|
+
export * from "simple-terms/lib/helper.js";
|
|
28
2
|
|
|
29
3
|
/**
|
|
30
4
|
* Wraps provided object in a proxy offering case-insensitive access on
|
|
@@ -37,7 +11,7 @@
|
|
|
37
11
|
* @param {object} meta set of meta properties to blend in (case-sensitively)
|
|
38
12
|
* @returns {any} provided data wrapped for case-insensitive selection of own properties
|
|
39
13
|
*/
|
|
40
|
-
export function
|
|
14
|
+
export function augmentDataSpace( data, meta = undefined ) {
|
|
41
15
|
if ( !data || typeof data !== "object" ) {
|
|
42
16
|
return data;
|
|
43
17
|
}
|
|
@@ -50,8 +24,12 @@ export function augmentedDataSpace( data, meta = undefined ) {
|
|
|
50
24
|
return meta[name];
|
|
51
25
|
}
|
|
52
26
|
|
|
27
|
+
if ( typeof name === "symbol" ) {
|
|
28
|
+
return object[name];
|
|
29
|
+
}
|
|
30
|
+
|
|
53
31
|
if ( Object.prototype.hasOwnProperty.call( object, name ) ) {
|
|
54
|
-
return
|
|
32
|
+
return augmentDataSpace( object[name] );
|
|
55
33
|
}
|
|
56
34
|
|
|
57
35
|
if ( !cached && typeof name === "string" ) {
|
|
@@ -68,12 +46,11 @@ export function augmentedDataSpace( data, meta = undefined ) {
|
|
|
68
46
|
}
|
|
69
47
|
}
|
|
70
48
|
|
|
71
|
-
return
|
|
49
|
+
return augmentDataSpace( object[cached[name.toLocaleLowerCase()]] );
|
|
72
50
|
},
|
|
73
51
|
} );
|
|
74
52
|
}
|
|
75
53
|
|
|
76
|
-
|
|
77
54
|
/**
|
|
78
55
|
* Implements special kind of value representing reference on uniquely identified
|
|
79
56
|
* item of a model selected by its name.
|
package/lib/index.mjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
import { cure } from "./cure.mjs";
|
|
30
2
|
import { Collector } from "./collector.mjs";
|
|
31
3
|
import { Shaper } from "./shaper.mjs";
|
package/lib/meta.cjs
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
1
|
const meta = require( "../package.json" );
|
|
30
2
|
|
|
31
3
|
module.exports = meta;
|
package/lib/options.mjs
ADDED