@inflector/aura 0.1.7 → 0.1.8
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/hooks/react.d.ts +21 -0
- package/dist/hooks/react.d.ts.map +1 -0
- package/dist/hooks/react.js +96 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CreateAura } from '../index';
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
export declare function useTable<TDef extends ValueOf<Awaited<ReturnType<typeof CreateAura<any, any>>>['Database']>>(table: TDef, Options?: {
|
|
4
|
+
where: Parameters<Awaited<ReturnType<TDef['GetOne']>['where']>>[0];
|
|
5
|
+
}): ({ [K_1 in keyof TDef as K_1 extends `__${string}` ? never : TDef[K_1] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? K_1 : never : never]: TDef[K_1] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U : never; } & { [K_2 in keyof TDef as K_2 extends `__${string}` ? never : TDef[K_2] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? never : K_2 : never]: TDef[K_2] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U | null : never; } extends infer T ? { [K in keyof T]: T[K]; } : never)[] | undefined;
|
|
6
|
+
export declare function useRecord<TDef extends ValueOf<Awaited<ReturnType<typeof CreateAura<any, any>>>['Database']>>(table: TDef, Options: {
|
|
7
|
+
where: Parameters<Awaited<ReturnType<TDef['GetOne']>['where']>>[0];
|
|
8
|
+
}): ({ [K_1 in keyof TDef as K_1 extends `__${string}` ? never : TDef[K_1] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? K_1 : never : never]: TDef[K_1] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U : never; } & { [K_2 in keyof TDef as K_2 extends `__${string}` ? never : TDef[K_2] extends import("@inflector/optima").ColumnBuilder<any, infer C extends import("@inflector/optima").ColumnConfig, any> ? C["notnull"] extends true ? never : K_2 : never]: TDef[K_2] extends import("@inflector/optima").ColumnBuilder<infer U, any, any> ? U | null : never; } extends infer T ? { [K in keyof T]: T[K]; } : never) | undefined;
|
|
9
|
+
export declare const useUser: (provider: Awaited<ReturnType<typeof CreateAura<any, any>>>) => {
|
|
10
|
+
id: string;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
email: string;
|
|
14
|
+
emailVerified: boolean;
|
|
15
|
+
name: string;
|
|
16
|
+
image?: string | null | undefined;
|
|
17
|
+
isAnonymous: boolean | null | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
export declare const useSession: (provider: any) => any;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/hooks/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,UAAU,CAAA;AAIjD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAkB5B,wBAAgB,QAAQ,CACtB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,CAAC,EAAE;IACR,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACnE,GAgDc,4tBAAS,GAAG,SAAS,CACrC;AAED,wBAAgB,SAAS,CACvB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,EAAE;IACP,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACnE,GAuCc,6tBAAU,SAAS,CACnC;AAED,eAAO,MAAM,OAAO,GAAI,UAAU,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;;;;;;;;;aAGjF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,UAAU,GAAG,QAGvC,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useStore } from '@nanostores/react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
function deepEqual(a, b) {
|
|
4
|
+
if (a === b)
|
|
5
|
+
return true;
|
|
6
|
+
if (typeof a !== 'object' || typeof b !== 'object' || !a || !b)
|
|
7
|
+
return false;
|
|
8
|
+
const keysA = Object.keys(a);
|
|
9
|
+
const keysB = Object.keys(b);
|
|
10
|
+
if (keysA.length !== keysB.length)
|
|
11
|
+
return false;
|
|
12
|
+
for (const key of keysA) {
|
|
13
|
+
if (!keysB.includes(key))
|
|
14
|
+
return false;
|
|
15
|
+
if (!deepEqual(a[key], b[key]))
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
export function useTable(table, Options) {
|
|
21
|
+
const [data, setData] = useState([]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const unsubscribe = table.Subscribe((event) => {
|
|
24
|
+
setData((prev) => {
|
|
25
|
+
if (!prev)
|
|
26
|
+
return prev;
|
|
27
|
+
switch (event.action) {
|
|
28
|
+
case 'Get':
|
|
29
|
+
return [...prev, event.data];
|
|
30
|
+
case 'Add':
|
|
31
|
+
return [...prev, event.data];
|
|
32
|
+
case 'AddMany':
|
|
33
|
+
return [...prev, ...event.data];
|
|
34
|
+
case 'Delete':
|
|
35
|
+
// Delete by matching old items
|
|
36
|
+
return prev.filter((x) => !event.data.old.some((d) => deepEqual(d, x)));
|
|
37
|
+
case 'Update':
|
|
38
|
+
// Update each item by matching old and replacing with new
|
|
39
|
+
return prev.map((item) => {
|
|
40
|
+
// Find if the item matches any "old" in event.data array
|
|
41
|
+
const update = event.data.find((d) => deepEqual(d.old, item));
|
|
42
|
+
if (update) {
|
|
43
|
+
return update.new;
|
|
44
|
+
}
|
|
45
|
+
return item;
|
|
46
|
+
});
|
|
47
|
+
default:
|
|
48
|
+
return prev;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}, Options?.where, true);
|
|
52
|
+
return () => {
|
|
53
|
+
unsubscribe();
|
|
54
|
+
};
|
|
55
|
+
}, [table, JSON.stringify(Options?.where)]);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
export function useRecord(table, Options) {
|
|
59
|
+
const [data, setData] = useState();
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const unsubscribe = table.Subscribe((event) => {
|
|
62
|
+
setData((prev) => {
|
|
63
|
+
if (!prev && event.action !== 'Get' && event.action !== 'Add')
|
|
64
|
+
return prev;
|
|
65
|
+
switch (event.action) {
|
|
66
|
+
case 'Get':
|
|
67
|
+
case 'Add':
|
|
68
|
+
return event.data;
|
|
69
|
+
case 'Delete':
|
|
70
|
+
// If deleted record matches the current one, remove it
|
|
71
|
+
if (event.data.old && deepEqual(event.data.old, prev))
|
|
72
|
+
return undefined;
|
|
73
|
+
return prev;
|
|
74
|
+
case 'Update':
|
|
75
|
+
// If the current record matches any "old", replace with "new"
|
|
76
|
+
const update = event.data.find((d) => deepEqual(d.old, prev));
|
|
77
|
+
if (update)
|
|
78
|
+
return update.new;
|
|
79
|
+
return prev;
|
|
80
|
+
default:
|
|
81
|
+
return prev;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}, Options.where, true);
|
|
85
|
+
return () => unsubscribe();
|
|
86
|
+
}, [table, JSON.stringify(Options.where)]);
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
export const useUser = (provider) => {
|
|
90
|
+
const data = useStore(provider.Auth.Signal);
|
|
91
|
+
return data ? data.data?.user : undefined;
|
|
92
|
+
};
|
|
93
|
+
export const useSession = (provider) => {
|
|
94
|
+
const data = useStore(provider.Auth.Signal);
|
|
95
|
+
return data ? data.data?.session : undefined;
|
|
96
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AuraDatabase } from "./database";
|
|
|
3
3
|
import { AuraStorage } from "./storage";
|
|
4
4
|
export * from "@inflector/optima/types";
|
|
5
5
|
export * from "./lib";
|
|
6
|
+
export * from "./hooks/react";
|
|
6
7
|
type CreateAuraConfig<T extends Record<string, any>> = {
|
|
7
8
|
config: {
|
|
8
9
|
Url: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,cAAc,yBAAyB,CAAC;AACxC,cAAc,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,cAAc,yBAAyB,CAAC;AACxC,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAE9B,KAAK,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IACnD,MAAM,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACtB,CAAC;IACF,MAAM,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAClD,QAAQ,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,QAAQ,EAAE,CAAC,CAAC;IACZ,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;IACxC,IAAI,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,UAAU,GACnB,CAAC,EACD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE7B,QAAQ,gBAAgB,CAAC,CAAC,CAAC,KAC5B,YAAY,CAAC,CAAC,EAAE,CAAC,CAQnB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createFunctionHandler } from "./function";
|
|
|
4
4
|
import { AuraStorage } from "./storage";
|
|
5
5
|
export * from "@inflector/optima/types";
|
|
6
6
|
export * from "./lib";
|
|
7
|
+
export * from "./hooks/react";
|
|
7
8
|
export const CreateAura = (Config) => {
|
|
8
9
|
const auth = AuraAuth(Config.config.Url, Config.config.WorkSpace);
|
|
9
10
|
return {
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inflector/aura",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"import": "./dist/index.js",
|
|
10
|
-
"types": "./dist/index.d.ts"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"react": "./dist/hooks/react.js"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"files": ["dist"],
|
|
@@ -29,11 +30,13 @@
|
|
|
29
30
|
"rollup-plugin-dts": "^6.1.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"typescript": "^5"
|
|
33
|
+
"typescript": "^5",
|
|
34
|
+
"react": "^19.2.3",
|
|
35
|
+
"@nanostores/react": "^1.0.0"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
38
|
"@inflector/optima": "1.1.0",
|
|
36
|
-
"@
|
|
39
|
+
"@types/react": "^19.2.10",
|
|
37
40
|
"axios": "^1.13.2",
|
|
38
41
|
"better-auth": "^1.4.16",
|
|
39
42
|
"chalk": "^5.6.2",
|