feat: release design system engine, studio and component contracts

This commit is contained in:
Clintchiz committed 2026-10-19 13:09:03 +05:30
1 parent ff1065fb27
commit 3943b946d6
693 files changed
+175546 -3894

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@wrnexus/pwa",
"version": "0.8.12",
"version": "0.8.13",
"type": "module",
"description": "Service workers, manifests, offline queues, background sync, push, and conflict resolution for WRNexusJS.",
"main": "./src/index.ts",
-1
View File
@@ -105,7 +105,6 @@ self.addEventListener("fetch",event=>{
self.addEventListener("sync",event=>{if(event.tag===${JSON.stringify(options.backgroundSyncTag ?? "wrnexus-offline-sync")})event.waitUntil(self.clients.matchAll().then(clients=>clients.forEach(client=>client.postMessage({type:"wrnexus:background-sync"}))))});
self.addEventListener("push",event=>{const data=event.data?.json?.()||{};event.waitUntil(self.registration.showNotification(data.title||"Notification",{body:data.body,icon:data.icon,data:{url:data.url||"/"}}))});
self.addEventListener("notificationclick",event=>{event.notification.close();event.waitUntil(clients.openWindow(event.notification.data?.url||"/"))});`;
}
export interface OfflineMutation<T = unknown> {
id: string;
+58 -26
View File
@@ -1,40 +1,72 @@
import { expect, test } from "bun:test";
import { generateServiceWorker } from "../src/index.ts";
function worker(fetcher: (r:any)=>Promise<Response>, failStore = false) {
const listeners: Record<string,Function> = {};
function worker(fetcher: (r: any) => Promise<Response>, failStore = false) {
const listeners: Record<string, (event: any) => void> = {};
const saved: string[] = [];
const cache = {match:async()=>undefined,put:async(r:any)=>{if(failStore)throw Error("quota");saved.push(r.url)}};
const self = {location:{origin:"https://account.example.test"},addEventListener:(name:string,fn:Function)=>listeners[name]=fn,skipWaiting(){},clients:{claim:async()=>{}}};
new Function("self","caches","fetch",generateServiceWorker())(self,{open:async()=>cache,keys:async()=>[],delete:async()=>true},fetcher);
return {saved, async fetch(path:string, mode="cors") {
let result:Promise<Response>|undefined;
const req = new Request(new URL(path,self.location.origin));
Object.defineProperty(req,"mode",{value:mode});
listeners.fetch({request:req,respondWith:(r:Promise<Response>)=>result=r,waitUntil:()=>{}});
return result;
}};
const cache = {
match: async () => undefined,
put: async (r: any) => {
if (failStore) throw Error("quota");
saved.push(r.url);
},
};
const self = {
location: { origin: "https://account.example.test" },
addEventListener: (name: string, fn: (event: any) => void) => (listeners[name] = fn),
skipWaiting() {},
clients: { claim: async () => {} },
};
new Function("self", "caches", "fetch", generateServiceWorker())(
self,
{ open: async () => cache, keys: async () => [], delete: async () => true },
fetcher,
);
return {
saved,
async fetch(path: string, mode = "cors") {
let result: Promise<Response> | undefined;
const req = new Request(new URL(path, self.location.origin));
Object.defineProperty(req, "mode", { value: mode });
listeners.fetch({
request: req,
respondWith: (r: Promise<Response>) => (result = r),
waitUntil: () => {},
});
return result;
},
};
}
test("handoffs and API calls bypass service worker interception", async()=>{
const w=worker(async()=>{throw Error("must not intercept")});
test("handoffs and API calls bypass service worker interception", async () => {
const w = worker(async () => {
throw Error("must not intercept");
});
expect(await w.fetch("/organization-add?sso_code=one-time")).toBeUndefined();
expect(await w.fetch("/api/account")).toBeUndefined();
});
test("private responses and navigations never enter cache", async()=>{
const w=worker(async()=>new Response("private",{headers:{"cache-control":"private, no-store"}}));
test("private responses and navigations never enter cache", async () => {
const w = worker(
async () => new Response("private", { headers: { "cache-control": "private, no-store" } }),
);
expect(await (await w.fetch("/profile"))?.text()).toBe("private");
expect(w.saved).toEqual([]);
const nav=worker(async()=>new Response("personal page"));
await nav.fetch("/profile","navigate"); expect(nav.saved).toEqual([]);
const nav = worker(async () => new Response("personal page"));
await nav.fetch("/profile", "navigate");
expect(nav.saved).toEqual([]);
});
test("cache quota errors do not turn successful requests into network errors", async()=>{
const w=worker(async()=>new Response("asset"),true);
test("cache quota errors do not turn successful requests into network errors", async () => {
const w = worker(async () => new Response("asset"), true);
expect(await (await w.fetch("/app.js"))?.text()).toBe("asset");
});
test("offline without a cached fallback always returns a Response", async()=>{
const w=worker(async()=>{throw Error("offline")});
expect((await w.fetch("/profile","navigate"))?.status).toBe(503);
test("offline without a cached fallback always returns a Response", async () => {
const w = worker(async () => {
throw Error("offline");
});
expect((await w.fetch("/profile", "navigate"))?.status).toBe(503);
});
test("public static assets remain cacheable", async()=>{
const w=worker(async()=>new Response("asset",{headers:{"cache-control":"public, max-age=3600"}}));
await w.fetch("/app.js"); expect(w.saved).toHaveLength(1);
test("public static assets remain cacheable", async () => {
const w = worker(
async () => new Response("asset", { headers: { "cache-control": "public, max-age=3600" } }),
);
await w.fetch("/app.js");
expect(w.saved).toHaveLength(1);
});