@realitycollective/service-framework-react 1.0.0-preview.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.
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import {
3
+ BaseService,
4
+ createServiceProfile,
5
+ createServiceToken
6
+ } from "@realitycollective/service-framework";
7
+ import {
8
+ ServiceFrameworkProvider,
9
+ useService
10
+ } from "@realitycollective/service-framework-react";
11
+
12
+ const STATUS_TOKEN = createServiceToken<StatusService>("StatusService");
13
+
14
+ class StatusService extends BaseService {
15
+ get message(): string {
16
+ return "React service framework ready";
17
+ }
18
+ }
19
+
20
+ function StatusPanel(): React.JSX.Element {
21
+ const service = useService(STATUS_TOKEN);
22
+ return <p>{service.message}</p>;
23
+ }
24
+
25
+ export function App(): React.JSX.Element {
26
+ return (
27
+ <ServiceFrameworkProvider
28
+ profile={createServiceProfile("react-example", [
29
+ {
30
+ token: STATUS_TOKEN,
31
+ useFactory: (context) => new StatusService(context)
32
+ }
33
+ ])}
34
+ >
35
+ <StatusPanel />
36
+ </ServiceFrameworkProvider>
37
+ );
38
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Reality Collective
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import type { IEnvironmentDescriptor, IScheduler, IService, ServiceProfile } from "@realitycollective/service-framework";
3
+ import { ServiceManager, ServiceToken } from "@realitycollective/service-framework";
4
+ export interface ServiceFrameworkProviderProps {
5
+ readonly children?: React.ReactNode;
6
+ readonly manager?: ServiceManager;
7
+ readonly profile?: ServiceProfile;
8
+ readonly autoStart?: boolean;
9
+ readonly scheduler?: IScheduler;
10
+ readonly environment?: IEnvironmentDescriptor;
11
+ }
12
+ export declare function ServiceFrameworkProvider({ children, manager, profile, autoStart, scheduler, environment }: ServiceFrameworkProviderProps): React.JSX.Element;
13
+ export declare function useServiceManager(): ServiceManager;
14
+ export declare function useService<TService extends IService>(token: ServiceToken<TService>, name?: string): TService;
15
+ export declare function useServices<TService extends IService>(token: ServiceToken<TService>): readonly TService[];
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,QAAQ,EACR,cAAc,EACf,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,sBAAsB,CAAC;CAC/C;AAID,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAgB,EAChB,SAAS,EACT,WAAW,EACZ,EAAE,6BAA6B,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAuBnD;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAQlD;AAED,wBAAgB,UAAU,CAAC,QAAQ,SAAS,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAE5G;AAED,wBAAgB,WAAW,CAAC,QAAQ,SAAS,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,SAAS,QAAQ,EAAE,CAEzG"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* v8 ignore file */
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { ServiceManager } from "@realitycollective/service-framework";
5
+ const ServiceFrameworkContext = createContext(null);
6
+ export function ServiceFrameworkProvider({ children, manager, profile, autoStart = true, scheduler, environment }) {
7
+ const resolvedManager = useMemo(() => {
8
+ const instance = manager ?? new ServiceManager({
9
+ ...(scheduler ? { scheduler } : {}),
10
+ ...(environment ? { environment } : {})
11
+ });
12
+ if (profile && !instance.isInitialized) {
13
+ instance.initializeProfile(profile);
14
+ }
15
+ if (autoStart && !instance.isStarted) {
16
+ instance.start();
17
+ }
18
+ return instance;
19
+ }, [autoStart, environment, manager, profile, scheduler]);
20
+ return (_jsx(ServiceFrameworkContext.Provider, { value: resolvedManager, children: children }));
21
+ }
22
+ export function useServiceManager() {
23
+ const manager = useContext(ServiceFrameworkContext);
24
+ if (!manager) {
25
+ throw new Error("ServiceFrameworkProvider is required before calling useServiceManager.");
26
+ }
27
+ return manager;
28
+ }
29
+ export function useService(token, name) {
30
+ return useServiceManager().resolve(token, name);
31
+ }
32
+ export function useServices(token) {
33
+ return useServiceManager().resolveAll(token);
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,oBAAoB;AACpB,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAOlE,OAAO,EAAE,cAAc,EAAgB,MAAM,sCAAsC,CAAC;AAWpF,MAAM,uBAAuB,GAAG,aAAa,CAAwB,IAAI,CAAC,CAAC;AAE3E,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,GAAG,IAAI,EAChB,SAAS,EACT,WAAW,EACmB;IAC9B,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE;QACnC,MAAM,QAAQ,GAAG,OAAO,IAAI,IAAI,cAAc,CAAC;YAC7C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxC,CAAC,CAAC;QAEH,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;YACvC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACrC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,EAAE,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IAE1D,OAAO,CACL,KAAC,uBAAuB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,YACrD,QAAQ,GACwB,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAC;IAEpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,UAAU,CAA4B,KAA6B,EAAE,IAAa;IAChG,OAAO,iBAAiB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,WAAW,CAA4B,KAA6B;IAClF,OAAO,iBAAiB,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@realitycollective/service-framework-react",
3
+ "version": "1.0.0-preview.1",
4
+ "description": "React bindings for the Reality Collective TypeScript Service Framework.",
5
+ "author": "Reality Collective",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "Examples"
19
+ ],
20
+ "keywords": [
21
+ "service-framework",
22
+ "react",
23
+ "hooks",
24
+ "realitycollective",
25
+ "typescript"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/realitycollective/com.realitycollective.service-framework.ts.git"
30
+ },
31
+ "homepage": "https://github.com/realitycollective/com.realitycollective.service-framework.ts#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/realitycollective/com.realitycollective.service-framework.ts/issues"
34
+ },
35
+ "dependencies": {
36
+ "@realitycollective/service-framework": "file:../service-framework"
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^19.2.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.build.json",
43
+ "typecheck": "tsc -p tsconfig.json --noEmit"
44
+ }
45
+ }