@sqrzro/server 4.0.0-alpha.32 → 4.0.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import { SQL } from 'drizzle-orm';
2
2
  import { PgColumn } from 'drizzle-orm/pg-core';
3
3
  import { P as Paginated } from '../interfaces-DTUqy5Oj.js';
4
+ import * as drizzle_orm_node_postgres from 'drizzle-orm/node-postgres';
5
+ import { Pool } from 'pg';
4
6
 
5
7
  type QueryConditions = (SQL | undefined)[];
6
8
  type UnwrapColumnType<T> = T extends PgColumn<infer C, any, any> ? C['data'] : never;
@@ -63,9 +65,16 @@ declare function createRepository<TConfig extends RepositoryConfig<TIndexes, any
63
65
  getFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<UnwrapModel<TConfig> | null>;
64
66
  getIDFromParams: (params?: Promise<Record<string, string>> | Record<string, string> | null) => Promise<UnwrapID<TConfig> | null>;
65
67
  getPaginated: (fnConfig?: PaginatedFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>) => Promise<Paginated<UnwrapModel<TConfig>>>;
66
- guardID: (id: (string | null | undefined)[] | string | null | undefined) => UnwrapID<TConfig> | UnwrapID<TConfig>[] | null;
68
+ guardID: {
69
+ (id: (string | null | undefined)[]): UnwrapID<TConfig>[];
70
+ (id: string | null | undefined): UnwrapID<TConfig> | null;
71
+ };
67
72
  undelete: (id: UnwrapID<TConfig>) => Promise<void>;
68
73
  update: (data: UnwrapUpdate<TConfig>["data"]) => Promise<UnwrapUpdate<TConfig>["model"]>;
69
74
  };
70
75
 
71
- export { type PaginatedFunctionConfig, type QueryConditions, type QueryConfig, type RepositoryConfig, type SelectFunctionConfig, type UnwrapColumnType, type UnwrapFilters, type UnwrapGuards, type UnwrapID, type UnwrapInsert, type UnwrapModel, type UnwrapUpdate, createRepository };
76
+ declare const db: drizzle_orm_node_postgres.NodePgDatabase<Record<string, never>> & {
77
+ $client: Pool;
78
+ };
79
+
80
+ export { type PaginatedFunctionConfig, type QueryConditions, type QueryConfig, type RepositoryConfig, type SelectFunctionConfig, type UnwrapColumnType, type UnwrapFilters, type UnwrapGuards, type UnwrapID, type UnwrapInsert, type UnwrapModel, type UnwrapUpdate, createRepository, db };
@@ -1,2 +1,2 @@
1
- import {a,b,c}from'../chunk-BA3BC4CD.js';import {eq}from'drizzle-orm';import {notFound}from'next/navigation';import {cache}from'react';async function B(r,d,u){let l=await c(r,d,u);return b(l,d)}var P=B;function o(r,d){for(let u of d)if(r[u]===void 0||r[u]===null)throw new Error(`Repository config is missing required field: "${String(u)}"`);return r}function G(r){function d(n){let{prefix:e}=o(r,["prefix"]);return Array.isArray(n)?a(n,e):a(n,e)}function u(n){let{prefix:e}=o(r,["prefix"]);return b(n,e)}async function l(n){let{paramKey:e,prefix:t}=o(r,["paramKey","prefix"]);return c(e,t,n)}async function w(n){let{paramKey:e,prefix:t}=o(r,["paramKey","prefix"]);try{return await P(e,t,n)}catch{notFound();}}async function D(n){let{makeQuery:e}=o(r,["makeQuery"]),t=[],i=await r.applyFilters?.(n?.filters??null);t.push(...i||[]);let a=await r.applyGuards?.(n?.guards??null);return t.push(...a||[]),e(t,{limit:n?.limit??-1,offset:n?.offset??0})}async function F(n){let{makeCountQuery:e,makeQuery:t}=o(r,["makeCountQuery","makeQuery"]),i=[],a=await r.applyFilters?.(n?.filters??null);i.push(...a||[]);let g=await r.applyGuards?.(n?.guards??null);i.push(...g||[]);let f=await e(i);return {data:await t(i,{limit:n?.limit??10,offset:((n?.page??1)-1)*(n?.limit??10)}),meta:{limit:n?.limit??10,page:n?.page??1,total:f}}}async function c$1(n,e,t){let{makeQuery:i}=o(r,["makeQuery"]);if(!r.indexes?.[n])throw new Error(`'Could not \`getByIndex\`. Index ${String(n)} is not defined in the repository configuration.`);let a=[],g=await r.applyFilters?.(t?.filters??null);a.push(...g||[]);let f=await r.applyGuards?.(t?.guards??null);a.push(...f||[]),a.push(eq(r.indexes[n],e));let[U]=await i(a,{limit:1,offset:0});return U??null}async function T(...n){let e=await c$1(...n);return e||notFound()}async function C(n){return c$1("id",n)}async function I(n){return T("id",n)}async function h(n){let e=await l(n);return e?C(e):null}async function k(n){let e=await w(n);return I(e)}async function R(n){let{makeInsertMutation:e}=o(r,["makeInsertMutation"]);return e(n)}async function K(n){let{makeUpdateMutation:e}=o(r,["makeUpdateMutation"]);return e(n)}async function M(n){let{makeDeleteMutation:e}=o(r,["makeDeleteMutation"]);return e(n)}async function Q(n){let{makeUndeleteMutation:e}=o(r,["makeUndeleteMutation"]);return e(n)}return {create:R,delete:M,ensureByID:cache(I),ensureByIndex:cache(T),ensureFromParams:cache(k),ensureID:u,ensureIDFromParams:w,getAll:cache(D),getByID:cache(C),getByIndex:cache(c$1),getFromParams:cache(h),getIDFromParams:l,getPaginated:cache(F),guardID:d,undelete:Q,update:K}}var S=G;export{S as createRepository};//# sourceMappingURL=index.js.map
1
+ import {a,b,c}from'../chunk-BA3BC4CD.js';import {eq}from'drizzle-orm';import {notFound}from'next/navigation';import {cache}from'react';import {drizzle}from'drizzle-orm/node-postgres';import {Pool}from'pg';async function B(r,d,u){let l=await c(r,d,u);return b(l,d)}var P=B;function o(r,d){for(let u of d)if(r[u]===void 0||r[u]===null)throw new Error(`Repository config is missing required field: "${String(u)}"`);return r}function A(r){function d(n){let{prefix:e}=o(r,["prefix"]);return Array.isArray(n)?a(n,e):a(n,e)}function u(n){let{prefix:e}=o(r,["prefix"]);return b(n,e)}async function l(n){let{paramKey:e,prefix:t}=o(r,["paramKey","prefix"]);return c(e,t,n)}async function w(n){let{paramKey:e,prefix:t}=o(r,["paramKey","prefix"]);try{return await P(e,t,n)}catch{notFound();}}async function x(n){let{makeQuery:e}=o(r,["makeQuery"]),t=[],i=await r.applyFilters?.(n?.filters??null);t.push(...i||[]);let a=await r.applyGuards?.(n?.guards??null);return t.push(...a||[]),e(t,{limit:n?.limit??-1,offset:n?.offset??0})}async function F(n){let{makeCountQuery:e,makeQuery:t}=o(r,["makeCountQuery","makeQuery"]),i=[],a=await r.applyFilters?.(n?.filters??null);i.push(...a||[]);let f=await r.applyGuards?.(n?.guards??null);i.push(...f||[]);let g=await e(i);return {data:await t(i,{limit:n?.limit??10,offset:((n?.page??1)-1)*(n?.limit??10)}),meta:{limit:n?.limit??10,page:n?.page??1,total:g}}}async function c$1(n,e,t){let{makeQuery:i}=o(r,["makeQuery"]);if(!r.indexes?.[n])throw new Error(`'Could not \`getByIndex\`. Index ${String(n)} is not defined in the repository configuration.`);let a=[],f=await r.applyFilters?.(t?.filters??null);a.push(...f||[]);let g=await r.applyGuards?.(t?.guards??null);a.push(...g||[]),a.push(eq(r.indexes[n],e));let[U]=await i(a,{limit:1,offset:0});return U??null}async function T(...n){let e=await c$1(...n);return e||notFound()}async function C(n){return c$1("id",n)}async function I(n){return T("id",n)}async function h(n){let e=await l(n);return e?C(e):null}async function k(n){let e=await w(n);return I(e)}async function R(n){let{makeInsertMutation:e}=o(r,["makeInsertMutation"]);return e(n)}async function K(n){let{makeUpdateMutation:e}=o(r,["makeUpdateMutation"]);return e(n)}async function M(n){let{makeDeleteMutation:e}=o(r,["makeDeleteMutation"]);return e(n)}async function Q(n){let{makeUndeleteMutation:e}=o(r,["makeUndeleteMutation"]);return e(n)}return {create:R,delete:M,ensureByID:cache(I),ensureByIndex:cache(T),ensureFromParams:cache(k),ensureID:u,ensureIDFromParams:w,getAll:cache(x),getByID:cache(C),getByIndex:cache(c$1),getFromParams:cache(h),getIDFromParams:l,getPaginated:cache(F),guardID:d,undelete:Q,update:K}}var G=A;var N=new Pool({connectionString:process.env.DATABASE_URL}),v=drizzle(N),E=v;export{G as createRepository,E as db};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utility/ensure-id-from-params.ts","../../src/database/create-repository.ts"],"names":["ensureIDFromParams","key","prefix","params","id","get_id_from_params_default","ensure_id_default","ensure_id_from_params_default","ensureConfig","config","keys","createRepository","guardID","guard_id_default","ensureID","getIDFromParams","paramKey","notFound","uncached_getAll","fnConfig","makeQuery","conditions","filters","guards","uncached_getPaginated","makeCountQuery","total","uncached_getByIndex","value","eq","result","uncached_ensureByIndex","args","uncached_getByID","uncached_ensureByID","uncached_getFromParams","uncached_ensureFromParams","create","data","makeInsertMutation","update","makeUpdateMutation","$delete","makeDeleteMutation","undelete","makeUndeleteMutation","cache","create_repository_default"],"mappings":"uIAGA,eAAeA,CAAAA,CACXC,CAAAA,CACAC,EACAC,CAAAA,CACU,CACV,IAAMC,CAAAA,CAAK,MAAMC,CAAAA,CAAmBJ,CAAAA,CAAKC,CAAAA,CAAQC,CAAM,EACvD,OAAOG,CAAAA,CAAYF,CAAAA,CAAIF,CAAM,CACjC,CAEA,IAAOK,CAAAA,CAAQP,CAAAA,CCaf,SAASQ,CAAAA,CACLC,CAAAA,CACAC,CAAAA,CAC2C,CAC3C,QAAWT,CAAAA,IAAOS,CAAAA,CACd,GAAID,CAAAA,CAAOR,CAAG,CAAA,GAAM,MAAA,EAAaQ,CAAAA,CAAOR,CAAG,IAAM,IAAA,CAC7C,MAAM,IAAI,KAAA,CAAM,iDAAiD,MAAA,CAAOA,CAAG,CAAC,CAAA,CAAA,CAAG,EAGvF,OAAOQ,CACX,CAEA,SAASE,EAGPF,CAAAA,CAAiB,CACf,SAASG,CAAAA,CACLR,EAC8C,CAC9C,GAAM,CAAE,MAAA,CAAAF,CAAO,CAAA,CAAIM,CAAAA,CAAaC,CAAAA,CAAQ,CAAC,QAAQ,CAAC,CAAA,CAElD,OAAI,MAAM,OAAA,CAAQL,CAAE,CAAA,CACTS,CAAAA,CAA6BT,EAAIF,CAAM,CAAA,CAG3CW,CAAAA,CAA6BT,CAAAA,CAAIF,CAAM,CAClD,CAEA,SAASY,CAAAA,CAASV,EAAkD,CAChE,GAAM,CAAE,MAAA,CAAAF,CAAO,CAAA,CAAIM,CAAAA,CAAaC,CAAAA,CAAQ,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AAgC,EACA,MAAA,CAAAJ,CACJ,CACJ,KAEOO,CAAAA,CAAQpC","file":"index.js","sourcesContent":["import ensureID from './ensure-id';\nimport getIDFromParams from './get-id-from-params';\n\nasync function ensureIDFromParams<T extends string>(\n key: string,\n prefix: string,\n params?: Promise<Record<string, string>> | Record<string, string> | null\n): Promise<T> {\n const id = await getIDFromParams<T>(key, prefix, params);\n return ensureID<T>(id, prefix);\n}\n\nexport default ensureIDFromParams;\n","import { eq } from 'drizzle-orm';\nimport { PgColumn } from 'drizzle-orm/pg-core';\nimport { notFound } from 'next/navigation';\nimport { cache } from 'react';\n\nimport ensureIDFn from '../utility/ensure-id';\nimport ensureIDFromParamsFn from '../utility/ensure-id-from-params';\nimport getIDFromParamsFn from '../utility/get-id-from-params';\nimport guardIDFn from '../utility/guard-id';\nimport { Paginated } from '../utility/interfaces';\n\nimport {\n QueryConditions,\n PaginatedFunctionConfig,\n RepositoryConfig,\n SelectFunctionConfig,\n UnwrapColumnType,\n UnwrapFilters,\n UnwrapGuards,\n UnwrapID,\n UnwrapInsert,\n UnwrapModel,\n UnwrapUpdate,\n} from './interfaces';\n\nfunction ensureConfig<TConfig extends RepositoryConfig, TKeys extends keyof TConfig>(\n config: TConfig,\n keys: TKeys[]\n): { [K in TKeys]-?: NonNullable<TConfig[K]> } {\n for (const key of keys) {\n if (config[key] === undefined || config[key] === null) {\n throw new Error(`Repository config is missing required field: \"${String(key)}\"`);\n }\n }\n return config as unknown as { [K in TKeys]-?: NonNullable<TConfig[K]> };\n}\n\nfunction createRepository<\n TConfig extends RepositoryConfig<TIndexes, any, any>,\n TIndexes extends Record<string, PgColumn<any>> = Record<string, PgColumn<any>>,\n>(config: TConfig) {\n function guardID(\n id: (string | null | undefined)[] | string | null | undefined\n ): UnwrapID<TConfig> | UnwrapID<TConfig>[] | null {\n const { prefix } = ensureConfig(config, ['prefix']);\n\n if (Array.isArray(id)) {\n return guardIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n return guardIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n function ensureID(id: string | null | undefined): UnwrapID<TConfig> {\n const { prefix } = ensureConfig(config, ['prefix']);\n return ensureIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n async function getIDFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapID<TConfig> | null> {\n const { paramKey, prefix } = ensureConfig(config, ['paramKey', 'prefix']);\n return getIDFromParamsFn<UnwrapID<TConfig>>(paramKey, prefix, params);\n }\n\n async function ensureIDFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapID<TConfig>> {\n const { paramKey, prefix } = ensureConfig(config, ['paramKey', 'prefix']);\n\n try {\n const id = await ensureIDFromParamsFn<UnwrapID<TConfig>>(paramKey, prefix, params);\n return id;\n } catch (err) {\n notFound();\n }\n }\n\n async function uncached_getAll(\n fnConfig?: SelectFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<UnwrapModel<TConfig>[]> {\n const { makeQuery } = ensureConfig(config, ['makeQuery']);\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n return makeQuery(conditions, {\n limit: fnConfig?.limit ?? -1,\n offset: fnConfig?.offset ?? 0,\n });\n }\n\n async function uncached_getPaginated(\n fnConfig?: PaginatedFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<Paginated<UnwrapModel<TConfig>>> {\n const { makeCountQuery, makeQuery } = ensureConfig(config, ['makeCountQuery', 'makeQuery']);\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n const total = await makeCountQuery(conditions);\n\n const data = await makeQuery(conditions, {\n limit: fnConfig?.limit ?? 10,\n offset: ((fnConfig?.page ?? 1) - 1) * (fnConfig?.limit ?? 10),\n });\n\n return {\n data,\n meta: { limit: fnConfig?.limit ?? 10, page: fnConfig?.page ?? 1, total },\n };\n }\n\n async function uncached_getByIndex<K extends keyof TIndexes>(\n key: K,\n value: UnwrapColumnType<TIndexes[K]>,\n fnConfig?: SelectFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<UnwrapModel<TConfig> | null> {\n const { makeQuery } = ensureConfig(config, ['makeQuery']);\n\n if (!config.indexes?.[key]) {\n throw new Error(\n `'Could not \\`getByIndex\\`. Index ${String(key)} is not defined in the repository configuration.`\n );\n }\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n conditions.push(eq(config.indexes[key], value));\n\n const [result] = await makeQuery(conditions, { limit: 1, offset: 0 });\n\n return result ?? null;\n }\n\n async function uncached_ensureByIndex<K extends keyof TIndexes>(\n ...args: Parameters<typeof uncached_getByIndex<K>>\n ): Promise<UnwrapModel<TConfig>> {\n const result = await uncached_getByIndex(...args);\n\n if (!result) {\n return notFound();\n }\n\n return result;\n }\n\n async function uncached_getByID(id: UnwrapID<TConfig>): Promise<UnwrapModel<TConfig> | null> {\n return uncached_getByIndex('id', id);\n }\n\n async function uncached_ensureByID(id: UnwrapID<TConfig>): Promise<UnwrapModel<TConfig>> {\n return uncached_ensureByIndex('id', id);\n }\n\n async function uncached_getFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapModel<TConfig> | null> {\n const id = await getIDFromParams(params);\n return id ? uncached_getByID(id) : null;\n }\n\n async function uncached_ensureFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapModel<TConfig>> {\n const id = await ensureIDFromParams(params);\n return uncached_ensureByID(id);\n }\n\n async function create(\n data: UnwrapInsert<TConfig>['data']\n ): Promise<UnwrapInsert<TConfig>['model']> {\n const { makeInsertMutation } = ensureConfig(config, ['makeInsertMutation']);\n return makeInsertMutation(data);\n }\n\n async function update(\n data: UnwrapUpdate<TConfig>['data']\n ): Promise<UnwrapUpdate<TConfig>['model']> {\n const { makeUpdateMutation } = ensureConfig(config, ['makeUpdateMutation']);\n return makeUpdateMutation(data);\n }\n\n async function $delete(id: UnwrapID<TConfig>): Promise<void> {\n const { makeDeleteMutation } = ensureConfig(config, ['makeDeleteMutation']);\n return makeDeleteMutation(id);\n }\n\n async function undelete(id: UnwrapID<TConfig>): Promise<void> {\n const { makeUndeleteMutation } = ensureConfig(config, ['makeUndeleteMutation']);\n return makeUndeleteMutation(id);\n }\n\n return {\n create,\n delete: $delete,\n ensureByID: cache(uncached_ensureByID),\n ensureByIndex: cache(uncached_ensureByIndex),\n ensureFromParams: cache(uncached_ensureFromParams),\n ensureID,\n ensureIDFromParams,\n getAll: cache(uncached_getAll),\n getByID: cache(uncached_getByID),\n getByIndex: cache(uncached_getByIndex),\n getFromParams: cache(uncached_getFromParams),\n getIDFromParams,\n getPaginated: cache(uncached_getPaginated),\n guardID,\n undelete,\n update,\n };\n}\n\nexport default createRepository;\n"]}
1
+ {"version":3,"sources":["../../src/utility/ensure-id-from-params.ts","../../src/database/create-repository.ts","../../src/database/db.ts"],"names":["ensureIDFromParams","key","prefix","params","id","get_id_from_params_default","ensure_id_default","ensure_id_from_params_default","ensureConfig","config","keys","createRepository","guardID","guard_id_default","ensureID","getIDFromParams","paramKey","notFound","uncached_getAll","fnConfig","makeQuery","conditions","filters","guards","uncached_getPaginated","makeCountQuery","total","uncached_getByIndex","value","eq","result","uncached_ensureByIndex","args","uncached_getByID","uncached_ensureByID","uncached_getFromParams","uncached_ensureFromParams","create","data","makeInsertMutation","update","makeUpdateMutation","$delete","makeDeleteMutation","undelete","makeUndeleteMutation","cache","create_repository_default","pool","Pool","db","drizz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,CAAI,CAClC,CAEA,eAAeI,CAAAA,CAAQtC,CAAAA,CAAsC,CACzD,GAAM,CAAE,kBAAA,CAAAuC,CAAmB,EAAInC,CAAAA,CAAaC,CAAAA,CAAQ,CAAC,oBAAoB,CAAC,CAAA,CAC1E,OAAOkC,CAAAA,CAAmBvC,CAAE,CAChC,CAEA,eAAewC,CAAAA,CAASxC,CAAAA,CAAsC,CAC1D,GAAM,CAAE,oBAAA,CAAAyC,CAAqB,EAAIrC,CAAAA,CAAaC,CAAAA,CAAQ,CAAC,sBAAsB,CAAC,EAC9E,OAAOoC,CAAAA,CAAqBzC,CAAE,CAClC,CAEA,OAAO,CACH,MAAA,CAAAiC,CAAAA,CACA,OAAQK,CAAAA,CACR,UAAA,CAAYI,KAAAA,CAAMZ,CAAmB,EACrC,aAAA,CAAeY,KAAAA,CAAMf,CAAsB,CAAA,CAC3C,iBAAkBe,KAAAA,CAAMV,CAAyB,CAAA,CACjD,QAAA,CAAAtB,EACA,kBAAA,CAAAd,CAAAA,CACA,MAAA,CAAQ8C,KAAAA,CAAM5B,CAAe,CAAA,CAC7B,OAAA,CAAS4B,KAAAA,CAAMb,CAAgB,EAC/B,UAAA,CAAYa,KAAAA,CAAMnB,GAAmB,CAAA,CACrC,aAAA,CAAemB,MAAMX,CAAsB,CAAA,CAC3C,eAAA,CAAApB,CAAAA,CACA,aAAc+B,KAAAA,CAAMtB,CAAqB,CAAA,CACzC,OAAA,CAAAZ,EACA,QAAA,CAAAgC,CAAAA,CACA,MAAA,CAAAJ,CACJ,CACJ,CAEA,IAAOO,EAAQpC,ECrOf,IAAMqC,CAAAA,CAAO,IAAIC,KAAK,CAClB,gBAAA,CAAkB,OAAA,CAAQ,GAAA,CAAI,YAClC,CAAC,CAAA,CAEKC,EAAKC,OAAAA,CAAQH,CAAI,EAEhBI,CAAAA,CAAQF","file":"index.js","sourcesContent":["import ensureID from './ensure-id';\nimport getIDFromParams from './get-id-from-params';\n\nasync function ensureIDFromParams<T extends string>(\n key: string,\n prefix: string,\n params?: Promise<Record<string, string>> | Record<string, string> | null\n): Promise<T> {\n const id = await getIDFromParams<T>(key, prefix, params);\n return ensureID<T>(id, prefix);\n}\n\nexport default ensureIDFromParams;\n","import { eq } from 'drizzle-orm';\nimport { PgColumn } from 'drizzle-orm/pg-core';\nimport { notFound } from 'next/navigation';\nimport { cache } from 'react';\n\nimport ensureIDFn from '../utility/ensure-id';\nimport ensureIDFromParamsFn from '../utility/ensure-id-from-params';\nimport getIDFromParamsFn from '../utility/get-id-from-params';\nimport guardIDFn from '../utility/guard-id';\nimport { Paginated } from '../utility/interfaces';\n\nimport {\n QueryConditions,\n PaginatedFunctionConfig,\n RepositoryConfig,\n SelectFunctionConfig,\n UnwrapColumnType,\n UnwrapFilters,\n UnwrapGuards,\n UnwrapID,\n UnwrapInsert,\n UnwrapModel,\n UnwrapUpdate,\n} from './interfaces';\n\nfunction ensureConfig<TConfig extends RepositoryConfig, TKeys extends keyof TConfig>(\n config: TConfig,\n keys: TKeys[]\n): { [K in TKeys]-?: NonNullable<TConfig[K]> } {\n for (const key of keys) {\n if (config[key] === undefined || config[key] === null) {\n throw new Error(`Repository config is missing required field: \"${String(key)}\"`);\n }\n }\n return config as unknown as { [K in TKeys]-?: NonNullable<TConfig[K]> };\n}\n\nfunction createRepository<\n TConfig extends RepositoryConfig<TIndexes, any, any>,\n TIndexes extends Record<string, PgColumn<any>> = Record<string, PgColumn<any>>,\n>(config: TConfig) {\n function guardID(id: (string | null | undefined)[]): UnwrapID<TConfig>[];\n function guardID(id: string | null | undefined): UnwrapID<TConfig> | null;\n\n function guardID(\n id: (string | null | undefined)[] | string | null | undefined\n ): UnwrapID<TConfig> | UnwrapID<TConfig>[] | null {\n const { prefix } = ensureConfig(config, ['prefix']);\n\n if (Array.isArray(id)) {\n return guardIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n return guardIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n function ensureID(id: string | null | undefined): UnwrapID<TConfig> {\n const { prefix } = ensureConfig(config, ['prefix']);\n return ensureIDFn<UnwrapID<TConfig>>(id, prefix);\n }\n\n async function getIDFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapID<TConfig> | null> {\n const { paramKey, prefix } = ensureConfig(config, ['paramKey', 'prefix']);\n return getIDFromParamsFn<UnwrapID<TConfig>>(paramKey, prefix, params);\n }\n\n async function ensureIDFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapID<TConfig>> {\n const { paramKey, prefix } = ensureConfig(config, ['paramKey', 'prefix']);\n\n try {\n const id = await ensureIDFromParamsFn<UnwrapID<TConfig>>(paramKey, prefix, params);\n return id;\n } catch (err) {\n notFound();\n }\n }\n\n async function uncached_getAll(\n fnConfig?: SelectFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<UnwrapModel<TConfig>[]> {\n const { makeQuery } = ensureConfig(config, ['makeQuery']);\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n return makeQuery(conditions, {\n limit: fnConfig?.limit ?? -1,\n offset: fnConfig?.offset ?? 0,\n });\n }\n\n async function uncached_getPaginated(\n fnConfig?: PaginatedFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<Paginated<UnwrapModel<TConfig>>> {\n const { makeCountQuery, makeQuery } = ensureConfig(config, ['makeCountQuery', 'makeQuery']);\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n const total = await makeCountQuery(conditions);\n\n const data = await makeQuery(conditions, {\n limit: fnConfig?.limit ?? 10,\n offset: ((fnConfig?.page ?? 1) - 1) * (fnConfig?.limit ?? 10),\n });\n\n return {\n data,\n meta: { limit: fnConfig?.limit ?? 10, page: fnConfig?.page ?? 1, total },\n };\n }\n\n async function uncached_getByIndex<K extends keyof TIndexes>(\n key: K,\n value: UnwrapColumnType<TIndexes[K]>,\n fnConfig?: SelectFunctionConfig<UnwrapFilters<TConfig>, UnwrapGuards<TConfig>>\n ): Promise<UnwrapModel<TConfig> | null> {\n const { makeQuery } = ensureConfig(config, ['makeQuery']);\n\n if (!config.indexes?.[key]) {\n throw new Error(\n `'Could not \\`getByIndex\\`. Index ${String(key)} is not defined in the repository configuration.`\n );\n }\n\n const conditions: QueryConditions = [];\n\n const filters = await config.applyFilters?.(fnConfig?.filters ?? null);\n conditions.push(...(filters || []));\n\n const guards = await config.applyGuards?.(fnConfig?.guards ?? null);\n conditions.push(...(guards || []));\n\n conditions.push(eq(config.indexes[key], value));\n\n const [result] = await makeQuery(conditions, { limit: 1, offset: 0 });\n\n return result ?? null;\n }\n\n async function uncached_ensureByIndex<K extends keyof TIndexes>(\n ...args: Parameters<typeof uncached_getByIndex<K>>\n ): Promise<UnwrapModel<TConfig>> {\n const result = await uncached_getByIndex(...args);\n\n if (!result) {\n return notFound();\n }\n\n return result;\n }\n\n async function uncached_getByID(id: UnwrapID<TConfig>): Promise<UnwrapModel<TConfig> | null> {\n return uncached_getByIndex('id', id);\n }\n\n async function uncached_ensureByID(id: UnwrapID<TConfig>): Promise<UnwrapModel<TConfig>> {\n return uncached_ensureByIndex('id', id);\n }\n\n async function uncached_getFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapModel<TConfig> | null> {\n const id = await getIDFromParams(params);\n return id ? uncached_getByID(id) : null;\n }\n\n async function uncached_ensureFromParams(\n params?: Promise<Record<string, string>> | Record<string, string> | null\n ): Promise<UnwrapModel<TConfig>> {\n const id = await ensureIDFromParams(params);\n return uncached_ensureByID(id);\n }\n\n async function create(\n data: UnwrapInsert<TConfig>['data']\n ): Promise<UnwrapInsert<TConfig>['model']> {\n const { makeInsertMutation } = ensureConfig(config, ['makeInsertMutation']);\n return makeInsertMutation(data);\n }\n\n async function update(\n data: UnwrapUpdate<TConfig>['data']\n ): Promise<UnwrapUpdate<TConfig>['model']> {\n const { makeUpdateMutation } = ensureConfig(config, ['makeUpdateMutation']);\n return makeUpdateMutation(data);\n }\n\n async function $delete(id: UnwrapID<TConfig>): Promise<void> {\n const { makeDeleteMutation } = ensureConfig(config, ['makeDeleteMutation']);\n return makeDeleteMutation(id);\n }\n\n async function undelete(id: UnwrapID<TConfig>): Promise<void> {\n const { makeUndeleteMutation } = ensureConfig(config, ['makeUndeleteMutation']);\n return makeUndeleteMutation(id);\n }\n\n return {\n create,\n delete: $delete,\n ensureByID: cache(uncached_ensureByID),\n ensureByIndex: cache(uncached_ensureByIndex),\n ensureFromParams: cache(uncached_ensureFromParams),\n ensureID,\n ensureIDFromParams,\n getAll: cache(uncached_getAll),\n getByID: cache(uncached_getByID),\n getByIndex: cache(uncached_getByIndex),\n getFromParams: cache(uncached_getFromParams),\n getIDFromParams,\n getPaginated: cache(uncached_getPaginated),\n guardID,\n undelete,\n update,\n };\n}\n\nexport default createRepository;\n","import { drizzle } from 'drizzle-orm/node-postgres';\nimport { Pool } from 'pg';\n\nconst pool = new Pool({\n connectionString: process.env.DATABASE_URL,\n});\n\nconst db = drizzle(pool);\n\nexport default db;\n"]}
@@ -1,2 +1,2 @@
1
- import {createClient}from'redis';var n=null;async function g(){if(!process.env.REDIS_URL)throw new Error("REDIS_URL is not defined. Access to the cache is not possible.");return n||(n=createClient({url:process.env.REDIS_URL}),await n.connect(),n)}var i=g;async function u(t,r,e){if(typeof e=="number")return e;let a=await(await i()).ttl(`[${t}]:${r}`);return a<0?0:a}var s=u;var c={async getItem(t,r){let e=await(await i()).get(`[${t}]:${r}`);if(!e)return null;try{return JSON.parse(e)}catch{return null}},async getArray(t,r){return await(await i()).sMembers(`[${t}]:${r}`)},async setArray(t,r,e){await(await i()).del(`[${t}]:${r}`),await(await i()).sAdd(`[${t}]:${r}`,e);},async addToArray(t,r,e){await(await i()).sAdd(`[${t}]:${r}`,e);},async removeFromArray(t,r,e){await(await i()).sRem(`[${t}]:${r}`,e);},async setItem(t,r,e,a){await(await i()).set(`[${t}]:${r}`,JSON.stringify(e),{expiration:{type:"EX",value:await s(t,r,a)}});},async setExpiry(t,r,e){await(await i()).expire(`[${t}]:${r}`,e);},async removeItem(t,r){await(await i()).del(`[${t}]:${r}`);}},p=c;export{p as default};//# sourceMappingURL=index.js.map
1
+ import {createClient}from'redis';var n=null;async function c(){if(!process.env.REDIS_URL)throw new Error("REDIS_URL is not defined. Access to the cache is not possible.");return n||(n=createClient({url:process.env.REDIS_URL}),await n.connect(),n)}var i=c;async function g(t,r,e){if(typeof e=="number")return e;let s=await(await i()).ttl(`[${t}]:${r}`);return s<0?0:s}var o=g;var m={async getItem(t,r){let e=await(await i()).get(`[${t}]:${r}`);if(!e)return null;try{return JSON.parse(e)}catch{return null}},async getArray(t,r){return await(await i()).sMembers(`[${t}]:${r}`)},async setArray(t,r,e){await(await i()).del(`[${t}]:${r}`),await(await i()).sAdd(`[${t}]:${r}`,e);},async addToArray(t,r,e){await(await i()).sAdd(`[${t}]:${r}`,e);},async removeFromArray(t,r,e){await(await i()).sRem(`[${t}]:${r}`,e);},async setItem(t,r,e,s){let a=await o(t,r,s);await(await i()).set(`[${t}]:${r}`,JSON.stringify(e),a>0?{expiration:{type:"EX",value:a}}:void 0);},async setExpiry(t,r,e){await(await i()).expire(`[${t}]:${r}`,e);},async removeItem(t,r){await(await i()).del(`[${t}]:${r}`);}},p=m;export{p as default};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/storage/utility/get-client.ts","../../src/storage/utility/get-ttl.ts","../../src/storage/index.ts"],"names":["client","getClient","createClient","get_client_default","getTTL","prefix","key","ttl","result","get_ttl_default","serverStorage","value","storage_default"],"mappings":"iCAIA,IAAIA,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,CACrE,KAAA,CAAO,MAAMJ,CAAAA,EAAU,EAAG,MAAA,CAAO,CAAA,CAAA,EAAIE,CAAM,CAAA,EAAA,EAAKC,CAAG,CAAA,CAAA,CAAIC,CAAG,EAC9D,EAOA,MAAM,UAAA,CAAWF,CAAAA,CAAgBC,CAAAA,CAA4B,CACzD,KAAA,CAAO,MAAMH,CAAAA,IAAa,GAAA,CAAI,CAAA,CAAA,EAAIE,CAAM,CAAA,EAAA,EAAKC,CAAG,CAAA,CAAE,EACtD,CACJ,EAEOM,CAAAA,CAAQF","file":"index.js","sourcesContent":["import { createClient } from 'redis';\n\nimport isLocalhost from './is-localhost.js';\n\nlet client: ReturnType<typeof createClient> | null = null;\n\n/**\n * Get a Redis client instance. If the client does not exist, it creates a new one and connects to the Redis server.\n * If the client already exists, it returns the existing instance.\n *\n * @returns A promise that resolves to a Redis client instance.\n */\nasync function getClient(): Promise<ReturnType<typeof createClient>> {\n if (!process.env.REDIS_URL) {\n throw new Error('REDIS_URL is not defined. Access to the cache is not possible.');\n }\n\n if (client) {\n return client;\n }\n\n client = createClient({\n url: process.env.REDIS_URL,\n });\n\n await client.connect();\n return client;\n}\n\nexport default getClient;\n","import getClient from './get-client';\n\nasync function getTTL(prefix: string, key: string, ttl?: number): Promise<number> {\n // If a TTL is provided, return it directly\n\n if (typeof ttl === 'number') {\n return ttl;\n }\n\n // Otherwise, get the TTL from the storage\n\n const result = await (await getClient()).ttl(`[${prefix}]:${key}`);\n\n // If the result is -2, the key does not exist. If it's -1, the key exists but has no associated expire. In both cases, we return 0.\n\n if (result < 0) {\n return 0;\n }\n\n return result;\n}\n\nexport default getTTL;\n","import getClient from './utility/get-client';\nimport getTTL from './utility/get-ttl';\n\n/**\n * Server-side storage utility for caching data using Redis. It is designed to match the interface of localStorage, but operates on the server side.\n */\nconst serverStorage = {\n /**\n * Get an item from the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to retrieve.\n * @returns The cached item, or null if not found.\n */\n async getItem(prefix: string, key: string): Promise<Record<string, unknown> | null> {\n const value = await (await getClient()).get(`[${prefix}]:${key}`);\n\n if (!value) {\n return null;\n }\n\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n },\n\n async getArray(prefix: string, key: string): Promise<string[]> {\n const values = await (await getClient()).sMembers(`[${prefix}]:${key}`);\n return values;\n },\n\n async setArray(prefix: string, key: string, value: string[]): Promise<void> {\n await (await getClient()).del(`[${prefix}]:${key}`);\n await (await getClient()).sAdd(`[${prefix}]:${key}`, value);\n },\n\n async addToArray(prefix: string, key: string, value: string): Promise<void> {\n await (await getClient()).sAdd(`[${prefix}]:${key}`, value);\n },\n\n async removeFromArray(prefix: string, key: string, value: string): Promise<void> {\n await (await getClient()).sRem(`[${prefix}]:${key}`, value);\n },\n\n /**\n * Set an item in the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to set.\n * @param value The value of the item to set.\n */\n async setItem(\n prefix: string,\n key: string,\n value: Record<string, unknown>,\n ttl?: number\n ): Promise<void> {\n await (\n await getClient()\n ).set(`[${prefix}]:${key}`, JSON.stringify(value), {\n expiration: { type: 'EX', value: await getTTL(prefix, key, ttl) },\n });\n },\n\n async setExpiry(prefix: string, key: string, ttl: number): Promise<void> {\n await (await getClient()).expire(`[${prefix}]:${key}`, ttl);\n },\n\n /**\n * Remove an item from the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to remove.\n */\n async removeItem(prefix: string, key: string): Promise<void> {\n await (await getClient()).del(`[${prefix}]:${key}`);\n },\n};\n\nexport default serverStorage;\n"]}
1
+ {"version":3,"sources":["../../src/storage/utility/get-client.ts","../../src/storage/utility/get-ttl.ts","../../src/storage/index.ts"],"names":["client","getClient","createClient","get_client_default","getTTL","prefix","key","ttl","result","get_ttl_default","serverStorage","value","itemTTL","storage_default"],"mappings":"iCAIA,IAAIA,CAAAA,CAAiD,IAAA,CAQrD,eAAeC,CAAAA,EAAsD,CACjE,GAAI,CAAC,OAAA,CAAQ,IAAI,SA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IE,CAAM,CAAA,EAAA,EAAKC,CAAG,CAAA,CAAA,CAAIC,CAAG,EAC9D,EAOA,MAAM,UAAA,CAAWF,CAAAA,CAAgBC,CAAAA,CAA4B,CACzD,KAAA,CAAO,MAAMH,CAAAA,IAAa,GAAA,CAAI,CAAA,CAAA,EAAIE,CAAM,CAAA,EAAA,EAAKC,CAAG,CAAA,CAAE,EACtD,CACJ,EAEOO,CAAAA,CAAQH","file":"index.js","sourcesContent":["import { createClient } from 'redis';\n\nimport isLocalhost from './is-localhost.js';\n\nlet client: ReturnType<typeof createClient> | null = null;\n\n/**\n * Get a Redis client instance. If the client does not exist, it creates a new one and connects to the Redis server.\n * If the client already exists, it returns the existing instance.\n *\n * @returns A promise that resolves to a Redis client instance.\n */\nasync function getClient(): Promise<ReturnType<typeof createClient>> {\n if (!process.env.REDIS_URL) {\n throw new Error('REDIS_URL is not defined. Access to the cache is not possible.');\n }\n\n if (client) {\n return client;\n }\n\n client = createClient({\n url: process.env.REDIS_URL,\n });\n\n await client.connect();\n return client;\n}\n\nexport default getClient;\n","import getClient from './get-client';\n\nasync function getTTL(prefix: string, key: string, ttl?: number): Promise<number> {\n // If a TTL is provided, return it directly\n\n if (typeof ttl === 'number') {\n return ttl;\n }\n\n // Otherwise, get the TTL from the storage\n\n const result = await (await getClient()).ttl(`[${prefix}]:${key}`);\n\n // If the result is -2, the key does not exist. If it's -1, the key exists but has no associated expire. In both cases, we return 0.\n\n if (result < 0) {\n return 0;\n }\n\n return result;\n}\n\nexport default getTTL;\n","import getClient from './utility/get-client';\nimport getTTL from './utility/get-ttl';\n\n/**\n * Server-side storage utility for caching data using Redis. It is designed to match the interface of localStorage, but operates on the server side.\n */\nconst serverStorage = {\n /**\n * Get an item from the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to retrieve.\n * @returns The cached item, or null if not found.\n */\n async getItem(prefix: string, key: string): Promise<Record<string, unknown> | null> {\n const value = await (await getClient()).get(`[${prefix}]:${key}`);\n\n if (!value) {\n return null;\n }\n\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n },\n\n async getArray(prefix: string, key: string): Promise<string[]> {\n const values = await (await getClient()).sMembers(`[${prefix}]:${key}`);\n return values;\n },\n\n async setArray(prefix: string, key: string, value: string[]): Promise<void> {\n await (await getClient()).del(`[${prefix}]:${key}`);\n await (await getClient()).sAdd(`[${prefix}]:${key}`, value);\n },\n\n async addToArray(prefix: string, key: string, value: string): Promise<void> {\n await (await getClient()).sAdd(`[${prefix}]:${key}`, value);\n },\n\n async removeFromArray(prefix: string, key: string, value: string): Promise<void> {\n await (await getClient()).sRem(`[${prefix}]:${key}`, value);\n },\n\n /**\n * Set an item in the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to set.\n * @param value The value of the item to set.\n */\n async setItem(\n prefix: string,\n key: string,\n value: Record<string, unknown>,\n ttl?: number\n ): Promise<void> {\n const itemTTL = await getTTL(prefix, key, ttl);\n\n await (\n await getClient()\n ).set(\n `[${prefix}]:${key}`,\n JSON.stringify(value),\n itemTTL > 0\n ? {\n expiration: { type: 'EX', value: itemTTL },\n }\n : undefined\n );\n },\n\n async setExpiry(prefix: string, key: string, ttl: number): Promise<void> {\n await (await getClient()).expire(`[${prefix}]:${key}`, ttl);\n },\n\n /**\n * Remove an item from the cache.\n * @param prefix The prefix to use for the cache key.\n * @param key The key of the item to remove.\n */\n async removeItem(prefix: string, key: string): Promise<void> {\n await (await getClient()).del(`[${prefix}]:${key}`);\n },\n};\n\nexport default serverStorage;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqrzro/server",
3
- "version": "4.0.0-alpha.32",
3
+ "version": "4.0.0-alpha.34",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "react-dom": "^19.2.4",
51
51
  "redis": "^5.11.0",
52
52
  "zod": "^4.3.6",
53
- "@sqrzro/utility": "^4.0.0-alpha.13"
53
+ "@sqrzro/utility": "^4.0.0-alpha.16"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/jest": "^29.5.14",