Skip to content

Commit

Permalink
chore!: update oca.js package to 0.6.0
Browse files Browse the repository at this point in the history
BRAKING CHANGE: order of attributes in OCA Bundle, Capture Base and Overlays has changed
which will lead to a change of SAIDs of the OCA objects generated from the same OCA Files
  • Loading branch information
olichwiruk committed Nov 15, 2024
1 parent b17f9d6 commit 499fe39
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 11 deletions.
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"vitest": "^1.3.1"
},
"dependencies": {
"oca.js": "^0.5.4",
"oca.js": "^0.6.0",
"oca.js044": "npm:oca.js@^0.4.4",
"oca.js054": "npm:oca.js@^0.5.4",
"sugar-date": "^2.0.6"
},
"prettier": {
Expand Down
38 changes: 32 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,42 @@ module.exports.from = async (bundleWithDeps, presentation, conditionals = {}, re
m: {},
}
}
const oca_box = new OCABox().load(bundleWithDeps.bundle)
/** @type { Record<SAID, OCABox> } */
let oca_box
let OCABoxDeps = {}
for (let i = 0; i < bundleWithDeps.dependencies.length; i++) {
const dep = bundleWithDeps.dependencies[i]
if (bundleWithDeps.v) {
if (bundleWithDeps.v.startsWith("OCAA11")) {
oca_box = new OCABox().load(bundleWithDeps.bundle)
/** @type { Record<SAID, OCABox> } */
for (let i = 0; i < bundleWithDeps.dependencies.length; i++) {
const dep = bundleWithDeps.dependencies[i]
OCABoxDeps[dep.d] = new OCABox().load(dep)
}
} else if (bundleWithDeps.v.startsWith("OCAA10")) {
const { OCABox } = require("oca.js054")
oca_box = new OCABox().load(bundleWithDeps.bundle)
/** @type { Record<SAID, OCABox> } */
for (let i = 0; i < bundleWithDeps.dependencies.length; i++) {
const dep = bundleWithDeps.dependencies[i]
OCABoxDeps[dep.d] = new OCABox().load(dep)
}
}
} else {
const { OCABox } = require("oca.js054")
try {
OCABoxDeps[dep.d] = new OCABox().load(dep)
oca_box = new OCABox().load(bundleWithDeps.bundle)
} catch (e) {
const { OCABox } = require("oca.js044")
OCABoxDeps[dep.d] = new OCABox().load(dep)
oca_box = new OCABox().load(bundleWithDeps.bundle)
}
/** @type { Record<SAID, OCABox> } */
for (let i = 0; i < bundleWithDeps.dependencies.length; i++) {
const dep = bundleWithDeps.dependencies[i]
try {
OCABoxDeps[dep.d] = new OCABox().load(dep)
} catch (e) {
const { OCABox } = require("oca.js044")
OCABoxDeps[dep.d] = new OCABox().load(dep)
}
}
}
/** @type { Record<string, SAID> } */
Expand Down
66 changes: 66 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,72 @@ ADD LABEL en ATTRS multi="Multi"
})
})
})

describe("backward compatibility", () => {
describe("based on version", () => {
test("OCAA10", async () => {
const bundle = require("../tests/fixtures/oca-1.0.json")
const pres = {
v: "1.0.0",
bd: bundle.bundle.d,
l: ["eng"],
d: "EK0T5StXlcYwIhfp_wJxhIpYwYpEnMhHwnKbHnodhxFU",
p: [{ ns: "page 1", ao: ["d"] }],
po: ["page 1"],
pl: {
eng: {
"page 1": "First page",
},
},
i: [],
}
const result = await from(bundle, pres, {})
expect(result.form.pages[0].fields[0].field.type).toBe("text")
})

test("OCAA11", async () => {
const bundle = require("../tests/fixtures/oca-1.1.json")
const pres = {
v: "1.0.0",
bd: bundle.bundle.d,
l: ["eng"],
d: "EK0T5StXlcYwIhfp_wJxhIpYwYpEnMhHwnKbHnodhxFU",
p: [{ ns: "page 1", ao: ["d"] }],
po: ["page 1"],
pl: {
eng: {
"page 1": "First page",
},
},
i: [],
}
const result = await from(bundle, pres, {})
expect(result.form.pages[0].fields[0].field.type).toBe("text")
})
})

describe("no version", () => {
test("new unit overlay", async () => {
const bundle = require("../tests/fixtures/oca-0.1.json")
const pres = {
v: "1.0.0",
bd: bundle.bundle.d,
l: ["eng"],
d: "EK0T5StXlcYwIhfp_wJxhIpYwYpEnMhHwnKbHnodhxFU",
p: [{ ns: "page 1", ao: ["d"] }],
po: ["page 1"],
pl: {
eng: {
"page 1": "First page",
},
},
i: [],
}
const result = await from(bundle, pres, {})
expect(result.form.pages[0].fields[0].field.type).toBe("text")
})
})
})
})

expect.extend({
Expand Down
78 changes: 78 additions & 0 deletions tests/fixtures/oca-0.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"bundle": {
"v": "OCAM10JSON000646_",
"d": "EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs",
"capture_base": {
"d": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"type": "spec/capture_base/1.0",
"classification": "",
"attributes": {
"d": "Text",
"i": "Text",
"passed": "Boolean"
},
"flagged_attributes": []
},
"overlays": {
"character_encoding": {
"d": "EOFWz7wYV2aQZzFRZf5_7hGoYOE3TeHl_iHoIsTQHX7h",
"type": "spec/overlays/character_encoding/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_character_encoding": {
"d": "utf-8",
"i": "utf-8",
"passed": "utf-8"
}
},
"meta": [
{
"d": "ELHseD741CQMbFp49of8qNjgdyKd9gubDvcAjIqCVQKw",
"language": "eng",
"type": "spec/overlays/meta/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"description": "Entrance credential",
"name": "Entrance credential"
}
],
"label": [
{
"d": "EHAJTB4yLtruZC6fmfCwlGmUDtlkIHrjTNOwrlvkmAtP",
"language": "eng",
"type": "spec/overlays/label/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_labels": {
"d": "Schema digest",
"i": "Credential Issuee",
"passed": "Passed"
},
"attribute_categories": [],
"category_labels": {}
}
],
"information": [
{
"d": "ELTfO1LCWrM8FlwW1JliyM2DgiH04vjipN0d6uKej_Md",
"language": "eng",
"type": "spec/overlays/information/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_information": {
"d": "Schema digest",
"i": "Credential Issuee",
"passed": "Enables or disables passing"
}
}
],
"conformance": {
"d": "EKzjcqJuiOKTVeSMRYNZsWnUsmnEiyv-8Uj1knydBfbU",
"type": "spec/overlays/conformance/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_conformance": {
"d": "M",
"i": "M",
"passed": "M"
}
}
}
},
"dependencies": []
}
79 changes: 79 additions & 0 deletions tests/fixtures/oca-1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"v": "OCAA10JSON000663_",
"bundle": {
"v": "OCAM10JSON000646_",
"d": "EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs",
"capture_base": {
"d": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"type": "spec/capture_base/1.0",
"classification": "",
"attributes": {
"d": "Text",
"i": "Text",
"passed": "Boolean"
},
"flagged_attributes": []
},
"overlays": {
"character_encoding": {
"d": "EOFWz7wYV2aQZzFRZf5_7hGoYOE3TeHl_iHoIsTQHX7h",
"type": "spec/overlays/character_encoding/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_character_encoding": {
"d": "utf-8",
"i": "utf-8",
"passed": "utf-8"
}
},
"meta": [
{
"d": "ELHseD741CQMbFp49of8qNjgdyKd9gubDvcAjIqCVQKw",
"language": "eng",
"type": "spec/overlays/meta/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"description": "Entrance credential",
"name": "Entrance credential"
}
],
"label": [
{
"d": "EHAJTB4yLtruZC6fmfCwlGmUDtlkIHrjTNOwrlvkmAtP",
"language": "eng",
"type": "spec/overlays/label/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_labels": {
"d": "Schema digest",
"i": "Credential Issuee",
"passed": "Passed"
},
"attribute_categories": [],
"category_labels": {}
}
],
"information": [
{
"d": "ELTfO1LCWrM8FlwW1JliyM2DgiH04vjipN0d6uKej_Md",
"language": "eng",
"type": "spec/overlays/information/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_information": {
"d": "Schema digest",
"i": "Credential Issuee",
"passed": "Enables or disables passing"
}
}
],
"conformance": {
"d": "EKzjcqJuiOKTVeSMRYNZsWnUsmnEiyv-8Uj1knydBfbU",
"type": "spec/overlays/conformance/1.0",
"capture_base": "EL4q2aahA0RN-ftw97E_fmbVDVTyDbIaQR2B44HGsqFG",
"attribute_conformance": {
"d": "M",
"i": "M",
"passed": "M"
}
}
}
},
"dependencies": []
}
Loading

0 comments on commit 499fe39

Please sign in to comment.