@wells-nelson/data-storage 0.0.0-stage → 0.0.1
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 +79 -2
- package/dist/app.svelte.d.ts +13 -0
- package/dist/app.svelte.js +16 -0
- package/dist/cloud.svelte.d.ts +68 -0
- package/dist/cloud.svelte.js +349 -0
- package/dist/containers.d.ts +74 -0
- package/dist/containers.js +283 -0
- package/dist/database.d.ts +24 -0
- package/dist/database.js +39 -0
- package/dist/dataset.d.ts +18 -0
- package/dist/dataset.js +25 -0
- package/dist/env.d.ts +20 -0
- package/dist/env.js +17 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/persisted.svelte.d.ts +12 -0
- package/dist/persisted.svelte.js +46 -0
- package/dist/prefs.svelte.d.ts +33 -0
- package/dist/prefs.svelte.js +56 -0
- package/dist/schema.d.ts +30 -0
- package/dist/schema.js +24 -0
- package/dist/sql.d.ts +49 -0
- package/dist/sql.js +274 -0
- package/dist/store.d.ts +79 -0
- package/dist/store.js +86 -0
- package/dist/supabase.d.ts +45 -0
- package/dist/supabase.js +77 -0
- package/dist/tombstones.svelte.d.ts +16 -0
- package/dist/tombstones.svelte.js +45 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +5 -0
- package/package.json +56 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RxJsonSchema } from 'rxdb/plugins/core';
|
|
2
|
+
/**
|
|
3
|
+
* Every synced document is flat (strings, numbers, booleans) because the RxDB Supabase
|
|
4
|
+
* replication maps each field 1:1 onto a Postgres column. `updated_at` (client clock, ms) drives
|
|
5
|
+
* last-write-wins conflict resolution.
|
|
6
|
+
*/
|
|
7
|
+
export interface DocBase {
|
|
8
|
+
id: string;
|
|
9
|
+
updated_at: number;
|
|
10
|
+
}
|
|
11
|
+
/** Collection name → document type, e.g. `{ projects: ProjectDoc; tasks: TaskDoc }`. */
|
|
12
|
+
export type DocMap = {
|
|
13
|
+
[name: string]: DocBase;
|
|
14
|
+
};
|
|
15
|
+
export type CollectionName<D extends DocMap> = keyof D & string;
|
|
16
|
+
/** Where a container lives: only on this device, or replicated to Supabase. */
|
|
17
|
+
export type Location = 'local' | 'cloud';
|
|
18
|
+
export type Role = 'viewer' | 'editor' | 'owner';
|
|
19
|
+
/** Lowercase nouns for the container, e.g. `{ singular: 'project', plural: 'projects' }`. */
|
|
20
|
+
export interface Nouns {
|
|
21
|
+
singular: string;
|
|
22
|
+
plural: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The shape of an app's data. A **container** (a project, a list…) owns every other row through
|
|
26
|
+
* `containerField` and is the unit that gets shared, synced and moved between data sets.
|
|
27
|
+
*/
|
|
28
|
+
export interface StoreSchema<D extends DocMap, C extends CollectionName<D> = CollectionName<D>> {
|
|
29
|
+
/** Every collection, parents before children (the container first). */
|
|
30
|
+
collections: readonly CollectionName<D>[];
|
|
31
|
+
schemas: {
|
|
32
|
+
[N in CollectionName<D>]: RxJsonSchema<D[N]>;
|
|
33
|
+
};
|
|
34
|
+
/** The container collection, e.g. 'projects'. */
|
|
35
|
+
container: C;
|
|
36
|
+
/** The field on every other collection pointing at its container, e.g. 'project_id'. */
|
|
37
|
+
containerField: string;
|
|
38
|
+
/** Index `containerField` in TanStack DB (worth it when a collection holds thousands of rows). */
|
|
39
|
+
indexContainerField?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** The container a document belongs to (containers are their own container). */
|
|
42
|
+
export declare function containerIdOf<D extends DocMap>(schema: Pick<StoreSchema<D>, 'container' | 'containerField'>, collection: CollectionName<D>, doc: object): string;
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wells-nelson/data-storage",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Offline-first storage for Wells Nelson apps: RxDB + TanStack DB data sets, Supabase sync of shared containers, tombstones, device prefs and a SQL migration generator.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bnelson729/wells-nelson-components.git",
|
|
9
|
+
"directory": "src/npm/data-storage"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/bnelson729/wells-nelson-components/tree/main/src/npm/data-storage#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/bnelson729/wells-nelson-components/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"svelte": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"svelte": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./sql": {
|
|
25
|
+
"types": "./dist/sql.d.ts",
|
|
26
|
+
"default": "./dist/sql.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "svelte-package -i src/lib -o dist",
|
|
35
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"lint:package": "publint"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@supabase/supabase-js": "^2.100.0",
|
|
41
|
+
"@tanstack/db": "^1.0.0-rc.1.4",
|
|
42
|
+
"@tanstack/rxdb-db-collection": "^1.0.0-rc.1.4",
|
|
43
|
+
"rxdb": "^17.6.0",
|
|
44
|
+
"rxjs": "^7.8.2",
|
|
45
|
+
"svelte": "^5.40.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@supabase/supabase-js": "^2.119.0",
|
|
49
|
+
"@tanstack/db": "^1.0.0-rc.1.4",
|
|
50
|
+
"@tanstack/rxdb-db-collection": "^1.0.0-rc.1.4",
|
|
51
|
+
"rxdb": "^17.6.0",
|
|
52
|
+
"rxjs": "^7.8.2"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"provenance": true
|
|
57
|
+
}
|
|
58
|
+
}
|