@foretag/tanstack-db-surrealdb 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -51,13 +51,12 @@ type Product = {
51
51
 
52
52
  export const products = createCollection(
53
53
  surrealCollection<Product>({
54
- id: 'products',
54
+ db,
55
55
  useLoro: true, // Optional if you need CRDTs
56
- getKey: (collection) => collection.id,
57
56
  table: {
58
- db,
59
57
  name: 'products',
60
- where: expr(eq('store', '123'))
58
+ where: expr(eq('store', '123')),
59
+ fields: ['name', 'price'] // Optional or defaults to *
61
60
  },
62
61
  });
63
62
  )
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CollectionConfig, StandardSchema, UtilsRecord } from '@tanstack/db';
1
+ import { CollectionConfig, UtilsRecord } from '@tanstack/db';
2
2
  import { Container } from 'loro-crdt';
3
3
  import { Surreal, Expr } from 'surrealdb';
4
4
 
@@ -6,26 +6,26 @@ type Id = string;
6
6
  type SurrealObject<T> = T & {
7
7
  id: Id;
8
8
  };
9
- type SurrealField<I> = keyof I | (string & {});
10
- type SyncedRow<T> = SurrealObject<T & {
9
+ type SurrealField<I> = keyof I;
10
+ type SyncedRow = SurrealObject<{
11
11
  sync_deleted?: boolean;
12
12
  updated_at?: Date;
13
13
  }>;
14
14
  type TableOptions<T> = {
15
- db: Surreal;
16
15
  name: string;
17
16
  where?: Expr;
18
- fields?: SurrealField<T>;
17
+ fields?: SurrealField<T>[];
19
18
  };
20
19
  type SurrealCollectionConfig<T extends SurrealObject<object>> = {
21
20
  id?: string;
21
+ db: Surreal;
22
22
  table: TableOptions<T>;
23
23
  useLoro?: boolean;
24
24
  onError?: (e: unknown) => void;
25
25
  };
26
26
 
27
- declare function surrealCollectionOptions<T extends SyncedRow<object>, S extends Record<string, Container> = {
27
+ declare function surrealCollectionOptions<T extends SyncedRow, S extends Record<string, Container> = {
28
28
  [k: string]: never;
29
- }>({ id, useLoro, onError, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, Id, StandardSchema<T>, UtilsRecord>;
29
+ }>({ id, useLoro, onError, db, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, Id, never, UtilsRecord>;
30
30
 
31
31
  export { surrealCollectionOptions };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CollectionConfig, StandardSchema, UtilsRecord } from '@tanstack/db';
1
+ import { CollectionConfig, UtilsRecord } from '@tanstack/db';
2
2
  import { Container } from 'loro-crdt';
3
3
  import { Surreal, Expr } from 'surrealdb';
4
4
 
@@ -6,26 +6,26 @@ type Id = string;
6
6
  type SurrealObject<T> = T & {
7
7
  id: Id;
8
8
  };
9
- type SurrealField<I> = keyof I | (string & {});
10
- type SyncedRow<T> = SurrealObject<T & {
9
+ type SurrealField<I> = keyof I;
10
+ type SyncedRow = SurrealObject<{
11
11
  sync_deleted?: boolean;
12
12
  updated_at?: Date;
13
13
  }>;
14
14
  type TableOptions<T> = {
15
- db: Surreal;
16
15
  name: string;
17
16
  where?: Expr;
18
- fields?: SurrealField<T>;
17
+ fields?: SurrealField<T>[];
19
18
  };
20
19
  type SurrealCollectionConfig<T extends SurrealObject<object>> = {
21
20
  id?: string;
21
+ db: Surreal;
22
22
  table: TableOptions<T>;
23
23
  useLoro?: boolean;
24
24
  onError?: (e: unknown) => void;
25
25
  };
26
26
 
27
- declare function surrealCollectionOptions<T extends SyncedRow<object>, S extends Record<string, Container> = {
27
+ declare function surrealCollectionOptions<T extends SyncedRow, S extends Record<string, Container> = {
28
28
  [k: string]: never;
29
- }>({ id, useLoro, onError, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, Id, StandardSchema<T>, UtilsRecord>;
29
+ }>({ id, useLoro, onError, db, ...config }: SurrealCollectionConfig<T>): CollectionConfig<T, Id, never, UtilsRecord>;
30
30
 
31
31
  export { surrealCollectionOptions };
package/dist/index.js CHANGED
@@ -27,16 +27,13 @@ var import_surrealdb2 = require("surrealdb");
27
27
 
28
28
  // src/table.ts
29
29
  var import_surrealdb = require("surrealdb");
30
- function manageTable({
31
- db,
32
- name,
33
- ...args
34
- }) {
30
+ function manageTable(db, { name, ...args }) {
31
+ const fields = args.fields?.join(", ") ?? "*";
35
32
  const listAll = async () => {
36
- return await db.select(new import_surrealdb.Table(name)).where(args.where).fields(args.fields);
33
+ return await db.select(new import_surrealdb.Table(name)).where(args.where).fields(fields);
37
34
  };
38
35
  const listActive = async () => {
39
- return await db.select(new import_surrealdb.Table(name)).where((0, import_surrealdb.and)(args.where, (0, import_surrealdb.eq)("sync_deleted", false))).fields(args.fields);
36
+ return await db.select(new import_surrealdb.Table(name)).where((0, import_surrealdb.and)(args.where, (0, import_surrealdb.eq)("sync_deleted", false))).fields(fields);
40
37
  };
41
38
  const upsert = async (id, data) => {
42
39
  await db.upsert(id).merge({
@@ -104,6 +101,7 @@ function surrealCollectionOptions({
104
101
  id,
105
102
  useLoro = false,
106
103
  onError,
104
+ db,
107
105
  ...config
108
106
  }) {
109
107
  let loro;
@@ -236,7 +234,7 @@ function surrealCollectionOptions({
236
234
  }
237
235
  prevById = currById;
238
236
  };
239
- const table = manageTable(config.table);
237
+ const table = manageTable(db, config.table);
240
238
  const sync = ({
241
239
  begin,
242
240
  write,
package/dist/index.mjs CHANGED
@@ -9,16 +9,13 @@ import {
9
9
  Table,
10
10
  Uuid
11
11
  } from "surrealdb";
12
- function manageTable({
13
- db,
14
- name,
15
- ...args
16
- }) {
12
+ function manageTable(db, { name, ...args }) {
13
+ const fields = args.fields?.join(", ") ?? "*";
17
14
  const listAll = async () => {
18
- return await db.select(new Table(name)).where(args.where).fields(args.fields);
15
+ return await db.select(new Table(name)).where(args.where).fields(fields);
19
16
  };
20
17
  const listActive = async () => {
21
- return await db.select(new Table(name)).where(and(args.where, eq("sync_deleted", false))).fields(args.fields);
18
+ return await db.select(new Table(name)).where(and(args.where, eq("sync_deleted", false))).fields(fields);
22
19
  };
23
20
  const upsert = async (id, data) => {
24
21
  await db.upsert(id).merge({
@@ -86,6 +83,7 @@ function surrealCollectionOptions({
86
83
  id,
87
84
  useLoro = false,
88
85
  onError,
86
+ db,
89
87
  ...config
90
88
  }) {
91
89
  let loro;
@@ -218,7 +216,7 @@ function surrealCollectionOptions({
218
216
  }
219
217
  prevById = currById;
220
218
  };
221
- const table = manageTable(config.table);
219
+ const table = manageTable(db, config.table);
222
220
  const sync = ({
223
221
  begin,
224
222
  write,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foretag/tanstack-db-surrealdb",
3
3
  "description": "Add Offline / Local First Caching & Syncing to your SurrealDB app with TanstackDB and Loro (CRDTs)",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
@@ -42,11 +42,11 @@
42
42
  "dependencies": {
43
43
  "@tanstack/db": "^0.4.10",
44
44
  "loro-crdt": "^1.8.4",
45
- "surrealdb": "2.0.0-alpha.8"
45
+ "surrealdb": "2.0.0-alpha.9"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@biomejs/biome": "^2.2.6",
49
- "bunup": "^0.14.20",
49
+ "@tanstack/svelte-db": "^0.1.32",
50
50
  "tsup": "^8.5.0"
51
51
  }
52
52
  }