From 48e7869befff9b0d3853c7d4633aa970db3dea6a Mon Sep 17 00:00:00 2001 From: anasmohammed361 Date: Sun, 17 Dec 2023 13:24:35 +0530 Subject: [PATCH] cache feature and plugin support --- examples/complex/src/lib/rest/index.ts | 2 +- package/src/lib/components/SvelteKitRest.ts | 38 +- package/src/lib/components/interface/index.ts | 25 +- .../src/lib/components/interface/server.ts | 69 ++-- package/src/lib/components/options.ts | 27 ++ package/src/lib/components/types.d.ts | 21 +- plugins/README.md | 0 plugins/svelte-query-plugin/.gitignore | 11 + plugins/svelte-query-plugin/.npmrc | 1 + plugins/svelte-query-plugin/README.md | 58 +++ plugins/svelte-query-plugin/package.json | 43 +++ plugins/svelte-query-plugin/src/app.d.ts | 13 + plugins/svelte-query-plugin/src/app.html | 12 + plugins/svelte-query-plugin/src/lib/index.ts | 1 + .../src/routes/+page.svelte | 3 + .../svelte-query-plugin/static/favicon.png | Bin 0 -> 1571 bytes plugins/svelte-query-plugin/svelte.config.js | 18 + plugins/svelte-query-plugin/tsconfig.json | 15 + plugins/svelte-query-plugin/vite.config.ts | 6 + plugins/svelte-store-plugin/.gitignore | 11 + plugins/svelte-store-plugin/.npmrc | 1 + plugins/svelte-store-plugin/README.md | 58 +++ plugins/svelte-store-plugin/package.json | 43 +++ plugins/svelte-store-plugin/src/app.d.ts | 13 + plugins/svelte-store-plugin/src/app.html | 12 + .../src/lib/components/store.ts | 1 + plugins/svelte-store-plugin/src/lib/index.ts | 1 + .../src/routes/+page.svelte | 3 + .../svelte-store-plugin/static/favicon.png | Bin 0 -> 1571 bytes plugins/svelte-store-plugin/svelte.config.js | 18 + plugins/svelte-store-plugin/tsconfig.json | 15 + plugins/svelte-store-plugin/vite.config.ts | 6 + pnpm-lock.yaml | 357 ++++++++++++++++-- pnpm-workspace.yaml | 3 +- 34 files changed, 816 insertions(+), 89 deletions(-) create mode 100644 package/src/lib/components/options.ts create mode 100644 plugins/README.md create mode 100644 plugins/svelte-query-plugin/.gitignore create mode 100644 plugins/svelte-query-plugin/.npmrc create mode 100644 plugins/svelte-query-plugin/README.md create mode 100644 plugins/svelte-query-plugin/package.json create mode 100644 plugins/svelte-query-plugin/src/app.d.ts create mode 100644 plugins/svelte-query-plugin/src/app.html create mode 100644 plugins/svelte-query-plugin/src/lib/index.ts create mode 100644 plugins/svelte-query-plugin/src/routes/+page.svelte create mode 100644 plugins/svelte-query-plugin/static/favicon.png create mode 100644 plugins/svelte-query-plugin/svelte.config.js create mode 100644 plugins/svelte-query-plugin/tsconfig.json create mode 100644 plugins/svelte-query-plugin/vite.config.ts create mode 100644 plugins/svelte-store-plugin/.gitignore create mode 100644 plugins/svelte-store-plugin/.npmrc create mode 100644 plugins/svelte-store-plugin/README.md create mode 100644 plugins/svelte-store-plugin/package.json create mode 100644 plugins/svelte-store-plugin/src/app.d.ts create mode 100644 plugins/svelte-store-plugin/src/app.html create mode 100644 plugins/svelte-store-plugin/src/lib/components/store.ts create mode 100644 plugins/svelte-store-plugin/src/lib/index.ts create mode 100644 plugins/svelte-store-plugin/src/routes/+page.svelte create mode 100644 plugins/svelte-store-plugin/static/favicon.png create mode 100644 plugins/svelte-store-plugin/svelte.config.js create mode 100644 plugins/svelte-store-plugin/tsconfig.json create mode 100644 plugins/svelte-store-plugin/vite.config.ts diff --git a/examples/complex/src/lib/rest/index.ts b/examples/complex/src/lib/rest/index.ts index cda7d67..b61f1cf 100644 --- a/examples/complex/src/lib/rest/index.ts +++ b/examples/complex/src/lib/rest/index.ts @@ -3,4 +3,4 @@ import { router } from "./router"; export const { serverHook, client } = - createRESTInterface(router); + createRESTInterface(router); \ No newline at end of file diff --git a/package/src/lib/components/SvelteKitRest.ts b/package/src/lib/components/SvelteKitRest.ts index 66e4c7b..f4e9ee7 100644 --- a/package/src/lib/components/SvelteKitRest.ts +++ b/package/src/lib/components/SvelteKitRest.ts @@ -1,13 +1,6 @@ import type { z } from 'zod'; -import type { Route, RouteMethod, Params, TContext, CombineTypes } from './types.js'; -import type { RequestEvent } from '@sveltejs/kit'; -type Options = { - contentType: string; - headers: { - client: Record; - server: Record; - }; -}; +import type { Route, Params, TContext, CombineTypes,Options } from './types.js'; + class SvelteKitREST { public get; public post; @@ -37,52 +30,57 @@ class SvelteKitREST { return this.getRouter(inp); } - middleware(func: (inp: { context: TContext }) => U) { + middleware>(func: (inp: { context: TContext }) => U) { const middlewares = this.middlewares; return SvelteKitREST.getMiddlewareInstance,Awaited>>(middlewares, func); } private getRouter(schema?: z.ZodSchema) { return { - get: (cb: (inp: Params) => U): Route => { + get: (cb: (inp: Params) => U,options?:Partial): Route => { return { method: 'GET', cb, schema: schema, - middlewares:this.middlewares + middlewares:this.middlewares, + options }; }, - post: (cb: (inp: Params) => U): Route => { + post: (cb: (inp: Params) => U,options?:Partial): Route => { return { method: 'POST', cb, schema: schema, - middlewares:this.middlewares + middlewares:this.middlewares, + options }; }, - put: (cb: (inp: Params) => U): Route => { + put: (cb: (inp: Params) => U,options?:Partial): Route => { return { method: 'PUT', cb, schema: schema, - middlewares:this.middlewares + middlewares:this.middlewares, + options }; }, - patch: (cb: (inp: Params) => U): Route => { + patch: (cb: (inp: Params) => U,options?:Partial): Route => { return { method: 'PATCH', cb, schema: schema, - middlewares:this.middlewares + middlewares:this.middlewares, + options }; }, - delete: (cb: (inp: Params) => U): Route => { + delete: (cb: (inp: Params) => U,options?:Partial): Route => { return { method: 'DELETE', cb, schema: schema, - middlewares:this.middlewares + middlewares:this.middlewares, + options }; } }; diff --git a/package/src/lib/components/interface/index.ts b/package/src/lib/components/interface/index.ts index 524dba7..7302714 100644 --- a/package/src/lib/components/interface/index.ts +++ b/package/src/lib/components/interface/index.ts @@ -1,25 +1,18 @@ import type { RequestEvent } from '@sveltejs/kit'; -import type { Context, SingleOrMultipleRoutes } from '../types.js'; +import type { Context, RESTInterfaceOptions, SingleOrMultipleRoutes } from '../types.js'; import { createClient } from './client.js'; import { createServerHandle } from './server.js'; - -/** - * @param {Record} input - * @param {{ - * createContext?: Context; - * routePrefiex?: `/${string}` - * }} - * @returns {{client: any;serverHook: any;}} - */ -export function createRESTInterface(input: Record,options:{ createContext?:Context , - /** Default to /api */ - routePrefiex?: `/${string}`}={}) { +export function createRESTInterface( + input: Record, + options?: RESTInterfaceOptions +) { + options = options ? options : {}; if (!options.routePrefiex) { - options.routePrefiex = "/api" + options.routePrefiex = '/api'; } return { client: createClient(input, options.routePrefiex), - serverHook: createServerHandle(input,options.routePrefiex,options.createContext) // createContext makes user to use db on routes. + serverHook: createServerHandle(input, options.routePrefiex, options.createContext,options.cacheContext) // createContext makes user to use db on routes. }; -} \ No newline at end of file +} diff --git a/package/src/lib/components/interface/server.ts b/package/src/lib/components/interface/server.ts index bca8899..b688501 100644 --- a/package/src/lib/components/interface/server.ts +++ b/package/src/lib/components/interface/server.ts @@ -1,33 +1,32 @@ import { json, type Handle, error, type RequestEvent } from '@sveltejs/kit'; -import type { SingleOrMultipleRoutes, Route, Context } from '../types.js'; +import type { SingleOrMultipleRoutes, Route, Context, Options } from '../types.js'; +import { handleCacheControl } from '../options.js'; export function createServerHandle( input: Record, routePrefiex: `/${string}`, - createContext?: Context + createContext?: Context, + cacheContext: boolean = false ): Handle { + // Regular Context with no cache + const createNonCachedContext = () => { + return async (event: RequestEvent) => { + const context = createContext ? await createContext(event) : undefined; + return context; + }; + }; /* Caching the createContext might be good idea to avoid called db instances upon every request*/ - const createCachedContext = () => { let cachedContext: T | undefined; - return async (event: RequestEvent) => { if (!cachedContext) { - cachedContext = createContext ? await createContext(event) : undefined; - if (cachedContext instanceof Promise) { - console.log('Context is promise type'); - cachedContext - .then((val) => { - cachedContext = val; - }) - .catch((err) => console.log(err)); - } + cachedContext = createContext ? await createContext(event) : undefined; } return cachedContext; }; }; - const getContext = createCachedContext(); + const getContext = cacheContext ? createCachedContext() : createNonCachedContext(); return async ({ event, resolve }) => { const url = event.url.pathname; @@ -45,15 +44,25 @@ export function createServerHandle( } else { data = await event.request.json(); } + const parsedData = currentRouteObject.schema?.parse(data); - const cachedContext = getContext ? await getContext(event) : undefined; // cachedContext - const context = cachedContext ? cachedContext : { event } - const middlewaredContext =await handleMiddlewares(context,currentRouteObject.middlewares) + const obtainedContext = await getContext(event); // cachedContext + const context = obtainedContext ? obtainedContext : { event }; + const middlewaredContext = await handleMiddlewares(context, currentRouteObject.middlewares); const result = await currentRouteObject.cb({ input: parsedData, context: middlewaredContext }); - return json({ output: result }); + //handling custom headers and options + const headers = handleOptions(currentRouteObject.options); + + //Return json + return json( + { output: result }, + { + headers + } + ); } else { throw error(405); } @@ -76,18 +85,28 @@ function getCurrentObject(obj: Record, keys: str return undefined; } } - if (currentObj && 'cb' in currentObj && 'method' in currentObj) { + if (currentObj && 'cb' in currentObj && 'method' in currentObj && 'schema' in currentObj) { return currentObj as Route; } else { return undefined; } } -async function handleMiddlewares(currentContext:any,middlewares:((...inp:any)=>any)[]){ - let context = {...currentContext} +async function handleMiddlewares(currentContext: any, middlewares: ((...inp: any) => any)[]) { + let context = { ...currentContext }; for (const middleware of middlewares) { - const result = await middleware({context}) - context = {...context,...result} + const result = await middleware({ context }); + context = { ...context, ...result }; + } + return context; +} + +function handleOptions(options?: Partial):Record { + let cacheControl: string = ''; + if (options?.cacheControl) { + cacheControl = `max-age=${handleCacheControl(options.cacheControl)}`; } - return context -} \ No newline at end of file + const headers = options?.responseHeaders ? options.responseHeaders : {}; + const cacheHeaders = cacheControl? { 'Cache-Control': cacheControl } : {} + return { ...headers,...cacheHeaders}; +} diff --git a/package/src/lib/components/options.ts b/package/src/lib/components/options.ts new file mode 100644 index 0000000..3741e8a --- /dev/null +++ b/package/src/lib/components/options.ts @@ -0,0 +1,27 @@ + + +export function handleCacheControl(input:`${number}s` | `${number}h` | `${number}m` | `${number}d` ) { + const regex = /^(\d+)([smhd])$/; // Regex to match patterns like '2s', '4h', '5m', '2d' + const matches = input.match(regex); + + if (matches) { + const value = parseInt(matches[1], 10); // Extract the numeric value + const unit = matches[2]; // Extract the unit + + switch (unit) { + case 's': + return value; // Seconds + case 'm': + return value * 60; // Minutes to Seconds + case 'h': + return value * 60 * 60; // Hours to Seconds + case 'd': + return value * 24 * 60 * 60; // Days to Seconds + default: + throw new Error("Invalid Value for Cache Control , please use 1s or 1m or 1h or 1d "); + // Return the original string if the unit is not recognized + } + } else { + throw new Error("Invalid Value for Cache Control , please use 1s or 1m or 1h or 1d ");; // Return the original string if the input format doesn't match + } + } diff --git a/package/src/lib/components/types.d.ts b/package/src/lib/components/types.d.ts index 65a3154..701a6de 100644 --- a/package/src/lib/components/types.d.ts +++ b/package/src/lib/components/types.d.ts @@ -2,7 +2,7 @@ import type { RequestEvent } from '@sveltejs/kit'; import type { ResolvedUrl } from 'vite'; import type { z } from 'zod'; -type TContext = T extends undefined ? {event:RequestEvent} : ContextReturnType; +type TContext = T extends undefined ? { event: RequestEvent } : ContextReturnType; type Params = T extends undefined ? { context: TContext } @@ -11,7 +11,8 @@ type Route = { method: string; cb: (inp: Params) => U; schema: z.ZodSchema | undefined; - middlewares:((...inp:any)=>any)[] + middlewares: ((...inp: any) => any)[]; + options?: Partial; }; type SingleOrMultipleRoutes = Route | Record; @@ -34,4 +35,18 @@ type ContextReturnType = T extends (...args: any[]) => infer R ? Awaited : type CombineTypes = { [K in keyof A]: K extends keyof B ? B[K] : A[K]; - } & B; \ No newline at end of file +} & B; + +type Options = { + responseHeaders: { + [key: string]: string; + }; +} & { + cacheControl: `${number}s` | `${number}h` | `${number}m` | `${number}d`; +}; + +type RESTInterfaceOptions = Partial<{ + createContext: Context; + routePrefiex: `/${string}`; + cacheContext: boolean; +}>; diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..e69de29 diff --git a/plugins/svelte-query-plugin/.gitignore b/plugins/svelte-query-plugin/.gitignore new file mode 100644 index 0000000..ac7211b --- /dev/null +++ b/plugins/svelte-query-plugin/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +node_modules +/build +/dist +/.svelte-kit +/package +.env +.env.* +!.env.example +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/plugins/svelte-query-plugin/.npmrc b/plugins/svelte-query-plugin/.npmrc new file mode 100644 index 0000000..b6f27f1 --- /dev/null +++ b/plugins/svelte-query-plugin/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/plugins/svelte-query-plugin/README.md b/plugins/svelte-query-plugin/README.md new file mode 100644 index 0000000..4fee31f --- /dev/null +++ b/plugins/svelte-query-plugin/README.md @@ -0,0 +1,58 @@ +# create-svelte + +Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). + +Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging). + +## Creating a project + +If you're seeing this, you've probably already done this step. Congrats! + +```bash +# create a new project in the current directory +npm create svelte@latest + +# create a new project in my-app +npm create svelte@latest my-app +``` + +## Developing + +Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: + +```bash +npm run dev + +# or start the server and open the app in a new browser tab +npm run dev -- --open +``` + +Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app. + +## Building + +To build your library: + +```bash +npm run package +``` + +To create a production version of your showcase app: + +```bash +npm run build +``` + +You can preview the production build with `npm run preview`. + +> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. + +## Publishing + +Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)). + +To publish your library to [npm](https://www.npmjs.com): + +```bash +npm publish +``` diff --git a/plugins/svelte-query-plugin/package.json b/plugins/svelte-query-plugin/package.json new file mode 100644 index 0000000..9868c22 --- /dev/null +++ b/plugins/svelte-query-plugin/package.json @@ -0,0 +1,43 @@ +{ + "name": "@sveltekit-rest/svelte-query-plugin", + "version": "0.0.1", + "scripts": { + "dev": "vite dev", + "build": "vite build && npm run package", + "preview": "vite preview", + "package": "svelte-kit sync && svelte-package && publint", + "prepublishOnly": "npm run package", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "svelte": "./dist/index.js" + } + }, + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*" + ], + "peerDependencies": { + "svelte": "^4.0.0", + "sveltekit-rest":"^0.6.1" + }, + "devDependencies": { + "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/package": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^3.0.0", + "publint": "^0.1.9", + "svelte": "^4.2.7", + "svelte-check": "^3.6.0", + "tslib": "^2.4.1", + "typescript": "^5.0.0", + "vite": "^5.0.3" + }, + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts", + "type": "module" +} diff --git a/plugins/svelte-query-plugin/src/app.d.ts b/plugins/svelte-query-plugin/src/app.d.ts new file mode 100644 index 0000000..743f07b --- /dev/null +++ b/plugins/svelte-query-plugin/src/app.d.ts @@ -0,0 +1,13 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } +} + +export {}; diff --git a/plugins/svelte-query-plugin/src/app.html b/plugins/svelte-query-plugin/src/app.html new file mode 100644 index 0000000..f22aeaa --- /dev/null +++ b/plugins/svelte-query-plugin/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/plugins/svelte-query-plugin/src/lib/index.ts b/plugins/svelte-query-plugin/src/lib/index.ts new file mode 100644 index 0000000..47d3c46 --- /dev/null +++ b/plugins/svelte-query-plugin/src/lib/index.ts @@ -0,0 +1 @@ +// Reexport your entry components here diff --git a/plugins/svelte-query-plugin/src/routes/+page.svelte b/plugins/svelte-query-plugin/src/routes/+page.svelte new file mode 100644 index 0000000..0a45b69 --- /dev/null +++ b/plugins/svelte-query-plugin/src/routes/+page.svelte @@ -0,0 +1,3 @@ +

Welcome to your library project

+

Create your package using @sveltejs/package and preview/showcase your work with SvelteKit

+

Visit kit.svelte.dev to read the documentation

diff --git a/plugins/svelte-query-plugin/static/favicon.png b/plugins/svelte-query-plugin/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. + +## Publishing + +Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)). + +To publish your library to [npm](https://www.npmjs.com): + +```bash +npm publish +``` diff --git a/plugins/svelte-store-plugin/package.json b/plugins/svelte-store-plugin/package.json new file mode 100644 index 0000000..5810931 --- /dev/null +++ b/plugins/svelte-store-plugin/package.json @@ -0,0 +1,43 @@ +{ + "name": "@sveltekit-rest/svelte-store-plugin", + "version": "0.0.1", + "scripts": { + "dev": "vite dev", + "build": "vite build && npm run package", + "preview": "vite preview", + "package": "svelte-kit sync && svelte-package && publint", + "prepublishOnly": "npm run package", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "svelte": "./dist/index.js" + } + }, + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*" + ], + "peerDependencies": { + "svelte": "^4.0.0", + "sveltekit-rest":"^0.6.1" + }, + "devDependencies": { + "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/package": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^3.0.0", + "publint": "^0.1.9", + "svelte": "^4.2.7", + "svelte-check": "^3.6.0", + "tslib": "^2.4.1", + "typescript": "^5.0.0", + "vite": "^5.0.3" + }, + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts", + "type": "module" +} diff --git a/plugins/svelte-store-plugin/src/app.d.ts b/plugins/svelte-store-plugin/src/app.d.ts new file mode 100644 index 0000000..743f07b --- /dev/null +++ b/plugins/svelte-store-plugin/src/app.d.ts @@ -0,0 +1,13 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } +} + +export {}; diff --git a/plugins/svelte-store-plugin/src/app.html b/plugins/svelte-store-plugin/src/app.html new file mode 100644 index 0000000..f22aeaa --- /dev/null +++ b/plugins/svelte-store-plugin/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/plugins/svelte-store-plugin/src/lib/components/store.ts b/plugins/svelte-store-plugin/src/lib/components/store.ts new file mode 100644 index 0000000..f8b3ebb --- /dev/null +++ b/plugins/svelte-store-plugin/src/lib/components/store.ts @@ -0,0 +1 @@ +import { writable,readable } from "svelte/store"; \ No newline at end of file diff --git a/plugins/svelte-store-plugin/src/lib/index.ts b/plugins/svelte-store-plugin/src/lib/index.ts new file mode 100644 index 0000000..47d3c46 --- /dev/null +++ b/plugins/svelte-store-plugin/src/lib/index.ts @@ -0,0 +1 @@ +// Reexport your entry components here diff --git a/plugins/svelte-store-plugin/src/routes/+page.svelte b/plugins/svelte-store-plugin/src/routes/+page.svelte new file mode 100644 index 0000000..0a45b69 --- /dev/null +++ b/plugins/svelte-store-plugin/src/routes/+page.svelte @@ -0,0 +1,3 @@ +

Welcome to your library project

+

Create your package using @sveltejs/package and preview/showcase your work with SvelteKit

+

Visit kit.svelte.dev to read the documentation

diff --git a/plugins/svelte-store-plugin/static/favicon.png b/plugins/svelte-store-plugin/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH=18} @@ -1185,6 +1350,32 @@ packages: - supports-color dev: true + /@sveltejs/kit@2.0.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.7)(vite@5.0.10): + resolution: {integrity: sha512-/GFxvit+q7PztRbgGTFXhVB6jvb0fZSeWuz5f4siQ2r/5BVhxYh7++Bw3/ZUjiOuyoZFiNBmOPcRNQbkzEce0g==} + engines: {node: '>=18.13'} + hasBin: true + requiresBuild: true + peerDependencies: + '@sveltejs/vite-plugin-svelte': ^3.0.0 + svelte: ^4.0.0 || ^5.0.0-next.0 + vite: ^5.0.3 + dependencies: + '@sveltejs/vite-plugin-svelte': 3.0.1(svelte@4.2.7)(vite@5.0.10) + '@types/cookie': 0.6.0 + cookie: 0.6.0 + devalue: 4.3.2 + esm-env: 1.0.0 + kleur: 4.1.5 + magic-string: 0.30.5 + mrmime: 1.0.1 + sade: 1.8.1 + set-cookie-parser: 2.6.0 + sirv: 2.0.3 + svelte: 4.2.7 + tiny-glob: 0.2.9 + vite: 5.0.10 + dev: true + /@sveltejs/package@2.2.3(svelte@4.2.7)(typescript@5.3.2): resolution: {integrity: sha512-iZEC5qw+2RIjfIAHR3O+IeokJIjVM/ieoxPxj6YmZCwu5JKFADtC4jzjSUJ7GkCMUQ4HqE7u4/3cCxXBocxi8A==} engines: {node: ^16.14 || >=18} @@ -1218,6 +1409,22 @@ packages: - supports-color dev: true + /@sveltejs/vite-plugin-svelte-inspector@2.0.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.7)(vite@5.0.10): + resolution: {integrity: sha512-gjr9ZFg1BSlIpfZ4PRewigrvYmHWbDrq2uvvPB1AmTWKuM+dI1JXQSUu2pIrYLb/QncyiIGkFDFKTwJ0XqQZZg==} + engines: {node: ^18.0.0 || >=20} + peerDependencies: + '@sveltejs/vite-plugin-svelte': ^3.0.0 + svelte: ^4.0.0 || ^5.0.0-next.0 + vite: ^5.0.0 + dependencies: + '@sveltejs/vite-plugin-svelte': 3.0.1(svelte@4.2.7)(vite@5.0.10) + debug: 4.3.4 + svelte: 4.2.7 + vite: 5.0.10 + transitivePeerDependencies: + - supports-color + dev: true + /@sveltejs/vite-plugin-svelte@2.5.3(svelte@4.2.7)(vite@4.5.0): resolution: {integrity: sha512-erhNtXxE5/6xGZz/M9eXsmI7Pxa6MS7jyTy06zN3Ck++ldrppOnOlJwHHTsMC7DHDQdgUp4NAc4cDNQ9eGdB/w==} engines: {node: ^14.18.0 || >= 16} @@ -1238,6 +1445,26 @@ packages: - supports-color dev: true + /@sveltejs/vite-plugin-svelte@3.0.1(svelte@4.2.7)(vite@5.0.10): + resolution: {integrity: sha512-CGURX6Ps+TkOovK6xV+Y2rn8JKa8ZPUHPZ/NKgCxAmgBrXReavzFl8aOSCj3kQ1xqT7yGJj53hjcV/gqwDAaWA==} + engines: {node: ^18.0.0 || >=20} + peerDependencies: + svelte: ^4.0.0 || ^5.0.0-next.0 + vite: ^5.0.0 + dependencies: + '@sveltejs/vite-plugin-svelte-inspector': 2.0.0(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.7)(vite@5.0.10) + debug: 4.3.4 + deepmerge: 4.3.1 + kleur: 4.1.5 + magic-string: 0.30.5 + svelte: 4.2.7 + svelte-hmr: 0.15.3(svelte@4.2.7) + vite: 5.0.10 + vitefu: 0.2.5(vite@5.0.10) + transitivePeerDependencies: + - supports-color + dev: true + /@types/acorn@4.0.6: resolution: {integrity: sha512-veQTnWP+1D/xbxVrPC3zHnCZRjSrKfhbMUlEA43iMZLu7EsnTtkJklIuwrCPbOi8YkvDQAiW05VQQFvvz9oieQ==} dependencies: @@ -1287,6 +1514,10 @@ packages: resolution: {integrity: sha512-7z/eR6O859gyWIAjuvBWFzNURmf2oPBmJlfVWkwehU5nzIyjwBsTh7WMmEEV4JFnHuQ3ex4oyTvfKzcyJVDBNA==} dev: true + /@types/cookie@0.6.0: + resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} + dev: true + /@types/debug@4.1.12: resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} dependencies: @@ -2003,6 +2234,11 @@ packages: resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} engines: {node: '>= 0.6'} + /cookie@0.6.0: + resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==} + engines: {node: '>= 0.6'} + dev: true + /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -2251,7 +2487,6 @@ packages: '@esbuild/win32-arm64': 0.19.8 '@esbuild/win32-ia32': 0.19.8 '@esbuild/win32-x64': 0.19.8 - dev: false /escalade@3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} @@ -4185,6 +4420,15 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.2 + /postcss@8.4.32: + resolution: {integrity: sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.3.7 + picocolors: 1.0.0 + source-map-js: 1.0.2 + dev: true + /prebuild-install@7.1.1: resolution: {integrity: sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==} engines: {node: '>=10'} @@ -4508,6 +4752,27 @@ packages: optionalDependencies: fsevents: 2.3.3 + /rollup@4.9.0: + resolution: {integrity: sha512-bUHW/9N21z64gw8s6tP4c88P382Bq/L5uZDowHlHx6s/QWpjJXivIAbEw6LZthgSvlEizZBfLC4OAvWe7aoF7A==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.9.0 + '@rollup/rollup-android-arm64': 4.9.0 + '@rollup/rollup-darwin-arm64': 4.9.0 + '@rollup/rollup-darwin-x64': 4.9.0 + '@rollup/rollup-linux-arm-gnueabihf': 4.9.0 + '@rollup/rollup-linux-arm64-gnu': 4.9.0 + '@rollup/rollup-linux-arm64-musl': 4.9.0 + '@rollup/rollup-linux-riscv64-gnu': 4.9.0 + '@rollup/rollup-linux-x64-gnu': 4.9.0 + '@rollup/rollup-linux-x64-musl': 4.9.0 + '@rollup/rollup-win32-arm64-msvc': 4.9.0 + '@rollup/rollup-win32-ia32-msvc': 4.9.0 + '@rollup/rollup-win32-x64-msvc': 4.9.0 + fsevents: 2.3.3 + dev: true + /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: @@ -5387,6 +5652,41 @@ packages: optionalDependencies: fsevents: 2.3.3 + /vite@5.0.10: + resolution: {integrity: sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@types/node': ^18.0.0 || >=20.0.0 + less: '*' + lightningcss: ^1.21.0 + sass: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + dependencies: + esbuild: 0.19.8 + postcss: 8.4.32 + rollup: 4.9.0 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /vitefu@0.2.5(vite@4.5.0): resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} peerDependencies: @@ -5397,6 +5697,17 @@ packages: dependencies: vite: 4.5.0(@types/node@20.10.2) + /vitefu@0.2.5(vite@5.0.10): + resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} + peerDependencies: + vite: ^3.0.0 || ^4.0.0 || ^5.0.0 + peerDependenciesMeta: + vite: + optional: true + dependencies: + vite: 5.0.10 + dev: true + /vitest@0.34.6: resolution: {integrity: sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==} engines: {node: '>=v14.18.0'} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a0eb242..1f3a422 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,5 @@ packages: - 'package/' - 'www/' - - 'examples/*' \ No newline at end of file + - 'examples/*' + - 'plugins/*' \ No newline at end of file