@linkedrecords/react 0.1.0 → 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.
- package/.claude/settings.local.json +19 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +22 -19
- package/dist/index.mjs +22 -20
- package/package.json +3 -3
- package/src/index.tsx +1 -1
- package/src/{useAttributes.ts → useRecords.ts} +22 -19
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(git -C /Users/wolf/git/linkedrecords diff main --stat)",
|
|
5
|
+
"Bash(git -C /Users/wolf/git/linkedrecords diff main -- src/browser_sdk/index.ts)",
|
|
6
|
+
"Bash(git -C /Users/wolf/git/linkedrecords diff main -- src/browser_sdk/records_repository.ts)",
|
|
7
|
+
"Bash(git -C /Users/wolf/git/linkedrecords show HEAD:src/browser_sdk/records_repository.ts)",
|
|
8
|
+
"Bash(git -C /Users/wolf/git/linkedrecords show HEAD:src/records/record_query.ts)",
|
|
9
|
+
"Bash(git -C /Users/wolf/git/linkedrecords-react log --oneline -3 -- package-lock.json)",
|
|
10
|
+
"Bash(git -C /Users/wolf/git/linkedrecords-react rm --cached src/useAttributes.ts -q)",
|
|
11
|
+
"Read(//Users/wolf/git/linkedrecords/**)",
|
|
12
|
+
"Read(//Users/wolf/git/linkedrecords/dist/src/browser_sdk/**)",
|
|
13
|
+
"Bash(npm install *)",
|
|
14
|
+
"Bash(npm run *)",
|
|
15
|
+
"Bash(node -e \"import\\('./dist/index.mjs'\\).then\\(m => console.log\\(Object.keys\\(m\\)\\)\\)\")",
|
|
16
|
+
"Bash(node *)"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -17,7 +17,9 @@ declare function LinkedRecordsProvider({ children, serverUrl }: LinkedRecordsPro
|
|
|
17
17
|
interface KVValue {
|
|
18
18
|
[key: string]: KVValue | string | boolean | number | undefined;
|
|
19
19
|
}
|
|
20
|
-
declare function
|
|
20
|
+
declare function useKeyValueRecords(query: any[]): KVValue[];
|
|
21
|
+
/** @deprecated Use useKeyValueRecords instead. */
|
|
22
|
+
declare const useKeyValueAttributes: typeof useKeyValueRecords;
|
|
21
23
|
|
|
22
24
|
declare function useLinkedRecords(): LinkedRecordsContextType;
|
|
23
25
|
|
|
@@ -26,4 +28,4 @@ type UserInfo = {
|
|
|
26
28
|
};
|
|
27
29
|
declare function useUserInfo(): UserInfo | null;
|
|
28
30
|
|
|
29
|
-
export { LinkedRecordsContext, type LinkedRecordsContextType, LinkedRecordsProvider, useKeyValueAttributes, useLinkedRecords, useUserInfo };
|
|
31
|
+
export { LinkedRecordsContext, type LinkedRecordsContextType, LinkedRecordsProvider, useKeyValueAttributes, useKeyValueRecords, useLinkedRecords, useUserInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,9 @@ declare function LinkedRecordsProvider({ children, serverUrl }: LinkedRecordsPro
|
|
|
17
17
|
interface KVValue {
|
|
18
18
|
[key: string]: KVValue | string | boolean | number | undefined;
|
|
19
19
|
}
|
|
20
|
-
declare function
|
|
20
|
+
declare function useKeyValueRecords(query: any[]): KVValue[];
|
|
21
|
+
/** @deprecated Use useKeyValueRecords instead. */
|
|
22
|
+
declare const useKeyValueAttributes: typeof useKeyValueRecords;
|
|
21
23
|
|
|
22
24
|
declare function useLinkedRecords(): LinkedRecordsContextType;
|
|
23
25
|
|
|
@@ -26,4 +28,4 @@ type UserInfo = {
|
|
|
26
28
|
};
|
|
27
29
|
declare function useUserInfo(): UserInfo | null;
|
|
28
30
|
|
|
29
|
-
export { LinkedRecordsContext, type LinkedRecordsContextType, LinkedRecordsProvider, useKeyValueAttributes, useLinkedRecords, useUserInfo };
|
|
31
|
+
export { LinkedRecordsContext, type LinkedRecordsContextType, LinkedRecordsProvider, useKeyValueAttributes, useKeyValueRecords, useLinkedRecords, useUserInfo };
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
LinkedRecordsContext: () => LinkedRecordsContext,
|
|
34
34
|
LinkedRecordsProvider: () => LinkedRecordsProvider,
|
|
35
35
|
useKeyValueAttributes: () => useKeyValueAttributes,
|
|
36
|
+
useKeyValueRecords: () => useKeyValueRecords,
|
|
36
37
|
useLinkedRecords: () => useLinkedRecords,
|
|
37
38
|
useUserInfo: () => useUserInfo
|
|
38
39
|
});
|
|
@@ -51,7 +52,7 @@ function LinkedRecordsProvider({ children, serverUrl }) {
|
|
|
51
52
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LinkedRecordsContext.Provider, { value: { lr }, children });
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
// src/
|
|
55
|
+
// src/useRecords.ts
|
|
55
56
|
var import_react4 = require("react");
|
|
56
57
|
|
|
57
58
|
// src/useLinkedRecords.ts
|
|
@@ -64,11 +65,11 @@ function useLinkedRecords() {
|
|
|
64
65
|
return context;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
// src/
|
|
68
|
+
// src/useRecords.ts
|
|
68
69
|
var import_browser2 = require("@linkedrecords/browser");
|
|
69
|
-
function
|
|
70
|
+
function useKeyValueRecords(query) {
|
|
70
71
|
const { lr } = useLinkedRecords();
|
|
71
|
-
const [
|
|
72
|
+
const [records, setRecords] = (0, import_react4.useState)([]);
|
|
72
73
|
(0, import_react4.useEffect)(() => {
|
|
73
74
|
const unsubscribeFnPromise = new Promise((resolve) => {
|
|
74
75
|
const checkActorId = () => {
|
|
@@ -80,22 +81,22 @@ function useKeyValueAttributes(query) {
|
|
|
80
81
|
};
|
|
81
82
|
checkActorId();
|
|
82
83
|
}).then(() => {
|
|
83
|
-
const queryUnsubscribe = lr.
|
|
84
|
-
|
|
85
|
-
["$it", "$hasDataType", import_browser2.
|
|
84
|
+
const queryUnsubscribe = lr.Record.subscribeToQuery({
|
|
85
|
+
records: [
|
|
86
|
+
["$it", "$hasDataType", import_browser2.KeyValueRecord],
|
|
86
87
|
...query
|
|
87
88
|
]
|
|
88
|
-
}, async ({
|
|
89
|
-
const values = await Promise.all(
|
|
90
|
-
_id:
|
|
91
|
-
...await
|
|
89
|
+
}, async ({ records: records2 }) => {
|
|
90
|
+
const values = await Promise.all(records2.map(async (r) => ({
|
|
91
|
+
_id: r.id,
|
|
92
|
+
...await r.getValue()
|
|
92
93
|
})));
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const newValue = await
|
|
97
|
-
|
|
98
|
-
(v) => v._id ===
|
|
94
|
+
setRecords(values);
|
|
95
|
+
records2.forEach((r) => {
|
|
96
|
+
r.subscribe(async () => {
|
|
97
|
+
const newValue = await r.getValue();
|
|
98
|
+
setRecords((prev) => prev.map(
|
|
99
|
+
(v) => v._id === r.id ? { _id: r.id, ...newValue } : v
|
|
99
100
|
));
|
|
100
101
|
});
|
|
101
102
|
});
|
|
@@ -107,9 +108,10 @@ function useKeyValueAttributes(query) {
|
|
|
107
108
|
return () => {
|
|
108
109
|
unsubscribeFnPromise.then((fn) => fn());
|
|
109
110
|
};
|
|
110
|
-
}, [lr.
|
|
111
|
-
return
|
|
111
|
+
}, [lr.Record, setRecords]);
|
|
112
|
+
return records;
|
|
112
113
|
}
|
|
114
|
+
var useKeyValueAttributes = useKeyValueRecords;
|
|
113
115
|
|
|
114
116
|
// src/useUserInfo.ts
|
|
115
117
|
var import_react5 = require("react");
|
|
@@ -126,6 +128,7 @@ function useUserInfo() {
|
|
|
126
128
|
LinkedRecordsContext,
|
|
127
129
|
LinkedRecordsProvider,
|
|
128
130
|
useKeyValueAttributes,
|
|
131
|
+
useKeyValueRecords,
|
|
129
132
|
useLinkedRecords,
|
|
130
133
|
useUserInfo
|
|
131
134
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ function LinkedRecordsProvider({ children, serverUrl }) {
|
|
|
11
11
|
return /* @__PURE__ */ jsx(LinkedRecordsContext.Provider, { value: { lr }, children });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// src/
|
|
14
|
+
// src/useRecords.ts
|
|
15
15
|
import { useEffect, useState } from "react";
|
|
16
16
|
|
|
17
17
|
// src/useLinkedRecords.ts
|
|
@@ -24,11 +24,11 @@ function useLinkedRecords() {
|
|
|
24
24
|
return context;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// src/
|
|
28
|
-
import {
|
|
29
|
-
function
|
|
27
|
+
// src/useRecords.ts
|
|
28
|
+
import { KeyValueRecord } from "@linkedrecords/browser";
|
|
29
|
+
function useKeyValueRecords(query) {
|
|
30
30
|
const { lr } = useLinkedRecords();
|
|
31
|
-
const [
|
|
31
|
+
const [records, setRecords] = useState([]);
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
const unsubscribeFnPromise = new Promise((resolve) => {
|
|
34
34
|
const checkActorId = () => {
|
|
@@ -40,22 +40,22 @@ function useKeyValueAttributes(query) {
|
|
|
40
40
|
};
|
|
41
41
|
checkActorId();
|
|
42
42
|
}).then(() => {
|
|
43
|
-
const queryUnsubscribe = lr.
|
|
44
|
-
|
|
45
|
-
["$it", "$hasDataType",
|
|
43
|
+
const queryUnsubscribe = lr.Record.subscribeToQuery({
|
|
44
|
+
records: [
|
|
45
|
+
["$it", "$hasDataType", KeyValueRecord],
|
|
46
46
|
...query
|
|
47
47
|
]
|
|
48
|
-
}, async ({
|
|
49
|
-
const values = await Promise.all(
|
|
50
|
-
_id:
|
|
51
|
-
...await
|
|
48
|
+
}, async ({ records: records2 }) => {
|
|
49
|
+
const values = await Promise.all(records2.map(async (r) => ({
|
|
50
|
+
_id: r.id,
|
|
51
|
+
...await r.getValue()
|
|
52
52
|
})));
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const newValue = await
|
|
57
|
-
|
|
58
|
-
(v) => v._id ===
|
|
53
|
+
setRecords(values);
|
|
54
|
+
records2.forEach((r) => {
|
|
55
|
+
r.subscribe(async () => {
|
|
56
|
+
const newValue = await r.getValue();
|
|
57
|
+
setRecords((prev) => prev.map(
|
|
58
|
+
(v) => v._id === r.id ? { _id: r.id, ...newValue } : v
|
|
59
59
|
));
|
|
60
60
|
});
|
|
61
61
|
});
|
|
@@ -67,9 +67,10 @@ function useKeyValueAttributes(query) {
|
|
|
67
67
|
return () => {
|
|
68
68
|
unsubscribeFnPromise.then((fn) => fn());
|
|
69
69
|
};
|
|
70
|
-
}, [lr.
|
|
71
|
-
return
|
|
70
|
+
}, [lr.Record, setRecords]);
|
|
71
|
+
return records;
|
|
72
72
|
}
|
|
73
|
+
var useKeyValueAttributes = useKeyValueRecords;
|
|
73
74
|
|
|
74
75
|
// src/useUserInfo.ts
|
|
75
76
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
@@ -85,6 +86,7 @@ export {
|
|
|
85
86
|
LinkedRecordsContext,
|
|
86
87
|
LinkedRecordsProvider,
|
|
87
88
|
useKeyValueAttributes,
|
|
89
|
+
useKeyValueRecords,
|
|
88
90
|
useLinkedRecords,
|
|
89
91
|
useUserInfo
|
|
90
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linkedrecords/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
18
|
"author": "Oliver Wolf",
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"description": "",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@linkedrecords/browser": "^0.
|
|
22
|
+
"@linkedrecords/browser": "^0.2.0",
|
|
23
23
|
"react": "^19.1.1",
|
|
24
24
|
"react-dom": "^19.1.1"
|
|
25
25
|
},
|
package/src/index.tsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { useLinkedRecords } from "./useLinkedRecords";
|
|
4
|
-
import {
|
|
4
|
+
import { KeyValueRecord } from '@linkedrecords/browser';
|
|
5
5
|
|
|
6
6
|
interface KVValue {
|
|
7
7
|
[key: string]: KVValue | string | boolean | number | undefined;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function useKeyValueRecords(query: any[]): KVValue[] {
|
|
11
11
|
const { lr } = useLinkedRecords();
|
|
12
|
-
const [
|
|
12
|
+
const [ records, setRecords ] = useState<KVValue[]>([]);
|
|
13
13
|
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
const unsubscribeFnPromise = new Promise<void>((resolve) => {
|
|
@@ -22,27 +22,27 @@ export function useKeyValueAttributes(query: any[]): KVValue[] {
|
|
|
22
22
|
};
|
|
23
23
|
checkActorId();
|
|
24
24
|
}).then(() => {
|
|
25
|
-
const queryUnsubscribe = lr.
|
|
26
|
-
|
|
27
|
-
['$it', '$hasDataType',
|
|
25
|
+
const queryUnsubscribe = lr.Record.subscribeToQuery({
|
|
26
|
+
records: [
|
|
27
|
+
['$it', '$hasDataType', KeyValueRecord],
|
|
28
28
|
...query
|
|
29
29
|
],
|
|
30
|
-
}, async ({
|
|
31
|
-
const values = await Promise.all(
|
|
32
|
-
_id:
|
|
33
|
-
...(await
|
|
30
|
+
}, async ({ records }) => {
|
|
31
|
+
const values = await Promise.all(records.map(async (r) => ({
|
|
32
|
+
_id: r.id,
|
|
33
|
+
...(await r.getValue()),
|
|
34
34
|
})));
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
setRecords(values);
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const newValue = await
|
|
38
|
+
records.forEach((r) => {
|
|
39
|
+
r.subscribe(async () => {
|
|
40
|
+
const newValue = await r.getValue();
|
|
41
41
|
|
|
42
42
|
// Use functional update to avoid stale closure
|
|
43
|
-
|
|
44
|
-
v._id ===
|
|
45
|
-
? { _id:
|
|
43
|
+
setRecords(prev => prev.map(v =>
|
|
44
|
+
v._id === r.id
|
|
45
|
+
? { _id: r.id, ...newValue }
|
|
46
46
|
: v
|
|
47
47
|
));
|
|
48
48
|
});
|
|
@@ -57,7 +57,10 @@ export function useKeyValueAttributes(query: any[]): KVValue[] {
|
|
|
57
57
|
return () => {
|
|
58
58
|
unsubscribeFnPromise.then(fn => fn());
|
|
59
59
|
}
|
|
60
|
-
}, [ lr.
|
|
60
|
+
}, [ lr.Record, setRecords ]);
|
|
61
61
|
|
|
62
|
-
return
|
|
62
|
+
return records;
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
/** @deprecated Use useKeyValueRecords instead. */
|
|
66
|
+
export const useKeyValueAttributes = useKeyValueRecords;
|