@wordrhyme/auto-crud-server 1.1.5 → 1.1.6

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/index.cjs CHANGED
@@ -432,6 +432,9 @@ function nonEmpty(value) {
432
432
 
433
433
  //#endregion
434
434
  //#region src/routers/_factory.ts
435
+ function normalizePluginRouteId(pluginId) {
436
+ return pluginId.replace(/^com\.wordrhyme\./, "").replace(/\./g, "-");
437
+ }
435
438
  function resolveSoftDelete(option) {
436
439
  if (!option) return null;
437
440
  if (option === true) return {
@@ -648,9 +651,14 @@ function readCrudTarget(config) {
648
651
  if (!id) return null;
649
652
  return { id };
650
653
  }
651
- function buildCrudLifecycleHookId(config, operation) {
654
+ function buildCrudLifecycleHookId(config, operation, ctx) {
652
655
  const target = readCrudTarget(config);
653
656
  if (!target) return null;
657
+ const pluginId = ctx?.pluginId;
658
+ if (typeof pluginId === "string" && target.id.startsWith(`${pluginId}.`)) {
659
+ const resourceId = target.id.slice(pluginId.length + 1);
660
+ if (resourceId) return `${normalizePluginRouteId(pluginId)}.${resourceId}.${operation}`;
661
+ }
654
662
  return `${target.id}.${operation}`;
655
663
  }
656
664
  function getCrudLifecycleHooks(ctx) {
@@ -658,10 +666,10 @@ function getCrudLifecycleHooks(ctx) {
658
666
  return typeof hooks?.emit === "function" ? hooks : null;
659
667
  }
660
668
  function shouldWrapCrudLifecycleTransaction(ctx, config) {
661
- return Boolean(buildCrudLifecycleHookId(config, "create") && getCrudLifecycleHooks(ctx));
669
+ return Boolean(buildCrudLifecycleHookId(config, "create", ctx) && getCrudLifecycleHooks(ctx));
662
670
  }
663
671
  async function emitCrudWriteLifecycle(ctx, config, operation, payload) {
664
- const hookId = buildCrudLifecycleHookId(config, operation);
672
+ const hookId = buildCrudLifecycleHookId(config, operation, ctx);
665
673
  const hooks = getCrudLifecycleHooks(ctx);
666
674
  if (!hookId || !hooks) return;
667
675
  await hooks.emit(hookId, payload, {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { PgTable } from "drizzle-orm/pg-core";
3
- import * as _trpc_server0 from "@trpc/server";
3
+ import * as _trpc_server2 from "@trpc/server";
4
4
  import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
5
5
  import { AnyColumn, SQL } from "drizzle-orm";
6
6
 
@@ -12,13 +12,13 @@ import { AnyColumn, SQL } from "drizzle-orm";
12
12
  interface Context {
13
13
  db: PostgresJsDatabase<Record<string, never>>;
14
14
  }
15
- declare const router: _trpc_server0.TRPCRouterBuilder<{
15
+ declare const router: _trpc_server2.TRPCRouterBuilder<{
16
16
  ctx: Context;
17
17
  meta: object;
18
- errorShape: _trpc_server0.TRPCDefaultErrorShape;
18
+ errorShape: _trpc_server2.TRPCDefaultErrorShape;
19
19
  transformer: true;
20
20
  }>;
21
- declare const publicProcedure: _trpc_server0.TRPCProcedureBuilder<Context, object, object, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, false>;
21
+ declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, object, object, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, false>;
22
22
  //#endregion
23
23
  //#region src/types/config.d.ts
24
24
  type CrudOperation = 'list' | 'get' | 'create' | 'update' | 'delete' | 'deleteMany' | 'updateMany' | 'upsert' | 'export' | 'import' | 'createMany';
@@ -890,12 +890,12 @@ type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCre
890
890
  } } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
891
891
  //#endregion
892
892
  //#region src/routers/index.d.ts
893
- declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
893
+ declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
894
894
  ctx: Context;
895
895
  meta: object;
896
- errorShape: _trpc_server0.TRPCDefaultErrorShape;
896
+ errorShape: _trpc_server2.TRPCDefaultErrorShape;
897
897
  transformer: true;
898
- }, _trpc_server0.TRPCDecorateCreateRouterOptions<{}>>;
898
+ }, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
899
899
  type AppRouter = typeof appRouter;
900
900
  //#endregion
901
901
  export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { AnyColumn, SQL } from "drizzle-orm";
3
- import * as _trpc_server2 from "@trpc/server";
3
+ import * as _trpc_server0 from "@trpc/server";
4
4
  import superjson from "superjson";
5
5
  import { PgTable } from "drizzle-orm/pg-core";
6
6
  import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
@@ -13,13 +13,13 @@ import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
13
13
  interface Context {
14
14
  db: PostgresJsDatabase<Record<string, never>>;
15
15
  }
16
- declare const router: _trpc_server2.TRPCRouterBuilder<{
16
+ declare const router: _trpc_server0.TRPCRouterBuilder<{
17
17
  ctx: Context;
18
18
  meta: object;
19
- errorShape: _trpc_server2.TRPCDefaultErrorShape;
19
+ errorShape: _trpc_server0.TRPCDefaultErrorShape;
20
20
  transformer: true;
21
21
  }>;
22
- declare const publicProcedure: _trpc_server2.TRPCProcedureBuilder<Context, object, object, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, _trpc_server2.TRPCUnsetMarker, false>;
22
+ declare const publicProcedure: _trpc_server0.TRPCProcedureBuilder<Context, object, object, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, _trpc_server0.TRPCUnsetMarker, false>;
23
23
  //#endregion
24
24
  //#region src/types/config.d.ts
25
25
  type CrudOperation = 'list' | 'get' | 'create' | 'update' | 'delete' | 'deleteMany' | 'updateMany' | 'upsert' | 'export' | 'import' | 'createMany';
@@ -891,12 +891,12 @@ type CrudHookEventMap<PluginId extends string, ResourceName extends string, TCre
891
891
  } } & { [K in `${PluginId}.${ResourceName}.createMany`]: TCreate[] };
892
892
  //#endregion
893
893
  //#region src/routers/index.d.ts
894
- declare const appRouter: _trpc_server2.TRPCBuiltRouter<{
894
+ declare const appRouter: _trpc_server0.TRPCBuiltRouter<{
895
895
  ctx: Context;
896
896
  meta: object;
897
- errorShape: _trpc_server2.TRPCDefaultErrorShape;
897
+ errorShape: _trpc_server0.TRPCDefaultErrorShape;
898
898
  transformer: true;
899
- }, _trpc_server2.TRPCDecorateCreateRouterOptions<{}>>;
899
+ }, _trpc_server0.TRPCDecorateCreateRouterOptions<{}>>;
900
900
  type AppRouter = typeof appRouter;
901
901
  //#endregion
902
902
  export { type AnyProcedure, type AppRouter, type CreateManyMiddlewareParams, type CreateMiddlewareParams, type CrudColumnConfig, type CrudColumnExpression, type CrudColumnRef, type CrudExtensionFilter, type CrudExtensionMetadata, type CrudExtensionsConfig, type CrudExtensionsProvider, type CrudHookEventMap, type CrudMiddleware, type CrudOperation, type CrudProcedures, type CrudRouterConfig, type DeleteManyMiddlewareParams, type DeleteMiddlewareParams, type ExportInput, type ExportMiddlewareParams, type ExportResult, type GetInput, type GetMiddlewareParams, type ImportFailedRow, type ImportInput, type ImportMiddlewareParams, type ImportResult, type ListInput, type ListMiddlewareParams, type ListResult, type ProcedureConfig, type ProcedureFactory, type ProcedureMap, type SoftDeleteConfig, type SoftDeleteOption, type UpdateManyMiddlewareParams, type UpdateMiddlewareParams, type UpsertMiddlewareParams, type WriteOperation, afterMiddleware, appRouter, baseExportInputSchema, baseGetInputSchema, baseListInputSchema, beforeMiddleware, composeMiddleware, createCrudRouter, publicProcedure, router };
package/dist/index.js CHANGED
@@ -403,6 +403,9 @@ function nonEmpty(value) {
403
403
 
404
404
  //#endregion
405
405
  //#region src/routers/_factory.ts
406
+ function normalizePluginRouteId(pluginId) {
407
+ return pluginId.replace(/^com\.wordrhyme\./, "").replace(/\./g, "-");
408
+ }
406
409
  function resolveSoftDelete(option) {
407
410
  if (!option) return null;
408
411
  if (option === true) return {
@@ -619,9 +622,14 @@ function readCrudTarget(config) {
619
622
  if (!id) return null;
620
623
  return { id };
621
624
  }
622
- function buildCrudLifecycleHookId(config, operation) {
625
+ function buildCrudLifecycleHookId(config, operation, ctx) {
623
626
  const target = readCrudTarget(config);
624
627
  if (!target) return null;
628
+ const pluginId = ctx?.pluginId;
629
+ if (typeof pluginId === "string" && target.id.startsWith(`${pluginId}.`)) {
630
+ const resourceId = target.id.slice(pluginId.length + 1);
631
+ if (resourceId) return `${normalizePluginRouteId(pluginId)}.${resourceId}.${operation}`;
632
+ }
625
633
  return `${target.id}.${operation}`;
626
634
  }
627
635
  function getCrudLifecycleHooks(ctx) {
@@ -629,10 +637,10 @@ function getCrudLifecycleHooks(ctx) {
629
637
  return typeof hooks?.emit === "function" ? hooks : null;
630
638
  }
631
639
  function shouldWrapCrudLifecycleTransaction(ctx, config) {
632
- return Boolean(buildCrudLifecycleHookId(config, "create") && getCrudLifecycleHooks(ctx));
640
+ return Boolean(buildCrudLifecycleHookId(config, "create", ctx) && getCrudLifecycleHooks(ctx));
633
641
  }
634
642
  async function emitCrudWriteLifecycle(ctx, config, operation, payload) {
635
- const hookId = buildCrudLifecycleHookId(config, operation);
643
+ const hookId = buildCrudLifecycleHookId(config, operation, ctx);
636
644
  const hooks = getCrudLifecycleHooks(ctx);
637
645
  if (!hookId || !hooks) return;
638
646
  await hooks.emit(hookId, payload, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud-server",
3
3
  "type": "module",
4
- "version": "1.1.5",
4
+ "version": "1.1.6",
5
5
  "description": "tRPC server utilities for auto-crud - automatic CRUD routers for Drizzle ORM",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -48,11 +48,11 @@
48
48
  "typescript": "^5.9.3",
49
49
  "vitest": "^4.0.18",
50
50
  "zod": "^4.3.6",
51
- "@internal/eslint-config": "0.3.0",
52
- "@internal/tsdown-config": "0.1.0",
53
- "@internal/vitest-config": "0.1.0",
54
51
  "@internal/tsconfig": "0.1.0",
55
- "@internal/prettier-config": "0.0.1"
52
+ "@internal/tsdown-config": "0.1.0",
53
+ "@internal/prettier-config": "0.0.1",
54
+ "@internal/eslint-config": "0.3.0",
55
+ "@internal/vitest-config": "0.1.0"
56
56
  },
57
57
  "prettier": "@internal/prettier-config",
58
58
  "scripts": {