diff --git a/src/lib/client/SuperDebug.svelte b/src/lib/client/SuperDebug.svelte index a463205d..dfa1e9df 100644 --- a/src/lib/client/SuperDebug.svelte +++ b/src/lib/client/SuperDebug.svelte @@ -1,16 +1,120 @@ - {#if display} -
+
{#if promise}{#await promiseSyntaxHighlight(data)}
Loading data
{:then result}{@html result}{/await}{:else}{@html syntaxHighlight( - data - )}{/if}
{#if assertPromise($debugData, raw, promise)}{#await $debugData}
Loading data...
{:then result}{@html syntaxHighlight( + assertStore(result, raw) ? get(result) : result + )}{:catch error}Rejected: {@html syntaxHighlight( + error + )}{/await}{:else}{@html syntaxHighlight($debugData)}{/if}
{/if} + + diff --git a/src/routes/super-debug/+page.server.ts b/src/routes/super-debug/+page.server.ts index d7319770..446b4791 100644 --- a/src/routes/super-debug/+page.server.ts +++ b/src/routes/super-debug/+page.server.ts @@ -9,10 +9,23 @@ const schema = z.object({ phone_number: z.string().min(1, 'Phone number is required.') }); +const bigSchema = z.object({ + full_name: z.string().min(1, 'Full Name is required.'), + email: z.string().min(1, 'Email is required.').email('Email is invalid.'), + age: z.number().min(1, 'Age is required.').max(100, 'Age is invalid.'), + optional: z.string().optional(), + nullable: z.string().nullable(), + today: z.date().min(new Date(2021, 0, 1), 'Date is invalid.').default(() => new Date()).optional(), +}); + export const load = (async ({ request }) => { const form = await superValidate(request, schema); + const bigForm = await superValidate(request, bigSchema); - return { form }; + return { + form, + bigForm + }; }) satisfies PageServerLoad; export const actions = { diff --git a/src/routes/super-debug/+page.svelte b/src/routes/super-debug/+page.svelte index e600bcda..fc5ea35e 100644 --- a/src/routes/super-debug/+page.svelte +++ b/src/routes/super-debug/+page.svelte @@ -1,108 +1,223 @@
-
-

Super Debug with label

-

Label is useful when using multiple instance of SuperDebug.

- -
-
-

Super Debug without status

- -
-
-

Super Debug without label

-

This is SuperDebug's classic layout. Make sure we don't have weird spaces when there is no label.

- -
-
-

Super Debug without label and status

- -
-
-

Super Debug with label and undefined data

-

Do not hide output from syntaxHighlight even when the result is undefined. In JavaScript it is a crucial piece of information.

- -
-
-

Super Debug without label and undefined data

-

There are cases when the data is not readily available on page load. Make sure SuperDebug layout does not break on itself.

- -
-
-

Super Debug with empty object

- -
-
-

Super Debug promise support

-

Fancy way of loading things for fancy people. Try reloading the page to see it in action. Right now when waiting for promise a message that says "Loading data" appears. Having a named slot for customization is nice but it is trivial.

-
{@html `let promiseNeverCameTrue = new Promise((resolve, reject) => {
-    setTimeout(() => resolve({}), 5000)
-})`}
-{@html "<SuperDebug promise={true} data={promiseNeverCameTrue} />"}
- -
{@html `let promiseProduct = async () => {
+  
+

SuperDebug demonstrations

+

+ Note: looking for the capabilities of SuperDebug? + Check + + All data cases examples. +

+ Change name: +
+
+

SuperDebug without label

+

+ This is SuperDebug's classic layout. Make sure we don't have weird + spaces when there is no label. +

+ +
+
+

SuperDebug with label

+

Label is useful when using multiple instance of SuperDebug.

+ +
+
+

SuperDebug without status

+ +
+
+

SuperDebug without label and status

+ +
+
+

SuperDebug with label and undefined data

+

+ Do not hide output when the result is undefined. In JavaScript it is a + crucial piece of information. +

+ +
+
+

SuperDebug without label and undefined data

+

+ There are cases when the data is not readily available on page load. + Make sure SuperDebug layout does not break on itself. +

+ +
+
+

SuperDebug with empty object

+ +
+
+

SuperDebug promise support

+

+ To see this in action, slightly scroll above near Dummyjson product and + hit refresh. +

+
{@html `let promiseProduct = async () => {
     const response = await fetch('https://dummyjson.com/products/1')
     const body = await response.json()
     return body
 }`}
-{@html `<SuperDebug label="Dummyjson product" promise={true} data={promiseProduct()} />`}
- -
-
-

Super Debug using promise on non-promise related data

-

To see this in action, slightly scroll above near Dummyjson product and hit refresh.

-
    -
  • ChadDev: No one can stop me from enabling promise because I can't read.
  • -
  • SuperForm: Hey, that's illegal!
  • -
  • ChadDev: It works!
  • -
- -
-
-

Super Debug displaying $page data

-

Svelte's $page data in all its glory.

- -
+{@html `<SuperDebug label="Dummyjson product" data={promiseProduct()} />`}
+ +
{@html `let promiseNeverCameTrue = new Promise((resolve, reject) => {
+  setTimeout(() => resolve({}), 5000)
+})`}
+{@html '<SuperDebug data={promiseNeverCameTrue} />'}
+

SuperDebug rejected promises

+

To see this in action, hit refresh. The promise is rejected with

+
new Error("Broken promise")
+ + +
+
+

SuperDebug displaying $page data

+

Svelte's $page data in all its glory.

+ +
+ +
+

SuperDebug loves stores

+

Why not to pass a store directly.

+ + +

+ Or maybe you want to see the store literal value instead of the store + itself. SuperDebug has you covered. +

+

+ For this use the raw and functions props. +

+ +
+ +
+

SuperDebug loves stores x2

+

Does superform handle stores of promises?, Yep its cool.

+ +
+ +
+

SuperDebug custom styling 😎

+

Bugs are easier to solve if they look familiar.

+ +

+ Note: styling the component produces the side-effect + described at the + Svelte docs. +

+
\ No newline at end of file + :global(.space-y-4 > * + *) { + margin-top: 1rem; + } + diff --git a/src/routes/super-debug/extensive-usage-cases/+page.server.ts b/src/routes/super-debug/extensive-usage-cases/+page.server.ts new file mode 100644 index 00000000..1e5fed23 --- /dev/null +++ b/src/routes/super-debug/extensive-usage-cases/+page.server.ts @@ -0,0 +1,60 @@ +import { z } from 'zod'; +import { superValidate } from '$lib/server'; +import { fail } from '@sveltejs/kit'; +import type { Actions, PageServerLoad } from './$types'; + + +const simpleSchema = z.object({ + full_name: z.string().min(1, 'Full Name is required.'), + email: z.string().min(1, 'Email is required.').email('Email is invalid.'), + age: z.number().min(1, 'Age is required.').max(100, 'Age is invalid.'), +}); + +const complexSchema = simpleSchema.extend({ + address: z.object({ + street: z.string().min(1, 'Street is required.'), + city: z.string().min(1, 'City is required.'), + state: z.string().min(1, 'State is required.'), + zip: z.string().min(1, 'Zip is required.'), + }), + phones: z.array( + z.string().min(1, 'Number is required.') + ), + children: z.array(z.object({ + name: z.string().min(1, 'Name is required.'), + age: z.number().min(1, 'Age is required.').max(100, 'Age is invalid.'), + })), + today: z.date().min(new Date(2021, 0, 1), 'Date is invalid.').default(() => new Date()).optional(), + optional: z.string().optional(), + nullable: z.string().nullable(), +}) + + +export const load = (async ({ request }) => { + const [simpleForm, complexForm] = await Promise.all([ + superValidate(request, simpleSchema), + superValidate(request, complexSchema), + ]); + + return { + simpleForm, + complexForm, + user: { + full_name: 'John Doe', + email: 'JhonBigWings@gmail.com', + role: 'USER' + } + }; +}) satisfies PageServerLoad; + + +export const actions = { + simple: async ({ request }) => { + const form = await superValidate(request, simpleSchema); + if (!form.valid) { + return fail(400, { form }) + }; + + return { form }; + } +} satisfies Actions; diff --git a/src/routes/super-debug/extensive-usage-cases/+page.svelte b/src/routes/super-debug/extensive-usage-cases/+page.svelte new file mode 100644 index 00000000..6c4855e9 --- /dev/null +++ b/src/routes/super-debug/extensive-usage-cases/+page.svelte @@ -0,0 +1,710 @@ + + +
+
+

Super Debug extensive usage cases examples

+
+ +
+

Super Debug configuration

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + {#if enableTests} +
+
+

Primitive values

+ + {#if testType.primitive} + + {/if} +
+ {#if testType.primitive} + {#key config.functions} +
    + {#each primitiveValues as value} +
  • + +
  • + {/each} + {#if primitiveRotation.enabled} +
  • + +
  • + {/if} +
+ {/key} + {/if} +
+ +
+
+

Non primitive values

+ + {#if testType.nonPrimitive} + + {/if} +
+ {#if testType.nonPrimitive} + {#key config.functions} +
    + {#each nonPrimitiveValues as value} +
  • + +
  • + {/each} + {#if nonPrimitiveRotation.enabled} +
  • + +
  • + {/if} +
+ {/key} + {/if} +
+ +
+
+

Complex values

+ +
+ {#if testType.complex} + {#key config.functions} +
    + {#each complexValues as value} +
  • + +
  • + {/each} + +
+ {/key} + {/if} +
+ +
+
+

Store values

+ + {#if testType.store} + + {/if} +
+ {#if testType.store} + {#key config.functions} +
    + {#each storeValues as value} +
  • + +
  • + {/each} +
  • + + +
  • +
  • + + +
  • +
  • + + {#if showPageStore} + + {/if} +
  • + {#if storeRotation.enabled} +
  • + +
  • + {/if} +
+ {/key} + {/if} +
+ +
+
+

Promise values

+ +
+ {#if testType.promise} + {#key config.functions} +
    + {#each [{ label: 'promise of store', data: createPromiseOfStore() }, { label: 'promise that resolves', data: new Promise( (resolve, reject) => { + setTimeout(() => { + resolve('resolved'); + }, 3000); + } ) }, { label: 'promise that rejects', data: new Promise( (resolve, reject) => { + setTimeout(() => { + reject('rejected'); + }, 3000); + } ) }, { label: 'fetch', data: fetch('randomthatewewenevercametrueurl.io/beweweaks').then( (res) => res.text() ) }] as value} +
  • + +
  • + {/each} +
  • + +
  • +
+ {/key} + {/if} +
+ +
+
+

Edge case values

+ + + {#if testType.edgecase} + + {/if} +
+ {#if testType.edgecase} + {#key config.functions} +
    + {#each edgecaseValues as value} +
  • + +
  • + {/each} +
  • + { + setTimeout(() => { + resolve('a'.repeat(1000)); + }, 5000); + })} + {...config} + /> +
  • +
  • + { + setTimeout(() => { + resolve(void 0); + }, 5000); + })} + {...config} + /> +
  • + {#if edgecaseRotation.enabled} +
  • + +
  • + {/if} +
+ {/key} + {/if} +
+ {/if} +
+ +