Skip to content

Commit

Permalink
fix: bump pb
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Aug 27, 2024
1 parent ed747c6 commit 440e057
Show file tree
Hide file tree
Showing 11 changed files with 459 additions and 419 deletions.
2 changes: 1 addition & 1 deletion packages/blog-platform/library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const allowCommitsFromSameSigners =
(document: Documents<any>) => async (props: CanPerformOperations<any>) => {
// allow all operations if the are signed by the same authors
// i.e. for all the related commits ('next') the signatures should be the same
const previousCommits = props.entry.next;
const previousCommits = props.entry.meta.next;
for (const commit of previousCommits) {
const prevSignatures = (await document.log.log.get(commit))
?.signatures;
Expand Down
2 changes: 1 addition & 1 deletion packages/file-share/library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class Files extends Program<Args> {
local: true,
remote: {
throwOnMissing: true,
sync: true, // sync here because this, because we might want to access it offline, even though we are not replicators
replicate: true, // sync here because this, because we might want to access it offline, even though we are not replicators
},
}
);
Expand Down
22 changes: 8 additions & 14 deletions packages/live-streaming/frontend/src/media/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ import {
} from "@peerbit/document";
import { Program } from "@peerbit/program";
import { v4 as uuid } from "uuid";
import { write, length } from "@protobufjs/utf8";
import { concat } from "uint8arrays";
import { Entry } from "@peerbit/log";
import { randomBytes } from "@peerbit/crypto";
import { ReplicationOptions } from "@peerbit/shared-log";

const utf8Encode = (value: string) => {
const l = length(value);
const arr = new Uint8Array(l);
write(value, arr, 0);
return arr;
};
import { createDocumentDomain, CustomDomain } from "./domain";

@variant(0)
export class Chunk {
Expand Down Expand Up @@ -144,13 +136,12 @@ export class MediaStreamInfo {

type Args = {
replicate?: ReplicationOptions;
sync?: (entry: Entry<any>) => boolean;
};

@variant("track-source")
export abstract class TrackSource {
@field({ type: Documents })
private _chunks: Documents<Chunk, ChunkIndexable>;
private _chunks: Documents<Chunk, ChunkIndexable, CustomDomain>;

constructor() {
this._chunks = new Documents({
Expand Down Expand Up @@ -187,7 +178,11 @@ export abstract class TrackSource {
},
},
replicate: args?.replicate,
sync: args?.sync,
domain: createDocumentDomain(this.chunks, {
fromValue: (value) => Number(value.timestamp),
fromMissing: (entry) =>
Number(entry.meta.clock.timestamp.wallTime / BigInt(1e6)),
}),
});
}

Expand Down Expand Up @@ -339,12 +334,11 @@ export class MediaStreamDB extends Program<Args> {
},
canOpen: (_) => Promise.resolve(false), // dont open subdbs by opening this db
replicate: args?.replicate,
sync: args?.sync,
});
}

async getLatest(
options?: SearchOptions<Track<AudioStreamDB | WebcodecsStreamDB>>
options?: SearchOptions<Track<AudioStreamDB | WebcodecsStreamDB>, any>
): Promise<Track<AudioStreamDB | WebcodecsStreamDB>[]> {
const latest = await this.streams.index.search(
new SearchRequest({
Expand Down
47 changes: 47 additions & 0 deletions packages/live-streaming/frontend/src/media/domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Entry, ShallowEntry } from "@peerbit/log";
import { type ReplicationDomain } from "@peerbit/shared-log";
import { Documents, type Operation, isPutOperation } from "@peerbit/document";

type RangeArgs = { from: number; to: number };
export type CustomDomain = ReplicationDomain<RangeArgs, Operation>;

export const createDocumentDomain = <T extends object>(
db: Documents<T, any, CustomDomain>,
options: {
fromValue: (value: T) => number;
fromMissing?: (entry: ShallowEntry | Entry<Operation>) => number;
}
): CustomDomain => {
const fromValue = options.fromValue;
const fromMissing = options.fromMissing || (() => 0xffffffff);
return {
type: "custom",
fromArgs(args, log) {
if (!args) {
return { offset: log.node.identity.publicKey };
}
return {
offset: args.from,
length: args.to - args.from,
};
},
fromEntry: async (entry) => {
const item = await (entry instanceof ShallowEntry
? await db.log.log.get(entry.hash)
: entry
)?.getPayloadValue();
if (!item) {
// @eslint-ignore no-console
console.error("Item not found");
return fromMissing(entry);
}

if (isPutOperation(item)) {
const document = db.index.valueEncoding.decoder(item.data);
return fromValue(document);
}

return fromMissing(entry);
},
};
};
3 changes: 1 addition & 2 deletions packages/live-streaming/frontend/src/media/viewer/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export const View = (args: DBArgs | IdentityArgs) => {
.then(() => {
updateStreamChoice();
videoStream.current.getLatest({
remote: { sync: true },
remote: { replicate: true },
});
})
.catch((e) => {
Expand Down Expand Up @@ -648,7 +648,6 @@ export const View = (args: DBArgs | IdentityArgs) => {
replicate: {
factor: 1,
},
sync: () => true,
},
existing: "reuse",
})
Expand Down
2 changes: 1 addition & 1 deletion packages/many-chat-rooms/frontend/src/Lobby.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Lobby = () => {
);

lobby.program.rooms.index
.search(new SearchRequest(), { remote: { sync: true } })
.search(new SearchRequest(), { remote: { replicate: true } })
.then((results) => {
addToLobby(results, true);
})
Expand Down
2 changes: 1 addition & 1 deletion packages/many-chat-rooms/frontend/src/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const Room = () => {

room.program.messages.index
.search(new SearchRequest({ query: [] }), {
remote: { sync: true },
remote: { replicate: true },
})
.then((results) => {
results.forEach(addPostToView);
Expand Down
2 changes: 1 addition & 1 deletion packages/one-chat-room/frontend/src/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const Room = () => {

room.program.messages.index
.search(new SearchRequest({ query: [] }), {
remote: { sync: true },
remote: { replicate: true },
})
.then((results) => {
results.forEach(addPostToView);
Expand Down
4 changes: 2 additions & 2 deletions packages/one-chat-room/frontend/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class Room extends Program<Args> {
}),
{
remote: {
sync: true,
replicate: true,
},
local: true,
}
Expand Down Expand Up @@ -264,7 +264,7 @@ export class Room extends Program<Args> {
}),
{
remote: {
sync: true,
replicate: true,
},
local: true,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/social-media-app/frontend/src/room/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export const Room = (properties: { room: RoomDB }) => {
(
await room.elements.index.search(
new SearchRequest({ query: [] }),
{ remote: { sync: true } }
{ remote: { replicate: true } }
)
).length
);
Expand Down
Loading

0 comments on commit 440e057

Please sign in to comment.