@ossy/sdk-react 3.0.9 → 3.11.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/build/packages/sdk-react/src/Cache.js +1 -1
- package/build/packages/sdk-react/src/WorkspaceProvider.js +1 -1
- package/build/packages/sdk-react/src/cacheKey.js +1 -1
- package/build/packages/sdk-react/src/fetchGeneration.js +1 -0
- package/build/packages/sdk-react/src/public.index.js +1 -1
- package/build/packages/sdk-react/src/usePushInvalidation.js +1 -1
- package/build/packages/sdk-react/src/useSdk.js +1 -1
- package/build/public.index.d.ts +10 -1
- package/build/types/Cache.d.ts +7 -0
- package/build/types/cacheKey.d.ts +4 -0
- package/build/types/fetchGeneration.d.ts +7 -0
- package/build/types/useSdk.d.ts +3 -0
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__assign as r}from"../../../node_modules/tslib/tslib.es6.js";import t,{createContext as
|
|
1
|
+
import{__assign as r}from"../../../node_modules/tslib/tslib.es6.js";import t,{createContext as n,useContext as e,useRef as u,useReducer as o,useCallback as c,useMemo as i}from"react";import{AsyncStatus as a}from"./asyncStatus.js";import{emptyEntry as f}from"./cacheEntry.js";import{bumpGeneration as s,readGeneration as l,isCurrentGeneration as v}from"./fetchGeneration.js";var d=n({}),h=function(n){var e=n.get,h=n.set,m=n.getInitialState;return function(n){var p,y=u(null!==(p=null==m?void 0:m())&&void 0!==p?p:{}),g=o(function(r){return r+1},0)[1],E=u(new Set),S=u(new Map),w=u(new Map),b=c(function(){E.current.forEach(function(r){return r()})},[]),j=c(function(r){y.current=r,g(),b()},[b]),M=c(function(r){return e(r,y.current)},[e]),A=c(function(r){return function(t){var n=e(r,y.current),u="function"==typeof t?t(n):t;j(h(r,u,y.current))}},[e,h,j]),k=c(function(r){var t=e(r,y.current);return null!=t?t:f()},[e]),P=c(function(r,t){var n,u=null!==(n=e(r,y.current))&&void 0!==n?n:f(),o="function"==typeof t?t(u):t;j(h(r,o,y.current))},[e,h,j]),q=c(function(r){for(var t=Array.isArray(r)?r:[r],n=y.current,e=0,u=t;e<u.length;e++){var o=u[e];S.current.delete(o),s(w.current,o),n=h(o,f(),n)}j(n)},[h,j]),x=c(function(r){var t=y.current;if(t instanceof Map&&"function"==typeof r){for(var n=t,e=!1,u=0,o=Array.from(t.keys());u<o.length;u++){var c=o[u];r(c)&&(S.current.delete(c),n=h(c,f(),n),e=!0)}e&&j(n)}},[h,j]),C=c(function(r){return E.current.add(r),function(){return E.current.delete(r)}},[]),G=c(function(t,n){var e=S.current.get(t);if(e)return e;var u=l(w.current,t),o=function(){return v(w.current,t,u)};P(t,function(t){return t.status===a.Success?r(r({},t),{error:null}):r(r({},t),{status:a.Loading,error:null})});var c=n().then(function(r){return o()?(P(t,{status:a.Success,data:r,error:null}),r):r}).catch(function(r){var n=r instanceof Error?r:new Error(String(r));throw o()&&P(t,{status:a.Error,data:void 0,error:n}),n}).finally(function(){o()&&S.current.delete(t)});return S.current.set(t,c),c},[P]),I=i(function(){return{getEntry:k,setEntry:P,invalidate:q,invalidateMatching:x,subscribe:C,fetch:G}},[k,P,q,x,C,G]);return t.createElement(d.Provider,{value:{get:M,set:A,readStore:I}},n.children)}},m=function(){var r=e(d).readStore;if(!r)throw new Error("useReadCacheStore requires WorkspaceProvider");return r};export{d as CacheContext,h as createCache,m as useReadCacheStore};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r,{createContext as e,useMemo as t}from"react";import{createCache as n,useReadCacheStore as o}from"./Cache.js";import{createMapCache as a}from"./cacheUtils.js";import{ReactSdk as i}from"./react-sdk.js";import{usePushInvalidation as m}from"./usePushInvalidation.js";var
|
|
1
|
+
import r,{createContext as e,useMemo as t}from"react";import{createCache as n,useReadCacheStore as o}from"./Cache.js";import{createMapCache as a}from"./cacheUtils.js";import{ReactSdk as i}from"./react-sdk.js";import{usePushInvalidation as m}from"./usePushInvalidation.js";var u=e({}),c=n(a());function l(r){var e=r.sdk,t=o();return m(e,t),null}var s=function(e){var n=e.sdk,o=e.enablePushInvalidation,a=void 0!==o&&o,m=e.children,s=t(function(){return i.from(n)},[n]),d=t(function(){return{sdk:s}},[s]);return r.createElement(c,null,r.createElement(u.Provider,{value:d},a&&r.createElement(l,{sdk:s}),m))};export{u as Context,s as WorkspaceProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{stableSerialize as o}from"./stableSerialize.js";import{normalizeLocation as t}from"./normalizeLocation.js";import{resolveActionId as n}from"./action.js";var r=["limit","offset","sortBy","sortOrder","sort"];function i(o){return"location:".concat(t(o))}function c(o){return"list:".concat(t(o),":")}function s(o,t){return"projection:".concat(o,":").concat(t)}function a(a,e){var l,u=n(a);if("@ossy/resources/actions/list"===u){var f=null==e?void 0:e.location,v=t("string"==typeof f?f:void 0),d=function(o){if(!o||"object"!=typeof o)return null;for(var t={},n=!1,i=0,c=r;i<c.length;i++){var s=c[i];void 0!==o[s]&&null!==o[s]&&""!==o[s]&&(t[s]=o[s],n=!0)}return n?t:null}(e);return d?"".concat(c(v)).concat(o(d)):i(v)}if("@ossy/resources/actions/search"===u)return"search:".concat(o(null!=e?e:{}));if("@ossy/resources/actions/get"===u){var m=null!==(l=null==e?void 0:e.resourceId)&&void 0!==l?l:null==e?void 0:e.id;return"resource:".concat(null!=m?m:"")}if("@ossy/booking/actions/list"===u)return"action:@ossy/booking/actions/list";if("@ossy/platform/actions/list-task-runs"===u){var p=null==e?void 0:e.workspaceId;return s("@ossy/platform/data/task-run-list",String(null!=p?p:""))}var y=o(e);return y?"action:".concat(u,":").concat(y):"action:".concat(u)}export{a as cacheKey,i as locationListCacheKey,c as locationListCachePrefix,s as projectionKey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(n,t){var r,u=(null!==(r=n.get(t))&&void 0!==r?r:0)+1;return n.set(t,u),u}function t(n,t){var r;return null!==(r=n.get(t))&&void 0!==r?r:0}function r(n,r,u){return t(n,r)===u}export{n as bumpGeneration,r as isCurrentGeneration,t as readGeneration};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{AsyncStatus}from"./asyncStatus.js";export{normalizeLocation}from"./normalizeLocation.js";export{ReactSdk}from"./react-sdk.js";export{resolveActionId,toActionRef}from"./action.js";export{Context,WorkspaceProvider}from"./WorkspaceProvider.js";export{PushInvalidationSubscriber}from"./PushInvalidationSubscriber.js";export{useSdk}from"./useSdk.js";export{useRead}from"./useRead.js";export{usePushInvalidation}from"./usePushInvalidation.js";export{applyOptimisticResource,rollbackOptimisticResource}from"./optimisticResource.js";export{cacheKey,projectionKey}from"./cacheKey.js";export{stableSerialize}from"./stableSerialize.js";export{useReadCacheStore}from"./Cache.js";
|
|
1
|
+
export{AsyncStatus}from"./asyncStatus.js";export{normalizeLocation}from"./normalizeLocation.js";export{ReactSdk}from"./react-sdk.js";export{resolveActionId,toActionRef}from"./action.js";export{Context,WorkspaceProvider}from"./WorkspaceProvider.js";export{PushInvalidationSubscriber}from"./PushInvalidationSubscriber.js";export{useSdk}from"./useSdk.js";export{useRead}from"./useRead.js";export{usePushInvalidation}from"./usePushInvalidation.js";export{applyOptimisticResource,rollbackOptimisticResource}from"./optimisticResource.js";export{cacheKey,locationListCacheKey,locationListCachePrefix,projectionKey}from"./cacheKey.js";export{stableSerialize}from"./stableSerialize.js";export{useReadCacheStore}from"./Cache.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as i}from"react";function n(n,o){i(function(){if((null==n?void 0:n.workspaceId)&&"function"==typeof n.subscribePush)return n.subscribePush({onMessage:function(i){var n;(null===(n=null==i?void 0:i.invalidate)||void 0===n?void 0:n.length)&&o.invalidate(i.invalidate)}})},[n,o])}export{n as usePushInvalidation};
|
|
1
|
+
import{useEffect as i}from"react";import{locationListCachePrefix as t}from"./cacheKey.js";function n(n,o){i(function(){if((null==n?void 0:n.workspaceId)&&"function"==typeof n.subscribePush)return n.subscribePush({onMessage:function(i){var n;if(null===(n=null==i?void 0:i.invalidate)||void 0===n?void 0:n.length)for(var e=function(i){if("string"==typeof i&&i.startsWith("location:")){var n=i.slice(9),e=t(n);return o.invalidateMatching(function(t){return t===i||t.startsWith(e)}),"continue"}o.invalidate(i)},r=0,a=i.invalidate;r<a.length;r++){e(a[r])}}})},[n,o])}export{n as usePushInvalidation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as
|
|
1
|
+
import{__awaiter as r,__generator as e}from"../../../node_modules/tslib/tslib.es6.js";import{useContext as t,useRef as n,useCallback as i,useMemo as o}from"react";import{locationListCacheKey as c,locationListCachePrefix as a,cacheKey as s}from"./cacheKey.js";import{Context as u}from"./WorkspaceProvider.js";import{useReadCacheStore as d}from"./Cache.js";import{useRead as l}from"./useRead.js";import{rollbackOptimisticResource as m,applyOptimisticResource as v}from"./optimisticResource.js";import{normalizeLocation as f}from"./normalizeLocation.js";function p(){var p=this,h=t(u).sdk,j=d(),k=n(j);k.current=j;var I=n(new Map),b=i(function(r){k.current.invalidate(r)},[]),M=i(function(r){k.current.invalidateMatching(r)},[]),g=i(function(r){var e=f(r),t=c(e),n=a(e);k.current.invalidateMatching(function(r){return r===t||r.startsWith(n)})},[]),w=i(function(r,e){return h.invoke(r,e)},[h]),y=i(function(t,n,i){return r(p,void 0,void 0,function(){var r,o,c;return e(this,function(e){switch(e.label){case 0:r=k.current,o=null,(null==i?void 0:i.resourceId)&&(o=v(r,i))&&I.current.set(i.resourceId,o),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,h.invoke(t,n)];case 2:return[2,e.sent()];case 3:throw c=e.sent(),(null==i?void 0:i.resourceId)&&(m(r,i.resourceId,o),I.current.delete(i.resourceId)),c;case 4:return[2]}})})},[h]);return o(function(){return{invoke:w,invokeOptimistic:y,read:l,invalidate:b,invalidateMatching:M,invalidateLocation:g,cacheKey:s,sdk:h}},[w,y,b,M,g,h])}export{p as useSdk};
|
package/build/public.index.d.ts
CHANGED
|
@@ -84,6 +84,10 @@ declare const WorkspaceProvider: ({ sdk, enablePushInvalidation, children, }: Pr
|
|
|
84
84
|
*/
|
|
85
85
|
declare function PushInvalidationSubscriber(): null;
|
|
86
86
|
|
|
87
|
+
/** Exact unpaginated list key for a folder location. */
|
|
88
|
+
declare function locationListCacheKey(location?: string): string;
|
|
89
|
+
/** Prefix used for paginated/sorted list variants of a folder. */
|
|
90
|
+
declare function locationListCachePrefix(location?: string): string;
|
|
87
91
|
declare function projectionKey(projectionId: string, scopeId: string): string;
|
|
88
92
|
declare function cacheKey(action: ActionRef | string, payload?: Record<string, unknown>): string;
|
|
89
93
|
|
|
@@ -110,6 +114,8 @@ interface ReadCacheStore {
|
|
|
110
114
|
getEntry: (key: string) => CacheEntry;
|
|
111
115
|
setEntry: (key: string, entry: CacheEntry | ((prev: CacheEntry) => CacheEntry)) => void;
|
|
112
116
|
invalidate: (key: string | string[]) => void;
|
|
117
|
+
/** Clear every cache entry whose key matches the predicate (e.g. location list variants). */
|
|
118
|
+
invalidateMatching: (match: (key: string) => boolean) => void;
|
|
113
119
|
subscribe: (listener: Listener) => () => void;
|
|
114
120
|
fetch: <T>(key: string, fetcher: () => Promise<T>) => Promise<T>;
|
|
115
121
|
}
|
|
@@ -136,6 +142,9 @@ interface SdkApi {
|
|
|
136
142
|
invokeOptimistic: (action: Parameters<ReactSdk['invoke']>[0], payload?: Record<string, unknown>, optimistic?: OptimisticResourceEvent) => ReturnType<ReactSdk['invoke']>;
|
|
137
143
|
read: typeof useRead;
|
|
138
144
|
invalidate: (key: string | string[]) => void;
|
|
145
|
+
invalidateMatching: (match: (key: string) => boolean) => void;
|
|
146
|
+
/** Invalidate unpaginated + paginated list cache entries for a folder. */
|
|
147
|
+
invalidateLocation: (location: string) => void;
|
|
139
148
|
cacheKey: typeof cacheKey;
|
|
140
149
|
sdk: ReactSdk;
|
|
141
150
|
}
|
|
@@ -154,5 +163,5 @@ declare function usePushInvalidation(sdk: {
|
|
|
154
163
|
/** Deterministic JSON for cache keys — sorted object keys, no Ramda. */
|
|
155
164
|
declare function stableSerialize(value: unknown): string;
|
|
156
165
|
|
|
157
|
-
export { AsyncStatus, Context, PushInvalidationSubscriber, ReactSdk, WorkspaceProvider, applyOptimisticResource, cacheKey, normalizeLocation, projectionKey, resolveActionId, rollbackOptimisticResource, stableSerialize, toActionRef, usePushInvalidation, useRead, useReadCacheStore, useSdk };
|
|
166
|
+
export { AsyncStatus, Context, PushInvalidationSubscriber, ReactSdk, WorkspaceProvider, applyOptimisticResource, cacheKey, locationListCacheKey, locationListCachePrefix, normalizeLocation, projectionKey, resolveActionId, rollbackOptimisticResource, stableSerialize, toActionRef, usePushInvalidation, useRead, useReadCacheStore, useSdk };
|
|
158
167
|
export type { ActionRef, AsyncStatusType, Config, OptimisticResourceEvent, ReadOptions, ReadResult, SdkApi, WorkspaceProviderProps };
|
package/build/types/Cache.d.ts
CHANGED
|
@@ -11,9 +11,16 @@ export interface ReadCacheStore {
|
|
|
11
11
|
getEntry: (key: string) => CacheEntry;
|
|
12
12
|
setEntry: (key: string, entry: CacheEntry | ((prev: CacheEntry) => CacheEntry)) => void;
|
|
13
13
|
invalidate: (key: string | string[]) => void;
|
|
14
|
+
/** Clear every cache entry whose key matches the predicate (e.g. location list variants). */
|
|
15
|
+
invalidateMatching: (match: (key: string) => boolean) => void;
|
|
14
16
|
subscribe: (listener: Listener) => () => void;
|
|
15
17
|
fetch: <T>(key: string, fetcher: () => Promise<T>) => Promise<T>;
|
|
16
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Keep the store object identity stable across cache writes.
|
|
21
|
+
* `getEntry` used to close over `state`, so every completed read rebuilt
|
|
22
|
+
* `useSdk()` and retriggered `useEffect(..., [sdk])` loaders (~0.5s flicker).
|
|
23
|
+
*/
|
|
17
24
|
export declare const createCache: ({ get: _get, set: _set, getInitialState, }: CacheConfig) => (props: any) => React.JSX.Element;
|
|
18
25
|
export declare const useCache: (cacheKey: string, defaultValue?: unknown) => {
|
|
19
26
|
data: any;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type ActionRef } from './action';
|
|
2
|
+
/** Exact unpaginated list key for a folder location. */
|
|
3
|
+
export declare function locationListCacheKey(location?: string): string;
|
|
4
|
+
/** Prefix used for paginated/sorted list variants of a folder. */
|
|
5
|
+
export declare function locationListCachePrefix(location?: string): string;
|
|
2
6
|
export declare function projectionKey(projectionId: string, scopeId: string): string;
|
|
3
7
|
export declare function cacheKey(action: ActionRef | string, payload?: Record<string, unknown>): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation tokens for read-cache fetches.
|
|
3
|
+
* invalidate() bumps the token so orphaned in-flight responses cannot write.
|
|
4
|
+
*/
|
|
5
|
+
export function bumpGeneration(generations: any, key: any): any;
|
|
6
|
+
export function readGeneration(generations: any, key: any): any;
|
|
7
|
+
export function isCurrentGeneration(generations: any, key: any, generation: any): boolean;
|
package/build/types/useSdk.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface SdkApi {
|
|
|
7
7
|
invokeOptimistic: (action: Parameters<ReactSdk['invoke']>[0], payload?: Record<string, unknown>, optimistic?: OptimisticResourceEvent) => ReturnType<ReactSdk['invoke']>;
|
|
8
8
|
read: typeof useRead;
|
|
9
9
|
invalidate: (key: string | string[]) => void;
|
|
10
|
+
invalidateMatching: (match: (key: string) => boolean) => void;
|
|
11
|
+
/** Invalidate unpaginated + paginated list cache entries for a folder. */
|
|
12
|
+
invalidateLocation: (location: string) => void;
|
|
10
13
|
cacheKey: typeof cacheKey;
|
|
11
14
|
sdk: ReactSdk;
|
|
12
15
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/sdk-react",
|
|
3
3
|
"description": "Software Development Kit React",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.11.0",
|
|
5
5
|
"url": "git://github.com/ossy-se/packages/sdk-react",
|
|
6
6
|
"source": "src/public.index.ts",
|
|
7
7
|
"main": "./build/packages/sdk-react/src/public.index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "",
|
|
19
19
|
"build": "rollup -c rollup.config.js",
|
|
20
|
-
"test": ""
|
|
20
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose"
|
|
21
21
|
},
|
|
22
22
|
"browserslist": {
|
|
23
23
|
"production": [
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"@babel/eslint-parser": "^7.15.8",
|
|
38
38
|
"@babel/preset-env": "^7.26.0",
|
|
39
39
|
"@babel/preset-react": "^7.24.1",
|
|
40
|
-
"@babel/preset-typescript": "^7.26.0"
|
|
40
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
41
|
+
"@jest/globals": "^30.2.0",
|
|
42
|
+
"jest": "^30.2.0"
|
|
41
43
|
},
|
|
42
44
|
"peerDependencies": {
|
|
43
45
|
"@ossy/fold": ">=1.0.0 <4.0.0",
|
|
@@ -53,5 +55,5 @@
|
|
|
53
55
|
"/build",
|
|
54
56
|
"README.md"
|
|
55
57
|
],
|
|
56
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "53ff8456920e09151c9d88df4a6c3ee958d811eb"
|
|
57
59
|
}
|