@korajs/svelte 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @korajs/svelte
|
|
2
|
+
|
|
3
|
+
Experimental Svelte bindings stub for [Kora.js](https://github.com/korajs/kora). Use `@korajs/react` for full reactive query hooks today.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { createApp } from 'korajs'
|
|
10
|
+
import { setKoraAppContext, getKoraApp } from '@korajs/svelte'
|
|
11
|
+
import schema from './schema'
|
|
12
|
+
|
|
13
|
+
const kora = createApp({ schema, store: { workerUrl: '/sqlite-wasm-worker.js' } })
|
|
14
|
+
setKoraAppContext(kora)
|
|
15
|
+
await kora.ready
|
|
16
|
+
</script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Child components call `getKoraApp()` and use collection accessors or subscribe to `app.events`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
getKoraApp: () => getKoraApp,
|
|
24
|
+
setKoraAppContext: () => setKoraAppContext
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_core = require("@korajs/core");
|
|
28
|
+
var import_svelte = require("svelte");
|
|
29
|
+
var koraAppContextKey = /* @__PURE__ */ Symbol("korajs-app");
|
|
30
|
+
function setKoraAppContext(koraApp) {
|
|
31
|
+
(0, import_svelte.setContext)(koraAppContextKey, koraApp);
|
|
32
|
+
}
|
|
33
|
+
function getKoraApp() {
|
|
34
|
+
const app = (0, import_svelte.getContext)(koraAppContextKey);
|
|
35
|
+
if (!app) {
|
|
36
|
+
throw new import_core.KoraError(
|
|
37
|
+
"getKoraApp() requires setKoraAppContext(koraApp) on an ancestor component.",
|
|
38
|
+
"KORA_NOT_PROVIDED",
|
|
39
|
+
{
|
|
40
|
+
fix: "In +layout.svelte: setKoraAppContext(kora); await kora.ready before queries."
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return app;
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getKoraApp,
|
|
49
|
+
setKoraAppContext
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { KoraError } from '@korajs/core'\nimport { getContext, setContext } from 'svelte'\nimport type { KoraAppHandle } from './types'\n\nexport type { KoraAppHandle } from './types'\n\nconst koraAppContextKey = Symbol('korajs-app')\n\n/**\n * Set the Kora app in Svelte context (call from a root layout or `+layout.svelte`).\n */\nexport function setKoraAppContext(koraApp: KoraAppHandle): void {\n\tsetContext(koraAppContextKey, koraApp)\n}\n\n/**\n * Read the Kora app from Svelte context in child components.\n */\nexport function getKoraApp(): KoraAppHandle {\n\tconst app = getContext<KoraAppHandle | undefined>(koraAppContextKey)\n\tif (!app) {\n\t\tthrow new KoraError(\n\t\t\t'getKoraApp() requires setKoraAppContext(koraApp) on an ancestor component.',\n\t\t\t'KORA_NOT_PROVIDED',\n\t\t\t{\n\t\t\t\tfix: 'In +layout.svelte: setKoraAppContext(kora); await kora.ready before queries.',\n\t\t\t},\n\t\t)\n\t}\n\treturn app\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,oBAAuC;AAKvC,IAAM,oBAAoB,uBAAO,YAAY;AAKtC,SAAS,kBAAkB,SAA8B;AAC/D,gCAAW,mBAAmB,OAAO;AACtC;AAKO,SAAS,aAA4B;AAC3C,QAAM,UAAM,0BAAsC,iBAAiB;AACnE,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,QACC,KAAK;AAAA,MACN;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { KoraEventEmitter } from '@korajs/core';
|
|
2
|
+
import { Store } from '@korajs/store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal app handle type for Svelte context (matches `createApp()` from korajs).
|
|
6
|
+
*/
|
|
7
|
+
interface KoraAppHandle {
|
|
8
|
+
readonly ready: Promise<void>;
|
|
9
|
+
readonly events: KoraEventEmitter;
|
|
10
|
+
readonly sync: unknown;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
getStore(): Store;
|
|
13
|
+
[collection: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set the Kora app in Svelte context (call from a root layout or `+layout.svelte`).
|
|
18
|
+
*/
|
|
19
|
+
declare function setKoraAppContext(koraApp: KoraAppHandle): void;
|
|
20
|
+
/**
|
|
21
|
+
* Read the Kora app from Svelte context in child components.
|
|
22
|
+
*/
|
|
23
|
+
declare function getKoraApp(): KoraAppHandle;
|
|
24
|
+
|
|
25
|
+
export { type KoraAppHandle, getKoraApp, setKoraAppContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { KoraEventEmitter } from '@korajs/core';
|
|
2
|
+
import { Store } from '@korajs/store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal app handle type for Svelte context (matches `createApp()` from korajs).
|
|
6
|
+
*/
|
|
7
|
+
interface KoraAppHandle {
|
|
8
|
+
readonly ready: Promise<void>;
|
|
9
|
+
readonly events: KoraEventEmitter;
|
|
10
|
+
readonly sync: unknown;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
getStore(): Store;
|
|
13
|
+
[collection: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set the Kora app in Svelte context (call from a root layout or `+layout.svelte`).
|
|
18
|
+
*/
|
|
19
|
+
declare function setKoraAppContext(koraApp: KoraAppHandle): void;
|
|
20
|
+
/**
|
|
21
|
+
* Read the Kora app from Svelte context in child components.
|
|
22
|
+
*/
|
|
23
|
+
declare function getKoraApp(): KoraAppHandle;
|
|
24
|
+
|
|
25
|
+
export { type KoraAppHandle, getKoraApp, setKoraAppContext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { KoraError } from "@korajs/core";
|
|
3
|
+
import { getContext, setContext } from "svelte";
|
|
4
|
+
var koraAppContextKey = /* @__PURE__ */ Symbol("korajs-app");
|
|
5
|
+
function setKoraAppContext(koraApp) {
|
|
6
|
+
setContext(koraAppContextKey, koraApp);
|
|
7
|
+
}
|
|
8
|
+
function getKoraApp() {
|
|
9
|
+
const app = getContext(koraAppContextKey);
|
|
10
|
+
if (!app) {
|
|
11
|
+
throw new KoraError(
|
|
12
|
+
"getKoraApp() requires setKoraAppContext(koraApp) on an ancestor component.",
|
|
13
|
+
"KORA_NOT_PROVIDED",
|
|
14
|
+
{
|
|
15
|
+
fix: "In +layout.svelte: setKoraAppContext(kora); await kora.ready before queries."
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return app;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getKoraApp,
|
|
23
|
+
setKoraAppContext
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { KoraError } from '@korajs/core'\nimport { getContext, setContext } from 'svelte'\nimport type { KoraAppHandle } from './types'\n\nexport type { KoraAppHandle } from './types'\n\nconst koraAppContextKey = Symbol('korajs-app')\n\n/**\n * Set the Kora app in Svelte context (call from a root layout or `+layout.svelte`).\n */\nexport function setKoraAppContext(koraApp: KoraAppHandle): void {\n\tsetContext(koraAppContextKey, koraApp)\n}\n\n/**\n * Read the Kora app from Svelte context in child components.\n */\nexport function getKoraApp(): KoraAppHandle {\n\tconst app = getContext<KoraAppHandle | undefined>(koraAppContextKey)\n\tif (!app) {\n\t\tthrow new KoraError(\n\t\t\t'getKoraApp() requires setKoraAppContext(koraApp) on an ancestor component.',\n\t\t\t'KORA_NOT_PROVIDED',\n\t\t\t{\n\t\t\t\tfix: 'In +layout.svelte: setKoraAppContext(kora); await kora.ready before queries.',\n\t\t\t},\n\t\t)\n\t}\n\treturn app\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY,kBAAkB;AAKvC,IAAM,oBAAoB,uBAAO,YAAY;AAKtC,SAAS,kBAAkB,SAA8B;AAC/D,aAAW,mBAAmB,OAAO;AACtC;AAKO,SAAS,aAA4B;AAC3C,QAAM,MAAM,WAAsC,iBAAiB;AACnE,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,QACC,KAAK;AAAA,MACN;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@korajs/svelte",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Experimental Svelte bindings stub for Kora.js (context helpers)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"svelte": "^4.0.0 || ^5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@korajs/store": "0.5.0",
|
|
29
|
+
"@korajs/core": "0.5.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.3.6",
|
|
33
|
+
"typescript": "^5.7.3",
|
|
34
|
+
"svelte": "^5.0.0"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"dev": "tsup --watch",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"lint": "biome check src/",
|
|
42
|
+
"clean": "rm -rf dist .turbo"
|
|
43
|
+
}
|
|
44
|
+
}
|