Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Nov 21, 2022
1 parent ea463f1 commit c63dc8e
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 68 deletions.
26 changes: 26 additions & 0 deletions files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
URL=http://localhost:3006/file
AUTH="Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsiYWRtaW4iXSwieC1oYXN1cmEtZGVmYXVsdC1yb2xlIjoiYWRtaW4iLCJ4LWhhc3VyYS11c2VyLWlkIjoiMzYyIn0sImlhdCI6MTY2NzU4NjAyMX0.M37W4jo-8zwEpXt0yTJ-bUvKA0OGWSqinlX1KreiA3o"
BUCKET=default

FILE_ID=55af1e60-0f28-454e-885e-ea6aab2bb285
ETAG=\"588be441fe7a59460850b0aa3e1c5a65\"

# we sleep for 1s to make sure a drift in the clocks between client/server doesn't
# lead to a JWTIssuedAtFuture error
sleep 1

output=`curl http://localhost:3006/file \
-v \
-H "Content-Type: multipart/form-data" \
-H "linkId: 652" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsiYWRtaW4iXSwieC1oYXN1cmEtZGVmYXVsdC1yb2xlIjoiYWRtaW4iLCJ4LWhhc3VyYS11c2VyLWlkIjoiMzYyIn0sImlhdCI6MTY2NzU4NjAyMX0.M37W4jo-8zwEpXt0yTJ-bUvKA0OGWSqinlX1KreiA3o" \
-F "metadata[]={\"id\":\"55af1e60-0f28-454e-885e-ea6aab2bb285\", \"name\":\"test.txt\"};type=application/json" \
-F "file[]=@./test.txt"`

echo $output

# time curl -v -o test0.jpg $URL/${FILE_ID} \
# -H "$AUTH"

# time curl -v -o test1.jpg $URL/${FILE_ID}?w=600\&h\=200\&q=50\&b=5 \
# -H "$AUTH"
52 changes: 46 additions & 6 deletions imports/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useLocalStore } from "@deep-foundation/store/local";
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
import { deprecate, inherits } from "util";
import { deleteMutation, generateQuery, generateQueryData, generateSerial, insertMutation, updateMutation } from "./gql";
import { Link, MinilinkCollection, minilinks, MinilinksInstance, MinilinksResult } from "./minilinks";
import { Link, MinilinkCollection, minilinks, MinilinksInstance, MinilinksResult, useMinilinksApply, useMinilinksQuery, useMinilinksSubscription } from "./minilinks";
import { awaitPromise } from "./promise";
import { useTokenController } from "./react-token";
import { reserve } from "./reserve";
Expand All @@ -31,7 +31,6 @@ export const _ids = {

export const _serialize = {
links: {
value: 'value',
fields: {
id: 'number',
from_id: 'number',
Expand All @@ -47,6 +46,7 @@ export const _serialize = {
typed: 'links',
selected: 'selector',
selectors: 'selector',
value: 'value',
string: 'value',
number: 'value',
object: 'value',
Expand Down Expand Up @@ -426,6 +426,14 @@ export interface DeepClientJWTOptions {
}

export class DeepClient<L = Link<number>> implements DeepClientInstance<L> {
useDeepSubscription = useDeepSubscription;
useDeepQuery = useDeepQuery;
useMinilinksQuery = (query: BoolExpLink) => useMinilinksQuery(this.minilinks, query);
useMinilinksSubscription = (query: BoolExpLink) => useMinilinksSubscription(this.minilinks, query)
useDeep = useDeep;
DeepProvider = DeepProvider;
DeepContext = DeepContext;

linkId?: number;
token?: string;
handleAuth?: (linkId?: number, token?: string) => any;
Expand Down Expand Up @@ -839,7 +847,21 @@ export function useDeep() {
return useContext(DeepContext);
}

export function useDeepQuery(query: any, options?: any): any {
export function useDeepQuery<Table extends 'links'|'numbers'|'strings'|'objects'|'can'|'selectors'|'tree'|'handlers', LL = Link<number>>(
query: BoolExpLink,
options?: {
table?: Table;
returning?: string;
variables?: any;
name?: string;
mini?: string;
},
): {
data?: LL[];
error?: any;
loading: boolean;
} {
const [miniName] = useState(options?.mini || Math.random().toString(36).slice(2, 7));
const deep = useDeep();
const wq = useMemo(() => {
const sq = serializeQuery(query);
Expand All @@ -860,13 +882,29 @@ export function useDeepQuery(query: any, options?: any): any {
});
}, [query, options]);
const result = useQuery(wq.query, { variables: wq?.variables });
useMinilinksApply(deep.minilinks, miniName, result?.data?.q0 || []);
const mlResult = deep.useMinilinksSubscription({ id: { _in: result?.data?.q0?.map(l => l.id) } });
return {
...result,
data: result?.data?.q0,
data: mlResult,
};
}

export function useDeepSubscription(query: any, options?: any): any {
export function useDeepSubscription<Table extends 'links'|'numbers'|'strings'|'objects'|'can'|'selectors'|'tree'|'handlers', LL = Link<number>>(
query: BoolExpLink,
options?: {
table?: Table;
returning?: string;
variables?: any;
name?: string;
mini?: string;
},
): {
data?: LL[];
error?: any;
loading: boolean;
} {
const [miniName] = useState(options?.mini || Math.random().toString(36).slice(2, 7));
const deep = useDeep();
const wq = useMemo(() => {
const sq = serializeQuery(query);
Expand All @@ -887,8 +925,10 @@ export function useDeepSubscription(query: any, options?: any): any {
});
}, [query, options]);
const result = useSubscription(wq.query, { variables: wq?.variables });
useMinilinksApply(deep.minilinks, miniName, result?.data?.q0 || []);
const mlResult = deep.useMinilinksSubscription({ id: { _in: result?.data?.q0?.map(l => l.id) } });
return {
...result,
data: result?.data?.q0,
data: mlResult,
};
}
175 changes: 152 additions & 23 deletions imports/deepcase-package.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,155 @@
import { Packager, Package } from './packager';

export const deepcaseSymbolsPckg: Package = {
package: {
name: '@deep-foundation/deepcase',
version: '0.0.0',
uri: 'deep-foundation/deepcase',
type: 'git',
},
dependencies: {
1: {
name: '@deep-foundation/core',
version: '0.0.0',
},
},
data: [
{ id: 'Type', package: { dependencyId: 1, containValue: 'Type' } },
{ id: 'Symbol', package: { dependencyId: 1, containValue: 'Symbol' } },
{ id: 'Query', package: { dependencyId: 1, containValue: 'Query' } },
{ id: 'Any', package: { dependencyId: 1, containValue: 'Any' } },

{ id: 'Traveler', type: 'Type', from: 'Any', to: 'Query' },
{ id: 'travelerSymbol', type: 'Symbol', from: 'package', to: 'Traveler', value: { value: '🧳' } },
],
errors: [],
};
"package": { "name": "@deep-foundation/deepcase", "version": "0.0.0" },
"data": [
{ "package": { "dependencyId": 0, "containValue": "TSX" }, "id": 1 },
{ "package": { "dependencyId": 1, "containValue": "Handler" }, "id": 2 },
{ "package": { "dependencyId": 1, "containValue": "clientSupportsJs" }, "id": 3 },
{ "package": { "dependencyId": 1, "containValue": "Query" }, "id": 4 },
{ "package": { "dependencyId": 1, "containValue": "HandleClient" }, "id": 5 },
{ "package": { "dependencyId": 1, "containValue": "Contain" }, "id": 6 },
{ "package": { "dependencyId": 1, "containValue": "Type" }, "id": 7 },
{ "package": { "dependencyId": 1, "containValue": "Any" }, "id": 8 },
{ "package": { "dependencyId": 1, "containValue": "Query" }, "id": 9 },
{ "package": { "dependencyId": 1, "containValue": "Symbol" }, "id": 10 },
{ "id": "queryClientHandler", "type": 1, "value": { "value": `({ deep, require }) => {
const React = require('react');
const { useState } = React;
const json5 = require('json5');
const { useContainer } = require('@deep-foundation/deepcase');
// Only objects editor.
return ({ fillSize, style, link }) => {
const currentValue = deep.stringify(link?.value?.value) || '';
const [value, setValue] = useState(currentValue);
const isSaved = value == currentValue;
const [container] = useContainer();
const { data } = deep.useDeepSubscription({
type_id: { _in: [
deep.idSync('@deep-foundation/core', 'Active'),
deep.idSync('@deep-foundation/core', 'Contain'),
] },
to_id: { _eq: link.id },
});
const contain = data?.find(l => l.type_id === deep.idSync('@deep-foundation/core', 'Contain'))
const active = data?.find(l => l.type_id === deep.idSync('@deep-foundation/core', 'Active'))
return <div
style={{
width: 300,
height: 200,
...style,
position: 'relative',
}}
>
<textarea
style={{
width: '100%',
height: '100%',
}}
onChange={(e) => {
setValue(e.target.value);
}}
value={value}
/>
<button
disabled={isSaved}
style={{
position: 'absolute',
top: 0, right: 0,
opacity: isSaved ? 0.2 : 1
}}
onClick={() => {
try {
const _value = json5.parse(value);
if (!link.value) deep.insert({
link_id: link.id, value: _value,
}, { table: 'objects' });
deep.update({ link_id: link.id }, { value: _value }, { table: 'objects' });
} catch(error) {}
}}
>
save
</button>
{!!contain && <button
style={{
position: 'absolute',
bottom: 0, right: 0,
}}
onClick={async () => {
if (active) {
await deep.delete({
_or: [{
id: { _eq: active.id },
}, {
type_id: deep.idSync('@deep-foundation/core', 'Contain'),
from_id: link.id,
to_id: active.id,
}],
});
} else {
await deep.insert({
type_id: deep.idSync('@deep-foundation/core', 'Active'),
from_id: contain.from_id,
to_id: contain.to_id,
in: { data: {
type_id: deep.idSync('@deep-foundation/core', 'Contain'),
from_id: link.id,
} },
});
}
}}
>
{active ? 'deactive' : 'active'}
</button>}
</div>;
}
}` } },
{ "id": "containClientHandlerHandler", "type": 2, "from": 3, "to": 4 },
{ "id": "containClientHandlerHandleClient", "type": 5, "from": 6, "to": "containClientHandlerHandler" },
{ "id": "Traveler", "type": 7, "from": 8, "to": 9 },
{ "id": "travelerSymbol", "type": 10, "to": "Traveler", "from": "Traveler", "value": { "value": "🧳" } },
{ "id": "queryClientHandlerHandler", "type": 2, "from": 3, "to": 4 },
{ "id": "queryClientHandlerHandleClient", "type": 5, "from": 9, "to": "queryClientHandlerHandler" },
{ "id": "containClientHandler", "type": 1, "value": { "value": `({ deep, require }) => {
const React = require('react');
const { useState } = React;
const json5 = require('json5');
const { Input } = require('@chakra-ui/react');
const { useHotkeys } = require('react-hotkeys-hook');
const { useDebounceCallback } = require('@react-hook/debounce');
const { useContainer } = require('@deep-foundation/deepcase');
// Only string editor.
return ({ fillSize, style, link, onClose }) => {
const currentValue = deep.stringify(link?.value?.value) || '';
const [value, setValue] = useState(currentValue);
const ref = useHotkeys('enter', async e => {
if (!link.value) await deep.insert({
link_id: link.id, value: value,
}, { table: 'strings' });
deep.update({ link_id: link.id }, { value: value }, { table: 'strings' });
onClose && onClose();
}, { enableOnTags: [\"INPUT\"] });
return <div
style={{
width: 300,
...style,
position: 'relative',
}}
>
<Input
ref={ref}
autoFocus
type=\"text\"
style={{
width: '100%',
bg: 'primary'
}}
onChange={(e) => {
setValue(e.target.value);
}}
value={value}
/>
</div>;
}
}` } }
], "errors": [], "dependencies": [{ "name": "@deep-foundation/tsx" }, { "name": "@deep-foundation/core" }] };
Loading

0 comments on commit c63dc8e

Please sign in to comment.