esque-ts 0.2.1-dev.31
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.d.ts +2 -0
- package/dist/cli.js +61 -0
- package/dist/cli.js.map +1 -0
- package/dist/configuration.d.ts +12 -0
- package/dist/configuration.js +9 -0
- package/dist/configuration.js.map +1 -0
- package/dist/elasticsearch/documents.d.ts +70 -0
- package/dist/elasticsearch/documents.js +70 -0
- package/dist/elasticsearch/documents.js.map +1 -0
- package/dist/elasticsearch/lock.d.ts +11 -0
- package/dist/elasticsearch/lock.js +52 -0
- package/dist/elasticsearch/lock.js.map +1 -0
- package/dist/elasticsearch/operations.d.ts +17 -0
- package/dist/elasticsearch/operations.js +107 -0
- package/dist/elasticsearch/operations.js.map +1 -0
- package/dist/esque.d.ts +17 -0
- package/dist/esque.js +152 -0
- package/dist/esque.js.map +1 -0
- package/dist/migration/loader.d.ts +10 -0
- package/dist/migration/loader.js +111 -0
- package/dist/migration/loader.js.map +1 -0
- package/dist/migration/model.d.ts +29 -0
- package/dist/migration/model.js +35 -0
- package/dist/migration/model.js.map +1 -0
- package/dist/migration/template.d.ts +9 -0
- package/dist/migration/template.js +57 -0
- package/dist/migration/template.js.map +1 -0
- package/package.json +42 -0
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Client } from "@elastic/elasticsearch";
|
|
3
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
4
|
+
import { createEsqueConfiguration } from "./configuration.js";
|
|
5
|
+
import { Esque } from "./esque.js";
|
|
6
|
+
function collectProperty(value, previous) {
|
|
7
|
+
const separator = value.indexOf("=");
|
|
8
|
+
if (separator <= 0) {
|
|
9
|
+
throw new InvalidArgumentError(`must be in key=value format, got: '${value}'`);
|
|
10
|
+
}
|
|
11
|
+
previous[value.slice(0, separator)] = value.slice(separator + 1);
|
|
12
|
+
return previous;
|
|
13
|
+
}
|
|
14
|
+
function formatErrorChain(error) {
|
|
15
|
+
if (!(error instanceof Error)) {
|
|
16
|
+
return String(error);
|
|
17
|
+
}
|
|
18
|
+
const messages = [error.message];
|
|
19
|
+
let cause = error.cause;
|
|
20
|
+
while (cause instanceof Error) {
|
|
21
|
+
messages.push(cause.message);
|
|
22
|
+
cause = cause.cause;
|
|
23
|
+
}
|
|
24
|
+
return messages.join(" -> ");
|
|
25
|
+
}
|
|
26
|
+
const program = new Command()
|
|
27
|
+
.name("esque")
|
|
28
|
+
.description("Run Elasticsearch migrations.")
|
|
29
|
+
.requiredOption("--es-url <url>", "Elasticsearch URL (e.g. http://localhost:9200)")
|
|
30
|
+
.requiredOption("--migrations-dir <path>", "Path to directory containing migration YAML files")
|
|
31
|
+
.requiredOption("--migration-key <key>", "Unique key scoping this migration set")
|
|
32
|
+
.option("--migration-user <user>", "User to record on each migration record")
|
|
33
|
+
.option("--lock-timeout-minutes <n>", "Lock acquisition timeout in minutes", (value) => {
|
|
34
|
+
const parsed = Number.parseInt(value, 10);
|
|
35
|
+
if (Number.isNaN(parsed)) {
|
|
36
|
+
throw new InvalidArgumentError(`must be an integer, got: '${value}'`);
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
}, 5)
|
|
40
|
+
.option("--property <key=value>", "Template substitution property as key=value (repeatable)", collectProperty, {});
|
|
41
|
+
program.parse();
|
|
42
|
+
const opts = program.opts();
|
|
43
|
+
const configuration = createEsqueConfiguration({
|
|
44
|
+
migrationKey: opts.migrationKey,
|
|
45
|
+
migrationUser: opts.migrationUser ?? null,
|
|
46
|
+
migrationDirectory: `file:${opts.migrationsDir}`,
|
|
47
|
+
lockTimeoutMinutes: opts.lockTimeoutMinutes,
|
|
48
|
+
});
|
|
49
|
+
let esque;
|
|
50
|
+
try {
|
|
51
|
+
esque = new Esque(new Client({ node: opts.esUrl }), configuration, opts.property);
|
|
52
|
+
await esque.execute();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(`Error: ${formatErrorChain(error)}`);
|
|
56
|
+
process.exitCode = 1;
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await esque?.close();
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,SAAS,eAAe,CAAC,KAAa,EAAE,QAAgC;IACtE,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,oBAAoB,CAAC,sCAAsC,KAAK,GAAG,CAAC,CAAC;IACjF,CAAC;IACD,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IACjE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACxB,OAAO,KAAK,YAAY,KAAK,EAAE,CAAC;QAC9B,QAAQ,CAAC,I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7B,IAAI,CAAC;IACH,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClF,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,KAAK,CAAC,UAAU,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC;QAAS,CAAC;IACT,MAAM,KAAK,EAAE,KAAK,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface EsqueConfiguration {
|
|
2
|
+
readonly migrationKey: string;
|
|
3
|
+
readonly migrationUser: string | null;
|
|
4
|
+
readonly migrationDirectory: string;
|
|
5
|
+
readonly lockTimeoutMinutes: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function createEsqueConfiguration(options: {
|
|
8
|
+
migrationKey: string;
|
|
9
|
+
migrationUser?: string | null;
|
|
10
|
+
migrationDirectory?: string;
|
|
11
|
+
lockTimeoutMinutes?: number;
|
|
12
|
+
}): EsqueConfiguration;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function createEsqueConfiguration(options) {
|
|
2
|
+
return {
|
|
3
|
+
migrationKey: options.migrationKey,
|
|
4
|
+
migrationUser: options.migrationUser ?? null,
|
|
5
|
+
migrationDirectory: options.migrationDirectory ?? "file:es.migration",
|
|
6
|
+
lockTimeoutMinutes: options.lockTimeoutMinutes ?? 5,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,wBAAwB,CAAC,OAKxC;IACC,OAAO;QACL,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,IAAI;QAC5C,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,mBAAmB;QACrE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,CAAC;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export declare const MIGRATION_INDEX = ".esque";
|
|
2
|
+
export declare const LOCK_ID_PREFIX = "lock";
|
|
3
|
+
export declare const INDEX_DEFINITION: {
|
|
4
|
+
readonly settings: {
|
|
5
|
+
readonly index: {
|
|
6
|
+
readonly number_of_shards: "1";
|
|
7
|
+
readonly auto_expand_replicas: "0-all";
|
|
8
|
+
readonly refresh_interval: "1s";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
readonly mappings: {
|
|
12
|
+
readonly properties: {
|
|
13
|
+
readonly lock: {
|
|
14
|
+
readonly properties: {
|
|
15
|
+
readonly date: {
|
|
16
|
+
readonly type: "date";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
readonly migration: {
|
|
21
|
+
readonly properties: {
|
|
22
|
+
readonly checksum: {
|
|
23
|
+
readonly type: "long";
|
|
24
|
+
};
|
|
25
|
+
readonly description: {
|
|
26
|
+
readonly type: "keyword";
|
|
27
|
+
};
|
|
28
|
+
readonly executionTime: {
|
|
29
|
+
readonly type: "long";
|
|
30
|
+
};
|
|
31
|
+
readonly filename: {
|
|
32
|
+
readonly type: "keyword";
|
|
33
|
+
};
|
|
34
|
+
readonly installedOn: {
|
|
35
|
+
readonly type: "date";
|
|
36
|
+
};
|
|
37
|
+
readonly migrationKey: {
|
|
38
|
+
readonly type: "keyword";
|
|
39
|
+
};
|
|
40
|
+
readonly order: {
|
|
41
|
+
readonly type: "long";
|
|
42
|
+
};
|
|
43
|
+
readonly version: {
|
|
44
|
+
readonly type: "keyword";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export interface MigrationRecord {
|
|
52
|
+
readonly migrationKey: string;
|
|
53
|
+
readonly order: number;
|
|
54
|
+
readonly filename: string;
|
|
55
|
+
readonly version: string;
|
|
56
|
+
readonly description: string;
|
|
57
|
+
readonly checksum: number;
|
|
58
|
+
readonly installedBy: string | null;
|
|
59
|
+
readonly installedOn: string;
|
|
60
|
+
readonly executionTime: number;
|
|
61
|
+
}
|
|
62
|
+
export declare function migrationRecordToDocument(record: MigrationRecord): {
|
|
63
|
+
migration: Record<string, unknown>;
|
|
64
|
+
};
|
|
65
|
+
export declare function migrationRecordFromDocument(source: Record<string, unknown>): MigrationRecord;
|
|
66
|
+
export declare function migrationLockToDocument(date: Date): {
|
|
67
|
+
lock: {
|
|
68
|
+
date: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const MIGRATION_INDEX = ".esque";
|
|
2
|
+
export const LOCK_ID_PREFIX = "lock";
|
|
3
|
+
export const INDEX_DEFINITION = {
|
|
4
|
+
settings: {
|
|
5
|
+
index: {
|
|
6
|
+
number_of_shards: "1",
|
|
7
|
+
auto_expand_replicas: "0-all",
|
|
8
|
+
refresh_interval: "1s",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
mappings: {
|
|
12
|
+
properties: {
|
|
13
|
+
lock: { properties: { date: { type: "date" } } },
|
|
14
|
+
migration: {
|
|
15
|
+
properties: {
|
|
16
|
+
checksum: { type: "long" },
|
|
17
|
+
description: { type: "keyword" },
|
|
18
|
+
executionTime: { type: "long" },
|
|
19
|
+
filename: { type: "keyword" },
|
|
20
|
+
installedOn: { type: "date" },
|
|
21
|
+
migrationKey: { type: "keyword" },
|
|
22
|
+
order: { type: "long" },
|
|
23
|
+
version: { type: "keyword" },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
// Wrapper-object serialization — mirrors JVM @JsonTypeInfo(As.WRAPPER_OBJECT).
|
|
30
|
+
export function migrationRecordToDocument(record) {
|
|
31
|
+
const doc = {
|
|
32
|
+
migrationKey: record.migrationKey,
|
|
33
|
+
order: record.order,
|
|
34
|
+
filename: record.filename,
|
|
35
|
+
version: record.version,
|
|
36
|
+
description: record.description,
|
|
37
|
+
checksum: record.checksum,
|
|
38
|
+
installedOn: record.installedOn,
|
|
39
|
+
executionTime: record.executionTime,
|
|
40
|
+
};
|
|
41
|
+
if (record.installedBy !== null) {
|
|
42
|
+
doc.installedBy = record.installedBy;
|
|
43
|
+
}
|
|
44
|
+
return { migration: doc };
|
|
45
|
+
}
|
|
46
|
+
function requireField(raw, field) {
|
|
47
|
+
const value = raw[field];
|
|
48
|
+
if (value === undefined || value === null) {
|
|
49
|
+
throw new Error(`malformed migration record in .esque index: missing field '${field}'`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
export function migrationRecordFromDocument(source) {
|
|
54
|
+
const raw = source.migration;
|
|
55
|
+
return {
|
|
56
|
+
migrationKey: String(requireField(raw, "migrationKey")),
|
|
57
|
+
order: Number(requireField(raw, "order")),
|
|
58
|
+
filename: String(requireField(raw, "filename")),
|
|
59
|
+
version: String(requireField(raw, "version")),
|
|
60
|
+
description: String(requireField(raw, "description")),
|
|
61
|
+
checksum: Number(requireField(raw, "checksum")),
|
|
62
|
+
installedBy: raw.installedBy !== undefined && raw.installedBy !== null ? String(raw.installedBy) : null,
|
|
63
|
+
installedOn: String(requireField(raw, "installedOn")),
|
|
64
|
+
executionTime: Number(requireField(raw, "executionTime")),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function migrationLockToDocument(date) {
|
|
68
|
+
return { lock: { date: date.toISOString() } };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0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,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI;QACvG,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACrD,aAAa,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAU;IAChD,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RestClientOperations } from "./operations.js";
|
|
2
|
+
export declare class LockNotHeldError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export declare class ElasticsearchDocumentLock {
|
|
5
|
+
private readonly operations;
|
|
6
|
+
private held;
|
|
7
|
+
constructor(operations: RestClientOperations);
|
|
8
|
+
tryLock(timeoutMinutes: number): Promise<boolean>;
|
|
9
|
+
unlock(): Promise<void>;
|
|
10
|
+
private doLock;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
const IDLE_BETWEEN_TRIES_MS = 100;
|
|
3
|
+
// Thrown by unlock() when the lock is not held — expected during Esque.close() after a clean run.
|
|
4
|
+
export class LockNotHeldError extends Error {
|
|
5
|
+
}
|
|
6
|
+
// Distributed lock via ES op_type=create. The JVM wraps this in a local ReentrantLock for
|
|
7
|
+
// thread safety; Node is single-threaded, so a held-flag suffices — it exists to make
|
|
8
|
+
// unlock() without tryLock() a detectable error, and to avoid deleting another process's
|
|
9
|
+
// lock document from a process that never acquired it.
|
|
10
|
+
export class ElasticsearchDocumentLock {
|
|
11
|
+
operations;
|
|
12
|
+
held = false;
|
|
13
|
+
constructor(operations) {
|
|
14
|
+
this.operations = operations;
|
|
15
|
+
}
|
|
16
|
+
async tryLock(timeoutMinutes) {
|
|
17
|
+
const deadline = Date.now() + timeoutMinutes * 60_000;
|
|
18
|
+
for (;;) {
|
|
19
|
+
if (await this.doLock()) {
|
|
20
|
+
this.held = true;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (Date.now() >= deadline) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
await sleep(IDLE_BETWEEN_TRIES_MS);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async unlock() {
|
|
30
|
+
if (!this.held) {
|
|
31
|
+
throw new LockNotHeldError("cannot release un-acquired lock");
|
|
32
|
+
}
|
|
33
|
+
this.held = false;
|
|
34
|
+
try {
|
|
35
|
+
await this.operations.deleteLockRecord();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new Error("Failed to release mutex", { cause: error });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async doLock() {
|
|
42
|
+
try {
|
|
43
|
+
await this.operations.createLockRecord();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// TODO: differentiate ConflictError (lock exists) from other failures
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../src/elasticsearch/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAElC,kGAAkG;AAClG,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,0FAA0F;AAC1F,sFAAsF;AACtF,yFAAyF;AACzF,uDAAuD;AACvD,MAAM,OAAO,yBAAyB;IACnB,UAAU,CAAuB;IAC1C,IAAI,GAAG,KAAK,CAAC;IAErB,YAAY,UAAgC;QAC1C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,cAAsB;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,GAAG,MAAM,CAAC;QACtD,SAAS,CAAC;YACR,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACjB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,gBAAgB,CAAC,iCAAiC,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,MAAM;QAClB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,sEAAsE;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import type { MigrationFile, MigrationFileRequestDefinition } from "../migration/model.js";
|
|
3
|
+
import type { MigrationRecord } from "./documents.js";
|
|
4
|
+
export declare class RestClientOperations {
|
|
5
|
+
private readonly client;
|
|
6
|
+
private readonly migrationKey;
|
|
7
|
+
constructor(client: Client, migrationKey: string);
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
checkMigrationIndexExists(): Promise<boolean>;
|
|
10
|
+
createMigrationIndex(): Promise<void>;
|
|
11
|
+
createLockRecord(): Promise<void>;
|
|
12
|
+
deleteLockRecord(): Promise<void>;
|
|
13
|
+
getMigrationRecords(): Promise<MigrationRecord[]>;
|
|
14
|
+
getMigrationRecordForMigrationFile(file: MigrationFile): Promise<MigrationRecord | null>;
|
|
15
|
+
executeMigrationDefinition(definition: MigrationFileRequestDefinition): Promise<void>;
|
|
16
|
+
createMigrationRecord(record: MigrationRecord): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { errors } from "@elastic/elasticsearch";
|
|
2
|
+
import { INDEX_DEFINITION, LOCK_ID_PREFIX, MIGRATION_INDEX, migrationLockToDocument, migrationRecordFromDocument, migrationRecordToDocument, } from "./documents.js";
|
|
3
|
+
export class RestClientOperations {
|
|
4
|
+
client;
|
|
5
|
+
migrationKey;
|
|
6
|
+
constructor(client, migrationKey) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.migrationKey = migrationKey;
|
|
9
|
+
}
|
|
10
|
+
async close() {
|
|
11
|
+
await this.client.close();
|
|
12
|
+
}
|
|
13
|
+
async checkMigrationIndexExists() {
|
|
14
|
+
return await this.client.indices.exists({ index: MIGRATION_INDEX });
|
|
15
|
+
}
|
|
16
|
+
async createMigrationIndex() {
|
|
17
|
+
try {
|
|
18
|
+
await this.client.indices.create({
|
|
19
|
+
index: MIGRATION_INDEX,
|
|
20
|
+
settings: INDEX_DEFINITION.settings,
|
|
21
|
+
mappings: INDEX_DEFINITION.mappings,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (isAlreadyExistsError(error)) {
|
|
26
|
+
return; // another process created it first — safe
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async createLockRecord() {
|
|
32
|
+
await this.client.index({
|
|
33
|
+
index: MIGRATION_INDEX,
|
|
34
|
+
id: `${LOCK_ID_PREFIX}:${this.migrationKey}`,
|
|
35
|
+
document: migrationLockToDocument(new Date()),
|
|
36
|
+
op_type: "create",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async deleteLockRecord() {
|
|
40
|
+
await this.client.delete({
|
|
41
|
+
index: MIGRATION_INDEX,
|
|
42
|
+
id: `${LOCK_ID_PREFIX}:${this.migrationKey}`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async getMigrationRecords() {
|
|
46
|
+
const response = await this.client.search({
|
|
47
|
+
index: MIGRATION_INDEX,
|
|
48
|
+
query: { bool: { filter: [{ term: { "migration.migrationKey": this.migrationKey } }] } },
|
|
49
|
+
size: 10000,
|
|
50
|
+
});
|
|
51
|
+
const records = response.hits.hits.map((hit) => migrationRecordFromDocument(hit._source));
|
|
52
|
+
records.sort((a, b) => a.order - b.order);
|
|
53
|
+
return records;
|
|
54
|
+
}
|
|
55
|
+
async getMigrationRecordForMigrationFile(file) {
|
|
56
|
+
const response = await this.client.search({
|
|
57
|
+
index: MIGRATION_INDEX,
|
|
58
|
+
query: {
|
|
59
|
+
bool: {
|
|
60
|
+
filter: [
|
|
61
|
+
{ term: { "migration.migrationKey": this.migrationKey } },
|
|
62
|
+
{ term: { "migration.filename": file.metadata.filename } },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const hits = response.hits.hits;
|
|
68
|
+
if (hits.length > 1) {
|
|
69
|
+
throw new Error(`found more than one migration record for file [${file.metadata.filename}] and migration key [${this.migrationKey}]`);
|
|
70
|
+
}
|
|
71
|
+
const first = hits[0];
|
|
72
|
+
if (first !== undefined) {
|
|
73
|
+
return migrationRecordFromDocument(first._source);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async executeMigrationDefinition(definition) {
|
|
78
|
+
const headers = {};
|
|
79
|
+
if (definition.contentType !== null) {
|
|
80
|
+
headers["content-type"] = definition.contentType;
|
|
81
|
+
}
|
|
82
|
+
await this.client.transport.request({
|
|
83
|
+
method: definition.method,
|
|
84
|
+
path: definition.path,
|
|
85
|
+
querystring: definition.params ?? undefined,
|
|
86
|
+
body: definition.body ?? undefined,
|
|
87
|
+
}, { headers });
|
|
88
|
+
}
|
|
89
|
+
async createMigrationRecord(record) {
|
|
90
|
+
if (record.migrationKey !== this.migrationKey) {
|
|
91
|
+
throw new Error("migration record migration key must match operational migration key");
|
|
92
|
+
}
|
|
93
|
+
await this.client.index({
|
|
94
|
+
index: MIGRATION_INDEX,
|
|
95
|
+
document: migrationRecordToDocument(record),
|
|
96
|
+
refresh: true, // without it, reads immediately after won't see the record
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isAlreadyExistsError(error) {
|
|
101
|
+
if (!(error instanceof errors.ResponseError)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const body = error.body;
|
|
105
|
+
return body?.error?.type === "resource_already_exists_exception";
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/elasticsearch/operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,oBAAoB;IACd,MAAM,CAAS;IACf,YAAY,CAAS;IAEtC,YAAY,MAAc,EAAE,YAAoB;QAC9C,IAAI,CAAC,MAAM,GAAG,MA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K,mCAAmC,CAAC;AACnE,CAAC"}
|
package/dist/esque.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Client } from "@elastic/elasticsearch";
|
|
2
|
+
import type { EsqueConfiguration } from "./configuration.js";
|
|
3
|
+
export declare class Esque {
|
|
4
|
+
private readonly configuration;
|
|
5
|
+
private readonly migrationLoader;
|
|
6
|
+
private readonly operations;
|
|
7
|
+
private readonly lock;
|
|
8
|
+
constructor(client: Client, configuration: EsqueConfiguration, properties?: Record<string, string>);
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
11
|
+
execute(): Promise<void>;
|
|
12
|
+
private initialize;
|
|
13
|
+
private verifyStateIntegrity;
|
|
14
|
+
private verifyRecordIntegrity;
|
|
15
|
+
private runMigrations;
|
|
16
|
+
private runMigrationForFile;
|
|
17
|
+
}
|
package/dist/esque.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { ElasticsearchDocumentLock, LockNotHeldError } from "./elasticsearch/lock.js";
|
|
2
|
+
import { RestClientOperations } from "./elasticsearch/operations.js";
|
|
3
|
+
import { MigrationFileLoader } from "./migration/loader.js";
|
|
4
|
+
import { MigrationTemplateResolver } from "./migration/template.js";
|
|
5
|
+
export class Esque {
|
|
6
|
+
configuration;
|
|
7
|
+
migrationLoader;
|
|
8
|
+
operations;
|
|
9
|
+
lock;
|
|
10
|
+
constructor(client, configuration, properties = {}) {
|
|
11
|
+
this.configuration = configuration;
|
|
12
|
+
this.migrationLoader = new MigrationFileLoader(configuration.migrationDirectory, new MigrationTemplateResolver(properties));
|
|
13
|
+
this.operations = new RestClientOperations(client, configuration.migrationKey);
|
|
14
|
+
this.lock = new ElasticsearchDocumentLock(this.operations);
|
|
15
|
+
}
|
|
16
|
+
async close() {
|
|
17
|
+
try {
|
|
18
|
+
await this.lock.unlock();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!(error instanceof LockNotHeldError)) {
|
|
22
|
+
console.warn("failed to release a execution lock. you may need to manually delete the lock document yourself");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
await this.operations.close();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
console.warn("failed to close client. this is likely not an issue");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async [Symbol.asyncDispose]() {
|
|
33
|
+
await this.close();
|
|
34
|
+
}
|
|
35
|
+
async execute() {
|
|
36
|
+
try {
|
|
37
|
+
await this.initialize();
|
|
38
|
+
const files = this.migrationLoader.load();
|
|
39
|
+
const history = await this.operations.getMigrationRecords();
|
|
40
|
+
this.verifyStateIntegrity(files, history);
|
|
41
|
+
await this.runMigrations(files);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new Error("Failed to run esque execution", { cause: error });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async initialize() {
|
|
48
|
+
if (!(await this.operations.checkMigrationIndexExists())) {
|
|
49
|
+
await this.operations.createMigrationIndex();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
verifyStateIntegrity(files, history) {
|
|
53
|
+
if (history.length > files.length) {
|
|
54
|
+
throw new Error("the migration records are showing more migrations than the local system defines. " +
|
|
55
|
+
"did you refactor your files or use an incorrect migration key?");
|
|
56
|
+
}
|
|
57
|
+
const last = history[history.length - 1];
|
|
58
|
+
if (last !== undefined && history.length !== last.order + 1) {
|
|
59
|
+
throw new Error("the migration records seem to be corrupt as some records appear to be missing.");
|
|
60
|
+
}
|
|
61
|
+
for (const record of history) {
|
|
62
|
+
this.verifyRecordIntegrity(record, files);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
verifyRecordIntegrity(record, files) {
|
|
66
|
+
const companion = files.find((f) => f.metadata.filename === record.filename);
|
|
67
|
+
if (companion === undefined) {
|
|
68
|
+
throw new Error(`could not find migration file matching migration history record by filename [${record.filename}]`);
|
|
69
|
+
}
|
|
70
|
+
if (record.order !== files.indexOf(companion) ||
|
|
71
|
+
record.version !== companion.metadata.version ||
|
|
72
|
+
record.description !== companion.metadata.description ||
|
|
73
|
+
record.checksum !== companion.metadata.checksum ||
|
|
74
|
+
record.migrationKey !== this.configuration.migrationKey) {
|
|
75
|
+
throw new Error(`could not verify integrity of migration history record for filename [${record.filename}]. ` +
|
|
76
|
+
"did you refactor your migration scripts after a previous execution?");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async runMigrations(files) {
|
|
80
|
+
try {
|
|
81
|
+
for (const file of files) {
|
|
82
|
+
let executionError;
|
|
83
|
+
try {
|
|
84
|
+
if (await this.lock.tryLock(this.configuration.lockTimeoutMinutes)) {
|
|
85
|
+
const existing = await this.operations.getMigrationRecordForMigrationFile(file);
|
|
86
|
+
if (existing === null) {
|
|
87
|
+
const start = performance.now();
|
|
88
|
+
await this.runMigrationForFile(file);
|
|
89
|
+
const elapsedMs = Math.round(performance.now() - start);
|
|
90
|
+
await this.operations.createMigrationRecord({
|
|
91
|
+
migrationKey: this.configuration.migrationKey,
|
|
92
|
+
order: files.indexOf(file),
|
|
93
|
+
filename: file.metadata.filename,
|
|
94
|
+
version: file.metadata.version,
|
|
95
|
+
description: file.metadata.description,
|
|
96
|
+
checksum: file.metadata.checksum,
|
|
97
|
+
installedBy: this.configuration.migrationUser,
|
|
98
|
+
installedOn: new Date().toISOString(),
|
|
99
|
+
executionTime: elapsedMs,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error("failed to acquire lock");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
executionError = new Error(`Failed to execute queries in migration file [${file.metadata.filename}]`, {
|
|
109
|
+
cause: error,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// Never let a release failure silently replace an execution failure (or its success) —
|
|
113
|
+
// capture both separately instead of releasing in a `finally` that could throw over
|
|
114
|
+
// whatever the try/catch above was about to produce.
|
|
115
|
+
let releaseError;
|
|
116
|
+
try {
|
|
117
|
+
await this.lock.unlock();
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (!(error instanceof LockNotHeldError)) {
|
|
121
|
+
releaseError = error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (executionError !== undefined) {
|
|
125
|
+
if (releaseError !== undefined) {
|
|
126
|
+
console.warn(`failed to release execution lock for migration file [${file.metadata.filename}] after a migration failure. you may need to manually delete the lock document yourself`);
|
|
127
|
+
}
|
|
128
|
+
throw executionError;
|
|
129
|
+
}
|
|
130
|
+
if (releaseError !== undefined) {
|
|
131
|
+
throw new Error(`Failed to release execution lock after migration file [${file.metadata.filename}]`, {
|
|
132
|
+
cause: releaseError,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new Error("failed to run migrations", { cause: error });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async runMigrationForFile(file) {
|
|
142
|
+
for (const [position, definition] of file.contents.requests.entries()) {
|
|
143
|
+
try {
|
|
144
|
+
await this.operations.executeMigrationDefinition(definition);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new Error(`Failed to execute query in position [${position}] in migration file [${file.metadata.filename}]`, { cause: error });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=esque.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esque.js","sourceRoot":"","sources":["../src/esque.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAA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;wBAC/B,OAAO,CAAC,IAAI,CACV,wDAAwD,IAAI,CAAC,QAAQ,CAAC,QAAQ,yFAAyF,CACxK,CAAC;oBACJ,CAAC;oBACD,MAAM,cAAc,CAAC;gBACvB,CAAC;gBACD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;oBAC/B,MAAM,IAAI,KAAK,CAAC,0DAA0D,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,EAAE;wBACnG,KAAK,EAAE,YAAY;qBACpB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAAC,IAAmB;QACnD,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YACtE,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CACb,wCAAwC,QAAQ,wBAAwB,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,EACjG,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MigrationFile, MigrationFileContents } from "./model.js";
|
|
2
|
+
import type { MigrationTemplateResolver } from "./template.js";
|
|
3
|
+
export declare function calculateChecksum(contents: MigrationFileContents): number;
|
|
4
|
+
export declare class MigrationFileLoader {
|
|
5
|
+
private readonly migrationDirectory;
|
|
6
|
+
private readonly templateResolver;
|
|
7
|
+
constructor(migrationDirectory: string, templateResolver: MigrationTemplateResolver);
|
|
8
|
+
load(): MigrationFile[];
|
|
9
|
+
private resolveFile;
|
|
10
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
import { compareMigrationFiles, toCanonicalDict } from "./model.js";
|
|
6
|
+
// Canonical JSON: keys sorted alphabetically at every level, null/undefined object values
|
|
7
|
+
// dropped, compact separators. Matches Python's
|
|
8
|
+
// json.dumps(remove_nulls(data), sort_keys=True, separators=(",", ":"), ensure_ascii=False).
|
|
9
|
+
// Only ever fed the closed shape produced by toCanonicalDict — do not reuse for arbitrary JSON.
|
|
10
|
+
function canonicalJson(value) {
|
|
11
|
+
if (value === null || typeof value !== "object") {
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return `[${value.map((item) => canonicalJson(item)).join(",")}]`;
|
|
16
|
+
}
|
|
17
|
+
const entries = Object.entries(value)
|
|
18
|
+
.filter((entry) => entry[1] !== null && entry[1] !== undefined)
|
|
19
|
+
.sort(([a], [b]) => (a < b ? -1 : 1));
|
|
20
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
21
|
+
}
|
|
22
|
+
// Canonical algorithm (identical across all implementations):
|
|
23
|
+
// canonical JSON of {"requests": [...]} → UTF-8 → MD5 → first 4 bytes as big-endian signed int32.
|
|
24
|
+
export function calculateChecksum(contents) {
|
|
25
|
+
const data = { requests: contents.requests.map((r) => toCanonicalDict(r)) };
|
|
26
|
+
const digest = createHash("md5").update(canonicalJson(data), "utf8").digest();
|
|
27
|
+
return digest.readInt32BE(0);
|
|
28
|
+
}
|
|
29
|
+
const FILE_NAME_PATTERN = /^V((\d+\.?)+)__(\w+)\.yml$/;
|
|
30
|
+
export class MigrationFileLoader {
|
|
31
|
+
migrationDirectory;
|
|
32
|
+
templateResolver;
|
|
33
|
+
constructor(migrationDirectory, templateResolver) {
|
|
34
|
+
this.migrationDirectory = migrationDirectory;
|
|
35
|
+
this.templateResolver = templateResolver;
|
|
36
|
+
}
|
|
37
|
+
load() {
|
|
38
|
+
const dir = resolveDirectoryPath(this.migrationDirectory);
|
|
39
|
+
const rawFiles = [];
|
|
40
|
+
for (const name of readdirSync(dir)) {
|
|
41
|
+
const filePath = join(dir, name);
|
|
42
|
+
if (!statSync(filePath).isFile()) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const match = FILE_NAME_PATTERN.exec(name);
|
|
46
|
+
if (match === null) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
rawFiles.push(readRawFile(filePath, name, match));
|
|
50
|
+
}
|
|
51
|
+
rawFiles.sort(compareMigrationFiles);
|
|
52
|
+
this.templateResolver.validate(rawFiles);
|
|
53
|
+
return rawFiles.map((file) => this.resolveFile(file));
|
|
54
|
+
}
|
|
55
|
+
resolveFile(file) {
|
|
56
|
+
const resolvedContents = this.templateResolver.resolveContents(file.contents);
|
|
57
|
+
return {
|
|
58
|
+
metadata: { ...file.metadata, checksum: calculateChecksum(resolvedContents) },
|
|
59
|
+
contents: resolvedContents,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function resolveDirectoryPath(directory) {
|
|
64
|
+
if (directory.startsWith("file:")) {
|
|
65
|
+
return directory.slice("file:".length);
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`unsupported migration directory scheme in '${directory}'. supported schemes: 'file:'`);
|
|
68
|
+
}
|
|
69
|
+
function readRawFile(filePath, filename, match) {
|
|
70
|
+
const version = match[1];
|
|
71
|
+
const description = match[3];
|
|
72
|
+
if (version === undefined || description === undefined || version.split(".").some((s) => s === "")) {
|
|
73
|
+
// Empty segment (e.g. trailing dot in "V1.__X.yml") — fail loud, mirroring Python's
|
|
74
|
+
// int("") ValueError, instead of silently treating it as 0.
|
|
75
|
+
throw new Error(`invalid migration filename: ${filename}`);
|
|
76
|
+
}
|
|
77
|
+
const data = parse(readFileSync(filePath, "utf8"));
|
|
78
|
+
if (!Array.isArray(data?.requests)) {
|
|
79
|
+
throw new Error(`migration file [${filename}] must contain a 'requests' list`);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
metadata: { filename, version, description, checksum: 0 },
|
|
83
|
+
contents: { requests: data.requests.map((raw) => parseRequest(raw)) },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function parseRequest(raw) {
|
|
87
|
+
if (!isPlainObject(raw)) {
|
|
88
|
+
throw new Error("migration request definition must be a mapping");
|
|
89
|
+
}
|
|
90
|
+
if (!("method" in raw) || !("path" in raw)) {
|
|
91
|
+
throw new Error("migration request definition missing required field 'method' or 'path'");
|
|
92
|
+
}
|
|
93
|
+
let params = null;
|
|
94
|
+
if ("params" in raw) {
|
|
95
|
+
if (!isPlainObject(raw.params)) {
|
|
96
|
+
throw new Error("migration request 'params' must be a mapping of string keys to values");
|
|
97
|
+
}
|
|
98
|
+
params = Object.fromEntries(Object.entries(raw.params).map(([k, v]) => [String(k), String(v)]));
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
method: String(raw.method),
|
|
102
|
+
path: String(raw.path),
|
|
103
|
+
contentType: "contentType" in raw ? String(raw.contentType) : null,
|
|
104
|
+
params,
|
|
105
|
+
body: "body" in raw ? String(raw.body) : null,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function isPlainObject(value) {
|
|
109
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/migration/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAA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AC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC;IACD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;QACtB,WAAW,EAAE,aAAa,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI;QAClE,MAAM;QACN,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;KAC9C,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface MigrationFileRequestDefinition {
|
|
2
|
+
readonly method: string;
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly contentType: string | null;
|
|
5
|
+
readonly params: Readonly<Record<string, string>> | null;
|
|
6
|
+
readonly body: string | null;
|
|
7
|
+
}
|
|
8
|
+
export interface CanonicalRequest {
|
|
9
|
+
method: string;
|
|
10
|
+
path: string;
|
|
11
|
+
body?: string;
|
|
12
|
+
contentType?: string;
|
|
13
|
+
params?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function toCanonicalDict(request: MigrationFileRequestDefinition): CanonicalRequest;
|
|
16
|
+
export interface MigrationFileMetadata {
|
|
17
|
+
readonly filename: string;
|
|
18
|
+
readonly version: string;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly checksum: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MigrationFileContents {
|
|
23
|
+
readonly requests: readonly MigrationFileRequestDefinition[];
|
|
24
|
+
}
|
|
25
|
+
export interface MigrationFile {
|
|
26
|
+
readonly metadata: MigrationFileMetadata;
|
|
27
|
+
readonly contents: MigrationFileContents;
|
|
28
|
+
}
|
|
29
|
+
export declare function compareMigrationFiles(a: MigrationFile, b: MigrationFile): number;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Only non-null fields, camelCase keys — this shape feeds the checksum.
|
|
2
|
+
export function toCanonicalDict(request) {
|
|
3
|
+
const d = { method: request.method, path: request.path };
|
|
4
|
+
if (request.body !== null) {
|
|
5
|
+
d.body = request.body;
|
|
6
|
+
}
|
|
7
|
+
if (request.contentType !== null) {
|
|
8
|
+
d.contentType = request.contentType;
|
|
9
|
+
}
|
|
10
|
+
if (request.params !== null) {
|
|
11
|
+
d.params = { ...request.params };
|
|
12
|
+
}
|
|
13
|
+
return d;
|
|
14
|
+
}
|
|
15
|
+
// Numeric per-segment comparison; shorter versions padded with zeros (1.9.0 < 1.10.0, 1.0 < 1.0.1).
|
|
16
|
+
// Ties broken by description, mirroring the Python MigrationFile.__lt__.
|
|
17
|
+
export function compareMigrationFiles(a, b) {
|
|
18
|
+
const av = a.metadata.version.split(".").map(Number);
|
|
19
|
+
const bv = b.metadata.version.split(".").map(Number);
|
|
20
|
+
const len = Math.max(av.length, bv.length);
|
|
21
|
+
for (let i = 0; i < len; i++) {
|
|
22
|
+
const diff = (av[i] ?? 0) - (bv[i] ?? 0);
|
|
23
|
+
if (diff !== 0) {
|
|
24
|
+
return diff;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (a.metadata.description < b.metadata.description) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
if (a.metadata.description > b.metadata.description) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35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,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACpD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACpD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MigrationFile, MigrationFileContents, MigrationFileRequestDefinition } from "./model.js";
|
|
2
|
+
export declare class MigrationTemplateResolver {
|
|
3
|
+
private readonly properties;
|
|
4
|
+
constructor(properties: Readonly<Record<string, string>>);
|
|
5
|
+
validate(files: readonly MigrationFile[]): void;
|
|
6
|
+
resolve(definition: MigrationFileRequestDefinition): MigrationFileRequestDefinition;
|
|
7
|
+
resolveContents(contents: MigrationFileContents): MigrationFileContents;
|
|
8
|
+
private substitute;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const PLACEHOLDER_PATTERN = /#\{([a-zA-Z0-9._-]+)\}/g;
|
|
2
|
+
export class MigrationTemplateResolver {
|
|
3
|
+
properties;
|
|
4
|
+
constructor(properties) {
|
|
5
|
+
this.properties = properties;
|
|
6
|
+
}
|
|
7
|
+
// Collects ALL missing variables before throwing.
|
|
8
|
+
validate(files) {
|
|
9
|
+
const missing = new Set();
|
|
10
|
+
for (const file of files) {
|
|
11
|
+
for (const request of file.contents.requests) {
|
|
12
|
+
const texts = [
|
|
13
|
+
request.path,
|
|
14
|
+
request.contentType ?? "",
|
|
15
|
+
request.body ?? "",
|
|
16
|
+
...Object.values(request.params ?? {}),
|
|
17
|
+
];
|
|
18
|
+
for (const text of texts) {
|
|
19
|
+
for (const match of text.matchAll(PLACEHOLDER_PATTERN)) {
|
|
20
|
+
const key = match[1];
|
|
21
|
+
if (key !== undefined && !Object.hasOwn(this.properties, key)) {
|
|
22
|
+
missing.add(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (missing.size > 0) {
|
|
29
|
+
throw new Error(`migration files reference template variables with no matching properties: ${[...missing].join(", ")}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Substitutes #{varName} in path, contentType, params values, body — NOT method.
|
|
33
|
+
resolve(definition) {
|
|
34
|
+
return {
|
|
35
|
+
method: definition.method,
|
|
36
|
+
path: this.substitute(definition.path),
|
|
37
|
+
contentType: definition.contentType !== null ? this.substitute(definition.contentType) : null,
|
|
38
|
+
params: definition.params !== null
|
|
39
|
+
? Object.fromEntries(Object.entries(definition.params).map(([k, v]) => [k, this.substitute(v)]))
|
|
40
|
+
: null,
|
|
41
|
+
body: definition.body !== null ? this.substitute(definition.body) : null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
resolveContents(contents) {
|
|
45
|
+
return { requests: contents.requests.map((r) => this.resolve(r)) };
|
|
46
|
+
}
|
|
47
|
+
substitute(text) {
|
|
48
|
+
return text.replace(PLACEHOLDER_PATTERN, (_match, key) => {
|
|
49
|
+
const value = Object.hasOwn(this.properties, key) ? this.properties[key] : undefined;
|
|
50
|
+
if (value === undefined) {
|
|
51
|
+
throw new Error(`unresolved template variable '#{${key}}' — was validate() called?`);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AC;YACrF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,6BAA6B,CAAC,CAAC;YACvF,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "esque-ts",
|
|
3
|
+
"version": "0.2.1-dev.31",
|
|
4
|
+
"description": "Esque (Elasticsearch Stateful Query Executor) — migration management for Elasticsearch, like Flyway for ES clusters",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"esque": "dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/esque.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/loesak/esque.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"lint": "biome ci src tests",
|
|
27
|
+
"format": "biome format --write src tests",
|
|
28
|
+
"test": "node --import tsx --test tests/*.test.ts",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@elastic/elasticsearch": "^9.0.0",
|
|
33
|
+
"commander": "^14.0.0",
|
|
34
|
+
"yaml": "^2.7.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "^2.0.0",
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"tsx": "^4.19.0",
|
|
40
|
+
"typescript": "^5.7.0"
|
|
41
|
+
}
|
|
42
|
+
}
|