Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to kv sources #29

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jetstream/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/jetstream",
"version": "3.0.0-3",
"version": "3.0.0-4",
"exports": {
".": "./src/mod.ts",
"./internal": "./src/internal_mod.ts"
Expand Down
4 changes: 2 additions & 2 deletions jetstream/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jetstream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/jetstream",
"version": "3.0.0-3",
"version": "3.0.0-4",
"files": [
"lib/",
"build/src/"
Expand Down
2 changes: 1 addition & 1 deletion jetstream/src/jsmstream_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class StreamAPIImpl extends BaseApiClientImpl implements StreamAPI {
context: string,
src: Partial<StreamSource>,
): void {
const count = src.subject_transforms?.length || 0;
const count = src?.subject_transforms?.length || 0;
if (count > 0) {
const { min, ok } = nci.features.get(
Feature.JS_STREAM_SOURCE_SUBJECT_TRANSFORM,
Expand Down
4 changes: 2 additions & 2 deletions kv/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/kv",
"version": "3.0.0-2",
"version": "3.0.0-3",
"exports": {
".": "./src/mod.ts",
"./internal": "./src/internal_mod.ts"
Expand Down Expand Up @@ -29,6 +29,6 @@
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-18",
"@nats-io/jetstream": "jsr:@nats-io/[email protected]3"
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-4"
}
}
4 changes: 2 additions & 2 deletions kv/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-18",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-18/internal",
"@nats-io/jetstream": "jsr:@nats-io/[email protected]3",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-3/internal",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-4",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-4/internal",
"test_helpers": "../test_helpers/mod.ts",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
Expand Down
81 changes: 36 additions & 45 deletions kv/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kv/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/kv",
"version": "3.0.0-2",
"version": "3.0.0-3",
"files": [
"lib/",
"build/src/"
Expand All @@ -27,7 +27,7 @@
"description": "kv library - this library implements all the base functionality for NATS KV javascript clients",
"dependencies": {
"@nats-io/nats-core": "~3.0.0-18",
"@nats-io/jetstream": "3.0.0-3"
"@nats-io/jetstream": "~3.0.0-4"
},
"devDependencies": {
"@types/node": "^20.11.30",
Expand Down
10 changes: 10 additions & 0 deletions kv/src/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,21 @@ export class Bucket implements KV, KvRemove {
} else if (opts.sources) {
const sources = opts.sources.map((s) => {
const c = Object.assign({}, s) as StreamSource;
const srcBucketName = c.name.startsWith(kvPrefix)
? c.name.substring(kvPrefix.length)
: c.name;
if (!c.name.startsWith(kvPrefix)) {
c.name = `${kvPrefix}${c.name}`;
}
if (!s.external && srcBucketName !== this.bucket) {
c.subject_transforms = [
{ src: `$KV.${srcBucketName}.>`, dest: `$KV.${this.bucket}.>` },
];
}
return c;
});
sc.sources = sources as unknown[] as StreamSource[];
sc.subjects = [this.subjectForBucket()];
} else {
sc.subjects = [this.subjectForBucket()];
}
Expand Down
29 changes: 29 additions & 0 deletions kv/tests/kv_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,3 +2269,32 @@ Deno.test("kv - replicas", async () => {
await nc.close();
await NatsServer.stopAll(servers, true);
});

Deno.test("kv - sourced", async () => {
const { ns, nc } = await _setup(
connect,
jetstreamServerConf({}),
);
if (await notCompatible(ns, nc, "2.6.3")) {
return;
}

const js = jetstream(nc);
const kvm = await new Kvm(js);
const source = await kvm.create("source");
const target = await kvm.create("target", {
sources: [{ name: "source" }],
});

await source.put("hello", "world");
for (let i = 0; i < 10; i++) {
const v = await target.get("hello");
if (v === null) {
await delay(250);
continue;
}
assertEquals(v.string(), "world");
}

await cleanup(ns, nc);
});
Loading