@relyio/sdk 0.2.1 → 0.4.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-RJBIJ2ZK.js → chunk-43VPZT2G.js} +496 -103
  4. package/dist/chunk-BBUB7C2Z.js +81 -0
  5. package/dist/{chunk-FJK7ZWKK.cjs → chunk-HAQELDZN.cjs} +156 -221
  6. package/dist/chunk-LSRPMNPT.cjs +89 -0
  7. package/dist/{chunk-7W4MJXQ4.cjs → chunk-XS32U2UP.cjs} +497 -102
  8. package/dist/{chunk-2QUK2ZGD.js → chunk-XY5KFEFY.js} +157 -219
  9. package/dist/client/index.cjs +4 -3
  10. package/dist/client/index.d.cts +4 -3
  11. package/dist/client/index.d.ts +4 -3
  12. package/dist/client/index.js +2 -1
  13. package/dist/define-content-type-CBfnTWSS.d.cts +716 -0
  14. package/dist/define-content-type-CBfnTWSS.d.ts +716 -0
  15. package/dist/{define-schema-DHvUCKwj.d.cts → define-schema-2xbHgtK-.d.cts} +63 -726
  16. package/dist/{define-schema-DHvUCKwj.d.ts → define-schema-DzYXk4HL.d.ts} +63 -726
  17. package/dist/dev-handshake/index.cjs +37 -0
  18. package/dist/dev-handshake/index.d.cts +144 -0
  19. package/dist/dev-handshake/index.d.ts +144 -0
  20. package/dist/dev-handshake/index.js +4 -0
  21. package/dist/{index-DGWaawHt.d.cts → index-BvO6HDtY.d.cts} +237 -12
  22. package/dist/{index-B-KiFHbx.d.ts → index-BzOFJJKS.d.ts} +237 -12
  23. package/dist/{index-BsUqCAu8.d.cts → index-DFehx5sI.d.cts} +749 -2160
  24. package/dist/{index-BsUqCAu8.d.ts → index-FDak5ofk.d.ts} +749 -2160
  25. package/dist/index.cjs +120 -70
  26. package/dist/index.d.cts +136 -55
  27. package/dist/index.d.ts +136 -55
  28. package/dist/index.js +45 -3
  29. package/dist/schema/index.cjs +35 -47
  30. package/dist/schema/index.d.cts +3 -2
  31. package/dist/schema/index.d.ts +3 -2
  32. package/dist/schema/index.js +1 -1
  33. package/dist/types/index.d.cts +2 -1
  34. package/dist/types/index.d.ts +2 -1
  35. package/package.json +15 -19
  36. package/dist/react/index.cjs +0 -4
  37. package/dist/react/index.d.cts +0 -2
  38. package/dist/react/index.d.ts +0 -2
  39. package/dist/react/index.js +0 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,121 @@
1
1
  # @relyio/sdk
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 06baad9: `relyio.changes()` follows the content changes feed (`GET /v1/changes`) as an async iterable.
8
+
9
+ ```ts
10
+ const controller = new AbortController()
11
+
12
+ for await (const change of relyio.changes({ types: ['post'], signal: controller.signal })) {
13
+ // { entryId, contentType, locale, kind: 'published' | 'updated' | 'unpublished' | 'deleted', cursor }
14
+ await revalidate(change.contentType, change.entryId)
15
+ }
16
+ ```
17
+
18
+ - A change carries ids only. Refetch the entry through the ordinary read methods to see it.
19
+ - The API key decides what arrives: a published key sees publication changes, a preview key sees draft saves as well.
20
+ - Each request long-polls, so an idle feed costs one request every 25 seconds or so. When the service or your key is at its limit of held connections, the iterator waits for the `Retry-After` the service sends before asking again.
21
+ - Pass `since` (a change's `cursor`) to resume where you stopped. Without it, the feed starts at the present.
22
+ - A cursor too old to replay throws `ChangesExpiredError` (with a `reason`). Pass `onExpired: 'resync'` to start again from the present instead, or a function to be called when that happens — the place to refetch everything you hold.
23
+ - Aborting the `signal` ends the loop without throwing.
24
+
25
+ Also fixed: a request given its own `signal` no longer loses the client's timeout, and aborting it is no longer retried or reported as a `TimeoutError`.
26
+
27
+ - f21099b: `createClient()` takes a `fetch` option, and `@relyio/sdk` exports `matchRoute`, `IMAGE_LADDER`, `snapToLadder` and `RELYIO_CHANGE_EVENT`.
28
+
29
+ `fetch` is the function every request to the RelyIO API is sent through. The client still builds each request and passes your function the same `RequestInit` it would pass the runtime's `fetch`, including on a retry, so a write's `Idempotency-Key` does not change between attempts. Use it to add what your framework reads off the request, such as Next.js cache tags:
30
+
31
+ ```ts
32
+ import { createClient } from '@relyio/sdk'
33
+
34
+ const relyio = createClient({
35
+ apiKey: process.env.RELYIO_API_KEY!,
36
+ fetch: (input, init) => fetch(input, { ...init, next: { tags: ['posts'] } }),
37
+ })
38
+ ```
39
+
40
+ Leave it out and the client uses the global `fetch`, as before. File bytes that an asset upload sends straight to a presigned storage URL do not go through it.
41
+
42
+ `matchRoute(url)` is the reverse of what the client does when it builds a URL. It returns the API route the URL names (`'/v1/{contentType}/{id}'`), its decoded path parameters and its query, or `null` for a URL that is not a RelyIO API route. If your `baseUrl` has a path of its own, pass it as `matchRoute(url, { baseUrl })`.
43
+
44
+ `snapToLadder(width)` rounds an image dimension to the sizes the RelyIO CDN renders: the nearest multiple of `IMAGE_LADDER.bucket` (100), from 100 up to `IMAGE_LADDER.maxDimension` (5000). The CDN snaps every requested width the same way, so snapping first means two widths that render the same image also share one URL and one cache entry.
45
+
46
+ `RELYIO_CHANGE_EVENT` (`'relyio:change'`) is the name of the DOM event a RelyIO preview surface dispatches on `window` when content on the page has changed. Listen for it by this constant rather than by the string: `@relyio/next`'s `<RelyIORefresh />` does.
47
+
48
+ The `cache` option still configures nothing: the client keeps no response cache of its own, so every call reaches `fetch`.
49
+
50
+ - 745103e: `createClient()` is typed by your schema without a generic or a `schema:` option, once `relyio generate-types` has run.
51
+
52
+ `@relyio/sdk` now exports an empty `Register` interface. The `schema.ts` that `relyio generate-types` writes fills it in, and from then on:
53
+
54
+ ```ts
55
+ import { createClient } from '@relyio/sdk'
56
+
57
+ const relyio = createClient({ apiKey: process.env.RELYIO_API_KEY! })
58
+
59
+ relyio.content('article') // content type, singleton, settings group and query names autocomplete
60
+ ```
61
+
62
+ `schema.ts` only has to be part of your TypeScript program, which it is if your `tsconfig.json` includes it or anything imports from it. Passing `schema:` or an explicit generic works exactly as before, and either one takes precedence over the registered schema.
63
+
64
+ **If you have not run the generator,** `createClient({ apiKey })` returns `TypedRelyIOClient<undefined>`, the untyped client: every name is accepted and entries are typed as `BaseContent`. Previously the call resolved to `TypedRelyIOClient<SchemaDefinition<any, …>>`, a client that claimed a schema it did not have. Code that named that type explicitly needs to name `TypedRelyIOClient<undefined>` instead.
65
+
66
+ **Also fixed:** on a client typed by a schema, `settings()`, `asset()` and `withLocale()` accepted no argument at all, because the settings groups, asset types and locales are optional parts of a schema and their names resolved to `never`. They now accept the schema's names.
67
+
68
+ - cf979dd: **Breaking:** `@relyio/sdk/react` is removed, and the package no longer declares `react` as a peer dependency. `relyioField` is added to `@relyio/sdk`.
69
+
70
+ The `@relyio/sdk/react` subpath exported nothing. It existed so that an import of it would resolve, and it carried an optional `react` peer and a React type dependency for that alone. It now fails to resolve with `ERR_PACKAGE_PATH_NOT_EXPORTED`.
71
+
72
+ **If you imported it:** delete the import. Nothing was exported from it, so nothing that used it needs a replacement. React hooks for RelyIO will ship as their own package, `@relyio/react`.
73
+
74
+ `relyioField(entry, field)` returns the attributes that tie a rendered element to the entry field it shows. Spread them onto that element:
75
+
76
+ ```tsx
77
+ import { relyioField } from '@relyio/sdk'
78
+
79
+ // `post` is an entry the client returned, e.g. from `relyio.content('post').fetchOne(id)`
80
+ ;<h1 {...relyioField(post, 'title')}>{post.title}</h1>
81
+ // → data-relyio-entry="6710f…" data-relyio-type="post" data-relyio-field="title"
82
+ // data-relyio-locale="en-US" data-relyio-v="1"
83
+ ```
84
+
85
+ The entry id, content type and locale all come from the entry itself, so the element is tied to the locale its value was actually served in. With a typed schema, `field` autocompletes to the content type's field names and a misspelt name does not compile. Without one, any field name is accepted. The helper throws a `TypeError` when the entry has no `_metadata.id`, `_metadata.type` or `_metadata.locale`. Every entry the API returns has all three, so that only happens with an object that did not come from RelyIO.
86
+
87
+ The attribute set is fixed at these five. `data-relyio-v` is the version of the set, and any future change to the attributes will bump it.
88
+
89
+ ## 0.3.0
90
+
91
+ ### Minor Changes
92
+
93
+ - a8ae363: **Breaking:** `schemaToJSON`, `viewToJSON` and `workflowToJSON` are removed from `@relyio/sdk` and `@relyio/sdk/schema`.
94
+
95
+ These converted a schema definition to JSON by stripping the internal `_tag` markers the `define*` helpers attach. Their docstrings described them as being "for the CLI", but the CLI never called them — it has always done the conversion itself, and the two implementations had drifted: the SDK's stripped a single level where the CLI's recurses. A nested content type, component or field kept its `_tag`, so anything built on these functions produced a payload `relyio deploy` would not have produced.
96
+
97
+ **If you were calling one of them:** you almost certainly do not need a replacement. `relyio deploy` and `relyio diff` read your schema module and perform the conversion themselves, so passing them a `defineSchema(...)` value is all that is required — as it was before.
98
+
99
+ If you need the JSON for something else, such as committing a snapshot or sending it to your own tooling, strip `_tag` **recursively**:
100
+
101
+ ```ts
102
+ function stripTags(value: unknown): unknown {
103
+ if (Array.isArray(value)) return value.map(stripTags)
104
+ if (value && typeof value === 'object') {
105
+ return Object.fromEntries(
106
+ Object.entries(value)
107
+ .filter(([key]) => key !== '_tag')
108
+ .map(([key, entry]) => [key, stripTags(entry)]),
109
+ )
110
+ }
111
+ return value
112
+ }
113
+ ```
114
+
115
+ That mirrors what the CLI does, so its output matches the payload `relyio deploy` sends. Note that it is a plain recursive walk: values that are not JSON to begin with, such as a `Date`, become `{}` — as they do on the deploy path today.
116
+
117
+ Everything you author with is unchanged. `defineSchema`, `defineContentType`, `defineSingleton`, `defineComponent`, `defineSettingsGroup`, `defineQuery`, `defineAssetType`, `defineLocale`, `defineRole`, `defineWorkflow` and `defineView` keep their signatures and their inferred types, and each now has a fixture asserted against the same validator the platform applies at deploy — so an authoring shape the platform would reject fails when we build the SDK rather than when you run `relyio deploy`.
118
+
3
119
  ## 0.2.1
4
120
 
5
121
  ### Patch Changes