@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.
@@ -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 useKeyValueAttributes(query: any[]): KVValue[];
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 useKeyValueAttributes(query: any[]): KVValue[];
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/useAttributes.ts
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/useAttributes.ts
68
+ // src/useRecords.ts
68
69
  var import_browser2 = require("@linkedrecords/browser");
69
- function useKeyValueAttributes(query) {
70
+ function useKeyValueRecords(query) {
70
71
  const { lr } = useLinkedRecords();
71
- const [attributes, setAttributes] = (0, import_react4.useState)([]);
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.Attribute.subscribeToQuery({
84
- attributes: [
85
- ["$it", "$hasDataType", import_browser2.KeyValueAttribute],
84
+ const queryUnsubscribe = lr.Record.subscribeToQuery({
85
+ records: [
86
+ ["$it", "$hasDataType", import_browser2.KeyValueRecord],
86
87
  ...query
87
88
  ]
88
- }, async ({ attributes: attributes2 }) => {
89
- const values = await Promise.all(attributes2.map(async (a) => ({
90
- _id: a.id,
91
- ...await a.getValue()
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
- setAttributes(values);
94
- attributes2.forEach((a) => {
95
- a.subscribe(async () => {
96
- const newValue = await a.getValue();
97
- setAttributes((prev) => prev.map(
98
- (v) => v._id === a.id ? { _id: a.id, ...newValue } : v
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.Attribute, setAttributes]);
111
- return attributes;
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/useAttributes.ts
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/useAttributes.ts
28
- import { KeyValueAttribute } from "@linkedrecords/browser";
29
- function useKeyValueAttributes(query) {
27
+ // src/useRecords.ts
28
+ import { KeyValueRecord } from "@linkedrecords/browser";
29
+ function useKeyValueRecords(query) {
30
30
  const { lr } = useLinkedRecords();
31
- const [attributes, setAttributes] = useState([]);
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.Attribute.subscribeToQuery({
44
- attributes: [
45
- ["$it", "$hasDataType", KeyValueAttribute],
43
+ const queryUnsubscribe = lr.Record.subscribeToQuery({
44
+ records: [
45
+ ["$it", "$hasDataType", KeyValueRecord],
46
46
  ...query
47
47
  ]
48
- }, async ({ attributes: attributes2 }) => {
49
- const values = await Promise.all(attributes2.map(async (a) => ({
50
- _id: a.id,
51
- ...await a.getValue()
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
- setAttributes(values);
54
- attributes2.forEach((a) => {
55
- a.subscribe(async () => {
56
- const newValue = await a.getValue();
57
- setAttributes((prev) => prev.map(
58
- (v) => v._id === a.id ? { _id: a.id, ...newValue } : v
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.Attribute, setAttributes]);
71
- return attributes;
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.1.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": "AGPL-3.0",
19
+ "license": "MIT",
20
20
  "description": "",
21
21
  "dependencies": {
22
- "@linkedrecords/browser": "^0.1.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,5 +1,5 @@
1
1
  export * from './linkedRecordsContext';
2
2
  export * from './LinkedRecordsProvider';
3
- export * from './useAttributes';
3
+ export * from './useRecords';
4
4
  export * from './useLinkedRecords';
5
5
  export * from './useUserInfo';
@@ -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 { KeyValueAttribute } from '@linkedrecords/browser';
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 useKeyValueAttributes(query: any[]): KVValue[] {
10
+ export function useKeyValueRecords(query: any[]): KVValue[] {
11
11
  const { lr } = useLinkedRecords();
12
- const [ attributes, setAttributes ] = useState<KVValue[]>([]);
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.Attribute.subscribeToQuery({
26
- attributes: [
27
- ['$it', '$hasDataType', KeyValueAttribute],
25
+ const queryUnsubscribe = lr.Record.subscribeToQuery({
26
+ records: [
27
+ ['$it', '$hasDataType', KeyValueRecord],
28
28
  ...query
29
29
  ],
30
- }, async ({ attributes }) => {
31
- const values = await Promise.all(attributes.map(async (a) => ({
32
- _id: a.id,
33
- ...(await a.getValue()),
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
- setAttributes(values);
36
+ setRecords(values);
37
37
 
38
- attributes.forEach((a) => {
39
- a.subscribe(async () => {
40
- const newValue = await a.getValue();
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
- setAttributes(prev => prev.map(v =>
44
- v._id === a.id
45
- ? { _id: a.id, ...newValue }
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.Attribute, setAttributes ]);
60
+ }, [ lr.Record, setRecords ]);
61
61
 
62
- return attributes;
62
+ return records;
63
63
  }
64
+
65
+ /** @deprecated Use useKeyValueRecords instead. */
66
+ export const useKeyValueAttributes = useKeyValueRecords;