@donotdev/crud 0.0.2 → 0.0.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.
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.js +1 -1
- package/dist/CrudStore.d.ts +1 -1
- package/dist/CrudStore.d.ts.map +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/adapters/FirestoreAdapter.js +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/components/ControlledFields.d.ts +18 -143
- package/dist/components/ControlledFields.d.ts.map +1 -1
- package/dist/components/ControlledFields.js +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/EntityFormRenderer.js +1 -1
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.d.ts +42 -0
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -0
- package/dist/components/form/fields/AddressFieldComponent.js +1 -0
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MapFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/RadioFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.d.ts +24 -18
- package/dist/components/form/fields/ReferenceFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/components/form/fields/TextFieldComponent.js +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
- package/dist/components/form/fields/index.d.ts +2 -0
- package/dist/components/form/fields/index.d.ts.map +1 -1
- package/dist/components/form/fields/index.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useCrud.d.ts +9 -17
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/package.json +4 -4
package/dist/useCrud.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type { dndevSchema } from '@donotdev/core';
|
|
1
|
+
import type { dndevSchema, FeatureStatus } from '@donotdev/core';
|
|
2
2
|
import { type BackendType } from './CrudStore';
|
|
3
|
-
import type
|
|
3
|
+
import { type QueryOptions } from './CrudService';
|
|
4
4
|
export interface UseCrudOptions<T> {
|
|
5
5
|
backend?: BackendType;
|
|
6
6
|
schema?: dndevSchema<T>;
|
|
7
|
+
/** TanStack Query stale time in ms (default: 5 min) */
|
|
8
|
+
staleTime?: number;
|
|
9
|
+
/** Disable caching (bypass TanStack Query) */
|
|
10
|
+
noCache?: boolean;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* Selector type for useCrud hook
|
|
@@ -13,27 +17,13 @@ export type CrudSelector = 'isAvailable';
|
|
|
13
17
|
* React hook for CRUD operations
|
|
14
18
|
*
|
|
15
19
|
* @overload Selector mode - get global CRUD state
|
|
16
|
-
* @param selector - 'isAvailable' to check if CRUD service is ready
|
|
17
|
-
* @returns Selected value
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* const isAvailable = useCrud('isAvailable');
|
|
22
|
-
* ```
|
|
23
20
|
*/
|
|
24
21
|
export declare function useCrud(selector: 'isAvailable'): boolean;
|
|
25
22
|
/**
|
|
26
23
|
* @overload Collection mode - full CRUD operations
|
|
27
|
-
* @param collection - Collection name
|
|
28
|
-
* @param options - Options including backend type and schema
|
|
29
|
-
* @returns CRUD operations and state
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const { query, update, isAvailable } = useCrud<License>('licenses', { schema });
|
|
34
|
-
* ```
|
|
35
24
|
*/
|
|
36
25
|
export declare function useCrud<T = unknown>(collection: string, options?: UseCrudOptions<T>): {
|
|
26
|
+
status: FeatureStatus;
|
|
37
27
|
data: T | null;
|
|
38
28
|
loading: boolean;
|
|
39
29
|
error: Error | null;
|
|
@@ -45,6 +35,8 @@ export declare function useCrud<T = unknown>(collection: string, options?: UseCr
|
|
|
45
35
|
query: (options: QueryOptions) => Promise<T[]>;
|
|
46
36
|
subscribe: (id: string, callback: (data: T | null, error?: Error) => void) => () => void;
|
|
47
37
|
subscribeToCollection: (options: QueryOptions, callback: (data: T[], error?: Error) => void) => () => void;
|
|
38
|
+
/** Invalidate cache for this collection */
|
|
39
|
+
invalidate: () => Promise<void>;
|
|
48
40
|
isAvailable: boolean;
|
|
49
41
|
};
|
|
50
42
|
//# sourceMappingURL=useCrud.d.ts.map
|
package/dist/useCrud.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrud.d.ts","sourceRoot":"","sources":["../src/useCrud.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useCrud.d.ts","sourceRoot":"","sources":["../src/useC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,CAAC,CAAC;IACtC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C,SAAS,EAAE,CACT,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAC9C,MAAM,IAAI,CAAC;IAChB,qBAAqB,EAAE,CACrB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KACzC,MAAM,IAAI,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
|
package/dist/useCrud.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as
|
|
1
|
+
"use client";import{useEffect as N}from"react";import{DEGRADED_CRUD_API as I,FEATURE_STATUS as d,useFeatureConsent as k}from"@donotdev/core";import{FRAMEWORK_FEATURES as z,handleError as G,isClient as L}from"@donotdev/core";import{useCrudStore as c}from"./CrudStore";import{getCrudService as M}from"./CrudService";let r=null,i=null,C=null,q=!1;const K=1e3*60*5;async function U(){if(i)return i;const{QueryClient:o}=await import("@tanstack/react-query");return i=new o({defaultOptions:{queries:{staleTime:K,gcTime:1e3*60*30,retry:1,refetchOnWindowFocus:!1}}}),i}function B(o,f={}){const l=k(z.CRUD),_=c(e=>e.crudService!==null);if(o==="isAvailable")return l?_:I.isAvailable;const t=o,y=f.backend||"firestore",u=f.schema,v=f.staleTime??K,a=f.noCache??!1;N(()=>{if(!L()||!l||!u)return;const{backend:e}=c.getState();e===y&&r||C||(C=(async()=>{try{const n=M();r=n,n.setStore(c),await n.initialize(y),q=!1}catch(n){q||(G(n,{userMessage:"Failed to initialize CRUD service.",context:{backend:y,collection:t},severity:"error"}),q=!0)}finally{C=null}})())},[l,y,u]);const E=async e=>r?a?r.get(t,e,u):(await U()).fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>r.get(t,e,u),staleTime:v}):null,A=async(e,n)=>{r&&(await r.set(t,e,n,u),!a&&i&&i.invalidateQueries({queryKey:["crud",t]}))},b=async(e,n)=>{r&&(await r.update(t,e,n),!a&&i&&i.invalidateQueries({queryKey:["crud",t]}))},D=async e=>{r&&(await r.delete(t,e),!a&&i&&i.invalidateQueries({queryKey:["crud",t]}))},g=async e=>{if(!r)return"";const n=await r.add(t,e,u);return!a&&i&&i.invalidateQueries({queryKey:["crud",t]}),n},T=async e=>r?a?r.query(t,e,u):(await U()).fetchQuery({queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:()=>r.query(t,e,u),staleTime:v}):[],S=(e,n)=>r?r.subscribe(t,e,(s,m)=>{!a&&i&&s&&i.setQueryData(["crud",t,"get",e],s),n(s,m)},u):()=>{},R=(e,n)=>r?r.subscribeToCollection(t,e,(s,m)=>{!a&&i&&s&&i.setQueryData(["crud",t,"query",JSON.stringify(e)],s),n(s,m)},u):()=>{},w=async()=>{i&&await i.invalidateQueries({queryKey:["crud",t]})},Q=c(e=>e.collections[t]?.data.current||null),h=c(e=>e.collections[t]?.loading||!1),F=c(e=>e.collections[t]?.error||null),p=l?r?d.READY:d.INITIALIZING:d.DEGRADED;return!l||!u||!r?{...I,status:p,data:Q,loading:h,error:F,get:E,set:A,update:b,delete:D,add:g,query:T,subscribe:S,subscribeToCollection:R,invalidate:w,isAvailable:!1}:{status:d.READY,data:Q,loading:h,error:F,get:E,set:A,update:b,delete:D,add:g,query:T,subscribe:S,subscribeToCollection:R,invalidate:w,isAvailable:!0}}export{B as useCrud};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getCrudService as
|
|
1
|
+
import{getCrudService as o}from"../CrudService";async function u(s,t){const e=o(),r=[],a=t.range?.start??1,n=t.range?.end??28;for(let c=a;c<=n;c++){const i=String(c),d=await e.get(t.path(s),i,t.schema);d&&r.push(d)}return r}async function m(s,t,e){const r=o();for(const a of e){const n=t.idOf(a);await r.set(t.path(s),n,a,t.schema)}}async function h(s,t,e){const r=o();if(t.idFrom){const a=t.idFrom(e);return r.set(t.path(s),a,e,t.schema)}return r.add(t.path(s),e,t.schema)}export{h as appendToCollection,u as loadDeterministicRange,m as upsertDeterministic};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/crud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"type-check": "tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@donotdev/components": "0.0.
|
|
51
|
-
"@donotdev/core": "0.0.
|
|
50
|
+
"@donotdev/components": "0.0.4",
|
|
51
|
+
"@donotdev/core": "0.0.4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@donotdev/firebase": "0.0.
|
|
54
|
+
"@donotdev/firebase": "0.0.4",
|
|
55
55
|
"@hookform/resolvers": "^5.2.2",
|
|
56
56
|
"firebase": "^12.5.0",
|
|
57
57
|
"lucide-react": "^0.562.0",
|