oca_package 1.4.0 → 1.6.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.
Files changed (41) hide show
  1. package/README.md +0 -2
  2. package/dist/cjs/oca_extensions/extensions.js +30 -14
  3. package/dist/cjs/oca_extensions/state/attribute.js +25 -10
  4. package/dist/cjs/oca_extensions/state/overlays/example.js +8 -3
  5. package/dist/cjs/oca_extensions/state/overlays/framing/attribute_framing.js +6 -1
  6. package/dist/cjs/oca_extensions/state/overlays/framing/unit_framing.js +6 -1
  7. package/dist/cjs/oca_extensions/state/overlays/ordering.js +6 -1
  8. package/dist/cjs/oca_extensions/state/overlays/range.js +6 -1
  9. package/dist/cjs/oca_extensions/state/overlays/sensitive.js +6 -1
  10. package/dist/cjs/oca_extensions/state/overlays/separator.js +31 -43
  11. package/dist/cjs/oca_package.js +1 -1
  12. package/dist/esm/oca_extensions/extensions.js +30 -14
  13. package/dist/esm/oca_extensions/state/attribute.js +25 -8
  14. package/dist/esm/oca_extensions/state/overlays/example.js +8 -3
  15. package/dist/esm/oca_extensions/state/overlays/framing/attribute_framing.js +6 -1
  16. package/dist/esm/oca_extensions/state/overlays/framing/unit_framing.js +6 -1
  17. package/dist/esm/oca_extensions/state/overlays/ordering.js +6 -1
  18. package/dist/esm/oca_extensions/state/overlays/range.js +6 -1
  19. package/dist/esm/oca_extensions/state/overlays/sensitive.js +6 -1
  20. package/dist/esm/oca_extensions/state/overlays/separator.js +28 -43
  21. package/dist/esm/oca_package.js +1 -1
  22. package/dist/types/oca_extensions/extensions.d.ts +4 -2
  23. package/dist/types/oca_extensions/extensions.d.ts.map +1 -1
  24. package/dist/types/oca_extensions/state/attribute.d.ts +0 -12
  25. package/dist/types/oca_extensions/state/attribute.d.ts.map +1 -1
  26. package/dist/types/oca_extensions/state/overlays/example.d.ts +3 -2
  27. package/dist/types/oca_extensions/state/overlays/example.d.ts.map +1 -1
  28. package/dist/types/oca_extensions/state/overlays/framing/attribute_framing.d.ts +2 -1
  29. package/dist/types/oca_extensions/state/overlays/framing/attribute_framing.d.ts.map +1 -1
  30. package/dist/types/oca_extensions/state/overlays/framing/unit_framing.d.ts +2 -1
  31. package/dist/types/oca_extensions/state/overlays/framing/unit_framing.d.ts.map +1 -1
  32. package/dist/types/oca_extensions/state/overlays/ordering.d.ts +2 -1
  33. package/dist/types/oca_extensions/state/overlays/ordering.d.ts.map +1 -1
  34. package/dist/types/oca_extensions/state/overlays/range.d.ts +2 -1
  35. package/dist/types/oca_extensions/state/overlays/range.d.ts.map +1 -1
  36. package/dist/types/oca_extensions/state/overlays/sensitive.d.ts +2 -1
  37. package/dist/types/oca_extensions/state/overlays/sensitive.d.ts.map +1 -1
  38. package/dist/types/oca_extensions/state/overlays/separator.d.ts +12 -43
  39. package/dist/types/oca_extensions/state/overlays/separator.d.ts.map +1 -1
  40. package/package.json +1 -2
  41. package/LICENSE +0 -287
package/README.md CHANGED
@@ -14,7 +14,6 @@ npm i oca_package
14
14
 
15
15
  ```typescript
16
16
  import { OcaPackage } from 'oca_package';
17
- import { except } from 'vitest'; // make sure to install vitest or use any other testing library
18
17
 
19
18
  const extension = {
20
19
  extensions: {
@@ -125,5 +124,4 @@ const oca_bundle = {
125
124
  };
126
125
 
127
126
  const oca_package = new OcaPackage(extension, oca_bundle);
128
- expect(JSON.parse(oca_package.GenerateOcaPackage()).d).toBe('EG5L9MmzrvRdscWysJKw7tfwutGD0MSkFNsbULms3AmV');
129
127
  ```
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  // TODO: use canonicalize to consistently order how properties of overlays should appear
3
- // Do validation for the generation exentension chunck, and parts of oca_package.
3
+ // TODO: Do validation for the generation exentension chunck, and parts of oca_package.
4
+ // TODO: what happens when extension json input contains an extension overlay that does exist in the a given community? logging or throwing an error?
5
+ // TODO: do validation for dynamic extension overlays (DynOverlay) input, per individual overlay.
4
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
5
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
8
  };
@@ -12,6 +14,7 @@ const example_js_1 = __importDefault(require("./state/overlays/example.js"));
12
14
  const range_js_1 = __importDefault(require("./state/overlays/range.js"));
13
15
  const sensitive_js_1 = __importDefault(require("./state/overlays/sensitive.js"));
14
16
  const attribute_framing_js_1 = __importDefault(require("./state/overlays/framing/attribute_framing.js"));
17
+ const separator_js_1 = __importDefault(require("./state/overlays/separator.js"));
15
18
  const helpers_js_1 = require("../utils/helpers.js");
16
19
  const saidify_1 = require("saidify");
17
20
  const ADC_COMMUNITY = 'adc';
@@ -39,38 +42,47 @@ class ExtensionState {
39
42
  }
40
43
  exports.ExtensionState = ExtensionState;
41
44
  class Overlay {
42
- constructor(community_overlay) {
45
+ constructor(community_overlay, capture_base_digest) {
46
+ if (!capture_base_digest) {
47
+ throw new Error('capture_base_digest is required');
48
+ }
43
49
  this._overlay = community_overlay;
50
+ this._capture_base_digest = capture_base_digest;
44
51
  }
45
52
  GenerateOverlay() {
46
53
  const overlay = {};
47
54
  for (const ov_type in this._overlay) {
48
55
  if (ov_type === 'ordering_overlay') {
49
- const ordering_instance = new ordering_js_1.default(this._overlay.ordering_overlay);
56
+ const ordering_instance = new ordering_js_1.default(this._overlay.ordering_overlay, this._capture_base_digest);
50
57
  const ordering_ov = ordering_instance.GenerateOverlay();
51
58
  overlay['ordering'] = JSON.parse(ordering_ov);
52
59
  }
53
60
  else if (ov_type === 'unit_framing_overlay') {
54
- const unit_framing_instance = new unit_framing_js_1.default(this._overlay.unit_framing_overlay);
61
+ const unit_framing_instance = new unit_framing_js_1.default(this._overlay.unit_framing_overlay, this._capture_base_digest);
55
62
  const unit_framing_ov = unit_framing_instance.GenerateOverlay();
56
63
  overlay['unit_framing'] = JSON.parse(unit_framing_ov);
57
64
  }
58
65
  else if (ov_type === 'range_overlay') {
59
- const range_instance = new range_js_1.default(this._overlay.range_overlay);
66
+ const range_instance = new range_js_1.default(this._overlay.range_overlay, this._capture_base_digest);
60
67
  const range_ov = range_instance.GenerateOverlay();
61
68
  overlay['range'] = JSON.parse(range_ov);
62
69
  }
63
70
  else if (ov_type === 'example_overlay') {
64
- const example_ov = example_js_1.default.GenerateOverlay(this._overlay.example_overlay);
71
+ const example_ov = example_js_1.default.GenerateOverlay(this._overlay.example_overlay, this._capture_base_digest);
65
72
  overlay['example'] = JSON.parse(example_ov);
66
73
  }
67
74
  else if (ov_type === 'sensitive_overlay') {
68
- const sensitive_instance = new sensitive_js_1.default(this._overlay.sensitive_overlay);
75
+ const sensitive_instance = new sensitive_js_1.default(this._overlay.sensitive_overlay, this._capture_base_digest);
69
76
  const sensitive_ov = sensitive_instance.GenerateOverlay();
70
77
  overlay['sensitive'] = JSON.parse(sensitive_ov);
71
78
  }
79
+ else if (ov_type === 'separator_overlay') {
80
+ const separator_instance = new separator_js_1.default(this._overlay.separator_overlay, this._capture_base_digest);
81
+ const separator_ov = separator_instance.GenerateOverlay();
82
+ overlay['separator'] = JSON.parse(separator_ov);
83
+ }
72
84
  else if (ov_type === 'attribute_framing_overlay') {
73
- const attribute_framing_instance = new attribute_framing_js_1.default(this._overlay.attribute_framing_overlay);
85
+ const attribute_framing_instance = new attribute_framing_js_1.default(this._overlay.attribute_framing_overlay, this._capture_base_digest);
74
86
  const attribute_framing_ov = attribute_framing_instance.GenerateOverlay();
75
87
  overlay['attribute_framing'] = JSON.parse(attribute_framing_ov);
76
88
  }
@@ -89,11 +101,11 @@ class Overlay {
89
101
  }
90
102
  exports.Overlay = Overlay;
91
103
  class ADCOverlayStrategy {
92
- GenerateOverlay(extensions) {
104
+ GenerateOverlay(extensions, capture_base_digest) {
93
105
  const overlays = {};
94
106
  for (const extKey in extensions) {
95
107
  const ext = extensions[extKey];
96
- const overlay_instance = new Overlay(ext);
108
+ const overlay_instance = new Overlay(ext, capture_base_digest);
97
109
  const generated_overlay = overlay_instance.GenerateOverlay();
98
110
  for (const overlay_type in generated_overlay) {
99
111
  overlays[overlay_type] = generated_overlay[overlay_type];
@@ -110,19 +122,23 @@ class DefaultOverlayStrategy {
110
122
  }
111
123
  }
112
124
  class Extension {
113
- constructor(_extensions_input, community) {
125
+ constructor(_extensions_input, community, capture_base_digest) {
114
126
  this.d = '';
115
127
  this.overlays = {};
116
128
  if (!_extensions_input || !community) {
117
129
  throw new Error('extension array is required from extension state and community is required');
118
130
  }
131
+ if (!capture_base_digest) {
132
+ throw new Error('capture_base_digest is required');
133
+ }
119
134
  this._community = community;
120
135
  this._exensions = _extensions_input;
121
136
  this.type = `community/${this._community}/extension/${EXTENSION_VERSION}`;
137
+ this.capture_base_digest = capture_base_digest;
122
138
  }
123
139
  GenerateOverlays() {
124
140
  const strategy = this._community === ADC_COMMUNITY ? new ADCOverlayStrategy() : new DefaultOverlayStrategy();
125
- return strategy.GenerateOverlay(this._exensions);
141
+ return strategy.GenerateOverlay(this._exensions, this.capture_base_digest);
126
142
  }
127
143
  toJSON() {
128
144
  return {
@@ -156,7 +172,7 @@ class ExtensionBox {
156
172
  if (bundle_digest === (0, helpers_js_1.ocabundleDigest)(this._oca_bundle)) {
157
173
  const capture_base_digest = (0, helpers_js_1.getDigest)(this._oca_bundle);
158
174
  const community_extension_input = extensionState_communities[community][bundle_digest];
159
- const extension = new Extension(community_extension_input, community);
175
+ const extension = new Extension(community_extension_input, community, capture_base_digest);
160
176
  extensionsBox[community][capture_base_digest] = extension.GenerateExtension();
161
177
  }
162
178
  else if (bundle_digest !== (0, helpers_js_1.ocabundleDigest)(this._oca_bundle)) {
@@ -164,7 +180,7 @@ class ExtensionBox {
164
180
  const current_bundle = (0, helpers_js_1.getOcaBundleFromDeps)(this._oca_bundle, bundle_digest);
165
181
  const capture_base_digest = (0, helpers_js_1.getDigest)(current_bundle);
166
182
  const community_extension_input = extensionState_communities[community][bundle_digest];
167
- const extension = new Extension(community_extension_input, community);
183
+ const extension = new Extension(community_extension_input, community, capture_base_digest);
168
184
  extensionsBox[community][capture_base_digest] = extension.GenerateExtension();
169
185
  }
170
186
  }
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Attribute {
4
- constructor(attribute) {
5
- this.name = attribute;
6
- this.attribute_separators = {};
7
- }
8
- setAttributeSeparators(attribute_separators) {
9
- this.attribute_separators = attribute_separators;
10
- }
2
+ /* The states of attributes from the extensions */
3
+ /* import { SeparatorValues } from '../state/overlays/separator.js';
4
+
5
+ interface IAttribute {
6
+ name: string;
7
+ attribute_separators: SeparatorValues;
11
8
  }
12
- exports.default = Attribute;
9
+
10
+ class Attribute implements IAttribute {
11
+ public name: string;
12
+ public attribute_separators: SeparatorValues;
13
+
14
+ constructor(attribute: string) {
15
+ this.name = attribute;
16
+ this.attribute_separators = {} as SeparatorValues;
17
+ }
18
+
19
+ public setAttributeSeparators(attribute_separators: SeparatorValues): void {
20
+ this.attribute_separators = attribute_separators;
21
+ }
22
+ }
23
+
24
+ export default Attribute;
25
+
26
+
27
+ */
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const saidify_1 = require("saidify");
7
7
  const canonical_js_1 = __importDefault(require("../../../utils/canonical.js"));
8
8
  class ExampleOverlay {
9
- constructor(dynOverlay) {
9
+ constructor(dynOverlay, capture_base_digest) {
10
10
  if (!dynOverlay) {
11
11
  throw new Error('A dynamic extension overlay is required');
12
12
  }
13
+ if (!capture_base_digest) {
14
+ throw new Error('capture_base_digest is required');
15
+ }
13
16
  this.dynOverlay = dynOverlay;
17
+ this.capture_base_digest = capture_base_digest;
14
18
  }
15
19
  get language() {
16
20
  return this.dynOverlay.language;
@@ -24,6 +28,7 @@ class ExampleOverlay {
24
28
  toJSON() {
25
29
  return {
26
30
  d: '',
31
+ capture_base: this.capture_base_digest,
27
32
  type: 'community/overlays/adc/example/1.1',
28
33
  language: this.language,
29
34
  attribute_examples: this.GetAttributeExamples(),
@@ -37,7 +42,7 @@ class ExampleOverlay {
37
42
  GenerateExampleOverlay() {
38
43
  return JSON.stringify(this.Saidifying());
39
44
  }
40
- static GenerateOverlay(dynOverlay) {
45
+ static GenerateOverlay(dynOverlay, capture_base_digest) {
41
46
  if (!dynOverlay || typeof dynOverlay !== 'object' || !Array.isArray(dynOverlay['example_overlays'])) {
42
47
  throw new Error('Invalid dynOverlay structure. Expected an object with an "example_overlays" array.');
43
48
  }
@@ -45,7 +50,7 @@ class ExampleOverlay {
45
50
  const overlays = dynOverlay['example_overlays'];
46
51
  for (let example_ov of overlays) {
47
52
  try {
48
- const example_overlay = new ExampleOverlay(example_ov);
53
+ const example_overlay = new ExampleOverlay(example_ov, capture_base_digest);
49
54
  example_overlays.push(JSON.parse(example_overlay.GenerateExampleOverlay()));
50
55
  }
51
56
  catch (error) {
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const saidify_1 = require("saidify");
7
7
  const canonical_js_1 = __importDefault(require("../../../../utils/canonical.js"));
8
8
  class AttributeFraming {
9
- constructor(dynOverlay) {
9
+ constructor(dynOverlay, capture_base_digest) {
10
10
  if (!dynOverlay) {
11
11
  throw new Error('a dynamic extension overlay are required');
12
12
  }
13
+ if (!capture_base_digest) {
14
+ throw new Error('capture_base_digest is required');
15
+ }
13
16
  this.dynOverlay = dynOverlay;
17
+ this.capture_base_digest = capture_base_digest;
14
18
  }
15
19
  GetFramedAttributes() {
16
20
  const attributes = this.dynOverlay.attributes;
@@ -41,6 +45,7 @@ class AttributeFraming {
41
45
  toJSON() {
42
46
  return {
43
47
  d: '',
48
+ capture_base: this.capture_base_digest,
44
49
  type: 'community/overlays/adc/attribute_framing/1.1',
45
50
  framing_metadata: this.GetFramingMetadata(),
46
51
  attributes: this.GetFramedAttributes(),
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const saidify_1 = require("saidify");
7
7
  const canonical_js_1 = __importDefault(require("../../../../utils/canonical.js"));
8
8
  class UnitFraming {
9
- constructor(dynOverlay) {
9
+ constructor(dynOverlay, capture_base_digest) {
10
10
  if (!dynOverlay) {
11
11
  throw new Error('a dynamic extension overlay are required');
12
12
  }
13
+ if (!capture_base_digest) {
14
+ throw new Error('capture_base_digest is required');
15
+ }
13
16
  this.dynOverlay = dynOverlay;
17
+ this.capture_base_digest = capture_base_digest;
14
18
  }
15
19
  GetUnits() {
16
20
  const units = this.dynOverlay.units;
@@ -33,6 +37,7 @@ class UnitFraming {
33
37
  toJSON() {
34
38
  return {
35
39
  d: '',
40
+ capture_base: this.capture_base_digest,
36
41
  type: 'community/overlays/adc/unit_framing/1.1',
37
42
  framing_metadata: {
38
43
  id: this.GetId(),
@@ -2,11 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const saidify_1 = require("saidify");
4
4
  class Ordering {
5
- constructor(dynOverlay) {
5
+ constructor(dynOverlay, capture_base_digest) {
6
6
  if (!dynOverlay) {
7
7
  throw new Error('a dynamic extension overlay are required');
8
8
  }
9
+ if (!capture_base_digest) {
10
+ throw new Error('capture_base_digest is required');
11
+ }
9
12
  this.dynOverlay = dynOverlay;
13
+ this.capture_base_digest = capture_base_digest;
10
14
  }
11
15
  GetAttributeOrdering() {
12
16
  return this.dynOverlay.attribute_ordering;
@@ -17,6 +21,7 @@ class Ordering {
17
21
  toJSON() {
18
22
  return {
19
23
  d: '',
24
+ capture_base: this.capture_base_digest,
20
25
  type: 'community/overlays/adc/ordering/1.1',
21
26
  attribute_ordering: this.GetAttributeOrdering(),
22
27
  entry_code_ordering: this.GetEntryCodeOrdering(),
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const saidify_1 = require("saidify");
7
7
  const canonical_js_1 = __importDefault(require("../../../utils/canonical.js"));
8
8
  class Range {
9
- constructor(dynOverlay) {
9
+ constructor(dynOverlay, capture_base_digest) {
10
10
  if (!dynOverlay) {
11
11
  throw new Error('a dynamic extension overlay are required');
12
12
  }
13
+ if (!capture_base_digest) {
14
+ throw new Error('capture_base_digest is required');
15
+ }
13
16
  this.dynOverlay = dynOverlay;
17
+ this.capture_base_digest = capture_base_digest;
14
18
  }
15
19
  GetAttributes() {
16
20
  const range_overlay_attributes = this.dynOverlay.attributes;
@@ -21,6 +25,7 @@ class Range {
21
25
  toJSON() {
22
26
  return {
23
27
  d: '',
28
+ capture_base: this.capture_base_digest,
24
29
  type: 'community/overlays/adc/range/1.1',
25
30
  attributes: this.GetAttributes(),
26
31
  };
@@ -2,11 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const saidify_1 = require("saidify");
4
4
  class Sensitive {
5
- constructor(dynOverlay) {
5
+ constructor(dynOverlay, capture_base_digest) {
6
6
  if (!dynOverlay) {
7
7
  throw new Error('a dynamic extension overlay are required');
8
8
  }
9
+ if (!capture_base_digest) {
10
+ throw new Error('capture_base_digest is required');
11
+ }
9
12
  this.dynOverlay = dynOverlay;
13
+ this.capture_base_digest = capture_base_digest;
10
14
  }
11
15
  GetSensitiveAttributes() {
12
16
  const sensitive_overlay_attributes = this.dynOverlay.sensitive_attributes;
@@ -17,6 +21,7 @@ class Sensitive {
17
21
  toJSON() {
18
22
  return {
19
23
  d: '',
24
+ capture_base: this.capture_base_digest,
20
25
  type: 'community/overlays/adc/sensitive/1.1',
21
26
  sensitive_attributes: this.GetSensitiveAttributes(),
22
27
  };
@@ -28,62 +28,50 @@ Canoncial rules:
28
28
  }
29
29
  }
30
30
  */
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
31
34
  Object.defineProperty(exports, "__esModule", { value: true });
32
35
  const saidify_1 = require("saidify");
33
- const helpers_js_1 = require("../../../utils/helpers.js");
34
- const types_js_1 = require("../../../types/types.js");
36
+ const canonical_js_1 = __importDefault(require("../../../utils/canonical.js"));
35
37
  class Separator {
36
- constructor(separators, oca_bundle) {
37
- this.said = '';
38
- this.type = types_js_1.OverlayTypes.Separator;
39
- this.separators = separators;
40
- this.oca_bundle = oca_bundle;
41
- this.capture_base = (0, helpers_js_1.getDigest)(this.oca_bundle);
38
+ constructor(dynOverlay, capture_base_digest) {
39
+ if (!dynOverlay) {
40
+ throw new Error('a dynamic extension overlay are required');
41
+ }
42
+ if (!capture_base_digest) {
43
+ throw new Error('capture_base_digest is required');
44
+ }
45
+ this.dynOverlay = dynOverlay;
46
+ this.capture_base_digest = capture_base_digest;
42
47
  }
43
- overlay_type() {
44
- return this.type;
48
+ GetAttributesSeparators() {
49
+ const separator_overlay_attributes = this.dynOverlay.attribute_separators;
50
+ const canonicalized_attributes = (0, canonical_js_1.default)(separator_overlay_attributes);
51
+ const sortedAttributes = JSON.parse(canonicalized_attributes);
52
+ return sortedAttributes;
45
53
  }
46
- attributes() {
47
- const sorted_attribute_separators = [];
48
- if (this.separators.attribute_separators) {
49
- for (const key in this.separators.attribute_separators) {
50
- if (Object.prototype.hasOwnProperty.call(this.separators.attribute_separators, key)) {
51
- if (!(0, helpers_js_1.isPresent)(key, this.oca_bundle)) {
52
- throw new Error(`Attribute ${key} not found in OCA bundle Capture Base.`);
53
- }
54
- sorted_attribute_separators.push({ key, value: this.separators.attribute_separators[key] });
55
- }
56
- }
57
- // Sort the attribute separators by key
58
- sorted_attribute_separators.sort((a, b) => a.key.localeCompare(b.key));
59
- }
60
- return sorted_attribute_separators;
54
+ GetDatasetSeparator() {
55
+ const separator_overlay_dataset = this.dynOverlay.dataset_separator;
56
+ const canonicalized_dataset = (0, canonical_js_1.default)(separator_overlay_dataset);
57
+ const sortedDataset = JSON.parse(canonicalized_dataset);
58
+ return sortedDataset;
61
59
  }
62
- // serialize the separator overlay
63
60
  toJSON() {
64
- const serialized_attribute_separators = {};
65
- for (const attr of this.attributes()) {
66
- serialized_attribute_separators[attr.key] = attr.value;
67
- }
68
61
  return {
69
- d: this.said,
70
- type: 'community/adc/overlays/separator/1.0',
71
- capture_base: this.capture_base,
72
- dataset_separator: this.separators.dataset_separator,
73
- attribute_separators: serialized_attribute_separators,
62
+ d: '',
63
+ capture_base: this.capture_base_digest,
64
+ type: 'community/overlays/adc/separator/1.1',
65
+ attribute_separators: this.GetAttributesSeparators(),
66
+ dataset_separator: this.GetDatasetSeparator(),
74
67
  };
75
68
  }
76
- saidifying() {
69
+ Saidifying() {
77
70
  const [, sad] = (0, saidify_1.saidify)(this.toJSON());
78
71
  return sad;
79
72
  }
80
- generate_overlay() {
81
- return JSON.stringify(this.saidifying());
82
- }
83
- // TODO: find out if it neccessary to implement this methood for all overlays
84
- static deser(separator_ov_json_string) {
85
- const separator_ov_json = JSON.parse(separator_ov_json_string);
86
- return new Separator(separator_ov_json, separator_ov_json.capture_base);
73
+ GenerateOverlay() {
74
+ return JSON.stringify(this.Saidifying());
87
75
  }
88
76
  }
89
77
  exports.default = Separator;
@@ -8,8 +8,8 @@ const extensions_js_1 = __importDefault(require("./oca_extensions/extensions.js"
8
8
  const saidify_1 = require("saidify");
9
9
  class OcaPackage {
10
10
  constructor(extension_input_json, oca_bundle) {
11
- this.extensions_box = new extensions_js_1.default(extension_input_json, oca_bundle);
12
11
  this.oca_bundle = oca_bundle;
12
+ this.extensions_box = new extensions_js_1.default(extension_input_json, oca_bundle);
13
13
  }
14
14
  Saidifying() {
15
15
  const [, sad] = (0, saidify_1.saidify)(this.toJSON());
@@ -1,11 +1,14 @@
1
1
  // TODO: use canonicalize to consistently order how properties of overlays should appear
2
- // Do validation for the generation exentension chunck, and parts of oca_package.
2
+ // TODO: Do validation for the generation exentension chunck, and parts of oca_package.
3
+ // TODO: what happens when extension json input contains an extension overlay that does exist in the a given community? logging or throwing an error?
4
+ // TODO: do validation for dynamic extension overlays (DynOverlay) input, per individual overlay.
3
5
  import Ordering from './state/overlays/ordering.js';
4
6
  import UnitFraming from './state/overlays/framing/unit_framing.js';
5
7
  import ExampleOverlay from './state/overlays/example.js';
6
8
  import Range from './state/overlays/range.js';
7
9
  import Sensitive from './state/overlays/sensitive.js';
8
10
  import AttributeFraming from './state/overlays/framing/attribute_framing.js';
11
+ import Separator from './state/overlays/separator.js';
9
12
  import { ocabundleDigest, getOcaBundleFromDeps, getDigest, isOcaBundleWithDeps } from '../utils/helpers.js';
10
13
  import { saidify } from 'saidify';
11
14
  const ADC_COMMUNITY = 'adc';
@@ -32,38 +35,47 @@ export class ExtensionState {
32
35
  }
33
36
  }
34
37
  export class Overlay {
35
- constructor(community_overlay) {
38
+ constructor(community_overlay, capture_base_digest) {
39
+ if (!capture_base_digest) {
40
+ throw new Error('capture_base_digest is required');
41
+ }
36
42
  this._overlay = community_overlay;
43
+ this._capture_base_digest = capture_base_digest;
37
44
  }
38
45
  GenerateOverlay() {
39
46
  const overlay = {};
40
47
  for (const ov_type in this._overlay) {
41
48
  if (ov_type === 'ordering_overlay') {
42
- const ordering_instance = new Ordering(this._overlay.ordering_overlay);
49
+ const ordering_instance = new Ordering(this._overlay.ordering_overlay, this._capture_base_digest);
43
50
  const ordering_ov = ordering_instance.GenerateOverlay();
44
51
  overlay['ordering'] = JSON.parse(ordering_ov);
45
52
  }
46
53
  else if (ov_type === 'unit_framing_overlay') {
47
- const unit_framing_instance = new UnitFraming(this._overlay.unit_framing_overlay);
54
+ const unit_framing_instance = new UnitFraming(this._overlay.unit_framing_overlay, this._capture_base_digest);
48
55
  const unit_framing_ov = unit_framing_instance.GenerateOverlay();
49
56
  overlay['unit_framing'] = JSON.parse(unit_framing_ov);
50
57
  }
51
58
  else if (ov_type === 'range_overlay') {
52
- const range_instance = new Range(this._overlay.range_overlay);
59
+ const range_instance = new Range(this._overlay.range_overlay, this._capture_base_digest);
53
60
  const range_ov = range_instance.GenerateOverlay();
54
61
  overlay['range'] = JSON.parse(range_ov);
55
62
  }
56
63
  else if (ov_type === 'example_overlay') {
57
- const example_ov = ExampleOverlay.GenerateOverlay(this._overlay.example_overlay);
64
+ const example_ov = ExampleOverlay.GenerateOverlay(this._overlay.example_overlay, this._capture_base_digest);
58
65
  overlay['example'] = JSON.parse(example_ov);
59
66
  }
60
67
  else if (ov_type === 'sensitive_overlay') {
61
- const sensitive_instance = new Sensitive(this._overlay.sensitive_overlay);
68
+ const sensitive_instance = new Sensitive(this._overlay.sensitive_overlay, this._capture_base_digest);
62
69
  const sensitive_ov = sensitive_instance.GenerateOverlay();
63
70
  overlay['sensitive'] = JSON.parse(sensitive_ov);
64
71
  }
72
+ else if (ov_type === 'separator_overlay') {
73
+ const separator_instance = new Separator(this._overlay.separator_overlay, this._capture_base_digest);
74
+ const separator_ov = separator_instance.GenerateOverlay();
75
+ overlay['separator'] = JSON.parse(separator_ov);
76
+ }
65
77
  else if (ov_type === 'attribute_framing_overlay') {
66
- const attribute_framing_instance = new AttributeFraming(this._overlay.attribute_framing_overlay);
78
+ const attribute_framing_instance = new AttributeFraming(this._overlay.attribute_framing_overlay, this._capture_base_digest);
67
79
  const attribute_framing_ov = attribute_framing_instance.GenerateOverlay();
68
80
  overlay['attribute_framing'] = JSON.parse(attribute_framing_ov);
69
81
  }
@@ -81,11 +93,11 @@ export class Overlay {
81
93
  }
82
94
  }
83
95
  class ADCOverlayStrategy {
84
- GenerateOverlay(extensions) {
96
+ GenerateOverlay(extensions, capture_base_digest) {
85
97
  const overlays = {};
86
98
  for (const extKey in extensions) {
87
99
  const ext = extensions[extKey];
88
- const overlay_instance = new Overlay(ext);
100
+ const overlay_instance = new Overlay(ext, capture_base_digest);
89
101
  const generated_overlay = overlay_instance.GenerateOverlay();
90
102
  for (const overlay_type in generated_overlay) {
91
103
  overlays[overlay_type] = generated_overlay[overlay_type];
@@ -102,19 +114,23 @@ class DefaultOverlayStrategy {
102
114
  }
103
115
  }
104
116
  export class Extension {
105
- constructor(_extensions_input, community) {
117
+ constructor(_extensions_input, community, capture_base_digest) {
106
118
  this.d = '';
107
119
  this.overlays = {};
108
120
  if (!_extensions_input || !community) {
109
121
  throw new Error('extension array is required from extension state and community is required');
110
122
  }
123
+ if (!capture_base_digest) {
124
+ throw new Error('capture_base_digest is required');
125
+ }
111
126
  this._community = community;
112
127
  this._exensions = _extensions_input;
113
128
  this.type = `community/${this._community}/extension/${EXTENSION_VERSION}`;
129
+ this.capture_base_digest = capture_base_digest;
114
130
  }
115
131
  GenerateOverlays() {
116
132
  const strategy = this._community === ADC_COMMUNITY ? new ADCOverlayStrategy() : new DefaultOverlayStrategy();
117
- return strategy.GenerateOverlay(this._exensions);
133
+ return strategy.GenerateOverlay(this._exensions, this.capture_base_digest);
118
134
  }
119
135
  toJSON() {
120
136
  return {
@@ -147,7 +163,7 @@ class ExtensionBox {
147
163
  if (bundle_digest === ocabundleDigest(this._oca_bundle)) {
148
164
  const capture_base_digest = getDigest(this._oca_bundle);
149
165
  const community_extension_input = extensionState_communities[community][bundle_digest];
150
- const extension = new Extension(community_extension_input, community);
166
+ const extension = new Extension(community_extension_input, community, capture_base_digest);
151
167
  extensionsBox[community][capture_base_digest] = extension.GenerateExtension();
152
168
  }
153
169
  else if (bundle_digest !== ocabundleDigest(this._oca_bundle)) {
@@ -155,7 +171,7 @@ class ExtensionBox {
155
171
  const current_bundle = getOcaBundleFromDeps(this._oca_bundle, bundle_digest);
156
172
  const capture_base_digest = getDigest(current_bundle);
157
173
  const community_extension_input = extensionState_communities[community][bundle_digest];
158
- const extension = new Extension(community_extension_input, community);
174
+ const extension = new Extension(community_extension_input, community, capture_base_digest);
159
175
  extensionsBox[community][capture_base_digest] = extension.GenerateExtension();
160
176
  }
161
177
  }
@@ -1,10 +1,27 @@
1
- class Attribute {
2
- constructor(attribute) {
3
- this.name = attribute;
4
- this.attribute_separators = {};
5
- }
6
- setAttributeSeparators(attribute_separators) {
7
- this.attribute_separators = attribute_separators;
8
- }
1
+ /* The states of attributes from the extensions */
2
+ export {};
3
+ /* import { SeparatorValues } from '../state/overlays/separator.js';
4
+
5
+ interface IAttribute {
6
+ name: string;
7
+ attribute_separators: SeparatorValues;
9
8
  }
9
+
10
+ class Attribute implements IAttribute {
11
+ public name: string;
12
+ public attribute_separators: SeparatorValues;
13
+
14
+ constructor(attribute: string) {
15
+ this.name = attribute;
16
+ this.attribute_separators = {} as SeparatorValues;
17
+ }
18
+
19
+ public setAttributeSeparators(attribute_separators: SeparatorValues): void {
20
+ this.attribute_separators = attribute_separators;
21
+ }
22
+ }
23
+
10
24
  export default Attribute;
25
+
26
+
27
+ */