@ng-org/orm 0.1.2-alpha.2 → 0.1.2-alpha.4

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.
@@ -1,6 +1,13 @@
1
1
  import type { BaseType } from "@ng-org/shex-orm";
2
2
  import type { ShapeType } from "@ng-org/shex-orm";
3
3
  import type { Scope } from "../../types.ts";
4
- declare const useShape: <T extends BaseType>(shape: ShapeType<T>, scope?: Scope) => import("@ng-org/alien-deepsignals").DeepSignalSet<T>;
4
+ /**
5
+ *
6
+ * @param shape The shape type
7
+ * @param scope The document scope (IRI of named graph)
8
+ * @returns A deep signal set with the orm objects, an empty set if still loading,
9
+ * or an empty set which errors on modifications if scope is undefined.
10
+ */
11
+ declare const useShape: <T extends BaseType>(shape: ShapeType<T>, scope?: Scope | undefined) => import("@ng-org/alien-deepsignals").DeepSignalSet<unknown> | import("@ng-org/alien-deepsignals").DeepSignalSet<T>;
5
12
  export default useShape;
6
13
  //# sourceMappingURL=useShape.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useShape.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/react/useShape.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,QAAA,MAAM,QAAQ,GAAI,CAAC,SAAS,QAAQ,EAChC,OAAO,SAAS,CAAC,CAAC,CAAC,EACnB,QAAO,KAAU,yDAcpB,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"useShape.d.ts","sourceRoot":"","sources":["../../../src/frontendAdapters/react/useShape.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,GAAI,CAAC,SAAS,QAAQ,EAChC,OAAO,SAAS,CAAC,CAAC,CAAC,EACnB,QAAO,KAAK,GAAG,SAAc,sHAqBhC,CAAC;AAiBF,eAAe,QAAQ,CAAC"}
@@ -8,17 +8,41 @@
8
8
  // according to those terms.
9
9
  // SPDX-License-Identifier: Apache-2.0 OR MIT
10
10
  import { useDeepSignal } from "@ng-org/alien-deepsignals/react";
11
- import { useEffect, useRef } from "react";
11
+ import { useEffect, useMemo } from "react";
12
12
  import { createSignalObjectForShape } from "../../connector/createSignalObjectForShape.js";
13
+ /**
14
+ *
15
+ * @param shape The shape type
16
+ * @param scope The document scope (IRI of named graph)
17
+ * @returns A deep signal set with the orm objects, an empty set if still loading,
18
+ * or an empty set which errors on modifications if scope is undefined.
19
+ */
13
20
  const useShape = (shape, scope = "") => {
14
- const handleRef = useRef(createSignalObjectForShape(shape, scope));
15
- const handle = handleRef.current;
16
- const state = useDeepSignal(handle.signalObject);
21
+ const signalHandler = useMemo(() => scope === undefined
22
+ ? undefined
23
+ : createSignalObjectForShape(shape, scope), [shape, scope]);
17
24
  useEffect(() => {
25
+ if (!signalHandler)
26
+ return;
18
27
  return () => {
19
- handleRef.current.stop();
28
+ signalHandler.stop();
20
29
  };
21
- }, [shape, scope]);
30
+ }, [signalHandler]);
31
+ const state = useDeepSignal(signalHandler?.signalObject ?? readOnlySet);
22
32
  return state;
23
33
  };
34
+ const readOnlySet = new Proxy(new Set(), {
35
+ get(target, key, receiver) {
36
+ if (key === "add" || key === "delete" || key === "clear") {
37
+ return () => {
38
+ throw new Error("Set is readonly because scope is empty.");
39
+ };
40
+ }
41
+ const value = target[key];
42
+ if (typeof value === "function") {
43
+ return value.bind(target);
44
+ }
45
+ return value;
46
+ },
47
+ });
24
48
  export default useShape;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-org/orm",
3
- "version": "0.1.2-alpha.2",
3
+ "version": "0.1.2-alpha.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "authors": [
@@ -49,8 +49,8 @@
49
49
  "react-dom": "19.1.1",
50
50
  "svelte": "5.39.12",
51
51
  "vue": "3.5.19",
52
- "@ng-org/shex-orm": "0.1.2-alpha.1",
53
- "@ng-org/alien-deepsignals": "0.1.2-alpha.1"
52
+ "@ng-org/shex-orm": "0.1.2-alpha.2",
53
+ "@ng-org/alien-deepsignals": "0.1.2-alpha.3"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@playwright/test": "^1.55.0",
@@ -60,7 +60,7 @@
60
60
  "vite": "7.1.3",
61
61
  "vitest": "^3.2.4",
62
62
  "typescript": "^5.3.0",
63
- "@ng-org/lib-wasm": "0.1.2"
63
+ "@ng-org/lib-wasm": "0.1.2-alpha.1"
64
64
  },
65
65
  "files": [
66
66
  "dist"