jazz-tools 0.19.20 → 0.19.22
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/.svelte-kit/__package__/server.d.ts.map +1 -1
- package/.svelte-kit/__package__/server.js +9 -7
- package/.turbo/turbo-build.log +56 -56
- package/CHANGELOG.md +15 -0
- package/dist/better-auth/auth/server.d.ts.map +1 -1
- package/dist/better-auth/auth/server.js +4 -4
- package/dist/better-auth/auth/server.js.map +1 -1
- package/dist/better-auth/database-adapter/index.js.map +1 -1
- package/dist/better-auth/database-adapter/repository/generic.d.ts +3 -3
- package/dist/better-auth/database-adapter/repository/session.d.ts +2 -2
- package/dist/better-auth/database-adapter/schema.d.ts +3 -3
- package/dist/better-auth/database-adapter/schema.d.ts.map +1 -1
- package/dist/{chunk-MI24YFCY.js → chunk-QCTQH5RS.js} +1 -1
- package/dist/chunk-QCTQH5RS.js.map +1 -0
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/dist/media/{chunk-3LKBM3G3.js → chunk-IRL3KNPO.js} +2 -2
- package/dist/media/{chunk-3LKBM3G3.js.map → chunk-IRL3KNPO.js.map} +1 -1
- package/dist/media/create-image/react-native.d.ts +1 -1
- package/dist/media/create-image/react-native.d.ts.map +1 -1
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.js +5 -5
- package/dist/media/index.native.js.map +1 -1
- package/dist/media/index.server.js +1 -1
- package/dist/react/hooks.d.ts +1 -2
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.js +7 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +92 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +126 -57
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/useCoStates.test.d.ts +2 -0
- package/dist/react-core/tests/useCoStates.test.d.ts.map +1 -0
- package/dist/react-native/index.js +4 -0
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +4 -0
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/svelte/auth/ClerkAuth.svelte.d.ts +38 -0
- package/dist/svelte/auth/ClerkAuth.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/ClerkAuth.svelte.js +47 -0
- package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte +156 -0
- package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts +67 -0
- package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/RegisterClerkAuth.svelte +27 -0
- package/dist/svelte/auth/RegisterClerkAuth.svelte.d.ts +17 -0
- package/dist/svelte/auth/RegisterClerkAuth.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/index.d.ts +2 -0
- package/dist/svelte/auth/index.d.ts.map +1 -1
- package/dist/svelte/auth/index.js +2 -0
- package/dist/svelte/tests/ClerkAuth.svelte.test.d.ts +2 -0
- package/dist/svelte/tests/ClerkAuth.svelte.test.d.ts.map +1 -0
- package/dist/svelte/tests/ClerkAuth.svelte.test.js +202 -0
- package/dist/svelte/tests/TestClerkAuthWrapper.svelte +16 -0
- package/dist/svelte/tests/TestClerkAuthWrapper.svelte.d.ts +8 -0
- package/dist/svelte/tests/TestClerkAuthWrapper.svelte.d.ts.map +1 -0
- package/dist/svelte/tests/testUtils.d.ts +1 -0
- package/dist/svelte/tests/testUtils.d.ts.map +1 -1
- package/dist/svelte/tests/testUtils.js +3 -1
- package/dist/testing.js +1 -1
- package/dist/tools/auth/clerk/index.d.ts +1 -1
- package/dist/tools/auth/clerk/types.d.ts +1 -1
- package/dist/tools/auth/clerk/types.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -0
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +1 -1
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/worker/JazzMessageChannel.d.ts +36 -0
- package/dist/worker/JazzMessageChannel.d.ts.map +1 -0
- package/dist/worker/index.d.ts +7 -1
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +28 -17
- package/dist/worker/index.js.map +1 -1
- package/package.json +4 -4
- package/src/better-auth/auth/server.ts +9 -7
- package/src/better-auth/database-adapter/repository/generic.ts +3 -3
- package/src/better-auth/database-adapter/repository/session.ts +2 -2
- package/src/better-auth/database-adapter/schema.ts +5 -5
- package/src/media/create-image/react-native.ts +9 -7
- package/src/media/create-image-factory.test.ts +1 -1
- package/src/media/create-image-factory.ts +1 -1
- package/src/react/hooks.tsx +4 -2
- package/src/react-core/hooks.ts +321 -76
- package/src/react-core/tests/testUtils.tsx +2 -2
- package/src/react-core/tests/useCoState.selector.test.ts +309 -22
- package/src/react-core/tests/useCoStates.test.tsx +414 -0
- package/src/react-native-core/hooks.tsx +2 -0
- package/src/svelte/auth/ClerkAuth.svelte.ts +67 -0
- package/src/svelte/auth/JazzSvelteProviderWithClerk.svelte +156 -0
- package/src/svelte/auth/RegisterClerkAuth.svelte +27 -0
- package/src/svelte/auth/index.ts +2 -0
- package/src/svelte/tests/ClerkAuth.svelte.test.ts +305 -0
- package/src/svelte/tests/TestClerkAuthWrapper.svelte +16 -0
- package/src/svelte/tests/testUtils.ts +4 -1
- package/src/tools/auth/clerk/types.ts +1 -1
- package/src/tools/exports.ts +5 -0
- package/src/tools/subscribe/types.ts +1 -1
- package/src/tools/tests/inbox.test.ts +7 -7
- package/src/tools/tests/testStorage.ts +2 -2
- package/src/worker/JazzMessageChannel.ts +73 -0
- package/src/worker/index.ts +36 -17
- package/dist/chunk-MI24YFCY.js.map +0 -1
package/dist/worker/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/worker/index.ts"],"sourcesContent":["import {\n AgentSecret,\n CryptoProvider,\n LocalNode,\n Peer,\n StorageAPI,\n} from \"cojson\";\nimport {\n type AnyWebSocketConstructor,\n WebSocketPeerWithReconnection,\n} from \"cojson-transport-ws\";\nimport { WasmCrypto } from \"cojson/crypto/WasmCrypto\";\nimport {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueFromRaw,\n Inbox,\n InstanceOfSchema,\n Loaded,\n createJazzContextFromExistingCredentials,\n MockSessionProvider,\n} from \"jazz-tools\";\n\ntype WorkerOptions<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n accountID?: string;\n accountSecret?: string;\n syncServer?: string;\n WebSocket?: AnyWebSocketConstructor;\n AccountSchema?: S;\n crypto?: CryptoProvider;\n /**\n * If true, the inbox will not be loaded.\n */\n skipInboxLoad?: boolean;\n /**\n * If false, the worker will not set in the global account context\n */\n asActiveAccount?: boolean;\n storage?: StorageAPI;\n};\n\n/** @category Context Creation */\nexport async function startWorker<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>(options: WorkerOptions<S>) {\n const {\n accountID = process.env.JAZZ_WORKER_ACCOUNT,\n accountSecret = process.env.JAZZ_WORKER_SECRET,\n syncServer = \"wss://cloud.jazz.tools\",\n AccountSchema = Account as unknown as S,\n skipInboxLoad = false,\n asActiveAccount = true,\n } = options;\n\n let node: LocalNode | undefined = undefined;\n\n const peers: Peer[] = [];\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/worker/index.ts"],"sourcesContent":["import {\n AgentSecret,\n CryptoProvider,\n LocalNode,\n Peer,\n StorageAPI,\n} from \"cojson\";\nimport {\n type AnyWebSocketConstructor,\n WebSocketPeerWithReconnection,\n} from \"cojson-transport-ws\";\nimport { WasmCrypto } from \"cojson/crypto/WasmCrypto\";\nimport {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueFromRaw,\n Inbox,\n InstanceOfSchema,\n Loaded,\n createJazzContextFromExistingCredentials,\n MockSessionProvider,\n} from \"jazz-tools\";\n\ntype WorkerOptions<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n> = {\n accountID?: string;\n accountSecret?: string;\n /**\n * A peer to connect to for synchronization.\n * If provided, syncServer is ignored.\n */\n peer?: Peer;\n syncServer?: string;\n WebSocket?: AnyWebSocketConstructor;\n AccountSchema?: S;\n crypto?: CryptoProvider;\n /**\n * If true, the inbox will not be loaded.\n */\n skipInboxLoad?: boolean;\n /**\n * If false, the worker will not set in the global account context\n */\n asActiveAccount?: boolean;\n storage?: StorageAPI;\n};\n\n/** @category Context Creation */\nexport async function startWorker<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | AnyAccountSchema,\n>(options: WorkerOptions<S>) {\n const {\n accountID = process.env.JAZZ_WORKER_ACCOUNT,\n accountSecret = process.env.JAZZ_WORKER_SECRET,\n syncServer = \"wss://cloud.jazz.tools\",\n AccountSchema = Account as unknown as S,\n skipInboxLoad = false,\n asActiveAccount = true,\n } = options;\n\n let node: LocalNode | undefined = undefined;\n\n const peers: Peer[] = [];\n\n // If a peer is provided directly, use it instead of WebSocket\n let wsPeer: WebSocketPeerWithReconnection | undefined;\n\n if (options.peer) {\n peers.push(options.peer);\n } else {\n wsPeer = new WebSocketPeerWithReconnection({\n peer: syncServer,\n reconnectionTimeout: 100,\n addPeer: (peer) => {\n if (node) {\n node.syncManager.addPeer(peer);\n } else {\n peers.push(peer);\n }\n },\n removePeer: () => {},\n WebSocketConstructor: options.WebSocket,\n });\n\n wsPeer.enable();\n }\n\n if (!accountID) {\n throw new Error(\"No accountID provided\");\n }\n if (!accountSecret) {\n throw new Error(\"No accountSecret provided\");\n }\n if (!accountID.startsWith(\"co_\")) {\n throw new Error(\"Invalid accountID\");\n }\n if (!accountSecret?.startsWith(\"sealerSecret_\")) {\n throw new Error(\"Invalid accountSecret\");\n }\n\n const context = await createJazzContextFromExistingCredentials({\n credentials: {\n accountID: accountID,\n secret: accountSecret as AgentSecret,\n },\n AccountSchema,\n sessionProvider: new MockSessionProvider(),\n peers,\n crypto: options.crypto ?? (await WasmCrypto.create()),\n asActiveAccount,\n storage: options.storage,\n });\n\n const account = context.account as InstanceOfSchema<S>;\n node = account.$jazz.localNode;\n\n if (!account.$jazz.refs.profile?.id) {\n throw new Error(\"Account has no profile\");\n }\n\n const inbox = skipInboxLoad ? undefined : await Inbox.load(account);\n\n async function done() {\n await context.account.$jazz.waitForAllCoValuesSync();\n\n wsPeer?.disable();\n context.done();\n }\n\n const inboxPublicApi = inbox\n ? {\n subscribe: inbox.subscribe.bind(inbox) as Inbox[\"subscribe\"],\n }\n : {\n subscribe: () => {},\n };\n\n return {\n /**\n * The worker account instance.\n */\n worker: context.account as Loaded<S>,\n experimental: {\n /**\n * API to subscribe to the inbox messages.\n *\n * More info on the Inbox API: https://jazz.tools/docs/react/server-side/inbox\n */\n inbox: inboxPublicApi,\n },\n /**\n * Wait for the connection to the sync server to be established.\n *\n * If already connected, it will resolve immediately.\n * Returns immediately if using a custom peer.\n */\n waitForConnection() {\n return wsPeer?.waitUntilConnected() ?? Promise.resolve();\n },\n subscribeToConnectionChange(listener: (connected: boolean) => void) {\n if (!wsPeer) {\n // For custom peers, immediately notify as connected\n listener(true);\n return () => {};\n }\n\n wsPeer.subscribe(listener);\n\n return () => {\n wsPeer.unsubscribe(listener);\n };\n },\n /**\n * Waits for all CoValues to sync and then shuts down the worker.\n *\n * To only wait for sync use worker.$jazz.waitForAllCoValuesSync()\n *\n * @deprecated Use shutdownWorker\n */\n done,\n /**\n * Waits for all CoValues to sync and then shuts down the worker.\n *\n * To only wait for sync use worker.$jazz.waitForAllCoValuesSync()\n */\n shutdownWorker() {\n return done();\n },\n };\n}\n"],"mappings":"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","names":[]}
|
package/package.json
CHANGED
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
},
|
|
212
212
|
"type": "module",
|
|
213
213
|
"license": "MIT",
|
|
214
|
-
"version": "0.19.
|
|
214
|
+
"version": "0.19.22",
|
|
215
215
|
"dependencies": {
|
|
216
216
|
"@manuscripts/prosemirror-recreate-steps": "^0.1.4",
|
|
217
217
|
"@scure/base": "1.2.1",
|
|
@@ -228,9 +228,9 @@
|
|
|
228
228
|
"prosemirror-transform": "^1.9.0",
|
|
229
229
|
"use-sync-external-store": "^1.5.0",
|
|
230
230
|
"zod": "4.1.11",
|
|
231
|
-
"cojson": "0.19.
|
|
232
|
-
"cojson-storage-indexeddb": "0.19.
|
|
233
|
-
"cojson-transport-ws": "0.19.
|
|
231
|
+
"cojson": "0.19.22",
|
|
232
|
+
"cojson-storage-indexeddb": "0.19.22",
|
|
233
|
+
"cojson-transport-ws": "0.19.22"
|
|
234
234
|
},
|
|
235
235
|
"devDependencies": {
|
|
236
236
|
"@scure/bip39": "^1.3.0",
|
|
@@ -168,8 +168,9 @@ export const jazzPlugin: () => JazzPlugin = () => {
|
|
|
168
168
|
{
|
|
169
169
|
matcher: (context) => {
|
|
170
170
|
return (
|
|
171
|
-
context.path
|
|
172
|
-
context.path
|
|
171
|
+
context.path?.startsWith("/callback") ||
|
|
172
|
+
context.path?.startsWith("/oauth2/callback") ||
|
|
173
|
+
false
|
|
173
174
|
);
|
|
174
175
|
},
|
|
175
176
|
handler: createAuthMiddleware(async (ctx) => {
|
|
@@ -212,7 +213,7 @@ export const jazzPlugin: () => JazzPlugin = () => {
|
|
|
212
213
|
*/
|
|
213
214
|
{
|
|
214
215
|
matcher: (context) => {
|
|
215
|
-
return context.path
|
|
216
|
+
return context.path?.startsWith("/sign-in/email-otp") || false;
|
|
216
217
|
},
|
|
217
218
|
handler: createAuthMiddleware(async (ctx) => {
|
|
218
219
|
const email = ctx.body.email;
|
|
@@ -256,9 +257,10 @@ export const jazzPlugin: () => JazzPlugin = () => {
|
|
|
256
257
|
{
|
|
257
258
|
matcher: (context) => {
|
|
258
259
|
return (
|
|
259
|
-
context.path
|
|
260
|
-
context.path
|
|
261
|
-
context.path
|
|
260
|
+
context.path?.startsWith("/sign-up") ||
|
|
261
|
+
context.path?.startsWith("/sign-in") ||
|
|
262
|
+
context.path?.startsWith("/get-session") ||
|
|
263
|
+
false
|
|
262
264
|
);
|
|
263
265
|
},
|
|
264
266
|
handler: createAuthMiddleware({}, async (ctx) => {
|
|
@@ -281,7 +283,7 @@ export const jazzPlugin: () => JazzPlugin = () => {
|
|
|
281
283
|
*/
|
|
282
284
|
{
|
|
283
285
|
matcher: (context) => {
|
|
284
|
-
return context.path
|
|
286
|
+
return context.path?.startsWith("/sign-in/social") || false;
|
|
285
287
|
},
|
|
286
288
|
handler: createAuthMiddleware(async (ctx) => {
|
|
287
289
|
if (!contextContainsJazzAuth(ctx)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CleanedWhere } from "better-auth/adapters";
|
|
2
|
-
import {
|
|
2
|
+
import { BetterAuthDBSchema } from "better-auth/db";
|
|
3
3
|
import { Account, CoList, CoMap, Group, co } from "jazz-tools";
|
|
4
4
|
import type { Database, TableItem } from "../schema.js";
|
|
5
5
|
import {
|
|
@@ -14,7 +14,7 @@ export class JazzRepository {
|
|
|
14
14
|
protected databaseRoot: co.loaded<Database, { group: true }>;
|
|
15
15
|
protected worker: Account;
|
|
16
16
|
protected owner: Group;
|
|
17
|
-
protected betterAuthSchema:
|
|
17
|
+
protected betterAuthSchema: BetterAuthDBSchema;
|
|
18
18
|
|
|
19
19
|
private coValuesTracker:
|
|
20
20
|
| {
|
|
@@ -26,7 +26,7 @@ export class JazzRepository {
|
|
|
26
26
|
databaseSchema: Database,
|
|
27
27
|
databaseRoot: co.loaded<Database, { group: true }>,
|
|
28
28
|
worker: Account,
|
|
29
|
-
betterAuthSchema:
|
|
29
|
+
betterAuthSchema: BetterAuthDBSchema = {},
|
|
30
30
|
ensureSync: boolean = false,
|
|
31
31
|
) {
|
|
32
32
|
this.databaseSchema = databaseSchema;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BetterAuthDBSchema } from "better-auth/db";
|
|
2
2
|
import { CleanedWhere } from "better-auth/adapters";
|
|
3
3
|
import { co, Account } from "jazz-tools";
|
|
4
4
|
import { JazzRepository } from "./generic";
|
|
@@ -22,7 +22,7 @@ export class SessionRepository extends JazzRepository {
|
|
|
22
22
|
databaseSchema: Database,
|
|
23
23
|
databaseRoot: co.loaded<Database, { group: true }>,
|
|
24
24
|
worker: Account,
|
|
25
|
-
betterAuthSchema:
|
|
25
|
+
betterAuthSchema: BetterAuthDBSchema = {},
|
|
26
26
|
ensureSync: boolean = false,
|
|
27
27
|
) {
|
|
28
28
|
super(databaseSchema, databaseRoot, worker, betterAuthSchema, ensureSync);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "better-auth/db";
|
|
2
2
|
import { Group, co, z } from "jazz-tools";
|
|
3
3
|
|
|
4
4
|
type TableRow = co.Map<any>;
|
|
@@ -20,7 +20,7 @@ type WorkerAccount = co.Account<{
|
|
|
20
20
|
type JazzSchema = {
|
|
21
21
|
WorkerAccount: WorkerAccount;
|
|
22
22
|
DatabaseRoot: Database;
|
|
23
|
-
betterAuthSchema:
|
|
23
|
+
betterAuthSchema: BetterAuthDBSchema;
|
|
24
24
|
loadDatabase: (
|
|
25
25
|
account: co.loaded<co.Account>,
|
|
26
26
|
options?: Parameters<Database["loadUnique"]>[2],
|
|
@@ -29,7 +29,7 @@ type JazzSchema = {
|
|
|
29
29
|
|
|
30
30
|
const DATABASE_ROOT_ID = "better-auth-root";
|
|
31
31
|
|
|
32
|
-
export function createJazzSchema(schema:
|
|
32
|
+
export function createJazzSchema(schema: BetterAuthDBSchema): JazzSchema {
|
|
33
33
|
const tablesSchema = generateSchemaFromBetterAuthSchema(schema);
|
|
34
34
|
|
|
35
35
|
const DatabaseRoot: Database = co.map({
|
|
@@ -134,7 +134,7 @@ type ZodPrimitiveSchema =
|
|
|
134
134
|
| z.z.ZodLiteral;
|
|
135
135
|
type ZodOptionalPrimitiveSchema = z.z.ZodOptional<ZodPrimitiveSchema>;
|
|
136
136
|
|
|
137
|
-
function generateSchemaFromBetterAuthSchema(schema:
|
|
137
|
+
function generateSchemaFromBetterAuthSchema(schema: BetterAuthDBSchema) {
|
|
138
138
|
const tablesSchema: Record<string, Table> = {};
|
|
139
139
|
|
|
140
140
|
for (const [key, value] of Object.entries(schema)) {
|
|
@@ -178,7 +178,7 @@ function generateSchemaFromBetterAuthSchema(schema: BetterAuthDbSchema) {
|
|
|
178
178
|
return tablesSchema;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
function convertFieldToCoValue(field:
|
|
181
|
+
function convertFieldToCoValue(field: DBFieldAttribute) {
|
|
182
182
|
let zodType: ZodPrimitiveSchema | ZodOptionalPrimitiveSchema;
|
|
183
183
|
|
|
184
184
|
switch (field.type) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { NativeModules } from "react-native";
|
|
2
1
|
import type ImageResizerType from "@bam.tech/react-native-image-resizer";
|
|
3
2
|
import type ImageManipulatorType from "expo-image-manipulator";
|
|
4
3
|
import type { Account, Group } from "jazz-tools";
|
|
5
|
-
import { FileStream } from "jazz-tools";
|
|
4
|
+
import { co, type FileStream } from "jazz-tools";
|
|
6
5
|
import { Image } from "react-native";
|
|
7
6
|
import { createImageFactory } from "../create-image-factory";
|
|
8
7
|
|
|
@@ -108,7 +107,8 @@ async function getPlaceholderBase64(filePath: string): Promise<string> {
|
|
|
108
107
|
);
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
|
|
110
|
+
// Convert base64 to data URL
|
|
111
|
+
return "data:image/png;base64," + base64;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -147,7 +147,7 @@ async function resize(
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
function getMimeType(filePath: string): Promise<string> {
|
|
150
|
+
async function getMimeType(filePath: string): Promise<string> {
|
|
151
151
|
return fetch(filePath)
|
|
152
152
|
.then((res) => res.blob())
|
|
153
153
|
.then((blob) => blob.type);
|
|
@@ -167,9 +167,11 @@ export async function createFileStreamFromSource(
|
|
|
167
167
|
const blob = await fetch(filePath).then((res) => res.blob());
|
|
168
168
|
const arrayBuffer = await toArrayBuffer(blob);
|
|
169
169
|
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
return co
|
|
171
|
+
.fileStream()
|
|
172
|
+
.createFromArrayBuffer(arrayBuffer, blob.type, undefined, {
|
|
173
|
+
owner,
|
|
174
|
+
});
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
// TODO: look for more efficient way to do this as React Native hasn't blob.arrayBuffer()
|
|
@@ -162,8 +162,8 @@ describe("createImage", async () => {
|
|
|
162
162
|
expect(image).toBeDefined();
|
|
163
163
|
expect(image.originalSize).toEqual([1920, 400]);
|
|
164
164
|
expect(image.placeholderDataURL).not.toBeDefined();
|
|
165
|
-
|
|
166
165
|
expect(image[`256x53`]).toBeDefined();
|
|
166
|
+
expect(image[`512x107`]).toBeDefined();
|
|
167
167
|
expect(image[`1024x213`]).toBeDefined();
|
|
168
168
|
expect(image[`2048x427`]).not.toBeDefined();
|
|
169
169
|
|
|
@@ -154,7 +154,7 @@ async function createImage<TSourceType, TResizeOutput>(
|
|
|
154
154
|
if (options?.progressive) {
|
|
155
155
|
imageCoValue.$jazz.set("progressive", true);
|
|
156
156
|
|
|
157
|
-
const resizes = ([256, 1024, 2048] as const).filter(
|
|
157
|
+
const resizes = ([256, 512, 1024, 2048] as const).filter(
|
|
158
158
|
(s) =>
|
|
159
159
|
s <
|
|
160
160
|
Math.max(imageCoValue.originalSize[0], imageCoValue.originalSize[1]),
|
package/src/react/hooks.tsx
CHANGED
|
@@ -4,8 +4,6 @@ import { useEffect } from "react";
|
|
|
4
4
|
import { CoValueClassOrSchema } from "jazz-tools";
|
|
5
5
|
import { useJazzContext } from "jazz-tools/react-core";
|
|
6
6
|
|
|
7
|
-
export { useCoState, useAuthSecretStorage } from "jazz-tools/react-core";
|
|
8
|
-
|
|
9
7
|
export function useAcceptInvite<S extends CoValueClassOrSchema>({
|
|
10
8
|
invitedObjectSchema,
|
|
11
9
|
onAccept,
|
|
@@ -49,7 +47,10 @@ export function useAcceptInvite<S extends CoValueClassOrSchema>({
|
|
|
49
47
|
export {
|
|
50
48
|
experimental_useInboxSender,
|
|
51
49
|
useJazzContext,
|
|
50
|
+
useAuthSecretStorage,
|
|
52
51
|
useAccount,
|
|
52
|
+
useCoState,
|
|
53
|
+
useCoStates,
|
|
53
54
|
useAgent,
|
|
54
55
|
useLogOut,
|
|
55
56
|
useSyncConnectionStatus,
|
|
@@ -58,4 +59,5 @@ export {
|
|
|
58
59
|
useSubscriptionSelector,
|
|
59
60
|
useSuspenseAccount,
|
|
60
61
|
useSuspenseCoState,
|
|
62
|
+
useSuspenseCoStates,
|
|
61
63
|
} from "jazz-tools/react-core";
|