feat: update console package and implement changes

This commit is contained in:
Arman committed 2022-09-13 13:29:45 +02:00
1 parent e041637285
commit 8d52891aa2
36 files changed
+150 -140

No files matched your search

+7 -7
View File
@@ -8,7 +8,7 @@
"name": "@appwrite/console",
"version": "0.0.1",
"dependencies": {
"@aw-labs/appwrite-console": "^1.0.0-0",
"@aw-labs/appwrite-console": "^5.0.1",
"@aw-labs/icons": "0.0.0-54",
"@aw-labs/ui": "0.0.0-54",
"echarts": "^5.3.3",
@@ -68,9 +68,9 @@
}
},
"node_modules/@aw-labs/appwrite-console": {
"version": "1.0.0-0",
"resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-1.0.0-0.tgz",
"integrity": "sha512-qvqCRBhG/LwmIv0Om3c0IWuLfvOCjVdbKel3cAcGadwbmz7vGDZkodgObqUPwi33T+8vnbzxBkhUOLncMF+DZQ==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-5.0.1.tgz",
"integrity": "sha512-sx9+riLjMYAwaUEqy1NkrgYRPwaD8UduIIpK8ZjtqYJOaFFhA8ubifysQywahvnjUf7B++S51tKgPgACAViUCA==",
"dependencies": {
"cross-fetch": "3.1.5",
"isomorphic-form-data": "2.0.0"
@@ -7659,9 +7659,9 @@
}
},
"@aw-labs/appwrite-console": {
"version": "1.0.0-0",
"resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-1.0.0-0.tgz",
"integrity": "sha512-qvqCRBhG/LwmIv0Om3c0IWuLfvOCjVdbKel3cAcGadwbmz7vGDZkodgObqUPwi33T+8vnbzxBkhUOLncMF+DZQ==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@aw-labs/appwrite-console/-/appwrite-console-5.0.1.tgz",
"integrity": "sha512-sx9+riLjMYAwaUEqy1NkrgYRPwaD8UduIIpK8ZjtqYJOaFFhA8ubifysQywahvnjUf7B++S51tKgPgACAViUCA==",
"requires": {
"cross-fetch": "3.1.5",
"isomorphic-form-data": "2.0.0"
+1 -1
View File
@@ -18,7 +18,7 @@
"e2e": "playwright test tests/e2e"
},
"dependencies": {
"@aw-labs/appwrite-console": "^1.0.0-0",
"@aw-labs/appwrite-console": "^5.0.1",
"@aw-labs/icons": "0.0.0-54",
"@aw-labs/ui": "0.0.0-54",
"echarts": "^5.3.3",
+1 -1
View File
@@ -4,7 +4,7 @@
export let label: string;
export let showLabel = true;
export let id: string;
export let value: string;
export let value: string | number | boolean;
export let placeholder = '';
export let required = false;
export let disabled = false;
+2 -2
View File
@@ -1,9 +1,9 @@
export function intersection(arr1: any[], arr2: any[]) {
export function intersection(arr1: unknown[], arr2: unknown[]) {
const set = new Set(arr2);
const intersection = new Set(arr1.filter((elem) => set.has(elem)));
return Array.from(intersection);
}
export function difference(arr1: any[], arr2: any[]) {
export function difference(arr1: unknown[], arr2: unknown[]) {
const set = new Set(arr2);
const intersection = new Set(arr1.filter((elem) => !set.has(elem)));
return Array.from(intersection);
+2 -3
View File
@@ -20,7 +20,6 @@ const clientProject = new Client();
clientProject.setEndpoint(endpoint).setMode('admin');
const setProject = (projectId: string): Client => clientProject.setProject(projectId);
const setDatabase = (databaseId: string): void => sdkForProject.databases.setDatabaseId(databaseId);
const sdkForConsole = {
client: clientConsole,
@@ -38,7 +37,7 @@ const sdkForProject = {
client: clientProject,
account: new Account(clientProject),
avatars: new Avatars(clientProject),
databases: new Databases(clientProject, null),
databases: new Databases(clientProject),
functions: new Functions(clientProject),
health: new Health(clientProject),
locale: new Locale(clientProject),
@@ -48,4 +47,4 @@ const sdkForProject = {
users: new Users(clientProject)
};
export { sdkForConsole, sdkForProject, setProject, setDatabase };
export { sdkForConsole, sdkForProject, setProject };
@@ -3,7 +3,7 @@
import { Pill } from '$lib/elements';
import { Button, InputText, Form, FormList } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdkForProject, setDatabase } from '$lib/stores/sdk';
import { sdkForProject } from '$lib/stores/sdk';
import { createEventDispatcher } from 'svelte';
export let showCreate = false;
@@ -16,8 +16,7 @@
const create = async () => {
try {
setDatabase(id ? id : 'unique()');
const database = await sdkForProject.databases.create(name);
const database = await sdkForProject.databases.create(id ? id : 'unique()', name);
name = id = null;
showCreate = false;
dispatch('created', database);
@@ -3,7 +3,6 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { updateLayout } from '$lib/stores/layout';
import { setDatabase } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { database } from './store';
@@ -16,8 +15,7 @@
async function handle(event = null) {
if ($database?.$id !== databaseId) {
setDatabase($page.params.database);
await database.load();
await database.load(databaseId);
}
updateLayout({
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { Modal, InnerModal } from '$lib/components';
import { Pill } from '$lib/elements';
import { Button, InputText, Form, FormList } from '$lib/elements/forms';
@@ -8,6 +10,7 @@
export let showCreate = false;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let name = '';
@@ -17,6 +20,7 @@
const create = async () => {
try {
const collection = await sdkForProject.databases.createCollection(
databaseId,
id ? id : 'unique()',
name,
'collection',
@@ -7,12 +7,13 @@
import { addNotification } from '$lib/stores/notifications';
import { sdkForProject } from '$lib/stores/sdk';
import { database } from './store';
const databaseId = $page.params.database;
export let showDelete = false;
const handleDelete = async () => {
try {
await sdkForProject.databases.delete();
await sdkForProject.databases.delete(databaseId);
showDelete = false;
await goto(`${base}/console/project-${$page.params.project}/databases`);
} catch (error) {
@@ -16,10 +16,10 @@
async function handle(event = null) {
if ($collection?.$id !== collectionId) {
await collection.load(collectionId);
await collection.load(databaseId, collectionId);
}
if ($collection) {
await documentList.load($collection.$id, [], 12, 0);
await documentList.load(databaseId, $collection.$id, [], 12, 0);
}
updateLayout({
navigate: event,
@@ -12,6 +12,9 @@
export let showCreate = false;
const databaseId = $page.params.database;
const collectionId = $page.params.collection;
let newDocument = {};
let read: string[];
let write: string[];
@@ -22,7 +25,7 @@
let attributes = [];
onMount(async () => {
await attributeList.load($page.params.collection);
await attributeList.load(databaseId, collectionId);
initializeDocument();
});
@@ -43,7 +46,8 @@
} else {
try {
await sdkForProject.databases.createDocument(
$page.params.collection,
databaseId,
collectionId,
id ?? 'unique()',
newDocument,
read,
@@ -63,7 +67,7 @@
}
};
$: attributeList.load($page.params.collection);
$: attributeList.load(databaseId, collectionId);
$: if (!showCreate) {
initializeDocument();
@@ -6,10 +6,13 @@
import { onMount } from 'svelte';
import { sdkForProject } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
import { page } from '$app/stores';
export let showCreateIndex = false;
export let externalAttribute: Attributes = null;
const databaseId = $page.params.database;
let key: string = null;
let types = [
{ value: 'key', label: 'Key' },
@@ -45,6 +48,7 @@
}
try {
await sdkForProject.databases.createIndex(
databaseId,
$collection.$id,
key,
selectedType,
@@ -10,9 +10,11 @@
export let showDelete = false;
const databaseId = $page.params.database;
const handleDelete = async () => {
try {
await sdkForProject.databases.deleteCollection($collection.$id);
await sdkForProject.databases.deleteCollection(databaseId, $collection.$id);
showDelete = false;
await goto(
`${base}/console/project-${$page.params.project}/databases/database/${$page.params.database}`
@@ -11,14 +11,19 @@
export let showDelete = false;
export let selectedAttribute: Attributes;
const databaseId = $page.params.database;
const handleDelete = async () => {
try {
await sdkForProject.databases.deleteAttribute($collection.$id, selectedAttribute.key);
await sdkForProject.databases.deleteAttribute(
databaseId,
$collection.$id,
selectedAttribute.key
);
collection.removeAttribute(selectedAttribute);
showDelete = false;
await goto(
`${base}/console/project-${$page.params.project}/databases/database/${$page.params.database}/collection/${$page.params.collection}/attributes`
`${base}/console/project-${$page.params.project}/databases/database/${databaseId}/collection/${$page.params.collection}/attributes`
);
} catch (error) {
addNotification({
@@ -6,15 +6,21 @@
import { sdkForProject } from '$lib/stores/sdk';
import type { Models } from '@aw-labs/appwrite-console';
import { createEventDispatcher } from 'svelte';
import { page } from '$app/stores';
export let showDelete = false;
export let selectedIndex: Models.Index;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
const handleDelete = async () => {
try {
await sdkForProject.databases.deleteIndex($collection.$id, selectedIndex.key);
await sdkForProject.databases.deleteIndex(
databaseId,
$collection.$id,
selectedIndex.key
);
showDelete = false;
dispatch('deleted');
} catch (error) {
@@ -5,12 +5,15 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let submitted = false;
export let key: string;
export let overview = false;
export let selectedAttribute: Models.AttributeBoolean;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let xdefault: boolean,
@@ -21,6 +24,7 @@
submitted = false;
try {
const attribute = await sdkForProject.databases.createBooleanAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -5,21 +5,25 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeEmail;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let xdefault: string,
required = false,
array = false;
const dispatch = createEventDispatcher();
const submit = async () => {
submitted = false;
try {
const attribute = await sdkForProject.databases.createEmailAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -5,21 +5,26 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeEnum;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let xdefault = '',
elements: string[],
required = false,
array = false;
const dispatch = createEventDispatcher();
const submit = async () => {
submitted = false;
try {
const attribute = await sdkForProject.databases.createEnumAttribute(
databaseId,
$collection.$id,
key,
elements,
@@ -5,13 +5,16 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
const dispatch = createEventDispatcher();
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeFloat;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let min: number,
max: number,
xdefault: number,
@@ -22,6 +25,7 @@
submitted = false;
try {
const attribute = await sdkForProject.databases.createFloatAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -5,13 +5,16 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
const dispatch = createEventDispatcher();
import { page } from '$app/stores';
export let key: string = null;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeInteger;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let min: number,
max: number,
xdefault: number,
@@ -22,6 +25,7 @@
submitted = false;
try {
const attribute = await sdkForProject.databases.createIntegerAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -5,20 +5,25 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeIp;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let xdefault: string,
required = false,
array = false;
const dispatch = createEventDispatcher();
const submit = async () => {
submitted = false;
try {
const attribute = await sdkForProject.databases.createIpAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -5,11 +5,15 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeString;
const databaseId = $page.params.database;
let xdefault: string,
size = 255,
required = false,
@@ -20,6 +24,7 @@
submitted = false;
try {
const attribute = await sdkForProject.databases.createStringAttribute(
databaseId,
$collection.$id,
key,
size,
@@ -5,20 +5,25 @@
import { createEventDispatcher } from 'svelte';
import { collection } from '../store';
import type { Models } from '@aw-labs/appwrite-console';
import { page } from '$app/stores';
export let key: string;
export let submitted = false;
export let overview = false;
export let selectedAttribute: Models.AttributeUrl;
const databaseId = $page.params.database;
const dispatch = createEventDispatcher();
let xdefault: string,
required = false,
array = false;
const dispatch = createEventDispatcher();
const submit = async () => {
submitted = false;
try {
const attribute = await sdkForProject.databases.createUrlAttribute(
databaseId,
$collection.$id,
key,
required,
@@ -1,78 +0,0 @@
<script lang="ts">
import { page } from '$app/stores';
import { Back, Card } from '$lib/components';
import { Button, Form } from '$lib/elements/forms';
import { sdkForProject } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { collection } from '../store';
import { doc } from './[document]/store';
import { addNotification } from '$lib/stores/notifications';
import Document from './[document]/_document.svelte';
import { goto } from '$app/navigation';
import InputCustomId from '$lib/elements/forms/inputCustomId.svelte';
import { Container, Cover } from '$lib/layout';
import { base } from '$app/paths';
$: projectId = $page.params.project;
onMount(() => {
doc.set({
$collection: $page.params.collection,
$id: null,
$createdAt: null,
$updatedAt: null,
$read: [],
$write: []
});
});
const createDocument = async () => {
try {
const created = await sdkForProject.databases.createDocument(
$collection.$id,
$doc.$id,
{
...$doc,
$id: undefined
},
$doc.$read,
$doc.$write
);
addNotification({
message: 'Document was created!',
type: 'success'
});
await goto(
`${base}/console/project-${projectId}/database/collection/${created.$collection}/document/${created.$id}`
);
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
}
};
</script>
<svelte:head>
<title>Appwrite - Document</title>
</svelte:head>
{#if $doc && $collection}
<Cover>
<Back href={`${base}/console/project-${projectId}/database/collection/${$collection.$id}`}>
Collection - {$collection.name}
</Back>
<h1>Create Document</h1>
</Cover>
<Container>
<Card>
<Form on:submit={createDocument}>
<InputCustomId id="id" label="Document ID" bind:value={$doc.$id} />
<Document />
<Button submit>Create</Button>
</Form>
</Card>
</Container>
{:else}
<div aria-busy="true" />
{/if}
@@ -16,7 +16,7 @@
async function handle(event = null) {
if ($doc?.$id !== documentId) {
await doc.load(collectionId, documentId);
await doc.load(databaseId, collectionId, documentId);
}
updateLayout({
@@ -10,9 +10,12 @@
export let showDelete = false;
const databaseId = $page.params.database;
const handleDelete = async () => {
try {
await sdkForProject.databases.deleteDocument(
databaseId,
$page.params.collection,
$page.params.document
);
@@ -11,9 +11,10 @@
let currentDoc: string;
let disableUpdate = true;
const databaseId = $page.params.database;
onMount(async () => {
await doc.load($collection.$id, $page.params.document);
await doc.load(databaseId, $collection.$id, $page.params.document);
currentDoc = JSON.stringify($doc);
});
@@ -28,6 +29,7 @@
const updateData = async () => {
try {
await sdkForProject.databases.updateDocument(
databaseId,
$collection.$id,
$page.params.document,
$doc,
@@ -9,15 +9,18 @@
import Document from './_document.svelte';
import Delete from './_delete.svelte';
import { difference } from '$lib/helpers/arrayComparison';
import { page } from '$app/stores';
let showDelete = false;
let read = $doc?.$read;
let write = $doc?.$write;
let arePermsDisabled = true;
const databaseId = $page.params.database;
async function updatePermissions() {
try {
await sdkForProject.databases.updateDocument(
databaseId,
$doc.collectionId,
$doc.$id,
$doc.data,
@@ -8,8 +8,8 @@ function createDocumentStore() {
return {
subscribe,
set,
load: async (collectionId: string, documentId: string) =>
set(await sdkForProject.databases.getDocument(collectionId, documentId)),
load: async (databaseId: string, collectionId: string, documentId: string) =>
set(await sdkForProject.databases.getDocument(databaseId, collectionId, documentId)),
addAttribute: (attribute: string) =>
update((n) => {
n[attribute].push(null);
@@ -25,7 +25,7 @@
const databaseId = $page.params.database;
onMount(async () => {
await documentList.load($collection.$id, [], limit, offset);
await documentList.load(databaseId, $collection.$id, [], limit, offset);
});
$: columns = [
@@ -30,9 +30,10 @@
const limit = 5;
const collectionId = $page.params.collection;
const databaseId = $page.params.database;
const handleDelete = async () => {
await indexList.load(collectionId);
await indexList.load(databaseId, collectionId);
};
// $: indexes.load(search);
@@ -53,7 +54,7 @@
// });
onMount(async () => {
await indexList.load(collectionId);
await indexList.load(databaseId, collectionId);
});
</script>
@@ -11,6 +11,8 @@
import { page } from '$app/stores';
import { difference } from '$lib/helpers/arrayComparison';
const databaseId = $page.params.database;
let showDelete = false;
let showError: false | 'name' | 'size' = false,
errorMessage = 'Something went wrong',
@@ -23,7 +25,7 @@
arePermsDisabled = true;
onMount(async () => {
await collection.load($page.params.collection);
await collection.load(databaseId, $page.params.collection);
enabled ??= $collection.enabled;
collectionName ??= $collection.name;
collectionName ??= $collection.name;
@@ -54,6 +56,7 @@
async function togglecollection() {
try {
await sdkForProject.databases.updateCollection(
databaseId,
$collection.$id,
$collection.name,
$collection.permission,
@@ -76,6 +79,7 @@
async function updateName() {
try {
await sdkForProject.databases.updateCollection(
databaseId,
$collection.$id,
$collection.name,
$collection.permission
@@ -93,6 +97,7 @@
async function updatePermissions() {
try {
await sdkForProject.databases.updateCollection(
databaseId,
$collection.$id,
$collection.name,
collectionPermissions,
@@ -25,9 +25,12 @@ function createCollection() {
return {
subscribe,
set,
load: async (collectionId: string) => {
load: async (databaseId: string, collectionId: string) => {
set(
(await sdkForProject.databases.getCollection(collectionId)) as unknown as Collection
(await sdkForProject.databases.getCollection(
databaseId,
collectionId
)) as unknown as Collection
);
},
addAttribute: (attribute: Attributes) =>
@@ -59,8 +62,15 @@ function createDocumentListStore() {
return {
subscribe,
set,
load: async (collectionId: string, queries: [], limit: number, offset: number) => {
load: async (
databaseId: string,
collectionId: string,
queries: [],
limit: number,
offset: number
) => {
const response = await sdkForProject.databases.listDocuments(
databaseId,
collectionId,
queries,
limit,
@@ -77,8 +87,8 @@ function createIndexListStore() {
return {
subscribe,
set,
load: async (collectionId: string) => {
const response = await sdkForProject.databases.listIndexes(collectionId);
load: async (databaseId: string, collectionId: string) => {
const response = await sdkForProject.databases.listIndexes(databaseId, collectionId);
set(response);
}
};
@@ -90,8 +100,8 @@ function createAttributeListStore() {
return {
subscribe,
set,
load: async (collectionId: string) => {
const response = await sdkForProject.databases.listAttributes(collectionId);
load: async (databaseId: string, collectionId: string) => {
const response = await sdkForProject.databases.listAttributes(databaseId, collectionId);
set(response);
}
};
@@ -24,7 +24,7 @@
);
};
$: collections.load(search, limit, offset ?? 0);
$: collections.load(databaseId, search, limit, offset ?? 0);
$: if (search) offset = 0;
</script>
@@ -46,7 +46,7 @@
<GridItem1
href={`${base}/console/project-${project}/databases/database/${databaseId}/collection/${collection.$id}`}>
<svelte:fragment slot="eyebrow">
{#await collections.total(collection.$id)}
{#await collections.total(databaseId, collection.$id)}
N Documents
{:then n}
{n[collection.$id] ? n[collection.$id] : 'NO'} Documents
@@ -9,6 +9,7 @@
import Delete from './_delete.svelte';
import { onMount } from 'svelte';
const databaseId = $page.params.database;
const getAvatar = (name: string) => sdkForProject.avatars.getInitials(name, 48, 48).toString();
let showDelete = false;
@@ -18,7 +19,7 @@
let databaseName: string = null;
onMount(async () => {
await database.load();
await database.load(databaseId);
databaseName ??= $database.name;
});
@@ -10,14 +10,19 @@ function createCollectionStore() {
return {
subscribe,
set,
load: async (search: string, limit: number, offset: number) => {
const response = await sdkForProject.databases.listCollections(search, limit, offset);
load: async (databaseId: string, search: string, limit: number, offset: number) => {
const response = await sdkForProject.databases.listCollections(
databaseId,
search,
limit,
offset
);
set(response);
},
total: async (id: string) => {
total: async (databaseId: string, id: string) => {
let total = {};
total = browser ? JSON.parse(sessionStorage.getItem('collectionTotal')) ?? {} : {};
const response = await sdkForProject.databases.listDocuments(id);
const response = await sdkForProject.databases.listDocuments(databaseId, id);
total[id] = response.total;
sessionStorage?.setItem('collectionTotal', JSON.stringify(total));
return total;
@@ -31,8 +36,8 @@ function createDatabase() {
return {
subscribe,
set,
load: async () => {
set(await sdkForProject.databases.get());
load: async (databaseId: string) => {
set(await sdkForProject.databases.get(databaseId));
}
};
}