@cepharum/concrete-db 0.1.0 → 0.1.2-alpha.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 cepharum GmbH
3
+ Copyright (c) 2022 cepharum GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/concrete-db.d.ts CHANGED
@@ -144,6 +144,48 @@ declare module "concrete-db" {
144
144
  shape: Shape;
145
145
  }
146
146
 
147
+ /**
148
+ * Describes a model's item processed during shaping stage.
149
+ */
150
+ export interface CollectedItem {
151
+ /**
152
+ * Refers to record this item is based on.
153
+ */
154
+ $original: CollectedRecord;
155
+
156
+ /**
157
+ * Exposes local shape declared in context of record item was collected
158
+ * from.
159
+ */
160
+ $localShape: ShapeModel;
161
+
162
+ /**
163
+ * Exposes shape of item's model in context of its originating record.
164
+ */
165
+ $shape: ShapeModel;
166
+
167
+ /**
168
+ * Names this item's model.
169
+ */
170
+ $model: string;
171
+
172
+ /**
173
+ * Uniquely identifies the item in context of its model.
174
+ */
175
+ $id: string;
176
+
177
+ /**
178
+ * Lists segments of relative path of file this item's originating
179
+ * record has been read from.
180
+ */
181
+ $segments: string[];
182
+
183
+ /**
184
+ * item's properties
185
+ */
186
+ [name: string]: any;
187
+ }
188
+
147
189
  /**
148
190
  * Lists default values for properties of a single model's item.
149
191
  */
@@ -202,6 +244,18 @@ declare module "concrete-db" {
202
244
  defaults: ShapePropertyDefaults;
203
245
  properties: ShapeProperties;
204
246
  collections: ShapeCollections;
247
+ contributions: {
248
+ [contributedModelName: string]: {
249
+ [targetPropertyName: string]: string;
250
+ };
251
+ };
252
+
253
+ /**
254
+ * Declares term to compute an item's variant. If falsy or omitted, the
255
+ * model does not have variants and multiple records describing an item
256
+ * are merged property by property.
257
+ */
258
+ variant?: string;
205
259
  }
206
260
 
207
261
  export interface Shape {
package/cure.mjs CHANGED
@@ -1,31 +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
- */
28
-
1
+ #!/usr/bin/env node
29
2
  import File from "fs";
30
3
  import Path from "path";
31
4
 
@@ -35,6 +8,7 @@ import YAML from "yaml";
35
8
  import meta from "./lib/meta.cjs";
36
9
  import { cure } from "./lib/index.mjs";
37
10
  import { ShapeFileName } from "./lib/defaults.mjs";
11
+ import { YAMLParserOptions } from "./lib/options.mjs";
38
12
 
39
13
 
40
14
  const args = minimist( process.argv.slice( 2 ) );
@@ -71,7 +45,7 @@ if ( args.V || args.version ) {
71
45
  const globalShapeFile = args.s || args.shape || Path.resolve( process.cwd(), ShapeFileName );
72
46
 
73
47
  try {
74
- options.shape = Object.freeze( YAML.parse( await File.promises.readFile( globalShapeFile, { encoding: "utf8" } ) ) );
48
+ options.shape = Object.freeze( YAML.parse( await File.promises.readFile( globalShapeFile, { encoding: "utf8" } ), YAMLParserOptions ) );
75
49
  } catch ( cause ) {
76
50
  if ( cause.code !== "ENOENT" ) {
77
51
  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 { ShapeFileName, DefaultCollectorOptions, DefaultShape } from "./defaults.mjs";
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,7 +30,10 @@ export class Collector extends EventEmitter {
58
30
  super();
59
31
 
60
32
  Object.defineProperties( this, {
61
- options: { value: { ...DefaultCollectorOptions, ...options }, enumerable: true },
33
+ options: {
34
+ value: { ...DefaultCollectorOptions, ...options },
35
+ enumerable: true
36
+ },
62
37
  records: { value: new Map(), enumerable: true },
63
38
  } );
64
39
  }
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";
File without changes
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.yml";
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.yml" ), { encoding: "utf8" } ) );
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";
package/lib/helper.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
  /**
30
2
  * Wraps provided object in a proxy offering case-insensitive access on
31
3
  * object's properties. Any accessed property's value is wrapped before
@@ -37,7 +9,7 @@
37
9
  * @param {object} meta set of meta properties to blend in (case-sensitively)
38
10
  * @returns {any} provided data wrapped for case-insensitive selection of own properties
39
11
  */
40
- export function augmentedDataSpace( data, meta = undefined ) {
12
+ export function augmentDataSpace( data, meta = undefined ) {
41
13
  if ( !data || typeof data !== "object" ) {
42
14
  return data;
43
15
  }
@@ -50,8 +22,12 @@ export function augmentedDataSpace( data, meta = undefined ) {
50
22
  return meta[name];
51
23
  }
52
24
 
25
+ if ( typeof name === "symbol" ) {
26
+ return object[name];
27
+ }
28
+
53
29
  if ( Object.prototype.hasOwnProperty.call( object, name ) ) {
54
- return augmentedDataSpace( object[name] );
30
+ return augmentDataSpace( object[name] );
55
31
  }
56
32
 
57
33
  if ( !cached && typeof name === "string" ) {
@@ -68,12 +44,11 @@ export function augmentedDataSpace( data, meta = undefined ) {
68
44
  }
69
45
  }
70
46
 
71
- return augmentedDataSpace( object[cached[name.toLocaleLowerCase()]] );
47
+ return augmentDataSpace( object[cached[name.toLocaleLowerCase()]] );
72
48
  },
73
49
  } );
74
50
  }
75
51
 
76
-
77
52
  /**
78
53
  * Implements special kind of value representing reference on uniquely identified
79
54
  * 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;
@@ -0,0 +1,3 @@
1
+ export const YAMLParserOptions = {
2
+ version: "1.1",
3
+ };