model-blueprint 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createId.js +12 -0
- package/dist/createId.js.map +1 -0
- package/dist/dropQuery.js.map +1 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/dist/withCursor.js.map +1 -0
- package/package.json +9 -9
- package/dist/createId/createId.js +0 -1724
- package/dist/createId/createId.js.map +0 -1
- package/dist/dropQuery/dropQuery.js.map +0 -1
- package/dist/withCursor/withCursor.js.map +0 -1
- /package/dist/{createId/createId.d.ts → createId.d.ts} +0 -0
- /package/dist/{dropQuery/dropQuery.d.ts → dropQuery.d.ts} +0 -0
- /package/dist/{dropQuery/dropQuery.js → dropQuery.js} +0 -0
- /package/dist/{withCursor/withCursor.d.ts → withCursor.d.ts} +0 -0
- /package/dist/{withCursor/withCursor.js → withCursor.js} +0 -0
package/dist/createId.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/queryUtils/createId.ts
|
|
2
|
+
import {
|
|
3
|
+
createId as createCuid2Id,
|
|
4
|
+
init as initCuid2
|
|
5
|
+
} from "@paralleldrive/cuid2";
|
|
6
|
+
var createId = ({ ctx }) => {
|
|
7
|
+
return { ...ctx, createId: createCuid2Id, init: initCuid2 };
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
createId
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=createId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/queryUtils/createId.ts"],"sourcesContent":["import {\n createId as createCuid2Id,\n init as initCuid2,\n} from '@paralleldrive/cuid2';\n\n/**\n * Middleware factory that adds a `createId` and `init` function to the context.\n * This function allows procedures to create CUID2 IDs and initialize CUID2.\n * @template TContext - The context type.\n * @param ctx - The context object.\n * @returns A middleware function that injects the `createId` and `init` helpers into the context.\n */\nexport const createId = <TContext>({ ctx }: { ctx: TContext }) => {\n return { ...ctx, createId: createCuid2Id, init: initCuid2 };\n};\n"],"mappings":";AAAA;AAAA,EACE,YAAY;AAAA,EACZ,QAAQ;AAAA,OACH;AASA,IAAM,WAAW,CAAW,EAAE,IAAI,MAAyB;AAChE,SAAO,EAAE,GAAG,KAAK,UAAU,eAAe,MAAM,UAAU;AAC5D;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/queryUtils/dropQuery.ts"],"sourcesContent":["import z, { ZodAny } from 'zod';\nimport { QUERY_MARKER } from './constant';\nimport { QueryBuilder } from './types';\nimport { ProcedureBuilder } from './ProcedureBuilder';\n\n/**\n * Type guard to check if a value is a valid `QueryBuilder`.\n * Used internally by the repository factory during hydration.\n * @param value - The value to check.\n * @returns True if the value is a QueryBuilder function.\n */\nexport function isQueryBuilder<TContext>(\n value: unknown\n): value is QueryBuilder<TContext, unknown, unknown> {\n return (\n typeof value === 'function' &&\n QUERY_MARKER in value &&\n (value as { [QUERY_MARKER]: boolean })[QUERY_MARKER] === true\n );\n}\n\n/**\n * Type guard to check if a value is a plain JavaScript object.\n * Used to determine if recursion is needed during repository hydration.\n * Excludes null, Arrays, and Dates.\n * @param value - The value to check.\n * @returns True if the value is a plain object.\n */\nexport function isPlainObject(\n value: unknown\n): value is Record<string, unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n/**\n * Initialize a new procedure builder.\n * @template TRootContext - The initial Context type provided by the application (e.g., Raw Request Context).\n * @returns A new ProcedureBuilder instance.\n */\nexport function initProcedure<TRootContext>() {\n // Initial state: Root = Current, Input = unknown\n return new ProcedureBuilder<TRootContext, TRootContext, ZodAny>();\n}\n\nexport const parseSchema = <TInput extends z.ZodType>(\n schema: TInput,\n input: unknown\n) => {\n const parsed = schema.safeParse(input);\n\n if (!parsed.success) {\n throw new ModelError(400, {\n message: 'input-not-valid',\n });\n }\n\n return parsed.data;\n};\n\ntype ModelErrorOptions = {\n message?: string;\n};\n\nexport class ModelError extends Error {\n constructor(\n public readonly status: number,\n options?: ModelErrorOptions\n ) {\n super(options?.message);\n this.name = 'ModuleError';\n }\n}\n","import { ModelError } from '@/utils';\n\n/**\n * Middleware factory that adds a `drop` function to the context.\n * This function allows procedures to throw controlled HTTP errors with specific messages.\n * @template Messages - A map of error keys to their corresponding message strings.\n * @param dropMessages - An object mapping error keys to messages.\n * @returns A middleware function that injects the `drop` helper into the context.\n */\nexport const dropQuery =\n <Messages extends Record<string, string>>(dropMessages: Messages) =>\n <TContext>({ ctx }: { ctx: TContext }) => {\n const drop = <Key extends keyof Messages>(message: Key, code?: number) => {\n throw new ModelError(code ?? 400, {\n message: dropMessages[message],\n });\n };\n\n return { ...ctx, drop };\n };\n"],"mappings":";AAoEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACkB,QAChB,SACA;AACA,UAAM,SAAS,OAAO;AAHN;AAIhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACnEO,IAAM,YACX,CAA0C,iBAC1C,CAAW,EAAE,IAAI,MAAyB;AACxC,QAAM,OAAO,CAA6B,SAAc,SAAkB;AACxE,UAAM,IAAI,WAAW,QAAQ,KAAK;AAAA,MAChC,SAAS,aAAa,OAAO;AAAA,IAC/B,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,GAAG,KAAK,KAAK;AACxB;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* A unique symbol used to identify `QueryBuilder` functions at runtime.
|
|
5
|
-
* This prevents accidental execution of arbitrary functions found in the blueprint object.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
declare const QUERY_MARKER: unique symbol;
|
|
9
|
-
|
|
10
3
|
/**
|
|
11
4
|
* Represents a compiled query function that is waiting for a Context to be injected.
|
|
12
5
|
* @template TContext - The type of the context object (e.g., DB connection, User session) this query requires.
|
|
@@ -19,11 +12,6 @@ type QueryBuilder<TContext, TInput, TOutput> = {
|
|
|
19
12
|
* @param ctx - The dependency injection context.
|
|
20
13
|
*/
|
|
21
14
|
(ctx: TContext): (input: TInput) => Promise<TOutput>;
|
|
22
|
-
/**
|
|
23
|
-
* Internal marker to verify this function was created by the library.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
[QUERY_MARKER]: true;
|
|
27
15
|
};
|
|
28
16
|
/**
|
|
29
17
|
* A recursive type that transforms a Blueprint definition into a usable API client.
|
|
@@ -64,8 +52,7 @@ declare function createModelFactory<TBlueprint extends Record<string, unknown>>(
|
|
|
64
52
|
* @template TInput - The validated input type (inferred from Zod).
|
|
65
53
|
*/
|
|
66
54
|
declare class ProcedureBuilder<TRootContext, TCurrentContext, TInput extends z.ZodType> {
|
|
67
|
-
private
|
|
68
|
-
private readonly _schema;
|
|
55
|
+
#private;
|
|
69
56
|
constructor(schema?: TInput, middlewares?: ProcedureMiddleware[]);
|
|
70
57
|
/**
|
|
71
58
|
* Define input validation.
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
|
|
1
9
|
// src/constant.ts
|
|
2
10
|
var QUERY_MARKER = /* @__PURE__ */ Symbol("QUERY_BUILDER");
|
|
3
11
|
|
|
4
12
|
// src/ProcedureBuilder.ts
|
|
5
|
-
var
|
|
13
|
+
var _middlewares, _schema;
|
|
14
|
+
var _ProcedureBuilder = class _ProcedureBuilder {
|
|
6
15
|
constructor(schema, middlewares = []) {
|
|
7
|
-
this
|
|
8
|
-
this
|
|
16
|
+
__privateAdd(this, _middlewares);
|
|
17
|
+
__privateAdd(this, _schema);
|
|
18
|
+
__privateSet(this, _schema, schema);
|
|
19
|
+
__privateSet(this, _middlewares, middlewares);
|
|
9
20
|
}
|
|
10
21
|
/**
|
|
11
22
|
* Define input validation.
|
|
@@ -14,7 +25,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
|
14
25
|
input(schema) {
|
|
15
26
|
return new _ProcedureBuilder(
|
|
16
27
|
schema,
|
|
17
|
-
this
|
|
28
|
+
__privateGet(this, _middlewares)
|
|
18
29
|
);
|
|
19
30
|
}
|
|
20
31
|
/**
|
|
@@ -29,8 +40,8 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
|
29
40
|
});
|
|
30
41
|
};
|
|
31
42
|
return new _ProcedureBuilder(
|
|
32
|
-
this
|
|
33
|
-
[...this
|
|
43
|
+
__privateGet(this, _schema),
|
|
44
|
+
[...__privateGet(this, _middlewares), storedMiddleware]
|
|
34
45
|
);
|
|
35
46
|
}
|
|
36
47
|
/**
|
|
@@ -40,12 +51,12 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
|
40
51
|
query(handler) {
|
|
41
52
|
const builder = (rootCtx) => {
|
|
42
53
|
return async (rawInput) => {
|
|
43
|
-
if (!this
|
|
54
|
+
if (!__privateGet(this, _schema)) {
|
|
44
55
|
throw new Error("No schema provided for query");
|
|
45
56
|
}
|
|
46
|
-
const validatedInput = parseSchema(this
|
|
57
|
+
const validatedInput = parseSchema(__privateGet(this, _schema), rawInput);
|
|
47
58
|
let ctxCursor = rootCtx;
|
|
48
|
-
for (const mw of this
|
|
59
|
+
for (const mw of __privateGet(this, _middlewares)) {
|
|
49
60
|
ctxCursor = await mw({ ctx: ctxCursor, input: validatedInput });
|
|
50
61
|
}
|
|
51
62
|
return handler({
|
|
@@ -63,6 +74,9 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
|
63
74
|
return builder;
|
|
64
75
|
}
|
|
65
76
|
};
|
|
77
|
+
_middlewares = new WeakMap();
|
|
78
|
+
_schema = new WeakMap();
|
|
79
|
+
var ProcedureBuilder = _ProcedureBuilder;
|
|
66
80
|
|
|
67
81
|
// src/utils.ts
|
|
68
82
|
function isQueryBuilder(value) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constant.ts","../src/ProcedureBuilder.ts","../src/utils.ts","../src/createModelFactory.ts"],"sourcesContent":["/**\n * A unique symbol used to identify `QueryBuilder` functions at runtime.\n * This prevents accidental execution of arbitrary functions found in the blueprint object.\n * @internal\n */\nexport const QUERY_MARKER = Symbol('QUERY_BUILDER');\n","import z from 'zod';\nimport type { ProcedureMiddleware, QueryBuilder } from './types';\nimport { QUERY_MARKER } from './constant';\nimport { parseSchema } from './utils';\n\n/**\n * The core builder class for creating type-safe database procedures.\n * Implements a fluent interface to chain validation, middleware, and handlers.\n * @template TRootContext - The initial Context type provided by the application (e.g., Raw Request Context).\n * @template TCurrentContext - The Context type at the current stage of the pipeline (modified by previous middlewares).\n * @template TInput - The validated input type (inferred from Zod).\n */\nexport class ProcedureBuilder<\n TRootContext,\n TCurrentContext,\n TInput extends z.ZodType,\n> {\n
|
|
1
|
+
{"version":3,"sources":["../src/constant.ts","../src/ProcedureBuilder.ts","../src/utils.ts","../src/createModelFactory.ts"],"sourcesContent":["/**\n * A unique symbol used to identify `QueryBuilder` functions at runtime.\n * This prevents accidental execution of arbitrary functions found in the blueprint object.\n * @internal\n */\nexport const QUERY_MARKER = Symbol('QUERY_BUILDER');\n","import z from 'zod';\nimport type { ProcedureMiddleware, QueryBuilder } from './types';\nimport { QUERY_MARKER } from './constant';\nimport { parseSchema } from './utils';\n\n/**\n * The core builder class for creating type-safe database procedures.\n * Implements a fluent interface to chain validation, middleware, and handlers.\n * @template TRootContext - The initial Context type provided by the application (e.g., Raw Request Context).\n * @template TCurrentContext - The Context type at the current stage of the pipeline (modified by previous middlewares).\n * @template TInput - The validated input type (inferred from Zod).\n */\nexport class ProcedureBuilder<\n TRootContext,\n TCurrentContext,\n TInput extends z.ZodType,\n> {\n readonly #middlewares: ProcedureMiddleware[];\n readonly #schema: TInput | undefined;\n\n constructor(schema?: TInput, middlewares: ProcedureMiddleware[] = []) {\n this.#schema = schema;\n this.#middlewares = middlewares;\n }\n /**\n * Define input validation.\n * Resets TInput to the inferred Zod type.\n */\n public input<TSchema extends z.ZodType>(schema: TSchema) {\n return new ProcedureBuilder<TRootContext, TCurrentContext, TSchema>(\n schema,\n this.#middlewares\n );\n }\n\n /**\n * Add middleware.\n * Transforms TCurrentContext -> TNextContext.\n */\n public use<TNextContext>(\n middleware: (params: {\n ctx: TCurrentContext;\n input: z.infer<TInput>;\n }) => Promise<TNextContext> | TNextContext\n ) {\n // We cast the middleware to the internal unknown type to store it\n const storedMiddleware: ProcedureMiddleware = async (p) => {\n // Safe casting because the class generics enforce strict usage upstream\n return middleware({\n ctx: p.ctx as TCurrentContext,\n input: p.input as z.infer<TInput>,\n });\n };\n\n return new ProcedureBuilder<TRootContext, TNextContext, TInput>(\n this.#schema,\n [...this.#middlewares, storedMiddleware]\n );\n }\n\n /**\n * Finalize the query.\n * Returns a QueryBuilder that expects TRootContext.\n */\n public query<TResult>(\n handler: (params: {\n ctx: TCurrentContext;\n input: z.infer<TInput>;\n }) => Promise<TResult>\n ): QueryBuilder<TRootContext, z.infer<TInput>, TResult> {\n // The Factory-Compatible Builder\n const builder = (rootCtx: TRootContext) => {\n return async (rawInput: z.infer<TInput>): Promise<TResult> => {\n // A. Validation\n if (!this.#schema) {\n throw new Error('No schema provided for query');\n }\n const validatedInput = parseSchema(this.#schema, rawInput);\n\n // B. Middleware Pipeline\n // We start with the Root Context\n let ctxCursor: unknown = rootCtx;\n\n for (const mw of this.#middlewares) {\n ctxCursor = await mw({ ctx: ctxCursor, input: validatedInput });\n }\n\n // C. Handler\n return handler({\n ctx: ctxCursor as TCurrentContext,\n input: validatedInput,\n });\n };\n };\n\n // Attach Marker safely\n Object.defineProperty(builder, QUERY_MARKER, {\n value: true,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n\n return builder as QueryBuilder<TRootContext, z.infer<TInput>, TResult>;\n }\n}\n","import z, { ZodAny } from 'zod';\nimport { QUERY_MARKER } from './constant';\nimport { QueryBuilder } from './types';\nimport { ProcedureBuilder } from './ProcedureBuilder';\n\n/**\n * Type guard to check if a value is a valid `QueryBuilder`.\n * Used internally by the repository factory during hydration.\n * @param value - The value to check.\n * @returns True if the value is a QueryBuilder function.\n */\nexport function isQueryBuilder<TContext>(\n value: unknown\n): value is QueryBuilder<TContext, unknown, unknown> {\n return (\n typeof value === 'function' &&\n QUERY_MARKER in value &&\n (value as { [QUERY_MARKER]: boolean })[QUERY_MARKER] === true\n );\n}\n\n/**\n * Type guard to check if a value is a plain JavaScript object.\n * Used to determine if recursion is needed during repository hydration.\n * Excludes null, Arrays, and Dates.\n * @param value - The value to check.\n * @returns True if the value is a plain object.\n */\nexport function isPlainObject(\n value: unknown\n): value is Record<string, unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n/**\n * Initialize a new procedure builder.\n * @template TRootContext - The initial Context type provided by the application (e.g., Raw Request Context).\n * @returns A new ProcedureBuilder instance.\n */\nexport function initProcedure<TRootContext>() {\n // Initial state: Root = Current, Input = unknown\n return new ProcedureBuilder<TRootContext, TRootContext, ZodAny>();\n}\n\nexport const parseSchema = <TInput extends z.ZodType>(\n schema: TInput,\n input: unknown\n) => {\n const parsed = schema.safeParse(input);\n\n if (!parsed.success) {\n throw new ModelError(400, {\n message: 'input-not-valid',\n });\n }\n\n return parsed.data;\n};\n\ntype ModelErrorOptions = {\n message?: string;\n};\n\nexport class ModelError extends Error {\n constructor(\n public readonly status: number,\n options?: ModelErrorOptions\n ) {\n super(options?.message);\n this.name = 'ModuleError';\n }\n}\n","import type { HydratedModel } from './types';\nimport { isPlainObject, isQueryBuilder } from './utils';\n\n/**\n * Creates a Model Factory based on your API Blueprint.\n * @template TBlueprint - The structure of your API (nested objects containing QueryBuilders).\n * @param blueprint - The static object defining your API structure.\n * @returns A function `createModel(ctx)` that takes your Context and returns the fully typed API.\n * @example\n * const modelFactory = createModelFactory({\n * users: { get: userGetQuery }\n * });\n * const DB = modelFactory({ db: myDb });\n */\nexport function createModelFactory<TBlueprint extends Record<string, unknown>>(\n blueprint: TBlueprint\n) {\n /**\n * The actual factory function used at runtime per-request.\n * @param ctx - The dependency injection context (must match TRootContext of your builders).\n */\n return function createModel<TContext>(\n ctx: TContext\n ): HydratedModel<TBlueprint, TContext> {\n // Recursive function to walk the blueprint tree and inject context.\n const hydrate = (structure: Record<string, unknown>): unknown => {\n const result: Record<string, unknown> = {};\n\n for (const key in structure) {\n const value = structure[key];\n\n if (isQueryBuilder(value)) {\n // Safe execution via Type Guard\n // value is strictly QueryBuilder<unknown, unknown, unknown>\n result[key] = value(ctx);\n // Note: We perform one specific cast here because TypeScript\n // cannot correlate the TContext generic of the *specific* builder\n // with the TContext passed to the factory without excessive complexity.\n // However, the *Generics* on the class ensure safety for the user.\n } else if (isPlainObject(value)) {\n result[key] = hydrate(value);\n } else {\n result[key] = value;\n }\n }\n return result;\n };\n\n return hydrate(blueprint) as HydratedModel<TBlueprint, TContext>;\n };\n}\n"],"mappings":";;;;;;;;;AAKO,IAAM,eAAe,uBAAO,eAAe;;;ACLlD;AAYO,IAAM,oBAAN,MAAM,kBAIX;AAAA,EAIA,YAAY,QAAiB,cAAqC,CAAC,GAAG;AAHtE,uBAAS;AACT,uBAAS;AAGP,uBAAK,SAAU;AACf,uBAAK,cAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKO,MAAiC,QAAiB;AACvD,WAAO,IAAI;AAAA,MACT;AAAA,MACA,mBAAK;AAAA,IACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,IACL,YAIA;AAEA,UAAM,mBAAwC,OAAO,MAAM;AAEzD,aAAO,WAAW;AAAA,QAChB,KAAK,EAAE;AAAA,QACP,OAAO,EAAE;AAAA,MACX,CAAC;AAAA,IACH;AAEA,WAAO,IAAI;AAAA,MACT,mBAAK;AAAA,MACL,CAAC,GAAG,mBAAK,eAAc,gBAAgB;AAAA,IACzC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MACL,SAIsD;AAEtD,UAAM,UAAU,CAAC,YAA0B;AACzC,aAAO,OAAO,aAAgD;AAE5D,YAAI,CAAC,mBAAK,UAAS;AACjB,gBAAM,IAAI,MAAM,8BAA8B;AAAA,QAChD;AACA,cAAM,iBAAiB,YAAY,mBAAK,UAAS,QAAQ;AAIzD,YAAI,YAAqB;AAEzB,mBAAW,MAAM,mBAAK,eAAc;AAClC,sBAAY,MAAM,GAAG,EAAE,KAAK,WAAW,OAAO,eAAe,CAAC;AAAA,QAChE;AAGA,eAAO,QAAQ;AAAA,UACb,KAAK;AAAA,UACL,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAGA,WAAO,eAAe,SAAS,cAAc;AAAA,MAC3C,OAAO;AAAA,MACP,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAxFW;AACA;AANJ,IAAM,mBAAN;;;ACDA,SAAS,eACd,OACmD;AACnD,SACE,OAAO,UAAU,cACjB,gBAAgB,SACf,MAAsC,YAAY,MAAM;AAE7D;AASO,SAAS,cACd,OACkC;AAClC,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,EAAE,iBAAiB;AAEvB;AAOO,SAAS,gBAA8B;AAE5C,SAAO,IAAI,iBAAqD;AAClE;AAEO,IAAM,cAAc,CACzB,QACA,UACG;AACH,QAAM,SAAS,OAAO,UAAU,KAAK;AAErC,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,WAAW,KAAK;AAAA,MACxB,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO,OAAO;AAChB;AAMO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACkB,QAChB,SACA;AACA,UAAM,SAAS,OAAO;AAHN;AAIhB,SAAK,OAAO;AAAA,EACd;AACF;;;AC9DO,SAAS,mBACd,WACA;AAKA,SAAO,SAAS,YACd,KACqC;AAErC,UAAM,UAAU,CAAC,cAAgD;AAC/D,YAAM,SAAkC,CAAC;AAEzC,iBAAW,OAAO,WAAW;AAC3B,cAAM,QAAQ,UAAU,GAAG;AAE3B,YAAI,eAAe,KAAK,GAAG;AAGzB,iBAAO,GAAG,IAAI,MAAM,GAAG;AAAA,QAKzB,WAAW,cAAc,KAAK,GAAG;AAC/B,iBAAO,GAAG,IAAI,QAAQ,KAAK;AAAA,QAC7B,OAAO;AACL,iBAAO,GAAG,IAAI;AAAA,QAChB;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,WAAO,QAAQ,SAAS;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/queryUtils/withCursor.ts"],"sourcesContent":["const getCursor = <T extends Record<string, unknown | number>>(\n entries: Array<T>,\n parameter: keyof T,\n pageSize: number\n) =>\n entries.length && pageSize === entries.length\n ? (entries[entries.length - 1][parameter] as number)\n : null;\n\nexport const withCursor = <T extends Record<string, unknown | number>>(\n entries: Array<T>,\n parameter: keyof T,\n pageSize: number,\n orderedBy: 'asc' | 'desc' = 'asc'\n) => {\n const cursor = getCursor<T>(entries, parameter, pageSize);\n\n return {\n entries: orderedBy === 'asc' ? entries : entries.reverse(),\n cursor,\n };\n};\n"],"mappings":";AAAA,IAAM,YAAY,CAChB,SACA,WACA,aAEA,QAAQ,UAAU,aAAa,QAAQ,SAClC,QAAQ,QAAQ,SAAS,CAAC,EAAE,SAAS,IACtC;AAEC,IAAM,aAAa,CACxB,SACA,WACA,UACA,YAA4B,UACzB;AACH,QAAM,SAAS,UAAa,SAAS,WAAW,QAAQ;AAExD,SAAO;AAAA,IACL,SAAS,cAAc,QAAQ,UAAU,QAAQ,QAAQ;AAAA,IACzD;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "model-blueprint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts"
|
|
11
11
|
},
|
|
12
12
|
"./withCursor": {
|
|
13
|
-
"import": "./dist/withCursor
|
|
14
|
-
"types": "./dist/withCursor
|
|
13
|
+
"import": "./dist/withCursor.js",
|
|
14
|
+
"types": "./dist/withCursor.d.ts"
|
|
15
15
|
},
|
|
16
16
|
"./createId": {
|
|
17
|
-
"import": "./dist/createId
|
|
18
|
-
"types": "./dist/createId
|
|
17
|
+
"import": "./dist/createId.js",
|
|
18
|
+
"types": "./dist/createId.d.ts"
|
|
19
19
|
},
|
|
20
20
|
"./dropQuery": {
|
|
21
|
-
"import": "./dist/dropQuery
|
|
22
|
-
"types": "./dist/dropQuery
|
|
21
|
+
"import": "./dist/dropQuery.js",
|
|
22
|
+
"types": "./dist/dropQuery.d.ts"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
},
|
|
55
55
|
"description": "model-blueprint",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"zod": "^4.3.6"
|
|
57
|
+
"zod": "^4.3.6",
|
|
58
|
+
"@paralleldrive/cuid2": "^3.3.0"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@paralleldrive/cuid2": "^3.3.0",
|
|
61
61
|
"@eslint/js": "^9.0.0",
|
|
62
62
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
63
63
|
"@typescript-eslint/parser": "^8.0.0",
|