@open-mercato/queue-provider-local 0.0.0-stage → 0.11.1-develop.8983.1.8f477e3f83

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.
@@ -0,0 +1,2 @@
1
+ [build:queue-provider-local] found 4 entry points
2
+ [build:queue-provider-local] built successfully
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # Open Mercato Local queue provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The default `QUEUE_STRATEGY=local` provider stores jobs in files shared by processes on the same filesystem. `@open-mercato/queue` installs and supports it by default, including for applications that upgrade without an app provider registry.
4
+
5
+ Set `QUEUE_BASE_DIR` to place the files on a durable volume. Explicit `createQueue` options override app provider settings. Existing queue files, locks, and processing behavior carry forward without conversion. When checking routing fingerprints, keep the generated `.queue-storage-id` on the same volume as the jobs. Separate storage volumes must initialize their own identity.
6
+
7
+ For direct Node.js consumers, the package root exports `createLocalQueue` and the `queueDriver` descriptor. Application modules should use the queue host.
package/build.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { dirname } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { buildPackage } from '../../scripts/build-package.mjs'
4
+
5
+ const packageDir = dirname(fileURLToPath(import.meta.url))
6
+
7
+ await buildPackage(packageDir, {
8
+ name: 'queue-provider-local',
9
+ entryPoints: 'src/**/*.ts',
10
+ target: 'node22',
11
+ })
@@ -0,0 +1,10 @@
1
+ import path from "node:path";
2
+ const DEFAULT_LOCAL_QUEUE_BASE_DIR = ".mercato/queue";
3
+ function resolveLocalQueueBaseDir(baseDir) {
4
+ const nodeProcess = globalThis.process;
5
+ return baseDir ?? path.resolve(nodeProcess?.env?.QUEUE_BASE_DIR || DEFAULT_LOCAL_QUEUE_BASE_DIR);
6
+ }
7
+ export {
8
+ resolveLocalQueueBaseDir
9
+ };
10
+ //# sourceMappingURL=base-dir.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/base-dir.ts"],
4
+ "sourcesContent": ["import path from 'node:path'\n\nconst DEFAULT_LOCAL_QUEUE_BASE_DIR = '.mercato/queue'\n\nexport function resolveLocalQueueBaseDir(baseDir?: string): string {\n const nodeProcess = (globalThis as typeof globalThis & { process?: NodeJS.Process }).process\n return baseDir ?? path.resolve(nodeProcess?.env?.QUEUE_BASE_DIR || DEFAULT_LOCAL_QUEUE_BASE_DIR)\n}\n"],
5
+ "mappings": "AAAA,OAAO,UAAU;AAEjB,MAAM,+BAA+B;AAE9B,SAAS,yBAAyB,SAA0B;AACjE,QAAM,cAAe,WAAgE;AACrF,SAAO,WAAW,KAAK,QAAQ,aAAa,KAAK,kBAAkB,4BAA4B;AACjG;",
6
+ "names": []
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { link, mkdir, readFile, realpath, unlink, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import packageMetadata from "../package.json" with { type: "json" };
5
+ import { resolveLocalQueueBaseDir } from "./base-dir.js";
6
+ import { probeLocalQueue } from "./probe.js";
7
+ import { createLocalQueue } from "./strategy.js";
8
+ const storageIdFile = ".queue-storage-id";
9
+ async function readOrCreateStorageId(baseDir) {
10
+ const filename = path.join(baseDir, storageIdFile);
11
+ let identity;
12
+ try {
13
+ identity = await readFile(filename, "utf8");
14
+ } catch (error) {
15
+ if (error.code !== "ENOENT") throw error;
16
+ const candidate = randomUUID();
17
+ const temporary = path.join(baseDir, `${storageIdFile}.${candidate}.tmp`);
18
+ await writeFile(temporary, candidate, { flag: "wx", mode: 384 });
19
+ try {
20
+ await link(temporary, filename);
21
+ } catch (linkError) {
22
+ if (linkError.code !== "EEXIST") throw linkError;
23
+ } finally {
24
+ await unlink(temporary);
25
+ }
26
+ identity = await readFile(filename, "utf8");
27
+ }
28
+ if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(identity)) {
29
+ throw new Error("[internal] Invalid local queue storage identity");
30
+ }
31
+ return identity;
32
+ }
33
+ const queueDriver = {
34
+ contractVersion: 1,
35
+ edition: "oss",
36
+ strategy: "local",
37
+ packageVersion: packageMetadata.version,
38
+ createQueue: createLocalQueue,
39
+ probe: probeLocalQueue,
40
+ async resourceIdentity(name, options) {
41
+ const baseDir = path.resolve(resolveLocalQueueBaseDir(options?.baseDir));
42
+ await mkdir(baseDir, { recursive: true });
43
+ const canonical = await realpath(baseDir);
44
+ const storageId = await readOrCreateStorageId(canonical);
45
+ return createHash("sha256").update(JSON.stringify([storageId, path.join(canonical, name)])).digest("hex");
46
+ }
47
+ };
48
+ export {
49
+ createLocalQueue,
50
+ queueDriver
51
+ };
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import { createHash, randomUUID } from 'node:crypto'\nimport { link, mkdir, readFile, realpath, unlink, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport packageMetadata from '../package.json' with { type: 'json' }\nimport type { DefaultQueueDriver } from '@open-mercato/queue-provider-kit/default-provider'\nimport { resolveLocalQueueBaseDir } from './base-dir'\nimport { probeLocalQueue } from './probe'\nimport { createLocalQueue } from './strategy'\n\nconst storageIdFile = '.queue-storage-id'\n\nasync function readOrCreateStorageId(baseDir: string): Promise<string> {\n const filename = path.join(baseDir, storageIdFile)\n let identity: string\n try {\n identity = await readFile(filename, 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n const candidate = randomUUID()\n const temporary = path.join(baseDir, `${storageIdFile}.${candidate}.tmp`)\n await writeFile(temporary, candidate, { flag: 'wx', mode: 0o600 })\n try {\n await link(temporary, filename)\n } catch (linkError) {\n if ((linkError as NodeJS.ErrnoException).code !== 'EEXIST') throw linkError\n } finally {\n await unlink(temporary)\n }\n identity = await readFile(filename, 'utf8')\n }\n if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(identity)) {\n throw new Error('[internal] Invalid local queue storage identity')\n }\n return identity\n}\n\nexport const queueDriver: DefaultQueueDriver<'local'> = {\n contractVersion: 1,\n edition: 'oss',\n strategy: 'local',\n packageVersion: packageMetadata.version,\n createQueue: createLocalQueue,\n probe: probeLocalQueue,\n async resourceIdentity(name, options) {\n const baseDir = path.resolve(resolveLocalQueueBaseDir(options?.baseDir))\n await mkdir(baseDir, { recursive: true })\n const canonical = await realpath(baseDir)\n const storageId = await readOrCreateStorageId(canonical)\n return createHash('sha256').update(JSON.stringify([storageId, path.join(canonical, name)])).digest('hex')\n },\n}\n\nexport { createLocalQueue }\n"],
5
+ "mappings": "AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,MAAM,OAAO,UAAU,UAAU,QAAQ,iBAAiB;AACnE,OAAO,UAAU;AACjB,OAAO,qBAAqB,kBAAkB,KAAK,EAAE,MAAM,OAAO;AAElE,SAAS,gCAAgC;AACzC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AAEjC,MAAM,gBAAgB;AAEtB,eAAe,sBAAsB,SAAkC;AACrE,QAAM,WAAW,KAAK,KAAK,SAAS,aAAa;AACjD,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,SAAS,UAAU,MAAM;AAAA,EAC5C,SAAS,OAAO;AACd,QAAK,MAAgC,SAAS,SAAU,OAAM;AAC9D,UAAM,YAAY,WAAW;AAC7B,UAAM,YAAY,KAAK,KAAK,SAAS,GAAG,aAAa,IAAI,SAAS,MAAM;AACxE,UAAM,UAAU,WAAW,WAAW,EAAE,MAAM,MAAM,MAAM,IAAM,CAAC;AACjE,QAAI;AACF,YAAM,KAAK,WAAW,QAAQ;AAAA,IAChC,SAAS,WAAW;AAClB,UAAK,UAAoC,SAAS,SAAU,OAAM;AAAA,IACpE,UAAE;AACA,YAAM,OAAO,SAAS;AAAA,IACxB;AACA,eAAW,MAAM,SAAS,UAAU,MAAM;AAAA,EAC5C;AACA,MAAI,CAAC,iDAAiD,KAAK,QAAQ,GAAG;AACpE,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AACA,SAAO;AACT;AAEO,MAAM,cAA2C;AAAA,EACtD,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,UAAU;AAAA,EACV,gBAAgB,gBAAgB;AAAA,EAChC,aAAa;AAAA,EACb,OAAO;AAAA,EACP,MAAM,iBAAiB,MAAM,SAAS;AACpC,UAAM,UAAU,KAAK,QAAQ,yBAAyB,SAAS,OAAO,CAAC;AACvE,UAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AACxC,UAAM,YAAY,MAAM,SAAS,OAAO;AACxC,UAAM,YAAY,MAAM,sBAAsB,SAAS;AACvD,WAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,UAAU,CAAC,WAAW,KAAK,KAAK,WAAW,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK;AAAA,EAC1G;AACF;",
6
+ "names": []
7
+ }
package/dist/probe.js ADDED
@@ -0,0 +1,49 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { emptyProbe, failedProbe } from "@open-mercato/queue-provider-kit/default-provider";
4
+ import { resolveLocalQueueBaseDir } from "./base-dir.js";
5
+ async function probeLocalQueue(queueName, options) {
6
+ const baseDir = resolveLocalQueueBaseDir(options?.baseDir);
7
+ const queueFile = path.join(baseDir, queueName, "queue.json");
8
+ let raw;
9
+ try {
10
+ raw = await readFile(queueFile, "utf8");
11
+ } catch (err) {
12
+ const fsErr = err;
13
+ if (fsErr?.code === "ENOENT") {
14
+ return emptyProbe(queueName, "local");
15
+ }
16
+ return failedProbe(queueName, "local", err);
17
+ }
18
+ let parsed;
19
+ try {
20
+ parsed = JSON.parse(raw);
21
+ } catch (err) {
22
+ return failedProbe(queueName, "local", err);
23
+ }
24
+ if (!Array.isArray(parsed)) {
25
+ return emptyProbe(queueName, "local");
26
+ }
27
+ const now = Date.now();
28
+ let ready = 0;
29
+ let delayedFuture = 0;
30
+ for (const entry of parsed) {
31
+ if (!entry || typeof entry !== "object") continue;
32
+ const availableAt = entry.availableAt;
33
+ if (typeof availableAt !== "string" || availableAt.length === 0) {
34
+ ready++;
35
+ continue;
36
+ }
37
+ const ts = Date.parse(availableAt);
38
+ if (!Number.isFinite(ts) || ts <= now) {
39
+ ready++;
40
+ } else {
41
+ delayedFuture++;
42
+ }
43
+ }
44
+ return { queueName, strategy: "local", ready, delayedFuture, active: 0, error: false };
45
+ }
46
+ export {
47
+ probeLocalQueue
48
+ };
49
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/probe.ts"],
4
+ "sourcesContent": ["import { readFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { emptyProbe, failedProbe, type QueuePendingProbeOptions, type QueuePendingProbeResult } from '@open-mercato/queue-provider-kit/default-provider'\nimport { resolveLocalQueueBaseDir } from './base-dir'\n\nexport async function probeLocalQueue(\n queueName: string,\n options?: QueuePendingProbeOptions,\n): Promise<QueuePendingProbeResult> {\n const baseDir = resolveLocalQueueBaseDir(options?.baseDir)\n const queueFile = path.join(baseDir, queueName, 'queue.json')\n\n let raw: string\n try {\n raw = await readFile(queueFile, 'utf8')\n } catch (err) {\n const fsErr = err as NodeJS.ErrnoException\n if (fsErr?.code === 'ENOENT') {\n return emptyProbe(queueName, 'local')\n }\n return failedProbe(queueName, 'local', err)\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (err) {\n return failedProbe(queueName, 'local', err)\n }\n\n if (!Array.isArray(parsed)) {\n return emptyProbe(queueName, 'local')\n }\n\n const now = Date.now()\n let ready = 0\n let delayedFuture = 0\n\n for (const entry of parsed) {\n if (!entry || typeof entry !== 'object') continue\n const availableAt = (entry as { availableAt?: unknown }).availableAt\n if (typeof availableAt !== 'string' || availableAt.length === 0) {\n ready++\n continue\n }\n const ts = Date.parse(availableAt)\n if (!Number.isFinite(ts) || ts <= now) {\n ready++\n } else {\n delayedFuture++\n }\n }\n\n return { queueName, strategy: 'local', ready, delayedFuture, active: 0, error: false }\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,SAAS,YAAY,mBAAgF;AACrG,SAAS,gCAAgC;AAEzC,eAAsB,gBACpB,WACA,SACkC;AAClC,QAAM,UAAU,yBAAyB,SAAS,OAAO;AACzD,QAAM,YAAY,KAAK,KAAK,SAAS,WAAW,YAAY;AAE5D,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,SAAS,WAAW,MAAM;AAAA,EACxC,SAAS,KAAK;AACZ,UAAM,QAAQ;AACd,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,WAAW,WAAW,OAAO;AAAA,IACtC;AACA,WAAO,YAAY,WAAW,SAAS,GAAG;AAAA,EAC5C;AAEA,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,GAAG;AAAA,EACzB,SAAS,KAAK;AACZ,WAAO,YAAY,WAAW,SAAS,GAAG;AAAA,EAC5C;AAEA,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC1B,WAAO,WAAW,WAAW,OAAO;AAAA,EACtC;AAEA,QAAM,MAAM,KAAK,IAAI;AACrB,MAAI,QAAQ;AACZ,MAAI,gBAAgB;AAEpB,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AACzC,UAAM,cAAe,MAAoC;AACzD,QAAI,OAAO,gBAAgB,YAAY,YAAY,WAAW,GAAG;AAC/D;AACA;AAAA,IACF;AACA,UAAM,KAAK,KAAK,MAAM,WAAW;AACjC,QAAI,CAAC,OAAO,SAAS,EAAE,KAAK,MAAM,KAAK;AACrC;AAAA,IACF,OAAO;AACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,WAAW,UAAU,SAAS,OAAO,eAAe,QAAQ,GAAG,OAAO,MAAM;AACvF;",
6
+ "names": []
7
+ }