diff --git a/app/__test__/api/Api.spec.ts b/app/__test__/api/Api.spec.ts index 85f144d..dee1e14 100644 --- a/app/__test__/api/Api.spec.ts +++ b/app/__test__/api/Api.spec.ts @@ -19,8 +19,8 @@ describe("Api", async () => { const token = await sign({ foo: "bar" }, "1234"); const request = new Request("http://example.com/test", { headers: { - Authorization: `Bearer ${token}` - } + Authorization: `Bearer ${token}`, + }, }); const api = new Api({ request }); expect(api.isAuthVerified()).toBe(false); @@ -35,8 +35,8 @@ describe("Api", async () => { const token = await sign({ foo: "bar" }, "1234"); const request = new Request("http://example.com/test", { headers: { - Cookie: `auth=${token}` - } + Cookie: `auth=${token}`, + }, }); const api = new Api({ request }); expect(api.isAuthVerified()).toBe(false); diff --git a/app/__test__/api/DataApi.spec.ts b/app/__test__/api/DataApi.spec.ts index c3c997a..2e4e4c5 100644 --- a/app/__test__/api/DataApi.spec.ts +++ b/app/__test__/api/DataApi.spec.ts @@ -26,7 +26,7 @@ describe("DataApi", () => { it("returns result", async () => { const schema = proto.em({ - posts: proto.entity("posts", { title: proto.text() }) + posts: proto.entity("posts", { title: proto.text() }), }); const em = schemaToEm(schema); await em.schema().sync({ force: true }); @@ -60,7 +60,7 @@ describe("DataApi", () => { select: ["title"], limit: 100000, offset: 0, - sort: "id" + sort: "id", }); expect(req.request.method).toBe("POST"); const res = await req; diff --git a/app/__test__/api/MediaApi.spec.ts b/app/__test__/api/MediaApi.spec.ts index 27e86da..785f1ab 100644 --- a/app/__test__/api/MediaApi.spec.ts +++ b/app/__test__/api/MediaApi.spec.ts @@ -18,8 +18,8 @@ const mockedBackend = new Hono() return new Response(file, { headers: { "Content-Type": file.type, - "Content-Length": file.size.toString() - } + "Content-Length": file.size.toString(), + }, }); }); @@ -30,7 +30,7 @@ describe("MediaApi", () => { // @ts-ignore tests const api = new MediaApi({ host, - basepath + basepath, }); expect(api.getFileUploadUrl({ path: "path" })).toBe(`${host}${basepath}/upload/path`); }); @@ -38,7 +38,7 @@ describe("MediaApi", () => { it("should have correct upload headers", () => { // @ts-ignore tests const api = new MediaApi({ - token: "token" + token: "token", }); expect(api.getUploadHeaders().get("Authorization")).toBe("Bearer token"); }); @@ -139,7 +139,7 @@ describe("MediaApi", () => { const response = (await mockedBackend.request(url)) as Response; await matches( await api.upload(response.body!, { filename: "readable.png" }), - "readable.png" + "readable.png", ); } }); diff --git a/app/__test__/api/ModuleApi.spec.ts b/app/__test__/api/ModuleApi.spec.ts index 9577fd1..59c8816 100644 --- a/app/__test__/api/ModuleApi.spec.ts +++ b/app/__test__/api/ModuleApi.spec.ts @@ -61,7 +61,7 @@ describe("ModuleApi", () => { it("adds additional headers from options", () => { const headers = new Headers({ - "X-Test": "123" + "X-Test": "123", }); const api = new Api({ host, headers }); expect(api.get("/").request.headers.get("X-Test")).toEqual("123"); @@ -75,7 +75,7 @@ describe("ModuleApi", () => { it("uses search params", () => { const api = new Api({ host }); const search = new URLSearchParams({ - foo: "bar" + foo: "bar", }); expect(api.get("/", search).request.url).toEqual("http://localhost/?" + search.toString()); }); diff --git a/app/__test__/app/repro.spec.ts b/app/__test__/app/repro.spec.ts index c76d55f..7b69376 100644 --- a/app/__test__/app/repro.spec.ts +++ b/app/__test__/app/repro.spec.ts @@ -24,9 +24,9 @@ describe("repros", async () => { adapter: { type: "local", config: { - path: "./" - } - } + path: "./", + }, + }, }); expect(config.enabled).toBe(true); @@ -38,9 +38,9 @@ describe("repros", async () => { "entities.test", proto .entity("test", { - content: proto.text() + content: proto.text(), }) - .toJSON() + .toJSON(), ); expect(app.em.entities.map((e) => e.name)).toContain("test"); } @@ -54,8 +54,8 @@ describe("repros", async () => { hidden: false, mime_types: [], virtual: true, - entity: "test" - } + entity: "test", + }, }); expect( @@ -63,8 +63,8 @@ describe("repros", async () => { type: "poly", source: "test", target: "media", - config: { mappedBy: "files" } - }) + config: { mappedBy: "files" }, + }), ).resolves.toBeDefined(); } @@ -75,17 +75,17 @@ describe("repros", async () => { const schema = proto.em( { products: proto.entity("products", { - title: proto.text() + title: proto.text(), }), product_likes: proto.entity("product_likes", { - created_at: proto.date() + created_at: proto.date(), }), - users: proto.entity("users", {}) + users: proto.entity("users", {}), }, (fns, schema) => { fns.relation(schema.product_likes).manyToOne(schema.products, { inversedBy: "likes" }); fns.relation(schema.product_likes).manyToOne(schema.users); - } + }, ); const app = createApp({ initialConfig: { data: schema.toJSON() } }); await app.build(); @@ -96,8 +96,8 @@ describe("repros", async () => { expect(info.relations.listable).toEqual([ { entity: "product_likes", - ref: "likes" - } + ref: "likes", + }, ]); }); }); diff --git a/app/__test__/auth/authorize/authorize.spec.ts b/app/__test__/auth/authorize/authorize.spec.ts index 4ca0ce1..4534969 100644 --- a/app/__test__/auth/authorize/authorize.spec.ts +++ b/app/__test__/auth/authorize/authorize.spec.ts @@ -7,13 +7,13 @@ describe("authorize", () => { ["read", "write"], { admin: { - permissions: ["read", "write"] - } + permissions: ["read", "write"], + }, }, - { enabled: true } + { enabled: true }, ); const user = { - role: "admin" + role: "admin", }; expect(guard.granted("read", user)).toBe(true); @@ -27,21 +27,21 @@ describe("authorize", () => { ["read", "write"], { admin: { - permissions: ["read", "write"] + permissions: ["read", "write"], }, guest: { permissions: ["read"], - is_default: true - } + is_default: true, + }, }, - { enabled: true } + { enabled: true }, ); expect(guard.granted("read")).toBe(true); expect(guard.granted("write")).toBe(false); const user = { - role: "admin" + role: "admin", }; expect(guard.granted("read", user)).toBe(true); @@ -58,12 +58,12 @@ describe("authorize", () => { test("role implicit allow", async () => { const guard = Guard.create(["read", "write"], { admin: { - implicit_allow: true - } + implicit_allow: true, + }, }); const user = { - role: "admin" + role: "admin", }; expect(guard.granted("read", user)).toBe(true); @@ -74,8 +74,8 @@ describe("authorize", () => { const guard = Guard.create(["read", "write"], { guest: { implicit_allow: true, - is_default: true - } + is_default: true, + }, }); expect(guard.getUserRole()?.name).toBe("guest"); diff --git a/app/__test__/auth/strategies/OAuthStrategy.spec.ts b/app/__test__/auth/strategies/OAuthStrategy.spec.ts index a41f189..eb1a397 100644 --- a/app/__test__/auth/strategies/OAuthStrategy.spec.ts +++ b/app/__test__/auth/strategies/OAuthStrategy.spec.ts @@ -8,9 +8,9 @@ describe("OAuthStrategy", async () => { type: "oidc", client: { client_id: process.env.OAUTH_CLIENT_ID, - client_secret: process.env.OAUTH_CLIENT_SECRET + client_secret: process.env.OAUTH_CLIENT_SECRET, }, - name: "google" + name: "google", }); const state = "---"; const redirect_uri = "http://localhost:3000/auth/google/callback"; @@ -21,7 +21,7 @@ describe("OAuthStrategy", async () => { const request = await strategy.request({ redirect_uri, - state + state, }); const server = Bun.serve({ @@ -31,13 +31,13 @@ describe("OAuthStrategy", async () => { console.log("req", req); const user = await strategy.callback(url, { redirect_uri, - state + state, }); console.log("---user", user); } return new Response("Bun!"); - } + }, }); console.log("request", request); diff --git a/app/__test__/core/EventManager.spec.ts b/app/__test__/core/EventManager.spec.ts index 5d81e77..995ebfa 100644 --- a/app/__test__/core/EventManager.spec.ts +++ b/app/__test__/core/EventManager.spec.ts @@ -26,7 +26,7 @@ class ReturnEvent extends Event<{ foo: string }, string> { } return this.clone({ - foo: [this.params.foo, value].join("-") + foo: [this.params.foo, value].join("-"), }); } } @@ -52,7 +52,7 @@ describe("EventManager", async () => { await new Promise((resolve) => setTimeout(resolve, 50)); delayed(); }, - "sync" + "sync", ); // don't allow unknown @@ -83,8 +83,8 @@ describe("EventManager", async () => { const emgr = new EventManager( { InformationalEvent }, { - asyncExecutor - } + asyncExecutor, + }, ); emgr.onEvent(InformationalEvent, async () => {}); @@ -98,8 +98,8 @@ describe("EventManager", async () => { const emgr = new EventManager( { ReturnEvent, InformationalEvent }, { - onInvalidReturn - } + onInvalidReturn, + }, ); // @ts-expect-error InformationalEvent has no return value @@ -140,7 +140,7 @@ describe("EventManager", async () => { expect(slug).toBe("informational-event"); call(); }, - { mode: "sync", once: true } + { mode: "sync", once: true }, ); expect(emgr.getListeners().length).toBe(1); diff --git a/app/__test__/core/Registry.spec.ts b/app/__test__/core/Registry.spec.ts index 557b39a..637a836 100644 --- a/app/__test__/core/Registry.spec.ts +++ b/app/__test__/core/Registry.spec.ts @@ -30,8 +30,8 @@ describe("Registry", () => { first: { cls: What, schema: Type.Object({ type: Type.String(), what: Type.String() }), - enabled: true - } + enabled: true, + }, } satisfies Record); const item = registry.get("first"); @@ -42,7 +42,7 @@ describe("Registry", () => { registry.add("second", { cls: What2, schema: second, - enabled: true + enabled: true, }); // @ts-ignore expect(registry.get("second").schema).toEqual(second); @@ -52,7 +52,7 @@ describe("Registry", () => { // @ts-expect-error cls: NotAllowed, schema: third, - enabled: true + enabled: true, }); // @ts-ignore expect(registry.get("third").schema).toEqual(third); @@ -62,7 +62,7 @@ describe("Registry", () => { cls: What, // @ts-expect-error schema: fourth, - enabled: true + enabled: true, }); // @ts-ignore expect(registry.get("fourth").schema).toEqual(fourth); @@ -75,7 +75,7 @@ describe("Registry", () => { return { cls: a, schema: a.prototype.getType(), - enabled: true + enabled: true, }; }); diff --git a/app/__test__/core/cache/CloudflareKvCache.native-spec.ts b/app/__test__/core/cache/CloudflareKvCache.native-spec.ts index 360bc7d..d5f0812 100644 --- a/app/__test__/core/cache/CloudflareKvCache.native-spec.ts +++ b/app/__test__/core/cache/CloudflareKvCache.native-spec.ts @@ -4,7 +4,7 @@ import { after, beforeEach, describe, test } from "node:test"; import { Miniflare } from "miniflare"; import { CloudflareKVCacheItem, - CloudflareKVCachePool + CloudflareKVCachePool, } from "../../../src/core/cache/adapters/CloudflareKvCache"; import { runTests } from "./cache-test-suite"; @@ -26,7 +26,7 @@ describe("CloudflareKv", async () => { mf = new Miniflare({ modules: true, script: "export default { async fetch() { return new Response(null); } }", - kvNamespaces: ["TEST"] + kvNamespaces: ["TEST"], }); const kv = await mf.getKVNamespace("TEST"); return new CloudflareKVCachePool(kv as any); @@ -45,10 +45,10 @@ describe("CloudflareKv", async () => { }, toBeUndefined() { assert.equal(actual, undefined); - } + }, }; - } - } + }, + }, }); after(async () => { diff --git a/app/__test__/core/cache/MemoryCache.spec.ts b/app/__test__/core/cache/MemoryCache.spec.ts index 051663a..d78a5d1 100644 --- a/app/__test__/core/cache/MemoryCache.spec.ts +++ b/app/__test__/core/cache/MemoryCache.spec.ts @@ -9,7 +9,7 @@ describe("MemoryCache", () => { tester: { test, beforeEach, - expect - } + expect, + }, }); }); diff --git a/app/__test__/core/crypto.spec.ts b/app/__test__/core/crypto.spec.ts index 238b9e4..3edbcd4 100644 --- a/app/__test__/core/crypto.spec.ts +++ b/app/__test__/core/crypto.spec.ts @@ -4,7 +4,7 @@ import { checksum, hash } from "../../src/core/utils"; describe("crypto", async () => { test("sha256", async () => { expect(await hash.sha256("test")).toBe( - "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", ); }); test("sha1", async () => { diff --git a/app/__test__/core/object/SchemaObject.spec.ts b/app/__test__/core/object/SchemaObject.spec.ts index 01db1c7..0c745e4 100644 --- a/app/__test__/core/object/SchemaObject.spec.ts +++ b/app/__test__/core/object/SchemaObject.spec.ts @@ -8,8 +8,8 @@ describe("SchemaObject", async () => { Type.Object({ a: Type.String({ default: "b" }) }), { a: "test" }, { - forceParse: true - } + forceParse: true, + }, ); expect(m.get()).toEqual({ a: "test" }); @@ -30,14 +30,14 @@ describe("SchemaObject", async () => { b: Type.Object( { c: Type.String({ default: "d" }), - e: Type.String({ default: "f" }) + e: Type.String({ default: "f" }), }, - { default: {} } - ) + { default: {} }, + ), }, - { default: {}, additionalProperties: false } - ) - }) + { default: {}, additionalProperties: false }, + ), + }), ); expect(m.get()).toEqual({ s: { a: "b", b: { c: "d", e: "f" } } }); @@ -59,8 +59,8 @@ describe("SchemaObject", async () => { test("patch array", async () => { const m = new SchemaObject( Type.Object({ - methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }) - }) + methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }), + }), ); expect(m.get()).toEqual({ methods: ["GET", "PATCH"] }); @@ -81,14 +81,14 @@ describe("SchemaObject", async () => { a: Type.String({ default: "b" }), b: Type.Object( { - c: Type.String({ default: "d" }) + c: Type.String({ default: "d" }), }, - { default: {} } - ) + { default: {} }, + ), }, - { default: {} } - ) - }) + { default: {} }, + ), + }), ); expect(m.get()).toEqual({ s: { a: "b", b: { c: "d" } } }); @@ -108,8 +108,8 @@ describe("SchemaObject", async () => { test("set", async () => { const m = new SchemaObject( Type.Object({ - methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }) - }) + methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }), + }), ); expect(m.get()).toEqual({ methods: ["GET", "PATCH"] }); @@ -125,7 +125,7 @@ describe("SchemaObject", async () => { let result: any; const m = new SchemaObject( Type.Object({ - methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }) + methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }), }), undefined, { @@ -133,8 +133,8 @@ describe("SchemaObject", async () => { await new Promise((r) => setTimeout(r, 10)); called = true; result = config; - } - } + }, + }, ); await m.set({ methods: ["GET", "POST"] }); @@ -146,7 +146,7 @@ describe("SchemaObject", async () => { let called = false; const m = new SchemaObject( Type.Object({ - methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }) + methods: Type.Array(Type.String(), { default: ["GET", "PATCH"] }), }), undefined, { @@ -155,8 +155,8 @@ describe("SchemaObject", async () => { called = true; to.methods.push("OPTIONS"); return to; - } - } + }, + }, ); const result = await m.set({ methods: ["GET", "POST"] }); @@ -168,7 +168,7 @@ describe("SchemaObject", async () => { test("throwIfRestricted", async () => { const m = new SchemaObject(Type.Object({}), undefined, { - restrictPaths: ["a.b"] + restrictPaths: ["a.b"], }); expect(() => m.throwIfRestricted("a.b")).toThrow(); @@ -185,18 +185,18 @@ describe("SchemaObject", async () => { a: Type.String({ default: "b" }), b: Type.Object( { - c: Type.String({ default: "d" }) + c: Type.String({ default: "d" }), }, - { default: {} } - ) + { default: {} }, + ), }, - { default: {} } - ) + { default: {} }, + ), }), undefined, { - restrictPaths: ["s.b"] - } + restrictPaths: ["s.b"], + }, ); expect(m.patch("s.b.c", "e")).rejects.toThrow(); @@ -217,33 +217,33 @@ describe("SchemaObject", async () => { additionalProperties: Type.Object({ type: Type.String(), config: Type.Optional( - Type.Object({}, { additionalProperties: Type.String() }) - ) - }) - } + Type.Object({}, { additionalProperties: Type.String() }), + ), + }), + }, ), - config: Type.Optional(Type.Object({}, { additionalProperties: Type.String() })) - }) - } - ) + config: Type.Optional(Type.Object({}, { additionalProperties: Type.String() })), + }), + }, + ), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); test("patch safe object, overwrite", async () => { const data = { entities: { some: { fields: { - a: { type: "string", config: { some: "thing" } } - } - } - } + a: { type: "string", config: { some: "thing" } }, + }, + }, + }, }; const m = new SchemaObject(dataEntitiesSchema, data, { forceParse: true, - overwritePaths: [/^entities\..*\.fields\..*\.config/] + overwritePaths: [/^entities\..*\.fields\..*\.config/], }); await m.patch("entities.some.fields.a", { type: "string", config: { another: "one" } }); @@ -252,10 +252,10 @@ describe("SchemaObject", async () => { entities: { some: { fields: { - a: { type: "string", config: { another: "one" } } - } - } - } + a: { type: "string", config: { another: "one" } }, + }, + }, + }, }); }); @@ -265,22 +265,22 @@ describe("SchemaObject", async () => { users: { fields: { email: { type: "string" }, - password: { type: "string" } - } - } - } + password: { type: "string" }, + }, + }, + }, }; const m = new SchemaObject(dataEntitiesSchema, data, { forceParse: true, - overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/] + overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/], }); await m.patch("entities.test", { fields: { content: { - type: "text" - } - } + type: "text", + }, + }, }); expect(m.get()).toEqual({ @@ -288,17 +288,17 @@ describe("SchemaObject", async () => { users: { fields: { email: { type: "string" }, - password: { type: "string" } - } + password: { type: "string" }, + }, }, test: { fields: { content: { - type: "text" - } - } - } - } + type: "text", + }, + }, + }, + }, }); }); @@ -308,14 +308,14 @@ describe("SchemaObject", async () => { users: { fields: { email: { type: "string" }, - password: { type: "string" } - } - } - } + password: { type: "string" }, + }, + }, + }, }; const m = new SchemaObject(dataEntitiesSchema, data, { forceParse: true, - overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/] + overwritePaths: [/^entities\..*\.fields\..*\.config\.html_config$/], }); expect(m.patch("desc", "entities.users.config.sort_dir")).rejects.toThrow(); @@ -323,13 +323,13 @@ describe("SchemaObject", async () => { await m.patch("entities.test", { fields: { content: { - type: "text" - } - } + type: "text", + }, + }, }); await m.patch("entities.users.config", { - sort_dir: "desc" + sort_dir: "desc", }); expect(m.get()).toEqual({ @@ -337,20 +337,20 @@ describe("SchemaObject", async () => { users: { fields: { email: { type: "string" }, - password: { type: "string" } + password: { type: "string" }, }, config: { - sort_dir: "desc" - } + sort_dir: "desc", + }, }, test: { fields: { content: { - type: "text" - } - } - } - } + type: "text", + }, + }, + }, + }, }); }); }); diff --git a/app/__test__/core/object/diff.test.ts b/app/__test__/core/object/diff.test.ts index b6ac6e4..d753880 100644 --- a/app/__test__/core/object/diff.test.ts +++ b/app/__test__/core/object/diff.test.ts @@ -13,8 +13,8 @@ describe("diff", () => { t: "a", p: ["b"], o: undefined, - n: 2 - } + n: 2, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -35,8 +35,8 @@ describe("diff", () => { t: "r", p: ["b"], o: 2, - n: undefined - } + n: undefined, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -57,8 +57,8 @@ describe("diff", () => { t: "e", p: ["a"], o: 1, - n: 2 - } + n: 2, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -79,8 +79,8 @@ describe("diff", () => { t: "e", p: ["a", "b"], o: 1, - n: 2 - } + n: 2, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -101,14 +101,14 @@ describe("diff", () => { t: "e", p: ["a", 1], o: 2, - n: 4 + n: 4, }, { t: "a", p: ["a", 3], o: undefined, - n: 5 - } + n: 5, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -129,20 +129,20 @@ describe("diff", () => { t: "a", p: ["a", 0], o: undefined, - n: 1 + n: 1, }, { t: "a", p: ["a", 1], o: undefined, - n: 2 + n: 2, }, { t: "a", p: ["a", 2], o: undefined, - n: 3 - } + n: 3, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -163,14 +163,14 @@ describe("diff", () => { t: "e", p: ["a", 1], o: 2, - n: 3 + n: 3, }, { t: "r", p: ["a", 2], o: 3, - n: undefined - } + n: undefined, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -183,14 +183,14 @@ describe("diff", () => { it("should handle complex nested changes", () => { const oldObj = { a: { - b: [1, 2, { c: 3 }] - } + b: [1, 2, { c: 3 }], + }, }; const newObj = { a: { - b: [1, 2, { c: 4 }, 5] - } + b: [1, 2, { c: 4 }, 5], + }, }; const diffs = diff(oldObj, newObj); @@ -200,14 +200,14 @@ describe("diff", () => { t: "e", p: ["a", "b", 2, "c"], o: 3, - n: 4 + n: 4, }, { t: "a", p: ["a", "b", 3], o: undefined, - n: 5 - } + n: 5, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -228,14 +228,14 @@ describe("diff", () => { t: "e", p: ["a"], o: undefined, - n: null + n: null, }, { t: "e", p: ["b"], o: null, - n: undefined - } + n: undefined, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -256,8 +256,8 @@ describe("diff", () => { t: "e", p: ["a"], o: 1, - n: "1" - } + n: "1", + }, ]); const appliedObj = apply(oldObj, diffs); @@ -278,14 +278,14 @@ describe("diff", () => { t: "r", p: ["b"], o: 2, - n: undefined + n: undefined, }, { t: "a", p: ["c"], o: undefined, - n: 3 - } + n: 3, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -306,8 +306,8 @@ describe("diff", () => { t: "e", p: ["a"], o: [1, 2, 3], - n: { b: 4 } - } + n: { b: 4 }, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -328,8 +328,8 @@ describe("diff", () => { t: "e", p: ["a"], o: { b: 1 }, - n: 2 - } + n: 2, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -350,14 +350,14 @@ describe("diff", () => { t: "r", p: ["a"], o: 1, - n: undefined + n: undefined, }, { t: "a", p: ["b"], o: undefined, - n: 2 - } + n: 2, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -408,8 +408,8 @@ describe("diff", () => { t: "a", p: ["a"], o: undefined, - n: 1 - } + n: 1, + }, ]); const appliedObj = apply(oldObj, diffs); @@ -430,8 +430,8 @@ describe("diff", () => { t: "r", p: ["a"], o: 1, - n: undefined - } + n: undefined, + }, ]); const appliedObj = apply(oldObj, diffs); diff --git a/app/__test__/core/object/object-query.spec.ts b/app/__test__/core/object/object-query.spec.ts index a6940a9..70ea70c 100644 --- a/app/__test__/core/object/object-query.spec.ts +++ b/app/__test__/core/object/object-query.spec.ts @@ -9,7 +9,7 @@ describe("object-query", () => { test("validates", async () => { const converted = convert({ - name: { $eq: "ch" } + name: { $eq: "ch" }, }); validate(converted, { name: "Michael" }); }); @@ -31,7 +31,7 @@ describe("object-query", () => { [{ val: { $notnull: 1 } }, { val: null }, false], [{ val: { $regex: ".*" } }, { val: "test" }, true], [{ val: { $regex: /^t.*/ } }, { val: "test" }, true], - [{ val: { $regex: /^b.*/ } }, { val: "test" }, false] + [{ val: { $regex: /^b.*/ } }, { val: "test" }, false], ]; for (const [query, object, expected] of tests) { @@ -55,10 +55,10 @@ describe("object-query", () => { [ { $or: { val1: { $eq: "foo" }, val2: { $eq: "bar" } } }, { val1: "foo", val2: "bar" }, - true + true, ], [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 1 }, true], - [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 3 }, false] + [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, { val1: 3 }, false], ]; for (const [query, object, expected] of tests) { diff --git a/app/__test__/core/utils.spec.ts b/app/__test__/core/utils.spec.ts index 8b8a185..db3c967 100644 --- a/app/__test__/core/utils.spec.ts +++ b/app/__test__/core/utils.spec.ts @@ -16,7 +16,7 @@ describe("Core Utils", async () => { expect(result).toEqual([ { key: "a", value: 1 }, { key: "b", value: 2 }, - { key: "c", value: 3 } + { key: "c", value: 3 }, ]); }); @@ -51,7 +51,7 @@ describe("Core Utils", async () => { const obj = utils.headersToObject(headers); expect(obj).toEqual({ "content-type": "application/json", - authorization: "Bearer 123" + authorization: "Bearer 123", }); }); @@ -82,7 +82,7 @@ describe("Core Utils", async () => { file: new File([""], "file.txt"), stream: new ReadableStream(), arrayBuffer: new ArrayBuffer(10), - arrayBufferView: new Uint8Array(new ArrayBuffer(10)) + arrayBufferView: new Uint8Array(new ArrayBuffer(10)), }; const fns = [ @@ -90,7 +90,7 @@ describe("Core Utils", async () => { [utils.isBlob, "blob", ["stream", "arrayBuffer", "arrayBufferView"]], [utils.isFile, "file", ["stream", "arrayBuffer", "arrayBufferView"]], [utils.isArrayBuffer, "arrayBuffer"], - [utils.isArrayBufferView, "arrayBufferView"] + [utils.isArrayBufferView, "arrayBufferView"], ] as const; const additional = [0, 0.0, "", null, undefined, {}, []]; @@ -116,10 +116,10 @@ describe("Core Utils", async () => { const name = "test.json"; const text = "attachment; filename=" + name; const headers = new Headers({ - "Content-Disposition": text + "Content-Disposition": text, }); const request = new Request("http://example.com", { - headers + headers, }); expect(utils.getContentName(text)).toBe(name); @@ -166,7 +166,7 @@ describe("Core Utils", async () => { [{ a: 1, b: 2, c: 3 }, ["b"], { a: 1, c: 3 }], [{ a: 1, b: 2, c: 3 }, ["c"], { a: 1, b: 2 }], [{ a: 1, b: 2, c: 3 }, ["a", "b"], { c: 3 }], - [{ a: 1, b: 2, c: 3 }, ["a", "b", "c"], {}] + [{ a: 1, b: 2, c: 3 }, ["a", "b", "c"], {}], ] as [object, string[], object][]; for (const [obj, keys, expected] of objects) { @@ -197,9 +197,9 @@ describe("Core Utils", async () => { new Map([["a", 1]]), new Map([ ["a", 1], - ["b", 2] + ["b", 2], ]), - false + false, ], [{ a: 1 }, { a: 1 }, true], [{ a: 1 }, { a: 2 }, false], @@ -220,7 +220,7 @@ describe("Core Utils", async () => { [[1, 2, 3], [1, 2, 3, 4], false], [[{ a: 1 }], [{ a: 1 }], true], [[{ a: 1 }], [{ a: 2 }], false], - [[{ a: 1 }], [{ b: 1 }], false] + [[{ a: 1 }], [{ b: 1 }], false], ] as [any, any, boolean][]; for (const [a, b, expected] of objects) { @@ -236,7 +236,7 @@ describe("Core Utils", async () => { [{ a: { b: 1 } }, "a.b", 1], [{ a: { b: 1 } }, "a.b.c", null, null], [{ a: { b: 1 } }, "a.b.c", 1, 1], - [[[1]], "0.0", 1] + [[[1]], "0.0", 1], ] as [object, string, any, any][]; for (const [obj, path, expected, defaultValue] of tests) { diff --git a/app/__test__/data/DataController.spec.ts b/app/__test__/data/DataController.spec.ts index cec2022..21ae226 100644 --- a/app/__test__/data/DataController.spec.ts +++ b/app/__test__/data/DataController.spec.ts @@ -9,7 +9,7 @@ import { ManyToOneRelation, type MutatorResponse, type RepositoryResponse, - TextField + TextField, } from "../../src/data"; import { DataController } from "../../src/data/api/DataController"; import { dataConfigSchema } from "../../src/data/data-schema"; @@ -35,17 +35,17 @@ describe("[data] DataController", async () => { meta: { total: 0, count: 0, - items: 0 - } + items: 0, + }, }); expect(res).toEqual({ meta: { total: 0, count: 0, - items: 0 + items: 0, }, - data: [] + data: [], }); }); @@ -59,22 +59,22 @@ describe("[data] DataController", async () => { data: [] as any, sql: "", parameters: [] as any, - result: [] as any + result: [] as any, }); expect(res).toEqual({ - data: [] + data: [], }); }); describe("getController", async () => { const users = new Entity("users", [ new TextField("name", { required: true }), - new TextField("bio") + new TextField("bio"), ]); const posts = new Entity("posts", [new TextField("content")]); const em = new EntityManager([users, posts], dummyConnection, [ - new ManyToOneRelation(posts, users) + new ManyToOneRelation(posts, users), ]); await em.schema().sync({ force: true }); @@ -83,12 +83,12 @@ describe("[data] DataController", async () => { users: [ { name: "foo", bio: "bar" }, { name: "bar", bio: null }, - { name: "baz", bio: "!!!" } + { name: "baz", bio: "!!!" }, ], posts: [ { content: "post 1", users_id: 1 }, - { content: "post 2", users_id: 2 } - ] + { content: "post 2", users_id: 2 }, + ], }; const ctx: any = { em, guard: new Guard() }; @@ -118,7 +118,7 @@ describe("[data] DataController", async () => { for await (const _user of fixtures.users) { const res = await app.request("/entity/users", { method: "POST", - body: JSON.stringify(_user) + body: JSON.stringify(_user), }); //console.log("res", { _user }, res); const result = (await res.json()) as MutatorResponse; @@ -133,7 +133,7 @@ describe("[data] DataController", async () => { for await (const _post of fixtures.posts) { const res = await app.request("/entity/posts", { method: "POST", - body: JSON.stringify(_post) + body: JSON.stringify(_post), }); const result = (await res.json()) as MutatorResponse; const { id, ...data } = result.data as any; @@ -159,11 +159,11 @@ describe("[data] DataController", async () => { const res = await app.request("/entity/users/query", { method: "POST", headers: { - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ - where: { bio: { $isnull: 1 } } - }) + where: { bio: { $isnull: 1 } }, + }), }); const data = (await res.json()) as RepositoryResponse; @@ -199,7 +199,7 @@ describe("[data] DataController", async () => { test("/:entity (update one)", async () => { const res = await app.request("/entity/users/3", { method: "PATCH", - body: JSON.stringify({ name: "new name" }) + body: JSON.stringify({ name: "new name" }), }); const { data } = (await res.json()) as MutatorResponse; @@ -221,7 +221,7 @@ describe("[data] DataController", async () => { test("/:entity/:id (delete one)", async () => { const res = await app.request("/entity/posts/2", { - method: "DELETE" + method: "DELETE", }); const { data } = (await res.json()) as RepositoryResponse; expect(data).toEqual({ id: 2, ...fixtures.posts[1] }); diff --git a/app/__test__/data/data-query-impl.spec.ts b/app/__test__/data/data-query-impl.spec.ts index d219bcc..d96247e 100644 --- a/app/__test__/data/data-query-impl.spec.ts +++ b/app/__test__/data/data-query-impl.spec.ts @@ -30,7 +30,7 @@ describe("data-query-impl", () => { [{ val: { $isnull: 0 } }, '"val" is not null', []], [{ val: { $isnull: false } }, '"val" is not null', []], [{ val: { $like: "what" } }, '"val" like ?', ["what"]], - [{ val: { $like: "w*t" } }, '"val" like ?', ["w%t"]] + [{ val: { $like: "w*t" } }, '"val" like ?', ["w%t"]], ]; for (const [query, expectedSql, expectedParams] of tests) { @@ -51,22 +51,22 @@ describe("data-query-impl", () => { [ { val1: { $eq: "foo" }, val2: { $eq: "bar" } }, '("val1" = ? and "val2" = ?)', - ["foo", "bar"] + ["foo", "bar"], ], [ { val1: { $eq: "foo" }, val2: { $eq: "bar" } }, '("val1" = ? and "val2" = ?)', - ["foo", "bar"] + ["foo", "bar"], ], // or constructs [ { $or: { val1: { $eq: "foo" }, val2: { $eq: "bar" } } }, '("val1" = ? or "val2" = ?)', - ["foo", "bar"] + ["foo", "bar"], ], [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, '("val1" = ? or "val1" = ?)', [1, 2]], - [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, '("val1" = ? or "val1" = ?)', [1, 2]] + [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, '("val1" = ? or "val1" = ?)', [1, 2]], ]; for (const [query, expectedSql, expectedParams] of tests) { @@ -86,7 +86,7 @@ describe("data-query-impl", () => { // or constructs [{ $or: { val1: { $eq: "foo" }, val2: { $eq: "bar" } } }, ["val1", "val2"]], - [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, ["val1"]] + [{ val1: { $eq: 1 }, $or: { val1: { $eq: 2 } } }, ["val1"]], ]; for (const [query, expectedKeys] of tests) { @@ -105,23 +105,23 @@ describe("data-query-impl", () => { posts: { with: { images: { - select: ["id"] - } - } - } - } + select: ["id"], + }, + }, + }, + }, }, { with: { posts: { with: { images: { - select: ["id"] - } - } - } - } - } + select: ["id"], + }, + }, + }, + }, + }, ); // over http diff --git a/app/__test__/data/data.test.ts b/app/__test__/data/data.test.ts index dc8257f..886f2aa 100644 --- a/app/__test__/data/data.test.ts +++ b/app/__test__/data/data.test.ts @@ -5,7 +5,7 @@ import { NumberField, PrimaryField, Repository, - TextField + TextField, } from "../../src/data"; import { getDummyConnection } from "./helper"; @@ -18,14 +18,14 @@ describe("some tests", async () => { const users = new Entity("users", [ new TextField("username", { required: true, default_value: "nobody" }), - new TextField("email", { maxLength: 3 }) + new TextField("email", { maxLength: 3 }), ]); const posts = new Entity("posts", [ new TextField("title"), new TextField("content"), new TextField("created_at"), - new NumberField("likes", { default_value: 0 }) + new NumberField("likes", { default_value: 0 }), ]); const em = new EntityManager([users, posts], connection); @@ -43,7 +43,7 @@ describe("some tests", async () => { });*/ expect(query.sql).toBe( - 'select "users"."id" as "id", "users"."username" as "username", "users"."email" as "email" from "users" where "id" = ? limit ?' + 'select "users"."id" as "id", "users"."username" as "username", "users"."email" as "email" from "users" where "id" = ? limit ?', ); expect(query.parameters).toEqual([1, 1]); expect(query.result).toEqual([]); @@ -53,7 +53,7 @@ describe("some tests", async () => { const query = await em.repository(users).findMany(); expect(query.sql).toBe( - 'select "users"."id" as "id", "users"."username" as "username", "users"."email" as "email" from "users" order by "users"."id" asc limit ? offset ?' + 'select "users"."id" as "id", "users"."username" as "username", "users"."email" as "email" from "users" order by "users"."id" asc limit ? offset ?', ); expect(query.parameters).toEqual([10, 0]); expect(query.result).toEqual([]); @@ -63,7 +63,7 @@ describe("some tests", async () => { const query = await em.repository(posts).findMany(); expect(query.sql).toBe( - 'select "posts"."id" as "id", "posts"."title" as "title", "posts"."content" as "content", "posts"."created_at" as "created_at", "posts"."likes" as "likes" from "posts" order by "posts"."id" asc limit ? offset ?' + 'select "posts"."id" as "id", "posts"."title" as "title", "posts"."content" as "content", "posts"."created_at" as "created_at", "posts"."likes" as "likes" from "posts" order by "posts"."id" asc limit ? offset ?', ); expect(query.parameters).toEqual([10, 0]); expect(query.result).toEqual([]); @@ -74,7 +74,7 @@ describe("some tests", async () => { new Entity("users", [ new TextField("username"), new TextField("email"), - new TextField("email") // not throwing, it's just being ignored + new TextField("email"), // not throwing, it's just being ignored ]); }).toBeDefined(); @@ -83,7 +83,7 @@ describe("some tests", async () => { new TextField("username"), new TextField("email"), // field config differs, will throw - new TextField("email", { required: true }) + new TextField("email", { required: true }), ]); }).toThrow(); @@ -91,7 +91,7 @@ describe("some tests", async () => { new Entity("users", [ new PrimaryField(), new TextField("username"), - new TextField("email") + new TextField("email"), ]); }).toBeDefined(); }); diff --git a/app/__test__/data/helper.ts b/app/__test__/data/helper.ts index dc4465b..df1ed88 100644 --- a/app/__test__/data/helper.ts +++ b/app/__test__/data/helper.ts @@ -16,7 +16,7 @@ export function getDummyDatabase(memory: boolean = true): { afterAllCleanup: async () => { if (!memory) await unlink(DB_NAME); return true; - } + }, }; } @@ -26,7 +26,7 @@ export function getDummyConnection(memory: boolean = true) { return { dummyConnection, - afterAllCleanup + afterAllCleanup, }; } diff --git a/app/__test__/data/mutation.relation.test.ts b/app/__test__/data/mutation.relation.test.ts index 32b8749..57124b2 100644 --- a/app/__test__/data/mutation.relation.test.ts +++ b/app/__test__/data/mutation.relation.test.ts @@ -6,7 +6,7 @@ import { ManyToOneRelation, NumberField, SchemaManager, - TextField + TextField, } from "../../src/data"; import { getDummyConnection } from "./helper"; @@ -21,7 +21,7 @@ describe("Mutator relation", async () => { const posts = new Entity("posts", [ new TextField("title"), new TextField("content", { default_value: "..." }), - new NumberField("count", { default_value: 0 }) + new NumberField("count", { default_value: 0 }), ]); const users = new Entity("users", [new TextField("username")]); @@ -44,7 +44,7 @@ describe("Mutator relation", async () => { expect(em.mutator(posts).insertOne({ title: "post2", users_id: 10 })).rejects.toThrow(); expect( - em.mutator(posts).insertOne({ title: "post2", users_id: data.id }) + em.mutator(posts).insertOne({ title: "post2", users_id: data.id }), ).resolves.toBeDefined(); }); }); diff --git a/app/__test__/data/mutation.simple.test.ts b/app/__test__/data/mutation.simple.test.ts index ac19935..8fb0a33 100644 --- a/app/__test__/data/mutation.simple.test.ts +++ b/app/__test__/data/mutation.simple.test.ts @@ -14,7 +14,7 @@ describe("Mutator simple", async () => { const items = new Entity("items", [ new TextField("label", { required: true, minLength: 1 }), - new NumberField("count", { default_value: 0 }) + new NumberField("count", { default_value: 0 }), ]); const em = new EntityManager([items], connection); @@ -29,11 +29,11 @@ describe("Mutator simple", async () => { test("insert single row", async () => { const mutation = await em.mutator(items).insertOne({ label: "test", - count: 1 + count: 1, }); expect(mutation.sql).toBe( - 'insert into "items" ("count", "label") values (?, ?) returning "id", "label", "count"' + 'insert into "items" ("count", "label") values (?, ?) returning "id", "label", "count"', ); expect(mutation.data).toEqual({ id: 1, label: "test", count: 1 }); @@ -41,8 +41,8 @@ describe("Mutator simple", async () => { limit: 1, sort: { by: "id", - dir: "desc" - } + dir: "desc", + }, }); expect(query.result).toEqual([{ id: 1, label: "test", count: 1 }]); @@ -53,18 +53,18 @@ describe("Mutator simple", async () => { limit: 1, sort: { by: "id", - dir: "desc" - } + dir: "desc", + }, }); const id = query.data![0].id as number; const mutation = await em.mutator(items).updateOne(id, { label: "new label", - count: 100 + count: 100, }); expect(mutation.sql).toBe( - 'update "items" set "label" = ?, "count" = ? where "id" = ? returning "id", "label", "count"' + 'update "items" set "label" = ?, "count" = ? where "id" = ? returning "id", "label", "count"', ); expect(mutation.data).toEqual({ id, label: "new label", count: 100 }); }); @@ -74,15 +74,15 @@ describe("Mutator simple", async () => { limit: 1, sort: { by: "id", - dir: "desc" - } + dir: "desc", + }, }); const id = query.data![0].id as number; const mutation = await em.mutator(items).deleteOne(id); expect(mutation.sql).toBe( - 'delete from "items" where "id" = ? returning "id", "label", "count"' + 'delete from "items" where "id" = ? returning "id", "label", "count"', ); expect(mutation.data).toEqual({ id, label: "new label", count: 100 }); @@ -94,7 +94,7 @@ describe("Mutator simple", async () => { const incompleteCreate = async () => await em.mutator(items).insertOne({ //label: "test", - count: 1 + count: 1, }); expect(incompleteCreate()).rejects.toThrow(); @@ -104,7 +104,7 @@ describe("Mutator simple", async () => { const invalidCreate1 = async () => await em.mutator(items).insertOne({ label: 111, // this should work - count: "1" // this should fail + count: "1", // this should fail }); expect(invalidCreate1()).rejects.toThrow(TransformPersistFailedException); @@ -112,7 +112,7 @@ describe("Mutator simple", async () => { const invalidCreate2 = async () => await em.mutator(items).insertOne({ label: "", // this should fail - count: 1 + count: 1, }); expect(invalidCreate2()).rejects.toThrow(TransformPersistFailedException); @@ -152,27 +152,27 @@ describe("Mutator simple", async () => { await em.mutator(items).updateWhere( { count: 2 }, { - count: 10 - } + count: 10, + }, ); expect((await em.repository(items).findMany()).data).toEqual([ { id: 6, label: "update", count: 1 }, { id: 7, label: "update too", count: 1 }, - { id: 8, label: "keep", count: 0 } + { id: 8, label: "keep", count: 0 }, ]); // expect 2 to be updated await em.mutator(items).updateWhere( { count: 2 }, { - count: 1 - } + count: 1, + }, ); expect((await em.repository(items).findMany()).data).toEqual([ { id: 6, label: "update", count: 2 }, { id: 7, label: "update too", count: 2 }, - { id: 8, label: "keep", count: 0 } + { id: 8, label: "keep", count: 0 }, ]); }); diff --git a/app/__test__/data/polymorphic.test.ts b/app/__test__/data/polymorphic.test.ts index 44df2de..88a0b8b 100644 --- a/app/__test__/data/polymorphic.test.ts +++ b/app/__test__/data/polymorphic.test.ts @@ -23,23 +23,23 @@ describe("Polymorphic", async () => { source: "categories", target: "media", config: { - mappedBy: "image" - } + mappedBy: "image", + }, }); // media should not see categories expect(em.relationsOf(media.name).map((r) => r.toJSON())).toEqual([]); // it's important that media cannot access categories expect(em.relations.targetRelationsOf(categories).map((r) => r.source.entity.name)).toEqual( - [] + [], ); expect(em.relations.targetRelationsOf(media).map((r) => r.source.entity.name)).toEqual([]); expect(em.relations.sourceRelationsOf(categories).map((r) => r.target.entity.name)).toEqual([ - "media" + "media", ]); expect(em.relations.sourceRelationsOf(categories).map((r) => r.target.reference)).toEqual([ - "image" + "image", ]); expect(em.relations.sourceRelationsOf(media).map((r) => r.target.entity.name)).toEqual([]); @@ -48,7 +48,7 @@ describe("Polymorphic", async () => { "id", "path", "reference", - "entity_id" + "entity_id", ]); expect(media.getSelect()).toEqual(["id", "path"]); }); @@ -60,7 +60,7 @@ describe("Polymorphic", async () => { const entities = [media, categories]; const single = new PolymorphicRelation(categories, media, { mappedBy: "single", - targetCardinality: 1 + targetCardinality: 1, }); const multiple = new PolymorphicRelation(categories, media, { mappedBy: "multiple" }); @@ -71,17 +71,17 @@ describe("Polymorphic", async () => { // it's important that media cannot access categories expect(em.relations.targetRelationsOf(categories).map((r) => r.source.entity.name)).toEqual( - [] + [], ); expect(em.relations.targetRelationsOf(media).map((r) => r.source.entity.name)).toEqual([]); expect(em.relations.sourceRelationsOf(categories).map((r) => r.target.entity.name)).toEqual([ "media", - "media" + "media", ]); expect(em.relations.sourceRelationsOf(categories).map((r) => r.target.reference)).toEqual([ "single", - "multiple" + "multiple", ]); expect(em.relations.sourceRelationsOf(media).map((r) => r.target.entity.name)).toEqual([]); @@ -90,7 +90,7 @@ describe("Polymorphic", async () => { "id", "path", "reference", - "entity_id" + "entity_id", ]); }); }); diff --git a/app/__test__/data/prototype.test.ts b/app/__test__/data/prototype.test.ts index 8b12aa4..83f0de1 100644 --- a/app/__test__/data/prototype.test.ts +++ b/app/__test__/data/prototype.test.ts @@ -12,7 +12,7 @@ import { NumberField, OneToOneRelation, PolymorphicRelation, - TextField + TextField, } from "../../src/data"; import { DummyConnection } from "../../src/data/connection/DummyConnection"; import { @@ -31,7 +31,7 @@ import { medium, number, relation, - text + text, } from "../../src/data/prototype"; import { MediaField } from "../../src/media/MediaField"; @@ -54,7 +54,7 @@ describe("prototype", () => { name: text(), bio: text(), age: number(), - some: number() + some: number(), }); type db = { users: Schema; @@ -70,7 +70,7 @@ describe("prototype", () => { name: text({ default_value: "hello" }).required(), bio: text(), age: number(), - some: number().required() + some: number().required(), }); const obj: InsertSchema = { name: "yo", some: 1 }; @@ -83,12 +83,12 @@ describe("prototype", () => { new TextField("title", { required: true }), new TextField("content"), new DateField("created_at", { - type: "datetime" + type: "datetime", }), // @ts-ignore new MediaField("images", { entity: "posts" }), // @ts-ignore - new MediaField("cover", { entity: "posts", max_items: 1 }) + new MediaField("cover", { entity: "posts", max_items: 1 }), ]); const posts2 = entity("posts", { @@ -96,7 +96,7 @@ describe("prototype", () => { content: text(), created_at: datetime(), images: media(), - cover: medium() + cover: medium(), }); type Posts = Schema; @@ -117,11 +117,11 @@ describe("prototype", () => { type: "objects", values: [ { value: "active", label: "Active" }, - { value: "inactive", label: "Not active" } - ] - } + { value: "inactive", label: "Not active" }, + ], + }, }), - new JsonField("json") + new JsonField("json"), ]); const test2 = entity("test", { @@ -134,10 +134,10 @@ describe("prototype", () => { status: enumm<"active" | "inactive">({ enum: [ { value: "active", label: "Active" }, - { value: "inactive", label: "Not active" } - ] + { value: "inactive", label: "Not active" }, + ], }), - json: json<{ some: number }>() + json: json<{ some: number }>(), }); expect(test.toJSON()).toEqual(test2.toJSON()); @@ -161,12 +161,12 @@ describe("prototype", () => { // category has single image new PolymorphicRelation(categories, _media, { mappedBy: "image", - targetCardinality: 1 + targetCardinality: 1, }), // post has multiple images new PolymorphicRelation(posts, _media, { mappedBy: "images" }), - new PolymorphicRelation(posts, _media, { mappedBy: "cover", targetCardinality: 1 }) + new PolymorphicRelation(posts, _media, { mappedBy: "cover", targetCardinality: 1 }), ]; const relations2 = [ @@ -180,7 +180,7 @@ describe("prototype", () => { relation(categories).polyToOne(_media, { mappedBy: "image" }), relation(posts).polyToMany(_media, { mappedBy: "images" }), - relation(posts).polyToOne(_media, { mappedBy: "cover" }) + relation(posts).polyToOne(_media, { mappedBy: "cover" }), ]; expect(relations.map((r) => r.toJSON())).toEqual(relations2.map((r) => r.toJSON())); @@ -194,21 +194,21 @@ describe("prototype", () => { posts, categories, { - connectionTableMappedName: "custom" + connectionTableMappedName: "custom", }, - [new TextField("description")] + [new TextField("description")], ); const fields = { - description: text() + description: text(), }; let o: FieldSchema; const rel2 = relation(posts).manyToMany( categories, { - connectionTableMappedName: "custom" + connectionTableMappedName: "custom", }, - fields + fields, ); expect(rel.toJSON()).toEqual(rel2.toJSON()); @@ -216,11 +216,11 @@ describe("prototype", () => { test("devexample", async () => { const users = entity("users", { - username: text() + username: text(), }); const comments = entity("comments", { - content: text() + content: text(), }); const posts = entity("posts", { @@ -228,17 +228,17 @@ describe("prototype", () => { content: text(), created_at: datetime(), images: media(), - cover: medium() + cover: medium(), }); const categories = entity("categories", { name: text(), description: text(), - image: medium() + image: medium(), }); const settings = entity("settings", { - theme: text() + theme: text(), }); const test = entity("test", { @@ -251,10 +251,10 @@ describe("prototype", () => { status: enumm<"active" | "inactive">({ enum: [ { value: "active", label: "Active" }, - { value: "inactive", label: "Not active" } - ] + { value: "inactive", label: "Not active" }, + ], }), - json: json<{ some: number }>() + json: json<{ some: number }>(), }); const _media = entity("media", {}); @@ -270,7 +270,7 @@ describe("prototype", () => { relation(users).oneToOne(settings), relation(comments).manyToOne(users, { required: true }), - relation(comments).manyToOne(posts, { required: true }) + relation(comments).manyToOne(posts, { required: true }), ]; const obj: Schema = {} as any; @@ -281,12 +281,12 @@ describe("prototype", () => { { posts: entity("posts", { name: text(), slug: text().required() }), comments: entity("comments", { some: text() }), - users: entity("users", { email: text() }) + users: entity("users", { email: text() }), }, ({ relation, index }, { posts, comments, users }) => { relation(posts).manyToOne(comments).manyToOne(users); index(posts).on(["name"]).on(["slug"], true); - } + }, ); type LocalDb = (typeof _em)["DB"]; @@ -294,7 +294,7 @@ describe("prototype", () => { const es = [ new Entity("posts", [new TextField("name"), new TextField("slug", { required: true })]), new Entity("comments", [new TextField("some")]), - new Entity("users", [new TextField("email")]) + new Entity("users", [new TextField("email")]), ]; const _em2 = new EntityManager( es, @@ -302,8 +302,8 @@ describe("prototype", () => { [new ManyToOneRelation(es[0], es[1]), new ManyToOneRelation(es[0], es[2])], [ new EntityIndex(es[0], [es[0].field("name")!]), - new EntityIndex(es[0], [es[0].field("slug")!], true) - ] + new EntityIndex(es[0], [es[0].field("slug")!], true), + ], ); // @ts-ignore diff --git a/app/__test__/data/relations.test.ts b/app/__test__/data/relations.test.ts index 886d02c..b4ff708 100644 --- a/app/__test__/data/relations.test.ts +++ b/app/__test__/data/relations.test.ts @@ -6,7 +6,7 @@ import { ManyToOneRelation, OneToOneRelation, PolymorphicRelation, - RelationField + RelationField, } from "../../src/data/relations"; import { getDummyConnection } from "./helper"; @@ -22,7 +22,7 @@ describe("Relations", async () => { const r1 = new RelationField("users_id", { reference: "users", target: "users", - target_field: "id" + target_field: "id", }); const sql1 = schema @@ -31,14 +31,14 @@ describe("Relations", async () => { .compile().sql; expect(sql1).toBe( - 'create table "posts" ("users_id" integer references "users" ("id") on delete set null)' + 'create table "posts" ("users_id" integer references "users" ("id") on delete set null)', ); //const r2 = new RelationField(new Entity("users"), "author"); const r2 = new RelationField("author_id", { reference: "author", target: "users", - target_field: "id" + target_field: "id", }); const sql2 = schema @@ -47,7 +47,7 @@ describe("Relations", async () => { .compile().sql; expect(sql2).toBe( - 'create table "posts" ("author_id" integer references "users" ("id") on delete set null)' + 'create table "posts" ("author_id" integer references "users" ("id") on delete set null)', ); }); @@ -57,7 +57,7 @@ describe("Relations", async () => { reference: "users", target: "users", target_field: "id", - required: true + required: true, }); expect(r1.isRequired()).toBeTrue(); }); @@ -66,8 +66,8 @@ describe("Relations", async () => { const users = new Entity("users", [new TextField("username")]); const posts = new Entity("posts", [ new TextField("title", { - maxLength: 2 - }) + maxLength: 2, + }), ]); const entities = [users, posts]; @@ -122,7 +122,7 @@ describe("Relations", async () => { .selectFrom(users.name) .select((eb) => postAuthorRel.buildWith(users, "posts")(eb).as("posts")); expect(selectPostsFromUsers.compile().sql).toBe( - 'select (select from "posts" as "posts" where "posts"."author_id" = "users"."id") as "posts" from "users"' + 'select (select from "posts" as "posts" where "posts"."author_id" = "users"."id") as "posts" from "users"', ); expect(postAuthorRel!.getField()).toBeInstanceOf(RelationField); const userObj = { id: 1, username: "test" }; @@ -142,7 +142,7 @@ describe("Relations", async () => { .select((eb) => postAuthorRel.buildWith(posts, "author")(eb).as("author")); expect(selectUsersFromPosts.compile().sql).toBe( - 'select (select from "users" as "author" where "author"."id" = "posts"."author_id" limit ?) as "author" from "posts"' + 'select (select from "users" as "author" where "author"."id" = "posts"."author_id" limit ?) as "author" from "posts"', ); expect(postAuthorRel.getField()).toBeInstanceOf(RelationField); const postObj = { id: 1, title: "test" }; @@ -158,7 +158,7 @@ describe("Relations", async () => { $detach: false, primary: undefined, cardinality: undefined, - relation_type: "n:1" + relation_type: "n:1", }); expect(postAuthorRel!.helper(posts.name)!.getMutationInfo()).toEqual({ @@ -170,7 +170,7 @@ describe("Relations", async () => { $detach: false, primary: "id", cardinality: 1, - relation_type: "n:1" + relation_type: "n:1", }); /*console.log("ManyToOne (source=posts, target=users)"); @@ -225,7 +225,7 @@ describe("Relations", async () => { $detach: false, primary: "id", cardinality: 1, - relation_type: "1:1" + relation_type: "1:1", }); expect(userSettingRel!.helper(settings.name)!.getMutationInfo()).toEqual({ reference: "users", @@ -236,7 +236,7 @@ describe("Relations", async () => { $detach: false, primary: undefined, cardinality: 1, - relation_type: "1:1" + relation_type: "1:1", }); /*console.log(""); @@ -312,14 +312,14 @@ describe("Relations", async () => { .selectFrom(posts.name) .select((eb) => postCategoriesRel.buildWith(posts)(eb).select("id").as("categories")); expect(selectCategoriesFromPosts.compile().sql).toBe( - 'select (select "id" from "categories" inner join "posts_categories" on "categories"."id" = "posts_categories"."categories_id" where "posts"."id" = "posts_categories"."posts_id" limit ?) as "categories" from "posts"' + 'select (select "id" from "categories" inner join "posts_categories" on "categories"."id" = "posts_categories"."categories_id" where "posts"."id" = "posts_categories"."posts_id" limit ?) as "categories" from "posts"', ); const selectPostsFromCategories = kysely .selectFrom(categories.name) .select((eb) => postCategoriesRel.buildWith(categories)(eb).select("id").as("posts")); expect(selectPostsFromCategories.compile().sql).toBe( - 'select (select "id" from "posts" inner join "posts_categories" on "posts"."id" = "posts_categories"."posts_id" where "categories"."id" = "posts_categories"."categories_id" limit ?) as "posts" from "categories"' + 'select (select "id" from "posts" inner join "posts_categories" on "posts"."id" = "posts_categories"."posts_id" where "categories"."id" = "posts_categories"."categories_id" limit ?) as "posts" from "categories"', ); // mutation info @@ -332,7 +332,7 @@ describe("Relations", async () => { $detach: true, primary: "id", cardinality: undefined, - relation_type: "m:n" + relation_type: "m:n", }); expect(relations[0].helper(categories.name)!.getMutationInfo()).toEqual({ reference: "posts", @@ -343,7 +343,7 @@ describe("Relations", async () => { $detach: false, primary: undefined, cardinality: undefined, - relation_type: "m:n" + relation_type: "m:n", }); /*console.log(""); diff --git a/app/__test__/data/specs/Entity.spec.ts b/app/__test__/data/specs/Entity.spec.ts index 9b66b96..358c106 100644 --- a/app/__test__/data/specs/Entity.spec.ts +++ b/app/__test__/data/specs/Entity.spec.ts @@ -6,7 +6,7 @@ describe("[data] Entity", async () => { new TextField("name", { required: true }), new TextField("description"), new NumberField("age", { fillable: false, default_value: 18 }), - new TextField("hidden", { hidden: true, default_value: "secret" }) + new TextField("hidden", { hidden: true, default_value: "secret" }), ]); test("getSelect", async () => { @@ -17,7 +17,7 @@ describe("[data] Entity", async () => { expect(entity.getFillableFields().map((f) => f.name)).toEqual([ "name", "description", - "hidden" + "hidden", ]); }); @@ -28,7 +28,7 @@ describe("[data] Entity", async () => { test("getDefaultObject", async () => { expect(entity.getDefaultObject()).toEqual({ age: 18, - hidden: "secret" + hidden: "secret", }); }); diff --git a/app/__test__/data/specs/EntityManager.spec.ts b/app/__test__/data/specs/EntityManager.spec.ts index 797a419..c9b5dba 100644 --- a/app/__test__/data/specs/EntityManager.spec.ts +++ b/app/__test__/data/specs/EntityManager.spec.ts @@ -4,7 +4,7 @@ import { EntityManager, ManyToManyRelation, ManyToOneRelation, - SchemaManager + SchemaManager, } from "../../../src/data"; import { UnableToConnectException } from "../../../src/data/errors"; import { getDummyConnection } from "../helper"; @@ -25,7 +25,7 @@ describe("[data] EntityManager", async () => { expect(await em.ping()).toBe(true); expect(() => em.entity("...")).toThrow(); expect(() => - em.addRelation(new ManyToOneRelation(new Entity("1"), new Entity("2"))) + em.addRelation(new ManyToOneRelation(new Entity("1"), new Entity("2"))), ).toThrow(); expect(em.schema()).toBeInstanceOf(SchemaManager); @@ -98,7 +98,7 @@ describe("[data] EntityManager", async () => { expect(userTargetRel.map((r) => r.other(users).entity.name)).toEqual(["posts", "comments"]); expect(postTargetRel.map((r) => r.other(posts).entity.name)).toEqual([ "comments", - "categories" + "categories", ]); expect(commentTargetRel.map((r) => r.other(comments).entity.name)).toEqual([]); expect(categoriesTargetRel.map((r) => r.other(categories).entity.name)).toEqual(["posts"]); diff --git a/app/__test__/data/specs/JoinBuilder.spec.ts b/app/__test__/data/specs/JoinBuilder.spec.ts index 37afd08..9260aeb 100644 --- a/app/__test__/data/specs/JoinBuilder.spec.ts +++ b/app/__test__/data/specs/JoinBuilder.spec.ts @@ -12,7 +12,7 @@ describe("[data] JoinBuilder", async () => { const em = new EntityManager([users], dummyConnection); expect(() => - JoinBuilder.addClause(em, em.connection.kysely.selectFrom("users"), users, ["posts"]) + JoinBuilder.addClause(em, em.connection.kysely.selectFrom("users"), users, ["posts"]), ).toThrow('Relation "posts" not found'); }); @@ -23,7 +23,7 @@ describe("[data] JoinBuilder", async () => { const em = new EntityManager([users, posts], dummyConnection, relations); const qb = JoinBuilder.addClause(em, em.connection.kysely.selectFrom("users"), users, [ - "posts" + "posts", ]); const res = qb.compile(); @@ -34,7 +34,7 @@ describe("[data] JoinBuilder", async () => { );*/ const qb2 = JoinBuilder.addClause(em, em.connection.kysely.selectFrom("posts"), posts, [ - "author" + "author", ]); const res2 = qb2.compile(); diff --git a/app/__test__/data/specs/Mutator.spec.ts b/app/__test__/data/specs/Mutator.spec.ts index 6493d52..4b3bee7 100644 --- a/app/__test__/data/specs/Mutator.spec.ts +++ b/app/__test__/data/specs/Mutator.spec.ts @@ -9,7 +9,7 @@ import { OneToOneRelation, type RelationField, RelationMutator, - TextField + TextField, } from "../../../src/data"; import * as proto from "../../../src/data/prototype"; import { getDummyConnection } from "../helper"; @@ -22,7 +22,7 @@ describe("[data] Mutator (base)", async () => { new TextField("label", { required: true }), new NumberField("count"), new TextField("hidden", { hidden: true }), - new TextField("not_fillable", { fillable: false }) + new TextField("not_fillable", { fillable: false }), ]); const em = new EntityManager([entity], dummyConnection); await em.schema().sync({ force: true }); @@ -44,7 +44,7 @@ describe("[data] Mutator (base)", async () => { test("updateOne", async () => { const { data } = await em.mutator(entity).insertOne(payload); const updated = await em.mutator(entity).updateOne(data.id, { - count: 2 + count: 2, }); expect(updated.parameters).toEqual([2, data.id]); @@ -77,7 +77,7 @@ describe("[data] Mutator (ManyToOne)", async () => { // persisting relational field should just return key value to be added expect( - postRelMutator.persistRelationField(postRelField, "users_id", userData.data.id) + postRelMutator.persistRelationField(postRelField, "users_id", userData.data.id), ).resolves.toEqual(["users_id", userData.data.id]); // persisting invalid value should throw @@ -86,8 +86,8 @@ describe("[data] Mutator (ManyToOne)", async () => { // persisting reference should ... expect( postRelMutator.persistReference(relations[0]!, "users", { - $set: { id: userData.data.id } - }) + $set: { id: userData.data.id }, + }), ).resolves.toEqual(["users_id", userData.data.id]); // @todo: add what methods are allowed to relation, like $create should not be allowed for post<>users @@ -99,8 +99,8 @@ describe("[data] Mutator (ManyToOne)", async () => { expect( em.mutator(posts).insertOne({ title: "post1", - users_id: 100 // user does not exist yet - }) + users_id: 100, // user does not exist yet + }), ).rejects.toThrow(); }); @@ -111,7 +111,7 @@ describe("[data] Mutator (ManyToOne)", async () => { const em = new EntityManager([items, cats], dummyConnection, relations); expect(em.mutator(items).insertOne({ label: "test" })).rejects.toThrow( - 'Field "cats_id" is required' + 'Field "cats_id" is required', ); }); @@ -119,14 +119,14 @@ describe("[data] Mutator (ManyToOne)", async () => { const { data } = await em.mutator(users).insertOne({ username: "user1" }); const res = await em.mutator(posts).insertOne({ title: "post1", - users_id: data.id + users_id: data.id, }); expect(res.data.users_id).toBe(data.id); // setting "null" should be allowed const res2 = await em.mutator(posts).insertOne({ title: "post1", - users_id: null + users_id: null, }); expect(res2.data.users_id).toBe(null); }); @@ -135,14 +135,14 @@ describe("[data] Mutator (ManyToOne)", async () => { const { data } = await em.mutator(users).insertOne({ username: "user1" }); const res = await em.mutator(posts).insertOne({ title: "post1", - users: { $set: { id: data.id } } + users: { $set: { id: data.id } }, }); expect(res.data.users_id).toBe(data.id); // setting "null" should be allowed const res2 = await em.mutator(posts).insertOne({ title: "post1", - users: { $set: { id: null } } + users: { $set: { id: null } }, }); expect(res2.data.users_id).toBe(null); }); @@ -151,8 +151,8 @@ describe("[data] Mutator (ManyToOne)", async () => { expect( em.mutator(posts).insertOne({ title: "test", - users: { $create: { username: "test" } } - }) + users: { $create: { username: "test" } }, + }), ).rejects.toThrow(); }); @@ -162,27 +162,27 @@ describe("[data] Mutator (ManyToOne)", async () => { const res2 = await em.mutator(posts).insertOne({ title: "post1" }); const up1 = await em.mutator(posts).updateOne(res2.data.id, { - users: { $set: { id: res1.data.id } } + users: { $set: { id: res1.data.id } }, }); expect(up1.data.users_id).toBe(res1.data.id); const up2 = await em.mutator(posts).updateOne(res2.data.id, { - users: { $set: { id: res1_1.data.id } } + users: { $set: { id: res1_1.data.id } }, }); expect(up2.data.users_id).toBe(res1_1.data.id); const up3_1 = await em.mutator(posts).updateOne(res2.data.id, { - users_id: res1.data.id + users_id: res1.data.id, }); expect(up3_1.data.users_id).toBe(res1.data.id); const up3_2 = await em.mutator(posts).updateOne(res2.data.id, { - users_id: res1_1.data.id + users_id: res1_1.data.id, }); expect(up3_2.data.users_id).toBe(res1_1.data.id); const up4 = await em.mutator(posts).updateOne(res2.data.id, { - users_id: null + users_id: null, }); expect(up4.data.users_id).toBe(null); }); @@ -199,8 +199,8 @@ describe("[data] Mutator (OneToOne)", async () => { expect( em.mutator(users).insertOne({ username: "test", - settings_id: 1 // todo: throws because it doesn't exist, but it shouldn't be allowed - }) + settings_id: 1, // todo: throws because it doesn't exist, but it shouldn't be allowed + }), ).rejects.toThrow(); }); @@ -210,15 +210,15 @@ describe("[data] Mutator (OneToOne)", async () => { expect( em.mutator(users).insertOne({ username: "test", - settings: { $set: { id: data.id } } - }) + settings: { $set: { id: data.id } }, + }), ).rejects.toThrow(); }); test("insertOne: using $create", async () => { const res = await em.mutator(users).insertOne({ username: "test", - settings: { $create: { theme: "dark" } } + settings: { $create: { theme: "dark" } }, }); expect(res.data.settings_id).toBeDefined(); }); @@ -303,7 +303,7 @@ describe("[data] Mutator (Events)", async () => { test("insertOne event return is respected", async () => { const posts = proto.entity("posts", { title: proto.text(), - views: proto.number() + views: proto.number(), }); const conn = getDummyConnection(); @@ -318,10 +318,10 @@ describe("[data] Mutator (Events)", async () => { async (event) => { return { ...event.params.data, - views: 2 + views: 2, }; }, - "sync" + "sync", ); const mutator = em.mutator("posts"); @@ -329,14 +329,14 @@ describe("[data] Mutator (Events)", async () => { expect(result.data).toEqual({ id: 1, title: "test", - views: 2 + views: 2, }); }); test("updateOne event return is respected", async () => { const posts = proto.entity("posts", { title: proto.text(), - views: proto.number() + views: proto.number(), }); const conn = getDummyConnection(); @@ -351,10 +351,10 @@ describe("[data] Mutator (Events)", async () => { async (event) => { return { ...event.params.data, - views: event.params.data.views + 1 + views: event.params.data.views + 1, }; }, - "sync" + "sync", ); const mutator = em.mutator("posts"); @@ -363,7 +363,7 @@ describe("[data] Mutator (Events)", async () => { expect(result.data).toEqual({ id: 1, title: "test", - views: 3 + views: 3, }); }); }); diff --git a/app/__test__/data/specs/Repository.spec.ts b/app/__test__/data/specs/Repository.spec.ts index d873389..2a42b9e 100644 --- a/app/__test__/data/specs/Repository.spec.ts +++ b/app/__test__/data/specs/Repository.spec.ts @@ -7,7 +7,7 @@ import { LibsqlConnection, ManyToOneRelation, RepositoryEvents, - TextField + TextField, } from "../../../src/data"; import { getDummyConnection } from "../helper"; @@ -70,13 +70,13 @@ describe("[Repository]", async () => { const q1 = selectQ(conn).compile(); const res = await client.execute({ sql: q1.sql, - args: q1.parameters as any + args: q1.parameters as any, }); const q2 = countQ(conn).compile(); const count = await client.execute({ sql: q2.sql, - args: q2.parameters as any + args: q2.parameters as any, }); return [res, count]; } @@ -93,7 +93,7 @@ describe("[Repository]", async () => { const exec = async ( name: string, fn: (em: EntityManager) => Promise, - em: EntityManager + em: EntityManager, ) => { const res = await Perf.execute(() => fn(em), times); await sleep(1000); @@ -102,7 +102,7 @@ describe("[Repository]", async () => { total: res.total.toFixed(2), avg: (res.total / times).toFixed(2), first: res.marks[0].time.toFixed(2), - last: res.marks[res.marks.length - 1].time.toFixed(2) + last: res.marks[res.marks.length - 1].time.toFixed(2), }; console.log(info.name, info, res.marks); return info; @@ -183,7 +183,7 @@ describe("[data] Repository (Events)", async () => { const items = new Entity("items", [new TextField("label")]); const categories = new Entity("categories", [new TextField("label")]); const em = new EntityManager([items, categories], dummyConnection, [ - new ManyToOneRelation(categories, items) + new ManyToOneRelation(categories, items), ]); await em.schema().sync({ force: true }); const events = new Map(); diff --git a/app/__test__/data/specs/SchemaManager.spec.ts b/app/__test__/data/specs/SchemaManager.spec.ts index 4cfb7d0..9e9fe90 100644 --- a/app/__test__/data/specs/SchemaManager.spec.ts +++ b/app/__test__/data/specs/SchemaManager.spec.ts @@ -26,7 +26,7 @@ describe("SchemaManager tests", async () => { isNullable: true, isAutoIncrementing: true, hasDefaultValue: false, - comment: undefined + comment: undefined, }, { name: "username", @@ -34,7 +34,7 @@ describe("SchemaManager tests", async () => { isNullable: true, isAutoIncrementing: false, hasDefaultValue: false, - comment: undefined + comment: undefined, }, { name: "email", @@ -42,7 +42,7 @@ describe("SchemaManager tests", async () => { isNullable: true, isAutoIncrementing: false, hasDefaultValue: false, - comment: undefined + comment: undefined, }, { name: "bio", @@ -50,8 +50,8 @@ describe("SchemaManager tests", async () => { isNullable: true, isAutoIncrementing: false, hasDefaultValue: false, - comment: undefined - } + comment: undefined, + }, ], indices: [ { @@ -61,11 +61,11 @@ describe("SchemaManager tests", async () => { columns: [ { name: "email", - order: 0 - } - ] - } - ] + order: 0, + }, + ], + }, + ], }); }); @@ -77,10 +77,10 @@ describe("SchemaManager tests", async () => { new Entity(table, [ new TextField("username"), new TextField("email"), - new TextField("bio") - ]) + new TextField("bio"), + ]), ], - dummyConnection + dummyConnection, ); const kysely = em.connection.kysely; @@ -101,8 +101,8 @@ describe("SchemaManager tests", async () => { name: table, isNew: false, columns: { add: ["bio"], drop: [], change: [] }, - indices: { add: [], drop: [index] } - } + indices: { add: [], drop: [index] }, + }, ]); // now sync @@ -119,7 +119,7 @@ describe("SchemaManager tests", async () => { const table = "drop_column"; const em = new EntityManager( [new Entity(table, [new TextField("username")])], - dummyConnection + dummyConnection, ); const kysely = em.connection.kysely; @@ -141,10 +141,10 @@ describe("SchemaManager tests", async () => { columns: { add: [], drop: ["email"], - change: [] + change: [], }, - indices: { add: [], drop: [] } - } + indices: { add: [], drop: [] }, + }, ]); // now sync @@ -165,15 +165,15 @@ describe("SchemaManager tests", async () => { new Entity(usersTable, [ new TextField("username"), new TextField("email"), - new TextField("bio") + new TextField("bio"), ]), new Entity(postsTable, [ new TextField("title"), new TextField("content"), - new TextField("created_at") - ]) + new TextField("created_at"), + ]), ], - dummyConnection + dummyConnection, ); const kysely = em.connection.kysely; @@ -192,7 +192,7 @@ describe("SchemaManager tests", async () => { name: usersTable, isNew: false, columns: { add: ["bio"], drop: [], change: [] }, - indices: { add: [], drop: [] } + indices: { add: [], drop: [] }, }, { name: postsTable, @@ -200,10 +200,10 @@ describe("SchemaManager tests", async () => { columns: { add: ["id", "title", "content", "created_at"], drop: [], - change: [] + change: [], }, - indices: { add: [], drop: [] } - } + indices: { add: [], drop: [] }, + }, ]); // now sync @@ -228,8 +228,8 @@ describe("SchemaManager tests", async () => { name: entity.name, isNew: true, columns: { add: ["id", "email"], drop: [], change: [] }, - indices: { add: [index.name!], drop: [] } - } + indices: { add: [index.name!], drop: [] }, + }, ]); // sync and then check again @@ -256,8 +256,8 @@ describe("SchemaManager tests", async () => { name: entity.name, isNew: false, columns: { add: [], drop: [], change: [] }, - indices: { add: [index.name!], drop: [] } - } + indices: { add: [index.name!], drop: [] }, + }, ]); // sync and then check again diff --git a/app/__test__/data/specs/WithBuilder.spec.ts b/app/__test__/data/specs/WithBuilder.spec.ts index 7b64198..094f9a7 100644 --- a/app/__test__/data/specs/WithBuilder.spec.ts +++ b/app/__test__/data/specs/WithBuilder.spec.ts @@ -7,7 +7,7 @@ import { ManyToOneRelation, PolymorphicRelation, TextField, - WithBuilder + WithBuilder, } from "../../../src/data"; import * as proto from "../../../src/data/prototype"; import { compileQb, prettyPrintQb, schemaToEm } from "../../helper"; @@ -21,12 +21,12 @@ describe("[data] WithBuilder", async () => { { posts: proto.entity("posts", {}), users: proto.entity("users", {}), - media: proto.entity("media", {}) + media: proto.entity("media", {}), }, ({ relation }, { posts, users, media }) => { relation(posts).manyToOne(users); relation(users).polyToOne(media, { mappedBy: "avatar" }); - } + }, ); const em = schemaToEm(schema); @@ -36,17 +36,17 @@ describe("[data] WithBuilder", async () => { expect( WithBuilder.validateWiths(em, "posts", { users: { - with: { avatar: {} } - } - }) + with: { avatar: {} }, + }, + }), ).toBe(2); expect(() => WithBuilder.validateWiths(em, "posts", { author: {} })).toThrow(); expect(() => WithBuilder.validateWiths(em, "posts", { users: { - with: { glibberish: {} } - } - }) + with: { glibberish: {} }, + }, + }), ).toThrow(); }); @@ -56,8 +56,8 @@ describe("[data] WithBuilder", async () => { expect(() => WithBuilder.addClause(em, em.connection.kysely.selectFrom("users"), users, { - posts: {} - }) + posts: {}, + }), ).toThrow('Relation "users<>posts" not found'); }); @@ -68,13 +68,13 @@ describe("[data] WithBuilder", async () => { const em = new EntityManager([users, posts], dummyConnection, relations); const qb = WithBuilder.addClause(em, em.connection.kysely.selectFrom("users"), users, { - posts: {} + posts: {}, }); const res = qb.compile(); expect(res.sql).toBe( - 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'content\', "agg"."content", \'author_id\', "agg"."author_id")), \'[]\') from (select "posts"."id" as "id", "posts"."content" as "content", "posts"."author_id" as "author_id" from "posts" as "posts" where "posts"."author_id" = "users"."id" order by "posts"."id" asc limit ? offset ?) as agg) as "posts" from "users"' + 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'content\', "agg"."content", \'author_id\', "agg"."author_id")), \'[]\') from (select "posts"."id" as "id", "posts"."content" as "content", "posts"."author_id" as "author_id" from "posts" as "posts" where "posts"."author_id" = "users"."id" order by "posts"."id" asc limit ? offset ?) as agg) as "posts" from "users"', ); expect(res.parameters).toEqual([10, 0]); @@ -83,14 +83,14 @@ describe("[data] WithBuilder", async () => { em.connection.kysely.selectFrom("posts"), posts, // @todo: try with "users", it gives output! { - author: {} - } + author: {}, + }, ); const res2 = qb2.compile(); expect(res2.sql).toBe( - 'select (select json_object(\'id\', "obj"."id", \'username\', "obj"."username") from (select "users"."id" as "id", "users"."username" as "username" from "users" as "author" where "author"."id" = "posts"."author_id" order by "users"."id" asc limit ? offset ?) as obj) as "author" from "posts"' + 'select (select json_object(\'id\', "obj"."id", \'username\', "obj"."username") from (select "users"."id" as "id", "users"."username" as "username" from "users" as "author" where "author"."id" = "posts"."author_id" order by "users"."id" asc limit ? offset ?) as obj) as "author" from "posts"', ); expect(res2.parameters).toEqual([1, 0]); }); @@ -124,7 +124,7 @@ describe("[data] WithBuilder", async () => { .values([ { posts_id: 1, categories_id: 1 }, { posts_id: 2, categories_id: 2 }, - { posts_id: 1, categories_id: 2 } + { posts_id: 1, categories_id: 2 }, ]) .execute(); @@ -138,14 +138,14 @@ describe("[data] WithBuilder", async () => { title: "fashion post", categories: [ { id: 1, label: "fashion" }, - { id: 2, label: "beauty" } - ] + { id: 2, label: "beauty" }, + ], }, { id: 2, title: "beauty post", - categories: [{ id: 2, label: "beauty" }] - } + categories: [{ id: 2, label: "beauty" }], + }, ]); const res2 = await em.repository(categories).findMany({ with: { posts: {} } }); @@ -156,21 +156,21 @@ describe("[data] WithBuilder", async () => { { id: 1, label: "fashion", - posts: [{ id: 1, title: "fashion post" }] + posts: [{ id: 1, title: "fashion post" }], }, { id: 2, label: "beauty", posts: [ { id: 1, title: "fashion post" }, - { id: 2, title: "beauty post" } - ] + { id: 2, title: "beauty post" }, + ], }, { id: 3, label: "tech", - posts: [] - } + posts: [], + }, ]); }); @@ -181,7 +181,7 @@ describe("[data] WithBuilder", async () => { const entities = [media, categories]; const single = new PolymorphicRelation(categories, media, { mappedBy: "single", - targetCardinality: 1 + targetCardinality: 1, }); const multiple = new PolymorphicRelation(categories, media, { mappedBy: "multiple" }); @@ -191,11 +191,11 @@ describe("[data] WithBuilder", async () => { em, em.connection.kysely.selectFrom("categories"), categories, - { single: {} } + { single: {} }, ); const res = qb.compile(); expect(res.sql).toBe( - 'select (select json_object(\'id\', "obj"."id", \'path\', "obj"."path") from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "categories"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as obj) as "single" from "categories"' + 'select (select json_object(\'id\', "obj"."id", \'path\', "obj"."path") from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "categories"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as obj) as "single" from "categories"', ); expect(res.parameters).toEqual(["categories.single", 1, 0]); @@ -203,11 +203,11 @@ describe("[data] WithBuilder", async () => { em, em.connection.kysely.selectFrom("categories"), categories, - { multiple: {} } + { multiple: {} }, ); const res2 = qb2.compile(); expect(res2.sql).toBe( - 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'path\', "agg"."path")), \'[]\') from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "categories"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as agg) as "multiple" from "categories"' + 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'path\', "agg"."path")), \'[]\') from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "categories"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as agg) as "multiple" from "categories"', ); expect(res2.parameters).toEqual(["categories.multiple", 10, 0]); }); @@ -240,16 +240,16 @@ describe("[data] WithBuilder", async () => { { posts: proto.entity("posts", {}), users: proto.entity("users", { - username: proto.text() + username: proto.text(), }), media: proto.entity("media", { - path: proto.text() - }) + path: proto.text(), + }), }, ({ relation }, { posts, users, media }) => { relation(posts).manyToOne(users); relation(users).polyToOne(media, { mappedBy: "avatar" }); - } + }, ); const em = schemaToEm(schema); @@ -265,16 +265,16 @@ describe("[data] WithBuilder", async () => { with: { avatar: { select: ["id", "path"], - limit: 2 // ignored - } - } - } - } + limit: 2, // ignored + }, + }, + }, + }, ); //prettyPrintQb(qb); expect(qb.compile().sql).toBe( - 'select (select json_object(\'id\', "obj"."id", \'username\', "obj"."username", \'avatar\', "obj"."avatar") from (select "users"."id" as "id", "users"."username" as "username", (select json_object(\'id\', "obj"."id", \'path\', "obj"."path") from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "users"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as obj) as "avatar" from "users" as "users" where "users"."id" = "posts"."users_id" order by "users"."username" asc limit ? offset ?) as obj) as "users" from "posts"' + 'select (select json_object(\'id\', "obj"."id", \'username\', "obj"."username", \'avatar\', "obj"."avatar") from (select "users"."id" as "id", "users"."username" as "username", (select json_object(\'id\', "obj"."id", \'path\', "obj"."path") from (select "media"."id" as "id", "media"."path" as "path" from "media" where "media"."reference" = ? and "users"."id" = "media"."entity_id" order by "media"."id" asc limit ? offset ?) as obj) as "avatar" from "users" as "users" where "users"."id" = "posts"."users_id" order by "users"."username" asc limit ? offset ?) as obj) as "users" from "posts"', ); expect(qb.compile().parameters).toEqual(["users.avatar", 1, 0, 1, 0]); }); @@ -285,17 +285,17 @@ describe("[data] WithBuilder", async () => { posts: proto.entity("posts", {}), comments: proto.entity("comments", {}), users: proto.entity("users", { - username: proto.text() + username: proto.text(), }), media: proto.entity("media", { - path: proto.text() - }) + path: proto.text(), + }), }, ({ relation }, { posts, comments, users, media }) => { relation(posts).manyToOne(users).polyToOne(media, { mappedBy: "images" }); relation(users).polyToOne(media, { mappedBy: "avatar" }); relation(comments).manyToOne(posts).manyToOne(users); - } + }, ); const em = schemaToEm(schema); @@ -308,15 +308,15 @@ describe("[data] WithBuilder", async () => { limit: 12, with: { users: { - select: ["username"] - } - } - } - } + select: ["username"], + }, + }, + }, + }, ); expect(qb.compile().sql).toBe( - 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'posts_id\', "agg"."posts_id", \'users_id\', "agg"."users_id", \'users\', "agg"."users")), \'[]\') from (select "comments"."id" as "id", "comments"."posts_id" as "posts_id", "comments"."users_id" as "users_id", (select json_object(\'username\', "obj"."username") from (select "users"."username" as "username" from "users" as "users" where "users"."id" = "comments"."users_id" order by "users"."id" asc limit ? offset ?) as obj) as "users" from "comments" as "comments" where "comments"."posts_id" = "posts"."id" order by "comments"."id" asc limit ? offset ?) as agg) as "comments" from "posts"' + 'select (select coalesce(json_group_array(json_object(\'id\', "agg"."id", \'posts_id\', "agg"."posts_id", \'users_id\', "agg"."users_id", \'users\', "agg"."users")), \'[]\') from (select "comments"."id" as "id", "comments"."posts_id" as "posts_id", "comments"."users_id" as "users_id", (select json_object(\'username\', "obj"."username") from (select "users"."username" as "username" from "users" as "users" where "users"."id" = "comments"."users_id" order by "users"."id" asc limit ? offset ?) as obj) as "users" from "comments" as "comments" where "comments"."posts_id" = "posts"."id" order by "comments"."id" asc limit ? offset ?) as agg) as "comments" from "posts"', ); expect(qb.compile().parameters).toEqual([1, 0, 12, 0]); }); @@ -325,23 +325,23 @@ describe("[data] WithBuilder", async () => { const schema = proto.em( { posts: proto.entity("posts", { - title: proto.text() + title: proto.text(), }), comments: proto.entity("comments", { - content: proto.text() + content: proto.text(), }), users: proto.entity("users", { - username: proto.text() + username: proto.text(), }), media: proto.entity("media", { - path: proto.text() - }) + path: proto.text(), + }), }, ({ relation }, { posts, comments, users, media }) => { relation(posts).manyToOne(users).polyToOne(media, { mappedBy: "images" }); relation(users).polyToOne(media, { mappedBy: "avatar" }); relation(comments).manyToOne(posts).manyToOne(users); - } + }, ); const em = schemaToEm(schema); await em.schema().sync({ force: true }); @@ -351,7 +351,7 @@ describe("[data] WithBuilder", async () => { await em.mutator("posts").insertMany([ { title: "post1", users_id: 1 }, { title: "post2", users_id: 1 }, - { title: "post3", users_id: 2 } + { title: "post3", users_id: 2 }, ]); await em.mutator("comments").insertMany([ { content: "comment1", posts_id: 1, users_id: 1 }, @@ -360,7 +360,7 @@ describe("[data] WithBuilder", async () => { { content: "comment3", posts_id: 2, users_id: 1 }, { content: "comment4", posts_id: 2, users_id: 2 }, { content: "comment5", posts_id: 3, users_id: 1 }, - { content: "comment6", posts_id: 3, users_id: 2 } + { content: "comment6", posts_id: 3, users_id: 2 }, ]); const result = await em.repo("posts").findMany({ @@ -371,11 +371,11 @@ describe("[data] WithBuilder", async () => { select: ["content"], with: { users: { - select: ["username"] - } - } - } - } + select: ["username"], + }, + }, + }, + }, }); expect(result.data).toEqual([ @@ -385,16 +385,16 @@ describe("[data] WithBuilder", async () => { { content: "comment1", users: { - username: "user1" - } + username: "user1", + }, }, { content: "comment1-1", users: { - username: "user1" - } - } - ] + username: "user1", + }, + }, + ], }, { title: "post2", @@ -402,16 +402,16 @@ describe("[data] WithBuilder", async () => { { content: "comment3", users: { - username: "user1" - } + username: "user1", + }, }, { content: "comment4", users: { - username: "user2" - } - } - ] + username: "user2", + }, + }, + ], }, { title: "post3", @@ -419,17 +419,17 @@ describe("[data] WithBuilder", async () => { { content: "comment5", users: { - username: "user1" - } + username: "user1", + }, }, { content: "comment6", users: { - username: "user2" - } - } - ] - } + username: "user2", + }, + }, + ], + }, ]); //console.log(_jsonp(result.data)); }); diff --git a/app/__test__/data/specs/connection/Connection.spec.ts b/app/__test__/data/specs/connection/Connection.spec.ts index cc73f7b..d3e8226 100644 --- a/app/__test__/data/specs/connection/Connection.spec.ts +++ b/app/__test__/data/specs/connection/Connection.spec.ts @@ -22,10 +22,10 @@ describe("Connection", async () => { columns: [ { name: "name", - order: 0 - } - ] - } + order: 0, + }, + ], + }, ]); }); @@ -54,14 +54,14 @@ describe("Connection", async () => { columns: [ { name: "name", - order: 0 + order: 0, }, { name: "desc", - order: 1 - } - ] - } + order: 1, + }, + ], + }, ]); }); @@ -83,10 +83,10 @@ describe("Connection", async () => { columns: [ { name: "name", - order: 0 - } - ] - } + order: 0, + }, + ], + }, ]); }); }); diff --git a/app/__test__/data/specs/fields/EnumField.spec.ts b/app/__test__/data/specs/fields/EnumField.spec.ts index 7cde4eb..2187bee 100644 --- a/app/__test__/data/specs/fields/EnumField.spec.ts +++ b/app/__test__/data/specs/fields/EnumField.spec.ts @@ -10,12 +10,12 @@ describe("[data] EnumField", async () => { runBaseFieldTests( EnumField, { defaultValue: "a", schemaType: "text" }, - { options: options(["a", "b", "c"]) } + { options: options(["a", "b", "c"]) }, ); test("yields if default value is not a valid option", async () => { expect( - () => new EnumField("test", { options: options(["a", "b"]), default_value: "c" }) + () => new EnumField("test", { options: options(["a", "b"]), default_value: "c" }), ).toThrow(); }); @@ -31,7 +31,7 @@ describe("[data] EnumField", async () => { const field = new EnumField("test", { options: options(["a", "b", "c"]), default_value: "a", - required: true + required: true, }); expect(field.transformRetrieve(null)).toBe("a"); diff --git a/app/__test__/data/specs/fields/Field.spec.ts b/app/__test__/data/specs/fields/Field.spec.ts index 77eb3fd..45e4351 100644 --- a/app/__test__/data/specs/fields/Field.spec.ts +++ b/app/__test__/data/specs/fields/Field.spec.ts @@ -24,20 +24,20 @@ describe("[data] Field", async () => { const required = new FieldSpec("test", { required: true }); const requiredDefault = new FieldSpec("test", { required: true, - default_value: "test" + default_value: "test", }); expect(required.transformPersist(null, undefined as any, undefined as any)).rejects.toThrow(); expect( - required.transformPersist(undefined, undefined as any, undefined as any) + required.transformPersist(undefined, undefined as any, undefined as any), ).rejects.toThrow(); // works because it has a default value expect( - requiredDefault.transformPersist(null, undefined as any, undefined as any) + requiredDefault.transformPersist(null, undefined as any, undefined as any), ).resolves.toBeDefined(); expect( - requiredDefault.transformPersist(undefined, undefined as any, undefined as any) + requiredDefault.transformPersist(undefined, undefined as any, undefined as any), ).resolves.toBeDefined(); }); }); diff --git a/app/__test__/data/specs/fields/FieldIndex.spec.ts b/app/__test__/data/specs/fields/FieldIndex.spec.ts index 3ba9606..8f1590c 100644 --- a/app/__test__/data/specs/fields/FieldIndex.spec.ts +++ b/app/__test__/data/specs/fields/FieldIndex.spec.ts @@ -5,7 +5,7 @@ import { EntityIndex, type EntityManager, Field, - type SchemaResponse + type SchemaResponse, } from "../../../../src/data"; class TestField extends Field { diff --git a/app/__test__/data/specs/fields/JsonField.spec.ts b/app/__test__/data/specs/fields/JsonField.spec.ts index 17fdaaa..dff15a1 100644 --- a/app/__test__/data/specs/fields/JsonField.spec.ts +++ b/app/__test__/data/specs/fields/JsonField.spec.ts @@ -7,7 +7,7 @@ describe("[data] JsonField", async () => { runBaseFieldTests(JsonField, { defaultValue: { a: 1 }, sampleValues: ["string", { test: 1 }, 1], - schemaType: "text" + schemaType: "text", }); test("transformPersist (no config)", async () => { diff --git a/app/__test__/data/specs/fields/inc.ts b/app/__test__/data/specs/fields/inc.ts index 98b5e5f..1754c20 100644 --- a/app/__test__/data/specs/fields/inc.ts +++ b/app/__test__/data/specs/fields/inc.ts @@ -18,7 +18,7 @@ export function transformPersist(field: Field, value: any, context?: TActionCont export function runBaseFieldTests( fieldClass: ConstructableField, config: FieldTestConfig, - _requiredConfig: any = {} + _requiredConfig: any = {}, ) { const noConfigField = new fieldClass("no_config", _requiredConfig); const fillable = new fieldClass("fillable", { ..._requiredConfig, fillable: true }); @@ -29,7 +29,7 @@ export function runBaseFieldTests( ..._requiredConfig, fillable: true, required: true, - default_value: config.defaultValue + default_value: config.defaultValue, }); test("schema", () => { @@ -37,7 +37,7 @@ export function runBaseFieldTests( expect(noConfigField.schema(null as any)).toEqual([ "no_config", config.schemaType, - expect.any(Function) + expect.any(Function), ]); }); @@ -96,7 +96,7 @@ export function runBaseFieldTests( //order: 1, fillable: true, required: false, - hidden: false + hidden: false, //virtual: false, //default_value: undefined }; @@ -105,20 +105,20 @@ export function runBaseFieldTests( const json = field.toJSON(); return { ...json, - config: omit(json.config, ["html"]) + config: omit(json.config, ["html"]), }; } expect(fieldJson(noConfigField)).toEqual({ //name: "no_config", type: noConfigField.type, - config: _config + config: _config, }); expect(fieldJson(fillable)).toEqual({ //name: "fillable", type: noConfigField.type, - config: _config + config: _config, }); expect(fieldJson(required)).toEqual({ @@ -126,8 +126,8 @@ export function runBaseFieldTests( type: required.type, config: { ..._config, - required: true - } + required: true, + }, }); expect(fieldJson(hidden)).toEqual({ @@ -135,8 +135,8 @@ export function runBaseFieldTests( type: required.type, config: { ..._config, - hidden: true - } + hidden: true, + }, }); expect(fieldJson(dflt)).toEqual({ @@ -144,8 +144,8 @@ export function runBaseFieldTests( type: dflt.type, config: { ..._config, - default_value: config.defaultValue - } + default_value: config.defaultValue, + }, }); expect(fieldJson(requiredAndDefault)).toEqual({ @@ -155,8 +155,8 @@ export function runBaseFieldTests( ..._config, fillable: true, required: true, - default_value: config.defaultValue - } + default_value: config.defaultValue, + }, }); }); } diff --git a/app/__test__/data/specs/relations/EntityRelation.spec.ts b/app/__test__/data/specs/relations/EntityRelation.spec.ts index 92c50e3..62561b6 100644 --- a/app/__test__/data/specs/relations/EntityRelation.spec.ts +++ b/app/__test__/data/specs/relations/EntityRelation.spec.ts @@ -4,7 +4,7 @@ import { type BaseRelationConfig, EntityRelation, EntityRelationAnchor, - RelationTypes + RelationTypes, } from "../../../../src/data/relations"; class TestEntityRelation extends EntityRelation { @@ -12,7 +12,7 @@ class TestEntityRelation extends EntityRelation { super( new EntityRelationAnchor(new Entity("source"), "source"), new EntityRelationAnchor(new Entity("target"), "target"), - config + config, ); } initialize(em: EntityManager) {} diff --git a/app/__test__/flows/FetchTask.spec.ts b/app/__test__/flows/FetchTask.spec.ts index fe8e731..d10bc84 100644 --- a/app/__test__/flows/FetchTask.spec.ts +++ b/app/__test__/flows/FetchTask.spec.ts @@ -30,14 +30,14 @@ beforeAll(() => method: init?.method ?? "GET", // @ts-ignore headers: Object.fromEntries(init?.headers?.entries() ?? []), - body: init?.body + body: init?.body, }; return new Response(JSON.stringify({ todos: [1, 2], request }), { status: 200, - headers: { "Content-Type": "application/json" } + headers: { "Content-Type": "application/json" }, }); - }) + }), ); afterAll(unmockFetch); @@ -46,7 +46,7 @@ describe("FetchTask", async () => { const task = new FetchTask("Fetch Something", { url: "https://jsonplaceholder.typicode.com/todos/1", method: "GET", - headers: [{ key: "Content-Type", value: "application/json" }] + headers: [{ key: "Content-Type", value: "application/json" }], }); const result = await task.run(); @@ -62,18 +62,18 @@ describe("FetchTask", async () => { expect( // // @ts-expect-error - () => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: 1 }) + () => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: 1 }), ).toThrow(); expect( new FetchTask("", { url: "https://jsonplaceholder.typicode.com", - method: "invalid" - }).execute() + method: "invalid", + }).execute(), ).rejects.toThrow(/^Invalid method/); expect( - () => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: "GET" }) + () => new FetchTask("", { url: "https://jsonplaceholder.typicode.com", method: "GET" }), ).toBeDefined(); expect(() => new FetchTask("", { url: "", method: "Invalid" })).toThrow(); @@ -85,17 +85,17 @@ describe("FetchTask", async () => { method: "{{ flow.output.method }}", headers: [ { key: "Content-{{ flow.output.headerKey }}", value: "application/json" }, - { key: "Authorization", value: "Bearer {{ flow.output.apiKey }}" } + { key: "Authorization", value: "Bearer {{ flow.output.apiKey }}" }, ], body: JSON.stringify({ - email: "{{ flow.output.email }}" - }) + email: "{{ flow.output.email }}", + }), }); const inputs = { headerKey: "Type", apiKey: 123, email: "what@else.com", - method: "PATCH" + method: "PATCH", }; const flow = new Flow("", [task]); diff --git a/app/__test__/flows/SubWorkflowTask.spec.ts b/app/__test__/flows/SubWorkflowTask.spec.ts index c05faf7..c52a0a2 100644 --- a/app/__test__/flows/SubWorkflowTask.spec.ts +++ b/app/__test__/flows/SubWorkflowTask.spec.ts @@ -4,16 +4,16 @@ import { Flow, LogTask, RenderTask, SubFlowTask } from "../../src/flows"; describe("SubFlowTask", async () => { test("Simple Subflow", async () => { const subTask = new RenderTask("render", { - render: "subflow" + render: "subflow", }); const subflow = new Flow("subflow", [subTask]); const task = new LogTask("log"); const task2 = new SubFlowTask("sub", { - flow: subflow + flow: subflow, }); const task3 = new RenderTask("render2", { - render: "Subflow output: {{ sub.output }}" + render: "Subflow output: {{ sub.output }}", }); const flow = new Flow("test", [task, task2, task3], []); @@ -30,7 +30,7 @@ describe("SubFlowTask", async () => { test("Simple loop", async () => { const subTask = new RenderTask("render", { - render: "run {{ flow.output }}" + render: "run {{ flow.output }}", }); const subflow = new Flow("subflow", [subTask]); @@ -38,10 +38,10 @@ describe("SubFlowTask", async () => { const task2 = new SubFlowTask("sub", { flow: subflow, loop: true, - input: [1, 2, 3] + input: [1, 2, 3], }); const task3 = new RenderTask("render2", { - render: `Subflow output: {{ sub.output | join: ", " }}` + render: `Subflow output: {{ sub.output | join: ", " }}`, }); const flow = new Flow("test", [task, task2, task3], []); @@ -61,7 +61,7 @@ describe("SubFlowTask", async () => { test("Simple loop from flow input", async () => { const subTask = new RenderTask("render", { - render: "run {{ flow.output }}" + render: "run {{ flow.output }}", }); const subflow = new Flow("subflow", [subTask]); @@ -70,10 +70,10 @@ describe("SubFlowTask", async () => { const task2 = new SubFlowTask("sub", { flow: subflow, loop: true, - input: "{{ flow.output | json }}" + input: "{{ flow.output | json }}", }); const task3 = new RenderTask("render2", { - render: `Subflow output: {{ sub.output | join: ", " }}` + render: `Subflow output: {{ sub.output | join: ", " }}`, }); const flow = new Flow("test", [task, task2, task3], []); diff --git a/app/__test__/flows/Task.spec.ts b/app/__test__/flows/Task.spec.ts index 8519288..2016478 100644 --- a/app/__test__/flows/Task.spec.ts +++ b/app/__test__/flows/Task.spec.ts @@ -8,13 +8,13 @@ describe("Task", async () => { const result = await Task.resolveParams( Type.Object({ test: dynamic(Type.Number()) }), { - test: "{{ some.path }}" + test: "{{ some.path }}", }, { some: { - path: 1 - } - } + path: 1, + }, + }, ); expect(result.test).toBe(1); @@ -24,13 +24,13 @@ describe("Task", async () => { const result = await Task.resolveParams( Type.Object({ test: Type.String() }), { - test: "{{ some.path }}" + test: "{{ some.path }}", }, { some: { - path: "1/1" - } - } + path: "1/1", + }, + }, ); expect(result.test).toBe("1/1"); @@ -40,13 +40,13 @@ describe("Task", async () => { const result = await Task.resolveParams( Type.Object({ test: dynamic(Type.Object({ key: Type.String(), value: Type.String() })) }), { - test: { key: "path", value: "{{ some.path }}" } + test: { key: "path", value: "{{ some.path }}" }, }, { some: { - path: "1/1" - } - } + path: "1/1", + }, + }, ); expect(result.test).toEqual({ key: "path", value: "1/1" }); @@ -55,17 +55,17 @@ describe("Task", async () => { test("resolveParams: with json", async () => { const result = await Task.resolveParams( Type.Object({ - test: dynamic(Type.Object({ key: Type.String(), value: Type.String() })) + test: dynamic(Type.Object({ key: Type.String(), value: Type.String() })), }), { - test: "{{ some | json }}" + test: "{{ some | json }}", }, { some: { key: "path", - value: "1/1" - } - } + value: "1/1", + }, + }, ); expect(result.test).toEqual({ key: "path", value: "1/1" }); @@ -74,11 +74,11 @@ describe("Task", async () => { test("resolveParams: with array", async () => { const result = await Task.resolveParams( Type.Object({ - test: dynamic(Type.Array(Type.String())) + test: dynamic(Type.Array(Type.String())), }), { - test: '{{ "1,2,3" | split: "," | json }}' - } + test: '{{ "1,2,3" | split: "," | json }}', + }, ); expect(result.test).toEqual(["1", "2", "3"]); @@ -87,11 +87,11 @@ describe("Task", async () => { test("resolveParams: boolean", async () => { const result = await Task.resolveParams( Type.Object({ - test: dynamic(Type.Boolean()) + test: dynamic(Type.Boolean()), }), { - test: "{{ true }}" - } + test: "{{ true }}", + }, ); expect(result.test).toEqual(true); @@ -100,11 +100,11 @@ describe("Task", async () => { test("resolveParams: float", async () => { const result = await Task.resolveParams( Type.Object({ - test: dynamic(Type.Number(), Number.parseFloat) + test: dynamic(Type.Number(), Number.parseFloat), }), { - test: "{{ 3.14 }}" - } + test: "{{ 3.14 }}", + }, ); expect(result.test).toEqual(3.14); diff --git a/app/__test__/flows/inc/fanout-condition.ts b/app/__test__/flows/inc/fanout-condition.ts index c2ec3f5..c0ab97d 100644 --- a/app/__test__/flows/inc/fanout-condition.ts +++ b/app/__test__/flows/inc/fanout-condition.ts @@ -7,11 +7,11 @@ const first = getNamedTask( //throw new Error("Error"); return { inner: { - result: 2 - } + result: 2, + }, }; }, - 1000 + 1000, ); const second = getNamedTask("second (if match)"); const third = getNamedTask("third (if error)"); diff --git a/app/__test__/flows/inc/helper.tsx b/app/__test__/flows/inc/helper.tsx index 2893e3a..8e2ddb8 100644 --- a/app/__test__/flows/inc/helper.tsx +++ b/app/__test__/flows/inc/helper.tsx @@ -11,7 +11,7 @@ class ExecTask extends Task { constructor( name: string, params: any, - private fn: () => any + private fn: () => any, ) { super(name, params); } @@ -54,8 +54,8 @@ export function getNamedTask(name: string, _func?: () => Promise, delay?: n return new ExecTask( name, { - delay + delay, }, - func + func, ); } diff --git a/app/__test__/flows/inc/simple-fetch.ts b/app/__test__/flows/inc/simple-fetch.ts index b5d21c3..7448e92 100644 --- a/app/__test__/flows/inc/simple-fetch.ts +++ b/app/__test__/flows/inc/simple-fetch.ts @@ -4,7 +4,7 @@ const first = new LogTask("First", { delay: 1000 }); const second = new LogTask("Second", { delay: 1000 }); const third = new LogTask("Long Third", { delay: 2500 }); const fourth = new FetchTask("Fetch Something", { - url: "https://jsonplaceholder.typicode.com/todos/1" + url: "https://jsonplaceholder.typicode.com/todos/1", }); const fifth = new LogTask("Task 4", { delay: 500 }); // without connection diff --git a/app/__test__/flows/inputs.test.ts b/app/__test__/flows/inputs.test.ts index 22d69f8..25a1c82 100644 --- a/app/__test__/flows/inputs.test.ts +++ b/app/__test__/flows/inputs.test.ts @@ -23,10 +23,10 @@ class OutputParamTask extends Task { static override schema = Type.Object({ number: dynamic( Type.Number({ - title: "Output number" + title: "Output number", }), - Number.parseInt - ) + Number.parseInt, + ), }); async execute(inputs: InputsMap) { @@ -75,7 +75,7 @@ describe("Flow task inputs", async () => { test("output/input", async () => { const task = new OutputParamTask("task1", { number: 111 }); const task2 = new OutputParamTask("task2", { - number: "{{ task1.output }}" + number: "{{ task1.output }}", }); const flow = new Flow("test", [task, task2]); @@ -94,10 +94,10 @@ describe("Flow task inputs", async () => { test("input from flow", async () => { const task = new OutputParamTask("task1", { - number: "{{flow.output.someFancyParam}}" + number: "{{flow.output.someFancyParam}}", }); const task2 = new OutputParamTask("task2", { - number: "{{task1.output}}" + number: "{{task1.output}}", }); const flow = new Flow("test", [task, task2]); @@ -126,7 +126,7 @@ describe("Flow task inputs", async () => { const emgr = new EventManager({ EventTriggerClass }); const task = new OutputParamTask("event", { - number: "{{flow.output.number}}" + number: "{{flow.output.number}}", }); const flow = new Flow( "test", @@ -134,8 +134,8 @@ describe("Flow task inputs", async () => { [], new EventTrigger({ event: "test-event", - mode: "sync" - }) + mode: "sync", + }), ); flow.setRespondingTask(task); flow.trigger.register(flow, emgr); @@ -155,8 +155,8 @@ describe("Flow task inputs", async () => { new HttpTrigger({ path: "/test", method: "GET", - mode: "sync" - }) + mode: "sync", + }), ); flow.setRespondingTask(task); diff --git a/app/__test__/flows/render.tsx b/app/__test__/flows/render.tsx index 8080b5c..61867e6 100644 --- a/app/__test__/flows/render.tsx +++ b/app/__test__/flows/render.tsx @@ -10,7 +10,7 @@ const flows = { back, fanout, parallel, - simpleFetch + simpleFetch, }; const arg = process.argv[2]; @@ -32,7 +32,7 @@ const colors = [ "#F78F1E", // Saffron "#BD10E0", // Vivid Purple "#50E3C2", // Turquoise - "#9013FE" // Grape + "#9013FE", // Grape ]; const colorsCache: Record = {}; @@ -82,7 +82,7 @@ function TerminalFlow({ flow }: { flow: Flow }) { } return t; - }) + }), ); } }); @@ -92,7 +92,7 @@ function TerminalFlow({ flow }: { flow: Flow }) { console.log("done", response ? response : "(no response)"); console.log( "Executed tasks:", - execution.logs.map((l) => l.task.name) + execution.logs.map((l) => l.task.name), ); console.log("Executed count:", execution.logs.length); }); diff --git a/app/__test__/flows/trigger.test.ts b/app/__test__/flows/trigger.test.ts index 1fec803..e85f13e 100644 --- a/app/__test__/flows/trigger.test.ts +++ b/app/__test__/flows/trigger.test.ts @@ -11,7 +11,7 @@ class ExecTask extends Task { constructor( name: string, params: any, - private fn: () => any + private fn: () => any, ) { super(name, params); } @@ -60,7 +60,7 @@ describe("Flow trigger", async () => { "test", [task], [], - new EventTrigger({ event: "test-event", mode: "sync" }) + new EventTrigger({ event: "test-event", mode: "sync" }), ); flow.trigger.register(flow, emgr); @@ -107,8 +107,8 @@ describe("Flow trigger", async () => { new HttpTrigger({ path: "/test", method: "GET", - mode: "sync" - }) + mode: "sync", + }), ); const hono = new Hono(); @@ -123,7 +123,7 @@ describe("Flow trigger", async () => { test("http trigger with response", async () => { const task = ExecTask.create("http", () => ({ - called: true + called: true, })); const flow = new Flow( "test", @@ -132,8 +132,8 @@ describe("Flow trigger", async () => { new HttpTrigger({ path: "/test", method: "GET", - mode: "sync" - }) + mode: "sync", + }), ); flow.setRespondingTask(task); diff --git a/app/__test__/flows/workflow-basic.test.ts b/app/__test__/flows/workflow-basic.test.ts index 6a0f1d6..56579f5 100644 --- a/app/__test__/flows/workflow-basic.test.ts +++ b/app/__test__/flows/workflow-basic.test.ts @@ -11,13 +11,13 @@ class ExecTask extends Task { type = "exec"; static override schema = Type.Object({ - delay: Type.Number({ default: 10 }) + delay: Type.Number({ default: 10 }), }); constructor( name: string, params: Static, - private func: () => Promise + private func: () => Promise, ) { super(name, params); } @@ -36,12 +36,12 @@ function getTask(num: number = 0, delay: number = 5) { return new ExecTask( `Task ${num}`, { - delay + delay, }, async () => { //console.log(`[DONE] Task: ${num}`); return true; - } + }, ); //return new LogTask(`Log ${num}`, { delay }); } @@ -56,9 +56,9 @@ function getNamedTask(name: string, _func?: () => Promise, delay?: number) return new ExecTask( name, { - delay: delay ?? 0 + delay: delay ?? 0, }, - func + func, ); } @@ -228,7 +228,7 @@ describe("Flow tests", async () => { back .task(third) .getOutTasks() - .map((t) => t.name) + .map((t) => t.name), ).toEqual(["second", "fourth"]); const execution = back.createExecution(); @@ -263,7 +263,7 @@ describe("Flow tests", async () => { back .task(third) .getOutTasks() - .map((t) => t.name) + .map((t) => t.name), ).toEqual(["second", "fourth"]); const execution = back.createExecution(); @@ -324,8 +324,8 @@ describe("Flow tests", async () => { const first = getNamedTask("first", async () => { return { inner: { - result: 2 - } + result: 2, + }, }; }); const second = getNamedTask("second"); @@ -361,7 +361,7 @@ describe("Flow tests", async () => { "[event]", event.isStart() ? "start" : "end", event.task().name, - event.isStart() ? undefined : event.succeeded() + event.isStart() ? undefined : event.succeeded(), ); } }); @@ -389,7 +389,7 @@ describe("Flow tests", async () => { const second = new LogTask("Task 1"); const third = new LogTask("Task 2", { delay: 50 }); const fourth = new FetchTask("Fetch Something", { - url: "https://jsonplaceholder.typicode.com/todos/1" + url: "https://jsonplaceholder.typicode.com/todos/1", }); const fifth = new LogTask("Task 4"); // without connection @@ -405,7 +405,7 @@ describe("Flow tests", async () => { // @todo: fix const deserialized = Flow.fromObject("", original, { fetch: { cls: FetchTask }, - log: { cls: LogTask } + log: { cls: LogTask }, } as any); const diffdeep = getObjectDiff(original, deserialized.toJSON()); @@ -414,7 +414,7 @@ describe("Flow tests", async () => { expect(flow.startTask.name).toEqual(deserialized.startTask.name); expect(flow.respondingTask?.name).toEqual( // @ts-ignore - deserialized.respondingTask?.name + deserialized.respondingTask?.name, ); //console.log("--- creating original sequence"); diff --git a/app/__test__/helper.ts b/app/__test__/helper.ts index 8cafff2..ae6454f 100644 --- a/app/__test__/helper.ts +++ b/app/__test__/helper.ts @@ -17,7 +17,7 @@ export function getDummyDatabase(memory: boolean = true): { afterAllCleanup: async () => { if (!memory) await unlink(DB_NAME); return true; - } + }, }; } @@ -27,7 +27,7 @@ export function getDummyConnection(memory: boolean = true) { return { dummyConnection, - afterAllCleanup + afterAllCleanup, }; } @@ -39,7 +39,7 @@ type ConsoleSeverity = "log" | "warn" | "error"; const _oldConsoles = { log: console.log, warn: console.warn, - error: console.error + error: console.error, }; export function disableConsoleLog(severities: ConsoleSeverity[] = ["log", "warn"]) { diff --git a/app/__test__/integration/auth.integration.test.ts b/app/__test__/integration/auth.integration.test.ts index 6f2466c..9b2bb51 100644 --- a/app/__test__/integration/auth.integration.test.ts +++ b/app/__test__/integration/auth.integration.test.ts @@ -16,25 +16,25 @@ const roles = { "system.schema.read", "system.access.api", "system.config.read", - "data.entity.read" + "data.entity.read", ], - is_default: true + is_default: true, }, admin: { is_default: true, - implicit_allow: true - } + implicit_allow: true, + }, }, strict: { guest: { permissions: ["system.access.api", "system.config.read", "data.entity.read"], - is_default: true + is_default: true, }, admin: { is_default: true, - implicit_allow: true - } - } + implicit_allow: true, + }, + }, }; const configs = { auth: { @@ -42,31 +42,31 @@ const configs = { entity_name: "users", jwt: { secret: secureRandomString(20), - issuer: randomString(10) + issuer: randomString(10), }, roles: roles.strict, guard: { - enabled: true - } + enabled: true, + }, }, users: { normal: { email: "normal@bknd.io", - password: "12345678" + password: "12345678", }, admin: { email: "admin@bknd.io", password: "12345678", - role: "admin" - } - } + role: "admin", + }, + }, }; function createAuthApp() { const app = createApp({ initialConfig: { - auth: configs.auth - } + auth: configs.auth, + }, }); app.emgr.onEvent( @@ -75,7 +75,7 @@ function createAuthApp() { await app.createUser(configs.users.normal); await app.createUser(configs.users.admin); }, - "sync" + "sync", ); return app; @@ -94,14 +94,14 @@ const fns = (app: App, mode?: Mode) = if (mode === "cookie") { return { cookie: `auth=${token};`, - ...additional + ...additional, }; } return { Authorization: token ? `Bearer ${token}` : "", "Content-Type": "application/json", - ...additional + ...additional, }; } function body(obj?: Record) { @@ -118,12 +118,12 @@ const fns = (app: App, mode?: Mode) = return { login: async ( - user: any + user: any, ): Promise<{ res: Response; data: Mode extends "token" ? AuthResponse : string }> => { const res = (await app.server.request("/api/auth/password/login", { method: "POST", headers: headers(), - body: body(user) + body: body(user), })) as Response; const data = mode === "cookie" ? getCookie(res, "auth") : await res.json(); @@ -133,10 +133,10 @@ const fns = (app: App, mode?: Mode) = me: async (token?: string): Promise> => { const res = (await app.server.request("/api/auth/me", { method: "GET", - headers: headers(token) + headers: headers(token), })) as Response; return await res.json(); - } + }, }; }; @@ -219,7 +219,7 @@ describe("integration auth", () => { app.server.get("/get", auth(), async (c) => { return c.json({ - user: c.get("auth").user ?? null + user: c.get("auth").user ?? null, }); }); app.server.get("/wait", auth(), async (c) => { @@ -232,7 +232,7 @@ describe("integration auth", () => { expect(me.user.email).toBe(configs.users.normal.email); app.server.request("/wait", { - headers: { Authorization: `Bearer ${data.token}` } + headers: { Authorization: `Bearer ${data.token}` }, }); { diff --git a/app/__test__/integration/config.integration.test.ts b/app/__test__/integration/config.integration.test.ts index 6eef035..f370e69 100644 --- a/app/__test__/integration/config.integration.test.ts +++ b/app/__test__/integration/config.integration.test.ts @@ -8,7 +8,7 @@ describe("integration config", () => { await app.build(); const api = new Api({ host: "http://localhost", - fetcher: app.server.request as typeof fetch + fetcher: app.server.request as typeof fetch, }); // create entity @@ -16,7 +16,7 @@ describe("integration config", () => { name: "posts", config: { sort_field: "id", sort_dir: "asc" }, fields: { id: { type: "primary", name: "id" }, asdf: { type: "text" } }, - type: "regular" + type: "regular", }); expect(app.em.entities.map((e) => e.name)).toContain("posts"); diff --git a/app/__test__/media/MediaController.spec.ts b/app/__test__/media/MediaController.spec.ts index be71e74..71b9cbb 100644 --- a/app/__test__/media/MediaController.spec.ts +++ b/app/__test__/media/MediaController.spec.ts @@ -22,13 +22,13 @@ async function makeApp(mediaOverride: Partial = {}) { adapter: { type: "local", config: { - path: assetsTmpPath - } - } + path: assetsTmpPath, + }, + }, }, - mediaOverride - ) - } + mediaOverride, + ), + }, }); await app.build(); @@ -50,7 +50,7 @@ describe("MediaController", () => { const name = makeName("png"); const res = await app.server.request("/api/media/upload/" + name, { method: "POST", - body: file + body: file, }); const result = (await res.json()) as any; console.log(result); @@ -71,7 +71,7 @@ describe("MediaController", () => { const res = await app.server.request("/api/media/upload/" + name, { method: "POST", - body: form + body: form, }); const result = (await res.json()) as any; expect(result.name).toBe(name); @@ -88,7 +88,7 @@ describe("MediaController", () => { const name = makeName("png"); const res = await app.server.request("/api/media/upload/" + name, { method: "POST", - body: file + body: file, }); expect(res.status).toBe(413); diff --git a/app/__test__/media/Storage.spec.ts b/app/__test__/media/Storage.spec.ts index 69d1f0e..f493606 100644 --- a/app/__test__/media/Storage.spec.ts +++ b/app/__test__/media/Storage.spec.ts @@ -60,7 +60,7 @@ describe("Storage", async () => { test("uploads a file", async () => { const { - meta: { type, size } + meta: { type, size }, } = await storage.uploadFile("hello", "world.txt"); expect({ type, size }).toEqual({ type: "text/plain", size: 0 }); }); diff --git a/app/__test__/media/StorageR2Adapter.native-spec.ts b/app/__test__/media/StorageR2Adapter.native-spec.ts index 8f33ca6..64c7a9f 100644 --- a/app/__test__/media/StorageR2Adapter.native-spec.ts +++ b/app/__test__/media/StorageR2Adapter.native-spec.ts @@ -14,7 +14,7 @@ test("what", async () => { const mf = new Miniflare({ modules: true, script: "export default { async fetch() { return new Response(null); } }", - r2Buckets: ["BUCKET"] + r2Buckets: ["BUCKET"], }); const bucket = await mf.getR2Bucket("BUCKET"); diff --git a/app/__test__/media/adapters/StorageCloudinaryAdapter.spec.ts b/app/__test__/media/adapters/StorageCloudinaryAdapter.spec.ts index 0762335..9cac2e4 100644 --- a/app/__test__/media/adapters/StorageCloudinaryAdapter.spec.ts +++ b/app/__test__/media/adapters/StorageCloudinaryAdapter.spec.ts @@ -8,7 +8,7 @@ const { CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET, - CLOUDINARY_UPLOAD_PRESET + CLOUDINARY_UPLOAD_PRESET, } = dotenvOutput.parsed!; const ALL_TESTS = !!process.env.ALL_TESTS; @@ -20,7 +20,7 @@ describe.skipIf(ALL_TESTS)("StorageCloudinaryAdapter", () => { cloud_name: CLOUDINARY_CLOUD_NAME as string, api_key: CLOUDINARY_API_KEY as string, api_secret: CLOUDINARY_API_SECRET as string, - upload_preset: CLOUDINARY_UPLOAD_PRESET as string + upload_preset: CLOUDINARY_UPLOAD_PRESET as string, }); const file = Bun.file(`${import.meta.dir}/icon.png`); diff --git a/app/__test__/media/adapters/StorageLocalAdapter.spec.ts b/app/__test__/media/adapters/StorageLocalAdapter.spec.ts index a74fa14..b23f84d 100644 --- a/app/__test__/media/adapters/StorageLocalAdapter.spec.ts +++ b/app/__test__/media/adapters/StorageLocalAdapter.spec.ts @@ -5,7 +5,7 @@ import { assetsPath, assetsTmpPath } from "../../helper"; describe("StorageLocalAdapter", () => { const adapter = new StorageLocalAdapter({ - path: assetsTmpPath + path: assetsTmpPath, }); const file = Bun.file(`${assetsPath}/image.png`); @@ -36,7 +36,7 @@ describe("StorageLocalAdapter", () => { test("gets object meta", async () => { expect(await adapter.getObjectMeta(filename)).toEqual({ type: file.type, // image/png - size: file.size + size: file.size, }); }); diff --git a/app/__test__/media/adapters/StorageS3Adapter.spec.ts b/app/__test__/media/adapters/StorageS3Adapter.spec.ts index 427e628..ad777e7 100644 --- a/app/__test__/media/adapters/StorageS3Adapter.spec.ts +++ b/app/__test__/media/adapters/StorageS3Adapter.spec.ts @@ -20,17 +20,17 @@ describe.skipIf(true)("StorageS3Adapter", async () => { new StorageS3Adapter({ access_key: R2_ACCESS_KEY as string, secret_access_key: R2_SECRET_ACCESS_KEY as string, - url: R2_URL as string - }) + url: R2_URL as string, + }), ], [ "s3", new StorageS3Adapter({ access_key: AWS_ACCESS_KEY as string, secret_access_key: AWS_SECRET_KEY as string, - url: AWS_S3_URL as string - }) - ] + url: AWS_S3_URL as string, + }), + ], ] as const; const _conf = { @@ -41,8 +41,8 @@ describe.skipIf(true)("StorageS3Adapter", async () => { "objectExists", "getObject", "deleteObject", - "getObjectMeta" - ] + "getObjectMeta", + ], }; const file = Bun.file(`${import.meta.dir}/icon.png`); @@ -86,7 +86,7 @@ describe.skipIf(true)("StorageS3Adapter", async () => { test.skipIf(disabled("getObjectMeta"))("gets object meta", async () => { expect(await adapter.getObjectMeta(filename)).toEqual({ type: file.type, // image/png - size: file.size + size: file.size, }); }); diff --git a/app/__test__/media/mime-types.spec.ts b/app/__test__/media/mime-types.spec.ts index cdc0ea7..6c51fab 100644 --- a/app/__test__/media/mime-types.spec.ts +++ b/app/__test__/media/mime-types.spec.ts @@ -28,7 +28,7 @@ describe("media/mime-types", () => { exts, ext, expected: ex, - actual: large.guessMimeType("." + ext) + actual: large.guessMimeType("." + ext), }); throw new Error(`Failed for ${ext}`); } @@ -49,13 +49,13 @@ describe("media/mime-types", () => { ["image/gif", true], ["whatever", false], ["text/tab-separated-values", true], - ["application/zip", true] + ["application/zip", true], ]; for (const [mime, expected, exclude] of tests) { expect( tiny.isMimeType(mime, exclude as any), - `isMimeType(): ${mime} should be ${expected}` + `isMimeType(): ${mime} should be ${expected}`, ).toBe(expected as any); } }); @@ -68,7 +68,7 @@ describe("media/mime-types", () => { ["image/jpeg", "jpeg"], ["application/zip", "zip"], ["text/tab-separated-values", "tsv"], - ["application/zip", "zip"] + ["application/zip", "zip"], ]; for (const [mime, ext] of tests) { @@ -85,13 +85,13 @@ describe("media/mime-types", () => { ["image.heic", "heic"], ["image.jpeg", "jpeg"], ["-473Wx593H-466453554-black-MODEL.jpg", "jpg"], - ["-473Wx593H-466453554-black-MODEL.avif", "avif"] + ["-473Wx593H-466453554-black-MODEL.avif", "avif"], ]; for (const [filename, ext] of tests) { expect( getRandomizedFilename(filename).split(".").pop(), - `getRandomizedFilename(): ${filename} should end with ${ext}` + `getRandomizedFilename(): ${filename} should end with ${ext}`, ).toBe(ext); } }); diff --git a/app/__test__/modules/AppAuth.spec.ts b/app/__test__/modules/AppAuth.spec.ts index f0ecc86..332b999 100644 --- a/app/__test__/modules/AppAuth.spec.ts +++ b/app/__test__/modules/AppAuth.spec.ts @@ -43,10 +43,10 @@ describe("AppAuth", () => { { enabled: true, jwt: { - secret: "123456" - } + secret: "123456", + }, }, - ctx + ctx, ); await auth.build(); @@ -63,12 +63,12 @@ describe("AppAuth", () => { const res = await app.request("/password/register", { method: "POST", headers: { - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: JSON.stringify({ email: "some@body.com", - password: "123456" - }) + password: "123456", + }), }); enableConsoleLog(); expect(res.status).toBe(200); @@ -85,10 +85,10 @@ describe("AppAuth", () => { auth: { enabled: true, jwt: { - secret: "123456" - } - } - } + secret: "123456", + }, + }, + }, }); await app.build(); @@ -109,14 +109,14 @@ describe("AppAuth", () => { initialConfig: { auth: { entity_name: "users", - enabled: true + enabled: true, }, data: em({ users: entity("users", { - additional: text() - }) - }).toJSON() - } + additional: text(), + }), + }).toJSON(), + }, }); await app.build(); @@ -132,21 +132,21 @@ describe("AppAuth", () => { const app = createApp({ initialConfig: { auth: { - enabled: true + enabled: true, }, data: em({ users: entity("users", { strategy: text({ fillable: true, - hidden: false + hidden: false, }), strategy_value: text({ fillable: true, - hidden: false - }) - }) - }).toJSON() - } + hidden: false, + }), + }), + }).toJSON(), + }, }); await app.build(); diff --git a/app/__test__/modules/AppMedia.spec.ts b/app/__test__/modules/AppMedia.spec.ts index b5ce17f..1423fd6 100644 --- a/app/__test__/modules/AppMedia.spec.ts +++ b/app/__test__/modules/AppMedia.spec.ts @@ -19,16 +19,16 @@ describe("AppMedia", () => { adapter: { type: "local", config: { - path: "./" - } - } + path: "./", + }, + }, }, data: em({ media: entity("media", { - additional: text() - }) - }).toJSON() - } + additional: text(), + }), + }).toJSON(), + }, }); await app.build(); @@ -49,7 +49,7 @@ describe("AppMedia", () => { "modified_at", "reference", "entity_id", - "metadata" + "metadata", ]); }); }); diff --git a/app/__test__/modules/Module.spec.ts b/app/__test__/modules/Module.spec.ts index 5c20ca5..bcb6aa8 100644 --- a/app/__test__/modules/Module.spec.ts +++ b/app/__test__/modules/Module.spec.ts @@ -47,7 +47,7 @@ describe("Module", async () => { prt = { ensureEntity: this.ensureEntity.bind(this), ensureIndex: this.ensureIndex.bind(this), - ensureSchema: this.ensureSchema.bind(this) + ensureSchema: this.ensureSchema.bind(this), }; get em() { @@ -60,7 +60,7 @@ describe("Module", async () => { Object.values(_em.entities), new DummyConnection(), _em.relations, - _em.indices + _em.indices, ); return new M({} as any, { em, flags: Module.ctx_flags } as any); } @@ -69,14 +69,14 @@ describe("Module", async () => { entities: _em.entities.map((e) => ({ name: e.name, fields: e.fields.map((f) => f.name), - type: e.type + type: e.type, })), indices: _em.indices.map((i) => ({ name: i.name, entity: i.entity.name, fields: i.fields.map((f) => f.name), - unique: i.unique - })) + unique: i.unique, + })), }; } @@ -88,15 +88,15 @@ describe("Module", async () => { expect(flat(make(initial).em)).toEqual({ entities: [], - indices: [] + indices: [], }); }); test("init", () => { const initial = em({ users: entity("u", { - name: text() - }) + name: text(), + }), }); const m = make(initial); @@ -107,18 +107,18 @@ describe("Module", async () => { { name: "u", fields: ["id", "name"], - type: "regular" - } + type: "regular", + }, ], - indices: [] + indices: [], }); }); test("ensure entity", () => { const initial = em({ users: entity("u", { - name: text() - }) + name: text(), + }), }); const m = make(initial); @@ -127,17 +127,17 @@ describe("Module", async () => { { name: "u", fields: ["id", "name"], - type: "regular" - } + type: "regular", + }, ], - indices: [] + indices: [], }); // this should add a new entity m.prt.ensureEntity( entity("p", { - title: text() - }) + title: text(), + }), ); // this should only add the field "important" @@ -145,11 +145,11 @@ describe("Module", async () => { entity( "u", { - important: text() + important: text(), }, undefined, - "system" - ) + "system", + ), ); expect(m.ctx.flags.sync_required).toBe(true); @@ -159,22 +159,22 @@ describe("Module", async () => { name: "u", fields: ["id", "name", "important"], // ensured type must be present - type: "system" + type: "system", }, { name: "p", fields: ["id", "title"], - type: "regular" - } + type: "regular", + }, ], - indices: [] + indices: [], }); }); test("ensure index", () => { const users = entity("u", { name: text(), - title: text() + title: text(), }); const initial = em({ users }, ({ index }, { users }) => { index(users).on(["title"]); @@ -189,23 +189,23 @@ describe("Module", async () => { { name: "u", fields: ["id", "name", "title"], - type: "regular" - } + type: "regular", + }, ], indices: [ { name: "idx_u_title", entity: "u", fields: ["title"], - unique: false + unique: false, }, { name: "idx_u_name", entity: "u", fields: ["name"], - unique: false - } - ] + unique: false, + }, + ], }); }); }); diff --git a/app/__test__/modules/ModuleManager.spec.ts b/app/__test__/modules/ModuleManager.spec.ts index 64e3cde..c556795 100644 --- a/app/__test__/modules/ModuleManager.spec.ts +++ b/app/__test__/modules/ModuleManager.spec.ts @@ -39,10 +39,10 @@ describe("ModuleManager", async () => { basepath: "/api/data2", entities: { test: entity("test", { - content: text() - }).toJSON() - } - } + content: text(), + }).toJSON(), + }, + }, }); //const { version, ...json } = mm.toJSON() as any; @@ -69,10 +69,10 @@ describe("ModuleManager", async () => { basepath: "/api/data2", entities: { test: entity("test", { - content: text() - }).toJSON() - } - } + content: text(), + }).toJSON(), + }, + }, }; //const { version, ...json } = mm.toJSON() as any; @@ -105,7 +105,7 @@ describe("ModuleManager", async () => { const c2 = getDummyConnection(); const db = c2.dummyConnection.kysely; const mm2 = new ModuleManager(c2.dummyConnection, { - initial: { version: version - 1, ...json } + initial: { version: version - 1, ...json }, }); await mm2.syncConfigTable(); @@ -129,7 +129,7 @@ describe("ModuleManager", async () => { const db = c2.dummyConnection.kysely; const mm2 = new ModuleManager(c2.dummyConnection, { - initial: { version: version - 1, ...json } + initial: { version: version - 1, ...json }, }); await mm2.syncConfigTable(); await db @@ -157,8 +157,8 @@ describe("ModuleManager", async () => { ...json, data: { ...json.data, - basepath: "/api/data2" - } + basepath: "/api/data2", + }, }; await db .insertInto(TABLE_NAME) @@ -190,9 +190,9 @@ describe("ModuleManager", async () => { ...configs.server, admin: { ...configs.server.admin, - color_scheme: "dark" - } - } + color_scheme: "dark", + }, + }, }); }); @@ -201,11 +201,11 @@ describe("ModuleManager", async () => { const partial = { auth: { - enabled: true - } + enabled: true, + }, }; const mm = new ModuleManager(dummyConnection, { - initial: partial + initial: partial, }); await mm.build(); @@ -227,9 +227,9 @@ describe("ModuleManager", async () => { const mm2 = new ModuleManager(c2.dummyConnection, { initial: { auth: { - basepath: "/shouldnt/take/this" - } - } + basepath: "/shouldnt/take/this", + }, + }, }); await mm2.syncConfigTable(); const payload = { @@ -237,15 +237,15 @@ describe("ModuleManager", async () => { auth: { ...json.auth, enabled: true, - basepath: "/api/auth2" - } + basepath: "/api/auth2", + }, }; await db .insertInto(TABLE_NAME) .values({ type: "config", json: JSON.stringify(payload), - version: CURRENT_VERSION + version: CURRENT_VERSION, }) .execute(); await mm2.build(); @@ -256,7 +256,7 @@ describe("ModuleManager", async () => { describe("revert", async () => { const failingModuleSchema = Type.Object({ - value: Type.Optional(Type.Number()) + value: Type.Optional(Type.Number()), }); class FailingModule extends Module { getSchema() { @@ -301,8 +301,8 @@ describe("ModuleManager", async () => { const mm = new TestModuleManager(dummyConnection, { initial: { // @ts-ignore - failing: { value: 2 } - } + failing: { value: 2 }, + }, }); await mm.build(); expect(mm.configs()["failing"].value).toBe(2); @@ -313,8 +313,8 @@ describe("ModuleManager", async () => { const mm = new TestModuleManager(dummyConnection, { initial: { // @ts-ignore - failing: { value: -1 } - } + failing: { value: -1 }, + }, }); expect(mm.build()).rejects.toThrow(/value must be positive/); expect(mm.configs()["failing"].value).toBe(-1); @@ -326,7 +326,7 @@ describe("ModuleManager", async () => { const mm = new TestModuleManager(dummyConnection, { onUpdated: async () => { mockOnUpdated(); - } + }, }); await mm.build(); // @ts-ignore @@ -342,11 +342,11 @@ describe("ModuleManager", async () => { const mm = new TestModuleManager(dummyConnection, { initial: { // @ts-ignore - failing: { value: 1 } + failing: { value: 1 }, }, onUpdated: async () => { mockOnUpdated(); - } + }, }); await mm.build(); expect(mm.configs()["failing"].value).toBe(1); @@ -354,7 +354,7 @@ describe("ModuleManager", async () => { // now safe mutate // @ts-ignore expect(mm.mutateConfigSafe("failing").set({ value: -2 })).rejects.toThrow( - /value must be positive/ + /value must be positive/, ); expect(mm.configs()["failing"].value).toBe(1); expect(mockOnUpdated).toHaveBeenCalled(); diff --git a/app/__test__/modules/module-test-suite.ts b/app/__test__/modules/module-test-suite.ts index d4f0f95..4ad7e5d 100644 --- a/app/__test__/modules/module-test-suite.ts +++ b/app/__test__/modules/module-test-suite.ts @@ -19,7 +19,7 @@ export function makeCtx(overrides?: Partial): ModuleBuildCon guard: new Guard(), flags: Module.ctx_flags, logger: new DebugLogger(false), - ...overrides + ...overrides, }; } diff --git a/app/__test__/ui/json-form.spec.ts b/app/__test__/ui/json-form.spec.ts index 2fa535a..c1331f2 100644 --- a/app/__test__/ui/json-form.spec.ts +++ b/app/__test__/ui/json-form.spec.ts @@ -16,7 +16,7 @@ describe("json form", () => { ["0", { type: "boolean" }, false], ["on", { type: "boolean" }, true], ["off", { type: "boolean" }, false], - ["null", { type: "null" }, null] + ["null", { type: "null" }, null], ] satisfies [string, Exclude, any][]; for (const [input, schema, output] of examples) { @@ -35,7 +35,7 @@ describe("json form", () => { ["array", "array", true], ["object", "array", false], [["string", "number"], "number", true], - ["number", ["string", "number"], true] + ["number", ["string", "number"], true], ] satisfies [IsTypeType, IsTypeType, boolean][]; for (const [type, schemaType, output] of examples) { @@ -48,7 +48,7 @@ describe("json form", () => { ["#/nested/property/0/name", "#/nested/property/0"], ["#/nested/property/0", "#/nested/property"], ["#/nested/property", "#/nested"], - ["#/nested", "#"] + ["#/nested", "#"], ]; for (const [input, output] of examples) { @@ -61,16 +61,16 @@ describe("json form", () => { [ "#/description", { type: "object", properties: { description: { type: "string" } } }, - false + false, ], [ "#/description", { type: "object", required: ["description"], - properties: { description: { type: "string" } } + properties: { description: { type: "string" } }, }, - true + true, ], [ "#/nested/property", @@ -79,11 +79,11 @@ describe("json form", () => { properties: { nested: { type: "object", - properties: { property: { type: "string" } } - } - } + properties: { property: { type: "string" } }, + }, + }, }, - false + false, ], [ "#/nested/property", @@ -93,12 +93,12 @@ describe("json form", () => { nested: { type: "object", required: ["property"], - properties: { property: { type: "string" } } - } - } + properties: { property: { type: "string" } }, + }, + }, }, - true - ] + true, + ], ] satisfies [string, Exclude, boolean][]; for (const [pointer, schema, output] of examples) { @@ -113,7 +113,7 @@ describe("json form", () => { ["tags", "0", "0.tags"], ["tags", 0, "0.tags"], ["nested.property", "prefix", "prefix.nested.property"], - ["nested.property", "", "nested.property"] + ["nested.property", "", "nested.property"], ] satisfies [string, any, string][]; for (const [path, prefix, output] of examples) { @@ -128,7 +128,7 @@ describe("json form", () => { ["tags", "0", "tags.0"], ["tags", 0, "tags.0"], ["nested.property", "suffix", "nested.property.suffix"], - ["nested.property", "", "nested.property"] + ["nested.property", "", "nested.property"], ] satisfies [string, any, string][]; for (const [path, suffix, output] of examples) { diff --git a/app/build.esbuild.ts b/app/build.esbuild.ts index 6cb1e13..d9fa6f4 100644 --- a/app/build.esbuild.ts +++ b/app/build.esbuild.ts @@ -19,11 +19,11 @@ const baseOptions: Partial> & { plugins?: format: "esm", drop: ["console", "debugger"], loader: { - ".svg": "dataurl" + ".svg": "dataurl", }, define: { - __isDev: "0" - } + __isDev: "0", + }, }; // @ts-ignore @@ -40,7 +40,7 @@ const builds: Record = { "src/core/index.ts", "src/core/utils/index.ts", "src/ui/index.ts", - "src/ui/main.css" + "src/ui/main.css", ], outdir: "dist", outExtension: { ".js": format === "esm" ? ".js" : ".cjs" }, @@ -49,7 +49,7 @@ const builds: Record = { bundle: true, plugins: [postcss()], //target: "es2022", - format + format, }), /*components: (format = "esm") => ({ ...baseOptions, @@ -84,11 +84,11 @@ const builds: Record = { format, loader: { ".svg": "dataurl", - ".js": "jsx" + ".js": "jsx", }, define: { __isDev: "0", - "process.env.NODE_ENV": '"production"' + "process.env.NODE_ENV": '"production"', }, chunkNames: "chunks/[name]-[hash]", plugins: [ @@ -100,7 +100,7 @@ const builds: Record = { return { name, path: output, - mime: guessMimeType(name) + mime: guessMimeType(name), }; }; for (const { output, meta } of info) { @@ -113,9 +113,9 @@ const builds: Record = { const manifest_file = "dist/static/manifest.json"; await Bun.write(manifest_file, JSON.stringify(manifest, null, 2)); console.log(`Manifest written to ${manifest_file}`, manifest); - }) - ] - }) + }), + ], + }), }; function adapter(adapter: string, overrides: Partial = {}): BuildOptions { @@ -135,12 +135,12 @@ function adapter(adapter: string, overrides: Partial = {}) "react*", "next*", "libsql", - "@libsql*" + "@libsql*", ], splitting: false, treeShaking: true, bundle: true, - ...overrides + ...overrides, }; } const adapters = [ @@ -152,7 +152,7 @@ const adapters = [ adapter("remix", { format: "cjs" }), adapter("bun"), adapter("node", { platform: "node", format: "esm" }), - adapter("node", { platform: "node", format: "cjs" }) + adapter("node", { platform: "node", format: "cjs" }), ]; const collect = [ @@ -161,7 +161,7 @@ const collect = [ //builds.components(), builds.backend("cjs"), //builds.components("cjs"), - ...adapters + ...adapters, ]; if (watch) { @@ -172,7 +172,7 @@ if (watch) { } = { timeout: undefined, cleanup: undefined, - building: undefined + building: undefined, }; async function rebuildTypes() { @@ -190,9 +190,9 @@ if (watch) { onExit: () => { _state.building = undefined; console.log("Types rebuilt"); - } + }, }); - } + }, }); }, 1000); } @@ -209,9 +209,9 @@ if (watch) { console.log(`rebuilt ${name} with ${result.errors.length} errors`); rebuildTypes(); }); - } - } - ] + }, + }, + ], }); ctx.watch(); } @@ -235,9 +235,9 @@ if (watch) { const from = String(i).padStart(String(count).length); console.log(`[${from}/${count}] built ${name} with ${errors} errors`); }); - } - } - ] + }, + }, + ], }); } @@ -249,7 +249,7 @@ if (watch) { Bun.spawn(["bun", "build:types"], { onExit: () => { console.log("Types rebuilt"); - } + }, }); } diff --git a/app/build.ts b/app/build.ts index ba14bc5..ff2f981 100644 --- a/app/build.ts +++ b/app/build.ts @@ -27,9 +27,9 @@ function buildTypes() { onExit: () => { console.log("Types aliased"); types_running = false; - } + }, }); - } + }, }); } @@ -63,11 +63,11 @@ async function buildApi() { splitting: false, treeshake: true, loader: { - ".svg": "dataurl" + ".svg": "dataurl", }, onSuccess: async () => { delayTypes(); - } + }, }); } @@ -90,7 +90,7 @@ async function buildUi() { "use-sync-external-store", /codemirror/, "@xyflow/react", - "@mantine/core" + "@mantine/core", ], metafile: true, platform: "browser", @@ -99,14 +99,14 @@ async function buildUi() { bundle: true, treeshake: true, loader: { - ".svg": "dataurl" + ".svg": "dataurl", }, esbuildOptions: (options) => { options.logLevel = "silent"; }, onSuccess: async () => { delayTypes(); - } + }, }); } @@ -128,7 +128,7 @@ async function buildUiElements() { "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", - "use-sync-external-store" + "use-sync-external-store", ], metafile: true, platform: "browser", @@ -137,12 +137,12 @@ async function buildUiElements() { bundle: true, treeshake: true, loader: { - ".svg": "dataurl" + ".svg": "dataurl", }, esbuildOptions: (options) => { options.alias = { // not important for elements, mock to reduce bundle - "tailwind-merge": "./src/ui/elements/mocks/tailwind-merge.ts" + "tailwind-merge": "./src/ui/elements/mocks/tailwind-merge.ts", }; }, onSuccess: async () => { @@ -152,7 +152,7 @@ async function buildUiElements() { await Bun.write(path, bundle.replaceAll("ui/client", "bknd/client")); delayTypes(); - } + }, }); } @@ -176,15 +176,15 @@ function baseConfig(adapter: string, overrides: Partial = {}): tsu ...overrides, define: { __isDev: "0", - ...overrides.define + ...overrides.define, }, external: [ /^cloudflare*/, /^@?(hono|libsql).*?/, /^(bknd|react|next|node).*?/, /.*\.(html)$/, - ...(Array.isArray(overrides.external) ? overrides.external : []) - ] + ...(Array.isArray(overrides.external) ? overrides.external : []), + ], }; } @@ -193,7 +193,7 @@ async function buildAdapters() { await tsup.build({ ...baseConfig(""), entry: ["src/adapter/index.ts"], - outDir: "dist/adapter" + outDir: "dist/adapter", }); // specific adatpers @@ -202,23 +202,23 @@ async function buildAdapters() { await tsup.build(baseConfig("astro")); await tsup.build( baseConfig("cloudflare", { - external: [/^kysely/] - }) + external: [/^kysely/], + }), ); await tsup.build({ ...baseConfig("vite"), - platform: "node" + platform: "node", }); await tsup.build({ ...baseConfig("nextjs"), - platform: "node" + platform: "node", }); await tsup.build({ ...baseConfig("node"), - platform: "node" + platform: "node", }); } diff --git a/app/internal/esbuild.entry-output-meta.plugin.ts b/app/internal/esbuild.entry-output-meta.plugin.ts index 6bd3ab4..0521c51 100644 --- a/app/internal/esbuild.entry-output-meta.plugin.ts +++ b/app/internal/esbuild.entry-output-meta.plugin.ts @@ -5,8 +5,8 @@ export const entryOutputMeta = ( outputs: { output: string; meta: Metafile["outputs"][string]; - }[] - ) => void | Promise + }[], + ) => void | Promise, ): Plugin => ({ name: "report-entry-output-plugin", setup(build) { @@ -29,5 +29,5 @@ export const entryOutputMeta = ( await onComplete?.(outputs); } }); - } + }, }); diff --git a/app/postcss.config.js b/app/postcss.config.js index 0c65377..5633993 100644 --- a/app/postcss.config.js +++ b/app/postcss.config.js @@ -11,8 +11,8 @@ export default { "mantine-breakpoint-sm": "48em", "mantine-breakpoint-md": "62em", "mantine-breakpoint-lg": "75em", - "mantine-breakpoint-xl": "88em" - } - } - } + "mantine-breakpoint-xl": "88em", + }, + }, + }, }; diff --git a/app/src/Api.ts b/app/src/Api.ts index 2e35cee..536ae0d 100644 --- a/app/src/Api.ts +++ b/app/src/Api.ts @@ -153,7 +153,7 @@ export class Api { return { token: this.token, user: this.user, - verified: this.verified + verified: this.verified, }; } @@ -198,7 +198,7 @@ export class Api { token: this.token, headers: this.options.headers, token_transport: this.token_transport, - verbose: this.options.verbose + verbose: this.options.verbose, }); } @@ -211,9 +211,9 @@ export class Api { this.auth = new AuthApi( { ...baseParams, - onTokenUpdate: (token) => this.updateToken(token, true) + onTokenUpdate: (token) => this.updateToken(token, true), }, - fetcher + fetcher, ); this.media = new MediaApi(baseParams, fetcher); } diff --git a/app/src/App.ts b/app/src/App.ts index fa79ebc..1cf88ce 100644 --- a/app/src/App.ts +++ b/app/src/App.ts @@ -8,7 +8,7 @@ import { type ModuleBuildContext, ModuleManager, type ModuleManagerOptions, - type Modules + type Modules, } from "modules/ModuleManager"; import * as SystemPermissions from "modules/permissions"; import { AdminController, type AdminControllerOptions } from "modules/server/AdminController"; @@ -61,7 +61,7 @@ export class App { constructor( private connection: Connection, _initialConfig?: InitialModuleConfigs, - private options?: AppOptions + private options?: AppOptions, ) { this.plugins = options?.plugins ?? []; this.modules = new ModuleManager(connection, { @@ -91,7 +91,7 @@ export class App { c.set("app", this); await next(); }); - } + }, }); this.modules.ctx().emgr.registerEvents(AppEvents); } @@ -148,8 +148,8 @@ export class App { { get: (_, module: keyof Modules) => { return this.modules.get(module); - } - } + }, + }, ) as Modules; } @@ -203,7 +203,7 @@ export function createApp(config: CreateAppConfig = {}) { } else if (typeof config.connection === "object") { if ("type" in config.connection) { $console.warn( - "Using deprecated connection type 'libsql', use the 'config' object directly." + "Using deprecated connection type 'libsql', use the 'config' object directly.", ); connection = new LibsqlConnection(config.connection.config); } else { diff --git a/app/src/adapter/astro/astro.adapter.ts b/app/src/adapter/astro/astro.adapter.ts index c15d570..61971e3 100644 --- a/app/src/adapter/astro/astro.adapter.ts +++ b/app/src/adapter/astro/astro.adapter.ts @@ -17,7 +17,7 @@ export type Options = { export async function getApi(Astro: TAstro, options: Options = { mode: "static" }) { const api = new Api({ host: new URL(Astro.request.url).origin, - headers: options.mode === "dynamic" ? Astro.request.headers : undefined + headers: options.mode === "dynamic" ? Astro.request.headers : undefined, }); await api.verifyAuth(); return api; diff --git a/app/src/adapter/bun/bun.adapter.ts b/app/src/adapter/bun/bun.adapter.ts index 851c54e..65ab616 100644 --- a/app/src/adapter/bun/bun.adapter.ts +++ b/app/src/adapter/bun/bun.adapter.ts @@ -19,7 +19,7 @@ export async function createApp({ distPath, ...config }: RuntimeBkndConfig = {}) registerLocalMediaAdapter(); app = await createRuntimeApp({ ...config, - serveStatic: serveStatic({ root }) + serveStatic: serveStatic({ root }), }); } @@ -46,10 +46,10 @@ export function serve({ options, onBuilt, buildConfig, - distPath + distPath, }); return app.fetch(request); - } + }, }); console.log(`Server is running on http://localhost:${port}`); diff --git a/app/src/adapter/cloudflare/D1Connection.ts b/app/src/adapter/cloudflare/D1Connection.ts index 810cca8..768ca44 100644 --- a/app/src/adapter/cloudflare/D1Connection.ts +++ b/app/src/adapter/cloudflare/D1Connection.ts @@ -12,7 +12,7 @@ export type D1ConnectionConfig = { class CustomD1Dialect extends D1Dialect { override createIntrospector(db: Kysely): DatabaseIntrospector { return new SqliteIntrospector(db, { - excludeTables: ["_cf_KV"] + excludeTables: ["_cf_KV"], }); } } @@ -23,7 +23,7 @@ export class D1Connection extends SqliteConnection { const kysely = new Kysely({ dialect: new CustomD1Dialect({ database: config.binding }), - plugins + plugins, }); super(kysely, {}, plugins); } @@ -37,7 +37,7 @@ export class D1Connection extends SqliteConnection { } protected override async batch( - queries: [...Queries] + queries: [...Queries], ): Promise<{ [K in keyof Queries]: Awaited>; }> { @@ -47,7 +47,7 @@ export class D1Connection extends SqliteConnection { queries.map((q) => { const { sql, parameters } = q.compile(); return db.prepare(sql).bind(...parameters); - }) + }), ); // let it run through plugins diff --git a/app/src/adapter/cloudflare/StorageR2Adapter.ts b/app/src/adapter/cloudflare/StorageR2Adapter.ts index aedeb10..5432e79 100644 --- a/app/src/adapter/cloudflare/StorageR2Adapter.ts +++ b/app/src/adapter/cloudflare/StorageR2Adapter.ts @@ -8,9 +8,9 @@ import { getBindings } from "./bindings"; export function makeSchema(bindings: string[] = []) { return Type.Object( { - binding: bindings.length > 0 ? StringEnum(bindings) : Type.Optional(Type.String()) + binding: bindings.length > 0 ? StringEnum(bindings) : Type.Optional(Type.String()), }, - { title: "R2", description: "Cloudflare R2 storage" } + { title: "R2", description: "Cloudflare R2 storage" }, ); } @@ -36,10 +36,10 @@ export function registerMedia(env: Record) { override toJSON() { return { ...super.toJSON(), - config: this.config + config: this.config, }; } - } + }, ); } @@ -67,13 +67,13 @@ export class StorageR2Adapter implements StorageAdapter { } } async listObjects( - prefix?: string + prefix?: string, ): Promise<{ key: string; last_modified: Date; size: number }[]> { const list = await this.bucket.list({ limit: 50 }); return list.objects.map((item) => ({ key: item.key, size: item.size, - last_modified: item.uploaded + last_modified: item.uploaded, })); } @@ -89,7 +89,7 @@ export class StorageR2Adapter implements StorageAdapter { let object: R2ObjectBody | null; const responseHeaders = new Headers({ "Accept-Ranges": "bytes", - "Content-Type": guess(key) + "Content-Type": guess(key), }); //console.log("getObject:headers", headersToObject(headers)); @@ -98,7 +98,7 @@ export class StorageR2Adapter implements StorageAdapter { ? {} // miniflare doesn't support range requests : { range: headers, - onlyIf: headers + onlyIf: headers, }; object = (await this.bucket.get(key, options)) as R2ObjectBody; @@ -130,7 +130,7 @@ export class StorageR2Adapter implements StorageAdapter { return new Response(object.body, { status: object.range ? 206 : 200, - headers: responseHeaders + headers: responseHeaders, }); } @@ -139,7 +139,7 @@ export class StorageR2Adapter implements StorageAdapter { if (!metadata || Object.keys(metadata).length === 0) { // guessing is especially required for dev environment (miniflare) metadata = { - contentType: guess(object.key) + contentType: guess(object.key), }; } @@ -157,7 +157,7 @@ export class StorageR2Adapter implements StorageAdapter { return { type: String(head.httpMetadata?.contentType ?? guess(key)), - size: head.size + size: head.size, }; } @@ -172,7 +172,7 @@ export class StorageR2Adapter implements StorageAdapter { toJSON(secrets?: boolean) { return { type: this.getName(), - config: {} + config: {}, }; } } diff --git a/app/src/adapter/cloudflare/bindings.ts b/app/src/adapter/cloudflare/bindings.ts index 491d0a8..82eca2a 100644 --- a/app/src/adapter/cloudflare/bindings.ts +++ b/app/src/adapter/cloudflare/bindings.ts @@ -15,7 +15,7 @@ export function getBindings(env: any, type: T): Bindin if (env[key] && (env[key] as any).constructor.name === type) { bindings.push({ key, - value: env[key] as BindingTypeMap[T] + value: env[key] as BindingTypeMap[T], }); } } catch (e) {} diff --git a/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts b/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts index 4486609..7483d52 100644 --- a/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts +++ b/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts @@ -84,7 +84,7 @@ export function serve(config: CloudflareBkndConfig = {}) { hono.all("*", async (c, next) => { const res = await serveStatic({ path: `./${pathname}`, - manifest: config.manifest! + manifest: config.manifest!, })(c as any, next); if (res instanceof Response) { const ttl = 60 * 60 * 24 * 365; @@ -114,6 +114,6 @@ export function serve(config: CloudflareBkndConfig = {}) { default: throw new Error(`Unknown mode ${mode}`); } - } + }, }; } diff --git a/app/src/adapter/cloudflare/index.ts b/app/src/adapter/cloudflare/index.ts index a10dc53..e89198e 100644 --- a/app/src/adapter/cloudflare/index.ts +++ b/app/src/adapter/cloudflare/index.ts @@ -10,7 +10,7 @@ export { getBindings, type BindingTypeMap, type GetBindingType, - type BindingMap + type BindingMap, } from "./bindings"; export function d1(config: D1ConnectionConfig) { diff --git a/app/src/adapter/cloudflare/modes/cached.ts b/app/src/adapter/cloudflare/modes/cached.ts index 48f6926..c126ff7 100644 --- a/app/src/adapter/cloudflare/modes/cached.ts +++ b/app/src/adapter/cloudflare/modes/cached.ts @@ -31,13 +31,13 @@ export async function getCached(config: CloudflareBkndConfig, { env, ctx, ...arg async ({ params: { app } }) => { saveConfig(app.toJSON(true)); }, - "sync" + "sync", ); await config.beforeBuild?.(app); }, - adminOptions: { html: config.html } + adminOptions: { html: config.html }, }, - { env, ctx, ...args } + { env, ctx, ...args }, ); if (!cachedConfig) { diff --git a/app/src/adapter/cloudflare/modes/durable.ts b/app/src/adapter/cloudflare/modes/durable.ts index bd58f85..63fce34 100644 --- a/app/src/adapter/cloudflare/modes/durable.ts +++ b/app/src/adapter/cloudflare/modes/durable.ts @@ -23,7 +23,7 @@ export async function getDurable(config: CloudflareBkndConfig, ctx: Context) { config: create_config, html: config.html, keepAliveSeconds: config.keepAliveSeconds, - setAdminHtml: config.setAdminHtml + setAdminHtml: config.setAdminHtml, }); const headers = new Headers(res.headers); @@ -32,7 +32,7 @@ export async function getDurable(config: CloudflareBkndConfig, ctx: Context) { return new Response(res.body, { status: res.status, statusText: res.statusText, - headers + headers, }); } @@ -48,7 +48,7 @@ export class DurableBkndApp extends DurableObject { html?: string; keepAliveSeconds?: number; setAdminHtml?: boolean; - } + }, ) { let buildtime = 0; if (!this.app) { @@ -73,7 +73,7 @@ export class DurableBkndApp extends DurableObject { return c.json({ id: this.id, keepAliveSeconds: options?.keepAliveSeconds ?? 0, - colo: context.colo + colo: context.colo, }); }); @@ -82,7 +82,7 @@ export class DurableBkndApp extends DurableObject { adminOptions: { html: options.html }, beforeBuild: async (app) => { await this.beforeBuild(app); - } + }, }); buildtime = performance.now() - start; @@ -101,7 +101,7 @@ export class DurableBkndApp extends DurableObject { return new Response(res.body, { status: res.status, statusText: res.statusText, - headers + headers, }); } diff --git a/app/src/adapter/cloudflare/modes/fresh.ts b/app/src/adapter/cloudflare/modes/fresh.ts index 7a2af67..b13c537 100644 --- a/app/src/adapter/cloudflare/modes/fresh.ts +++ b/app/src/adapter/cloudflare/modes/fresh.ts @@ -6,9 +6,9 @@ export async function makeApp(config: CloudflareBkndConfig, ctx: Context) { return await createRuntimeApp( { ...makeCfConfig(config, ctx), - adminOptions: config.html ? { html: config.html } : undefined + adminOptions: config.html ? { html: config.html } : undefined, }, - ctx + ctx, ); } diff --git a/app/src/adapter/index.ts b/app/src/adapter/index.ts index 1c48f8b..99f9100 100644 --- a/app/src/adapter/index.ts +++ b/app/src/adapter/index.ts @@ -34,7 +34,7 @@ export function makeConfig(config: BkndConfig, args?: Args): C export async function createFrameworkApp( config: FrameworkBkndConfig, - args?: Args + args?: Args, ): Promise { const app = App.create(makeConfig(config, args)); @@ -44,7 +44,7 @@ export async function createFrameworkApp( async () => { await config.onBuilt?.(app); }, - "sync" + "sync", ); } @@ -63,7 +63,7 @@ export async function createRuntimeApp( serveStatic?: MiddlewareHandler | [string, MiddlewareHandler]; adminOptions?: AdminControllerOptions | false; }, - env?: Env + env?: Env, ): Promise { const app = App.create(makeConfig(config, env)); @@ -82,7 +82,7 @@ export async function createRuntimeApp( app.registerAdminController(adminOptions); } }, - "sync" + "sync", ); await config.beforeBuild?.(app); diff --git a/app/src/adapter/nextjs/nextjs.adapter.ts b/app/src/adapter/nextjs/nextjs.adapter.ts index adaf853..fe8346e 100644 --- a/app/src/adapter/nextjs/nextjs.adapter.ts +++ b/app/src/adapter/nextjs/nextjs.adapter.ts @@ -26,7 +26,7 @@ export function createApi({ req }: GetServerSidePropsContext) { const request = nodeRequestToRequest(req); return new Api({ host: new URL(request.url).origin, - headers: request.headers + headers: request.headers, }); } @@ -40,7 +40,7 @@ export function withApi(handler: (ctx: GetServerSidePropsContext & { api: Api function getCleanRequest( req: Request, - { cleanSearch = ["route"] }: Pick + { cleanSearch = ["route"] }: Pick, ) { const url = new URL(req.url); cleanSearch?.forEach((k) => url.searchParams.delete(k)); @@ -48,7 +48,7 @@ function getCleanRequest( return new Request(url.toString(), { method: req.method, headers: req.headers, - body: req.body + body: req.body, }); } diff --git a/app/src/adapter/node/index.ts b/app/src/adapter/node/index.ts index b70a274..5d71d8c 100644 --- a/app/src/adapter/node/index.ts +++ b/app/src/adapter/node/index.ts @@ -1,7 +1,7 @@ import { registries } from "bknd"; import { type LocalAdapterConfig, - StorageLocalAdapter + StorageLocalAdapter, } from "../../media/storage/adapters/StorageLocalAdapter"; export * from "./node.adapter"; diff --git a/app/src/adapter/node/node.adapter.ts b/app/src/adapter/node/node.adapter.ts index 326ab92..97a8b82 100644 --- a/app/src/adapter/node/node.adapter.ts +++ b/app/src/adapter/node/node.adapter.ts @@ -24,7 +24,7 @@ export function serve({ }: NodeBkndConfig = {}) { const root = path.relative( process.cwd(), - path.resolve(distPath ?? relativeDistPath ?? "./node_modules/bknd/dist", "static") + path.resolve(distPath ?? relativeDistPath ?? "./node_modules/bknd/dist", "static"), ); if (relativeDistPath) { console.warn("relativeDistPath is deprecated, please use distPath instead"); @@ -41,16 +41,16 @@ export function serve({ registerLocalMediaAdapter(); app = await createRuntimeApp({ ...config, - serveStatic: serveStatic({ root }) + serveStatic: serveStatic({ root }), }); } return app.fetch(req); - } + }, }, (connInfo) => { console.log(`Server is running on http://localhost:${connInfo.port}`); listener?.(connInfo); - } + }, ); } diff --git a/app/src/adapter/remix/remix.adapter.ts b/app/src/adapter/remix/remix.adapter.ts index 38b81e8..1112500 100644 --- a/app/src/adapter/remix/remix.adapter.ts +++ b/app/src/adapter/remix/remix.adapter.ts @@ -28,7 +28,7 @@ export async function getApp(config: RemixBkndConfig, args?: RemixContext) { } export function serve( - config: RemixBkndConfig = {} + config: RemixBkndConfig = {}, ) { return async (args: Args) => { app = await createFrameworkApp(config, args); diff --git a/app/src/adapter/utils.ts b/app/src/adapter/utils.ts index f804133..b18b4c8 100644 --- a/app/src/adapter/utils.ts +++ b/app/src/adapter/utils.ts @@ -20,6 +20,6 @@ export function nodeRequestToRequest(req: IncomingMessage): Request { const method = req.method || "GET"; return new Request(url, { method, - headers + headers, }); } diff --git a/app/src/adapter/vite/dev-server-config.ts b/app/src/adapter/vite/dev-server-config.ts index 372e470..9be18fd 100644 --- a/app/src/adapter/vite/dev-server-config.ts +++ b/app/src/adapter/vite/dev-server-config.ts @@ -8,7 +8,7 @@ export const devServerConfig = { /^\/@.+$/, /\/components.*?\.json.*/, // @todo: improve /^\/(public|assets|static)\/.+/, - /^\/node_modules\/.*/ + /^\/node_modules\/.*/, ] as any, - injectClientScript: false + injectClientScript: false, } as const; diff --git a/app/src/adapter/vite/vite.adapter.ts b/app/src/adapter/vite/vite.adapter.ts index dee0603..bb7eb59 100644 --- a/app/src/adapter/vite/vite.adapter.ts +++ b/app/src/adapter/vite/vite.adapter.ts @@ -24,7 +24,7 @@ window.__vite_plugin_react_preamble_installed__ = true ${addBkndContext ? "" : ""} -` +`, ); } @@ -39,12 +39,12 @@ async function createApp(config: ViteBkndConfig = {}, env?: any) { : { html: config.html, forceDev: config.forceDev ?? { - mainPath: "/src/main.tsx" - } + mainPath: "/src/main.tsx", + }, }, - serveStatic: ["/assets/*", serveStatic({ root: config.distPath ?? "./" })] + serveStatic: ["/assets/*", serveStatic({ root: config.distPath ?? "./" })], }, - env + env, ); } @@ -53,7 +53,7 @@ export function serveFresh(config: Omit = {}) { async fetch(request: Request, env: any, ctx: ExecutionContext) { const app = await createApp(config, env); return app.fetch(request, env, ctx); - } + }, }; } @@ -66,7 +66,7 @@ export function serveCached(config: Omit = {}) { } return app.fetch(request, env, ctx); - } + }, }; } @@ -77,6 +77,6 @@ export function serve({ mode, ...config }: ViteBkndConfig = {}) { export function devServer(options: DevServerOptions) { return honoViteDevServer({ ...devServerConfig, - ...options + ...options, }); } diff --git a/app/src/auth/AppAuth.ts b/app/src/auth/AppAuth.ts index ba13862..31a082e 100644 --- a/app/src/auth/AppAuth.ts +++ b/app/src/auth/AppAuth.ts @@ -4,7 +4,7 @@ import { Authenticator, type ProfileExchange, Role, - type Strategy + type Strategy, } from "auth"; import type { PasswordStrategy } from "auth/authenticate/strategies"; import { type DB, Exception, type PrimaryFieldType } from "core"; @@ -68,15 +68,15 @@ export class AppAuth extends Module { } catch (e) { throw new Error( `Could not build strategy ${String( - name - )} with config ${JSON.stringify(strategy.config)}` + name, + )} with config ${JSON.stringify(strategy.config)}`, ); } }); this._authenticator = new Authenticator(strategies, this.resolveUser.bind(this), { jwt: this.config.jwt, - cookie: this.config.cookie + cookie: this.config.cookie, }); this.registerEntities(); @@ -117,7 +117,7 @@ export class AppAuth extends Module { action: AuthAction, strategy: Strategy, identifier: string, - profile: ProfileExchange + profile: ProfileExchange, ): Promise { if (!this.config.allow_register && action === "register") { throw new Exception("Registration is not allowed", 403); @@ -127,7 +127,7 @@ export class AppAuth extends Module { .getFillableFields("create") .map((f) => f.name); const filteredProfile = Object.fromEntries( - Object.entries(profile).filter(([key]) => fields.includes(key)) + Object.entries(profile).filter(([key]) => fields.includes(key)), ); switch (action) { @@ -190,7 +190,7 @@ export class AppAuth extends Module { const payload: any = { ...profile, strategy: strategy.getName(), - strategy_value: identifier + strategy_value: identifier, }; const mutator = this.em.mutator(users); @@ -240,13 +240,13 @@ export class AppAuth extends Module { email: text().required(), strategy: text({ fillable: ["create"], - hidden: ["update", "form"] + hidden: ["update", "form"], }).required(), strategy_value: text({ fillable: ["create"], - hidden: ["read", "table", "update", "form"] + hidden: ["read", "table", "update", "form"], }).required(), - role: text() + role: text(), }; registerEntities() { @@ -254,12 +254,12 @@ export class AppAuth extends Module { this.ensureSchema( em( { - [users.name as "users"]: users + [users.name as "users"]: users, }, ({ index }, { users }) => { index(users).on(["email"], true).on(["strategy"]).on(["strategy_value"]); - } - ) + }, + ), ); try { @@ -288,7 +288,7 @@ export class AppAuth extends Module { ...(additional as any), email, strategy, - strategy_value + strategy_value, }); mutator.__unstable_toggleSystemEntityCreation(true); return created; @@ -307,8 +307,8 @@ export class AppAuth extends Module { strategies: transformObject(strategies, (strategy) => ({ enabled: this.isStrategyEnabled(strategy), type: strategy.getType(), - config: strategy.toJSON(secrets) - })) + config: strategy.toJSON(secrets), + })), }; } } diff --git a/app/src/auth/api/AuthApi.ts b/app/src/auth/api/AuthApi.ts index f5ba882..d4cc3d2 100644 --- a/app/src/auth/api/AuthApi.ts +++ b/app/src/auth/api/AuthApi.ts @@ -10,13 +10,13 @@ export type AuthApiOptions = BaseModuleApiOptions & { export class AuthApi extends ModuleApi { protected override getDefaultOptions(): Partial { return { - basepath: "/api/auth" + basepath: "/api/auth", }; } async login(strategy: string, input: any) { const res = await this.post([strategy, "login"], input, { - credentials: "include" + credentials: "include", }); if (res.ok && res.body.token) { @@ -27,7 +27,7 @@ export class AuthApi extends ModuleApi { async register(strategy: string, input: any) { const res = await this.post([strategy, "register"], input, { - credentials: "include" + credentials: "include", }); if (res.ok && res.body.token) { diff --git a/app/src/auth/api/AuthController.ts b/app/src/auth/api/AuthController.ts index a3fd90b..536f93b 100644 --- a/app/src/auth/api/AuthController.ts +++ b/app/src/auth/api/AuthController.ts @@ -58,7 +58,7 @@ export class AuthController extends Controller { try { const body = await this.auth.authenticator.getBody(c); const valid = parse(create.schema, body, { - skipMark: true + skipMark: true, }); const processed = (await create.preprocess?.(valid)) ?? valid; @@ -67,7 +67,7 @@ export class AuthController extends Controller { mutator.__unstable_toggleSystemEntityCreation(false); const { data: created } = await mutator.insertOne({ ...processed, - strategy: name + strategy: name, }); mutator.__unstable_toggleSystemEntityCreation(true); @@ -75,21 +75,21 @@ export class AuthController extends Controller { success: true, action: "create", strategy: name, - data: created as unknown as SafeUser + data: created as unknown as SafeUser, } as AuthActionResponse); } catch (e) { if (e instanceof TypeInvalidError) { return c.json( { success: false, - errors: e.errors + errors: e.errors, }, - 400 + 400, ); } throw e; } - } + }, ); hono.get("create/schema.json", async (c) => { return c.json(create.schema); @@ -147,12 +147,12 @@ export class AuthController extends Controller { strategies: transformObject(strategies ?? {}, (strategy, name) => { return this.auth.isStrategyEnabled(name) ? strategy : undefined; }), - basepath + basepath, }); } return c.json({ strategies, basepath }); - } + }, ); return hono.all("*", (c) => c.notFound()); diff --git a/app/src/auth/auth-schema.ts b/app/src/auth/auth-schema.ts index ab16ccf..ce45ea5 100644 --- a/app/src/auth/auth-schema.ts +++ b/app/src/auth/auth-schema.ts @@ -5,16 +5,16 @@ import { type Static, StringRecord, Type, objectTransform } from "core/utils"; export const Strategies = { password: { cls: PasswordStrategy, - schema: PasswordStrategy.prototype.getSchema() + schema: PasswordStrategy.prototype.getSchema(), }, oauth: { cls: OAuthStrategy, - schema: OAuthStrategy.prototype.getSchema() + schema: OAuthStrategy.prototype.getSchema(), }, custom_oauth: { cls: CustomOAuthStrategy, - schema: CustomOAuthStrategy.prototype.getSchema() - } + schema: CustomOAuthStrategy.prototype.getSchema(), + }, } as const; export const STRATEGIES = Strategies; @@ -23,12 +23,12 @@ const strategiesSchemaObject = objectTransform(STRATEGIES, (strategy, name) => { { enabled: Type.Optional(Type.Boolean({ default: true })), type: Type.Const(name, { default: name, readOnly: true }), - config: strategy.schema + config: strategy.schema, }, { title: name, - additionalProperties: false - } + additionalProperties: false, + }, ); }); const strategiesSchema = Type.Union(Object.values(strategiesSchemaObject)); @@ -37,15 +37,15 @@ export type AppAuthOAuthStrategy = Static; export type AppAuthCustomOAuthStrategy = Static; const guardConfigSchema = Type.Object({ - enabled: Type.Optional(Type.Boolean({ default: false })) + enabled: Type.Optional(Type.Boolean({ default: false })), }); export const guardRoleSchema = Type.Object( { permissions: Type.Optional(Type.Array(Type.String())), is_default: Type.Optional(Type.Boolean()), - implicit_allow: Type.Optional(Type.Boolean()) + implicit_allow: Type.Optional(Type.Boolean()), }, - { additionalProperties: false } + { additionalProperties: false }, ); export const authConfigSchema = Type.Object( @@ -64,19 +64,19 @@ export const authConfigSchema = Type.Object( type: "password", enabled: true, config: { - hashing: "sha256" - } - } - } - }) + hashing: "sha256", + }, + }, + }, + }), ), guard: Type.Optional(guardConfigSchema), - roles: Type.Optional(StringRecord(guardRoleSchema, { default: {} })) + roles: Type.Optional(StringRecord(guardRoleSchema, { default: {} })), }, { title: "Authentication", - additionalProperties: false - } + additionalProperties: false, + }, ); export type AppAuthSchema = Static; diff --git a/app/src/auth/authenticate/Authenticator.ts b/app/src/auth/authenticate/Authenticator.ts index 51f2d3b..6d1acc5 100644 --- a/app/src/auth/authenticate/Authenticator.ts +++ b/app/src/auth/authenticate/Authenticator.ts @@ -7,7 +7,7 @@ import { Type, parse, runtimeSupports, - transformObject + transformObject, } from "core/utils"; import type { Context, Hono } from "hono"; import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie"; @@ -71,9 +71,9 @@ export const cookieConfig = Type.Partial( expires: Type.Number({ default: defaultCookieExpires }), // seconds renew: Type.Boolean({ default: true }), pathSuccess: Type.String({ default: "/" }), - pathLoggedOut: Type.String({ default: "/" }) + pathLoggedOut: Type.String({ default: "/" }), }), - { default: {}, additionalProperties: false } + { default: {}, additionalProperties: false }, ); // @todo: maybe add a config to not allow cookie/api tokens to be used interchangably? @@ -86,16 +86,16 @@ export const jwtConfig = Type.Object( alg: Type.Optional(StringEnum(["HS256", "HS384", "HS512"], { default: "HS256" })), expires: Type.Optional(Type.Number()), // seconds issuer: Type.Optional(Type.String()), - fields: Type.Array(Type.String(), { default: ["id", "email", "role"] }) + fields: Type.Array(Type.String(), { default: ["id", "email", "role"] }), }, { default: {}, - additionalProperties: false - } + additionalProperties: false, + }, ); export const authenticatorConfig = Type.Object({ jwt: jwtConfig, - cookie: cookieConfig + cookie: cookieConfig, }); type AuthConfig = Static; @@ -104,7 +104,7 @@ export type AuthUserResolver = ( action: AuthAction, strategy: Strategy, identifier: string, - profile: ProfileExchange + profile: ProfileExchange, ) => Promise; type AuthClaims = SafeUser & { iat: number; @@ -127,7 +127,7 @@ export class Authenticator = Record< action: AuthAction, strategy: Strategy, identifier: string, - profile: ProfileExchange + profile: ProfileExchange, ): Promise { //console.log("resolve", { action, strategy: strategy.getName(), profile }); const user = await this.userResolver(action, strategy, identifier, profile); @@ -135,7 +135,7 @@ export class Authenticator = Record< if (user) { return { user, - token: await this.jwt(user) + token: await this.jwt(user), }; } @@ -148,7 +148,7 @@ export class Authenticator = Record< strategy< StrategyName extends keyof Strategies, - Strat extends Strategy = Strategies[StrategyName] + Strat extends Strategy = Strategies[StrategyName], >(strategy: StrategyName): Strat { try { return this.strategies[strategy] as unknown as Strat; @@ -168,7 +168,7 @@ export class Authenticator = Record< const payload: JWTPayload = { ...user, - iat: Math.floor(Date.now() / 1000) + iat: Math.floor(Date.now() / 1000), }; // issuer @@ -194,7 +194,7 @@ export class Authenticator = Record< const payload = await verify( jwt, this.config.jwt?.secret ?? "", - this.config.jwt?.alg ?? "HS256" + this.config.jwt?.alg ?? "HS256", ); // manually verify issuer (hono doesn't support it) @@ -215,7 +215,7 @@ export class Authenticator = Record< return { ...cookieConfig, - expires: new Date(Date.now() + expires * 1000) + expires: new Date(Date.now() + expires * 1000), }; } @@ -342,17 +342,17 @@ export class Authenticator = Record< toJSON(secrets?: boolean) { return { ...this.config, - jwt: secrets ? this.config.jwt : undefined + jwt: secrets ? this.config.jwt : undefined, }; } } export function createStrategyAction( schema: S, - preprocess: (input: Static) => Promise> + preprocess: (input: Static) => Promise>, ) { return { schema, - preprocess + preprocess, } as StrategyAction; } diff --git a/app/src/auth/authenticate/strategies/PasswordStrategy.ts b/app/src/auth/authenticate/strategies/PasswordStrategy.ts index 726dc9f..8f30c58 100644 --- a/app/src/auth/authenticate/strategies/PasswordStrategy.ts +++ b/app/src/auth/authenticate/strategies/PasswordStrategy.ts @@ -9,7 +9,7 @@ type LoginSchema = { username: string; password: string } | { email: string; pas type RegisterSchema = { email: string; password: string; [key: string]: any }; const schema = Type.Object({ - hashing: StringEnum(["plain", "sha256" /*, "bcrypt"*/] as const, { default: "sha256" }) + hashing: StringEnum(["plain", "sha256" /*, "bcrypt"*/] as const, { default: "sha256" }), }); export type PasswordStrategyOptions = Static; @@ -49,7 +49,7 @@ export class PasswordStrategy implements Strategy { return { ...input, - password: await this.hash(input.password) + password: await this.hash(input.password), }; } @@ -62,8 +62,8 @@ export class PasswordStrategy implements Strategy { tb( "query", Type.Object({ - redirect: Type.Optional(Type.String()) - }) + redirect: Type.Optional(Type.String()), + }), ), async (c) => { const body = await authenticator.getBody(c); @@ -75,22 +75,22 @@ export class PasswordStrategy implements Strategy { "login", this, payload.password, - payload + payload, ); return await authenticator.respond(c, data, redirect); } catch (e) { return await authenticator.respond(c, e); } - } + }, ) .post( "/register", tb( "query", Type.Object({ - redirect: Type.Optional(Type.String()) - }) + redirect: Type.Optional(Type.String()), + }), ), async (c) => { const body = await authenticator.getBody(c); @@ -101,11 +101,11 @@ export class PasswordStrategy implements Strategy { "register", this, payload.password, - payload + payload, ); return await authenticator.respond(c, data, redirect); - } + }, ); } @@ -114,19 +114,19 @@ export class PasswordStrategy implements Strategy { create: createStrategyAction( Type.Object({ email: Type.String({ - pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$" + pattern: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", }), password: Type.String({ - minLength: 8 // @todo: this should be configurable - }) + minLength: 8, // @todo: this should be configurable + }), }), async ({ password, ...input }) => { return { ...input, - strategy_value: await this.hash(password) + strategy_value: await this.hash(password), }; - } - ) + }, + ), }; } diff --git a/app/src/auth/authenticate/strategies/index.ts b/app/src/auth/authenticate/strategies/index.ts index 97ea311..86c3ba2 100644 --- a/app/src/auth/authenticate/strategies/index.ts +++ b/app/src/auth/authenticate/strategies/index.ts @@ -9,5 +9,5 @@ export { type PasswordStrategyOptions, OAuthStrategy, OAuthCallbackException, - CustomOAuthStrategy + CustomOAuthStrategy, }; diff --git a/app/src/auth/authenticate/strategies/oauth/CustomOAuthStrategy.ts b/app/src/auth/authenticate/strategies/oauth/CustomOAuthStrategy.ts index 2ff54c9..6e7f458 100644 --- a/app/src/auth/authenticate/strategies/oauth/CustomOAuthStrategy.ts +++ b/app/src/auth/authenticate/strategies/oauth/CustomOAuthStrategy.ts @@ -15,11 +15,11 @@ const oauthSchemaCustom = Type.Object( { client_id: Type.String(), client_secret: Type.String(), - token_endpoint_auth_method: StringEnum(["client_secret_basic"]) + token_endpoint_auth_method: StringEnum(["client_secret_basic"]), }, { - additionalProperties: false - } + additionalProperties: false, + }, ), as: Type.Object( { @@ -29,15 +29,15 @@ const oauthSchemaCustom = Type.Object( scope_separator: Type.Optional(Type.String({ default: " " })), authorization_endpoint: Type.Optional(UrlString), token_endpoint: Type.Optional(UrlString), - userinfo_endpoint: Type.Optional(UrlString) + userinfo_endpoint: Type.Optional(UrlString), }, { - additionalProperties: false - } - ) + additionalProperties: false, + }, + ), // @todo: profile mapping }, - { title: "Custom OAuth", additionalProperties: false } + { title: "Custom OAuth", additionalProperties: false }, ); type OAuthConfigCustom = Static; @@ -57,7 +57,7 @@ export type IssuerConfig = { profile: ( info: UserInfo, config: Omit, - tokenResponse: any + tokenResponse: any, ) => Promise; }; diff --git a/app/src/auth/authenticate/strategies/oauth/OAuthStrategy.ts b/app/src/auth/authenticate/strategies/oauth/OAuthStrategy.ts index 5751556..b3177b5 100644 --- a/app/src/auth/authenticate/strategies/oauth/OAuthStrategy.ts +++ b/app/src/auth/authenticate/strategies/oauth/OAuthStrategy.ts @@ -18,14 +18,14 @@ const schemaProvided = Type.Object( client: Type.Object( { client_id: Type.String(), - client_secret: Type.String() + client_secret: Type.String(), }, { - additionalProperties: false - } - ) + additionalProperties: false, + }, + ), }, - { title: "OAuth" } + { title: "OAuth" }, ); type ProvidedOAuthConfig = Static; @@ -56,7 +56,7 @@ export type IssuerConfig = { profile: ( info: UserInfo, config: Omit, - tokenResponse: any + tokenResponse: any, ) => Promise; }; @@ -65,7 +65,7 @@ export class OAuthCallbackException extends Exception { constructor( public error: any, - public step: string + public step: string, ) { super("OAuthCallbackException on " + step); } @@ -103,8 +103,8 @@ export class OAuthStrategy implements Strategy { type: info.type, client: { ...info.client, - ...this._config.client - } + ...this._config.client, + }, }; } @@ -129,7 +129,7 @@ export class OAuthStrategy implements Strategy { const { challenge_supported, challenge, challenge_method } = await this.getCodeChallenge( as, - options.state + options.state, ); if (!as.authorization_endpoint) { @@ -150,7 +150,7 @@ export class OAuthStrategy implements Strategy { client_id: client.client_id, redirect_uri: options.redirect_uri, response_type: "code", - scope: scopes.join(as.scope_separator ?? " ") + scope: scopes.join(as.scope_separator ?? " "), }; if (challenge_supported) { params.code_challenge = challenge; @@ -162,13 +162,13 @@ export class OAuthStrategy implements Strategy { return { url: new URL(endpoint) + "?" + new URLSearchParams(params).toString(), endpoint, - params + params, }; } private async oidc( callbackParams: URL | URLSearchParams, - options: { redirect_uri: string; state: string; scopes?: string[] } + options: { redirect_uri: string; state: string; scopes?: string[] }, ) { const config = await this.getConfig(); const { client, as, type } = config; @@ -178,7 +178,7 @@ export class OAuthStrategy implements Strategy { as, client, // no client_secret required callbackParams, - oauth.expectNoState + oauth.expectNoState, ); if (oauth.isOAuth2Error(parameters)) { //console.log("callback.error", parameters); @@ -193,7 +193,7 @@ export class OAuthStrategy implements Strategy { client, parameters, options.redirect_uri, - options.state + options.state, ); //console.log("callback.response", response); @@ -213,7 +213,7 @@ export class OAuthStrategy implements Strategy { as, client, response, - expectedNonce + expectedNonce, ); if (oauth.isOAuth2Error(result)) { console.log("callback.error", result); @@ -236,7 +236,7 @@ export class OAuthStrategy implements Strategy { private async oauth2( callbackParams: URL | URLSearchParams, - options: { redirect_uri: string; state: string; scopes?: string[] } + options: { redirect_uri: string; state: string; scopes?: string[] }, ) { const config = await this.getConfig(); const { client, type, as, profile } = config; @@ -246,7 +246,7 @@ export class OAuthStrategy implements Strategy { as, client, // no client_secret required callbackParams, - oauth.expectNoState + oauth.expectNoState, ); if (oauth.isOAuth2Error(parameters)) { console.log("callback.error", parameters); @@ -254,14 +254,14 @@ export class OAuthStrategy implements Strategy { } console.log( "callback.parameters", - JSON.stringify(Object.fromEntries(parameters.entries()), null, 2) + JSON.stringify(Object.fromEntries(parameters.entries()), null, 2), ); const response = await oauth.authorizationCodeGrantRequest( as, client, parameters, options.redirect_uri, - options.state + options.state, ); const challenges = oauth.parseWwwAuthenticateChallenges(response); @@ -297,7 +297,7 @@ export class OAuthStrategy implements Strategy { async callback( callbackParams: URL | URLSearchParams, - options: { redirect_uri: string; state: string; scopes?: string[] } + options: { redirect_uri: string; state: string; scopes?: string[] }, ): Promise { const type = this.getIssuerConfig().type; @@ -330,7 +330,7 @@ export class OAuthStrategy implements Strategy { secure: true, httpOnly: true, sameSite: "Lax", - maxAge: 60 * 5 // 5 minutes + maxAge: 60 * 5, // 5 minutes }); }; @@ -339,7 +339,7 @@ export class OAuthStrategy implements Strategy { return { state: c.req.header("X-State-Challenge"), action: c.req.header("X-State-Action"), - mode: "token" + mode: "token", } as any; } @@ -366,7 +366,7 @@ export class OAuthStrategy implements Strategy { const profile = await this.callback(params, { redirect_uri, - state: state.state + state: state.state, }); try { @@ -392,7 +392,7 @@ export class OAuthStrategy implements Strategy { const params = new URLSearchParams(url.search); return c.json({ - code: params.get("code") ?? null + code: params.get("code") ?? null, }); }); @@ -410,7 +410,7 @@ export class OAuthStrategy implements Strategy { const state = oauth.generateRandomCodeVerifier(); const response = await this.request({ redirect_uri, - state + state, }); //console.log("_state", state); @@ -433,7 +433,7 @@ export class OAuthStrategy implements Strategy { const state = oauth.generateRandomCodeVerifier(); const response = await this.request({ redirect_uri, - state + state, }); if (isDebug()) { @@ -442,14 +442,14 @@ export class OAuthStrategy implements Strategy { redirect_uri, challenge: state, action, - params: response.params + params: response.params, }); } return c.json({ url: response.url, challenge: state, - action + action, }); }); @@ -477,7 +477,7 @@ export class OAuthStrategy implements Strategy { return { type: this.getIssuerConfig().type, - ...config + ...config, }; } } diff --git a/app/src/auth/authorize/Guard.ts b/app/src/auth/authorize/Guard.ts index 84cfda4..8a1da25 100644 --- a/app/src/auth/authorize/Guard.ts +++ b/app/src/auth/authorize/Guard.ts @@ -37,7 +37,7 @@ export class Guard { implicit_allow?: boolean; } >, - config?: GuardConfig + config?: GuardConfig, ) { const _roles = roles ? objectTransform(roles, ({ permissions = [], is_default, implicit_allow }, name) => { @@ -103,7 +103,7 @@ export class Guard { debug && console.log("guard: role not found", { user: user, - role: user?.role + role: user?.role, }); return this.getDefaultRole(); } @@ -141,14 +141,14 @@ export class Guard { } const rolePermission = role.permissions.find( - (rolePermission) => rolePermission.permission.name === name + (rolePermission) => rolePermission.permission.name === name, ); debug && console.log("guard: rolePermission, allowing?", { permission: name, role: role.name, - allowing: !!rolePermission + allowing: !!rolePermission, }); return !!rolePermission; } @@ -162,7 +162,7 @@ export class Guard { if (!this.granted(permission, c)) { throw new Exception( `Permission "${typeof permission === "string" ? permission : permission.name}" not granted`, - 403 + 403, ); } } diff --git a/app/src/auth/authorize/Role.ts b/app/src/auth/authorize/Role.ts index 6d1e0c5..b5b09b2 100644 --- a/app/src/auth/authorize/Role.ts +++ b/app/src/auth/authorize/Role.ts @@ -3,7 +3,7 @@ import { Permission } from "core"; export class RolePermission { constructor( public permission: Permission, - public config?: any + public config?: any, ) {} } @@ -12,20 +12,20 @@ export class Role { public name: string, public permissions: RolePermission[] = [], public is_default: boolean = false, - public implicit_allow: boolean = false + public implicit_allow: boolean = false, ) {} static createWithPermissionNames( name: string, permissionNames: string[], is_default: boolean = false, - implicit_allow: boolean = false + implicit_allow: boolean = false, ) { return new Role( name, permissionNames.map((name) => new RolePermission(new Permission(name))), is_default, - implicit_allow + implicit_allow, ); } @@ -39,7 +39,7 @@ export class Role { config.name, config.permissions?.map((name) => new RolePermission(new Permission(name))) ?? [], config.is_default, - config.implicit_allow + config.implicit_allow, ); } } diff --git a/app/src/auth/index.ts b/app/src/auth/index.ts index 11c3367..b99de5a 100644 --- a/app/src/auth/index.ts +++ b/app/src/auth/index.ts @@ -12,7 +12,7 @@ export { type AuthUserResolver, Authenticator, authenticatorConfig, - jwtConfig + jwtConfig, } from "./authenticate/Authenticator"; export { AppAuth, type UserFieldSchema } from "./AppAuth"; diff --git a/app/src/auth/middlewares.ts b/app/src/auth/middlewares.ts index 636cd2b..83e64ce 100644 --- a/app/src/auth/middlewares.ts +++ b/app/src/auth/middlewares.ts @@ -36,7 +36,7 @@ export const auth = (options?: { registered: false, resolved: false, skip: false, - user: undefined + user: undefined, }); } @@ -77,7 +77,7 @@ export const permission = ( options?: { onGranted?: (c: Context) => Promise; onDenied?: (c: Context) => Promise; - } + }, ) => // @ts-ignore createMiddleware(async (c, next) => { diff --git a/app/src/cli/commands/create/create.ts b/app/src/cli/commands/create/create.ts index 6d74385..d135422 100644 --- a/app/src/cli/commands/create/create.ts +++ b/app/src/cli/commands/create/create.ts @@ -13,18 +13,18 @@ import { type Template, templates } from "./templates"; const config = { types: { runtime: "Runtime", - framework: "Framework" + framework: "Framework", }, runtime: { node: "Node.js", bun: "Bun", - cloudflare: "Cloudflare" + cloudflare: "Cloudflare", }, framework: { nextjs: "Next.js", remix: "Remix", - astro: "Astro" - } + astro: "Astro", + }, } as const; export const create: CliCommand = (program) => { @@ -41,7 +41,7 @@ function errorOutro() { $p.outro(color.red("Failed to create project.")); console.log( color.yellow("Sorry that this happened. If you think this is a bug, please report it at: ") + - color.cyan("https://github.com/bknd-io/bknd/issues") + color.cyan("https://github.com/bknd-io/bknd/issues"), ); console.log(""); process.exit(1); @@ -53,26 +53,26 @@ async function action(options: { template?: string; dir?: string; integration?: const downloadOpts = { dir: options.dir || "./", - clean: false + clean: false, }; const version = await getVersion(); $p.intro( - `👋 Welcome to the ${color.bold(color.cyan("bknd"))} create wizard ${color.bold(`v${version}`)}` + `👋 Welcome to the ${color.bold(color.cyan("bknd"))} create wizard ${color.bold(`v${version}`)}`, ); await $p.stream.message( (async function* () { yield* typewriter("Thanks for choosing to create a new project with bknd!", color.dim); await wait(); - })() + })(), ); if (!options.dir) { const dir = await $p.text({ message: "Where to create your project?", placeholder: downloadOpts.dir, - initialValue: downloadOpts.dir + initialValue: downloadOpts.dir, }); if ($p.isCancel(dir)) { process.exit(1); @@ -84,7 +84,7 @@ async function action(options: { template?: string; dir?: string; integration?: if (fs.existsSync(downloadOpts.dir)) { const clean = await $p.confirm({ message: `Directory ${color.cyan(downloadOpts.dir)} exists. Clean it?`, - initialValue: false + initialValue: false, }); if ($p.isCancel(clean)) { process.exit(1); @@ -115,7 +115,7 @@ async function action(options: { template?: string; dir?: string; integration?: await wait(2); yield* typewriter("Let's find the perfect template for you.", color.dim); await wait(2); - })() + })(), ); const type = await $p.select({ @@ -123,8 +123,8 @@ async function action(options: { template?: string; dir?: string; integration?: options: Object.entries(config.types).map(([value, name]) => ({ value, label: name, - hint: Object.values(config[value]).join(", ") - })) + hint: Object.values(config[value]).join(", "), + })), }); if ($p.isCancel(type)) { @@ -135,8 +135,8 @@ async function action(options: { template?: string; dir?: string; integration?: message: `Which ${color.cyan(config.types[type])} do you want to continue with?`, options: Object.entries(config[type]).map(([value, name]) => ({ value, - label: name - })) as any + label: name, + })) as any, }); if ($p.isCancel(_integration)) { process.exit(1); @@ -157,7 +157,7 @@ async function action(options: { template?: string; dir?: string; integration?: } else if (choices.length > 1) { const selected_template = await $p.select({ message: "Pick a template", - options: choices.map((t) => ({ value: t.key, label: t.title, hint: t.description })) + options: choices.map((t) => ({ value: t.key, label: t.title, hint: t.description })), }); if ($p.isCancel(selected_template)) { @@ -196,7 +196,7 @@ async function action(options: { template?: string; dir?: string; integration?: try { await downloadTemplate(url, { dir: ctx.dir, - force: downloadOpts.clean ? "clean" : true + force: downloadOpts.clean ? "clean" : true, }); } catch (e) { if (e instanceof Error) { @@ -221,15 +221,15 @@ async function action(options: { template?: string; dir?: string; integration?: await overridePackageJson( (pkg) => ({ ...pkg, - name: ctx.name + name: ctx.name, }), - { dir: ctx.dir } + { dir: ctx.dir }, ); $p.log.success(`Updated package name to ${color.cyan(ctx.name)}`); { const install = await $p.confirm({ - message: "Install dependencies?" + message: "Install dependencies?", }); if ($p.isCancel(install)) { @@ -263,10 +263,10 @@ async function action(options: { template?: string; dir?: string; integration?: yield* typewriter( color.dim("Remember to run ") + color.cyan("npm install") + - color.dim(" after setup") + color.dim(" after setup"), ); await wait(); - })() + })(), ); } } @@ -284,10 +284,10 @@ async function action(options: { template?: string; dir?: string; integration?: yield "\n\n"; yield* typewriter( `Enter your project's directory using ${color.cyan("cd " + ctx.dir)} -If you need help, check ${color.cyan("https://docs.bknd.io")} or join our Discord!` +If you need help, check ${color.cyan("https://docs.bknd.io")} or join our Discord!`, ); await wait(2); - })() + })(), ); $p.outro(color.green("Setup complete.")); diff --git a/app/src/cli/commands/create/npm.ts b/app/src/cli/commands/create/npm.ts index 49fd2c0..beaeb50 100644 --- a/app/src/cli/commands/create/npm.ts +++ b/app/src/cli/commands/create/npm.ts @@ -16,7 +16,7 @@ export type TPackageJson = Partial<{ export async function overrideJson( file: string, fn: (pkg: File) => Promise | File, - opts?: { dir?: string; indent?: number } + opts?: { dir?: string; indent?: number }, ) { const pkgPath = path.resolve(opts?.dir ?? process.cwd(), file); const pkg = await readFile(pkgPath, "utf-8"); @@ -26,7 +26,7 @@ export async function overrideJson( export async function overridePackageJson( fn: (pkg: TPackageJson) => Promise | TPackageJson, - opts?: { dir?: string } + opts?: { dir?: string }, ) { return await overrideJson("package.json", fn, { dir: opts?.dir }); } @@ -44,7 +44,7 @@ export async function getVersion(pkg: string, version: string = "latest") { const _deps = ["dependencies", "devDependencies", "optionalDependencies"] as const; export async function replacePackageJsonVersions( fn: (pkg: string, version: string) => Promise | string | undefined, - opts?: { include?: (keyof typeof _deps)[]; dir?: string } + opts?: { include?: (keyof typeof _deps)[]; dir?: string }, ) { const deps = (opts?.include ?? _deps) as string[]; await overridePackageJson( @@ -62,14 +62,14 @@ export async function replacePackageJsonVersions( return json; }, - { dir: opts?.dir } + { dir: opts?.dir }, ); } export async function updateBkndPackages(dir?: string, map?: Record) { const versions = { bknd: "^" + (await sysGetVersion()), - ...(map ?? {}) + ...(map ?? {}), }; await replacePackageJsonVersions( async (pkg) => { @@ -78,6 +78,6 @@ export async function updateBkndPackages(dir?: string, map?: Record")} and update your wrangler configuration.`, - c.dim + c.dim, ); - })() + })(), ); } @@ -108,10 +108,10 @@ async function createLibsql(ctx: TemplateSetupCtx) { (json) => ({ ...json, vars: { - DB_URL: "http://127.0.0.1:8080" - } + DB_URL: "http://127.0.0.1:8080", + }, }), - { dir: ctx.dir } + { dir: ctx.dir }, ); await overridePackageJson( @@ -120,10 +120,10 @@ async function createLibsql(ctx: TemplateSetupCtx) { scripts: { ...pkg.scripts, db: "turso dev", - dev: "npm run db && wrangler dev" - } + dev: "npm run db && wrangler dev", + }, }), - { dir: ctx.dir } + { dir: ctx.dir }, ); await $p.stream.info( @@ -132,13 +132,13 @@ async function createLibsql(ctx: TemplateSetupCtx) { await wait(); yield* typewriter( `\nYou can now run ${c.cyan("npm run db")} to start the database and ${c.cyan("npm run dev")} to start the worker.`, - c.dim + c.dim, ); await wait(); yield* typewriter( `\nAlso make sure you have Turso's CLI installed. Check their docs on how to install at ${c.cyan("https://docs.turso.tech/cli/introduction")}`, - c.dim + c.dim, ); - })() + })(), ); } diff --git a/app/src/cli/commands/create/templates/index.ts b/app/src/cli/commands/create/templates/index.ts index 469827f..b128e44 100644 --- a/app/src/cli/commands/create/templates/index.ts +++ b/app/src/cli/commands/create/templates/index.ts @@ -43,7 +43,7 @@ export const templates: Template[] = [ integration: "node", description: "A basic bknd Node.js server", path: "gh:bknd-io/bknd/examples/node", - ref: true + ref: true, }, { key: "bun", @@ -51,7 +51,7 @@ export const templates: Template[] = [ integration: "bun", description: "A basic bknd Bun server", path: "gh:bknd-io/bknd/examples/bun", - ref: true + ref: true, }, { key: "astro", @@ -59,6 +59,6 @@ export const templates: Template[] = [ integration: "astro", description: "A basic bknd Astro starter", path: "gh:bknd-io/bknd/examples/astro", - ref: true - } + ref: true, + }, ]; diff --git a/app/src/cli/commands/create/templates/nextjs.ts b/app/src/cli/commands/create/templates/nextjs.ts index bd36c2a..94b4b58 100644 --- a/app/src/cli/commands/create/templates/nextjs.ts +++ b/app/src/cli/commands/create/templates/nextjs.ts @@ -9,7 +9,7 @@ export const nextjs = { description: "A basic bknd Next.js starter", path: "gh:bknd-io/bknd/examples/nextjs", scripts: { - install: "npm install --force" + install: "npm install --force", }, ref: true, preinstall: async (ctx) => { @@ -20,10 +20,10 @@ export const nextjs = { dependencies: { ...pkg.dependencies, react: undefined, - "react-dom": undefined - } + "react-dom": undefined, + }, }), - { dir: ctx.dir } + { dir: ctx.dir }, ); - } + }, } as const satisfies Template; diff --git a/app/src/cli/commands/create/templates/remix.ts b/app/src/cli/commands/create/templates/remix.ts index 42d494e..3eef651 100644 --- a/app/src/cli/commands/create/templates/remix.ts +++ b/app/src/cli/commands/create/templates/remix.ts @@ -16,10 +16,10 @@ export const remix = { dependencies: { ...pkg.dependencies, react: "^18.2.0", - "react-dom": "^18.2.0" - } + "react-dom": "^18.2.0", + }, }), - { dir: ctx.dir } + { dir: ctx.dir }, ); - } + }, } as const satisfies Template; diff --git a/app/src/cli/commands/debug.ts b/app/src/cli/commands/debug.ts index 167e0ed..9f817c3 100644 --- a/app/src/cli/commands/debug.ts +++ b/app/src/cli/commands/debug.ts @@ -23,7 +23,7 @@ const subjects = { relativeDistPath: getRelativeDistPath(), cwd: process.cwd(), dir: path.dirname(url.fileURLToPath(import.meta.url)), - resolvedPkg: path.resolve(getRootPath(), "package.json") + resolvedPkg: path.resolve(getRootPath(), "package.json"), }); }, routes: async () => { @@ -32,7 +32,7 @@ const subjects = { const app = createApp({ connection: credentials }); await app.build(); showRoutes(app.server); - } + }, }; async function action(subject: string) { diff --git a/app/src/cli/commands/run/platform.ts b/app/src/cli/commands/run/platform.ts index eda86e4..eda3d44 100644 --- a/app/src/cli/commands/run/platform.ts +++ b/app/src/cli/commands/run/platform.ts @@ -14,13 +14,13 @@ export async function serveStatic(server: Platform): Promise const m = await import("@hono/node-server/serve-static"); return m.serveStatic({ // somehow different for node - root: getRelativeDistPath() + "/static" + root: getRelativeDistPath() + "/static", }); } case "bun": { const m = await import("hono/bun"); return m.serveStatic({ - root: path.resolve(getRelativeDistPath(), "static") + root: path.resolve(getRelativeDistPath(), "static"), }); } } @@ -40,14 +40,14 @@ export async function startServer(server: Platform, app: any, options: { port: n const serve = await import("@hono/node-server").then((m) => m.serve); serve({ fetch: (req) => app.fetch(req), - port + port, }); break; } case "bun": { Bun.serve({ fetch: (req) => app.fetch(req), - port + port, }); break; } diff --git a/app/src/cli/commands/run/run.ts b/app/src/cli/commands/run/run.ts index c4e5442..c3a5755 100644 --- a/app/src/cli/commands/run/run.ts +++ b/app/src/cli/commands/run/run.ts @@ -13,7 +13,7 @@ import { attachServeStatic, getConfigPath, getConnectionCredentialsFromEnv, - startServer + startServer, } from "./platform"; dotenv.config(); @@ -26,26 +26,26 @@ export const run: CliCommand = (program) => { new Option("-p, --port ", "port to run on") .env("PORT") .default(config.server.default_port) - .argParser((v) => Number.parseInt(v)) + .argParser((v) => Number.parseInt(v)), ) .addOption( new Option("-m, --memory", "use in-memory database").conflicts([ "config", "db-url", - "db-token" - ]) + "db-token", + ]), ) .addOption(new Option("-c, --config ", "config file")) .addOption( new Option("--db-url ", "database url, can be any valid libsql url").conflicts( - "config" - ) + "config", + ), ) .addOption(new Option("--db-token ", "database token").conflicts("config")) .addOption( new Option("--server ", "server type") .choices(PLATFORMS) - .default(isBun ? "bun" : "node") + .default(isBun ? "bun" : "node"), ) .action(action); }; @@ -76,7 +76,7 @@ async function makeApp(config: MakeAppConfig) { await config.onBuilt(app); } }, - "sync" + "sync", ); await app.build(); @@ -95,7 +95,7 @@ export async function makeConfigApp(config: CliBkndConfig, platform?: Platform) await config.onBuilt?.(app); }, - "sync" + "sync", ); await config.beforeBuild?.(app); @@ -141,7 +141,7 @@ async function action(options: { console.info("Using connection", c.cyan(connection.url)); app = await makeApp({ connection, - server: { platform: options.server } + server: { platform: options.server }, }); } diff --git a/app/src/cli/commands/user.ts b/app/src/cli/commands/user.ts index 235fd4c..3545093 100644 --- a/app/src/cli/commands/user.ts +++ b/app/src/cli/commands/user.ts @@ -48,7 +48,7 @@ async function create(app: App, options: any) { return "Invalid email"; } return; - } + }, }); const password = await $password({ @@ -58,7 +58,7 @@ async function create(app: App, options: any) { return "Invalid password"; } return; - } + }, }); if (typeof email !== "string" || typeof password !== "string") { @@ -69,8 +69,8 @@ async function create(app: App, options: any) { try { const created = await app.createUser({ email, - password: await strategy.hash(password as string) - }) + password: await strategy.hash(password as string), + }); console.log("Created:", created); } catch (e) { console.error("Error", e); @@ -90,7 +90,7 @@ async function update(app: App, options: any) { return "Invalid email"; } return; - } + }, })) as string; if (typeof email !== "string") { console.log("Cancelled"); @@ -111,7 +111,7 @@ async function update(app: App, options: any) { return "Invalid password"; } return; - } + }, }); if (typeof password !== "string") { console.log("Cancelled"); @@ -130,7 +130,7 @@ async function update(app: App, options: any) { .ctx() .em.mutator(users_entity) .updateOne(user.id, { - strategy_value: await strategy.hash(password as string) + strategy_value: await strategy.hash(password as string), }); togglePw(false); @@ -138,4 +138,4 @@ async function update(app: App, options: any) { } catch (e) { console.error("Error", e); } -} \ No newline at end of file +} diff --git a/app/src/cli/utils/cli.ts b/app/src/cli/utils/cli.ts index 5b0d8e7..ab7c341 100644 --- a/app/src/cli/utils/cli.ts +++ b/app/src/cli/utils/cli.ts @@ -12,7 +12,7 @@ export default function ansiRegex({ onlyFirst = false } = {}) { const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)"; const pattern = [ `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`, - "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))" + "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", ].join("|"); return new RegExp(pattern, onlyFirst ? undefined : "g"); @@ -22,7 +22,7 @@ const DEFAULT_WAIT_WRITER = _SPEEDUP ? 0 : 20; export async function* typewriter( text: string, transform?: (char: string) => string, - _delay?: number + _delay?: number, ) { const delay = DEFAULT_WAIT_WRITER * (_delay ?? 1); const regex = ansiRegex(); diff --git a/app/src/cli/utils/sys.ts b/app/src/cli/utils/sys.ts index 4ea3531..ba6c579 100644 --- a/app/src/cli/utils/sys.ts +++ b/app/src/cli/utils/sys.ts @@ -44,7 +44,7 @@ export function exec(command: string, opts?: { silent?: boolean; env?: Record } + opts?: { silent?: boolean; env?: Record }, ) { return new Promise((resolve, reject) => { nodeExec( command, { - env: { ...process.env, ...opts?.env } + env: { ...process.env, ...opts?.env }, }, (err, stdout, stderr) => { if (err) { return reject(err); } resolve(stdout); - } + }, ); }); } diff --git a/app/src/core/cache/adapters/MemoryCache.ts b/app/src/core/cache/adapters/MemoryCache.ts index 75e0df7..5cf36b2 100644 --- a/app/src/core/cache/adapters/MemoryCache.ts +++ b/app/src/core/cache/adapters/MemoryCache.ts @@ -10,7 +10,7 @@ export class MemoryCache implements ICachePool { supports = () => ({ metadata: true, - clear: true + clear: true, }); async get(key: string): Promise> { @@ -61,7 +61,7 @@ export class MemoryCache implements ICachePool { async put( key: string, value: Data, - options: { expiresAt?: Date; ttl?: number; metadata?: Record } = {} + options: { expiresAt?: Date; ttl?: number; metadata?: Record } = {}, ): Promise { const item = await this.get(key); item.set(value, options.metadata || {}); diff --git a/app/src/core/config.ts b/app/src/core/config.ts index 2f2cf06..f48385f 100644 --- a/app/src/core/config.ts +++ b/app/src/core/config.ts @@ -17,9 +17,9 @@ export const config = { server: { default_port: 1337, // resetted to root for now, bc bundling with vite - assets_path: "/" + assets_path: "/", }, data: { - default_primary_field: "id" - } + default_primary_field: "id", + }, } as const; diff --git a/app/src/core/console.ts b/app/src/core/console.ts index ced396c..8197a27 100644 --- a/app/src/core/console.ts +++ b/app/src/core/console.ts @@ -26,7 +26,7 @@ const originalConsoles = { warn: console.warn, info: console.info, log: console.log, - debug: console.debug + debug: console.debug, } as typeof console; function __tty(type: any, args: any[]) { @@ -34,25 +34,25 @@ function __tty(type: any, args: any[]) { const styles = { error: { prefix: colors.red, - args: colors.red + args: colors.red, }, warn: { prefix: colors.yellow, - args: colors.yellow + args: colors.yellow, }, info: { - prefix: colors.cyan + prefix: colors.cyan, }, log: { - prefix: colors.dim + prefix: colors.dim, }, debug: { - prefix: colors.yellow - } + prefix: colors.yellow, + }, } as const; const prefix = styles[type].prefix(`[${type.toUpperCase()}]`); const _args = args.map((a) => - "args" in styles[type] && has && typeof a === "string" ? styles[type].args(a) : a + "args" in styles[type] && has && typeof a === "string" ? styles[type].args(a) : a, ); return originalConsoles[type](prefix, colors.gray(datetimeStringLocal()), ..._args); } @@ -78,13 +78,13 @@ export const $console = new Proxy( return (...args: any[]) => __tty(prop, args); } return () => null; - } - } + }, + }, ) as typeof console; export async function withDisabledConsole( fn: () => Promise, - sev?: TConsoleSeverity[] + sev?: TConsoleSeverity[], ): Promise { disableConsole(sev); try { diff --git a/app/src/core/errors.ts b/app/src/core/errors.ts index d9a1cdc..9173b4b 100644 --- a/app/src/core/errors.ts +++ b/app/src/core/errors.ts @@ -19,7 +19,7 @@ export class Exception extends Error { return { error: this.message, type: this.name, - context: this._context + context: this._context, }; } } @@ -28,7 +28,7 @@ export class BkndError extends Error { constructor( message: string, public details?: Record, - public type?: string + public type?: string, ) { super(message); } @@ -41,7 +41,7 @@ export class BkndError extends Error { return { type: this.type ?? "unknown", message: this.message, - details: this.details + details: this.details, }; } } diff --git a/app/src/core/events/Event.ts b/app/src/core/events/Event.ts index 8073c12..9defb4c 100644 --- a/app/src/core/events/Event.ts +++ b/app/src/core/events/Event.ts @@ -20,7 +20,7 @@ export abstract class Event { protected clone = Event>( this: This, - params: Params + params: Params, ): This { const cloned = new (this.constructor as any)(params); cloned.returned = true; @@ -50,7 +50,7 @@ export class InvalidEventReturn extends Error { export class EventReturnedWithoutValidation extends Error { constructor( event: EventClass, - public data: any + public data: any, ) { // @ts-expect-error slug is static super(`Event "${event.constructor.slug}" returned without validation`); diff --git a/app/src/core/events/EventListener.ts b/app/src/core/events/EventListener.ts index d3ac6ff..76a067e 100644 --- a/app/src/core/events/EventListener.ts +++ b/app/src/core/events/EventListener.ts @@ -6,7 +6,7 @@ export type ListenerMode = (typeof ListenerModes)[number]; export type ListenerHandler> = ( event: E, - slug: string + slug: string, ) => E extends Event ? R | Promise : never; export class EventListener { @@ -20,7 +20,7 @@ export class EventListener { event: EventClass, handler: ListenerHandler, mode: ListenerMode = "async", - id?: string + id?: string, ) { this.event = event; this.handler = handler; diff --git a/app/src/core/events/EventManager.ts b/app/src/core/events/EventManager.ts index 26549ba..c2de8c9 100644 --- a/app/src/core/events/EventManager.ts +++ b/app/src/core/events/EventManager.ts @@ -17,7 +17,7 @@ export interface EmitsEvents { export type { EventClass }; export class EventManager< - RegisteredEvents extends Record = Record + RegisteredEvents extends Record = Record, > { protected events: EventClass[] = []; protected listeners: EventListener[] = []; @@ -30,7 +30,7 @@ export class EventManager< onError?: (event: Event, e: unknown) => void; onInvalidReturn?: (event: Event, e: InvalidEventReturn) => void; asyncExecutor?: typeof Promise.all; - } + }, ) { if (events) { this.registerEvents(events); @@ -69,7 +69,7 @@ export class EventManager< return new Proxy(this, { get: (_, prop: string) => { return this.events.find((e) => e.slug === prop); - } + }, }) as any; } @@ -141,7 +141,7 @@ export class EventManager< protected createEventListener( _event: EventClass | string, handler: ListenerHandler, - _config: RegisterListenerConfig = "async" + _config: RegisterListenerConfig = "async", ) { const event = typeof _event === "string" ? this.events.find((e) => e.slug === _event)! : _event; @@ -159,7 +159,7 @@ export class EventManager< onEvent>( event: ActualEvent, handler: ListenerHandler, - config?: RegisterListenerConfig + config?: RegisterListenerConfig, ) { this.createEventListener(event, handler, config); } @@ -167,7 +167,7 @@ export class EventManager< on( slug: string, handler: ListenerHandler>, - config?: RegisterListenerConfig + config?: RegisterListenerConfig, ) { this.createEventListener(slug, handler, config); } @@ -225,7 +225,7 @@ export class EventManager< if (!newEvent.returned) { throw new Error( // @ts-expect-error slug is static - `Returned event ${newEvent.constructor.slug} must be marked as returned.` + `Returned event ${newEvent.constructor.slug} must be marked as returned.`, ); } _event = newEvent as Actual; diff --git a/app/src/core/events/index.ts b/app/src/core/events/index.ts index 1edb065..b60ff04 100644 --- a/app/src/core/events/index.ts +++ b/app/src/core/events/index.ts @@ -3,6 +3,6 @@ export { EventListener, ListenerModes, type ListenerMode, - type ListenerHandler + type ListenerHandler, } from "./EventListener"; export { EventManager, type EmitsEvents, type EventClass } from "./EventManager"; diff --git a/app/src/core/index.ts b/app/src/core/index.ts index 9f13b20..c9d0590 100644 --- a/app/src/core/index.ts +++ b/app/src/core/index.ts @@ -9,7 +9,7 @@ export { SimpleRenderer, type TemplateObject, type TemplateTypes, - type SimpleRendererOptions + type SimpleRendererOptions, } from "./template/SimpleRenderer"; export { SchemaObject } from "./object/SchemaObject"; export { DebugLogger } from "./utils/DebugLogger"; @@ -22,7 +22,7 @@ export { isPrimitive, type TExpression, type BooleanLike, - isBooleanLike + isBooleanLike, } from "./object/query/query"; export { Registry, type Constructor } from "./registry/Registry"; diff --git a/app/src/core/object/SchemaObject.ts b/app/src/core/object/SchemaObject.ts index c8584bf..8151c8a 100644 --- a/app/src/core/object/SchemaObject.ts +++ b/app/src/core/object/SchemaObject.ts @@ -6,14 +6,14 @@ import { getFullPathKeys, mergeObjectWith, parse, - stripMark + stripMark, } from "../utils"; export type SchemaObjectOptions = { onUpdate?: (config: Static) => void | Promise; onBeforeUpdate?: ( from: Static, - to: Static + to: Static, ) => Static | Promise>; restrictPaths?: string[]; overwritePaths?: (RegExp | string)[]; @@ -29,13 +29,13 @@ export class SchemaObject { constructor( private _schema: Schema, initial?: Partial>, - private options?: SchemaObjectOptions + private options?: SchemaObjectOptions, ) { this._default = Default(_schema, {} as any) as any; this._value = initial ? parse(_schema, structuredClone(initial as any), { forceParse: this.isForceParse(), - skipMark: this.isForceParse() + skipMark: this.isForceParse(), }) : this._default; this._config = Object.freeze(this._value); @@ -71,7 +71,7 @@ export class SchemaObject { async set(config: Static, noEmit?: boolean): Promise> { const valid = parse(this._schema, structuredClone(config) as any, { forceParse: true, - skipMark: this.isForceParse() + skipMark: this.isForceParse(), }); // regardless of "noEmit" – this should always be triggered const updatedConfig = await this.onBeforeUpdate(this._config, valid); @@ -159,7 +159,7 @@ export class SchemaObject { overwritePaths.some((k2) => { //console.log("keep?", { k, k2 }, k2 !== k && k2.startsWith(k)); return k2 !== k && k2.startsWith(k); - }) + }), ) : overwritePaths; //console.log("specific", specific); diff --git a/app/src/core/object/diff.ts b/app/src/core/object/diff.ts index 9a182bd..10fa427 100644 --- a/app/src/core/object/diff.ts +++ b/app/src/core/object/diff.ts @@ -1,7 +1,7 @@ enum Change { Add = "a", Remove = "r", - Edit = "e" + Edit = "e", } type Object = object; @@ -50,7 +50,7 @@ function diff(oldObj: Object, newObj: Object): DiffEntry[] { t: Change.Edit, p: path, o: oldValue, - n: newValue + n: newValue, }); } else if (Array.isArray(oldValue) && Array.isArray(newValue)) { const maxLength = Math.max(oldValue.length, newValue.length); @@ -60,14 +60,14 @@ function diff(oldObj: Object, newObj: Object): DiffEntry[] { t: Change.Add, p: [...path, i], o: undefined, - n: newValue[i] + n: newValue[i], }); } else if (i >= newValue.length) { diffs.push({ t: Change.Remove, p: [...path, i], o: oldValue[i], - n: undefined + n: undefined, }); } else { recurse(oldValue[i], newValue[i], [...path, i]); @@ -83,14 +83,14 @@ function diff(oldObj: Object, newObj: Object): DiffEntry[] { t: Change.Add, p: [...path, key], o: undefined, - n: newValue[key] + n: newValue[key], }); } else if (!(key in newValue)) { diffs.push({ t: Change.Remove, p: [...path, key], o: oldValue[key], - n: undefined + n: undefined, }); } else { recurse(oldValue[key], newValue[key], [...path, key]); @@ -101,7 +101,7 @@ function diff(oldObj: Object, newObj: Object): DiffEntry[] { t: Change.Edit, p: path, o: oldValue, - n: newValue + n: newValue, }); } } diff --git a/app/src/core/object/query/object-query.ts b/app/src/core/object/query/object-query.ts index c4c802e..2e6a799 100644 --- a/app/src/core/object/query/object-query.ts +++ b/app/src/core/object/query/object-query.ts @@ -4,12 +4,12 @@ const expressions = [ exp( "$eq", (v: Primitive) => isPrimitive(v), - (e, a) => e === a + (e, a) => e === a, ), exp( "$ne", (v: Primitive) => isPrimitive(v), - (e, a) => e !== a + (e, a) => e !== a, ), exp( "$like", @@ -25,7 +25,7 @@ const expressions = [ default: return false; } - } + }, ), exp( "$regex", @@ -39,54 +39,54 @@ const expressions = [ return regex.test(a); } return false; - } + }, ), exp( "$isnull", (v: boolean | 1 | 0) => true, - (e, a) => (e ? a === null : a !== null) + (e, a) => (e ? a === null : a !== null), ), exp( "$notnull", (v: boolean | 1 | 0) => true, - (e, a) => (e ? a !== null : a === null) + (e, a) => (e ? a !== null : a === null), ), exp( "$in", (v: (string | number)[]) => Array.isArray(v), - (e: any, a: any) => e.includes(a) + (e: any, a: any) => e.includes(a), ), exp( "$notin", (v: (string | number)[]) => Array.isArray(v), - (e: any, a: any) => !e.includes(a) + (e: any, a: any) => !e.includes(a), ), exp( "$gt", (v: number) => typeof v === "number", - (e: any, a: any) => a > e + (e: any, a: any) => a > e, ), exp( "$gte", (v: number) => typeof v === "number", - (e: any, a: any) => a >= e + (e: any, a: any) => a >= e, ), exp( "$lt", (v: number) => typeof v === "number", - (e: any, a: any) => a < e + (e: any, a: any) => a < e, ), exp( "$lte", (v: number) => typeof v === "number", - (e: any, a: any) => a <= e + (e: any, a: any) => a <= e, ), exp( "$between", (v: [number, number]) => Array.isArray(v) && v.length === 2 && v.every((n) => typeof n === "number"), - (e: any, a: any) => e[0] <= a && a <= e[1] - ) + (e: any, a: any) => e[0] <= a && a <= e[1], + ), ]; export type ObjectQuery = FilterQuery; diff --git a/app/src/core/object/query/query.ts b/app/src/core/object/query/query.ts index e30979e..d70c211 100644 --- a/app/src/core/object/query/query.ts +++ b/app/src/core/object/query/query.ts @@ -13,7 +13,7 @@ export class Expression { constructor( public key: Key, public valid: (v: Expect) => boolean, - public validate: (e: any, a: any, ctx: CTX) => any + public validate: (e: any, a: any, ctx: CTX) => any, ) {} } export type TExpression = Expression; @@ -21,7 +21,7 @@ export type TExpression = Expression( key: Key, valid: (v: Expect) => boolean, - validate: (e: Expect, a: unknown, ctx: CTX) => any + validate: (e: Expect, a: unknown, ctx: CTX) => any, ): Expression { return new Expression(key, valid, validate); } @@ -38,7 +38,7 @@ type ExpressionCondition = { function getExpression( expressions: Exps, - key: string + key: string, ): Expression { const exp = expressions.find((e) => e.key === key); if (!exp) throw new Error(`Expression does not exist: "${key}"`); @@ -61,7 +61,7 @@ export type FilterQuery = function _convert( $query: FilterQuery, expressions: Exps, - path: string[] = [] + path: string[] = [], ): FilterQuery { //console.log("-----------------"); const ExpressionConditionKeys = expressions.map((e) => e.key); @@ -98,7 +98,7 @@ function _convert( } else if (typeof value === "object") { // when object is given, check if all keys are expressions const invalid = Object.keys(value).filter( - (f) => !ExpressionConditionKeys.includes(f as any) + (f) => !ExpressionConditionKeys.includes(f as any), ); if (invalid.length === 0) { newQuery[key] = {}; @@ -109,7 +109,7 @@ function _convert( } } else { throw new Error( - `Invalid key(s) at "${key}": ${invalid.join(", ")}. Expected expressions.` + `Invalid key(s) at "${key}": ${invalid.join(", ")}. Expected expressions.`, ); } } @@ -128,7 +128,7 @@ type BuildOptions = { function _build( _query: FilterQuery, expressions: Exps, - options: BuildOptions + options: BuildOptions, ): ValidationResults { const $query = options.convert ? _convert(_query, expressions) : _query; @@ -137,7 +137,7 @@ function _build( const result: ValidationResults = { $and: [], $or: [], - keys: new Set() + keys: new Set(), }; const { $or, ...$and } = $query; @@ -187,7 +187,7 @@ function _build( function _validate(results: ValidationResults): boolean { const matches: { $and?: boolean; $or?: boolean } = { $and: undefined, - $or: undefined + $or: undefined, }; matches.$and = results.$and.every((r) => Boolean(r)); @@ -204,6 +204,6 @@ export function makeValidator(expressions: Exps) { validate: (query: FilterQuery, options: BuildOptions) => { const fns = _build(query, expressions, options); return _validate(fns); - } + }, }; } diff --git a/app/src/core/registry/Registry.ts b/app/src/core/registry/Registry.ts index b895f51..7c56070 100644 --- a/app/src/core/registry/Registry.ts +++ b/app/src/core/registry/Registry.ts @@ -5,7 +5,7 @@ export type RegisterFn = (unknown: any) => Item; export class Registry< Item, Items extends Record = Record, - Fn extends RegisterFn = RegisterFn + Fn extends RegisterFn = RegisterFn, > { private is_set: boolean = false; private items: Items = {} as Items; diff --git a/app/src/core/security/Permission.ts b/app/src/core/security/Permission.ts index eb72ccb..86cf46b 100644 --- a/app/src/core/security/Permission.ts +++ b/app/src/core/security/Permission.ts @@ -5,7 +5,7 @@ export class Permission { toJSON() { return { - name: this.name + name: this.name, }; } } diff --git a/app/src/core/server/flash.ts b/app/src/core/server/flash.ts index aeac431..6c7b259 100644 --- a/app/src/core/server/flash.ts +++ b/app/src/core/server/flash.ts @@ -7,7 +7,7 @@ export type FlashMessageType = "error" | "warning" | "success" | "info"; export function addFlashMessage(c: Context, message: string, type: FlashMessageType = "info") { if (c.req.header("Accept")?.includes("text/html")) { setCookie(c, flash_key, JSON.stringify({ type, message }), { - path: "/" + path: "/", }); } } @@ -28,7 +28,7 @@ function getCookieValue(name) { } export function getFlashMessage( - clear = true + clear = true, ): { type: FlashMessageType; message: string } | undefined { const flash = getCookieValue(flash_key); if (flash && clear) { diff --git a/app/src/core/server/lib/tbValidator.ts b/app/src/core/server/lib/tbValidator.ts index 2118b18..6ae4c41 100644 --- a/app/src/core/server/lib/tbValidator.ts +++ b/app/src/core/server/lib/tbValidator.ts @@ -5,7 +5,7 @@ import { validator } from "hono/validator"; type Hook = ( result: { success: true; data: T } | { success: false; errors: ValueError[] }, - c: Context + c: Context, ) => Response | Promise | void; export function tbValidator< @@ -13,7 +13,7 @@ export function tbValidator< Target extends keyof ValidationTargets, E extends Env, P extends string, - V extends { in: { [K in Target]: StaticDecode }; out: { [K in Target]: StaticDecode } } + V extends { in: { [K in Target]: StaticDecode }; out: { [K in Target]: StaticDecode } }, >(target: Target, schema: T, hook?: Hook, E, P>): MiddlewareHandler { // Compile the provided schema once rather than per validation. This could be optimized further using a shared schema // compilation pool similar to the Fastify implementation. diff --git a/app/src/core/template/SimpleRenderer.ts b/app/src/core/template/SimpleRenderer.ts index 0e90c8e..1a16d1d 100644 --- a/app/src/core/template/SimpleRenderer.ts +++ b/app/src/core/template/SimpleRenderer.ts @@ -14,7 +14,7 @@ export class SimpleRenderer { constructor( private variables: Record = {}, - private options: SimpleRendererOptions = {} + private options: SimpleRendererOptions = {}, ) {} another() { @@ -48,7 +48,7 @@ export class SimpleRenderer { return (await this.renderString(template)) as unknown as Given; } else if (Array.isArray(template)) { return (await Promise.all( - template.map((item) => this.render(item)) + template.map((item) => this.render(item)), )) as unknown as Given; } else if (typeof template === "object") { return (await this.renderObject(template)) as unknown as Given; @@ -61,8 +61,8 @@ export class SimpleRenderer { kind: e.token.kind, input: e.token.input, begin: e.token.begin, - end: e.token.end - } + end: e.token.end, + }, }; throw new BkndError(e.message, details, "liquid"); diff --git a/app/src/core/types.ts b/app/src/core/types.ts index a3bf623..cfb32e4 100644 --- a/app/src/core/types.ts +++ b/app/src/core/types.ts @@ -1,4 +1,4 @@ export interface Serializable { toJSON(): Json; fromJSON(json: Json): Class; -} \ No newline at end of file +} diff --git a/app/src/core/utils/crypto.ts b/app/src/core/utils/crypto.ts index 21a188a..00f92b9 100644 --- a/app/src/core/utils/crypto.ts +++ b/app/src/core/utils/crypto.ts @@ -20,7 +20,7 @@ export const hash = { sha256: async (input: string, salt?: string, pepper?: string) => digest("SHA-256", input, salt, pepper), sha1: async (input: string, salt?: string, pepper?: string) => - digest("SHA-1", input, salt, pepper) + digest("SHA-1", input, salt, pepper), }; export async function checksum(s: any) { diff --git a/app/src/core/utils/objects.ts b/app/src/core/utils/objects.ts index 2c7c68d..e3a0135 100644 --- a/app/src/core/utils/objects.ts +++ b/app/src/core/utils/objects.ts @@ -14,7 +14,7 @@ export function isObject(value: unknown): value is Record { export function omitKeys( obj: T, - keys_: readonly K[] + keys_: readonly K[], ): Omit> { const keys = new Set(keys_); const result = {} as Omit>; @@ -47,7 +47,7 @@ export function keepChanged(origin: T, updated: T): Partial } return acc; }, - {} as Partial + {} as Partial, ); } @@ -66,13 +66,13 @@ export function objectKeysPascalToKebab(obj: any, ignoreKeys: string[] = []): an acc[kebabKey] = objectKeysPascalToKebab(obj[key], ignoreKeys); return acc; }, - {} as Record + {} as Record, ); } export function filterKeys( obj: Object, - keysToFilter: string[] + keysToFilter: string[], ): Object { const result = {} as Object; @@ -92,7 +92,7 @@ export function filterKeys( export function transformObject, U>( object: T, - transform: (value: T[keyof T], key: keyof T) => U | undefined + transform: (value: T[keyof T], key: keyof T) => U | undefined, ): { [K in keyof T]: U } { return Object.entries(object).reduce( (acc, [key, value]) => { @@ -102,20 +102,20 @@ export function transformObject, U>( } return acc; }, - {} as { [K in keyof T]: U } + {} as { [K in keyof T]: U }, ); } export const objectTransform = transformObject; export function objectEach, U>( object: T, - each: (value: T[keyof T], key: keyof T) => U + each: (value: T[keyof T], key: keyof T) => U, ): void { Object.entries(object).forEach( ([key, value]) => { each(value, key); }, - {} as { [K in keyof T]: U } + {} as { [K in keyof T]: U }, ); } @@ -291,7 +291,7 @@ export function isEqual(value1: any, value2: any): boolean { return "plainObject"; if (value instanceof Function) return "function"; throw new Error( - `deeply comparing an instance of type ${value1.constructor?.name} is not supported.` + `deeply comparing an instance of type ${value1.constructor?.name} is not supported.`, ); }; @@ -336,7 +336,7 @@ export function isEqual(value1: any, value2: any): boolean { export function getPath( object: object, _path: string | (string | number)[], - defaultValue = undefined + defaultValue = undefined, ): any { const path = typeof _path === "string" ? _path.split(/[.\[\]\"]+/).filter((x) => x) : _path; diff --git a/app/src/core/utils/reqres.ts b/app/src/core/utils/reqres.ts index ea29a80..fa8c6ad 100644 --- a/app/src/core/utils/reqres.ts +++ b/app/src/core/utils/reqres.ts @@ -161,11 +161,11 @@ const FILE_SIGNATURES: Record = { FFF9: "audio/aac", "52494646????41564920": "audio/wav", "52494646????57415645": "audio/wave", - "52494646????415550": "audio/aiff" + "52494646????415550": "audio/aiff", }; async function detectMimeType( - input: ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob | File | null + input: ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob | File | null, ): Promise { if (!input) return; @@ -202,7 +202,7 @@ async function detectMimeType( export async function blobToFile( blob: Blob | File | unknown, - overrides: FilePropertyBag & { name?: string } = {} + overrides: FilePropertyBag & { name?: string } = {}, ): Promise { if (isFile(blob)) return blob; if (!isBlob(blob)) throw new Error("Not a Blob"); @@ -215,7 +215,7 @@ export async function blobToFile( return new File([blob], name, { type: type || guess(name), - lastModified: Date.now() + lastModified: Date.now(), }); } @@ -340,5 +340,5 @@ export const enum HttpStatus { INSUFFICIENT_STORAGE = 507, LOOP_DETECTED = 508, NOT_EXTENDED = 510, - NETWORK_AUTHENTICATION_REQUIRED = 511 + NETWORK_AUTHENTICATION_REQUIRED = 511, } diff --git a/app/src/core/utils/runtime.ts b/app/src/core/utils/runtime.ts index c7007fa..311cef3 100644 --- a/app/src/core/utils/runtime.ts +++ b/app/src/core/utils/runtime.ts @@ -28,7 +28,7 @@ export function getRuntimeKey(): string { const features = { // supports the redirect of not full qualified addresses // not supported in nextjs - redirects_non_fq: true + redirects_non_fq: true, }; export function runtimeSupports(feature: keyof typeof features) { diff --git a/app/src/core/utils/test.ts b/app/src/core/utils/test.ts index 0b9b69a..f5cb0e8 100644 --- a/app/src/core/utils/test.ts +++ b/app/src/core/utils/test.ts @@ -2,17 +2,17 @@ type ConsoleSeverity = "log" | "warn" | "error"; const _oldConsoles = { log: console.log, warn: console.warn, - error: console.error + error: console.error, }; export async function withDisabledConsole( fn: () => Promise, - severities: ConsoleSeverity[] = ["log", "warn", "error"] + severities: ConsoleSeverity[] = ["log", "warn", "error"], ): Promise { const _oldConsoles = { log: console.log, warn: console.warn, - error: console.error + error: console.error, }; disableConsoleLog(severities); const enable = () => { @@ -57,6 +57,6 @@ export function formatMemoryUsage() { rss: usage.rss / 1024 / 1024, heapUsed: usage.heapUsed / 1024 / 1024, external: usage.external / 1024 / 1024, - arrayBuffers: usage.arrayBuffers / 1024 / 1024 + arrayBuffers: usage.arrayBuffers / 1024 / 1024, }; } diff --git a/app/src/core/utils/typebox/from-schema.ts b/app/src/core/utils/typebox/from-schema.ts index 4c2663a..b939978 100644 --- a/app/src/core/utils/typebox/from-schema.ts +++ b/app/src/core/utils/typebox/from-schema.ts @@ -56,6 +56,7 @@ const IsSArray = (value: unknown): value is SArray => !Type.ValueGuard.IsArray(value.items) && Type.ValueGuard.IsObject(value.items); const IsSConst = (value: unknown): value is SConst => + // biome-ignore lint/complexity/useLiteralKeys: Type.ValueGuard.IsObject(value) && Type.ValueGuard.IsObject(value["const"]); const IsSString = (value: unknown): value is SString => Type.ValueGuard.IsObject(value) && IsExact(value.type, "string"); @@ -68,7 +69,7 @@ const IsSBoolean = (value: unknown): value is SBoolean => const IsSNull = (value: unknown): value is SBoolean => Type.ValueGuard.IsObject(value) && IsExact(value.type, "null"); const IsSProperties = (value: unknown): value is SProperties => Type.ValueGuard.IsObject(value); -// prettier-ignore +// biome-ignore format: keep const IsSObject = (value: unknown): value is SObject => Type.ValueGuard.IsObject(value) && IsExact(value.type, 'object') && IsSProperties(value.properties) && (value.required === undefined || Type.ValueGuard.IsArray(value.required) && value.required.every((value: unknown) => Type.ValueGuard.IsString(value))) type SValue = string | number | boolean; type SEnum = Readonly<{ enum: readonly SValue[] }>; @@ -88,8 +89,9 @@ type SNull = Readonly<{ type: "null" }>; // ------------------------------------------------------------------ // FromRest // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromRest = ( + // biome-ignore lint/complexity/noUselessTypeConstraint: T extends readonly [infer L extends unknown, ...infer R extends unknown[]] ? TFromSchema extends infer S extends Type.TSchema ? TFromRest @@ -102,7 +104,7 @@ function FromRest(T: T): TFromRest { // ------------------------------------------------------------------ // FromEnumRest // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromEnumRest = ( T extends readonly [infer L extends SValue, ...infer R extends SValue[]] ? TFromEnumRest]> @@ -114,7 +116,7 @@ function FromEnumRest(T: T): TFromEnumRest { // ------------------------------------------------------------------ // AllOf // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromAllOf = ( TFromRest extends infer Rest extends Type.TSchema[] ? Type.TIntersectEvaluated @@ -126,7 +128,7 @@ function FromAllOf(T: T): TFromAllOf { // ------------------------------------------------------------------ // AnyOf // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromAnyOf = ( TFromRest extends infer Rest extends Type.TSchema[] ? Type.TUnionEvaluated @@ -138,7 +140,7 @@ function FromAnyOf(T: T): TFromAnyOf { // ------------------------------------------------------------------ // OneOf // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromOneOf = ( TFromRest extends infer Rest extends Type.TSchema[] ? Type.TUnionEvaluated @@ -150,7 +152,7 @@ function FromOneOf(T: T): TFromOneOf { // ------------------------------------------------------------------ // Enum // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromEnum = ( TFromEnumRest extends infer Elements extends Type.TSchema[] ? Type.TUnionEvaluated @@ -162,33 +164,33 @@ function FromEnum(T: T): TFromEnum { // ------------------------------------------------------------------ // Tuple // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromTuple = ( TFromRest extends infer Elements extends Type.TSchema[] ? Type.TTuple : Type.TTuple<[]> ) -// prettier-ignore +// biome-ignore format: keep function FromTuple(T: T): TFromTuple { return Type.Tuple(FromRest(T.items), T) as never } // ------------------------------------------------------------------ // Array // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromArray = ( TFromSchema extends infer Items extends Type.TSchema ? Type.TArray : Type.TArray ) -// prettier-ignore +// biome-ignore format: keep function FromArray(T: T): TFromArray { return Type.Array(FromSchema(T.items), T) as never } // ------------------------------------------------------------------ // Const // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep type TFromConst = ( Type.Ensure> ) @@ -202,13 +204,13 @@ type TFromPropertiesIsOptional< K extends PropertyKey, R extends string | unknown, > = unknown extends R ? true : K extends R ? false : true; -// prettier-ignore +// biome-ignore format: keep type TFromProperties = Type.Evaluate<{ -readonly [K in keyof T]: TFromPropertiesIsOptional extends true ? Type.TOptional> : TFromSchema }> -// prettier-ignore +// biome-ignore format: keep type TFromObject = ( TFromProperties[number]> extends infer Properties extends Type.TProperties ? Type.TObject @@ -217,11 +219,11 @@ type TFromObject = ( function FromObject(T: T): TFromObject { const properties = globalThis.Object.getOwnPropertyNames(T.properties).reduce((Acc, K) => { return { + // biome-ignore lint/performance/noAccumulatingSpread: ...Acc, - [K]: - T.required && T.required.includes(K) - ? FromSchema(T.properties[K]) - : Type.Optional(FromSchema(T.properties[K])), + [K]: T.required?.includes(K) + ? FromSchema(T.properties[K]) + : Type.Optional(FromSchema(T.properties[K])), }; }, {} as Type.TProperties); return Type.Object(properties, T) as never; @@ -229,7 +231,7 @@ function FromObject(T: T): TFromObject { // ------------------------------------------------------------------ // FromSchema // ------------------------------------------------------------------ -// prettier-ignore +// biome-ignore format: keep export type TFromSchema = ( T extends SAllOf ? TFromAllOf : T extends SAnyOf ? TFromAnyOf : @@ -248,7 +250,7 @@ export type TFromSchema = ( ) /** Parses a TypeBox type from raw JsonSchema */ export function FromSchema(T: T): TFromSchema { - // prettier-ignore + // biome-ignore format: keep return ( IsSAllOf(T) ? FromAllOf(T) : IsSAnyOf(T) ? FromAnyOf(T) : diff --git a/app/src/core/utils/typebox/index.ts b/app/src/core/utils/typebox/index.ts index 9e6f2d6..ee44a5b 100644 --- a/app/src/core/utils/typebox/index.ts +++ b/app/src/core/utils/typebox/index.ts @@ -12,13 +12,13 @@ import { type TSchema, type TString, Type, - TypeRegistry + TypeRegistry, } from "@sinclair/typebox"; import { DefaultErrorFunction, Errors, SetErrorFunction, - type ValueErrorIterator + type ValueErrorIterator, } from "@sinclair/typebox/errors"; import { Check, Default, Value, type ValueError } from "@sinclair/typebox/value"; @@ -45,7 +45,7 @@ export class TypeInvalidError extends Error { constructor( public schema: TSchema, public data: unknown, - message?: string + message?: string, ) { //console.warn("errored schema", JSON.stringify(schema, null, 2)); super(message ?? `Invalid: ${JSON.stringify(data)}`); @@ -66,7 +66,7 @@ export class TypeInvalidError extends Error { message: this.message, schema: this.schema, data: this.data, - errors: this.errors + errors: this.errors, }; } } @@ -95,7 +95,7 @@ export function mark(obj: any, validated = true) { export function parse( schema: Schema, data: RecursivePartial>, - options?: ParseOptions + options?: ParseOptions, ): Static { if (!options?.forceParse && typeof data === "object" && validationSymbol in data) { if (options?.useDefaults === false) { @@ -124,7 +124,7 @@ export function parse( export function parseDecode( schema: Schema, - data: RecursivePartial> + data: RecursivePartial>, ): StaticDecode { //console.log("parseDecode", schema, data); const parsed = Default(schema, data); @@ -140,7 +140,7 @@ export function parseDecode( export function strictParse( schema: Schema, data: Static, - options?: ParseOptions + options?: ParseOptions, ): Static { return parse(schema, data as any, options); } @@ -157,7 +157,7 @@ export const StringEnum = (values: T, options [Kind]: "StringEnum", type: "string", enum: values, - ...options + ...options, }); // key value record compatible with RJSF and typebox inference @@ -175,7 +175,7 @@ export const Const = (value: T, options export const StringIdentifier = Type.String({ pattern: "^[a-zA-Z_][a-zA-Z0-9_]*$", minLength: 2, - maxLength: 150 + maxLength: 150, }); SetErrorFunction((error) => { @@ -202,5 +202,5 @@ export { Value, Default, Errors, - Check + Check, }; diff --git a/app/src/data/AppData.ts b/app/src/data/AppData.ts index 45edb15..185ee09 100644 --- a/app/src/data/AppData.ts +++ b/app/src/data/AppData.ts @@ -5,7 +5,7 @@ import { EntityIndex, type EntityManager, constructEntity, - constructRelation + constructRelation, } from "data"; import { Module } from "modules/Module"; import { DataController } from "./api/DataController"; @@ -16,7 +16,7 @@ export class AppData extends Module { const { entities: _entities = {}, relations: _relations = {}, - indices: _indices = {} + indices: _indices = {}, } = this.config; this.ctx.logger.context("AppData").log("building with entities", Object.keys(_entities)); @@ -33,7 +33,7 @@ export class AppData extends Module { }; const relations = transformObject(_relations, (relation) => - constructRelation(relation, _entity) + constructRelation(relation, _entity), ); const indices = transformObject(_indices, (index, name) => { @@ -56,7 +56,7 @@ export class AppData extends Module { this.ctx.server.route( this.basepath, - new DataController(this.ctx, this.config).getController() + new DataController(this.ctx, this.config).getController(), ); this.ctx.guard.registerPermissions(Object.values(DataPermissions)); @@ -84,7 +84,7 @@ export class AppData extends Module { override toJSON(secrets?: boolean): AppDataConfig { return { ...this.config, - ...this.em.toJSON() + ...this.em.toJSON(), }; } } diff --git a/app/src/data/api/DataApi.ts b/app/src/data/api/DataApi.ts index abb710b..bff63e7 100644 --- a/app/src/data/api/DataApi.ts +++ b/app/src/data/api/DataApi.ts @@ -13,25 +13,25 @@ export class DataApi extends ModuleApi { basepath: "/api/data", queryLengthLimit: 1000, defaultQuery: { - limit: 10 - } + limit: 10, + }, }; } readOne( entity: E, id: PrimaryFieldType, - query: Omit = {} + query: Omit = {}, ) { return this.get, "meta" | "data">>( ["entity", entity as any, id], - query + query, ); } readMany( entity: E, - query: RepoQueryIn = {} + query: RepoQueryIn = {}, ) { type T = Pick, "meta" | "data">; @@ -48,17 +48,17 @@ export class DataApi extends ModuleApi { readManyByReference< E extends keyof DB | string, R extends keyof DB | string, - Data = R extends keyof DB ? DB[R] : EntityData + Data = R extends keyof DB ? DB[R] : EntityData, >(entity: E, id: PrimaryFieldType, reference: R, query: RepoQueryIn = {}) { return this.get, "meta" | "data">>( ["entity", entity as any, id, reference], - query ?? this.options.defaultQuery + query ?? this.options.defaultQuery, ); } createOne( entity: E, - input: Omit + input: Omit, ) { return this.post>(["entity", entity as any], input); } @@ -66,14 +66,14 @@ export class DataApi extends ModuleApi { updateOne( entity: E, id: PrimaryFieldType, - input: Partial> + input: Partial>, ) { return this.patch>(["entity", entity as any, id], input); } deleteOne( entity: E, - id: PrimaryFieldType + id: PrimaryFieldType, ) { return this.delete>(["entity", entity as any, id]); } @@ -81,7 +81,7 @@ export class DataApi extends ModuleApi { count(entity: E, where: RepoQueryIn["where"] = {}) { return this.post>( ["entity", entity as any, "fn", "count"], - where + where, ); } } diff --git a/app/src/data/api/DataController.ts b/app/src/data/api/DataController.ts index c3b4d4d..bf51eb8 100644 --- a/app/src/data/api/DataController.ts +++ b/app/src/data/api/DataController.ts @@ -7,7 +7,7 @@ import { type MutatorResponse, type RepoQuery, type RepositoryResponse, - querySchema + querySchema, } from "data"; import type { Handler } from "hono/types"; import type { ModuleBuildContext } from "modules"; @@ -18,7 +18,7 @@ import type { AppDataConfig } from "../data-schema"; export class DataController extends Controller { constructor( private readonly ctx: ModuleBuildContext, - private readonly config: AppDataConfig + private readonly config: AppDataConfig, ) { super(); } @@ -32,7 +32,7 @@ export class DataController extends Controller { } repoResult = RepositoryResponse>( - res: T + res: T, ): Pick { let meta: Partial = {}; @@ -48,7 +48,7 @@ export class DataController extends Controller { //return objectCleanEmpty(template) as any; // filter empty return Object.fromEntries( - Object.entries(template).filter(([_, v]) => typeof v !== "undefined" && v !== null) + Object.entries(template).filter(([_, v]) => typeof v !== "undefined" && v !== null), ) as any; } @@ -91,7 +91,7 @@ export class DataController extends Controller { handler("data info", (c) => { // sample implementation return c.json(this.em.toJSON()); - }) + }), ); // sync endpoint @@ -103,7 +103,7 @@ export class DataController extends Controller { //console.log("tables", tables); const changes = await this.em.schema().sync({ force, - drop + drop, }); return c.json({ tables: tables.map((t) => t.name), changes }); }); @@ -118,14 +118,14 @@ export class DataController extends Controller { this.em.entities.map((e) => [ e.name, { - $ref: `${this.config.basepath}/schemas/${e.name}` - } - ]) + $ref: `${this.config.basepath}/schemas/${e.name}`, + }, + ]), ); return c.json({ $schema: "https://json-schema.org/draft/2020-12/schema", $id, - properties: schemas + properties: schemas, }); }); @@ -137,8 +137,8 @@ export class DataController extends Controller { "param", Type.Object({ entity: Type.String(), - context: Type.Optional(StringEnum(["create", "update"])) - }) + context: Type.Optional(StringEnum(["create", "update"])), + }), ), async (c) => { //console.log("request", c.req.raw); @@ -157,9 +157,9 @@ export class DataController extends Controller { $id, title: _entity.label, $comment: _entity.config.description, - ...schema + ...schema, }); - } + }, ); // entity endpoints @@ -178,7 +178,7 @@ export class DataController extends Controller { const $rels = (r: any) => r.map((r: any) => ({ entity: r.other(_entity).entity.name, - ref: r.other(_entity).reference + ref: r.other(_entity).reference, })); return c.json({ @@ -188,8 +188,8 @@ export class DataController extends Controller { all: $rels(this.em.relations.relationsOf(_entity)), listable: $rels(this.em.relations.listableRelationsOf(_entity)), source: $rels(this.em.relations.sourceRelationsOf(_entity)), - target: $rels(this.em.relations.targetRelationsOf(_entity)) - } + target: $rels(this.em.relations.targetRelationsOf(_entity)), + }, }); }); @@ -222,7 +222,7 @@ export class DataController extends Controller { const where = (await c.req.json()) as any; const result = await this.em.repository(entity).count(where); return c.json({ entity, count: result.count }); - } + }, ); // fn: exists @@ -239,7 +239,7 @@ export class DataController extends Controller { const where = c.req.json() as any; const result = await this.em.repository(entity).exists(where); return c.json({ entity, exists: result.exists }); - } + }, ); /** @@ -263,7 +263,7 @@ export class DataController extends Controller { const result = await this.em.repository(entity).findMany(options); return c.json(this.repoResult(result), { status: result.data ? 200 : 404 }); - } + }, ); // read one @@ -274,8 +274,8 @@ export class DataController extends Controller { "param", Type.Object({ entity: Type.String(), - id: tbNumber - }) + id: tbNumber, + }), ), tb("query", querySchema), async (c) => { @@ -287,7 +287,7 @@ export class DataController extends Controller { const result = await this.em.repository(entity).findId(Number(id), options); return c.json(this.repoResult(result), { status: result.data ? 200 : 404 }); - } + }, ); // read many by reference @@ -299,8 +299,8 @@ export class DataController extends Controller { Type.Object({ entity: Type.String(), id: tbNumber, - reference: Type.String() - }) + reference: Type.String(), + }), ), tb("query", querySchema), async (c) => { @@ -315,7 +315,7 @@ export class DataController extends Controller { .findManyByReference(Number(id), reference, options); return c.json(this.repoResult(result), { status: result.data ? 200 : 404 }); - } + }, ); // func query @@ -334,7 +334,7 @@ export class DataController extends Controller { const result = await this.em.repository(entity).findMany(options); return c.json(this.repoResult(result), { status: result.data ? 200 : 404 }); - } + }, ); /** @@ -354,7 +354,7 @@ export class DataController extends Controller { const result = await this.em.mutator(entity).insertOne(body); return c.json(this.mutatorResult(result), 201); - } + }, ); // update many @@ -366,8 +366,8 @@ export class DataController extends Controller { "json", Type.Object({ update: Type.Object({}), - where: querySchema.properties.where - }) + where: querySchema.properties.where, + }), ), async (c) => { const { entity } = c.req.param(); @@ -381,7 +381,7 @@ export class DataController extends Controller { const result = await this.em.mutator(entity).updateWhere(update, where); return c.json(this.mutatorResult(result)); - } + }, ); // update one @@ -398,7 +398,7 @@ export class DataController extends Controller { const result = await this.em.mutator(entity).updateOne(Number(id), body); return c.json(this.mutatorResult(result)); - } + }, ); // delete one @@ -414,7 +414,7 @@ export class DataController extends Controller { const result = await this.em.mutator(entity).deleteOne(Number(id)); return c.json(this.mutatorResult(result)); - } + }, ); // delete many @@ -432,7 +432,7 @@ export class DataController extends Controller { const result = await this.em.mutator(entity).deleteWhere(where); return c.json(this.mutatorResult(result)); - } + }, ); return hono; diff --git a/app/src/data/connection/Connection.ts b/app/src/data/connection/Connection.ts index f2ee073..2a3933b 100644 --- a/app/src/data/connection/Connection.ts +++ b/app/src/data/connection/Connection.ts @@ -8,7 +8,7 @@ import { type SelectQueryBuilder, type SelectQueryNode, type Simplify, - sql + sql, } from "kysely"; export type QB = SelectQueryBuilder; @@ -33,7 +33,7 @@ export type DbFunctions = { jsonObjectFrom(expr: SelectQueryBuilderExpression): RawBuilder | null>; jsonArrayFrom(expr: SelectQueryBuilderExpression): RawBuilder[]>; jsonBuildObject>>( - obj: O + obj: O, ): RawBuilder< Simplify<{ [K in keyof O]: O[K] extends Expression ? V : never; @@ -49,7 +49,7 @@ export abstract class Connection { constructor( kysely: Kysely, public fn: Partial = {}, - protected plugins: KyselyPlugin[] = [] + protected plugins: KyselyPlugin[] = [], ) { this.kysely = kysely; this[CONN_SYMBOL] = true; @@ -84,7 +84,7 @@ export abstract class Connection { } protected async batch( - queries: [...Queries] + queries: [...Queries], ): Promise<{ [K in keyof Queries]: Awaited>; }> { @@ -92,7 +92,7 @@ export abstract class Connection { } async batchQuery( - queries: [...Queries] + queries: [...Queries], ): Promise<{ [K in keyof Queries]: Awaited>; }> { diff --git a/app/src/data/connection/LibsqlConnection.ts b/app/src/data/connection/LibsqlConnection.ts index b8b9a9b..d341adc 100644 --- a/app/src/data/connection/LibsqlConnection.ts +++ b/app/src/data/connection/LibsqlConnection.ts @@ -15,7 +15,7 @@ export type LibSqlCredentials = Config & { class CustomLibsqlDialect extends LibsqlDialect { override createIntrospector(db: Kysely): DatabaseIntrospector { return new SqliteIntrospector(db, { - excludeTables: ["libsql_wasm_func_table"] + excludeTables: ["libsql_wasm_func_table"], }); } } @@ -44,7 +44,7 @@ export class LibsqlConnection extends SqliteConnection { const kysely = new Kysely({ // @ts-expect-error libsql has type issues dialect: new CustomLibsqlDialect({ client }), - plugins + plugins, }); super(kysely, {}, plugins); @@ -64,7 +64,7 @@ export class LibsqlConnection extends SqliteConnection { } protected override async batch( - queries: [...Queries] + queries: [...Queries], ): Promise<{ [K in keyof Queries]: Awaited>; }> { @@ -72,7 +72,7 @@ export class LibsqlConnection extends SqliteConnection { const compiled = q.compile(); return { sql: compiled.sql, - args: compiled.parameters as any[] + args: compiled.parameters as any[], }; }); diff --git a/app/src/data/connection/SqliteConnection.ts b/app/src/data/connection/SqliteConnection.ts index 7a32093..2572667 100644 --- a/app/src/data/connection/SqliteConnection.ts +++ b/app/src/data/connection/SqliteConnection.ts @@ -10,9 +10,9 @@ export class SqliteConnection extends Connection { ...fn, jsonArrayFrom, jsonObjectFrom, - jsonBuildObject + jsonBuildObject, }, - plugins + plugins, ); } diff --git a/app/src/data/connection/SqliteIntrospector.ts b/app/src/data/connection/SqliteIntrospector.ts index 516e8cf..cf68816 100644 --- a/app/src/data/connection/SqliteIntrospector.ts +++ b/app/src/data/connection/SqliteIntrospector.ts @@ -5,7 +5,7 @@ import type { ExpressionBuilder, Kysely, SchemaMetadata, - TableMetadata + TableMetadata, } from "kysely"; import { DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, sql } from "kysely"; import type { ConnectionIntrospector, IndexMetadata } from "./Connection"; @@ -62,7 +62,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro seqno: number; cid: number; name: string; - }>`pragma_index_info(${index})`.as("index_info") + }>`pragma_index_info(${index})`.as("index_info"), ) .select(["seqno", "cid", "name"]) .orderBy("cid") @@ -74,8 +74,8 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro isUnique: isUnique, columns: columns.map((col) => ({ name: col.name, - order: col.seqno - })) + order: col.seqno, + })), }; } @@ -87,7 +87,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro } async getTables( - options: DatabaseMetadataOptions = { withInternalKyselyTables: false } + options: DatabaseMetadataOptions = { withInternalKyselyTables: false }, ): Promise { let query = this.#db .selectFrom("sqlite_master") @@ -99,7 +99,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro if (!options.withInternalKyselyTables) { query = query.where( - this.excludeTables([DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK_TABLE]) + this.excludeTables([DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK_TABLE]), ); } if (this._excludeTables.length > 0) { @@ -112,7 +112,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro async getMetadata(options?: DatabaseMetadataOptions): Promise { return { - tables: await this.getTables(options) + tables: await this.getTables(options), }; } @@ -142,7 +142,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro type: string; notnull: 0 | 1; dflt_value: any; - }>`pragma_table_info(${table})`.as("table_info") + }>`pragma_table_info(${table})`.as("table_info"), ) .select(["name", "type", "notnull", "dflt_value"]) .orderBy("cid") @@ -157,8 +157,8 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro isNullable: !col.notnull, isAutoIncrementing: col.name === autoIncrementCol, hasDefaultValue: col.dflt_value != null, - comment: undefined - })) + comment: undefined, + })), }; } } diff --git a/app/src/data/connection/SqliteLocalConnection.ts b/app/src/data/connection/SqliteLocalConnection.ts index b3bfab3..7c26428 100644 --- a/app/src/data/connection/SqliteLocalConnection.ts +++ b/app/src/data/connection/SqliteLocalConnection.ts @@ -6,7 +6,7 @@ import { SqliteIntrospector } from "./SqliteIntrospector"; class CustomSqliteDialect extends SqliteDialect { override createIntrospector(db: Kysely): DatabaseIntrospector { return new SqliteIntrospector(db, { - excludeTables: ["test_table"] + excludeTables: ["test_table"], }); } } @@ -16,7 +16,7 @@ export class SqliteLocalConnection extends SqliteConnection { const plugins = [new ParseJSONResultsPlugin()]; const kysely = new Kysely({ dialect: new CustomSqliteDialect({ database }), - plugins + plugins, //log: ["query"], }); diff --git a/app/src/data/data-schema.ts b/app/src/data/data-schema.ts index cc53bfd..cec6b61 100644 --- a/app/src/data/data-schema.ts +++ b/app/src/data/data-schema.ts @@ -4,14 +4,14 @@ import { RelationClassMap, RelationFieldClassMap, entityConfigSchema, - entityTypes + entityTypes, } from "data"; import { MediaField, mediaFieldConfigSchema } from "../media/MediaField"; export const FIELDS = { ...FieldClassMap, ...RelationFieldClassMap, - media: { schema: mediaFieldConfigSchema, field: MediaField } + media: { schema: mediaFieldConfigSchema, field: MediaField }, }; export type FieldType = keyof typeof FIELDS; @@ -21,11 +21,11 @@ export const fieldsSchemaObject = objectTransform(FIELDS, (field, name) => { return Type.Object( { type: Type.Const(name, { default: name, readOnly: true }), - config: Type.Optional(field.schema) + config: Type.Optional(field.schema), }, { - title: name - } + title: name, + }, ); }); export const fieldsSchema = Type.Union(Object.values(fieldsSchemaObject)); @@ -37,7 +37,7 @@ export const entitiesSchema = Type.Object({ //name: Type.String(), type: Type.Optional(Type.String({ enum: entityTypes, default: "regular", readOnly: true })), config: Type.Optional(entityConfigSchema), - fields: Type.Optional(entityFields) + fields: Type.Optional(entityFields), }); export type TAppDataEntity = Static; @@ -47,11 +47,11 @@ export const relationsSchema = Object.entries(RelationClassMap).map(([name, rela type: Type.Const(name, { default: name, readOnly: true }), source: Type.String(), target: Type.String(), - config: Type.Optional(relationClass.schema) + config: Type.Optional(relationClass.schema), }, { - title: name - } + title: name, + }, ); }); export type TAppDataRelation = Static<(typeof relationsSchema)[number]>; @@ -61,11 +61,11 @@ export const indicesSchema = Type.Object( entity: Type.String(), fields: Type.Array(Type.String(), { minItems: 1 }), //name: Type.Optional(Type.String()), - unique: Type.Optional(Type.Boolean({ default: false })) + unique: Type.Optional(Type.Boolean({ default: false })), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); export const dataConfigSchema = Type.Object( @@ -73,11 +73,11 @@ export const dataConfigSchema = Type.Object( basepath: Type.Optional(Type.String({ default: "/api/data" })), entities: Type.Optional(StringRecord(entitiesSchema, { default: {} })), relations: Type.Optional(StringRecord(Type.Union(relationsSchema), { default: {} })), - indices: Type.Optional(StringRecord(indicesSchema, { default: {} })) + indices: Type.Optional(StringRecord(indicesSchema, { default: {} })), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); export type AppDataConfig = Static; diff --git a/app/src/data/entities/Entity.ts b/app/src/data/entities/Entity.ts index 69a8d4a..5706832 100644 --- a/app/src/data/entities/Entity.ts +++ b/app/src/data/entities/Entity.ts @@ -5,7 +5,7 @@ import { Type, parse, snakeToPascalWithSpaces, - transformObject + transformObject, } from "core/utils"; import { type Field, PrimaryField, type TActionContext, type TRenderContext } from "../fields"; @@ -16,11 +16,11 @@ export const entityConfigSchema = Type.Object( name_singular: Type.Optional(Type.String()), description: Type.Optional(Type.String()), sort_field: Type.Optional(Type.String({ default: config.data.default_primary_field })), - sort_dir: Type.Optional(StringEnum(["asc", "desc"], { default: "asc" })) + sort_dir: Type.Optional(StringEnum(["asc", "desc"], { default: "asc" })), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); export type EntityConfig = Static; @@ -42,7 +42,7 @@ export type TEntityType = (typeof entityTypes)[number]; */ export class Entity< EntityName extends string = string, - Fields extends Record> = Record> + Fields extends Record> = Record>, > { readonly #_name!: EntityName; readonly #_fields!: Fields; // only for types @@ -99,14 +99,14 @@ export class Entity< getDefaultSort() { return { by: this.config.sort_field ?? "id", - dir: this.config.sort_dir ?? "asc" + dir: this.config.sort_dir ?? "asc", }; } getAliasedSelectFrom( select: string[], _alias?: string, - context?: TActionContext | TRenderContext + context?: TActionContext | TRenderContext, ): string[] { const alias = _alias ?? this.name; return this.getFields() @@ -114,7 +114,7 @@ export class Entity< (field) => !field.isVirtual() && !field.isHidden(context ?? "read") && - select.includes(field.name) + select.includes(field.name), ) .map((field) => (alias ? `${alias}.${field.name} as ${field.name}` : field.name)); } @@ -206,7 +206,7 @@ export class Entity< options?: { explain?: boolean; ignoreUnknown?: boolean; - } + }, ): boolean { if (typeof data !== "object") { if (options?.explain) { @@ -224,7 +224,7 @@ export class Entity< if (unknown_keys.length > 0) { if (options?.explain) { throw new Error( - `Entity "${this.name}" data must only contain known keys, unknown: "${unknown_keys}"` + `Entity "${this.name}" data must only contain known keys, unknown: "${unknown_keys}"`, ); } } @@ -265,10 +265,10 @@ export class Entity< $comment: field.config.description, $field: field.type, readOnly: !fillable ? true : undefined, - ...field.toJsonSchema() + ...field.toJsonSchema(), }; }), - { additionalProperties: false } + { additionalProperties: false }, ); return options?.clean ? JSON.parse(JSON.stringify(schema)) : schema; @@ -280,7 +280,7 @@ export class Entity< type: this.type, //fields: transformObject(this.fields, (field) => field.toJSON()), fields: Object.fromEntries(this.fields.map((field) => [field.name, field.toJSON()])), - config: this.config + config: this.config, }; } } diff --git a/app/src/data/entities/EntityManager.ts b/app/src/data/entities/EntityManager.ts index 9c08065..c7f9c5b 100644 --- a/app/src/data/entities/EntityManager.ts +++ b/app/src/data/entities/EntityManager.ts @@ -5,7 +5,7 @@ import { Connection } from "../connection/Connection"; import { EntityNotDefinedException, TransformRetrieveFailedException, - UnableToConnectException + UnableToConnectException, } from "../errors"; import { MutatorEvents, RepositoryEvents } from "../events"; import type { Field } from "../fields/Field"; @@ -18,7 +18,7 @@ import { type EntityData, Mutator, Repository } from "./index"; type EntitySchema< TBD extends object = DefaultDB, - E extends Entity | keyof TBD | string = string + E extends Entity | keyof TBD | string = string, > = E extends Entity ? Name extends keyof TBD ? Name @@ -42,7 +42,7 @@ export class EntityManager { connection: Connection, relations: EntityRelation[] = [], indices: EntityIndex[] = [], - emgr?: EventManager + emgr?: EventManager, ) { // add entities & relations entities.forEach((entity) => this.addEntity(entity)); @@ -114,11 +114,11 @@ export class EntityManager { entity( e: Entity | keyof TBD | string, - silent?: Silent + silent?: Silent, ): Silent extends true ? Entity | undefined : Entity { // make sure to always retrieve by name const entity = this.entities.find((entity) => - e instanceof Entity ? entity.name === e.name : entity.name === e + e instanceof Entity ? entity.name === e.name : entity.name === e, ); if (!entity) { @@ -177,7 +177,7 @@ export class EntityManager { if (found) { throw new Error( `Relation "${relation.type}" between "${relation.source.entity.name}" ` + - `and "${relation.target.entity.name}" already exists` + `and "${relation.target.entity.name}" already exists`, ); } @@ -206,7 +206,7 @@ export class EntityManager { } repository( - entity: E + entity: E, ): Repository> { return this.repo(entity); } @@ -277,7 +277,7 @@ export class EntityManager { row[key] = field.transformRetrieve(value as any); } catch (e: any) { throw new TransformRetrieveFailedException( - `"${field.type}" field "${key}" on entity "${entity.name}": ${e.message}` + `"${field.type}" field "${key}" on entity "${entity.name}": ${e.message}`, ); } } @@ -293,7 +293,7 @@ export class EntityManager { entities: Object.fromEntries(this.entities.map((e) => [e.name, e.toJSON()])), relations: Object.fromEntries(this.relations.all.map((r) => [r.getName(), r.toJSON()])), //relations: this.relations.all.map((r) => r.toJSON()), - indices: Object.fromEntries(this.indices.map((i) => [i.name, i.toJSON()])) + indices: Object.fromEntries(this.indices.map((i) => [i.name, i.toJSON()])), }; } } diff --git a/app/src/data/entities/Mutator.ts b/app/src/data/entities/Mutator.ts index 198cb11..8877ff3 100644 --- a/app/src/data/entities/Mutator.ts +++ b/app/src/data/entities/Mutator.ts @@ -29,7 +29,7 @@ export class Mutator< TBD extends object = DefaultDB, TB extends keyof TBD = any, Output = TBD[TB], - Input = Omit + Input = Omit, > implements EmitsEvents { em: EntityManager; @@ -85,7 +85,7 @@ export class Mutator< `Field "${key}" not found on entity "${entity.name}". Fields: ${entity .getFillableFields() .map((f) => f.name) - .join(", ")}` + .join(", ")}`, ); } @@ -118,7 +118,7 @@ export class Mutator< sql, parameters: [...parameters], result: result, - data + data, }; } catch (e) { // @todo: redact @@ -139,14 +139,14 @@ export class Mutator< } const result = await this.emgr.emit( - new Mutator.Events.MutatorInsertBefore({ entity, data: data as any }) + new Mutator.Events.MutatorInsertBefore({ entity, data: data as any }), ); // if listener returned, take what's returned const _data = result.returned ? result.params.data : data; const validatedData = { ...entity.getDefaultObject(), - ...(await this.getValidatedData(_data, "create")) + ...(await this.getValidatedData(_data, "create")), }; // check if required fields are present @@ -182,8 +182,8 @@ export class Mutator< new Mutator.Events.MutatorUpdateBefore({ entity, entityId: id, - data - }) + data, + }), ); const _data = result.returned ? result.params.data : data; @@ -198,7 +198,7 @@ export class Mutator< const res = await this.single(query); await this.emgr.emit( - new Mutator.Events.MutatorUpdateAfter({ entity, entityId: id, data: res.data }) + new Mutator.Events.MutatorUpdateAfter({ entity, entityId: id, data: res.data }), ); return res as any; @@ -220,7 +220,7 @@ export class Mutator< const res = await this.single(query); await this.emgr.emit( - new Mutator.Events.MutatorDeleteAfter({ entity, entityId: id, data: res.data }) + new Mutator.Events.MutatorDeleteAfter({ entity, entityId: id, data: res.data }), ); return res as any; @@ -274,7 +274,7 @@ export class Mutator< const entity = this.entity; const qb = this.appendWhere(this.conn.deleteFrom(entity.name), where).returning( - entity.getSelect() + entity.getSelect(), ); return (await this.many(qb)) as any; @@ -282,7 +282,7 @@ export class Mutator< async updateWhere( data: Partial, - where?: RepoQuery["where"] + where?: RepoQuery["where"], ): Promise> { const entity = this.entity; const validatedData = await this.getValidatedData(data, "update"); @@ -304,7 +304,7 @@ export class Mutator< for (const row of data) { const validatedData = { ...entity.getDefaultObject(), - ...(await this.getValidatedData(row, "create")) + ...(await this.getValidatedData(row, "create")), }; // check if required fields are present diff --git a/app/src/data/entities/query/Repository.ts b/app/src/data/entities/query/Repository.ts index fc8f1ba..e89cd61 100644 --- a/app/src/data/entities/query/Repository.ts +++ b/app/src/data/entities/query/Repository.ts @@ -11,7 +11,7 @@ import { type EntityData, type EntityManager, WhereBuilder, - WithBuilder + WithBuilder, } from "../index"; import { JoinBuilder } from "./JoinBuilder"; @@ -79,7 +79,7 @@ export class Repository 0) { throw new InvalidSearchParamsException( - `Invalid select field(s): ${invalid.join(", ")}` + `Invalid select field(s): ${invalid.join(", ")}`, ).context({ entity: entity.name, - valid: validated.select + valid: validated.select, }); } @@ -122,7 +122,7 @@ export class Repository 0) { throw new InvalidSearchParamsException( - `Invalid where field(s): ${invalid.join(", ")}` + `Invalid where field(s): ${invalid.join(", ")}`, ).context({ aliases, entity: entity.name }); } @@ -189,7 +189,7 @@ export class Repository> { await this.emgr.emit( - new Repository.Events.RepositoryFindOneBefore({ entity: this.entity, options }) + new Repository.Events.RepositoryFindOneBefore({ entity: this.entity, options }), ); const { data, ...response } = await this.performQuery(qb); @@ -233,8 +233,8 @@ export class Repository; - } + }, ) { const entity = this.entity; let qb = _qb ?? (this.conn.selectFrom(entity.name) as RepositoryQB); @@ -262,7 +262,7 @@ export class Repository, - ignore: (keyof RepoQuery)[] = [] + ignore: (keyof RepoQuery)[] = [], ): { qb: RepositoryQB; options: RepoQuery } { const entity = this.entity; const options = this.getValidOptions(_options); @@ -305,23 +305,23 @@ export class Repository> + _options?: Partial>, ): Promise> { const { qb, options } = this.buildQuery( { ..._options, where: { [this.entity.getPrimaryField().name]: id }, - limit: 1 + limit: 1, }, - ["offset", "sort"] + ["offset", "sort"], ); return this.single(qb, options) as any; @@ -329,12 +329,12 @@ export class Repository> + _options?: Partial>, ): Promise> { const { qb, options } = this.buildQuery({ ..._options, where, - limit: 1 + limit: 1, }); return this.single(qb, options) as any; @@ -344,7 +344,7 @@ export class Repository> + _options?: Partial>, ): Promise> { const entity = this.entity; const listable_relations = this.em.relations.listableRelationsOf(entity); @@ -372,7 +372,7 @@ export class Repository 0 + exists: result[0]!.count > 0, }; } } diff --git a/app/src/data/entities/query/WhereBuilder.ts b/app/src/data/entities/query/WhereBuilder.ts index 3473497..acafad5 100644 --- a/app/src/data/entities/query/WhereBuilder.ts +++ b/app/src/data/entities/query/WhereBuilder.ts @@ -6,14 +6,14 @@ import { exp, isBooleanLike, isPrimitive, - makeValidator + makeValidator, } from "core"; import type { DeleteQueryBuilder, ExpressionBuilder, ExpressionWrapper, SelectQueryBuilder, - UpdateQueryBuilder + UpdateQueryBuilder, } from "kysely"; type Builder = ExpressionBuilder; @@ -34,58 +34,58 @@ const expressions = [ exp( "$eq", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), "=", v) + (v, k, eb: Builder) => eb(key(k), "=", v), ), exp( "$ne", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), "!=", v) + (v, k, eb: Builder) => eb(key(k), "!=", v), ), exp( "$gt", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), ">", v) + (v, k, eb: Builder) => eb(key(k), ">", v), ), exp( "$gte", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), ">=", v) + (v, k, eb: Builder) => eb(key(k), ">=", v), ), exp( "$lt", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), "<", v) + (v, k, eb: Builder) => eb(key(k), "<", v), ), exp( "$lte", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), "<=", v) + (v, k, eb: Builder) => eb(key(k), "<=", v), ), exp( "$isnull", (v: BooleanLike) => isBooleanLike(v), - (v, k, eb: Builder) => eb(key(k), v ? "is" : "is not", null) + (v, k, eb: Builder) => eb(key(k), v ? "is" : "is not", null), ), exp( "$in", (v: any[]) => Array.isArray(v), - (v, k, eb: Builder) => eb(key(k), "in", v) + (v, k, eb: Builder) => eb(key(k), "in", v), ), exp( "$notin", (v: any[]) => Array.isArray(v), - (v, k, eb: Builder) => eb(key(k), "not in", v) + (v, k, eb: Builder) => eb(key(k), "not in", v), ), exp( "$between", (v: [number, number]) => Array.isArray(v) && v.length === 2, - (v, k, eb: Builder) => eb.between(key(k), v[0], v[1]) + (v, k, eb: Builder) => eb.between(key(k), v[0], v[1]), ), exp( "$like", (v: Primitive) => isPrimitive(v), - (v, k, eb: Builder) => eb(key(k), "like", String(v).replace(/\*/g, "%")) - ) + (v, k, eb: Builder) => eb(key(k), "like", String(v).replace(/\*/g, "%")), + ), ]; export type WhereQuery = FilterQuery; @@ -103,7 +103,7 @@ export class WhereBuilder { const fns = validator.build(query, { value_is_kv: true, exp_ctx: eb, - convert: true + convert: true, }); if (fns.$or.length > 0 && fns.$and.length > 0) { @@ -124,7 +124,7 @@ export class WhereBuilder { const { keys } = validator.build(query, { value_is_kv: true, exp_ctx: () => null, - convert: true + convert: true, }); return Array.from(keys); } diff --git a/app/src/data/entities/query/WithBuilder.ts b/app/src/data/entities/query/WithBuilder.ts index ce4f14c..84eebb4 100644 --- a/app/src/data/entities/query/WithBuilder.ts +++ b/app/src/data/entities/query/WithBuilder.ts @@ -8,7 +8,7 @@ export class WithBuilder { em: EntityManager, qb: RepositoryQB, entity: Entity, - withs: RepoQuery["with"] + withs: RepoQuery["with"], ) { if (!withs || !isObject(withs)) { console.warn(`'withs' undefined or invalid, given: ${JSON.stringify(withs)}`); @@ -36,8 +36,8 @@ export class WithBuilder { if (query) { subQuery = em.repo(other.entity).addOptionsToQueryBuilder(subQuery, query as any, { ignore: ["with", "join", cardinality === 1 ? "limit" : undefined].filter( - Boolean - ) as any + Boolean, + ) as any, }); } @@ -64,7 +64,7 @@ export class WithBuilder { const related = em.relationOf(entity, ref); if (!related) { throw new InvalidSearchParamsException( - `WITH: "${ref}" is not a relation of "${entity}"` + `WITH: "${ref}" is not a relation of "${entity}"`, ); } depth++; diff --git a/app/src/data/errors.ts b/app/src/data/errors.ts index f4f5810..9f159f7 100644 --- a/app/src/data/errors.ts +++ b/app/src/data/errors.ts @@ -42,11 +42,11 @@ export class InvalidFieldConfigException extends Exception { constructor( field: Field, public given: any, - error: TypeInvalidError + error: TypeInvalidError, ) { console.error("InvalidFieldConfigException", { given, - error: error.firstToString() + error: error.firstToString(), }); super(`Invalid Field config given for field "${field.name}": ${error.firstToString()}`); } @@ -71,7 +71,7 @@ export class EntityNotFoundException extends Exception { constructor(entity: Entity | string, id: any) { super( - `Entity "${typeof entity !== "string" ? entity.name : entity}" with id "${id}" not found` + `Entity "${typeof entity !== "string" ? entity.name : entity}" with id "${id}" not found`, ); } } diff --git a/app/src/data/events/index.ts b/app/src/data/events/index.ts index 3ea038c..5245fca 100644 --- a/app/src/data/events/index.ts +++ b/app/src/data/events/index.ts @@ -14,7 +14,7 @@ export class MutatorInsertBefore extends Event<{ entity: Entity; data: EntityDat return this.clone({ entity, - data + data, }); } } @@ -40,7 +40,7 @@ export class MutatorUpdateBefore extends Event< return this.clone({ ...rest, entity, - data + data, }); } } @@ -68,7 +68,7 @@ export const MutatorEvents = { MutatorUpdateBefore, MutatorUpdateAfter, MutatorDeleteBefore, - MutatorDeleteAfter + MutatorDeleteAfter, }; export class RepositoryFindOneBefore extends Event<{ entity: Entity; options: RepoQuery }> { @@ -98,5 +98,5 @@ export const RepositoryEvents = { RepositoryFindOneBefore, RepositoryFindOneAfter, RepositoryFindManyBefore, - RepositoryFindManyAfter + RepositoryFindManyAfter, }; diff --git a/app/src/data/fields/BooleanField.ts b/app/src/data/fields/BooleanField.ts index bbae784..6f73e6f 100644 --- a/app/src/data/fields/BooleanField.ts +++ b/app/src/data/fields/BooleanField.ts @@ -5,9 +5,9 @@ import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema export const booleanFieldConfigSchema = Type.Composite([ Type.Object({ - default_value: Type.Optional(Type.Boolean({ default: false })) + default_value: Type.Optional(Type.Boolean({ default: false })), }), - baseFieldConfigSchema + baseFieldConfigSchema, ]); export type BooleanFieldConfig = Static; @@ -40,7 +40,7 @@ export class BooleanField extends Field< override getHtmlConfig() { return { ...super.getHtmlConfig(), - element: "boolean" + element: "boolean", }; } @@ -64,7 +64,7 @@ export class BooleanField extends Field< override async transformPersist( val: unknown, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(val, em, context); if (this.nullish(value)) { diff --git a/app/src/data/fields/DateField.ts b/app/src/data/fields/DateField.ts index 000e64e..5020376 100644 --- a/app/src/data/fields/DateField.ts +++ b/app/src/data/fields/DateField.ts @@ -9,13 +9,13 @@ export const dateFieldConfigSchema = Type.Composite( type: StringEnum(["date", "datetime", "week"] as const, { default: "date" }), timezone: Type.Optional(Type.String()), min_date: Type.Optional(Type.String()), - max_date: Type.Optional(Type.String()) + max_date: Type.Optional(Type.String()), }), - baseFieldConfigSchema + baseFieldConfigSchema, ], { - additionalProperties: false - } + additionalProperties: false, + }, ); export type DateFieldConfig = Static; @@ -43,8 +43,8 @@ export class DateField extends Field< ...super.getHtmlConfig(), element: "date", props: { - type: htmlType - } + type: htmlType, + }, }; } @@ -53,7 +53,7 @@ export class DateField extends Field< if (this.config.type === "week" && value.includes("-W")) { const [year, week] = value.split("-W").map((n) => Number.parseInt(n, 10)) as [ number, - number + number, ]; //console.log({ year, week }); // @ts-ignore causes errors on build? @@ -129,7 +129,7 @@ export class DateField extends Field< override async transformPersist( _value: any, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(_value, em, context); if (this.nullish(value)) return value; diff --git a/app/src/data/fields/EnumField.ts b/app/src/data/fields/EnumField.ts index 8c44afb..79eee93 100644 --- a/app/src/data/fields/EnumField.ts +++ b/app/src/data/fields/EnumField.ts @@ -12,9 +12,9 @@ export const enumFieldConfigSchema = Type.Composite( Type.Object( { type: Const("strings"), - values: Type.Array(Type.String()) + values: Type.Array(Type.String()), }, - { title: "Strings" } + { title: "Strings" }, ), Type.Object( { @@ -22,23 +22,23 @@ export const enumFieldConfigSchema = Type.Composite( values: Type.Array( Type.Object({ label: Type.String(), - value: Type.String() - }) - ) + value: Type.String(), + }), + ), }, { title: "Objects", - additionalProperties: false - } - ) - ]) - ) + additionalProperties: false, + }, + ), + ]), + ), }), - baseFieldConfigSchema + baseFieldConfigSchema, ], { - additionalProperties: false - } + additionalProperties: false, + }, ); export type EnumFieldConfig = Static; @@ -123,7 +123,7 @@ export class EnumField, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(_value, em, context); if (this.nullish(value)) return value; @@ -132,7 +132,7 @@ export class EnumField o.value) - .join(", ")}` + .join(", ")}`, ); } @@ -146,8 +146,8 @@ export class EnumField; @@ -72,7 +72,7 @@ export type SchemaResponse = [string, ColumnDataType, ColumnBuilderCallback] | u export abstract class Field< Config extends BaseFieldConfig = BaseFieldConfig, Type = any, - Required extends true | false = false + Required extends true | false = false, > { _required!: Required; _type!: Type; @@ -108,7 +108,7 @@ export abstract class Field< protected useSchemaHelper( type: ColumnDataType, - builder?: (col: ColumnDefinitionBuilder) => ColumnDefinitionBuilder + builder?: (col: ColumnDefinitionBuilder) => ColumnDefinitionBuilder, ): SchemaResponse { return [ this.name, @@ -116,7 +116,7 @@ export abstract class Field< (col: ColumnDefinitionBuilder) => { if (builder) return builder(col); return col; - } + }, ]; } @@ -189,7 +189,7 @@ export abstract class Field< getHtmlConfig(): { element: HTMLInputTypeAttribute | string; props?: InputHTMLAttributes } { return { element: "input", - props: { type: "text" } + props: { type: "text" }, }; } @@ -217,7 +217,7 @@ export abstract class Field< async transformPersist( value: unknown, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { if (this.nullish(value)) { if (this.isRequired() && !this.hasDefault()) { @@ -245,7 +245,7 @@ export abstract class Field< return { // @todo: current workaround because of fixed string type type: this.type as any, - config: this.config + config: this.config, }; } } diff --git a/app/src/data/fields/JsonField.ts b/app/src/data/fields/JsonField.ts index dd08ae9..62a7677 100644 --- a/app/src/data/fields/JsonField.ts +++ b/app/src/data/fields/JsonField.ts @@ -83,7 +83,7 @@ export class JsonField, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(_value, em, context); //console.log("value", value); @@ -91,7 +91,7 @@ export class JsonField; export class JsonSchemaField< Required extends true | false = false, - TypeOverride = object + TypeOverride = object, > extends Field { override readonly type = "jsonschema"; private validator: Validator; @@ -107,7 +107,7 @@ export class JsonSchemaField< override async transformPersist( _value: any, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(_value, em, context); if (this.nullish(value)) return value; @@ -130,8 +130,8 @@ export class JsonSchemaField< return this.toSchemaWrapIfRequired( FromSchema({ default: this.getDefault(), - ...schema - }) + ...schema, + }), ); } } diff --git a/app/src/data/fields/NumberField.ts b/app/src/data/fields/NumberField.ts index 0e98832..756ccba 100644 --- a/app/src/data/fields/NumberField.ts +++ b/app/src/data/fields/NumberField.ts @@ -11,13 +11,13 @@ export const numberFieldConfigSchema = Type.Composite( maximum: Type.Optional(Type.Number()), exclusiveMinimum: Type.Optional(Type.Number()), exclusiveMaximum: Type.Optional(Type.Number()), - multipleOf: Type.Optional(Type.Number()) + multipleOf: Type.Optional(Type.Number()), }), - baseFieldConfigSchema + baseFieldConfigSchema, ], { - additionalProperties: false - } + additionalProperties: false, + }, ); export type NumberFieldConfig = Static; @@ -39,8 +39,8 @@ export class NumberField extends Field< props: { type: "number", pattern: "d*", - inputMode: "numeric" - } as any // @todo: react expects "inputMode", but type dictates "inputmode" + inputMode: "numeric", + } as any, // @todo: react expects "inputMode", but type dictates "inputmode" }; } @@ -62,7 +62,7 @@ export class NumberField extends Field< override async transformPersist( _value: unknown, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { const value = await super.transformPersist(_value, em, context); @@ -72,13 +72,13 @@ export class NumberField extends Field< if (this.config.maximum && (value as number) > this.config.maximum) { throw new TransformPersistFailedException( - `Field "${this.name}" cannot be greater than ${this.config.maximum}` + `Field "${this.name}" cannot be greater than ${this.config.maximum}`, ); } if (this.config.minimum && (value as number) < this.config.minimum) { throw new TransformPersistFailedException( - `Field "${this.name}" cannot be less than ${this.config.minimum}` + `Field "${this.name}" cannot be less than ${this.config.minimum}`, ); } @@ -93,8 +93,8 @@ export class NumberField extends Field< maximum: this.config?.maximum, exclusiveMinimum: this.config?.exclusiveMinimum, exclusiveMaximum: this.config?.exclusiveMaximum, - multipleOf: this.config?.multipleOf - }) + multipleOf: this.config?.multipleOf, + }), ); } } diff --git a/app/src/data/fields/PrimaryField.ts b/app/src/data/fields/PrimaryField.ts index c2d9436..6245944 100644 --- a/app/src/data/fields/PrimaryField.ts +++ b/app/src/data/fields/PrimaryField.ts @@ -5,8 +5,8 @@ import { Field, baseFieldConfigSchema } from "./Field"; export const primaryFieldConfigSchema = Type.Composite([ Type.Omit(baseFieldConfigSchema, ["required"]), Type.Object({ - required: Type.Optional(Type.Literal(false)) - }) + required: Type.Optional(Type.Literal(false)), + }), ]); export type PrimaryFieldConfig = Static; diff --git a/app/src/data/fields/TextField.ts b/app/src/data/fields/TextField.ts index 6dc17d3..7ebcea5 100644 --- a/app/src/data/fields/TextField.ts +++ b/app/src/data/fields/TextField.ts @@ -19,19 +19,19 @@ export const textFieldConfigSchema = Type.Composite( { additionalProperties: Type.Union([ Type.String({ title: "String" }), - Type.Number({ title: "Number" }) - ]) - } - ) - ) - }) - ) + Type.Number({ title: "Number" }), + ]), + }, + ), + ), + }), + ), }), - baseFieldConfigSchema + baseFieldConfigSchema, ], { - additionalProperties: false - } + additionalProperties: false, + }, ); export type TextFieldConfig = Static; @@ -81,7 +81,7 @@ export class TextField extends Field< override async transformPersist( _value: any, em: EntityManager, - context: TActionContext + context: TActionContext, ): Promise { let value = await super.transformPersist(_value, em, context); @@ -94,19 +94,19 @@ export class TextField extends Field< if (this.config.maxLength && value?.length > this.config.maxLength) { throw new TransformPersistFailedException( - `Field "${this.name}" must be at most ${this.config.maxLength} character(s)` + `Field "${this.name}" must be at most ${this.config.maxLength} character(s)`, ); } if (this.config.minLength && value?.length < this.config.minLength) { throw new TransformPersistFailedException( - `Field "${this.name}" must be at least ${this.config.minLength} character(s)` + `Field "${this.name}" must be at least ${this.config.minLength} character(s)`, ); } if (this.config.pattern && value && !new RegExp(this.config.pattern).test(value)) { throw new TransformPersistFailedException( - `Field "${this.name}" must match the pattern ${this.config.pattern}` + `Field "${this.name}" must match the pattern ${this.config.pattern}`, ); } @@ -119,8 +119,8 @@ export class TextField extends Field< default: this.getDefault(), minLength: this.config?.minLength, maxLength: this.config?.maxLength, - pattern: this.config?.pattern - }) + pattern: this.config?.pattern, + }), ); } } diff --git a/app/src/data/fields/VirtualField.ts b/app/src/data/fields/VirtualField.ts index ebb1300..d02869b 100644 --- a/app/src/data/fields/VirtualField.ts +++ b/app/src/data/fields/VirtualField.ts @@ -25,8 +25,8 @@ export class VirtualField extends Field { return this.toSchemaWrapIfRequired( Type.Any({ default: this.getDefault(), - readOnly: true - }) + readOnly: true, + }), ); } } diff --git a/app/src/data/fields/index.ts b/app/src/data/fields/index.ts index ddca371..58a34f8 100644 --- a/app/src/data/fields/index.ts +++ b/app/src/data/fields/index.ts @@ -5,7 +5,7 @@ import { JsonField, type JsonFieldConfig, jsonFieldConfigSchema } from "./JsonFi import { JsonSchemaField, type JsonSchemaFieldConfig, - jsonSchemaFieldConfigSchema + jsonSchemaFieldConfigSchema, } from "./JsonSchemaField"; import { NumberField, type NumberFieldConfig, numberFieldConfigSchema } from "./NumberField"; import { PrimaryField, type PrimaryFieldConfig, primaryFieldConfigSchema } from "./PrimaryField"; @@ -35,7 +35,7 @@ export { type NumberFieldConfig, TextField, textFieldConfigSchema, - type TextFieldConfig + type TextFieldConfig, }; export * from "./Field"; @@ -51,5 +51,5 @@ export const FieldClassMap = { date: { schema: dateFieldConfigSchema, field: DateField }, enum: { schema: enumFieldConfigSchema, field: EnumField }, json: { schema: jsonFieldConfigSchema, field: JsonField }, - jsonschema: { schema: jsonSchemaFieldConfigSchema, field: JsonSchemaField } + jsonschema: { schema: jsonSchemaFieldConfigSchema, field: JsonSchemaField }, } as const; diff --git a/app/src/data/fields/indices/EntityIndex.ts b/app/src/data/fields/indices/EntityIndex.ts index 8346eba..239510b 100644 --- a/app/src/data/fields/indices/EntityIndex.ts +++ b/app/src/data/fields/indices/EntityIndex.ts @@ -6,7 +6,7 @@ export class EntityIndex { public entity: Entity, public fields: Field[], public unique: boolean = false, - public name?: string + public name?: string, ) { if (fields.length === 0) { throw new Error("Indices must contain at least one field"); @@ -21,7 +21,7 @@ export class EntityIndex { throw new Error( `Unique indices must have first field as required: ${fields .map((f) => f.name) - .join(", ")}` + .join(", ")}`, ); } } @@ -30,7 +30,7 @@ export class EntityIndex { this.name = [ unique ? "idx_unique" : "idx", entity.name, - ...fields.map((f) => f.name) + ...fields.map((f) => f.name), ].join("_"); } } @@ -40,7 +40,7 @@ export class EntityIndex { entity: this.entity.name, fields: this.fields.map((f) => f.name), //name: this.name, - unique: this.unique + unique: this.unique, }; } } diff --git a/app/src/data/helper.ts b/app/src/data/helper.ts index e465247..838b3b0 100644 --- a/app/src/data/helper.ts +++ b/app/src/data/helper.ts @@ -8,7 +8,7 @@ export function getDefaultValues(fields: Field[], data: EntityData): EntityData // form fields don't like "null" or "undefined", so return empty string acc[field.name] = field.getValue(data?.[field.name], "form") ?? ""; }, - {} as EntityData + {} as EntityData, ); } @@ -16,7 +16,7 @@ export function getChangeSet( action: string, formData: EntityData, data: EntityData, - fields: Field[] + fields: Field[], ): EntityData { //console.log("getChangeSet", formData, data); return transform( @@ -45,7 +45,7 @@ export function getChangeSet( //console.log("no change", key, value, data[key]); } }, - {} as typeof formData + {} as typeof formData, ); } @@ -54,17 +54,17 @@ export function readableEmJson(_em: EntityManager) { entities: _em.entities.map((e) => ({ name: e.name, fields: e.fields.map((f) => f.name), - type: e.type + type: e.type, })), indices: _em.indices.map((i) => ({ name: i.name, entity: i.entity.name, fields: i.fields.map((f) => f.name), - unique: i.unique + unique: i.unique, })), relations: _em.relations.all.map((r) => ({ name: r.getName(), - ...r.toJSON() - })) + ...r.toJSON(), + })), }; } diff --git a/app/src/data/index.ts b/app/src/data/index.ts index e63707e..165436f 100644 --- a/app/src/data/index.ts +++ b/app/src/data/index.ts @@ -11,7 +11,7 @@ export { type RepoQueryIn, defaultQuerySchema, querySchema, - whereSchema + whereSchema, } from "./server/data-query-impl"; export { Connection } from "./connection/Connection"; @@ -25,7 +25,7 @@ export { constructEntity, constructRelation } from "./schema/constructor"; export const DatabaseEvents = { ...MutatorEvents, - ...RepositoryEvents + ...RepositoryEvents, }; export { MutatorEvents, RepositoryEvents }; diff --git a/app/src/data/plugins/DeserializeJsonValuesPlugin.ts b/app/src/data/plugins/DeserializeJsonValuesPlugin.ts index 494b4b4..519b26d 100644 --- a/app/src/data/plugins/DeserializeJsonValuesPlugin.ts +++ b/app/src/data/plugins/DeserializeJsonValuesPlugin.ts @@ -13,9 +13,7 @@ export class DeserializeJsonValuesPlugin implements KyselyPlugin { transformQuery(args: PluginTransformQueryArgs): RootOperationNode { return args.node; } - transformResult( - args: PluginTransformResultArgs - ): Promise> { + transformResult(args: PluginTransformResultArgs): Promise> { return Promise.resolve({ ...args.result, rows: args.result.rows.map((row: KeyValueObject) => { diff --git a/app/src/data/prototype/index.ts b/app/src/data/prototype/index.ts index 6a05f72..aa6d90a 100644 --- a/app/src/data/prototype/index.ts +++ b/app/src/data/prototype/index.ts @@ -31,7 +31,7 @@ import { type PolymorphicRelationConfig, type TEntityType, TextField, - type TextFieldConfig + type TextFieldConfig, } from "../index"; type Options = { @@ -56,44 +56,44 @@ const FieldMap = { media: (o: Options) => new MediaField(o.field_name, { ...o.config, entity: o.entity.name, required: o.is_required }), medium: (o: Options) => - new MediaField(o.field_name, { ...o.config, entity: o.entity.name, required: o.is_required }) + new MediaField(o.field_name, { ...o.config, entity: o.entity.name, required: o.is_required }), } as const; type TFieldType = keyof typeof FieldMap; export function text( - config?: Omit + config?: Omit, ): TextField & { required: () => TextField } { return new FieldPrototype("text", config, false) as any; } export function number( - config?: Omit + config?: Omit, ): NumberField & { required: () => NumberField } { return new FieldPrototype("number", config, false) as any; } export function date( - config?: Omit + config?: Omit, ): DateField & { required: () => DateField } { return new FieldPrototype("date", { ...config, type: "date" }, false) as any; } export function datetime( - config?: Omit + config?: Omit, ): DateField & { required: () => DateField } { return new FieldPrototype("date", { ...config, type: "datetime" }, false) as any; } export function week( - config?: Omit + config?: Omit, ): DateField & { required: () => DateField } { return new FieldPrototype("date", { ...config, type: "week" }, false) as any; } export function boolean( - config?: Omit + config?: Omit, ): BooleanField & { required: () => BooleanField } { return new FieldPrototype("boolean", config, false) as any; } export function enumm( config?: Omit & { enum: string[] | { label: string; value: string }[]; - } + }, ): EnumField & { required: () => EnumField; } { @@ -101,18 +101,18 @@ export function enumm( const actual_config = { options: { type, - values: config?.enum ?? [] - } + values: config?.enum ?? [], + }, }; return new FieldPrototype("enumm", actual_config, false) as any; } export function json( - config?: Omit + config?: Omit, ): JsonField & { required: () => JsonField } { return new FieldPrototype("json", config, false) as any; } export function jsonSchema( - config?: Omit + config?: Omit, ): JsonField & { required: () => JsonSchemaField } { return new FieldPrototype("jsonSchema", config, false) as any; } @@ -120,7 +120,7 @@ export function media(config?: Omit): MediaField + config?: Omit, ): MediaField { return new FieldPrototype("media", { ...config, max_items: 1 }, false) as any; } @@ -135,7 +135,7 @@ export class FieldPrototype { constructor( public type: TFieldType, public config: any, - public is_required: boolean + public is_required: boolean, ) {} required() { @@ -163,7 +163,7 @@ export class FieldPrototype { entity: { name: "unknown", fields: {} }, field_name, config: this.config, - is_required: this.is_required + is_required: this.is_required, }) as unknown as Field; } catch (e) { throw new Error(`Faild to construct field "${this.type}": ${e}`); @@ -175,12 +175,12 @@ export class FieldPrototype { export function entity< EntityName extends string, - Fields extends Record> + Fields extends Record>, >( name: EntityName, fields: Fields, config?: EntityConfig, - type?: TEntityType + type?: TEntityType, ): Entity { const _fields: Field[] = []; for (const [field_name, field] of Object.entries(fields)) { @@ -189,7 +189,7 @@ export function entity< entity: { name, fields }, field_name, config: f.config, - is_required: f.is_required + is_required: f.is_required, }; _fields.push(f.getField(o)); } @@ -207,7 +207,7 @@ export function relation(local: Local) { manyToMany: ( foreign: Foreign, config?: ManyToManyRelationConfig, - additionalFields?: Record> + additionalFields?: Record>, ) => { const add_fields: Field[] = []; if (additionalFields) { @@ -221,7 +221,7 @@ export function relation(local: Local) { entity: { name: entity_name, fields }, field_name, config: f.config, - is_required: f.is_required + is_required: f.is_required, }; _fields.push(f.getField(o)); } @@ -232,16 +232,16 @@ export function relation(local: Local) { }, polyToOne: ( foreign: Foreign, - config?: Omit + config?: Omit, ) => { return new PolymorphicRelation(local, foreign, { ...config, targetCardinality: 1 }); }, polyToMany: ( foreign: Foreign, - config?: PolymorphicRelationConfig + config?: PolymorphicRelationConfig, ) => { return new PolymorphicRelation(local, foreign, config); - } + }, }; } @@ -256,7 +256,7 @@ export function index(entity: E) { return field; }); return new EntityIndex(entity, _fields, unique); - } + }, }; } @@ -266,7 +266,7 @@ class EntityManagerPrototype> extends En constructor( public __entities: Entities, relations: EntityRelation[] = [], - indices: EntityIndex[] = [] + indices: EntityIndex[] = [], ) { super(Object.values(__entities), new DummyConnection(), relations, indices); } @@ -279,7 +279,7 @@ type Chained any>> = { }; type ChainedFn< Fn extends (...args: any[]) => Record any>, - Return extends ReturnType = ReturnType + Return extends ReturnType = ReturnType, > = (e: Entity) => { [K in keyof Return]: (...args: Parameters) => Chained; }; @@ -288,8 +288,8 @@ export function em>( entities: Entities, schema?: ( fns: { relation: ChainedFn; index: ChainedFn }, - entities: Entities - ) => void + entities: Entities, + ) => void, ) { const relations: EntityRelation[] = []; const indices: EntityIndex[] = []; @@ -301,7 +301,7 @@ export function em>( relations.push(target[prop](...args)); return relationProxy(e); }; - } + }, }) as any; }; @@ -312,7 +312,7 @@ export function em>( indices.push(target[prop](...args)); return indexProxy(e); }; - } + }, }) as any; }; @@ -327,7 +327,7 @@ export function em>( relations, indices, toJSON: () => - e.toJSON() as unknown as Pick + e.toJSON() as unknown as Pick, }; } @@ -367,7 +367,7 @@ type OptionalUndefined< ? undefined extends T[Props] ? Props : never - : never + : never, > = Merge< { [K in OptionsProps]?: T[K]; diff --git a/app/src/data/relations/EntityRelation.ts b/app/src/data/relations/EntityRelation.ts index 07611d0..884fb23 100644 --- a/app/src/data/relations/EntityRelation.ts +++ b/app/src/data/relations/EntityRelation.ts @@ -4,7 +4,7 @@ import type { Entity, EntityData, EntityManager } from "../entities"; import { type EntityRelationAnchor, type MutationInstructionResponse, - RelationHelper + RelationHelper, } from "../relations"; import type { RepoQuery } from "../server/data-query-impl"; import type { RelationType } from "./relation-types"; @@ -25,7 +25,7 @@ export type BaseRelationConfig = Static; // @todo: add generic type for relation config export abstract class EntityRelation< - Schema extends typeof EntityRelation.schema = typeof EntityRelation.schema + Schema extends typeof EntityRelation.schema = typeof EntityRelation.schema, > { config: Static; @@ -39,14 +39,14 @@ export abstract class EntityRelation< static schema = Type.Object({ mappedBy: Type.Optional(Type.String()), inversedBy: Type.Optional(Type.String()), - required: Type.Optional(Type.Boolean()) + required: Type.Optional(Type.Boolean()), }); // don't make protected, App requires it to instantiatable constructor( source: EntityRelationAnchor, target: EntityRelationAnchor, - config: Partial> = {} + config: Partial> = {}, ) { this.source = source; this.target = target; @@ -67,13 +67,13 @@ export abstract class EntityRelation< */ abstract buildWith( entity: Entity, - reference: string + reference: string, ): (eb: ExpressionBuilder) => KyselyQueryBuilder; abstract buildJoin( entity: Entity, qb: KyselyQueryBuilder, - reference: string + reference: string, ): KyselyQueryBuilder; getReferenceQuery(entity: Entity, id: number, reference: string): Partial { @@ -105,7 +105,7 @@ export abstract class EntityRelation< throw new Error( `Entity "${entity_name}" is not part of the relation ` + - `"${this.source.entity.name} <-> ${this.target.entity.name}"` + `"${this.source.entity.name} <-> ${this.target.entity.name}"`, ); } @@ -141,7 +141,7 @@ export abstract class EntityRelation< if (Array.isArray(hydrated) && hydrated.length > 1) { throw new Error( `Failed to hydrate "${anchor.entity.name}" ` + - `with value: ${JSON.stringify(value)} (cardinality: 1)` + `with value: ${JSON.stringify(value)} (cardinality: 1)`, ); } @@ -151,7 +151,7 @@ export abstract class EntityRelation< if (!hydrated) { throw new Error( `Failed to hydrate "${anchor.entity.name}" ` + - `with value: ${JSON.stringify(value)} (cardinality: -)` + `with value: ${JSON.stringify(value)} (cardinality: -)`, ); } @@ -178,7 +178,7 @@ export abstract class EntityRelation< async $set( em: EntityManager, key: string, - value: unknown + value: unknown, ): Promise { throw new Error("$set is not allowed"); } @@ -186,7 +186,7 @@ export abstract class EntityRelation< async $create( em: EntityManager, key: string, - value: unknown + value: unknown, ): Promise { throw new Error("$create is not allowed"); } @@ -194,7 +194,7 @@ export abstract class EntityRelation< async $attach( em: EntityManager, key: string, - value: unknown + value: unknown, ): Promise { throw new Error("$attach is not allowed"); } @@ -202,7 +202,7 @@ export abstract class EntityRelation< async $detach( em: EntityManager, key: string, - value: unknown + value: unknown, ): Promise { throw new Error("$detach is not allowed"); } @@ -213,7 +213,7 @@ export abstract class EntityRelation< this.source.entity.name, this.target.entity.name, this.config.mappedBy, - this.config.inversedBy + this.config.inversedBy, ].filter(Boolean); return parts.join("_"); } @@ -223,7 +223,7 @@ export abstract class EntityRelation< type: this.type(), source: this.source.entity.name, target: this.target.entity.name, - config: this.config + config: this.config, }; } } diff --git a/app/src/data/relations/ManyToManyRelation.ts b/app/src/data/relations/ManyToManyRelation.ts index 3f5f20c..5629783 100644 --- a/app/src/data/relations/ManyToManyRelation.ts +++ b/app/src/data/relations/ManyToManyRelation.ts @@ -21,19 +21,19 @@ export class ManyToManyRelation extends EntityRelation f instanceof RelationField && f.target() === entity.name + (f) => f instanceof RelationField && f.target() === entity.name, )!; if (!selfField || !(selfField instanceof RelationField)) { throw new Error( - `Connection entity "${conn.name}" does not have a relation to "${entity.name}"` + `Connection entity "${conn.name}" does not have a relation to "${entity.name}"`, ); } @@ -87,7 +87,7 @@ export class ManyToManyRelation extends EntityRelation !(f instanceof RelationField || f instanceof PrimaryField) + (f) => !(f instanceof RelationField || f instanceof PrimaryField), ); return (eb: ExpressionBuilder) => @@ -149,9 +149,9 @@ export class ManyToManyRelation extends EntityRelation [f.name, eb2.ref(`${conn}.${f.name}`)]) - ) - ).as(this.connectionTableMappedName) + additionalFields.map((f) => [f.name, eb2.ref(`${conn}.${f.name}`)]), + ), + ).as(this.connectionTableMappedName), ); } @@ -186,7 +186,7 @@ export class ManyToManyRelation extends EntityRelation; export class ManyToOneRelation extends EntityRelation { private fieldConfig?: RelationFieldBaseConfig; static DEFAULTS = { - with_limit: 5 + with_limit: 5, }; static override schema = Type.Composite( @@ -32,24 +32,24 @@ export class ManyToOneRelation extends EntityRelation> = {} + config: Partial> = {}, ) { const mappedBy = config.mappedBy || target.name; const inversedBy = config.inversedBy || source.name; @@ -78,15 +78,15 @@ export class ManyToOneRelation extends EntityRelation, key: string, - value: object + value: object, ): Promise { if (typeof value !== "object") { throw new Error(`Invalid value for relation field "${key}" given, expected object.`); @@ -204,14 +204,14 @@ export class ManyToOneRelation extends EntityRelation, key: string, - value: object + value: object, ): Promise { throw new Error("$set is not allowed"); } @@ -49,7 +49,7 @@ export class OneToOneRelation extends ManyToOneRelation { override async $create( em: EntityManager, key: string, - value: unknown + value: unknown, ): Promise { if (value === null || typeof value !== "object") { throw new Error(`Invalid value for relation field "${key}" given, expected object.`); diff --git a/app/src/data/relations/PolymorphicRelation.ts b/app/src/data/relations/PolymorphicRelation.ts index cf77108..f15b04e 100644 --- a/app/src/data/relations/PolymorphicRelation.ts +++ b/app/src/data/relations/PolymorphicRelation.ts @@ -15,12 +15,12 @@ export class PolymorphicRelation extends EntityRelation = {}) { @@ -63,7 +63,7 @@ export class PolymorphicRelation extends EntityRelation - join.onRef(entityRef, "=", otherRef).on(whereLhs, "=", reference) + join.onRef(entityRef, "=", otherRef).on(whereLhs, "=", reference), ) .groupBy(groupBy); } @@ -83,8 +83,8 @@ export class PolymorphicRelation extends EntityRelation { static create( relation: EntityRelation, target: EntityRelationAnchor, - config?: RelationFieldBaseConfig + config?: RelationFieldBaseConfig, ) { const name = [ target.reference ?? target.entity.name, - target.entity.getPrimaryField().name + target.entity.getPrimaryField().name, ].join("_"); //console.log('name', name); return new RelationField(name, { @@ -56,7 +56,7 @@ export class RelationField extends Field { required: relation.required, reference: target.reference, target: target.entity.name, - target_field: target.entity.getPrimaryField().name + target_field: target.entity.getPrimaryField().name, }); } @@ -94,8 +94,8 @@ export class RelationField extends Field { override toJsonSchema() { return this.toSchemaWrapIfRequired( Type.Number({ - $ref: `${this.config?.target}#/properties/${this.config?.target_field}` - }) + $ref: `${this.config?.target}#/properties/${this.config?.target_field}`, + }), ); } } diff --git a/app/src/data/relations/RelationMutator.ts b/app/src/data/relations/RelationMutator.ts index 2becd17..60366e9 100644 --- a/app/src/data/relations/RelationMutator.ts +++ b/app/src/data/relations/RelationMutator.ts @@ -5,7 +5,7 @@ import { ManyToManyRelation, type MutationOperation, MutationOperations, - RelationField + RelationField, } from "../relations"; export type MutationInstructionResponse = [string, PrimaryFieldType | null]; @@ -13,7 +13,7 @@ export type MutationInstructionResponse = [string, PrimaryFieldType | null]; export class RelationMutator { constructor( protected entity: Entity, - protected em: EntityManager + protected em: EntityManager, ) {} /** @@ -32,11 +32,11 @@ export class RelationMutator { // @todo: improve later if (this.entity.type === "generated") { const relation = this.em.relations.all.find( - (r) => r instanceof ManyToManyRelation && r.connectionEntity.name === this.entity.name + (r) => r instanceof ManyToManyRelation && r.connectionEntity.name === this.entity.name, ); if (relation instanceof ManyToManyRelation) { references.push( - ...this.entity.fields.filter((f) => f.type === "relation").map((f) => f.name) + ...this.entity.fields.filter((f) => f.type === "relation").map((f) => f.name), ); } } @@ -53,7 +53,7 @@ export class RelationMutator { async persistRelationField( field: RelationField, key: string, - value: PrimaryFieldType + value: PrimaryFieldType, ): Promise { // allow empty if field is not required if (value === null && !field.isRequired()) { @@ -68,14 +68,14 @@ export class RelationMutator { } const query = await this.em.repository(field.target()).exists({ - [field.targetField()]: value + [field.targetField()]: value, }); if (!query.exists) { const idProp = field.targetField(); throw new Error( `Cannot connect "${this.entity.name}.${key}" to ` + - `"${field.target()}.${idProp}" = "${value}": not found.` + `"${field.target()}.${idProp}" = "${value}": not found.`, ); } @@ -85,11 +85,11 @@ export class RelationMutator { async persistReference( relation: EntityRelation, key: string, - value: unknown + value: unknown, ): Promise { if (typeof value !== "object" || value === null || typeof value === "undefined") { throw new Error( - `Invalid value for relation "${key}" given, expected object to persist reference. Like '{$set: {id: 1}}'.` + `Invalid value for relation "${key}" given, expected object to persist reference. Like '{$set: {id: 1}}'.`, ); } @@ -97,7 +97,7 @@ export class RelationMutator { if (!MutationOperations.includes(operation)) { throw new Error( `Invalid operation "${operation}" for relation "${key}". ` + - `Allowed: ${MutationOperations.join(", ")}` + `Allowed: ${MutationOperations.join(", ")}`, ); } @@ -131,7 +131,7 @@ export class RelationMutator { throw new Error( `Relation "${key}" failed to resolve on entity "${this.entity.name}": ` + - "Unable to resolve relation origin." + "Unable to resolve relation origin.", ); } } diff --git a/app/src/data/relations/index.ts b/app/src/data/relations/index.ts index 5988689..6f4c3a5 100644 --- a/app/src/data/relations/index.ts +++ b/app/src/data/relations/index.ts @@ -14,7 +14,7 @@ import { RelationField, type RelationFieldBaseConfig, type RelationFieldConfig, - relationFieldConfigSchema + relationFieldConfigSchema, } from "./RelationField"; export { @@ -32,7 +32,7 @@ export { RelationField, relationFieldConfigSchema, type RelationFieldBaseConfig, - type RelationFieldConfig + type RelationFieldConfig, }; export const RelationClassMap = { @@ -41,10 +41,10 @@ export const RelationClassMap = { [RelationTypes.ManyToMany]: { schema: ManyToManyRelation.schema, cls: ManyToManyRelation }, [RelationTypes.Polymorphic]: { schema: PolymorphicRelation.schema, - cls: PolymorphicRelation - } + cls: PolymorphicRelation, + }, } as const; export const RelationFieldClassMap = { - relation: { schema: relationFieldConfigSchema, field: RelationField } + relation: { schema: relationFieldConfigSchema, field: RelationField }, } as const; diff --git a/app/src/data/schema/SchemaManager.ts b/app/src/data/schema/SchemaManager.ts index ef880bd..58a3127 100644 --- a/app/src/data/schema/SchemaManager.ts +++ b/app/src/data/schema/SchemaManager.ts @@ -58,7 +58,7 @@ export class SchemaManager { async introspect(): Promise { const tables = await this.getIntrospector().getTables({ - withInternalKyselyTables: false + withInternalKyselyTables: false, }); const indices = await this.getIntrospector().getIndices(); @@ -71,7 +71,7 @@ export class SchemaManager { cleanTables.push({ ...table, - indices: indices.filter((index) => index.table === table.name) + indices: indices.filter((index) => index.table === table.name), }); } @@ -94,7 +94,7 @@ export class SchemaManager { isNullable: true, // managed by the field isAutoIncrementing: field instanceof PrimaryField, hasDefaultValue: false, // managed by the field - comment: undefined + comment: undefined, })), indices: indices.map((index) => ({ name: index.name, @@ -102,9 +102,9 @@ export class SchemaManager { isUnique: index.unique, columns: index.fields.map((f) => ({ name: f.name, - order: 0 // doesn't matter - })) - })) as any + order: 0, // doesn't matter + })), + })) as any, }; } @@ -131,12 +131,12 @@ export class SchemaManager { columns: { add: [], drop: [], - change: [] + change: [], }, indices: { add: [], - drop: [] - } + drop: [], + }, }); }); @@ -151,22 +151,22 @@ export class SchemaManager { columns: { add: entity.columns.map(namesFn), drop: [], - change: [] + change: [], }, indices: { add: entity.indices.map(namesFn), - drop: [] - } + drop: [], + }, }); } else { // If the table exists, check for new columns const newColumns = entity.columns.filter( - (newColumn) => !table.columns.map(namesFn).includes(newColumn.name) + (newColumn) => !table.columns.map(namesFn).includes(newColumn.name), ); // check for columns to drop const dropColumns = table.columns.filter( - (oldColumn) => !entity.columns.map(namesFn).includes(oldColumn.name) + (oldColumn) => !entity.columns.map(namesFn).includes(oldColumn.name), ); // check for changed columns @@ -179,25 +179,25 @@ export class SchemaManager { col_diffs.push({ attribute: key, prev: db_col[key], - next: value + next: value, }); } } if (Object.keys(col_diffs).length > 0) { columnDiffs.push({ name: entity_col.name, - changes: col_diffs + changes: col_diffs, }); } } // new indices const newIndices = entity.indices.filter( - (newIndex) => !table.indices.map((i) => i.name).includes(newIndex.name) + (newIndex) => !table.indices.map((i) => i.name).includes(newIndex.name), ); const dropIndices = table.indices.filter( - (oldIndex) => !entity.indices.map((i) => i.name).includes(oldIndex.name) + (oldIndex) => !entity.indices.map((i) => i.name).includes(oldIndex.name), ); const anythingChanged = [ @@ -205,7 +205,7 @@ export class SchemaManager { dropColumns, //columnDiffs, // ignored newIndices, - dropIndices + dropIndices, ].some((arr) => arr.length > 0); if (anythingChanged) { @@ -217,12 +217,12 @@ export class SchemaManager { drop: dropColumns.map(namesFn), // @todo: this is ignored for now //change: columnDiffs.map(namesFn), - change: [] + change: [], }, indices: { add: newIndices.map(namesFn), - drop: dropIndices.map(namesFn) - } + drop: dropIndices.map(namesFn), + }, }); } } diff --git a/app/src/data/schema/constructor.ts b/app/src/data/schema/constructor.ts index a88ba5e..1da566c 100644 --- a/app/src/data/schema/constructor.ts +++ b/app/src/data/schema/constructor.ts @@ -18,17 +18,17 @@ export function constructEntity(name: string, entityConfig: TAppDataEntity) { name, Object.values(fields), entityConfig.config as any, - entityConfig.type as any + entityConfig.type as any, ); } export function constructRelation( relationConfig: TAppDataRelation, - resolver: (name: Entity | string) => Entity + resolver: (name: Entity | string) => Entity, ) { return new RELATIONS[relationConfig.type].cls( resolver(relationConfig.source), resolver(relationConfig.target), - relationConfig.config + relationConfig.config, ); } diff --git a/app/src/data/server/data-query-impl.ts b/app/src/data/server/data-query-impl.ts index ba72c40..581d91e 100644 --- a/app/src/data/server/data-query-impl.ts +++ b/app/src/data/server/data-query-impl.ts @@ -6,7 +6,7 @@ import { StringEnum, Type, Value, - isObject + isObject, } from "core/utils"; import { WhereBuilder, type WhereQuery } from "../entities"; @@ -23,9 +23,9 @@ const sort = Type.Transform( Type.Union( [Type.String(), Type.Object({ by: Type.String(), dir: StringEnum(["asc", "desc"]) })], { - default: sort_default - } - ) + default: sort_default, + }, + ), ) .Decode((value): { by: string; dir: "asc" | "desc" } => { if (typeof value === "string") { @@ -43,7 +43,7 @@ const sort = Type.Transform( .Encode((value) => value); const stringArray = Type.Transform( - Type.Union([Type.String(), Type.Array(Type.String())], { default: [] }) + Type.Union([Type.String(), Type.Array(Type.String())], { default: [] }), ) .Decode((value) => { if (Array.isArray(value)) { @@ -56,7 +56,7 @@ const stringArray = Type.Transform( .Encode((value) => (Array.isArray(value) ? value : [value])); export const whereSchema = Type.Transform( - Type.Union([Type.String(), Type.Object({})], { default: {} }) + Type.Union([Type.String(), Type.Object({})], { default: {} }), ) .Decode((value) => { const q = typeof value === "string" ? JSON.parse(value) : value; @@ -73,7 +73,7 @@ export type RepoWithSchema = Record< export const withSchema = (Self: TSelf) => Type.Transform( - Type.Union([Type.String(), Type.Array(Type.String()), Type.Record(Type.String(), Self)]) + Type.Union([Type.String(), Type.Array(Type.String()), Type.Record(Type.String(), Self)]), ) .Decode((value) => { // images @@ -130,15 +130,15 @@ export const querySchema = Type.Recursive( select: stringArray, with: withSchema(Self), join: stringArray, - where: whereSchema + where: whereSchema, }, { // @todo: determine if unknown is allowed, it's ignore anyway - additionalProperties: false - } - ) + additionalProperties: false, + }, + ), ), - { $id: "query-schema" } + { $id: "query-schema" }, ); export type RepoQueryIn = { diff --git a/app/src/flows/AppFlows.ts b/app/src/flows/AppFlows.ts index c31e051..a75defe 100644 --- a/app/src/flows/AppFlows.ts +++ b/app/src/flows/AppFlows.ts @@ -20,7 +20,7 @@ export class AppFlows extends Module { return { ...flow.toJSON(), tasks: flow.tasks.length, - connections: flow.connections + connections: flow.connections, }; } @@ -59,7 +59,7 @@ export class AppFlows extends Module { errors, response: execution.getResponse(), flow: this.getFlowInfo(flow), - logs: execution.logs + logs: execution.logs, }); }); @@ -84,7 +84,7 @@ export class AppFlows extends Module { override toJSON() { return { ...this.config, - flows: transformObject(this.flows, (flow) => flow.toJSON()) + flows: transformObject(this.flows, (flow) => flow.toJSON()), }; } } diff --git a/app/src/flows/flows-schema.ts b/app/src/flows/flows-schema.ts index d073d15..15365c7 100644 --- a/app/src/flows/flows-schema.ts +++ b/app/src/flows/flows-schema.ts @@ -2,7 +2,7 @@ import { Const, type Static, StringRecord, Type, transformObject } from "core/ut import { TaskMap, TriggerMap } from "flows"; export const TASKS = { - ...TaskMap + ...TaskMap, } as const; export const TRIGGERS = TriggerMap; @@ -11,9 +11,9 @@ const taskSchemaObject = transformObject(TASKS, (task, name) => { return Type.Object( { type: Const(name), - params: task.cls.schema + params: task.cls.schema, }, - { title: String(name), additionalProperties: false } + { title: String(name), additionalProperties: false }, ); }); const taskSchema = Type.Union(Object.values(taskSchemaObject)); @@ -23,9 +23,9 @@ const triggerSchemaObject = transformObject(TRIGGERS, (trigger, name) => { return Type.Object( { type: Const(name), - config: trigger.cls.schema + config: trigger.cls.schema, }, - { title: String(name), additionalProperties: false } + { title: String(name), additionalProperties: false }, ); }); @@ -38,22 +38,22 @@ const connectionSchema = Type.Object({ Type.Union([ Type.Object( { type: Const("success") }, - { additionalProperties: false, title: "success" } + { additionalProperties: false, title: "success" }, ), Type.Object( { type: Const("error") }, - { additionalProperties: false, title: "error" } + { additionalProperties: false, title: "error" }, ), Type.Object( { type: Const("matches"), path: Type.String(), value: Type.String() }, - { additionalProperties: false, title: "matches" } - ) - ]) + { additionalProperties: false, title: "matches" }, + ), + ]), ), - max_retries: Type.Optional(Type.Number()) + max_retries: Type.Optional(Type.Number()), }, - { default: {}, additionalProperties: false } - ) + { default: {}, additionalProperties: false }, + ), }); // @todo: rework to have fixed ids per task and connections (and preferrably arrays) @@ -64,21 +64,21 @@ export const flowSchema = Type.Object( tasks: Type.Optional(StringRecord(Type.Union(Object.values(taskSchemaObject)))), connections: Type.Optional(StringRecord(connectionSchema)), start_task: Type.Optional(Type.String()), - responding_task: Type.Optional(Type.String()) + responding_task: Type.Optional(Type.String()), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); export type TAppFlowSchema = Static; export const flowsConfigSchema = Type.Object( { basepath: Type.String({ default: "/api/flows" }), - flows: StringRecord(flowSchema, { default: {} }) + flows: StringRecord(flowSchema, { default: {} }), }, { default: {}, - additionalProperties: false - } + additionalProperties: false, + }, ); diff --git a/app/src/flows/flows/Execution.ts b/app/src/flows/flows/Execution.ts index cf5cbc7..fc69f74 100644 --- a/app/src/flows/flows/Execution.ts +++ b/app/src/flows/flows/Execution.ts @@ -127,7 +127,7 @@ export class Execution implements EmitsEvents { if (target_runs > max_retries) { //console.log("*** Task reached max retries", t.name); throw new Error( - `Task "${t.name}" reached max retries (${target_runs}/${max_retries})` + `Task "${t.name}" reached max retries (${target_runs}/${max_retries})`, ); } @@ -202,7 +202,7 @@ export class Execution implements EmitsEvents { output: input, // @todo: remove error: undefined, success: true, - params: input + params: input, }); //graceful && (await new Promise((resolve) => setTimeout(resolve, 100))); diff --git a/app/src/flows/flows/Flow.ts b/app/src/flows/flows/Flow.ts index 43356b6..287a46e 100644 --- a/app/src/flows/flows/Flow.ts +++ b/app/src/flows/flows/Flow.ts @@ -163,7 +163,7 @@ export class Flow { tasks: Object.fromEntries(this.tasks.map((t) => [t.name, t.toJSON()])), connections: Object.fromEntries(this.connections.map((c) => [c.id, c.toJSON()])), start_task: this.startTask?.name, - responding_task: this.respondingTask?.name + responding_task: this.respondingTask?.name, }; } @@ -192,7 +192,7 @@ export class Flow { tasks[obj.source], tasks[obj.target], { ...obj.config, condition }, - id as string + id as string, ); }); diff --git a/app/src/flows/flows/FlowTaskConnector.ts b/app/src/flows/flows/FlowTaskConnector.ts index 006ef2d..cd11ff5 100644 --- a/app/src/flows/flows/FlowTaskConnector.ts +++ b/app/src/flows/flows/FlowTaskConnector.ts @@ -22,7 +22,7 @@ export class FlowTaskConnector { const outConnections = this.getOutConnections(); const definedOutConditions = outConnections.map((c) => c.condition); const hasOutGoingBack = outConnections.some( - (c) => this.task(c.target).getDepth() <= ownDepth + (c) => this.task(c.target).getDepth() <= ownDepth, ); if (definedOutConditions.length > 0 && hasOutGoingBack) { @@ -76,7 +76,7 @@ export class FlowTaskConnector { if (lower_only) { const depth = this.getDepth(); return this.getInConnections().filter( - (c) => c.target === this.source && this.task(c.source).getDepth() < depth + (c) => c.target === this.source && this.task(c.source).getDepth() < depth, ); } @@ -97,7 +97,7 @@ export class FlowTaskConnector { getOutConnections(result?: TaskResult): TaskConnection[] { if (result) { return this.flow.connections.filter( - (c) => c.source === this.source && c.condition.isMet(result) + (c) => c.source === this.source && c.condition.isMet(result), ); } diff --git a/app/src/flows/flows/executors/RuntimeExecutor.ts b/app/src/flows/flows/executors/RuntimeExecutor.ts index f1204ea..4f8ec31 100644 --- a/app/src/flows/flows/executors/RuntimeExecutor.ts +++ b/app/src/flows/flows/executors/RuntimeExecutor.ts @@ -3,7 +3,7 @@ import type { Task } from "../../tasks/Task"; export class RuntimeExecutor { async run( nextTasks: () => Task[], - onDone?: (task: Task, result: Awaited>) => void + onDone?: (task: Task, result: Awaited>) => void, ) { const tasks = nextTasks(); if (tasks.length === 0) { diff --git a/app/src/flows/flows/triggers/EventTrigger.ts b/app/src/flows/flows/triggers/EventTrigger.ts index 2fa194c..7426075 100644 --- a/app/src/flows/flows/triggers/EventTrigger.ts +++ b/app/src/flows/flows/triggers/EventTrigger.ts @@ -9,9 +9,9 @@ export class EventTrigger extends Trigger { static override schema = Type.Composite([ Trigger.schema, Type.Object({ - event: Type.String() + event: Type.String(), // add match - }) + }), ]); override async register(flow: Flow, emgr: EventManager) { @@ -35,7 +35,7 @@ export class EventTrigger extends Trigger { console.error(e); } }, - this.config.mode + this.config.mode, ); } } diff --git a/app/src/flows/flows/triggers/HttpTrigger.ts b/app/src/flows/flows/triggers/HttpTrigger.ts index 9c91a9f..442f9de 100644 --- a/app/src/flows/flows/triggers/HttpTrigger.ts +++ b/app/src/flows/flows/triggers/HttpTrigger.ts @@ -14,10 +14,10 @@ export class HttpTrigger extends Trigger { { path: Type.String({ pattern: "^/.*$" }), method: StringEnum(httpMethods, { default: "GET" }), - response_type: StringEnum(["json", "text", "html"], { default: "json" }) - } + response_type: StringEnum(["json", "text", "html"], { default: "json" }), + }, //{ additionalProperties: false } - ) + ), ]); override async register(flow: Flow, hono: Hono) { diff --git a/app/src/flows/flows/triggers/Trigger.ts b/app/src/flows/flows/triggers/Trigger.ts index 9b8afcc..6879ccc 100644 --- a/app/src/flows/flows/triggers/Trigger.ts +++ b/app/src/flows/flows/triggers/Trigger.ts @@ -10,8 +10,8 @@ export class Trigger = any; export function dynamic( type: Type, - parse?: (val: any | string) => Static + parse?: (val: any | string) => Static, ) { const guessDecode = (val: unknown): Static => { if (typeof val === "string") { @@ -46,7 +46,7 @@ export function dynamic( return val as Static; }; - const title = type.title ?? type.type ? ucFirst(type.type) : "Raw"; + const title = (type.title ?? type.type) ? ucFirst(type.type) : "Raw"; return ( Type.Transform(Type.Union([{ title, ...type }, Type.String({ title: "Template" })])) @@ -87,7 +87,7 @@ export abstract class Task { Object.keys(params).length > 0 ) { throw new Error( - `Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}` + `Task "${name}" has no schema defined but params passed: ${JSON.stringify(params)}`, ); } @@ -121,7 +121,7 @@ export abstract class Task { static async resolveParams( schema: S, params: any, - inputs: object = {} + inputs: object = {}, ): Promise> { const newParams: any = {}; const renderer = new SimpleRenderer(inputs, { strictVariables: true, renderKeys: true }); @@ -141,9 +141,9 @@ export abstract class Task { { key, value, - error: e.message + error: e.message, }, - "resolve-params" + "resolve-params", ); } @@ -170,7 +170,7 @@ export abstract class Task { const newParams = await Task.resolveParams( (this.constructor as any).schema, this._params, - inputs + inputs, ); //console.log("--clone:newParams", this.name, newParams); @@ -207,7 +207,7 @@ export abstract class Task { } else { error = { type: "unknown", - message: (e as any).message + message: (e as any).message, }; } } @@ -229,7 +229,7 @@ export abstract class Task { toJSON() { return { type: this.type, - params: this.params + params: this.params, }; } } diff --git a/app/src/flows/tasks/TaskConnection.ts b/app/src/flows/tasks/TaskConnection.ts index fb9e102..54efa3e 100644 --- a/app/src/flows/tasks/TaskConnection.ts +++ b/app/src/flows/tasks/TaskConnection.ts @@ -39,8 +39,8 @@ export class TaskConnection { target: this.target.name, config: { ...this.config, - condition: this.config.condition?.toJSON() - } + condition: this.config.condition?.toJSON(), + }, }); } } @@ -49,7 +49,7 @@ export class Condition { private constructor( public type: "success" | "error" | "matches", public path: string = "", - public value: any = undefined + public value: any = undefined, ) {} static default() { @@ -96,7 +96,7 @@ export class Condition { return { type: this.type, path: this.path.length === 0 ? undefined : this.path, - value: this.value + value: this.value, }; } diff --git a/app/src/flows/tasks/presets/FetchTask.ts b/app/src/flows/tasks/presets/FetchTask.ts index 55671b4..b590c26 100644 --- a/app/src/flows/tasks/presets/FetchTask.ts +++ b/app/src/flows/tasks/presets/FetchTask.ts @@ -12,7 +12,7 @@ export class FetchTask> extends Task< static override schema = Type.Object({ url: Type.String({ - pattern: "^(http|https)://" + pattern: "^(http|https)://", }), //method: Type.Optional(Type.Enum(FetchMethodsEnum)), //method: Type.Optional(dynamic(Type.String({ enum: FetchMethods, default: "GET" }))), @@ -22,14 +22,14 @@ export class FetchTask> extends Task< Type.Array( Type.Object({ key: Type.String(), - value: Type.String() - }) + value: Type.String(), + }), ), - JSON.parse - ) + JSON.parse, + ), ), body: Type.Optional(dynamic(Type.String())), - normal: Type.Optional(dynamic(Type.Number(), Number.parseInt)) + normal: Type.Optional(dynamic(Type.Number(), Number.parseInt)), }); protected getBody(): string | undefined { @@ -46,7 +46,7 @@ export class FetchTask> extends Task< if (!FetchMethods.includes(this.params.method ?? "GET")) { throw this.error("Invalid method", { given: this.params.method, - valid: FetchMethods + valid: FetchMethods, }); } @@ -62,14 +62,14 @@ export class FetchTask> extends Task< const result = await fetch(this.params.url, { method: this.params.method ?? "GET", headers, - body + body, }); //console.log("fetch:response", result); if (!result.ok) { throw this.error("Failed to fetch", { status: result.status, - statusText: result.statusText + statusText: result.statusText, }); } diff --git a/app/src/flows/tasks/presets/LogTask.ts b/app/src/flows/tasks/presets/LogTask.ts index e307ed6..fec93b7 100644 --- a/app/src/flows/tasks/presets/LogTask.ts +++ b/app/src/flows/tasks/presets/LogTask.ts @@ -5,7 +5,7 @@ export class LogTask extends Task { type = "log"; static override schema = Type.Object({ - delay: Type.Number({ default: 10 }) + delay: Type.Number({ default: 10 }), }); async execute() { diff --git a/app/src/flows/tasks/presets/RenderTask.ts b/app/src/flows/tasks/presets/RenderTask.ts index b4a750f..fd3801b 100644 --- a/app/src/flows/tasks/presets/RenderTask.ts +++ b/app/src/flows/tasks/presets/RenderTask.ts @@ -8,7 +8,7 @@ export class RenderTask> extends Task< type = "render"; static override schema = Type.Object({ - render: Type.String() + render: Type.String(), }); async execute() { diff --git a/app/src/flows/tasks/presets/SubFlowTask.ts b/app/src/flows/tasks/presets/SubFlowTask.ts index 8a0fc4c..813ab3d 100644 --- a/app/src/flows/tasks/presets/SubFlowTask.ts +++ b/app/src/flows/tasks/presets/SubFlowTask.ts @@ -11,7 +11,7 @@ export class SubFlowTask> extends Task< static override schema = Type.Object({ flow: Type.Any(), input: Type.Optional(dynamic(Type.Any(), JSON.parse)), - loop: Type.Optional(Type.Boolean()) + loop: Type.Optional(Type.Boolean()), }); async execute() { diff --git a/app/src/index.ts b/app/src/index.ts index 42ab9f8..ca3939c 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -4,7 +4,7 @@ export { AppEvents, type AppConfig, type CreateAppConfig, - type AppPlugin + type AppPlugin, } from "./App"; export { @@ -14,7 +14,7 @@ export { type ModuleSchemas, type ModuleManagerOptions, type ModuleBuildContext, - type InitialModuleConfigs + type InitialModuleConfigs, } from "./modules/ModuleManager"; export * as middlewares from "modules/middlewares"; diff --git a/app/src/media/AppMedia.ts b/app/src/media/AppMedia.ts index 1652440..f71ef6a 100644 --- a/app/src/media/AppMedia.ts +++ b/app/src/media/AppMedia.ts @@ -10,7 +10,7 @@ import { entity, json, number, - text + text, } from "../data/prototype"; import { MediaController } from "./api/MediaController"; import { ADAPTERS, buildMediaSchema, type mediaConfigSchema, registry } from "./media-schema"; @@ -52,12 +52,12 @@ export class AppMedia extends Module { this.ensureSchema( em({ [media.name as "media"]: media }, ({ index }, { media }) => { index(media).on(["path"], true).on(["reference"]).on(["entity_id"]); - }) + }), ); } catch (e) { console.error(e); throw new Error( - `Could not build adapter with config ${JSON.stringify(this.config.adapter)}` + `Could not build adapter with config ${JSON.stringify(this.config.adapter)}`, ); } } @@ -81,7 +81,7 @@ export class AppMedia extends Module { mime_type: info.meta.type, size: info.meta.size, etag: info.etag, - modified_at: new Date() + modified_at: new Date(), }; } @@ -95,7 +95,7 @@ export class AppMedia extends Module { modified_at: datetime(), reference: text(), entity_id: number(), - metadata: json() + metadata: json(), }; getMediaEntity(forceCreate?: boolean): Entity<"media", typeof AppMedia.mediaFields> { @@ -128,7 +128,7 @@ export class AppMedia extends Module { mutator.__unstable_toggleSystemEntityCreation(true); return { data }; }, - { mode: "sync", id: "add-data-media" } + { mode: "sync", id: "add-data-media" }, ); // when file is deleted, sync with media entity @@ -144,7 +144,7 @@ export class AppMedia extends Module { console.log("App:storage:file deleted", e); }, - { mode: "sync", id: "delete-data-media" } + { mode: "sync", id: "delete-data-media" }, ); } @@ -161,7 +161,7 @@ export class AppMedia extends Module { return { ...this.config, - adapter: this.storage.getAdapter().toJSON(secrets) + adapter: this.storage.getAdapter().toJSON(secrets), }; } } diff --git a/app/src/media/MediaField.ts b/app/src/media/MediaField.ts index 6dbb34f..d865f59 100644 --- a/app/src/media/MediaField.ts +++ b/app/src/media/MediaField.ts @@ -6,9 +6,9 @@ export const mediaFieldConfigSchema = Type.Composite([ entity: Type.String(), // @todo: is this really required? min_items: Type.Optional(Type.Number()), max_items: Type.Optional(Type.Number()), - mime_types: Type.Optional(Type.Array(Type.String())) + mime_types: Type.Optional(Type.Array(Type.String())), }), - baseFieldConfigSchema + baseFieldConfigSchema, ]); export type MediaFieldConfig = Static; @@ -26,7 +26,7 @@ export type MediaItem = { export class MediaField< Required extends true | false = false, - TypeOverride = MediaItem[] + TypeOverride = MediaItem[], > extends Field { override readonly type = "media"; @@ -64,7 +64,7 @@ export class MediaField< type: "array", items: { $ref }, minItems, - maxItems + maxItems, }; } } diff --git a/app/src/media/api/MediaApi.ts b/app/src/media/api/MediaApi.ts index c139435..2c3bc7e 100644 --- a/app/src/media/api/MediaApi.ts +++ b/app/src/media/api/MediaApi.ts @@ -3,7 +3,7 @@ import { type BaseModuleApiOptions, ModuleApi, type PrimaryFieldType, - type TInput + type TInput, } from "modules/ModuleApi"; import type { FileWithPath } from "ui/elements/media/file-selector"; @@ -12,7 +12,7 @@ export type MediaApiOptions = BaseModuleApiOptions & {}; export class MediaApi extends ModuleApi { protected override getDefaultOptions(): Partial { return { - basepath: "/api/media" + basepath: "/api/media", }; } @@ -23,8 +23,8 @@ export class MediaApi extends ModuleApi { getFile(filename: string) { return this.get>(["file", filename], undefined, { headers: { - Accept: "*/*" - } + Accept: "*/*", + }, }); } @@ -55,7 +55,7 @@ export class MediaApi extends ModuleApi { getUploadHeaders(): Headers { return new Headers({ - Authorization: `Bearer ${this.options.token}` + Authorization: `Bearer ${this.options.token}`, }); } @@ -65,11 +65,11 @@ export class MediaApi extends ModuleApi { filename?: string; path?: TInput; _init?: Omit; - } + }, ) { const headers = { "Content-Type": "application/octet-stream", - ...(opts?._init?.headers || {}) + ...(opts?._init?.headers || {}), }; let name: string = opts?.filename || ""; try { @@ -87,7 +87,7 @@ export class MediaApi extends ModuleApi { const init = { ...(opts?._init || {}), - headers + headers, }; if (opts?.path) { return this.post(opts.path, body, init); @@ -106,7 +106,7 @@ export class MediaApi extends ModuleApi { filename?: string; _init?: Omit; path?: TInput; - } = {} + } = {}, ) { if (item instanceof Request || typeof item === "string") { const res = await this.fetcher(item); @@ -124,9 +124,9 @@ export class MediaApi extends ModuleApi { ...(opts._init ?? {}), headers: { ...(opts._init?.headers ?? {}), - "Content-Type": item.headers.get("Content-Type") || "application/octet-stream" - } - } + "Content-Type": item.headers.get("Content-Type") || "application/octet-stream", + }, + }, }); } @@ -140,11 +140,11 @@ export class MediaApi extends ModuleApi { item: Request | Response | string | File | ReadableStream, opts?: { _init?: Omit; - } + }, ) { return this.upload(item, { ...opts, - path: ["entity", entity, id, field] + path: ["entity", entity, id, field], }); } diff --git a/app/src/media/api/MediaController.ts b/app/src/media/api/MediaController.ts index 9758fcf..db94553 100644 --- a/app/src/media/api/MediaController.ts +++ b/app/src/media/api/MediaController.ts @@ -65,7 +65,7 @@ export class MediaController extends Controller { return c.json({ type: file?.type, name: file?.name, - size: file?.size + size: file?.size, }); }); } @@ -82,7 +82,7 @@ export class MediaController extends Controller { if (body.size > maxSize) { return c.json( { error: `Max size (${maxSize} bytes) exceeded` }, - HttpStatus.PAYLOAD_TOO_LARGE + HttpStatus.PAYLOAD_TOO_LARGE, ); } @@ -99,8 +99,8 @@ export class MediaController extends Controller { tb( "query", Type.Object({ - overwrite: Type.Optional(booleanLike) - }) + overwrite: Type.Optional(booleanLike), + }), ), async (c) => { const entity_name = c.req.param("entity"); @@ -124,7 +124,7 @@ export class MediaController extends Controller { const mediaRef = { scope: field_name, reference, - entity_id: entity_id + entity_id: entity_id, }; // check max items @@ -140,7 +140,7 @@ export class MediaController extends Controller { if (!overwrite) { return c.json( { error: `Max items (${max_items}) reached` }, - HttpStatus.BAD_REQUEST + HttpStatus.BAD_REQUEST, ); } @@ -149,7 +149,7 @@ export class MediaController extends Controller { if (count > max_items) { return c.json( { error: `Max items (${max_items}) exceeded already with ${count} items.` }, - HttpStatus.UNPROCESSABLE_ENTITY + HttpStatus.UNPROCESSABLE_ENTITY, ); } @@ -159,9 +159,9 @@ export class MediaController extends Controller { where: mediaRef, sort: { by: "id", - dir: "asc" + dir: "asc", }, - limit: count - max_items + 1 + limit: count - max_items + 1, }); if (deleteRes.data && deleteRes.data.length > 0) { @@ -175,7 +175,7 @@ export class MediaController extends Controller { if (!exists) { return c.json( { error: `Entity "${entity_name}" with ID "${entity_id}" doesn't exist found` }, - HttpStatus.NOT_FOUND + HttpStatus.NOT_FOUND, ); } @@ -186,7 +186,7 @@ export class MediaController extends Controller { if (file.size > maxSize) { return c.json( { error: `Max size (${maxSize} bytes) exceeded` }, - HttpStatus.PAYLOAD_TOO_LARGE + HttpStatus.PAYLOAD_TOO_LARGE, ); } @@ -197,7 +197,7 @@ export class MediaController extends Controller { mutator.__unstable_toggleSystemEntityCreation(false); const result = await mutator.insertOne({ ...this.media.uploadedEventDataToMediaPayload(info), - ...mediaRef + ...mediaRef, } as any); mutator.__unstable_toggleSystemEntityCreation(true); @@ -210,7 +210,7 @@ export class MediaController extends Controller { } return c.json({ ok: true, result: result.data, ...info }, HttpStatus.CREATED); - } + }, ); return hono.all("*", (c) => c.notFound()); diff --git a/app/src/media/index.ts b/app/src/media/index.ts index 71bcc80..d131fa2 100644 --- a/app/src/media/index.ts +++ b/app/src/media/index.ts @@ -8,12 +8,12 @@ export { type StorageAdapter, type FileMeta, type FileListObject, - type StorageConfig + type StorageConfig, } from "./storage/Storage"; import type { StorageAdapter } from "./storage/Storage"; import { type CloudinaryConfig, - StorageCloudinaryAdapter + StorageCloudinaryAdapter, } from "./storage/adapters/StorageCloudinaryAdapter"; import { type S3AdapterConfig, StorageS3Adapter } from "./storage/adapters/StorageS3Adapter"; @@ -30,7 +30,7 @@ export const MediaAdapterRegistry = new Registry<{ schema: TObject; }>((cls: ClassThatImplements) => ({ cls, - schema: cls.prototype.getSchema() as TObject + schema: cls.prototype.getSchema() as TObject, })) .register("s3", StorageS3Adapter) .register("cloudinary", StorageCloudinaryAdapter); @@ -38,10 +38,10 @@ export const MediaAdapterRegistry = new Registry<{ export const Adapters = { s3: { cls: StorageS3Adapter, - schema: StorageS3Adapter.prototype.getSchema() + schema: StorageS3Adapter.prototype.getSchema(), }, cloudinary: { cls: StorageCloudinaryAdapter, - schema: StorageCloudinaryAdapter.prototype.getSchema() - } + schema: StorageCloudinaryAdapter.prototype.getSchema(), + }, } as const; diff --git a/app/src/media/media-schema.ts b/app/src/media/media-schema.ts index 229b108..7716077 100644 --- a/app/src/media/media-schema.ts +++ b/app/src/media/media-schema.ts @@ -3,7 +3,7 @@ import { Adapters } from "media"; import { registries } from "modules/registries"; export const ADAPTERS = { - ...Adapters + ...Adapters, } as const; export const registry = registries.media; @@ -13,13 +13,13 @@ export function buildMediaSchema() { return Type.Object( { type: Const(name), - config: adapter.schema + config: adapter.schema, }, { title: adapter.schema?.title ?? name, description: adapter.schema?.description, - additionalProperties: false - } + additionalProperties: false, + }, ); }); const adapterSchema = Type.Union(Object.values(adapterSchemaObject)); @@ -33,17 +33,17 @@ export function buildMediaSchema() { { body_max_size: Type.Optional( Type.Number({ - description: "Max size of the body in bytes. Leave blank for unlimited." - }) - ) + description: "Max size of the body in bytes. Leave blank for unlimited.", + }), + ), }, - { default: {} } + { default: {} }, ), - adapter: Type.Optional(adapterSchema) + adapter: Type.Optional(adapterSchema), }, { - additionalProperties: false - } + additionalProperties: false, + }, ); } diff --git a/app/src/media/storage/Storage.ts b/app/src/media/storage/Storage.ts index 6226cf9..718d8b1 100644 --- a/app/src/media/storage/Storage.ts +++ b/app/src/media/storage/Storage.ts @@ -49,12 +49,12 @@ export class Storage implements EmitsEvents { constructor( adapter: StorageAdapter, config: Partial = {}, - emgr?: EventManager + emgr?: EventManager, ) { this.#adapter = adapter; this.config = { ...config, - body_max_size: config.body_max_size + body_max_size: config.body_max_size, }; this.emgr = emgr ?? new EventManager(); @@ -78,7 +78,7 @@ export class Storage implements EmitsEvents { async uploadFile( file: FileBody, name: string, - noEmit?: boolean + noEmit?: boolean, ): Promise { const result = await this.#adapter.putObject(name, file); if (typeof result === "undefined") { @@ -89,9 +89,9 @@ export class Storage implements EmitsEvents { name, meta: { size: 0, - type: "application/octet-stream" + type: "application/octet-stream", }, - etag: typeof result === "string" ? result : "" + etag: typeof result === "string" ? result : "", }; if (typeof result === "object") { @@ -115,8 +115,8 @@ export class Storage implements EmitsEvents { ...info, state: { name: info.name, - path: info.name - } + path: info.name, + }, }; if (!noEmit) { const result = await this.emgr.emit(new StorageEvents.FileUploadedEvent(eventData)); diff --git a/app/src/media/storage/adapters/StorageCloudinaryAdapter.ts b/app/src/media/storage/adapters/StorageCloudinaryAdapter.ts index 7f2de8c..43509f7 100644 --- a/app/src/media/storage/adapters/StorageCloudinaryAdapter.ts +++ b/app/src/media/storage/adapters/StorageCloudinaryAdapter.ts @@ -7,9 +7,9 @@ export const cloudinaryAdapterConfig = Type.Object( cloud_name: Type.String(), api_key: Type.String(), api_secret: Type.String(), - upload_preset: Type.Optional(Type.String()) + upload_preset: Type.Optional(Type.String()), }, - { title: "Cloudinary", description: "Cloudinary media storage" } + { title: "Cloudinary", description: "Cloudinary media storage" }, ); export type CloudinaryConfig = Static; @@ -80,7 +80,7 @@ export class StorageCloudinaryAdapter implements StorageAdapter { private getAuthorizationHeader() { const credentials = btoa(`${this.config.api_key}:${this.config.api_secret}`); return { - Authorization: `Basic ${credentials}` + Authorization: `Basic ${credentials}`, }; } @@ -102,12 +102,12 @@ export class StorageCloudinaryAdapter implements StorageAdapter { { method: "POST", headers: { - Accept: "application/json" + Accept: "application/json", // content type must be undefined to use correct boundaries //"Content-Type": "multipart/form-data", }, - body: formData - } + body: formData, + }, ); if (!result.ok) { @@ -121,8 +121,8 @@ export class StorageCloudinaryAdapter implements StorageAdapter { etag: data.etag, meta: { type: this.getMimeType(data), - size: data.bytes - } + size: data.bytes, + }, }; } @@ -133,9 +133,9 @@ export class StorageCloudinaryAdapter implements StorageAdapter { method: "GET", headers: { Accept: "application/json", - ...this.getAuthorizationHeader() - } - } + ...this.getAuthorizationHeader(), + }, + }, ); if (!result.ok) { @@ -146,7 +146,7 @@ export class StorageCloudinaryAdapter implements StorageAdapter { return data.resources.map((item) => ({ key: item.public_id, last_modified: new Date(item.uploaded_at), - size: item.bytes + size: item.bytes, })); } @@ -155,8 +155,8 @@ export class StorageCloudinaryAdapter implements StorageAdapter { return await fetch(url, { method: "GET", headers: { - Range: "bytes=0-1" - } + Range: "bytes=0-1", + }, }); } @@ -172,7 +172,7 @@ export class StorageCloudinaryAdapter implements StorageAdapter { const size = Number(result.headers.get("content-range")?.split("/")[1]); return { type: type as string, - size: size + size: size, }; } @@ -182,7 +182,7 @@ export class StorageCloudinaryAdapter implements StorageAdapter { private guessType(key: string): string | undefined { const extensions = { image: ["jpg", "jpeg", "png", "gif", "webp", "svg"], - video: ["mp4", "webm", "ogg"] + video: ["mp4", "webm", "ogg"], }; const ext = key.split(".").pop(); @@ -199,13 +199,13 @@ export class StorageCloudinaryAdapter implements StorageAdapter { async getObject(key: string, headers: Headers): Promise { const res = await fetch(this.getObjectUrl(key), { method: "GET", - headers: pickHeaders(headers, ["range"]) + headers: pickHeaders(headers, ["range"]), }); return new Response(res.body, { status: res.status, statusText: res.statusText, - headers: res.headers + headers: res.headers, }); } @@ -216,14 +216,14 @@ export class StorageCloudinaryAdapter implements StorageAdapter { await fetch(`https://res.cloudinary.com/${this.config.cloud_name}/${type}/upload/`, { method: "DELETE", - body: formData + body: formData, }); } toJSON(secrets?: boolean) { return { type: "cloudinary", - config: secrets ? this.config : { cloud_name: this.config.cloud_name } + config: secrets ? this.config : { cloud_name: this.config.cloud_name }, }; } } diff --git a/app/src/media/storage/adapters/StorageLocalAdapter/StorageLocalAdapter.ts b/app/src/media/storage/adapters/StorageLocalAdapter/StorageLocalAdapter.ts index 8b2f9ba..9a1a21c 100644 --- a/app/src/media/storage/adapters/StorageLocalAdapter/StorageLocalAdapter.ts +++ b/app/src/media/storage/adapters/StorageLocalAdapter/StorageLocalAdapter.ts @@ -5,15 +5,15 @@ import type { FileListObject, FileMeta, FileUploadPayload, - StorageAdapter + StorageAdapter, } from "../../Storage"; import { guess } from "../../mime-types-tiny"; export const localAdapterConfig = Type.Object( { - path: Type.String({ default: "./" }) + path: Type.String({ default: "./" }), }, - { title: "Local", description: "Local file system storage" } + { title: "Local", description: "Local file system storage" }, ); export type LocalAdapterConfig = Static; @@ -42,9 +42,9 @@ export class StorageLocalAdapter implements StorageAdapter { return { key: file, last_modified: stats.mtime, - size: stats.size + size: stats.size, }; - }) + }), ); return fileStats; } @@ -95,8 +95,8 @@ export class StorageLocalAdapter implements StorageAdapter { status: 200, headers: { "Content-Type": mimeType || "application/octet-stream", - "Content-Length": content.length.toString() - } + "Content-Length": content.length.toString(), + }, }); } catch (error) { // Handle file reading errors @@ -112,14 +112,14 @@ export class StorageLocalAdapter implements StorageAdapter { const stats = await stat(`${this.config.path}/${key}`); return { type: guess(key) || "application/octet-stream", - size: stats.size + size: stats.size, }; } toJSON(secrets?: boolean) { return { type: this.getName(), - config: this.config + config: this.config, }; } } diff --git a/app/src/media/storage/adapters/StorageLocalAdapter/index.ts b/app/src/media/storage/adapters/StorageLocalAdapter/index.ts index 6fc7e70..a3f1804 100644 --- a/app/src/media/storage/adapters/StorageLocalAdapter/index.ts +++ b/app/src/media/storage/adapters/StorageLocalAdapter/index.ts @@ -1,5 +1,5 @@ export { StorageLocalAdapter, type LocalAdapterConfig, - localAdapterConfig + localAdapterConfig, } from "./StorageLocalAdapter"; diff --git a/app/src/media/storage/adapters/StorageS3Adapter.ts b/app/src/media/storage/adapters/StorageS3Adapter.ts index cd051d7..9d2cb50 100644 --- a/app/src/media/storage/adapters/StorageS3Adapter.ts +++ b/app/src/media/storage/adapters/StorageS3Adapter.ts @@ -4,7 +4,7 @@ import type { HeadObjectRequest, ListObjectsV2Output, ListObjectsV2Request, - PutObjectRequest + PutObjectRequest, } from "@aws-sdk/client-s3"; import { AwsClient, isDebug } from "core"; import { type Static, Type, isFile, parse, pickHeaders } from "core/utils"; @@ -20,14 +20,14 @@ export const s3AdapterConfig = Type.Object( description: "URL to S3 compatible endpoint without trailing slash", examples: [ "https://{account_id}.r2.cloudflarestorage.com/{bucket}", - "https://{bucket}.s3.{region}.amazonaws.com" - ] - }) + "https://{bucket}.s3.{region}.amazonaws.com", + ], + }), }, { title: "AWS S3", - description: "AWS S3 or compatible storage" - } + description: "AWS S3 or compatible storage", + }, ); export type S3AdapterConfig = Static; @@ -40,12 +40,12 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { { accessKeyId: config.access_key, secretAccessKey: config.secret_access_key, - retries: isDebug() ? 0 : 10 + retries: isDebug() ? 0 : 10, }, { convertParams: "pascalToKebab", - responseType: "xml" - } + responseType: "xml", + }, ); this.#config = parse(s3AdapterConfig, config); } @@ -78,12 +78,12 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { async listObjects(key: string = ""): Promise { const params: Omit & { ListType: number } = { ListType: 2, - Prefix: key + Prefix: key, }; const url = this.getUrl("", params); const res = await this.fetchJson<{ ListBucketResult: ListObjectsV2Output }>(url, { - method: "GET" + method: "GET", }); // absolutely weird, but if only one object is there, it's an object, not an array @@ -98,11 +98,11 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { acc.push({ key: obj.Key, last_modified: obj.LastModified, - size: obj.Size + size: obj.Size, }); } }, - [] as FileListObject[] + [] as FileListObject[], ); return transformed; @@ -112,12 +112,12 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { key: string, body: FileBody, // @todo: params must be added as headers, skipping for now - params: Omit = {} + params: Omit = {}, ) { const url = this.getUrl(key, {}); const res = await this.fetch(url, { method: "PUT", - body + body, }); if (res.ok) { @@ -130,14 +130,14 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { private async headObject( key: string, - params: Pick = {} + params: Pick = {}, ) { const url = this.getUrl(key, {}); return await this.fetch(url, { method: "HEAD", headers: { - Range: "bytes=0-1" - } + Range: "bytes=0-1", + }, }); } @@ -148,7 +148,7 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { return { type, - size + size, }; } @@ -159,7 +159,7 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { */ async objectExists( key: string, - params: Pick = {} + params: Pick = {}, ) { return (await this.headObject(key)).ok; } @@ -171,14 +171,14 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { const url = this.getUrl(key); const res = await this.fetch(url, { method: "GET", - headers: pickHeaders(headers, ["range"]) + headers: pickHeaders(headers, ["range"]), }); // Response has to be copied, because of middlewares that might set headers return new Response(res.body, { status: res.status, statusText: res.statusText, - headers: res.headers + headers: res.headers, }); } @@ -187,18 +187,18 @@ export class StorageS3Adapter extends AwsClient implements StorageAdapter { */ async deleteObject( key: string, - params: Omit = {} + params: Omit = {}, ): Promise { const url = this.getUrl(key, params); const res = await this.fetch(url, { - method: "DELETE" + method: "DELETE", }); } toJSON(secrets?: boolean) { return { type: this.getName(), - config: secrets ? this.#config : undefined + config: secrets ? this.#config : undefined, }; } } diff --git a/app/src/media/storage/events/index.ts b/app/src/media/storage/events/index.ts index 0b63cd4..e539341 100644 --- a/app/src/media/storage/events/index.ts +++ b/app/src/media/storage/events/index.ts @@ -15,7 +15,7 @@ export class FileUploadedEvent extends Event { return this.clone({ // prepending result, so original is always kept ...data, - ...this.params + ...this.params, }); } } diff --git a/app/src/media/storage/mime-types-tiny.ts b/app/src/media/storage/mime-types-tiny.ts index 6936e43..0718da2 100644 --- a/app/src/media/storage/mime-types-tiny.ts +++ b/app/src/media/storage/mime-types-tiny.ts @@ -4,7 +4,7 @@ export const Q = { image: ["jpeg", "png", "gif", "webp", "bmp", "tiff", "avif", "heic", "heif"], text: ["html", "css", "mdx", "yaml", "vcard", "csv", "vtt"], application: ["zip", "xml", "toml", "json", "json5"], - font: ["woff", "woff2", "ttf", "otf"] + font: ["woff", "woff2", "ttf", "otf"], } as const; // reduced @@ -14,7 +14,7 @@ const c = { t: (w = "plain") => `text/${w}`, a: (w = "octet-stream") => `application/${w}`, i: (w) => `image/${w}`, - v: (w) => `video/${w}` + v: (w) => `video/${w}`, } as const; export const M = new Map([ ["7z", c.z], @@ -52,7 +52,7 @@ export const M = new Map([ ["webmanifest", c.a("manifest+json")], ["xls", c.a("vnd.ms-excel")], ["xlsx", `${c.vnd}.spreadsheetml.sheet`], - ["yml", c.t("yaml")] + ["yml", c.t("yaml")], ]); export function guess(f: string): string { diff --git a/app/src/modules/Module.ts b/app/src/modules/Module.ts index 036eb10..249fe08 100644 --- a/app/src/modules/Module.ts +++ b/app/src/modules/Module.ts @@ -9,7 +9,7 @@ import { type Field, FieldPrototype, make, - type em as prototypeEm + type em as prototypeEm, } from "data"; import { Entity } from "data"; import type { Hono } from "hono"; @@ -33,7 +33,7 @@ export abstract class Module>, - protected _ctx?: ModuleBuildContext + protected _ctx?: ModuleBuildContext, ) { this._schema = new SchemaObject(this.getSchema(), initial, { forceParse: this.useForceParse(), @@ -42,13 +42,13 @@ export abstract class Module = {}, - fetcher?: typeof fetch + fetcher?: typeof fetch, ) { this.fetcher = fetcher ?? fetch; } @@ -42,7 +42,7 @@ export abstract class ModuleApi( _input: TInput, _query?: Record | URLSearchParams, - _init?: RequestInit + _init?: RequestInit, ): FetchPromise> { const method = _init?.method ?? "GET"; const input = Array.isArray(_input) ? _input.join("/") : _input; @@ -104,23 +104,23 @@ export abstract class ModuleApi( _input: TInput, _query?: Record | URLSearchParams, - _init?: RequestInit + _init?: RequestInit, ) { return this.request(_input, _query, { ..._init, - method: "GET" + method: "GET", }); } @@ -128,7 +128,7 @@ export abstract class ModuleApi(_input, undefined, { ..._init, body, - method: "POST" + method: "POST", }); } @@ -136,7 +136,7 @@ export abstract class ModuleApi(_input, undefined, { ..._init, body, - method: "PATCH" + method: "PATCH", }); } @@ -144,14 +144,14 @@ export abstract class ModuleApi(_input, undefined, { ..._init, body, - method: "PUT" + method: "PUT", }); } delete(_input: TInput, _init?: RequestInit) { return this.request(_input, undefined, { ..._init, - method: "DELETE" + method: "DELETE", }); } } @@ -169,7 +169,7 @@ export type ResponseObject( raw: Response, body: Body, - data?: Data + data?: Data, ): ResponseObject { let actualData: any = data ?? body; const _props = ["raw", "body", "ok", "status", "res", "data", "toJSON"]; @@ -205,11 +205,11 @@ export function createResponseProxy( return { configurable: true, enumerable: true, - value: Reflect.get({ raw, body, ok: raw.ok, status: raw.status }, prop) + value: Reflect.get({ raw, body, ok: raw.ok, status: raw.status }, prop), }; } return Reflect.getOwnPropertyDescriptor(target, prop); - } + }, }) as ResponseObject; } @@ -222,7 +222,7 @@ export class FetchPromise> implements Promise { protected options?: { fetcher?: typeof fetch; verbose?: boolean; - } + }, ) {} get verbose() { @@ -237,7 +237,7 @@ export class FetchPromise> implements Promise { if (this.verbose) { console.log("[FetchPromise] Request", { method: this.request.method, - url: this.request.url + url: this.request.url, }); } @@ -246,7 +246,7 @@ export class FetchPromise> implements Promise { console.log("[FetchPromise] Response", { res: res, ok: res.ok, - status: res.status + status: res.status, }); } @@ -272,13 +272,13 @@ export class FetchPromise> implements Promise { // biome-ignore lint/suspicious/noThenProperty: it's a promise :) then( onfulfilled?: ((value: T) => TResult1 | PromiseLike) | null | undefined, - onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined + onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined, ): Promise { return this.execute().then(onfulfilled as any, onrejected); } catch( - onrejected?: ((reason: any) => TResult | PromiseLike) | null | undefined + onrejected?: ((reason: any) => TResult | PromiseLike) | null | undefined, ): Promise { return this.then(undefined, onrejected); } @@ -292,7 +292,7 @@ export class FetchPromise> implements Promise { (reason) => { onfinally?.(); throw reason; - } + }, ); } @@ -310,7 +310,7 @@ export class FetchPromise> implements Promise { const url = new URL(this.request.url); const path = this.path().split("/"); return (options?.search !== false ? [...path, url.searchParams.toString()] : path).filter( - Boolean + Boolean, ); } } diff --git a/app/src/modules/ModuleManager.ts b/app/src/modules/ModuleManager.ts index 14ac697..6a4ac9d 100644 --- a/app/src/modules/ModuleManager.ts +++ b/app/src/modules/ModuleManager.ts @@ -10,7 +10,7 @@ import { mark, objectEach, stripMark, - transformObject + transformObject, } from "core/utils"; import { type Connection, @@ -20,7 +20,7 @@ import { entity, enumm, jsonSchema, - number + number, } from "data"; import { TransformPersistFailedException } from "data/errors"; import { Hono } from "hono"; @@ -42,7 +42,7 @@ export const MODULES = { data: AppData, auth: AppAuth, media: AppMedia, - flows: AppFlows + flows: AppFlows, } as const; // get names of MODULES as an array @@ -71,7 +71,7 @@ export type InitialModuleConfigs = enum Verbosity { silent = 0, error = 1, - log = 2 + log = 2, } export type ModuleManagerOptions = { @@ -79,7 +79,7 @@ export type ModuleManagerOptions = { eventManager?: EventManager; onUpdated?: ( module: Module, - config: ModuleConfigs[Module] + config: ModuleConfigs[Module], ) => Promise; // triggered when no config table existed onFirstBoot?: () => Promise; @@ -111,16 +111,16 @@ const configJsonSchema = Type.Union([ t: StringEnum(["a", "r", "e"]), p: Type.Array(Type.Union([Type.String(), Type.Number()])), o: Type.Optional(Type.Any()), - n: Type.Optional(Type.Any()) - }) - ) + n: Type.Optional(Type.Any()), + }), + ), ]); const __bknd = entity(TABLE_NAME, { version: number().required(), type: enumm({ enum: ["config", "diff", "backup"] }).required(), json: jsonSchema({ schema: configJsonSchema }).required(), created_at: datetime(), - updated_at: datetime() + updated_at: datetime(), }); type ConfigTable2 = Schema; interface T_INTERNAL_EM { @@ -147,7 +147,7 @@ export class ModuleManager { constructor( private readonly connection: Connection, - private options?: Partial + private options?: Partial, ) { this.__em = new EntityManager([__bknd], this.connection); this.modules = {} as Modules; @@ -249,7 +249,7 @@ export class ModuleManager { emgr: this.emgr, guard: this.guard, flags: Module.ctx_flags, - logger: this.logger + logger: this.logger, }; } @@ -263,8 +263,8 @@ export class ModuleManager { const { data: result } = await this.repo().findOne( { type: "config" }, { - sort: { by: "version", dir: "desc" } - } + sort: { by: "version", dir: "desc" }, + }, ); if (!result) { @@ -273,13 +273,13 @@ export class ModuleManager { return result as unknown as ConfigTable; }, - this.verbosity > Verbosity.silent ? [] : ["log", "error", "warn"] + this.verbosity > Verbosity.silent ? [] : ["log", "error", "warn"], ); this.logger .log("took", performance.now() - startTime, "ms", { version: result.version, - id: result.id + id: result.id, }) .clear(); return result; @@ -300,12 +300,12 @@ export class ModuleManager { await this.mutator().insertOne({ version: state.version, type: "backup", - json: configs + json: configs, }); await this.mutator().insertOne({ version: version, type: "config", - json: configs + json: configs, }); } else { this.logger.log("version matches"); @@ -319,7 +319,7 @@ export class ModuleManager { await this.mutator().insertOne({ version, type: "diff", - json: clone(diffs) + json: clone(diffs), }); // store new version @@ -327,12 +327,12 @@ export class ModuleManager { { version, json: configs, - updated_at: new Date() + updated_at: new Date(), } as any, { type: "config", - version - } + version, + }, ); } else { this.logger.log("no diff, not saving"); @@ -347,7 +347,7 @@ export class ModuleManager { version, json: configs, created_at: new Date(), - updated_at: new Date() + updated_at: new Date(), }); } else if (e instanceof TransformPersistFailedException) { console.error("Cannot save invalid config"); @@ -383,7 +383,7 @@ export class ModuleManager { if (state.version !== this.version()) { // @todo: potentially drop provided config and use database version throw new Error( - `Given version (${this.version()}) and fetched version (${state.version}) do not match.` + `Given version (${this.version()}) and fetched version (${state.version}) do not match.`, ); } } catch (e: any) { @@ -400,7 +400,7 @@ export class ModuleManager { } const [_version, _configs] = await migrate(version, configs, { - db: this.db + db: this.db, }); version = _version; configs = _configs; @@ -427,7 +427,7 @@ export class ModuleManager { } catch (e) { console.error(e); throw new Error( - `Failed to set config for module ${key}: ${JSON.stringify(config, null, 2)}` + `Failed to set config for module ${key}: ${JSON.stringify(config, null, 2)}`, ); } }); @@ -493,7 +493,7 @@ export class ModuleManager { modules: [] as ModuleKey[], synced: false, saved: false, - reloaded: false + reloaded: false, }; this.logger.log("buildModules() triggered", options, this._built); @@ -545,7 +545,7 @@ export class ModuleManager { const ctx = { ...this.ctx(), // disable events for initial setup - em: this.ctx().em.fork() + em: this.ctx().em.fork(), }; // perform a sync @@ -557,7 +557,7 @@ export class ModuleManager { } mutateConfigSafe( - name: Module + name: Module, ): Pick, "set" | "patch" | "overwrite" | "remove"> { const module = this.modules[name]; const copy = structuredClone(this.configs()); @@ -602,7 +602,7 @@ export class ModuleManager { throw e; } }; - } + }, }); } @@ -630,7 +630,7 @@ export class ModuleManager { return { version: this.version(), - ...schemas + ...schemas, }; } @@ -646,7 +646,7 @@ export class ModuleManager { return { version: this.version(), - ...modules + ...modules, } as any; } } @@ -654,7 +654,7 @@ export class ModuleManager { export function getDefaultSchema() { const schema = { type: "object", - ...transformObject(MODULES, (module) => module.prototype.getSchema()) + ...transformObject(MODULES, (module) => module.prototype.getSchema()), }; return schema as any; diff --git a/app/src/modules/SystemApi.ts b/app/src/modules/SystemApi.ts index 3241141..219a979 100644 --- a/app/src/modules/SystemApi.ts +++ b/app/src/modules/SystemApi.ts @@ -12,7 +12,7 @@ export type ApiSchemaResponse = { export class SystemApi extends ModuleApi { protected override getDefaultOptions(): Partial { return { - basepath: "/api/system" + basepath: "/api/system", }; } @@ -23,18 +23,18 @@ export class SystemApi extends ModuleApi { readSchema(options?: { config?: boolean; secrets?: boolean }) { return this.get("schema", { config: options?.config ? 1 : 0, - secrets: options?.secrets ? 1 : 0 + secrets: options?.secrets ? 1 : 0, }); } setConfig( module: Module, value: ModuleConfigs[Module], - force?: boolean + force?: boolean, ) { return this.post( ["config", "set", module].join("/") + `?force=${force ? 1 : 0}`, - value + value, ); } diff --git a/app/src/modules/index.ts b/app/src/modules/index.ts index 5411636..84a50cc 100644 --- a/app/src/modules/index.ts +++ b/app/src/modules/index.ts @@ -9,7 +9,7 @@ export { type ModuleConfigs, type ModuleSchemas, MODULE_NAMES, - type ModuleKey + type ModuleKey, } from "./ModuleManager"; export type { ModuleBuildContext } from "./Module"; @@ -17,5 +17,5 @@ export { type PrimaryFieldType, type BaseModuleApiOptions, type ApiResponse, - ModuleApi + ModuleApi, } from "./ModuleApi"; diff --git a/app/src/modules/migrations.ts b/app/src/modules/migrations.ts index b85f01a..b955476 100644 --- a/app/src/modules/migrations.ts +++ b/app/src/modules/migrations.ts @@ -17,18 +17,18 @@ export const migrations: Migration[] = [ { version: 1, //schema: true, - up: async (config) => config + up: async (config) => config, }, { version: 2, up: async (config, { db }) => { return config; - } + }, }, { version: 3, //schema: true, - up: async (config) => config + up: async (config) => config, }, { version: 4, @@ -37,10 +37,10 @@ export const migrations: Migration[] = [ ...config, auth: { ...config.auth, - basepath: "/api/auth2" - } + basepath: "/api/auth2", + }, }; - } + }, }, { version: 5, @@ -49,13 +49,13 @@ export const migrations: Migration[] = [ const cors = config.server.cors?.allow_methods ?? []; set(config.server, "cors.allow_methods", [...new Set([...cors, "PATCH"])]); return config; - } + }, }, { version: 6, up: async (config, { db }) => { return config; - } + }, }, { version: 7, @@ -67,11 +67,11 @@ export const migrations: Migration[] = [ ...config, auth: { ...config.auth, - jwt - } + jwt, + }, }; - } - } + }, + }, /*{ version: 8, up: async (config, { db }) => { @@ -88,7 +88,7 @@ export async function migrateTo( current: number, to: number, config: GenericConfigObject, - ctx: MigrationContext + ctx: MigrationContext, ): Promise<[number, GenericConfigObject]> { //console.log("migrating from", current, "to", CURRENT_VERSION, config); const todo = migrations.filter((m) => m.version > current && m.version <= to); @@ -115,7 +115,7 @@ export async function migrateTo( export async function migrate( current: number, config: GenericConfigObject, - ctx: MigrationContext + ctx: MigrationContext, ): Promise<[number, GenericConfigObject]> { return migrateTo(current, CURRENT_VERSION, config, ctx); } diff --git a/app/src/modules/registries.ts b/app/src/modules/registries.ts index 9513794..fdd29aa 100644 --- a/app/src/modules/registries.ts +++ b/app/src/modules/registries.ts @@ -1,7 +1,7 @@ import { MediaAdapterRegistry } from "media"; const registries = { - media: MediaAdapterRegistry + media: MediaAdapterRegistry, } as const; export { registries }; diff --git a/app/src/modules/server/AdminController.tsx b/app/src/modules/server/AdminController.tsx index 7d48bb0..d83119a 100644 --- a/app/src/modules/server/AdminController.tsx +++ b/app/src/modules/server/AdminController.tsx @@ -23,7 +23,7 @@ export type AdminControllerOptions = { export class AdminController extends Controller { constructor( private readonly app: App, - private _options: AdminControllerOptions = {} + private _options: AdminControllerOptions = {}, ) { super(); } @@ -36,7 +36,7 @@ export class AdminController extends Controller { return { ...this._options, basepath: this._options.basepath ?? "/", - assets_path: this._options.assets_path ?? config.server.assets_path + assets_path: this._options.assets_path ?? config.server.assets_path, }; } @@ -53,7 +53,7 @@ export class AdminController extends Controller { const hono = this.create().use( authMiddleware({ //skip: [/favicon\.ico$/] - }) + }), ); const auth = this.app.module.auth; @@ -66,14 +66,14 @@ export class AdminController extends Controller { success: configs.auth.cookie.pathSuccess ?? "/", loggedOut: configs.auth.cookie.pathLoggedOut ?? "/", login: "/auth/login", - logout: "/auth/logout" + logout: "/auth/logout", }; hono.use("*", async (c, next) => { const obj = { user: c.get("auth")?.user, logout_route: this.withBasePath(authRoutes.logout), - color_scheme: configs.server.admin.color_scheme + color_scheme: configs.server.admin.color_scheme, }; const html = await this.getHtml(obj); if (!html) { @@ -97,11 +97,11 @@ export class AdminController extends Controller { console.log("redirecting to success"); return c.redirect(authRoutes.success); } - } + }, }), async (c) => { return c.html(c.get("html")!); - } + }, ); hono.get(authRoutes.logout, async (c) => { @@ -119,16 +119,16 @@ export class AdminController extends Controller { console.log("redirecting"); return c.redirect(authRoutes.login); - } + }, }), permission(SystemPermissions.schemaRead, { onDenied: async (c) => { addFlashMessage(c, "You not allowed to read the schema", "warning"); - } + }, }), async (c) => { return c.html(c.get("html")!); - } + }, ); return hono; @@ -141,12 +141,12 @@ export class AdminController extends Controller { if (this.options.html.includes(htmlBkndContextReplace)) { return this.options.html.replace( htmlBkndContextReplace, - "" + "", ); } console.warn( - `Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context` + `Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`, ); return this.options.html as string; } @@ -160,13 +160,13 @@ export class AdminController extends Controller { const assets = { js: "main.js", - css: "styles.css" + css: "styles.css", }; if (isProd) { // @ts-ignore const manifest = await import("bknd/dist/manifest.json", { - assert: { type: "json" } + assert: { type: "json" }, }); // @todo: load all marked as entry (incl. css) assets.js = manifest.default["src/ui/main.tsx"].file; @@ -217,7 +217,7 @@ export class AdminController extends Controller { RefreshRuntime.injectIntoGlobalHook(window) window.$RefreshReg$ = () => {} window.$RefreshSig$ = () => (type) => type - window.__vite_plugin_react_preamble_installed__ = true` + window.__vite_plugin_react_preamble_installed__ = true`, }} />