oca_package 1.2.0 → 1.2.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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Extension = exports.Overlay = exports.ExtensionState = void 0;
7
7
  const ordering_js_1 = __importDefault(require("./state/overlays/ordering.js"));
8
8
  const unit_framing_js_1 = __importDefault(require("./state/overlays/framing/unit_framing.js"));
9
+ const example_js_1 = __importDefault(require("./state/overlays/example.js"));
9
10
  const range_js_1 = __importDefault(require("./state/overlays/range.js"));
10
11
  const helpers_js_1 = require("../utils/helpers.js");
11
12
  const saidify_1 = require("saidify");
@@ -41,21 +42,26 @@ class Overlay {
41
42
  const overlay = {};
42
43
  for (const ov_type in this._overlay) {
43
44
  if (ov_type === 'ordering_overlay') {
44
- const ordering_instance = new ordering_js_1.default(this._overlay);
45
+ const ordering_instance = new ordering_js_1.default(this._overlay.ordering_overlay);
45
46
  const ordering_ov = ordering_instance.GenerateOverlay();
46
47
  overlay['ordering'] = JSON.parse(ordering_ov);
47
48
  }
48
49
  else if (ov_type === 'unit_framing_overlay') {
49
- const unit_framing_instance = new unit_framing_js_1.default(this._overlay);
50
+ const unit_framing_instance = new unit_framing_js_1.default(this._overlay.unit_framing_overlay);
50
51
  const unit_framing_ov = unit_framing_instance.GenerateOverlay();
51
52
  overlay['unit_framing'] = JSON.parse(unit_framing_ov);
52
53
  }
53
54
  else if (ov_type === 'range_overlay') {
54
- const range_instance = new range_js_1.default(this._overlay);
55
+ const range_instance = new range_js_1.default(this._overlay.range_overlay);
55
56
  const range_ov = range_instance.GenerateOverlay();
56
57
  overlay['range'] = JSON.parse(range_ov);
57
58
  }
59
+ else if (ov_type === 'example_overlay') {
60
+ const example_ov = example_js_1.default.GenerateOverlay(this._overlay.example_overlay);
61
+ overlay['example'] = JSON.parse(example_ov);
62
+ }
58
63
  else {
64
+ // throwing an error as all extension overlays authored by adc should be handled by the overlay class
59
65
  throw new Error('Invalid overlay name');
60
66
  }
61
67
  }
@@ -80,7 +86,7 @@ class ADCOverlayStrategy {
80
86
  // To implement overlays for external communities, create a new class that implements the OverlayStrategy interface.
81
87
  // For example, if you have a community called "external_community", you can create a class like this:
82
88
  class DefaultOverlayStrategy {
83
- GenerateOverlay(extensions) {
89
+ GenerateOverlay(_extensions) {
84
90
  throw new Error('Unsupported community type');
85
91
  }
86
92
  }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const saidify_1 = require("saidify");
7
+ const canonical_js_1 = __importDefault(require("../../../utils/canonical.js"));
8
+ class ExampleOverlay {
9
+ constructor(dynOverlay) {
10
+ if (!dynOverlay) {
11
+ throw new Error('A dynamic extension overlay is required');
12
+ }
13
+ this.dynOverlay = dynOverlay;
14
+ }
15
+ get language() {
16
+ return this.dynOverlay.language;
17
+ }
18
+ GetAttributeExamples() {
19
+ const examples = this.dynOverlay.attribute_examples;
20
+ const canonicalizedExamples = (0, canonical_js_1.default)(examples);
21
+ const sortedExamples = JSON.parse(canonicalizedExamples);
22
+ return sortedExamples;
23
+ }
24
+ toJSON() {
25
+ return {
26
+ d: '',
27
+ type: 'community/overlays/adc/example/1.1',
28
+ language: this.language,
29
+ attribute_examples: this.GetAttributeExamples(),
30
+ };
31
+ }
32
+ Saidifying() {
33
+ const [, sad] = (0, saidify_1.saidify)(this.toJSON());
34
+ return sad;
35
+ }
36
+ // generates a single example overlay
37
+ GenerateExampleOverlay() {
38
+ return JSON.stringify(this.Saidifying());
39
+ }
40
+ static GenerateOverlay(dynOverlay) {
41
+ if (!dynOverlay || typeof dynOverlay !== 'object' || !Array.isArray(dynOverlay['example_overlays'])) {
42
+ throw new Error('Invalid dynOverlay structure. Expected an object with an "example_overlays" array.');
43
+ }
44
+ const example_overlays = [];
45
+ const overlays = dynOverlay['example_overlays'];
46
+ for (let example_ov of overlays) {
47
+ try {
48
+ const example_overlay = new ExampleOverlay(example_ov);
49
+ example_overlays.push(JSON.parse(example_overlay.GenerateExampleOverlay()));
50
+ }
51
+ catch (error) {
52
+ console.error('Failed to process example overlay:', error);
53
+ }
54
+ }
55
+ example_overlays.sort((a, b) => a.language.localeCompare(b.language));
56
+ return JSON.stringify(example_overlays);
57
+ }
58
+ }
59
+ exports.default = ExampleOverlay;
@@ -13,22 +13,22 @@ class UnitFraming {
13
13
  this.dynOverlay = dynOverlay;
14
14
  }
15
15
  GetUnits() {
16
- const units = this.dynOverlay.unit_framing_overlay.units;
16
+ const units = this.dynOverlay.units;
17
17
  const canonicalizedUnits = (0, canonical_js_1.default)(units);
18
18
  const sortedUnits = JSON.parse(canonicalizedUnits);
19
19
  return sortedUnits;
20
20
  }
21
21
  GetId() {
22
- return this.dynOverlay.unit_framing_overlay.properties.id;
22
+ return this.dynOverlay.properties.id;
23
23
  }
24
24
  GetLabel() {
25
- return this.dynOverlay.unit_framing_overlay.properties.label;
25
+ return this.dynOverlay.properties.label;
26
26
  }
27
27
  GetLocation() {
28
- return this.dynOverlay.unit_framing_overlay.properties.location;
28
+ return this.dynOverlay.properties.location;
29
29
  }
30
30
  GetVersion() {
31
- return this.dynOverlay.unit_framing_overlay.properties.version;
31
+ return this.dynOverlay.properties.version;
32
32
  }
33
33
  toJSON() {
34
34
  return {
@@ -9,10 +9,10 @@ class Ordering {
9
9
  this.dynOverlay = dynOverlay;
10
10
  }
11
11
  GetAttributeOrdering() {
12
- return this.dynOverlay.ordering_overlay.attribute_ordering;
12
+ return this.dynOverlay.attribute_ordering;
13
13
  }
14
14
  GetEntryCodeOrdering() {
15
- return this.dynOverlay.ordering_overlay.entry_code_ordering;
15
+ return this.dynOverlay.entry_code_ordering;
16
16
  }
17
17
  toJSON() {
18
18
  return {
@@ -13,7 +13,7 @@ class Range {
13
13
  this.dynOverlay = dynOverlay;
14
14
  }
15
15
  GetAttributes() {
16
- const range_overlay_attributes = this.dynOverlay.range_overlay.attributes;
16
+ const range_overlay_attributes = this.dynOverlay.attributes;
17
17
  const canonicalized_attributes = (0, canonical_js_1.default)(range_overlay_attributes);
18
18
  const sortedAttributes = JSON.parse(canonicalized_attributes);
19
19
  return sortedAttributes;
@@ -1,5 +1,6 @@
1
1
  import Ordering from './state/overlays/ordering.js';
2
2
  import UnitFraming from './state/overlays/framing/unit_framing.js';
3
+ import ExampleOverlay from './state/overlays/example.js';
3
4
  import Range from './state/overlays/range.js';
4
5
  import { ocabundleDigest, getOcaBundleFromDeps, getDigest, isOcaBundleWithDeps } from '../utils/helpers.js';
5
6
  import { saidify } from 'saidify';
@@ -34,21 +35,26 @@ export class Overlay {
34
35
  const overlay = {};
35
36
  for (const ov_type in this._overlay) {
36
37
  if (ov_type === 'ordering_overlay') {
37
- const ordering_instance = new Ordering(this._overlay);
38
+ const ordering_instance = new Ordering(this._overlay.ordering_overlay);
38
39
  const ordering_ov = ordering_instance.GenerateOverlay();
39
40
  overlay['ordering'] = JSON.parse(ordering_ov);
40
41
  }
41
42
  else if (ov_type === 'unit_framing_overlay') {
42
- const unit_framing_instance = new UnitFraming(this._overlay);
43
+ const unit_framing_instance = new UnitFraming(this._overlay.unit_framing_overlay);
43
44
  const unit_framing_ov = unit_framing_instance.GenerateOverlay();
44
45
  overlay['unit_framing'] = JSON.parse(unit_framing_ov);
45
46
  }
46
47
  else if (ov_type === 'range_overlay') {
47
- const range_instance = new Range(this._overlay);
48
+ const range_instance = new Range(this._overlay.range_overlay);
48
49
  const range_ov = range_instance.GenerateOverlay();
49
50
  overlay['range'] = JSON.parse(range_ov);
50
51
  }
52
+ else if (ov_type === 'example_overlay') {
53
+ const example_ov = ExampleOverlay.GenerateOverlay(this._overlay.example_overlay);
54
+ overlay['example'] = JSON.parse(example_ov);
55
+ }
51
56
  else {
57
+ // throwing an error as all extension overlays authored by adc should be handled by the overlay class
52
58
  throw new Error('Invalid overlay name');
53
59
  }
54
60
  }
@@ -72,7 +78,7 @@ class ADCOverlayStrategy {
72
78
  // To implement overlays for external communities, create a new class that implements the OverlayStrategy interface.
73
79
  // For example, if you have a community called "external_community", you can create a class like this:
74
80
  class DefaultOverlayStrategy {
75
- GenerateOverlay(extensions) {
81
+ GenerateOverlay(_extensions) {
76
82
  throw new Error('Unsupported community type');
77
83
  }
78
84
  }
@@ -0,0 +1,54 @@
1
+ import { saidify } from 'saidify';
2
+ import canonicalize from '../../../utils/canonical.js';
3
+ class ExampleOverlay {
4
+ constructor(dynOverlay) {
5
+ if (!dynOverlay) {
6
+ throw new Error('A dynamic extension overlay is required');
7
+ }
8
+ this.dynOverlay = dynOverlay;
9
+ }
10
+ get language() {
11
+ return this.dynOverlay.language;
12
+ }
13
+ GetAttributeExamples() {
14
+ const examples = this.dynOverlay.attribute_examples;
15
+ const canonicalizedExamples = canonicalize(examples);
16
+ const sortedExamples = JSON.parse(canonicalizedExamples);
17
+ return sortedExamples;
18
+ }
19
+ toJSON() {
20
+ return {
21
+ d: '',
22
+ type: 'community/overlays/adc/example/1.1',
23
+ language: this.language,
24
+ attribute_examples: this.GetAttributeExamples(),
25
+ };
26
+ }
27
+ Saidifying() {
28
+ const [, sad] = saidify(this.toJSON());
29
+ return sad;
30
+ }
31
+ // generates a single example overlay
32
+ GenerateExampleOverlay() {
33
+ return JSON.stringify(this.Saidifying());
34
+ }
35
+ static GenerateOverlay(dynOverlay) {
36
+ if (!dynOverlay || typeof dynOverlay !== 'object' || !Array.isArray(dynOverlay['example_overlays'])) {
37
+ throw new Error('Invalid dynOverlay structure. Expected an object with an "example_overlays" array.');
38
+ }
39
+ const example_overlays = [];
40
+ const overlays = dynOverlay['example_overlays'];
41
+ for (let example_ov of overlays) {
42
+ try {
43
+ const example_overlay = new ExampleOverlay(example_ov);
44
+ example_overlays.push(JSON.parse(example_overlay.GenerateExampleOverlay()));
45
+ }
46
+ catch (error) {
47
+ console.error('Failed to process example overlay:', error);
48
+ }
49
+ }
50
+ example_overlays.sort((a, b) => a.language.localeCompare(b.language));
51
+ return JSON.stringify(example_overlays);
52
+ }
53
+ }
54
+ export default ExampleOverlay;
@@ -8,22 +8,22 @@ class UnitFraming {
8
8
  this.dynOverlay = dynOverlay;
9
9
  }
10
10
  GetUnits() {
11
- const units = this.dynOverlay.unit_framing_overlay.units;
11
+ const units = this.dynOverlay.units;
12
12
  const canonicalizedUnits = canonicalize(units);
13
13
  const sortedUnits = JSON.parse(canonicalizedUnits);
14
14
  return sortedUnits;
15
15
  }
16
16
  GetId() {
17
- return this.dynOverlay.unit_framing_overlay.properties.id;
17
+ return this.dynOverlay.properties.id;
18
18
  }
19
19
  GetLabel() {
20
- return this.dynOverlay.unit_framing_overlay.properties.label;
20
+ return this.dynOverlay.properties.label;
21
21
  }
22
22
  GetLocation() {
23
- return this.dynOverlay.unit_framing_overlay.properties.location;
23
+ return this.dynOverlay.properties.location;
24
24
  }
25
25
  GetVersion() {
26
- return this.dynOverlay.unit_framing_overlay.properties.version;
26
+ return this.dynOverlay.properties.version;
27
27
  }
28
28
  toJSON() {
29
29
  return {
@@ -7,10 +7,10 @@ class Ordering {
7
7
  this.dynOverlay = dynOverlay;
8
8
  }
9
9
  GetAttributeOrdering() {
10
- return this.dynOverlay.ordering_overlay.attribute_ordering;
10
+ return this.dynOverlay.attribute_ordering;
11
11
  }
12
12
  GetEntryCodeOrdering() {
13
- return this.dynOverlay.ordering_overlay.entry_code_ordering;
13
+ return this.dynOverlay.entry_code_ordering;
14
14
  }
15
15
  toJSON() {
16
16
  return {
@@ -8,7 +8,7 @@ class Range {
8
8
  this.dynOverlay = dynOverlay;
9
9
  }
10
10
  GetAttributes() {
11
- const range_overlay_attributes = this.dynOverlay.range_overlay.attributes;
11
+ const range_overlay_attributes = this.dynOverlay.attributes;
12
12
  const canonicalized_attributes = canonicalize(range_overlay_attributes);
13
13
  const sortedAttributes = JSON.parse(canonicalized_attributes);
14
14
  return sortedAttributes;
@@ -1 +1 @@
1
- {"version":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,GAAG,CAAC;KACpB,CAAC;CACH;AAED,qBAAa,OAAQ,YAAW,UAAU;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;gBAEP,iBAAiB,EAAE,UAAU;IAIlC,eAAe,IAAI,QAAQ,CAAC,UAAU,CAAC;CA0B/C;AAiFD,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,IAAI,CAAC;IACR,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,SAAU,YAAW,UAAU;IAC1C,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAM;IACf,UAAU,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,QAAQ,KAAM;gBAEX,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM;IAU5D,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,UAAU;IAKX,iBAAiB,IAAI,GAAG;CAGhC;AAED,KAAK,gBAAgB,GAAG;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;CAAE,CAAC;AAE9F,cAAM,YAAY;IACT,eAAe,EAAE,gBAAgB,CAAC;IAClC,WAAW,EAAE,GAAG,CAAC;IACjB,eAAe,EAAE,cAAc,CAAC;gBAE3B,oBAAoB,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG;IAMrE,IAAW,kBAAkB,IAAI,gBAAgB,CA4BhD;CACF;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { DynOverlay } from '../../extensions.js';
2
+ export interface IExampleOverlay {
3
+ dynOverlay: DynOverlay;
4
+ GenerateExampleOverlay(): string;
5
+ }
6
+ declare class ExampleOverlay implements IExampleOverlay {
7
+ dynOverlay: DynOverlay;
8
+ constructor(dynOverlay: DynOverlay);
9
+ get language(): any;
10
+ private GetAttributeExamples;
11
+ private toJSON;
12
+ private Saidifying;
13
+ GenerateExampleOverlay(): string;
14
+ static GenerateOverlay(dynOverlay: {
15
+ example_overlays: any[];
16
+ }): string;
17
+ }
18
+ export default ExampleOverlay;
19
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../../../../src/oca_extensions/state/overlays/example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAIjD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,sBAAsB,IAAI,MAAM,CAAC;CAClC;AAED,cAAM,cAAe,YAAW,eAAe;IACtC,UAAU,EAAE,UAAU,CAAC;gBAElB,UAAU,EAAE,UAAU;IAOlC,IAAW,QAAQ,IAAI,GAAG,CAEzB;IAED,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,UAAU;IAMX,sBAAsB,IAAI,MAAM;WAIzB,eAAe,CAAC,UAAU,EAAE;QAAE,gBAAgB,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,MAAM;CAqB/E;AAED,eAAe,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oca_package",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "The wrapper of OCA bundle to generate OCA Package at ADC",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",