@byamoah/studio-state 0.0.0-stage → 0.1.0-beta.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/CHANGELOG.md +11 -0
- package/LICENSE +202 -0
- package/README.md +380 -2
- package/delivery-contract.d.ts +21 -0
- package/delivery-contract.js +22 -0
- package/delivery.d.ts +47 -0
- package/delivery.js +256 -0
- package/index.d.ts +102 -0
- package/index.js +371 -0
- package/migration.js +235 -0
- package/package.json +41 -4
- package/react.d.ts +152 -0
- package/react.js +258 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @byamoah/studio-state
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.0
|
|
4
|
+
|
|
5
|
+
Initial public prerelease.
|
|
6
|
+
|
|
7
|
+
- Typed React context with generated state declarations.
|
|
8
|
+
- Repeatable collections, registered layout blocks, nested slots and stable item identities.
|
|
9
|
+
- Validated content delivery with persistent caching, readiness status and refresh controls.
|
|
10
|
+
- Document validation, collection editing, presets and migration utilities.
|
|
11
|
+
- Apache-2.0 license and package integration documentation.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,381 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @byamoah/studio-state
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed, remotely managed content for React and React Native applications. Read editable values through React context, render repeatable components and configurable layouts, and deliver compatible content revisions with persistent caching.
|
|
4
|
+
|
|
5
|
+
Studio changes data rendered by components already shipped in your application. It does not download new components or execute server-provided JavaScript. Database records, authentication and transactions remain owned by your application.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @byamoah/studio-state@next @byamoah/studio-core@next
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The initial release is a prerelease distributed under `next`. Use matching versions of both packages. React 18 or later is a peer dependency. Use the React instance already supplied by your application. The companion CLI requires Node.js 22.18 or later.
|
|
14
|
+
|
|
15
|
+
| Import | Purpose |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `@byamoah/studio-state/react` | Providers, hooks, repeats, layouts and slots |
|
|
18
|
+
| `@byamoah/studio-state/delivery` | Delivery client, revision validation and development endpoint parsing |
|
|
19
|
+
| `@byamoah/studio-state` | Contract validation, collection operations, presets and migrations |
|
|
20
|
+
|
|
21
|
+
## First editable screen
|
|
22
|
+
|
|
23
|
+
Initialize the CLI in the application root:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npx --no-install studio init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Set `projectId` and `routesDir` in the created `studio.config.mjs`. For a route-based React Native app, a screen can read editable content directly:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// src/app/index.tsx
|
|
33
|
+
import { Text, View } from "react-native";
|
|
34
|
+
import { useStudioContext } from "@byamoah/studio-state/react";
|
|
35
|
+
|
|
36
|
+
export default function Home() {
|
|
37
|
+
const std = useStudioContext();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<View>
|
|
41
|
+
<Text style={{ color: std.theme.color.heading }}>
|
|
42
|
+
{std.screens.home.title}
|
|
43
|
+
</Text>
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Generate the contract, authoring snapshot and TypeScript declarations:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
npx --no-install studio discover
|
|
53
|
+
npx --no-install studio dev
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The second command watches for source changes. Ensure `studio-env.d.ts` is included by the application's TypeScript configuration. Generated declarations augment `StudioState`; do not edit the generated interface or maintain a duplicate list of fields.
|
|
57
|
+
|
|
58
|
+
The name `std` is a convention. Discovery tracks the imported `useStudioContext` binding. Direct, statically resolvable property access gives discovery the clearest information. A computed property selected only at runtime may require a more explicit supported binding; check diagnostics with `studio check`.
|
|
59
|
+
|
|
60
|
+
### Provide a document
|
|
61
|
+
|
|
62
|
+
For a local authoring snapshot, place this provider above the routes:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import type { ReactNode } from "react";
|
|
66
|
+
import { StudioProvider } from "@byamoah/studio-state/react";
|
|
67
|
+
import document from "./.studio/content.snapshot.json";
|
|
68
|
+
import type { StudioContract } from "@byamoah/studio-state";
|
|
69
|
+
import contractJson from "./.studio/state.contract.json";
|
|
70
|
+
|
|
71
|
+
const contract = contractJson as StudioContract;
|
|
72
|
+
|
|
73
|
+
export function ContentRoot({ children }: { children: ReactNode }) {
|
|
74
|
+
return (
|
|
75
|
+
<StudioProvider value={document} contract={contract}>
|
|
76
|
+
{children}
|
|
77
|
+
</StudioProvider>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Paths above assume this module is at the project root and TypeScript supports JSON imports. Generate the files before importing them. This is a bundled snapshot: it does not subscribe to Studio changes or fetch published updates. Use the delivery client below for that behavior.
|
|
83
|
+
|
|
84
|
+
Discovery scaffolds supported new values into the authoring document and preserves existing edits. A developer-maintained defaults object is optional. Authoring scaffolds are not automatically production content.
|
|
85
|
+
|
|
86
|
+
## Deliver content to installed applications
|
|
87
|
+
|
|
88
|
+
Create one client per endpoint/project configuration and keep its identity stable across renders. The storage interface works with any asynchronous key-value store:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
// content-client.ts — React Native example
|
|
92
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
93
|
+
import { createContentClient } from "@byamoah/studio-state/delivery";
|
|
94
|
+
import { validateStudioState } from "@byamoah/studio-state";
|
|
95
|
+
import type { StudioState } from "@byamoah/studio-state/react";
|
|
96
|
+
import type { StudioContract } from "@byamoah/studio-state";
|
|
97
|
+
import contractJson from "./.studio/state.contract.json";
|
|
98
|
+
|
|
99
|
+
const contract = contractJson as StudioContract;
|
|
100
|
+
|
|
101
|
+
export const contentClient = createContentClient<StudioState>({
|
|
102
|
+
projectId: "my-app",
|
|
103
|
+
schemaVersion: 1,
|
|
104
|
+
contractId: contract.contractId,
|
|
105
|
+
endpoint: "https://content.example.com/studio/content",
|
|
106
|
+
mode: "production",
|
|
107
|
+
storage: AsyncStorage,
|
|
108
|
+
validate: (value) => validateStudioState(value, contract),
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Install a storage implementation appropriate to your framework separately; it is not bundled with Studio. In an Expo project, install native storage with `npx expo install @react-native-async-storage/async-storage`. Web applications can implement `getItem` and `setItem` around their own persistent store. The SDK does not read environment variables itself: resolve the endpoint through your framework's public configuration and pass it to `endpoint`.
|
|
113
|
+
|
|
114
|
+
Mount the delivery provider and gate content-dependent screens:
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import type { ReactNode } from "react";
|
|
118
|
+
import { Text } from "react-native";
|
|
119
|
+
import {
|
|
120
|
+
StudioDeliveryProvider,
|
|
121
|
+
useStudioStatus,
|
|
122
|
+
} from "@byamoah/studio-state/react";
|
|
123
|
+
import { contentClient } from "./content-client";
|
|
124
|
+
import type { StudioContract } from "@byamoah/studio-state";
|
|
125
|
+
import contractJson from "./.studio/state.contract.json";
|
|
126
|
+
|
|
127
|
+
const contract = contractJson as StudioContract;
|
|
128
|
+
|
|
129
|
+
function ContentBoundary({ children }: { children: ReactNode }) {
|
|
130
|
+
const status = useStudioStatus();
|
|
131
|
+
|
|
132
|
+
if (!status.ready) {
|
|
133
|
+
return <Text>{status.error ? "Content is unavailable. Try again." : "Loading…"}</Text>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return children;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function ContentRoot({ children }: { children: ReactNode }) {
|
|
140
|
+
return (
|
|
141
|
+
<StudioDeliveryProvider client={contentClient} contract={contract}>
|
|
142
|
+
<ContentBoundary>{children}</ContentBoundary>
|
|
143
|
+
</StudioDeliveryProvider>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Replace the loading view with your application's skeleton and retry experience. Keep hooks unconditional. Mount components that dereference content only when `ready` is true; the typed context is not a promise that a first-launch document has already arrived.
|
|
149
|
+
|
|
150
|
+
### Client options
|
|
151
|
+
|
|
152
|
+
| Option | Purpose |
|
|
153
|
+
| --- | --- |
|
|
154
|
+
| `projectId`, `schemaVersion` | Stable content identity and schema version |
|
|
155
|
+
| `contractId` | Generated compatibility ID; use it for build-specific delivery |
|
|
156
|
+
| `validate(value)` | Return validation error strings, or an empty array |
|
|
157
|
+
| `storage` | Asynchronous `getItem(key)` and `setItem(key, value)` |
|
|
158
|
+
| `endpoint` | Content API URL; omit for explicitly supplied local content |
|
|
159
|
+
| `mode` | Development or production classification and cache separation |
|
|
160
|
+
| `initialContent` | Optional validated document available before a fetch |
|
|
161
|
+
| `prepare(document, signal)` | Optional media preparation before activation |
|
|
162
|
+
| `timeoutMs` | Request timeout; defaults to 8,000 milliseconds |
|
|
163
|
+
| `maxCharacters` | Maximum envelope text length; defaults to 4,000,000 characters |
|
|
164
|
+
| `fetch` | Optional replacement fetch implementation |
|
|
165
|
+
| `allowHttp` | Explicitly permit HTTP for development |
|
|
166
|
+
|
|
167
|
+
`defaults` is an older optional fallback alias; prefer `initialContent` in new integrations.
|
|
168
|
+
|
|
169
|
+
### Delivery lifecycle
|
|
170
|
+
|
|
171
|
+
1. The client reads and validates cached content.
|
|
172
|
+
2. It requests a compatible revision from the configured endpoint.
|
|
173
|
+
3. It validates identity, schema, contract and document before activation.
|
|
174
|
+
4. If supplied, `prepare(document, signal)` resolves required media before activation.
|
|
175
|
+
5. It activates the accepted document and persists it for later launches.
|
|
176
|
+
|
|
177
|
+
On a request, validation or preparation failure, previously accepted content remains usable. Without valid cache, `initialContent`, or a successful fetch, `ready` remains false. The application decides what to show. `initialContent` is an explicit optional fallback, not an implicit defaults source.
|
|
178
|
+
|
|
179
|
+
Caches are separated by project, schema, contract, mode and endpoint. Changing these can intentionally produce a fresh cache. Persisted JSON alone does not guarantee that remote media will be available offline; use `prepare` and an application media cache when required.
|
|
180
|
+
|
|
181
|
+
### Server response
|
|
182
|
+
|
|
183
|
+
Serve JSON using this envelope; only `document` depends on your project:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"protocolVersion": 1,
|
|
188
|
+
"projectId": "my-app",
|
|
189
|
+
"schemaVersion": 1,
|
|
190
|
+
"contractId": "<generated contractId>",
|
|
191
|
+
"revision": "release-0001",
|
|
192
|
+
"publishedAt": "2026-11-08T12:00:00.000Z",
|
|
193
|
+
"document": {
|
|
194
|
+
"theme": { "color": { "heading": "#17212B" } },
|
|
195
|
+
"screens": { "home": { "title": "Welcome back" } }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The document must satisfy the entire generated contract, including any collections used by the application. The client adds `projectId` and `contractId` query parameters. Your server must select a revision compatible with that installed build. Keep prior compatible releases available when new application versions change the contract. Do not change the contract ID merely to force an incompatible document through validation.
|
|
201
|
+
|
|
202
|
+
Use HTTPS in production. `allowHttp: true` exists for development endpoints. Configure browser CORS when the content endpoint and web application have different origins. Never put publishing credentials in a client application.
|
|
203
|
+
|
|
204
|
+
### Status and refresh
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import { Button } from "react-native";
|
|
208
|
+
import { useStudioStatus } from "@byamoah/studio-state/react";
|
|
209
|
+
|
|
210
|
+
export function RefreshContent() {
|
|
211
|
+
const { refresh, refreshing } = useStudioStatus();
|
|
212
|
+
return (
|
|
213
|
+
<Button title={refreshing ? "Refreshing…" : "Refresh content"}
|
|
214
|
+
disabled={refreshing} onPress={() => void refresh()} />
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
| Status | Meaning |
|
|
220
|
+
| --- | --- |
|
|
221
|
+
| `ready` | A usable document is available |
|
|
222
|
+
| `hydrated` | The initial cache read has completed |
|
|
223
|
+
| `refreshing` | A refresh is in progress |
|
|
224
|
+
| `source` | Origin of the current document, such as cache or remote |
|
|
225
|
+
| `revision` | Active revision, or `null` |
|
|
226
|
+
| `error` | Latest delivery error, or `null`; content may still be ready |
|
|
227
|
+
| `phase` | Optional detail: hydrating, fetching, preparing or idle |
|
|
228
|
+
| `channel` | Optional draft/published/unknown classification |
|
|
229
|
+
| `checkedAt` | Optional timestamp of the latest check |
|
|
230
|
+
| `contractId` | Optional active compatibility identifier |
|
|
231
|
+
| `refresh()` | Request another update |
|
|
232
|
+
|
|
233
|
+
For non-React consumers, the client exposes `getSnapshot`, `subscribe`, `start`, `refresh` and `stop`. `StudioDeliveryProvider` manages subscription and start/stop. `StudioProvider` only supplies the value and status you pass; it does not own network delivery.
|
|
234
|
+
|
|
235
|
+
### Development pairing
|
|
236
|
+
|
|
237
|
+
`studioDevelopmentEndpoint(link, development)` parses Studio connection links:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import { studioDevelopmentEndpoint } from "@byamoah/studio-state/delivery";
|
|
241
|
+
|
|
242
|
+
const result = studioDevelopmentEndpoint(incomingLink, isDevelopment);
|
|
243
|
+
// string: validated draft endpoint
|
|
244
|
+
// null: disconnect request
|
|
245
|
+
// undefined: unrelated link or development disabled
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Handle both launch links and later link events using your framework. Recreate the client when its selected endpoint changes. Permit a paired endpoint to override the production endpoint only in development. Both channels use the same revision envelope. Pairing, navigation and inspection bridges require integration in the application; the provider alone does not implement them.
|
|
249
|
+
|
|
250
|
+
## Repeatable components
|
|
251
|
+
|
|
252
|
+
Bind a collection directly instead of declaring a separate list of paths:
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
import { Text, View } from "react-native";
|
|
256
|
+
import * as Studio from "@byamoah/studio-state/react";
|
|
257
|
+
|
|
258
|
+
function Card({ id }: Studio.RepeatItemProps) {
|
|
259
|
+
const std = Studio.useStudioContext();
|
|
260
|
+
const card = Studio.useStudioListItem(std.screens.home.cards, id);
|
|
261
|
+
const testID = Studio.useStudioInstanceId("card");
|
|
262
|
+
return <View testID={testID}><Text>{card.title}</Text></View>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function Cards() {
|
|
266
|
+
const std = Studio.useStudioContext();
|
|
267
|
+
return (
|
|
268
|
+
<View>
|
|
269
|
+
<Studio.Repeat items={std.screens.home.cards} template={Card} />
|
|
270
|
+
</View>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Run discovery after introducing the collection and item fields. Each item has a stable string `id`. The compiler infers templates and item fields from the supported usage. `Repeat` owns iteration and keys: do not wrap it in another `.map()` over the same collection.
|
|
276
|
+
|
|
277
|
+
`Repeat` is headless. Your `View`, row, grid or scrolling component owns actual layout. `direction="horizontal"` describes editing order; it does not apply a flex style. Pass non-editorial runtime values through `itemProps`. The template receives `id`, `index` and `instanceId` in addition to those props.
|
|
278
|
+
|
|
279
|
+
Use `useStudioRepeat` when a pager requires separate keyed children. `useStudioCollection(items, { reveal })` and `Repeat`'s `reveal(id)` can register an application scrolling callback so inspection can reveal an off-screen item. Virtualized or hidden content still needs a working reveal implementation.
|
|
280
|
+
|
|
281
|
+
Duplication creates new owned identities, including registered nested owned collections. External entity references should remain references. Use `useStudioInstanceId(suffix)` for owned attributes such as test or accessibility linkage IDs; do not copy hardcoded unique IDs into templates.
|
|
282
|
+
|
|
283
|
+
## Layouts and slots
|
|
284
|
+
|
|
285
|
+
Register component implementations shipped with the application:
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
import { Text, View } from "react-native";
|
|
289
|
+
import * as Studio from "@byamoah/studio-state/react";
|
|
290
|
+
|
|
291
|
+
function Heading() {
|
|
292
|
+
const block = Studio.useStudioBlock("heading");
|
|
293
|
+
return <Text>{block.title}</Text>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function Notice() {
|
|
297
|
+
const block = Studio.useStudioBlock("notice");
|
|
298
|
+
return <Text>{block.message}</Text>;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const blocks = Studio.defineBlocks({ heading: Heading, notice: Notice });
|
|
302
|
+
|
|
303
|
+
export function Page() {
|
|
304
|
+
const std = Studio.useStudioContext();
|
|
305
|
+
return <View><Studio.Layout items={std.screens.home.sections} blocks={blocks} /></View>;
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
The generated collection contains stable `id` and `type` properties. Discovery records the registered variants and their fields. Studio can insert, replace, remove and reorder allowed variants. Publishing a new variant requires first shipping its implementation in an application build.
|
|
310
|
+
|
|
311
|
+
Within a block, expose a nested region using a literal slot name and an allowed registry:
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
import { Text, View } from "react-native";
|
|
315
|
+
import * as Studio from "@byamoah/studio-state/react";
|
|
316
|
+
|
|
317
|
+
// blocks is the allowed registry declared above.
|
|
318
|
+
function Panel() {
|
|
319
|
+
const block = Studio.useStudioBlock("panel");
|
|
320
|
+
return (
|
|
321
|
+
<View>
|
|
322
|
+
<Text>{block.title}</Text>
|
|
323
|
+
<Studio.Slot name="footer" blocks={blocks} />
|
|
324
|
+
</View>
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Register `Panel` in the parent layout's block registry. Slots belong to their enclosing block and store their nested content under owned `.slots` collections. The allowed registry controls what can be placed there; arbitrary native views cannot be moved into undeclared regions.
|
|
330
|
+
|
|
331
|
+
## Contract and document utilities
|
|
332
|
+
|
|
333
|
+
The root entry point supplies lower-level functions for custom editors and servers:
|
|
334
|
+
|
|
335
|
+
| Area | Exports |
|
|
336
|
+
| --- | --- |
|
|
337
|
+
| Validation and access | `validateStudioState`, `getStudioValue`, `expandStudioPath`, `studioItemSegment` |
|
|
338
|
+
| List editing | `createStudioItem`, `duplicateStudioItem`, `moveStudioItem`, `removeStudioItem` |
|
|
339
|
+
| Layout editing | `insertStudioBlock`, `studioCollectionDefinition`, `matchesStudioConditions` |
|
|
340
|
+
| Presets | `createStudioPreset`, `insertStudioPreset` |
|
|
341
|
+
| Migration | `compareStudioContracts`, `studioMigrationFieldKey`, `previewStudioMigration` |
|
|
342
|
+
| Explicit fallbacks | `defineStudioDefaults`, `mergeStudioDefaults` |
|
|
343
|
+
| Reveal coordination | `requestStudioItemReveal`, `subscribeStudioReveal` |
|
|
344
|
+
|
|
345
|
+
Editing functions operate on the supplied document. Clone first when using immutable application state, then validate the candidate before persisting or publishing:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
import { duplicateStudioItem, validateStudioState } from "@byamoah/studio-state";
|
|
349
|
+
|
|
350
|
+
const candidate = structuredClone(document);
|
|
351
|
+
const newId = duplicateStudioItem(candidate, "screens.home.cards", selectedId, {
|
|
352
|
+
position: "after",
|
|
353
|
+
});
|
|
354
|
+
const errors = validateStudioState(candidate, contract);
|
|
355
|
+
if (errors.length) throw new Error(errors.join("\n"));
|
|
356
|
+
// Commit candidate to your editor's state. newId identifies the duplicate.
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Presets are scoped to a project and contract. Migration previews return a candidate, changes and errors without mutating their inputs; review and validate the result before activation. Conversions support copy, text, number and boolean. They do not automatically redesign layouts or convert image content into video.
|
|
360
|
+
|
|
361
|
+
## Troubleshooting
|
|
362
|
+
|
|
363
|
+
- **New properties have TypeScript errors:** run discovery/watch, include `studio-env.d.ts` in TypeScript, and inspect compiler diagnostics. Restart the TypeScript language service if necessary.
|
|
364
|
+
- **First launch has no document:** supply a reachable compatible endpoint, an explicit initial document, or a loading boundary. Discovery does not publish runtime data.
|
|
365
|
+
- **An update is rejected:** compare project ID, schema version, contract ID and validation errors. Preserve compatibility for older builds.
|
|
366
|
+
- **A duplicate cannot be inspected:** verify stable IDs, compiler instrumentation and application inspection bridge registration. Rendering repeats alone does not establish a device connection.
|
|
367
|
+
- **Styles changed but native code did not:** Studio delivers referenced values and registered layout data. New component code requires a new build or your framework's supported code-update mechanism.
|
|
368
|
+
|
|
369
|
+
## Further reading
|
|
370
|
+
|
|
371
|
+
- [CLI and integration package](https://github.com/KBismark/studio/blob/main/packages/core/README.md)
|
|
372
|
+
- [Application integration guide](https://github.com/KBismark/studio/blob/main/docs/GETTING_STARTED.md)
|
|
373
|
+
- [State and composition conventions](https://github.com/KBismark/studio/blob/main/docs/STUDIO_STATE.md)
|
|
374
|
+
|
|
375
|
+
The package documentation is included in the npm tarball. Repository links require access while the source repository is private.
|
|
376
|
+
|
|
377
|
+
## License
|
|
378
|
+
|
|
379
|
+
Copyright 2026 Bismark Yamoah.
|
|
380
|
+
|
|
381
|
+
Licensed under the [Apache License, Version 2.0](./LICENSE). This license covers this package. Dependencies retain their respective licenses.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Immutable editorial content. Operational/database data has its own APIs. */
|
|
2
|
+
export interface ContentRevision<D = unknown> {
|
|
3
|
+
protocolVersion: 1;
|
|
4
|
+
projectId: string;
|
|
5
|
+
schemaVersion: number;
|
|
6
|
+
contractId?: string;
|
|
7
|
+
revision: string;
|
|
8
|
+
publishedAt: string;
|
|
9
|
+
document: D;
|
|
10
|
+
}
|
|
11
|
+
export interface ContentContract<D> {
|
|
12
|
+
projectId: string;
|
|
13
|
+
schemaVersion: number;
|
|
14
|
+
contractId?: string;
|
|
15
|
+
defaults?: D;
|
|
16
|
+
validate: (value: unknown) => string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function validateRevision<D>(
|
|
19
|
+
value: unknown,
|
|
20
|
+
contract: ContentContract<D>,
|
|
21
|
+
): ContentRevision<D>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Immutable editorial content. Operational/database data has its own APIs. */
|
|
2
|
+
|
|
3
|
+
export function validateRevision(value, contract) {
|
|
4
|
+
const r = value;
|
|
5
|
+
if (
|
|
6
|
+
!r ||
|
|
7
|
+
r.protocolVersion !== 1 ||
|
|
8
|
+
r.projectId !== contract.projectId ||
|
|
9
|
+
r.schemaVersion !== contract.schemaVersion ||
|
|
10
|
+
(contract.contractId !== undefined &&
|
|
11
|
+
r.contractId !== contract.contractId) ||
|
|
12
|
+
typeof r.revision !== "string" ||
|
|
13
|
+
!/^[a-zA-Z0-9-]{1,128}$/.test(r.revision) ||
|
|
14
|
+
typeof r.publishedAt !== "string" ||
|
|
15
|
+
!Number.isFinite(Date.parse(r.publishedAt))
|
|
16
|
+
)
|
|
17
|
+
throw new Error("Incompatible content revision.");
|
|
18
|
+
const errors = contract.validate(r.document);
|
|
19
|
+
if (errors.length)
|
|
20
|
+
throw new Error(`Invalid content: ${errors.slice(0, 3).join(" ")}`);
|
|
21
|
+
return r;
|
|
22
|
+
}
|