@atomic-ehr/codegen 0.0.1-canary.20251010120621.05ce13f → 0.0.1-canary.20251010140912.b42d372
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/dist/cli/index.js +20 -20
- package/dist/index.js +22 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5319,12 +5319,20 @@ var tsResourceName = (id) => {
|
|
|
5319
5319
|
}
|
|
5320
5320
|
return normalizeTsName(id.name);
|
|
5321
5321
|
};
|
|
5322
|
-
var
|
|
5322
|
+
var tsKeywords = /* @__PURE__ */ new Set(["class", "function", "return", "if", "for", "while", "const", "let", "var", "import", "export", "interface"]);
|
|
5323
|
+
var tsFieldName = (n) => {
|
|
5324
|
+
if (tsKeywords.has(n)) return `"${n}"`;
|
|
5325
|
+
if (n.includes(" ") || n.includes("-")) return `"${n}"`;
|
|
5326
|
+
return n;
|
|
5327
|
+
};
|
|
5323
5328
|
var normalizeTsName = (n) => {
|
|
5324
|
-
const tsKeywords = /* @__PURE__ */ new Set(["abstract", "any", "as", "async", "await", "boolean", "bigint", "break", "case", "catch", "class", "const", "constructor", "continue", "debugger", "declare", "default", "delete", "do", "else", "enum", "export", "extends", "extern", "false", "finally", "for", "function", "from", "get", "goto", "if", "implements", "import", "in", "infer", "instanceof", "interface", "keyof", "let", "module", "namespace", "never", "new", "null", "number", "object", "of", "override", "private", "protected", "public", "readonly", "return", "satisfies", "set", "static", "string", "super", "switch", "this", "throw", "true", "try", "type", "typeof", "unknown", "var", "void", "while"]);
|
|
5325
5329
|
if (tsKeywords.has(n)) n = `${n}_`;
|
|
5326
5330
|
return n.replace(/[- ]/g, "_");
|
|
5327
5331
|
};
|
|
5332
|
+
var tsGet = (object, tsFieldName2) => {
|
|
5333
|
+
if (tsFieldName2.startsWith('"')) return `${object}[${tsFieldName2}]`;
|
|
5334
|
+
return `${object}.${tsFieldName2}`;
|
|
5335
|
+
};
|
|
5328
5336
|
var TypeScript = class extends Writer {
|
|
5329
5337
|
tsImportType(tsPackageName, ...entities) {
|
|
5330
5338
|
this.lineSM(`import type { ${entities.join(", ")} } from "${tsPackageName}"`);
|
|
@@ -5388,7 +5396,8 @@ var TypeScript = class extends Writer {
|
|
|
5388
5396
|
}
|
|
5389
5397
|
addFieldExtension(fieldName, field) {
|
|
5390
5398
|
if (field.type.kind === "primitive-type") {
|
|
5391
|
-
|
|
5399
|
+
const extFieldName = tsFieldName(`_${fieldName}`);
|
|
5400
|
+
this.lineSM(`${extFieldName}?: Element`);
|
|
5392
5401
|
}
|
|
5393
5402
|
}
|
|
5394
5403
|
generateType(tsIndex, schema) {
|
|
@@ -5513,7 +5522,7 @@ var TypeScript = class extends Writer {
|
|
|
5513
5522
|
this.line(`profile: ['${flatProfile.identifier.url}']`);
|
|
5514
5523
|
}, [","]);
|
|
5515
5524
|
profileFields.forEach((fieldName) => {
|
|
5516
|
-
this.line(`${fieldName}
|
|
5525
|
+
this.line(`${fieldName}: ${tsGet("profile", fieldName)},`);
|
|
5517
5526
|
});
|
|
5518
5527
|
});
|
|
5519
5528
|
}
|
|
@@ -5544,7 +5553,7 @@ var TypeScript = class extends Writer {
|
|
|
5544
5553
|
if (!isNotChoiceDeclarationField(pField) || !isNotChoiceDeclarationField(rField)) return;
|
|
5545
5554
|
if (pField.required && !rField.required) {
|
|
5546
5555
|
this.curlyBlock(
|
|
5547
|
-
[`if (resource
|
|
5556
|
+
[`if (${tsGet("resource", tsField)} === undefined)`],
|
|
5548
5557
|
() => this.lineSM(
|
|
5549
5558
|
`throw new Error("'${tsField}' is required for ${flatProfile.identifier.url}")`
|
|
5550
5559
|
)
|
|
@@ -5563,11 +5572,11 @@ var TypeScript = class extends Writer {
|
|
|
5563
5572
|
this.line(";");
|
|
5564
5573
|
});
|
|
5565
5574
|
});
|
|
5566
|
-
let cond = !pField?.required ?
|
|
5575
|
+
let cond = !pField?.required ? `!${tsGet("resource", tsField)} || ` : "";
|
|
5567
5576
|
if (pField.array) {
|
|
5568
|
-
cond +=
|
|
5577
|
+
cond += `${tsGet("resource", tsField)}.every( (ref) => ${predName}(ref) )`;
|
|
5569
5578
|
} else {
|
|
5570
|
-
cond += `!${predName}(resource
|
|
5579
|
+
cond += `!${predName}(${tsGet("resource", tsField)})`;
|
|
5571
5580
|
}
|
|
5572
5581
|
this.curlyBlock(["if (", cond, ")"], () => {
|
|
5573
5582
|
this.lineSM(
|
|
@@ -5583,9 +5592,12 @@ var TypeScript = class extends Writer {
|
|
|
5583
5592
|
profileFields.forEach((fieldName) => {
|
|
5584
5593
|
const tsField = tsFieldName(fieldName);
|
|
5585
5594
|
if (shouldCast[fieldName]) {
|
|
5586
|
-
this.line(
|
|
5595
|
+
this.line(
|
|
5596
|
+
`${tsField}:`,
|
|
5597
|
+
`${tsGet("resource", tsField)} as ${tsProfileName}['${tsField}'],`
|
|
5598
|
+
);
|
|
5587
5599
|
} else {
|
|
5588
|
-
this.line(`${tsField}:`,
|
|
5600
|
+
this.line(`${tsField}:`, `${tsGet("resource", tsField)},`);
|
|
5589
5601
|
}
|
|
5590
5602
|
});
|
|
5591
5603
|
});
|