fhir-persistence 0.3.0 → 0.4.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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/cjs/index.cjs +104 -43
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/index.d.ts +16 -5
- package/dist/esm/index.d.ts +16 -5
- package/dist/esm/index.mjs +104 -43
- package/dist/esm/index.mjs.map +2 -2
- package/dist/index.d.ts +16 -5
- package/dist/lib/migration/reindex-scheduler.d.ts +3 -1
- package/dist/lib/migration/reindex-scheduler.d.ts.map +1 -1
- package/dist/lib/migrations/migration-runner.d.ts +3 -1
- package/dist/lib/migrations/migration-runner.d.ts.map +1 -1
- package/dist/lib/registry/package-registry-repo.d.ts +7 -1
- package/dist/lib/registry/package-registry-repo.d.ts.map +1 -1
- package/dist/lib/repo/indexing-pipeline.d.ts +3 -0
- package/dist/lib/repo/indexing-pipeline.d.ts.map +1 -1
- package/dist/lib/repo/lookup-table-writer.d.ts +3 -1
- package/dist/lib/repo/lookup-table-writer.d.ts.map +1 -1
- package/dist/lib/startup/fhir-system.d.ts.map +1 -1
- package/dist/lib/terminology/valueset-repo.d.ts +3 -1
- package/dist/lib/terminology/valueset-repo.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1194,6 +1194,8 @@ export declare interface IndexingPipelineOptions {
|
|
|
1194
1194
|
enableReferences?: boolean;
|
|
1195
1195
|
/** Optional RuntimeProvider for FHIRPath-driven extraction (B3). */
|
|
1196
1196
|
runtimeProvider?: RuntimeProvider;
|
|
1197
|
+
/** SQL dialect for lookup table DDL (default: 'sqlite'). */
|
|
1198
|
+
dialect?: DDLDialect;
|
|
1197
1199
|
}
|
|
1198
1200
|
|
|
1199
1201
|
/**
|
|
@@ -1306,7 +1308,8 @@ declare type LookupTableType = 'HumanName' | 'Address' | 'ContactPoint' | 'Ident
|
|
|
1306
1308
|
export declare class LookupTableWriter {
|
|
1307
1309
|
private readonly adapter;
|
|
1308
1310
|
private initialized;
|
|
1309
|
-
|
|
1311
|
+
private readonly ddl;
|
|
1312
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1310
1313
|
/**
|
|
1311
1314
|
* Create all 4 lookup tables + indexes if they don't exist.
|
|
1312
1315
|
*/
|
|
@@ -1390,7 +1393,8 @@ export declare interface MigrationResultV2 {
|
|
|
1390
1393
|
export declare class MigrationRunnerV2 {
|
|
1391
1394
|
private readonly adapter;
|
|
1392
1395
|
private readonly migrations;
|
|
1393
|
-
|
|
1396
|
+
private readonly dialect;
|
|
1397
|
+
constructor(adapter: StorageAdapter, migrations?: MigrationV2[], dialect?: DDLDialect);
|
|
1394
1398
|
/**
|
|
1395
1399
|
* Ensure the tracking table exists.
|
|
1396
1400
|
*/
|
|
@@ -1481,7 +1485,8 @@ export declare interface OperationContext {
|
|
|
1481
1485
|
|
|
1482
1486
|
export declare class PackageRegistryRepo {
|
|
1483
1487
|
private readonly adapter;
|
|
1484
|
-
|
|
1488
|
+
private readonly dialect;
|
|
1489
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1485
1490
|
/**
|
|
1486
1491
|
* Ensure the packages tracking table exists.
|
|
1487
1492
|
*/
|
|
@@ -1513,6 +1518,10 @@ export declare class PackageRegistryRepo {
|
|
|
1513
1518
|
* Uses INSERT OR REPLACE (SQLite UPSERT) to handle both new and upgraded packages.
|
|
1514
1519
|
*/
|
|
1515
1520
|
upsertPackage(pkg: Omit<InstalledPackage, 'installedAt' | 'status'>): Promise<void>;
|
|
1521
|
+
/**
|
|
1522
|
+
* Generate dialect-aware UPSERT SQL.
|
|
1523
|
+
*/
|
|
1524
|
+
private upsertSQL;
|
|
1516
1525
|
/**
|
|
1517
1526
|
* Remove all versions of a package.
|
|
1518
1527
|
*/
|
|
@@ -1900,7 +1909,8 @@ declare interface ReindexResultV2 {
|
|
|
1900
1909
|
|
|
1901
1910
|
export declare class ReindexScheduler {
|
|
1902
1911
|
private readonly adapter;
|
|
1903
|
-
|
|
1912
|
+
private readonly dialect;
|
|
1913
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1904
1914
|
/**
|
|
1905
1915
|
* Ensure the reindex jobs table exists.
|
|
1906
1916
|
*/
|
|
@@ -3199,7 +3209,8 @@ declare interface ValueSetInput {
|
|
|
3199
3209
|
|
|
3200
3210
|
export declare class ValueSetRepo {
|
|
3201
3211
|
private readonly adapter;
|
|
3202
|
-
|
|
3212
|
+
private readonly dialect;
|
|
3213
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
3203
3214
|
/**
|
|
3204
3215
|
* Ensure the terminology_valuesets table exists.
|
|
3205
3216
|
*/
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1194,6 +1194,8 @@ export declare interface IndexingPipelineOptions {
|
|
|
1194
1194
|
enableReferences?: boolean;
|
|
1195
1195
|
/** Optional RuntimeProvider for FHIRPath-driven extraction (B3). */
|
|
1196
1196
|
runtimeProvider?: RuntimeProvider;
|
|
1197
|
+
/** SQL dialect for lookup table DDL (default: 'sqlite'). */
|
|
1198
|
+
dialect?: DDLDialect;
|
|
1197
1199
|
}
|
|
1198
1200
|
|
|
1199
1201
|
/**
|
|
@@ -1306,7 +1308,8 @@ declare type LookupTableType = 'HumanName' | 'Address' | 'ContactPoint' | 'Ident
|
|
|
1306
1308
|
export declare class LookupTableWriter {
|
|
1307
1309
|
private readonly adapter;
|
|
1308
1310
|
private initialized;
|
|
1309
|
-
|
|
1311
|
+
private readonly ddl;
|
|
1312
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1310
1313
|
/**
|
|
1311
1314
|
* Create all 4 lookup tables + indexes if they don't exist.
|
|
1312
1315
|
*/
|
|
@@ -1390,7 +1393,8 @@ export declare interface MigrationResultV2 {
|
|
|
1390
1393
|
export declare class MigrationRunnerV2 {
|
|
1391
1394
|
private readonly adapter;
|
|
1392
1395
|
private readonly migrations;
|
|
1393
|
-
|
|
1396
|
+
private readonly dialect;
|
|
1397
|
+
constructor(adapter: StorageAdapter, migrations?: MigrationV2[], dialect?: DDLDialect);
|
|
1394
1398
|
/**
|
|
1395
1399
|
* Ensure the tracking table exists.
|
|
1396
1400
|
*/
|
|
@@ -1481,7 +1485,8 @@ export declare interface OperationContext {
|
|
|
1481
1485
|
|
|
1482
1486
|
export declare class PackageRegistryRepo {
|
|
1483
1487
|
private readonly adapter;
|
|
1484
|
-
|
|
1488
|
+
private readonly dialect;
|
|
1489
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1485
1490
|
/**
|
|
1486
1491
|
* Ensure the packages tracking table exists.
|
|
1487
1492
|
*/
|
|
@@ -1513,6 +1518,10 @@ export declare class PackageRegistryRepo {
|
|
|
1513
1518
|
* Uses INSERT OR REPLACE (SQLite UPSERT) to handle both new and upgraded packages.
|
|
1514
1519
|
*/
|
|
1515
1520
|
upsertPackage(pkg: Omit<InstalledPackage, 'installedAt' | 'status'>): Promise<void>;
|
|
1521
|
+
/**
|
|
1522
|
+
* Generate dialect-aware UPSERT SQL.
|
|
1523
|
+
*/
|
|
1524
|
+
private upsertSQL;
|
|
1516
1525
|
/**
|
|
1517
1526
|
* Remove all versions of a package.
|
|
1518
1527
|
*/
|
|
@@ -1900,7 +1909,8 @@ declare interface ReindexResultV2 {
|
|
|
1900
1909
|
|
|
1901
1910
|
export declare class ReindexScheduler {
|
|
1902
1911
|
private readonly adapter;
|
|
1903
|
-
|
|
1912
|
+
private readonly dialect;
|
|
1913
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
1904
1914
|
/**
|
|
1905
1915
|
* Ensure the reindex jobs table exists.
|
|
1906
1916
|
*/
|
|
@@ -3199,7 +3209,8 @@ declare interface ValueSetInput {
|
|
|
3199
3209
|
|
|
3200
3210
|
export declare class ValueSetRepo {
|
|
3201
3211
|
private readonly adapter;
|
|
3202
|
-
|
|
3212
|
+
private readonly dialect;
|
|
3213
|
+
constructor(adapter: StorageAdapter, dialect?: DDLDialect);
|
|
3203
3214
|
/**
|
|
3204
3215
|
* Ensure the terminology_valuesets table exists.
|
|
3205
3216
|
*/
|
package/dist/esm/index.mjs
CHANGED
|
@@ -6435,16 +6435,18 @@ var FhirStore = class {
|
|
|
6435
6435
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6436
6436
|
|
|
6437
6437
|
// src/repo/lookup-table-writer.ts
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6438
|
+
function buildLookupTableDDL(dialect) {
|
|
6439
|
+
const pk = dialect === "postgres" ? '"id" SERIAL PRIMARY KEY' : '"id" INTEGER PRIMARY KEY AUTOINCREMENT';
|
|
6440
|
+
return {
|
|
6441
|
+
HumanName: `CREATE TABLE IF NOT EXISTS "HumanName" (
|
|
6442
|
+
${pk},
|
|
6441
6443
|
"resourceId" TEXT NOT NULL,
|
|
6442
6444
|
"name" TEXT,
|
|
6443
6445
|
"given" TEXT,
|
|
6444
6446
|
"family" TEXT
|
|
6445
6447
|
)`,
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
+
Address: `CREATE TABLE IF NOT EXISTS "Address" (
|
|
6449
|
+
${pk},
|
|
6448
6450
|
"resourceId" TEXT NOT NULL,
|
|
6449
6451
|
"address" TEXT,
|
|
6450
6452
|
"city" TEXT,
|
|
@@ -6453,20 +6455,21 @@ var LOOKUP_TABLE_DDL = {
|
|
|
6453
6455
|
"state" TEXT,
|
|
6454
6456
|
"use" TEXT
|
|
6455
6457
|
)`,
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
+
ContactPoint: `CREATE TABLE IF NOT EXISTS "ContactPoint" (
|
|
6459
|
+
${pk},
|
|
6458
6460
|
"resourceId" TEXT NOT NULL,
|
|
6459
6461
|
"system" TEXT,
|
|
6460
6462
|
"value" TEXT,
|
|
6461
6463
|
"use" TEXT
|
|
6462
6464
|
)`,
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
+
Identifier: `CREATE TABLE IF NOT EXISTS "Identifier" (
|
|
6466
|
+
${pk},
|
|
6465
6467
|
"resourceId" TEXT NOT NULL,
|
|
6466
6468
|
"system" TEXT,
|
|
6467
6469
|
"value" TEXT
|
|
6468
6470
|
)`
|
|
6469
|
-
};
|
|
6471
|
+
};
|
|
6472
|
+
}
|
|
6470
6473
|
var LOOKUP_TABLE_INDEXES = {
|
|
6471
6474
|
HumanName: [
|
|
6472
6475
|
'CREATE INDEX IF NOT EXISTS "HumanName_resourceId_idx" ON "HumanName" ("resourceId")',
|
|
@@ -6492,10 +6495,12 @@ var LOOKUP_COLUMNS = {
|
|
|
6492
6495
|
Identifier: ["resourceId", "system", "value"]
|
|
6493
6496
|
};
|
|
6494
6497
|
var LookupTableWriter = class {
|
|
6495
|
-
constructor(adapter) {
|
|
6498
|
+
constructor(adapter, dialect = "sqlite") {
|
|
6496
6499
|
this.adapter = adapter;
|
|
6500
|
+
this.ddl = buildLookupTableDDL(dialect);
|
|
6497
6501
|
}
|
|
6498
6502
|
initialized = false;
|
|
6503
|
+
ddl;
|
|
6499
6504
|
// ---------------------------------------------------------------------------
|
|
6500
6505
|
// DDL
|
|
6501
6506
|
// ---------------------------------------------------------------------------
|
|
@@ -6504,8 +6509,8 @@ var LookupTableWriter = class {
|
|
|
6504
6509
|
*/
|
|
6505
6510
|
async ensureTables() {
|
|
6506
6511
|
if (this.initialized) return;
|
|
6507
|
-
for (const table of Object.keys(
|
|
6508
|
-
await this.adapter.execute(
|
|
6512
|
+
for (const table of Object.keys(this.ddl)) {
|
|
6513
|
+
await this.adapter.execute(this.ddl[table]);
|
|
6509
6514
|
for (const idx of LOOKUP_TABLE_INDEXES[table]) {
|
|
6510
6515
|
await this.adapter.execute(idx);
|
|
6511
6516
|
}
|
|
@@ -6554,7 +6559,7 @@ var LookupTableWriter = class {
|
|
|
6554
6559
|
*/
|
|
6555
6560
|
async deleteRows(resourceId) {
|
|
6556
6561
|
await this.ensureTables();
|
|
6557
|
-
for (const table of Object.keys(
|
|
6562
|
+
for (const table of Object.keys(this.ddl)) {
|
|
6558
6563
|
await this.adapter.execute(
|
|
6559
6564
|
`DELETE FROM "${table}" WHERE "resourceId" = ?`,
|
|
6560
6565
|
[resourceId]
|
|
@@ -6580,7 +6585,7 @@ var LookupTableWriter = class {
|
|
|
6580
6585
|
var IndexingPipeline = class {
|
|
6581
6586
|
constructor(adapter, options) {
|
|
6582
6587
|
this.adapter = adapter;
|
|
6583
|
-
this.lookupWriter = new LookupTableWriter(adapter);
|
|
6588
|
+
this.lookupWriter = new LookupTableWriter(adapter, options?.dialect ?? "sqlite");
|
|
6584
6589
|
this.runtimeProvider = options?.runtimeProvider;
|
|
6585
6590
|
this.options = {
|
|
6586
6591
|
enableLookupTables: options?.enableLookupTables ?? true,
|
|
@@ -7278,35 +7283,43 @@ function mapColumnTypeForDialect(type, dialect) {
|
|
|
7278
7283
|
|
|
7279
7284
|
// src/registry/package-registry-repo.ts
|
|
7280
7285
|
var PACKAGES_TABLE = "_packages";
|
|
7281
|
-
var
|
|
7286
|
+
var SCHEMA_VERSION_TABLE = "_schema_version";
|
|
7287
|
+
function createPackagesTableDDL(dialect) {
|
|
7288
|
+
const ts = dialect === "postgres" ? "TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP" : "TEXT NOT NULL DEFAULT (datetime('now'))";
|
|
7289
|
+
return `
|
|
7282
7290
|
CREATE TABLE IF NOT EXISTS "${PACKAGES_TABLE}" (
|
|
7283
7291
|
"name" TEXT NOT NULL,
|
|
7284
7292
|
"version" TEXT NOT NULL,
|
|
7285
7293
|
"checksum" TEXT NOT NULL,
|
|
7286
7294
|
"schemaSnapshot" TEXT,
|
|
7287
|
-
"installedAt"
|
|
7295
|
+
"installedAt" ${ts},
|
|
7288
7296
|
"status" TEXT NOT NULL DEFAULT 'active',
|
|
7289
7297
|
PRIMARY KEY ("name", "version")
|
|
7290
7298
|
);
|
|
7291
7299
|
`;
|
|
7292
|
-
|
|
7293
|
-
|
|
7300
|
+
}
|
|
7301
|
+
function createSchemaVersionTableDDL(dialect) {
|
|
7302
|
+
const ts = dialect === "postgres" ? "TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP" : "TEXT NOT NULL DEFAULT (datetime('now'))";
|
|
7303
|
+
return `
|
|
7294
7304
|
CREATE TABLE IF NOT EXISTS "${SCHEMA_VERSION_TABLE}" (
|
|
7295
7305
|
"version" INTEGER NOT NULL PRIMARY KEY,
|
|
7296
7306
|
"packageList" TEXT NOT NULL,
|
|
7297
7307
|
"description" TEXT NOT NULL DEFAULT '',
|
|
7298
|
-
"appliedAt"
|
|
7308
|
+
"appliedAt" ${ts}
|
|
7299
7309
|
);
|
|
7300
7310
|
`;
|
|
7311
|
+
}
|
|
7301
7312
|
var PackageRegistryRepo = class {
|
|
7302
|
-
constructor(adapter) {
|
|
7313
|
+
constructor(adapter, dialect = "sqlite") {
|
|
7303
7314
|
this.adapter = adapter;
|
|
7315
|
+
this.dialect = dialect;
|
|
7304
7316
|
}
|
|
7317
|
+
dialect;
|
|
7305
7318
|
/**
|
|
7306
7319
|
* Ensure the packages tracking table exists.
|
|
7307
7320
|
*/
|
|
7308
7321
|
async ensureTable() {
|
|
7309
|
-
await this.adapter.execute(
|
|
7322
|
+
await this.adapter.execute(createPackagesTableDDL(this.dialect));
|
|
7310
7323
|
}
|
|
7311
7324
|
/**
|
|
7312
7325
|
* Get the active version of a package by name.
|
|
@@ -7351,7 +7364,7 @@ var PackageRegistryRepo = class {
|
|
|
7351
7364
|
[pkg.name]
|
|
7352
7365
|
);
|
|
7353
7366
|
await this.adapter.execute(
|
|
7354
|
-
|
|
7367
|
+
this.upsertSQL(),
|
|
7355
7368
|
[pkg.name, pkg.version, pkg.checksum, pkg.schemaSnapshot ?? null]
|
|
7356
7369
|
);
|
|
7357
7370
|
await this.recordSchemaVersion(description ?? `Register ${pkg.name}@${pkg.version}`);
|
|
@@ -7368,10 +7381,19 @@ var PackageRegistryRepo = class {
|
|
|
7368
7381
|
[pkg.name]
|
|
7369
7382
|
);
|
|
7370
7383
|
await this.adapter.execute(
|
|
7371
|
-
|
|
7384
|
+
this.upsertSQL(),
|
|
7372
7385
|
[pkg.name, pkg.version, pkg.checksum, pkg.schemaSnapshot ?? null]
|
|
7373
7386
|
);
|
|
7374
7387
|
}
|
|
7388
|
+
/**
|
|
7389
|
+
* Generate dialect-aware UPSERT SQL.
|
|
7390
|
+
*/
|
|
7391
|
+
upsertSQL() {
|
|
7392
|
+
if (this.dialect === "postgres") {
|
|
7393
|
+
return `INSERT INTO "${PACKAGES_TABLE}" ("name", "version", "checksum", "schemaSnapshot", "status") VALUES (?, ?, ?, ?, 'active') ON CONFLICT ("name", "version") DO UPDATE SET "checksum" = EXCLUDED."checksum", "schemaSnapshot" = EXCLUDED."schemaSnapshot", "status" = 'active'`;
|
|
7394
|
+
}
|
|
7395
|
+
return `INSERT OR REPLACE INTO "${PACKAGES_TABLE}" ("name", "version", "checksum", "schemaSnapshot", "status") VALUES (?, ?, ?, ?, 'active')`;
|
|
7396
|
+
}
|
|
7375
7397
|
/**
|
|
7376
7398
|
* Remove all versions of a package.
|
|
7377
7399
|
*/
|
|
@@ -7403,7 +7425,7 @@ var PackageRegistryRepo = class {
|
|
|
7403
7425
|
* Ensure the schema version table exists.
|
|
7404
7426
|
*/
|
|
7405
7427
|
async ensureSchemaVersionTable() {
|
|
7406
|
-
await this.adapter.execute(
|
|
7428
|
+
await this.adapter.execute(createSchemaVersionTableDDL(this.dialect));
|
|
7407
7429
|
}
|
|
7408
7430
|
/**
|
|
7409
7431
|
* Record a schema version with the current active package list.
|
|
@@ -7453,12 +7475,25 @@ CREATE TABLE IF NOT EXISTS "${TRACKING_TABLE_V2}" (
|
|
|
7453
7475
|
"applied_at" TEXT NOT NULL DEFAULT (datetime('now'))
|
|
7454
7476
|
);
|
|
7455
7477
|
`;
|
|
7478
|
+
var CREATE_TRACKING_TABLE_V2_POSTGRES = `
|
|
7479
|
+
CREATE TABLE IF NOT EXISTS "${TRACKING_TABLE_V2}" (
|
|
7480
|
+
"version" INTEGER PRIMARY KEY,
|
|
7481
|
+
"description" TEXT NOT NULL,
|
|
7482
|
+
"type" TEXT NOT NULL DEFAULT 'file',
|
|
7483
|
+
"applied_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
7484
|
+
);
|
|
7485
|
+
`;
|
|
7486
|
+
function createTrackingDDL(dialect) {
|
|
7487
|
+
return dialect === "postgres" ? CREATE_TRACKING_TABLE_V2_POSTGRES : CREATE_TRACKING_TABLE_V2_SQLITE;
|
|
7488
|
+
}
|
|
7456
7489
|
var MigrationRunnerV2 = class {
|
|
7457
7490
|
adapter;
|
|
7458
7491
|
migrations;
|
|
7459
|
-
|
|
7492
|
+
dialect;
|
|
7493
|
+
constructor(adapter, migrations = [], dialect = "sqlite") {
|
|
7460
7494
|
this.adapter = adapter;
|
|
7461
7495
|
this.migrations = [...migrations].sort((a, b) => a.version - b.version);
|
|
7496
|
+
this.dialect = dialect;
|
|
7462
7497
|
}
|
|
7463
7498
|
// ---------------------------------------------------------------------------
|
|
7464
7499
|
// Public API
|
|
@@ -7467,7 +7502,7 @@ var MigrationRunnerV2 = class {
|
|
|
7467
7502
|
* Ensure the tracking table exists.
|
|
7468
7503
|
*/
|
|
7469
7504
|
async ensureTrackingTable() {
|
|
7470
|
-
await this.adapter.execute(
|
|
7505
|
+
await this.adapter.execute(createTrackingDDL(this.dialect));
|
|
7471
7506
|
}
|
|
7472
7507
|
/**
|
|
7473
7508
|
* Apply all pending migrations (or up to a target version).
|
|
@@ -7643,7 +7678,23 @@ var MigrationRunnerV2 = class {
|
|
|
7643
7678
|
|
|
7644
7679
|
// src/migration/reindex-scheduler.ts
|
|
7645
7680
|
var REINDEX_JOBS_TABLE = "_reindex_jobs";
|
|
7646
|
-
|
|
7681
|
+
function createReindexJobsTableDDL(dialect) {
|
|
7682
|
+
if (dialect === "postgres") {
|
|
7683
|
+
return `
|
|
7684
|
+
CREATE TABLE IF NOT EXISTS "${REINDEX_JOBS_TABLE}" (
|
|
7685
|
+
"id" SERIAL PRIMARY KEY,
|
|
7686
|
+
"resourceType" TEXT NOT NULL,
|
|
7687
|
+
"searchParamCode" TEXT NOT NULL,
|
|
7688
|
+
"expression" TEXT NOT NULL,
|
|
7689
|
+
"status" TEXT NOT NULL DEFAULT 'pending',
|
|
7690
|
+
"cursor" TEXT,
|
|
7691
|
+
"processedCount" INTEGER NOT NULL DEFAULT 0,
|
|
7692
|
+
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7693
|
+
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
7694
|
+
);
|
|
7695
|
+
`;
|
|
7696
|
+
}
|
|
7697
|
+
return `
|
|
7647
7698
|
CREATE TABLE IF NOT EXISTS "${REINDEX_JOBS_TABLE}" (
|
|
7648
7699
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7649
7700
|
"resourceType" TEXT NOT NULL,
|
|
@@ -7656,15 +7707,21 @@ CREATE TABLE IF NOT EXISTS "${REINDEX_JOBS_TABLE}" (
|
|
|
7656
7707
|
"updatedAt" TEXT NOT NULL DEFAULT (datetime('now'))
|
|
7657
7708
|
);
|
|
7658
7709
|
`;
|
|
7710
|
+
}
|
|
7711
|
+
function nowExpression(dialect) {
|
|
7712
|
+
return dialect === "postgres" ? "CURRENT_TIMESTAMP" : "datetime('now')";
|
|
7713
|
+
}
|
|
7659
7714
|
var ReindexScheduler = class {
|
|
7660
|
-
constructor(adapter) {
|
|
7715
|
+
constructor(adapter, dialect = "sqlite") {
|
|
7661
7716
|
this.adapter = adapter;
|
|
7717
|
+
this.dialect = dialect;
|
|
7662
7718
|
}
|
|
7719
|
+
dialect;
|
|
7663
7720
|
/**
|
|
7664
7721
|
* Ensure the reindex jobs table exists.
|
|
7665
7722
|
*/
|
|
7666
7723
|
async ensureTable() {
|
|
7667
|
-
await this.adapter.execute(
|
|
7724
|
+
await this.adapter.execute(createReindexJobsTableDDL(this.dialect));
|
|
7668
7725
|
}
|
|
7669
7726
|
/**
|
|
7670
7727
|
* Schedule reindex jobs from REINDEX deltas.
|
|
@@ -7731,7 +7788,7 @@ var ReindexScheduler = class {
|
|
|
7731
7788
|
sets.push('"processedCount" = ?');
|
|
7732
7789
|
values.push(update.processedCount);
|
|
7733
7790
|
}
|
|
7734
|
-
sets.push(`"updatedAt" =
|
|
7791
|
+
sets.push(`"updatedAt" = ${nowExpression(this.dialect)}`);
|
|
7735
7792
|
values.push(id);
|
|
7736
7793
|
await this.adapter.execute(
|
|
7737
7794
|
`UPDATE "${REINDEX_JOBS_TABLE}" SET ${sets.join(", ")} WHERE "id" = ?`,
|
|
@@ -7764,9 +7821,9 @@ var IGPersistenceManager = class {
|
|
|
7764
7821
|
reindexScheduler;
|
|
7765
7822
|
constructor(adapter, dialect = "sqlite") {
|
|
7766
7823
|
this.dialect = dialect;
|
|
7767
|
-
this.packageRepo = new PackageRegistryRepo(adapter);
|
|
7768
|
-
this.migrationRunner = new MigrationRunnerV2(adapter);
|
|
7769
|
-
this.reindexScheduler = new ReindexScheduler(adapter);
|
|
7824
|
+
this.packageRepo = new PackageRegistryRepo(adapter, dialect);
|
|
7825
|
+
this.migrationRunner = new MigrationRunnerV2(adapter, [], dialect);
|
|
7826
|
+
this.reindexScheduler = new ReindexScheduler(adapter, dialect);
|
|
7770
7827
|
}
|
|
7771
7828
|
/**
|
|
7772
7829
|
* Initialize an IG package — the main entry point.
|
|
@@ -7947,25 +8004,30 @@ var TerminologyCodeRepo = class {
|
|
|
7947
8004
|
|
|
7948
8005
|
// src/terminology/valueset-repo.ts
|
|
7949
8006
|
var VALUESETS_TABLE = "terminology_valuesets";
|
|
7950
|
-
|
|
8007
|
+
function createValuesetsTableDDL(dialect) {
|
|
8008
|
+
const ts = dialect === "postgres" ? "TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP" : "TEXT NOT NULL DEFAULT (datetime('now'))";
|
|
8009
|
+
return `
|
|
7951
8010
|
CREATE TABLE IF NOT EXISTS "${VALUESETS_TABLE}" (
|
|
7952
8011
|
"url" TEXT NOT NULL,
|
|
7953
8012
|
"version" TEXT NOT NULL,
|
|
7954
8013
|
"name" TEXT,
|
|
7955
8014
|
"content" TEXT NOT NULL,
|
|
7956
|
-
"storedAt"
|
|
8015
|
+
"storedAt" ${ts},
|
|
7957
8016
|
PRIMARY KEY ("url", "version")
|
|
7958
8017
|
);
|
|
7959
8018
|
`;
|
|
8019
|
+
}
|
|
7960
8020
|
var ValueSetRepo = class {
|
|
7961
|
-
constructor(adapter) {
|
|
8021
|
+
constructor(adapter, dialect = "sqlite") {
|
|
7962
8022
|
this.adapter = adapter;
|
|
8023
|
+
this.dialect = dialect;
|
|
7963
8024
|
}
|
|
8025
|
+
dialect;
|
|
7964
8026
|
/**
|
|
7965
8027
|
* Ensure the terminology_valuesets table exists.
|
|
7966
8028
|
*/
|
|
7967
8029
|
async ensureTable() {
|
|
7968
|
-
await this.adapter.execute(
|
|
8030
|
+
await this.adapter.execute(createValuesetsTableDDL(this.dialect));
|
|
7969
8031
|
}
|
|
7970
8032
|
/**
|
|
7971
8033
|
* Insert or update a ValueSet.
|
|
@@ -7973,10 +8035,8 @@ var ValueSetRepo = class {
|
|
|
7973
8035
|
*/
|
|
7974
8036
|
async upsert(input) {
|
|
7975
8037
|
await this.ensureTable();
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
[input.url, input.version, input.name ?? null, input.content]
|
|
7979
|
-
);
|
|
8038
|
+
const sql = this.dialect === "postgres" ? `INSERT INTO "${VALUESETS_TABLE}" ("url", "version", "name", "content") VALUES (?, ?, ?, ?) ON CONFLICT ("url", "version") DO UPDATE SET "name" = EXCLUDED."name", "content" = EXCLUDED."content"` : `INSERT OR REPLACE INTO "${VALUESETS_TABLE}" ("url", "version", "name", "content") VALUES (?, ?, ?, ?)`;
|
|
8039
|
+
await this.adapter.execute(sql, [input.url, input.version, input.name ?? null, input.content]);
|
|
7980
8040
|
}
|
|
7981
8041
|
/**
|
|
7982
8042
|
* Get a specific ValueSet by url and version.
|
|
@@ -8435,7 +8495,8 @@ var FhirSystem = class {
|
|
|
8435
8495
|
indexing: {
|
|
8436
8496
|
enableLookupTables: this.options.enableLookupTables,
|
|
8437
8497
|
enableReferences: this.options.enableReferences,
|
|
8438
|
-
runtimeProvider: this.options.runtimeProvider
|
|
8498
|
+
runtimeProvider: this.options.runtimeProvider,
|
|
8499
|
+
dialect: this.dialect
|
|
8439
8500
|
}
|
|
8440
8501
|
});
|
|
8441
8502
|
return {
|