@fhirust/sdk 0.2.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 (87) hide show
  1. package/dist/bin/cli.d.ts +10 -0
  2. package/dist/bin/cli.d.ts.map +1 -0
  3. package/dist/bin/cli.js +217 -0
  4. package/dist/bin/cli.js.map +1 -0
  5. package/dist/events.d.ts +18 -0
  6. package/dist/events.d.ts.map +1 -0
  7. package/dist/events.js +22 -0
  8. package/dist/events.js.map +1 -0
  9. package/dist/fhir-client.d.ts +80 -0
  10. package/dist/fhir-client.d.ts.map +1 -0
  11. package/dist/fhir-client.js +65 -0
  12. package/dist/fhir-client.js.map +1 -0
  13. package/dist/helpers.d.ts +19 -0
  14. package/dist/helpers.d.ts.map +1 -0
  15. package/dist/helpers.js +38 -0
  16. package/dist/helpers.js.map +1 -0
  17. package/dist/http-client.d.ts +63 -0
  18. package/dist/http-client.d.ts.map +1 -0
  19. package/dist/http-client.js +98 -0
  20. package/dist/http-client.js.map +1 -0
  21. package/dist/index.d.ts +27 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +28 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/logger.d.ts +22 -0
  26. package/dist/logger.d.ts.map +1 -0
  27. package/dist/logger.js +27 -0
  28. package/dist/logger.js.map +1 -0
  29. package/dist/plugin.d.ts +70 -0
  30. package/dist/plugin.d.ts.map +1 -0
  31. package/dist/plugin.js +219 -0
  32. package/dist/plugin.js.map +1 -0
  33. package/dist/r4/allergy-intolerance.d.ts +37 -0
  34. package/dist/r4/allergy-intolerance.d.ts.map +1 -0
  35. package/dist/r4/allergy-intolerance.js +2 -0
  36. package/dist/r4/allergy-intolerance.js.map +1 -0
  37. package/dist/r4/common.d.ts +148 -0
  38. package/dist/r4/common.d.ts.map +1 -0
  39. package/dist/r4/common.js +5 -0
  40. package/dist/r4/common.js.map +1 -0
  41. package/dist/r4/condition.d.ts +42 -0
  42. package/dist/r4/condition.d.ts.map +1 -0
  43. package/dist/r4/condition.js +2 -0
  44. package/dist/r4/condition.js.map +1 -0
  45. package/dist/r4/diagnostic-report.d.ts +31 -0
  46. package/dist/r4/diagnostic-report.d.ts.map +1 -0
  47. package/dist/r4/diagnostic-report.js +2 -0
  48. package/dist/r4/diagnostic-report.js.map +1 -0
  49. package/dist/r4/encounter.d.ts +66 -0
  50. package/dist/r4/encounter.d.ts.map +1 -0
  51. package/dist/r4/encounter.js +2 -0
  52. package/dist/r4/encounter.js.map +1 -0
  53. package/dist/r4/index.d.ts +19 -0
  54. package/dist/r4/index.d.ts.map +1 -0
  55. package/dist/r4/index.js +9 -0
  56. package/dist/r4/index.js.map +1 -0
  57. package/dist/r4/medication-request.d.ts +54 -0
  58. package/dist/r4/medication-request.d.ts.map +1 -0
  59. package/dist/r4/medication-request.js +2 -0
  60. package/dist/r4/medication-request.js.map +1 -0
  61. package/dist/r4/observation.d.ts +65 -0
  62. package/dist/r4/observation.d.ts.map +1 -0
  63. package/dist/r4/observation.js +2 -0
  64. package/dist/r4/observation.js.map +1 -0
  65. package/dist/r4/organization.d.ts +24 -0
  66. package/dist/r4/organization.d.ts.map +1 -0
  67. package/dist/r4/organization.js +2 -0
  68. package/dist/r4/organization.js.map +1 -0
  69. package/dist/r4/patient.d.ts +43 -0
  70. package/dist/r4/patient.d.ts.map +1 -0
  71. package/dist/r4/patient.js +2 -0
  72. package/dist/r4/patient.js.map +1 -0
  73. package/dist/r4/practitioner.d.ts +24 -0
  74. package/dist/r4/practitioner.d.ts.map +1 -0
  75. package/dist/r4/practitioner.js +2 -0
  76. package/dist/r4/practitioner.js.map +1 -0
  77. package/dist/r4/procedure.d.ts +42 -0
  78. package/dist/r4/procedure.d.ts.map +1 -0
  79. package/dist/r4/procedure.js +2 -0
  80. package/dist/r4/procedure.js.map +1 -0
  81. package/dist/types.d.ts +99 -0
  82. package/dist/types.d.ts.map +1 -0
  83. package/dist/types.js +30 -0
  84. package/dist/types.js.map +1 -0
  85. package/package.json +53 -0
  86. package/wit/plugin.wit +114 -0
  87. package/wit/world.wit +12 -0
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * FHIRust SDK CLI
4
+ *
5
+ * Commands:
6
+ * fhirust-sdk init <name> — Scaffold a new plugin project
7
+ * fhirust-sdk build — Build plugin to WASM
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG"}
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * FHIRust SDK CLI
4
+ *
5
+ * Commands:
6
+ * fhirust-sdk init <name> — Scaffold a new plugin project
7
+ * fhirust-sdk build — Build plugin to WASM
8
+ */
9
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
10
+ import { resolve, dirname, join } from "node:path";
11
+ import { execSync } from "node:child_process";
12
+ import { fileURLToPath } from "node:url";
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = dirname(__filename);
15
+ // SDK package root (one level up from dist/bin/)
16
+ const SDK_ROOT = resolve(__dirname, "..", "..");
17
+ function main() {
18
+ const args = process.argv.slice(2);
19
+ const command = args[0];
20
+ switch (command) {
21
+ case "init":
22
+ return cmdInit(args.slice(1));
23
+ case "build":
24
+ return cmdBuild(args.slice(1));
25
+ case "help":
26
+ case "--help":
27
+ case "-h":
28
+ return cmdHelp();
29
+ default:
30
+ console.error(`Unknown command: ${command ?? "(none)"}`);
31
+ cmdHelp();
32
+ process.exit(1);
33
+ }
34
+ }
35
+ function cmdHelp() {
36
+ console.log(`
37
+ fhirust-sdk — Build FHIRust WASM plugins in TypeScript
38
+
39
+ Commands:
40
+ init <name> Scaffold a new plugin project
41
+ build Compile TypeScript plugin to WASM
42
+ build --output Specify output filename (default: <package-name>.wasm)
43
+
44
+ Examples:
45
+ npx @fhirust/sdk init my-plugin
46
+ cd my-plugin && npm install && npx @fhirust/sdk build
47
+ `);
48
+ }
49
+ function cmdInit(args) {
50
+ const name = args[0];
51
+ if (!name) {
52
+ console.error("Usage: fhirust-sdk init <plugin-name>");
53
+ process.exit(1);
54
+ }
55
+ if (existsSync(name)) {
56
+ console.error(`Directory "${name}" already exists`);
57
+ process.exit(1);
58
+ }
59
+ console.log(`Creating plugin: ${name}`);
60
+ // Create directory structure
61
+ mkdirSync(join(name, "src"), { recursive: true });
62
+ // package.json
63
+ const packageJson = {
64
+ name: name,
65
+ version: "1.0.0",
66
+ description: `FHIRust plugin: ${name}`,
67
+ type: "module",
68
+ scripts: {
69
+ build: "fhirust-sdk build",
70
+ },
71
+ devDependencies: {
72
+ "@fhirust/sdk": "^0.2.0",
73
+ "@bytecodealliance/componentize-js": "^0.14.0",
74
+ esbuild: "^0.24.0",
75
+ typescript: "^5.5.0",
76
+ },
77
+ };
78
+ writeFileSync(join(name, "package.json"), JSON.stringify(packageJson, null, 2) + "\n");
79
+ // tsconfig.json
80
+ const tsconfig = {
81
+ compilerOptions: {
82
+ target: "ES2022",
83
+ module: "ES2022",
84
+ moduleResolution: "bundler",
85
+ strict: true,
86
+ outDir: "./dist",
87
+ rootDir: "./src",
88
+ skipLibCheck: true,
89
+ esModuleInterop: true,
90
+ },
91
+ include: ["src/**/*"],
92
+ };
93
+ writeFileSync(join(name, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n");
94
+ // src/index.ts — starter template
95
+ const indexTs = `import { FhirPlugin, reject } from "@fhirust/sdk";
96
+ import type { Patient } from "@fhirust/sdk/r4";
97
+
98
+ const plugin = new FhirPlugin("${name}", "1.0.0");
99
+
100
+ plugin.beforeCreate<Patient>("Patient", (patient, ctx) => {
101
+ plugin.log.info(\`Processing Patient create, request: \${ctx.requestId}\`);
102
+
103
+ // Add your validation logic here:
104
+ // if (!patient.name?.length) {
105
+ // return reject("Patient must have at least one name");
106
+ // }
107
+
108
+ return patient;
109
+ });
110
+
111
+ export const { lifecycle, hooks } = plugin.exports();
112
+ `;
113
+ writeFileSync(join(name, "src", "index.ts"), indexTs);
114
+ console.log(`
115
+ Plugin "${name}" created.
116
+
117
+ Next steps:
118
+ cd ${name}
119
+ npm install
120
+ npx fhirust-sdk build
121
+ `);
122
+ }
123
+ function cmdBuild(args) {
124
+ // Parse --output flag
125
+ let outputName;
126
+ for (let i = 0; i < args.length; i++) {
127
+ if (args[i] === "--output" || args[i] === "-o") {
128
+ outputName = args[i + 1];
129
+ i++;
130
+ }
131
+ }
132
+ // Read package.json for default output name
133
+ const pkgPath = resolve("package.json");
134
+ if (!existsSync(pkgPath)) {
135
+ console.error("No package.json found. Run this command from your plugin directory.");
136
+ process.exit(1);
137
+ }
138
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
139
+ const pluginName = outputName ?? `${pkg.name.replace(/^@.*\//, "")}.wasm`;
140
+ // Find WIT files — look in SDK package first, then local wit/ directory
141
+ let witPath = resolve("wit");
142
+ const sdkWitPath = join(SDK_ROOT, "wit");
143
+ if (existsSync(join(sdkWitPath, "plugin.wit"))) {
144
+ witPath = sdkWitPath;
145
+ }
146
+ if (!existsSync(join(witPath, "plugin.wit"))) {
147
+ console.error("WIT files not found. Ensure @fhirust/sdk is installed or create a local wit/ directory.");
148
+ process.exit(1);
149
+ }
150
+ console.log(`Building ${pluginName}...`);
151
+ // Step 1: Compile TypeScript
152
+ console.log(" Compiling TypeScript...");
153
+ try {
154
+ execSync("npx tsc", { stdio: "inherit" });
155
+ }
156
+ catch {
157
+ console.error("TypeScript compilation failed");
158
+ process.exit(1);
159
+ }
160
+ // Step 2: Bundle all imports into a single file
161
+ // componentize-js runs inside WASM and can't resolve node_modules imports.
162
+ // esbuild bundles everything into one self-contained JS file.
163
+ console.log(" Bundling...");
164
+ const entryPoint = resolve("dist", "index.js");
165
+ if (!existsSync(entryPoint)) {
166
+ console.error(`Entry point not found: ${entryPoint}`);
167
+ process.exit(1);
168
+ }
169
+ const bundledFile = resolve("dist", "bundle.js");
170
+ try {
171
+ execSync(`npx esbuild ${entryPoint} --bundle --format=esm --outfile=${bundledFile}`, { stdio: "inherit" });
172
+ }
173
+ catch {
174
+ console.error("Bundling failed");
175
+ process.exit(1);
176
+ }
177
+ // Step 3: Componentize to WASM
178
+ // componentize-js is a library API — invoke via a temp Node.js script
179
+ console.log(" Componentizing to WASM...");
180
+ const tmpScript = resolve("_fhirust_build.mjs");
181
+ const buildScript = [
182
+ `import { componentize } from '@bytecodealliance/componentize-js';`,
183
+ `import { readFile, writeFile } from 'node:fs/promises';`,
184
+ ``,
185
+ `const source = await readFile(${JSON.stringify(bundledFile)}, 'utf-8');`,
186
+ ``,
187
+ `const { component } = await componentize(source, {`,
188
+ ` witPath: ${JSON.stringify(witPath)},`,
189
+ ` worldName: 'fhir-plugin',`,
190
+ `});`,
191
+ ``,
192
+ `await writeFile(${JSON.stringify(pluginName)}, component);`,
193
+ `console.log(' WASM component written: ${pluginName}');`,
194
+ ].join("\n");
195
+ writeFileSync(tmpScript, buildScript);
196
+ try {
197
+ execSync(`node ${tmpScript}`, { stdio: "inherit" });
198
+ }
199
+ catch {
200
+ console.error("WASM componentization failed");
201
+ process.exit(1);
202
+ }
203
+ finally {
204
+ try {
205
+ unlinkSync(tmpScript);
206
+ }
207
+ catch { }
208
+ try {
209
+ unlinkSync(bundledFile);
210
+ }
211
+ catch { }
212
+ }
213
+ console.log(`\nBuilt: ${pluginName}`);
214
+ console.log(`Deploy: cp ${pluginName} /path/to/fhirust/plugins/`);
215
+ }
216
+ main();
217
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAA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C,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,UAAU,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,cAAc,UAAU,4BAA4B,CAAC,CAAC;AACpE,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Typed wrapper around the WIT utils.emitEvent function.
3
+ *
4
+ * Usage inside hooks:
5
+ * plugin.events.emit("patient-created", { id: patient.id });
6
+ */
7
+ import type { WitUtils } from "./logger.js";
8
+ export declare class EventEmitter {
9
+ private utils;
10
+ /** @internal Called by FhirPlugin to inject WIT bindings */
11
+ _bind(utils: WitUtils): void;
12
+ /**
13
+ * Emit a fire-and-forget event.
14
+ * Payload is automatically JSON.stringify'd if it's an object.
15
+ */
16
+ emit(eventType: string, payload: any): void;
17
+ }
18
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAyB;IAEtC,4DAA4D;IAC5D,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI5B;;;OAGG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;CAI5C"}
package/dist/events.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Typed wrapper around the WIT utils.emitEvent function.
3
+ *
4
+ * Usage inside hooks:
5
+ * plugin.events.emit("patient-created", { id: patient.id });
6
+ */
7
+ export class EventEmitter {
8
+ utils = null;
9
+ /** @internal Called by FhirPlugin to inject WIT bindings */
10
+ _bind(utils) {
11
+ this.utils = utils;
12
+ }
13
+ /**
14
+ * Emit a fire-and-forget event.
15
+ * Payload is automatically JSON.stringify'd if it's an object.
16
+ */
17
+ emit(eventType, payload) {
18
+ const payloadStr = typeof payload === "string" ? payload : JSON.stringify(payload);
19
+ this.utils?.emitEvent(eventType, payloadStr);
20
+ }
21
+ }
22
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,OAAO,YAAY;IACf,KAAK,GAAoB,IAAI,CAAC;IAEtC,4DAA4D;IAC5D,KAAK,CAAC,KAAe;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,SAAiB,EAAE,OAAY;QAClC,MAAM,UAAU,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACnF,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Typed FHIR client wrapper over the WIT fhir import.
3
+ *
4
+ * Handles JSON parse/stringify and error conversion so plugin authors
5
+ * work with plain objects instead of raw strings.
6
+ *
7
+ * Usage inside hooks:
8
+ * const patient = plugin.fhir.read<Patient>("Patient", "123");
9
+ * const bundle = plugin.fhir.search<Observation>("Observation", { subject: "Patient/123" });
10
+ */
11
+ import type { Bundle, OperationOutcome } from "./types.js";
12
+ /** Raw WIT fhir interface */
13
+ export interface WitFhir {
14
+ read(resourceType: string, id: string): {
15
+ tag: "ok";
16
+ val: string;
17
+ } | {
18
+ tag: "err";
19
+ val: {
20
+ json: string;
21
+ };
22
+ };
23
+ search(resourceType: string, params: [string, string][]): {
24
+ tag: "ok";
25
+ val: string;
26
+ } | {
27
+ tag: "err";
28
+ val: {
29
+ json: string;
30
+ };
31
+ };
32
+ create(resourceType: string, resourceJson: string): {
33
+ tag: "ok";
34
+ val: string;
35
+ } | {
36
+ tag: "err";
37
+ val: {
38
+ json: string;
39
+ };
40
+ };
41
+ update(resourceType: string, id: string, resourceJson: string): {
42
+ tag: "ok";
43
+ val: string;
44
+ } | {
45
+ tag: "err";
46
+ val: {
47
+ json: string;
48
+ };
49
+ };
50
+ delete(resourceType: string, id: string): {
51
+ tag: "ok";
52
+ val: boolean;
53
+ } | {
54
+ tag: "err";
55
+ val: {
56
+ json: string;
57
+ };
58
+ };
59
+ }
60
+ export declare class FhirClientError extends Error {
61
+ readonly outcome: OperationOutcome;
62
+ constructor(outcome: OperationOutcome);
63
+ }
64
+ export declare class FhirClient {
65
+ private fhir;
66
+ /** @internal Called by FhirPlugin to inject WIT bindings */
67
+ _bind(fhir: WitFhir): void;
68
+ private ensureBound;
69
+ /** Read a single resource by type and id */
70
+ read<T = any>(resourceType: string, id: string): T;
71
+ /** Search for resources. Returns a parsed Bundle. */
72
+ search<T = any>(resourceType: string, params: Record<string, string>): Bundle<T>;
73
+ /** Create a resource. Returns the created resource with server-assigned id. */
74
+ create<T = any>(resourceType: string, resource: T): T;
75
+ /** Update a resource by id. Returns the updated resource. */
76
+ update<T = any>(resourceType: string, id: string, resource: T): T;
77
+ /** Delete a resource by id. Returns true if deleted. */
78
+ delete(resourceType: string, id: string): boolean;
79
+ }
80
+ //# sourceMappingURL=fhir-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fhir-client.d.ts","sourceRoot":"","sources":["../src/fhir-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE3D,6BAA6B;AAC7B,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,IAAI,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,K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UAAU;IACrB,OAAO,CAAC,IAAI,CAAwB;IAEpC,4DAA4D;IAC5D,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAI1B,OAAO,CAAC,WAAW;IAOnB,4CAA4C;IAC5C,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC;IAKlD,qDAAqD;IACrD,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAMhF,+EAA+E;IAC/E,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAKrD,6DAA6D;IAC7D,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAKjE,wDAAwD;IACxD,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;CAGlD"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Typed FHIR client wrapper over the WIT fhir import.
3
+ *
4
+ * Handles JSON parse/stringify and error conversion so plugin authors
5
+ * work with plain objects instead of raw strings.
6
+ *
7
+ * Usage inside hooks:
8
+ * const patient = plugin.fhir.read<Patient>("Patient", "123");
9
+ * const bundle = plugin.fhir.search<Observation>("Observation", { subject: "Patient/123" });
10
+ */
11
+ export class FhirClientError extends Error {
12
+ outcome;
13
+ constructor(outcome) {
14
+ const diag = outcome.issue?.[0]?.diagnostics ?? "FHIR operation failed";
15
+ super(diag);
16
+ this.name = "FhirClientError";
17
+ this.outcome = outcome;
18
+ }
19
+ }
20
+ function unwrapResult(result) {
21
+ if (result.tag === "err") {
22
+ const outcome = JSON.parse(result.val.json);
23
+ throw new FhirClientError(outcome);
24
+ }
25
+ return result.val;
26
+ }
27
+ export class FhirClient {
28
+ fhir = null;
29
+ /** @internal Called by FhirPlugin to inject WIT bindings */
30
+ _bind(fhir) {
31
+ this.fhir = fhir;
32
+ }
33
+ ensureBound() {
34
+ if (!this.fhir) {
35
+ throw new Error("FHIR client not available — host did not provide fhir bindings");
36
+ }
37
+ return this.fhir;
38
+ }
39
+ /** Read a single resource by type and id */
40
+ read(resourceType, id) {
41
+ const raw = unwrapResult(this.ensureBound().read(resourceType, id));
42
+ return JSON.parse(raw);
43
+ }
44
+ /** Search for resources. Returns a parsed Bundle. */
45
+ search(resourceType, params) {
46
+ const tuples = Object.entries(params);
47
+ const raw = unwrapResult(this.ensureBound().search(resourceType, tuples));
48
+ return JSON.parse(raw);
49
+ }
50
+ /** Create a resource. Returns the created resource with server-assigned id. */
51
+ create(resourceType, resource) {
52
+ const raw = unwrapResult(this.ensureBound().create(resourceType, JSON.stringify(resource)));
53
+ return JSON.parse(raw);
54
+ }
55
+ /** Update a resource by id. Returns the updated resource. */
56
+ update(resourceType, id, resource) {
57
+ const raw = unwrapResult(this.ensureBound().update(resourceType, id, JSON.stringify(resource)));
58
+ return JSON.parse(raw);
59
+ }
60
+ /** Delete a resource by id. Returns true if deleted. */
61
+ delete(resourceType, id) {
62
+ return unwrapResult(this.ensureBound().delete(resourceType, id));
63
+ }
64
+ }
65
+ //# sourceMappingURL=fhir-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fhir-client.js","sourceRoot":"","sources":["../src/fhir-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0BH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,OAAO,CAAmB;IAEnC,YAAY,OAAyB;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,uBAAuB,CAAC;QACxE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CA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+EAA+E;IAC/E,MAAM,CAAU,YAAoB,EAAE,QAAW;QAC/C,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,KAAK,CAAC,GAAa,CAAM,CAAC;IACxC,CAAC;IAED,6DAA6D;IAC7D,MAAM,CAAU,YAAoB,EAAE,EAAU,EAAE,QAAW;QAC3D,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC,KAAK,CAAC,GAAa,CAAM,CAAC;IACxC,CAAC;IAED,wDAAwD;IACxD,MAAM,CAAC,YAAoB,EAAE,EAAU;QACrC,OAAO,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Helper functions for common plugin patterns.
3
+ */
4
+ import { Rejection, type OperationOutcome } from "./types.js";
5
+ /**
6
+ * Create a rejection that stops the FHIR operation with an OperationOutcome.
7
+ *
8
+ * Usage:
9
+ * return reject("Patient must have a name");
10
+ * return reject("Invalid code", "code-invalid");
11
+ * return reject({ resourceType: "OperationOutcome", issue: [...] });
12
+ */
13
+ export declare function reject(messageOrOutcome: string | OperationOutcome, code?: string): Rejection;
14
+ /**
15
+ * Build an OperationOutcome from a simple message.
16
+ * Useful when you need the OperationOutcome object itself (not a Rejection).
17
+ */
18
+ export declare function outcome(severity: "fatal" | "error" | "warning" | "information", code: string, diagnostics: string): OperationOutcome;
19
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAe5F;AAED;;;GAGG;AACH,wBAAgB,OAAO,CACrB,QAAQ,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,EACvD,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,gBAAgB,CAKlB"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Helper functions for common plugin patterns.
3
+ */
4
+ import { Rejection } from "./types.js";
5
+ /**
6
+ * Create a rejection that stops the FHIR operation with an OperationOutcome.
7
+ *
8
+ * Usage:
9
+ * return reject("Patient must have a name");
10
+ * return reject("Invalid code", "code-invalid");
11
+ * return reject({ resourceType: "OperationOutcome", issue: [...] });
12
+ */
13
+ export function reject(messageOrOutcome, code) {
14
+ if (typeof messageOrOutcome === "string") {
15
+ return new Rejection({
16
+ resourceType: "OperationOutcome",
17
+ issue: [
18
+ {
19
+ severity: "error",
20
+ code: code ?? "processing",
21
+ diagnostics: messageOrOutcome,
22
+ },
23
+ ],
24
+ });
25
+ }
26
+ return new Rejection(messageOrOutcome);
27
+ }
28
+ /**
29
+ * Build an OperationOutcome from a simple message.
30
+ * Useful when you need the OperationOutcome object itself (not a Rejection).
31
+ */
32
+ export function outcome(severity, code, diagnostics) {
33
+ return {
34
+ resourceType: "OperationOutcome",
35
+ issue: [{ severity, code, diagnostics }],
36
+ };
37
+ }
38
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,YAAY,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,gBAA2C,EAAE,IAAa;IAC/E,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QACzC,OAAO,IAAI,SAAS,CAAC;YACnB,YAAY,EAAE,kBAAkB;YAChC,KAAK,EAAE;gBACL;oBACE,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,IAAI,IAAI,YAAY;oBAC1B,WAAW,EAAE,gBAAgB;iBAC9B;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CACrB,QAAuD,EACvD,IAAY,EACZ,WAAmB;IAEnB,OAAO;QACL,YAAY,EAAE,kBAAkB;QAChC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Ergonomic HTTP client wrapper over the WIT http.fetch import.
3
+ *
4
+ * Usage inside hooks:
5
+ * const resp = plugin.http.post("https://example.com/webhook", {
6
+ * body: { event: "patient-created", id: "123" },
7
+ * timeout: 3000,
8
+ * });
9
+ * if (resp.ok) { ... }
10
+ */
11
+ /** Raw WIT http interface */
12
+ export interface WitHttp {
13
+ fetch(url: string, method: string, headers: [string, string][], body: string | undefined, timeoutMs: number): {
14
+ tag: "ok";
15
+ val: WitHttpResponse;
16
+ } | {
17
+ tag: "err";
18
+ val: string;
19
+ };
20
+ }
21
+ interface WitHttpResponse {
22
+ status: number;
23
+ headers: [string, string][];
24
+ body: string;
25
+ }
26
+ export interface RequestOptions {
27
+ headers?: Record<string, string>;
28
+ /** Request body. Objects are auto-serialized to JSON. */
29
+ body?: any;
30
+ /** Timeout in milliseconds. Default: 5000. */
31
+ timeout?: number;
32
+ }
33
+ export declare class HttpResponse {
34
+ readonly status: number;
35
+ readonly headers: Record<string, string>;
36
+ readonly body: string;
37
+ constructor(status: number, headers: Record<string, string>, body: string);
38
+ /** True if status is 200-299 */
39
+ get ok(): boolean;
40
+ /** Parse body as JSON */
41
+ json<T = any>(): T;
42
+ }
43
+ export declare class HttpClientError extends Error {
44
+ constructor(message: string);
45
+ }
46
+ export declare class HttpClient {
47
+ private http;
48
+ /** @internal Called by FhirPlugin to inject WIT bindings */
49
+ _bind(http: WitHttp): void;
50
+ private ensureBound;
51
+ private doFetch;
52
+ get(url: string, options?: RequestOptions): HttpResponse;
53
+ post(url: string, options?: RequestOptions): HttpResponse;
54
+ put(url: string, options?: RequestOptions): HttpResponse;
55
+ delete(url: string, options?: RequestOptions): HttpResponse;
56
+ patch(url: string, options?: RequestOptions): HttpResponse;
57
+ /** Raw fetch matching the WIT signature more closely */
58
+ fetch(url: string, options: RequestOptions & {
59
+ method: string;
60
+ }): HttpResponse;
61
+ }
62
+ export {};
63
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6BAA6B;AAC7B,MAAM,WAAW,OAAO;IACtB,KAAK,CACH,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,SAAS,EAAE,MAAM,GAChB;QAAE,GAAG,EAAE,IAAI,CAAC;QAAC,GAAG,EAAE,eAAe,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CACtE;AAED,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC5B,IAAI,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