Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hasundue/lophus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.5
Choose a base ref
...
head repository: hasundue/lophus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.0.6
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 4, 2023

  1. Copy the full SHA
    a57295b View commit details
  2. Copy the full SHA
    2ef24d0 View commit details
  3. chore(main): release 0.0.6

    github-actions[bot] authored and hasundue committed Oct 4, 2023
    Copy the full SHA
    01b3c4a View commit details
Showing with 98 additions and 12 deletions.
  1. +7 −0 CHANGELOG.md
  2. +1 −1 deno.json
  3. +12 −10 nips/01.ts
  4. +78 −1 nips/01_test.ts
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.0.6](https://github.com/hasundue/lophus/compare/0.0.5...0.0.6) (2023-10-04)


### Bug Fixes

* **nips/01:** fix SubscriptionFilter interface ([2ef24d0](https://github.com/hasundue/lophus/commit/2ef24d0a0c3853467043640e79d71a8bfac7ff56))

## [0.0.5](https://github.com/hasundue/lophus/compare/0.0.4...0.0.5) (2023-10-04)


2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"check": "deno check ./**/*.ts",
"test": "deno test -A --no-check",
"build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts",
"dev": "deno fmt && deno lint && deno task -q check && deno task -q test"
"dev": "deno fmt && deno lint && deno task -q check && deno task cache && deno task -q test"
},
"exclude": [
"dist/",
22 changes: 12 additions & 10 deletions nips/01.ts
Original file line number Diff line number Diff line change
@@ -41,16 +41,16 @@ export type EventSerializePrecursor<K extends EventKind = EventKind> = [
export type AnyTag = Tag<string>;
export type IndexedTag = Tag<AlphabetLetter>;

export type Tag<T extends string> = [T, ...TagValueFor[T]];
export type Tag<T extends string> = [T, ...TagContentFor[T]];

export interface TagValueFor extends Record<string, TagValue> {
export interface TagContentFor extends Record<string, TagContent> {
// Event
"e": [EventId, RelayUrl?];
// Public key
"p": [PublicKey, RelayUrl?];
// (Maybe parameterized) replaceable event
"a": [
`${EventKind}:${PublicKey}:${TagValueFor["d"][0]}`,
`${EventKind}:${PublicKey}:${TagValueFor["d"]}`,
RelayUrl?,
] | [
`${EventKind}:${PublicKey}`,
@@ -61,7 +61,11 @@ export interface TagValueFor extends Record<string, TagValue> {
}

// TODO: Tighten the type of TagValue
export type TagValue = (string | undefined)[];
export type TagContent = (string | undefined)[];

export type TagValueFor = {
[T in keyof TagContentFor]: TagContentFor[T][0];
};

export interface TagFor extends Record<number, AnyTag> {
0: AnyTag;
@@ -101,7 +105,6 @@ export type EventMessage<K extends EventKind = EventKind> = [
];
export type OkMessage<B extends boolean = boolean> = [
"OK",

EventId,
B,
OkMessageBody<B>,
@@ -123,17 +126,16 @@ export type OkMessageBodyPrefix =
| "error";

export type SubscriptionFilter<
K extends EventKind = EventKind,
T extends AlphabetLetter = AlphabetLetter,
Ks extends EventKind = EventKind,
Ts extends AlphabetLetter = AlphabetLetter,
> =
& {
ids?: EventId[];
authors?: PublicKey[];
kinds?: K[];
kinds?: Ks[];
}
// TODO: Restrict to 1 tag per filter
& {
[key in `#${T}`]?: TagValueFor[T][];
[T in Ts as `#${T}`]?: TagValueFor[T][];
}
& {
since?: Timestamp;
79 changes: 78 additions & 1 deletion nips/01_test.ts
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
import {} from "./01.ts";
import { describe, it } from "../lib/std/testing.ts";
import { assert } from "../lib/std/assert.ts";
import type { EventId, PublicKey } from "../mod.ts";
import { Timestamp } from "../lib/times.ts";
import { SubscriptionFilter } from "./01.ts";

describe("SubscriptionFilter", () => {
it("valid", () => {
const filter = {
ids: ["" as EventId],
kinds: [0, 1],
authors: ["" as PublicKey],
"#p": ["" as PublicKey],
"#e": ["" as EventId],
"#Z": [""],
since: Timestamp.now,
until: Timestamp.now,
limit: 10,
} satisfies SubscriptionFilter;
assert(filter);
});
it("ids should be an array of EventId", () => {
const filter = {
// @ts-expect-error: ids should be EventId[]
ids: [""],
} satisfies SubscriptionFilter;
assert(filter);
});
it("kinds should be an array of EventKind", () => {
const filter = {
// @ts-expect-error: kinds should be EventKind[]
kinds: [""],
} satisfies SubscriptionFilter;
assert(filter);
});
it("authors should be an array of PublicKey", () => {
const filter = {
// @ts-expect-error: authors should be PublicKey[]
authors: [""],
} satisfies SubscriptionFilter;
assert(filter);
});
it("tag #p should be an array of PublicKey", () => {
const filter = {
// @ts-expect-error: tag #p should be PublicKey[]
"#p": [""],
} satisfies SubscriptionFilter;
assert(filter);
});
it("tag #e should be an array of EventId", () => {
const filter = {
// @ts-expect-error: tag #e should be EventId[]
"#e": [""],
} satisfies SubscriptionFilter;
assert(filter);
});
it("since should be Timestamp", () => {
const filter = {
// @ts-expect-error: since should be Timestamp
since: 0,
} satisfies SubscriptionFilter;
assert(filter);
});
it("until should be Timestamp", () => {
const filter = {
// @ts-expect-error: until should be Timestamp
until: 0,
} satisfies SubscriptionFilter;
assert(filter);
});
it("limit should be number", () => {
const filter = {
// @ts-expect-error: limit should be number
limit: "10",
} satisfies SubscriptionFilter;
assert(filter);
});
});