-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
088f83d
commit 48e7869
Showing
34 changed files
with
816 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, SingleOrMultipleRoutes>} input | ||
* @param {{ | ||
* createContext?: Context<any>; | ||
* routePrefiex?: `/${string}` | ||
* }} | ||
* @returns {{client: any;serverHook: any;}} | ||
*/ | ||
export function createRESTInterface<T>(input: Record<string,SingleOrMultipleRoutes>,options:{ createContext?:Context<any> , | ||
/** Default to /api */ | ||
routePrefiex?: `/${string}`}={}) { | ||
export function createRESTInterface<T>( | ||
input: Record<string, SingleOrMultipleRoutes>, | ||
options?: RESTInterfaceOptions | ||
) { | ||
options = options ? options : {}; | ||
if (!options.routePrefiex) { | ||
options.routePrefiex = "/api" | ||
options.routePrefiex = '/api'; | ||
} | ||
return { | ||
client: createClient<T>(input, options.routePrefiex), | ||
serverHook: createServerHandle<any>(input,options.routePrefiex,options.createContext) // createContext makes user to use db on routes. | ||
serverHook: createServerHandle<T>(input, options.routePrefiex, options.createContext,options.cacheContext) // createContext makes user to use db on routes. | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
Oops, something went wrong.