tablinum 0.1.1 → 0.2.0

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.
Files changed (58) hide show
  1. package/README.md +124 -1
  2. package/dist/brands.d.ts +5 -0
  3. package/dist/crud/collection-handle.d.ts +5 -5
  4. package/dist/crud/query-builder.d.ts +4 -13
  5. package/dist/crud/watch.d.ts +0 -10
  6. package/dist/db/create-tablinum.d.ts +7 -0
  7. package/dist/db/database-handle.d.ts +22 -1
  8. package/dist/db/epoch.d.ts +48 -0
  9. package/dist/db/invite.d.ts +8 -0
  10. package/dist/db/key-rotation.d.ts +24 -0
  11. package/dist/db/members.d.ts +24 -0
  12. package/dist/db/runtime-config.d.ts +16 -0
  13. package/dist/index.d.ts +8 -1
  14. package/dist/index.js +1552 -820
  15. package/dist/layers/EpochStoreLive.d.ts +6 -0
  16. package/dist/layers/GiftWrapLive.d.ts +5 -0
  17. package/dist/layers/IdentityLive.d.ts +5 -0
  18. package/dist/layers/PublishQueueLive.d.ts +5 -0
  19. package/dist/layers/RelayLive.d.ts +3 -0
  20. package/dist/layers/StorageLive.d.ts +4 -0
  21. package/dist/layers/SyncStatusLive.d.ts +3 -0
  22. package/dist/layers/TablinumLive.d.ts +5 -0
  23. package/dist/layers/index.d.ts +8 -0
  24. package/dist/schema/field.d.ts +0 -1
  25. package/dist/schema/types.d.ts +0 -4
  26. package/dist/services/Config.d.ts +16 -0
  27. package/dist/services/EpochStore.d.ts +6 -0
  28. package/dist/services/GiftWrap.d.ts +6 -0
  29. package/dist/services/Identity.d.ts +6 -0
  30. package/dist/services/PublishQueue.d.ts +6 -0
  31. package/dist/services/Relay.d.ts +6 -0
  32. package/dist/services/Storage.d.ts +6 -0
  33. package/dist/services/Sync.d.ts +6 -0
  34. package/dist/services/SyncStatus.d.ts +6 -0
  35. package/dist/services/Tablinum.d.ts +7 -0
  36. package/dist/services/index.d.ts +10 -0
  37. package/dist/storage/idb.d.ts +11 -2
  38. package/dist/storage/lww.d.ts +0 -5
  39. package/dist/storage/records-store.d.ts +0 -7
  40. package/dist/svelte/collection.svelte.d.ts +9 -6
  41. package/dist/svelte/deferred.d.ts +7 -0
  42. package/dist/svelte/index.svelte.d.ts +6 -6
  43. package/dist/svelte/index.svelte.js +1881 -1023
  44. package/dist/svelte/query.svelte.d.ts +6 -6
  45. package/dist/svelte/tablinum.svelte.d.ts +35 -0
  46. package/dist/sync/gift-wrap.d.ts +6 -2
  47. package/dist/sync/negentropy.d.ts +1 -1
  48. package/dist/sync/publish-queue.d.ts +3 -2
  49. package/dist/sync/relay.d.ts +9 -2
  50. package/dist/sync/sync-service.d.ts +5 -2
  51. package/dist/sync/sync-status.d.ts +1 -0
  52. package/dist/utils/uuid.d.ts +0 -1
  53. package/package.json +1 -1
  54. package/dist/main.d.ts +0 -1
  55. package/dist/storage/events-store.d.ts +0 -6
  56. package/dist/storage/giftwraps-store.d.ts +0 -6
  57. package/dist/svelte/database.svelte.d.ts +0 -15
  58. package/dist/svelte/live-query.svelte.d.ts +0 -8
@@ -0,0 +1,6 @@
1
+ import { Layer } from "effect";
2
+ import { EpochStore } from "../services/EpochStore.ts";
3
+ import { Config } from "../services/Config.ts";
4
+ import { Identity } from "../services/Identity.ts";
5
+ import { Storage } from "../services/Storage.ts";
6
+ export declare const EpochStoreLive: Layer.Layer<EpochStore, import("../errors.ts").StorageError, Config | Identity | Storage>;
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { GiftWrap } from "../services/GiftWrap.ts";
3
+ import { Identity } from "../services/Identity.ts";
4
+ import { EpochStore } from "../services/EpochStore.ts";
5
+ export declare const GiftWrapLive: Layer.Layer<GiftWrap, never, Identity | EpochStore>;
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { Identity } from "../services/Identity.ts";
3
+ import { Config } from "../services/Config.ts";
4
+ import { Storage } from "../services/Storage.ts";
5
+ export declare const IdentityLive: Layer.Layer<Identity, import("../errors.ts").StorageError | import("../errors.ts").CryptoError, Config | Storage>;
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { PublishQueue } from "../services/PublishQueue.ts";
3
+ import { Storage } from "../services/Storage.ts";
4
+ import { Relay } from "../services/Relay.ts";
5
+ export declare const PublishQueueLive: Layer.Layer<PublishQueue, import("../errors.ts").StorageError, Storage | Relay>;
@@ -0,0 +1,3 @@
1
+ import { Layer } from "effect";
2
+ import { Relay } from "../services/Relay.ts";
3
+ export declare const RelayLive: Layer.Layer<Relay, never, never>;
@@ -0,0 +1,4 @@
1
+ import { Layer } from "effect";
2
+ import { Storage } from "../services/Storage.ts";
3
+ import { Config } from "../services/Config.ts";
4
+ export declare const StorageLive: Layer.Layer<Storage, import("../errors.ts").StorageError, Config>;
@@ -0,0 +1,3 @@
1
+ import { Layer } from "effect";
2
+ import { SyncStatus } from "../services/SyncStatus.ts";
3
+ export declare const SyncStatusLive: Layer.Layer<SyncStatus, never, never>;
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { StorageError } from "../errors.ts";
3
+ import { Tablinum } from "../services/Tablinum.ts";
4
+ import { Config } from "../services/Config.ts";
5
+ export declare const TablinumLive: Layer.Layer<Tablinum, StorageError | import("../errors.ts").CryptoError, Config>;
@@ -0,0 +1,8 @@
1
+ export { IdentityLive } from "./IdentityLive.ts";
2
+ export { EpochStoreLive } from "./EpochStoreLive.ts";
3
+ export { StorageLive } from "./StorageLive.ts";
4
+ export { RelayLive } from "./RelayLive.ts";
5
+ export { GiftWrapLive } from "./GiftWrapLive.ts";
6
+ export { PublishQueueLive } from "./PublishQueueLive.ts";
7
+ export { SyncStatusLive } from "./SyncStatusLive.ts";
8
+ export { TablinumLive } from "./TablinumLive.ts";
@@ -4,7 +4,6 @@ export interface FieldDef<out T = unknown> {
4
4
  readonly kind: FieldKind;
5
5
  readonly isOptional: boolean;
6
6
  readonly isArray: boolean;
7
- /** Phantom type carrier — never read at runtime. */
8
7
  readonly _T?: T;
9
8
  }
10
9
  export declare const field: {
@@ -1,14 +1,10 @@
1
1
  import type { CollectionDef, CollectionFields } from "./collection.ts";
2
2
  import type { FieldDef } from "./field.ts";
3
- /** Extract the TypeScript type from a FieldDef phantom. */
4
3
  export type InferFieldType<F> = F extends FieldDef<infer T> ? T : never;
5
- /** Infer the full record type from a CollectionDef, including the auto-injected `id`. */
6
4
  export type InferRecord<C> = C extends CollectionDef<infer F> ? {
7
5
  readonly id: string;
8
6
  } & {
9
7
  readonly [K in keyof F]: InferFieldType<F[K]>;
10
8
  } : never;
11
- /** A schema configuration mapping collection names to their definitions. */
12
9
  export type SchemaConfig = Record<string, CollectionDef<CollectionFields>>;
13
- /** Extract indexed field names from a CollectionDef. */
14
10
  export type IndexedFields<C> = C extends CollectionDef<infer _F> ? C["indices"][number] : never;
@@ -0,0 +1,16 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { ResolvedRuntimeConfig } from "../db/runtime-config.ts";
3
+ import type { SchemaConfig } from "../schema/types.ts";
4
+ export interface TablinumConfigShape extends ResolvedRuntimeConfig {
5
+ readonly schema: SchemaConfig;
6
+ readonly onSyncError?: ((error: Error) => void) | undefined;
7
+ readonly onRemoved?: ((info: {
8
+ epochId: string;
9
+ removedBy: string;
10
+ }) => void) | undefined;
11
+ readonly onMembersChanged?: (() => void) | undefined;
12
+ }
13
+ declare const Config_base: ServiceMap.ServiceClass<Config, "tablinum/Config", TablinumConfigShape>;
14
+ export declare class Config extends Config_base {
15
+ }
16
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { EpochStore as EpochStoreShape } from "../db/epoch.ts";
3
+ declare const EpochStore_base: ServiceMap.ServiceClass<EpochStore, "tablinum/EpochStore", EpochStoreShape>;
4
+ export declare class EpochStore extends EpochStore_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { GiftWrapHandle } from "../sync/gift-wrap.ts";
3
+ declare const GiftWrap_base: ServiceMap.ServiceClass<GiftWrap, "tablinum/GiftWrap", GiftWrapHandle>;
4
+ export declare class GiftWrap extends GiftWrap_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { Identity as IdentityShape } from "../db/identity.ts";
3
+ declare const Identity_base: ServiceMap.ServiceClass<Identity, "tablinum/Identity", IdentityShape>;
4
+ export declare class Identity extends Identity_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { PublishQueueHandle } from "../sync/publish-queue.ts";
3
+ declare const PublishQueue_base: ServiceMap.ServiceClass<PublishQueue, "tablinum/PublishQueue", PublishQueueHandle>;
4
+ export declare class PublishQueue extends PublishQueue_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { RelayHandle } from "../sync/relay.ts";
3
+ declare const Relay_base: ServiceMap.ServiceClass<Relay, "tablinum/Relay", RelayHandle>;
4
+ export declare class Relay extends Relay_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { IDBStorageHandle } from "../storage/idb.ts";
3
+ declare const Storage_base: ServiceMap.ServiceClass<Storage, "tablinum/Storage", IDBStorageHandle>;
4
+ export declare class Storage extends Storage_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { SyncHandle } from "../sync/sync-service.ts";
3
+ declare const Sync_base: ServiceMap.ServiceClass<Sync, "tablinum/Sync", SyncHandle>;
4
+ export declare class Sync extends Sync_base {
5
+ }
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { SyncStatusHandle } from "../sync/sync-status.ts";
3
+ declare const SyncStatus_base: ServiceMap.ServiceClass<SyncStatus, "tablinum/SyncStatus", SyncStatusHandle>;
4
+ export declare class SyncStatus extends SyncStatus_base {
5
+ }
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ServiceMap } from "effect";
2
+ import type { DatabaseHandle } from "../db/database-handle.ts";
3
+ import type { SchemaConfig } from "../schema/types.ts";
4
+ declare const Tablinum_base: ServiceMap.ServiceClass<Tablinum, "tablinum/Tablinum", DatabaseHandle<SchemaConfig>>;
5
+ export declare class Tablinum extends Tablinum_base {
6
+ }
7
+ export {};
@@ -0,0 +1,10 @@
1
+ export { Config, type TablinumConfigShape } from "./Config.ts";
2
+ export { Identity } from "./Identity.ts";
3
+ export { EpochStore } from "./EpochStore.ts";
4
+ export { Storage } from "./Storage.ts";
5
+ export { Relay } from "./Relay.ts";
6
+ export { GiftWrap } from "./GiftWrap.ts";
7
+ export { PublishQueue } from "./PublishQueue.ts";
8
+ export { SyncStatus } from "./SyncStatus.ts";
9
+ export { Sync } from "./Sync.ts";
10
+ export { Tablinum } from "./Tablinum.ts";
@@ -1,6 +1,8 @@
1
1
  import { Effect, Scope } from "effect";
2
+ import type { NostrEvent } from "nostr-tools/pure";
2
3
  import { StorageError } from "../errors.ts";
3
4
  import type { SchemaConfig } from "../schema/types.ts";
5
+ import type { DatabaseName } from "../brands.ts";
4
6
  export interface StoredEvent {
5
7
  readonly id: string;
6
8
  readonly collection: string;
@@ -8,10 +10,12 @@ export interface StoredEvent {
8
10
  readonly kind: "create" | "update" | "delete";
9
11
  readonly data: Record<string, unknown> | null;
10
12
  readonly createdAt: number;
13
+ readonly author?: string | undefined;
11
14
  }
12
15
  export interface StoredGiftWrap {
13
16
  readonly id: string;
14
- readonly event: Record<string, unknown>;
17
+ readonly eventId?: string;
18
+ readonly event?: NostrEvent;
15
19
  readonly createdAt: number;
16
20
  }
17
21
  export interface IDBStorageHandle {
@@ -30,6 +34,11 @@ export interface IDBStorageHandle {
30
34
  readonly putGiftWrap: (gw: StoredGiftWrap) => Effect.Effect<void, StorageError>;
31
35
  readonly getGiftWrap: (id: string) => Effect.Effect<StoredGiftWrap | undefined, StorageError>;
32
36
  readonly getAllGiftWraps: () => Effect.Effect<ReadonlyArray<StoredGiftWrap>, StorageError>;
37
+ readonly deleteGiftWrap: (id: string) => Effect.Effect<void, StorageError>;
38
+ readonly stripGiftWrapBlob: (id: string) => Effect.Effect<void, StorageError>;
39
+ readonly deleteEvent: (id: string) => Effect.Effect<void, StorageError>;
40
+ readonly getMeta: (key: string) => Effect.Effect<unknown | undefined, StorageError>;
41
+ readonly putMeta: (key: string, value: unknown) => Effect.Effect<void, StorageError>;
33
42
  readonly close: () => Effect.Effect<void>;
34
43
  }
35
- export declare function openIDBStorage(dbName: string | undefined, schema: SchemaConfig): Effect.Effect<IDBStorageHandle, StorageError, Scope.Scope>;
44
+ export declare function openIDBStorage(dbName: DatabaseName, schema: SchemaConfig): Effect.Effect<IDBStorageHandle, StorageError, Scope.Scope>;
@@ -2,9 +2,4 @@ export interface EventMeta {
2
2
  readonly id: string;
3
3
  readonly createdAt: number;
4
4
  }
5
- /**
6
- * Last-write-wins resolution.
7
- * Higher `createdAt` wins. Ties broken by lowest event ID (lexicographic).
8
- * Returns the winner.
9
- */
10
5
  export declare function resolveWinner<T extends EventMeta>(existing: T | null, incoming: T): T;
@@ -1,12 +1,5 @@
1
1
  import { Effect } from "effect";
2
2
  import type { IDBStorageHandle, StoredEvent } from "./idb.ts";
3
3
  import type { StorageError } from "../errors.ts";
4
- /**
5
- * Apply an event to the records store using LWW resolution.
6
- * Returns true if the incoming event won and the record was updated.
7
- */
8
4
  export declare function applyEvent(storage: IDBStorageHandle, event: StoredEvent): Effect.Effect<boolean, StorageError>;
9
- /**
10
- * Rebuild the records store by clearing it and replaying all events.
11
- */
12
5
  export declare function rebuild(storage: IDBStorageHandle, collections: ReadonlyArray<string>): Effect.Effect<void, StorageError>;
@@ -4,17 +4,20 @@ import type { CollectionHandle } from "../crud/collection-handle.ts";
4
4
  import { type SvelteWhereClause, type SvelteOrderByBuilder } from "./query.svelte.ts";
5
5
  export declare class Collection<C extends CollectionDef<CollectionFields>> {
6
6
  #private;
7
- items: any;
8
- error: any;
9
- constructor(handle: CollectionHandle<C>);
7
+ error: Error | null;
8
+ /** @internal */
9
+ _bind(handle: CollectionHandle<C>): void;
10
+ /** @internal */
11
+ _fail(err: Error): void;
10
12
  add: (data: Omit<InferRecord<C>, "id">) => Promise<string>;
11
13
  update: (id: string, data: Partial<Omit<InferRecord<C>, "id">>) => Promise<void>;
12
14
  delete: (id: string) => Promise<void>;
13
- get: (id: string) => Promise<InferRecord<C>>;
15
+ get(): Promise<ReadonlyArray<InferRecord<C>>>;
16
+ get(id: string): Promise<InferRecord<C>>;
14
17
  first: () => Promise<InferRecord<C> | null>;
15
18
  count: () => Promise<number>;
16
19
  where: (field: string & keyof Omit<InferRecord<C>, "id">) => SvelteWhereClause<InferRecord<C>>;
17
20
  orderBy: (field: string & keyof Omit<InferRecord<C>, "id">) => SvelteOrderByBuilder<InferRecord<C>>;
18
- /** @internal Called by Database.close() */
19
- _destroy(): void;
21
+ /** @internal */
22
+ _destroy(reason?: Error): void;
20
23
  }
@@ -0,0 +1,7 @@
1
+ export interface Deferred<T> {
2
+ readonly promise: Promise<T>;
3
+ readonly settled: () => boolean;
4
+ readonly resolve: (value?: T | PromiseLike<T>) => void;
5
+ readonly reject: (reason?: unknown) => void;
6
+ }
7
+ export declare function createDeferred<T>(): Deferred<T>;
@@ -1,6 +1,3 @@
1
- import type { SchemaConfig } from "../schema/types.ts";
2
- import { type TablinumConfig } from "../db/create-tablinum.ts";
3
- import { Database } from "./database.svelte.ts";
4
1
  export { field } from "../schema/field.ts";
5
2
  export { collection } from "../schema/collection.ts";
6
3
  export type { CollectionDef, CollectionFields } from "../schema/collection.ts";
@@ -8,9 +5,12 @@ export type { FieldDef, FieldKind } from "../schema/field.ts";
8
5
  export type { InferRecord, SchemaConfig } from "../schema/types.ts";
9
6
  export type { TablinumConfig } from "../db/create-tablinum.ts";
10
7
  export type { SyncStatus } from "../db/database-handle.ts";
8
+ export type { RelayStatus } from "../sync/relay.ts";
9
+ export { encodeInvite, decodeInvite } from "../db/invite.ts";
10
+ export type { Invite } from "../db/invite.ts";
11
+ export type { EpochKey, EpochKeyInput } from "../db/epoch.ts";
12
+ export type { MemberRecord } from "../db/members.ts";
11
13
  export { ValidationError, StorageError, CryptoError, RelayError, SyncError, NotFoundError, ClosedError, } from "../errors.ts";
12
- export { Database } from "./database.svelte.ts";
14
+ export { Tablinum } from "./tablinum.svelte.ts";
13
15
  export { Collection } from "./collection.svelte.ts";
14
- export { LiveQuery } from "./live-query.svelte.ts";
15
16
  export type { SvelteQueryBuilder, SvelteWhereClause, SvelteOrderByBuilder, } from "./query.svelte.ts";
16
- export declare function createTablinum<S extends SchemaConfig>(config: TablinumConfig<S>): Promise<Database<S>>;