Skip to content

Commit d7e83eb

Browse files
Add temporary tanstack playground
1 parent 573dfad commit d7e83eb

File tree

4 files changed

+200
-4
lines changed

4 files changed

+200
-4
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@powersync/temp-tanstackdb",
3+
"private": true,
4+
"version": "0.0.0",
5+
"publishConfig": {
6+
"registry": "https://registry.npmjs.org/",
7+
"access": "public"
8+
},
9+
"description": "API definitions for JourneyApps PowerSync",
10+
"type": "module",
11+
"main": "dist/bundle.mjs",
12+
"module": "dist/bundle.mjs",
13+
"types": "lib/index.d.ts",
14+
"exports": {
15+
".": {
16+
"import": {
17+
"types": "./lib/index.d.ts",
18+
"default": "./dist/bundle.mjs"
19+
},
20+
"require": {
21+
"types": "./dist/index.d.cts",
22+
"require": "./dist/bundle.cjs"
23+
}
24+
}
25+
},
26+
"author": "POWERSYNC",
27+
"license": "Apache-2.0",
28+
"files": [
29+
"lib",
30+
"dist"
31+
],
32+
"repository": {
33+
"type": "git",
34+
"url": "git+https://github.com/powersync-ja/powersync-js.git"
35+
},
36+
"bugs": {
37+
"url": "https://github.com/powersync-ja/powersync-js/issues"
38+
},
39+
"homepage": "https://docs.powersync.com",
40+
"scripts": {
41+
"build": "tsc -b",
42+
"build:prod": "tsc -b",
43+
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
44+
"test": "vitest",
45+
"test:exports": "attw --pack ."
46+
},
47+
"dependencies": {
48+
"@powersync/lite-sdk": "workspace:*",
49+
"@standard-schema/spec": "^1.0.0",
50+
"@tanstack/db": "0.4.20",
51+
"@tanstack/store": "^0.8.0"
52+
},
53+
"devDependencies": {
54+
"@types/node": "^20.5.9"
55+
}
56+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { StandardSchemaV1 } from '@standard-schema/spec';
2+
import { BaseCollectionConfig, CollectionConfig, SyncConfig } from '@tanstack/db';
3+
4+
export type BasePowerSyncCollectionConfig<
5+
TTable extends Record<string, unknown>,
6+
TSchema extends StandardSchemaV1 = never
7+
> = Omit<BaseCollectionConfig<TTable, string, TSchema>, `onInsert` | `onUpdate` | `onDelete` | `getKey`> & {};
8+
9+
export function powerSyncCollectionOptions<
10+
TTable extends Record<string, unknown>,
11+
TSchema extends StandardSchemaV1<any> = never
12+
>(config: BasePowerSyncCollectionConfig<TTable, TSchema>) {
13+
const { ...restConfig } = config;
14+
15+
const sync: SyncConfig<TTable, string> = {
16+
sync: (params) => {
17+
const { begin, write, commit, markReady } = params;
18+
const abortController = new AbortController();
19+
20+
// The sync function needs to be synchronous
21+
async function start() {}
22+
23+
start().catch((error) => console.error(`Could not start syncing process for TODO into TODO`, error));
24+
25+
return () => {
26+
console.info(`Sync has been stopped for TODO into TODO`);
27+
abortController.abort();
28+
};
29+
}
30+
};
31+
32+
const getKey = (record: TTable) => {
33+
if ('id' in record) {
34+
return record.id as string;
35+
}
36+
throw new Error('Record has no id');
37+
};
38+
39+
const outputConfig: CollectionConfig<TTable, string, TSchema> = {
40+
...restConfig,
41+
getKey,
42+
// Syncing should start immediately since we need to monitor the changes for mutations
43+
startSync: true,
44+
sync,
45+
onInsert: async (params) => {},
46+
onUpdate: async (params) => {},
47+
onDelete: async (params) => {},
48+
utils: {}
49+
};
50+
return outputConfig;
51+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "../../tsconfig.base",
3+
"compilerOptions": {
4+
"baseUrl": "./",
5+
"jsx": "react",
6+
"types": ["node"],
7+
"rootDir": "src",
8+
"outDir": "./lib",
9+
"lib": ["esnext"],
10+
"declaration": true,
11+
"module": "NodeNext",
12+
"moduleResolution": "nodenext",
13+
"preserveConstEnums": true,
14+
"esModuleInterop": false,
15+
"skipLibCheck": true,
16+
"strictNullChecks": true
17+
},
18+
"include": ["src/**/*"],
19+
"exclude": ["node_modules", "lib"]
20+
}

pnpm-lock.yaml

Lines changed: 73 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)