@venizia/ignis-connectors 0.4.1 → 0.4.2

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.
Files changed (69) hide show
  1. package/dist/cjs/common/scope-filter.d.ts +1 -1
  2. package/dist/cjs/common/scope-filter.d.ts.map +1 -1
  3. package/dist/cjs/common/scope-filter.js +33 -7
  4. package/dist/cjs/common/scope-filter.js.map +1 -1
  5. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts +50 -0
  6. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  7. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js +248 -0
  8. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  9. package/dist/cjs/relational/core/repositories/core/base.d.ts +19 -4
  10. package/dist/cjs/relational/core/repositories/core/base.d.ts.map +1 -1
  11. package/dist/cjs/relational/core/repositories/core/base.js +28 -4
  12. package/dist/cjs/relational/core/repositories/core/base.js.map +1 -1
  13. package/dist/cjs/relational/core/repositories/core/persistable.d.ts.map +1 -1
  14. package/dist/cjs/relational/core/repositories/core/persistable.js +6 -1
  15. package/dist/cjs/relational/core/repositories/core/persistable.js.map +1 -1
  16. package/dist/cjs/relational/core/repositories/dialect/filter.d.ts +2 -2
  17. package/dist/cjs/relational/core/repositories/dialect/filter.js +3 -3
  18. package/dist/cjs/relational/core/repositories/dialect/filter.js.map +1 -1
  19. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  20. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  21. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js +14 -3
  22. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  23. package/dist/cjs/search/core/controllers/abstract.d.ts +4 -0
  24. package/dist/cjs/search/core/controllers/abstract.d.ts.map +1 -1
  25. package/dist/cjs/search/core/controllers/abstract.js +15 -1
  26. package/dist/cjs/search/core/controllers/abstract.js.map +1 -1
  27. package/dist/cjs/search/core/controllers/factory.d.ts +14 -0
  28. package/dist/cjs/search/core/controllers/factory.d.ts.map +1 -1
  29. package/dist/cjs/search/core/controllers/factory.js +7 -1
  30. package/dist/cjs/search/core/controllers/factory.js.map +1 -1
  31. package/dist/cjs/search/core/controllers/scope.d.ts +28 -0
  32. package/dist/cjs/search/core/controllers/scope.d.ts.map +1 -0
  33. package/dist/cjs/search/core/controllers/scope.js +68 -0
  34. package/dist/cjs/search/core/controllers/scope.js.map +1 -0
  35. package/dist/esm/common/scope-filter.d.ts +1 -1
  36. package/dist/esm/common/scope-filter.d.ts.map +1 -1
  37. package/dist/esm/common/scope-filter.js +34 -8
  38. package/dist/esm/common/scope-filter.js.map +1 -1
  39. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +50 -0
  40. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  41. package/dist/esm/relational/core/repositories/common/scope-write-guard.js +244 -0
  42. package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  43. package/dist/esm/relational/core/repositories/core/base.d.ts +19 -4
  44. package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
  45. package/dist/esm/relational/core/repositories/core/base.js +28 -4
  46. package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
  47. package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +1 -1
  48. package/dist/esm/relational/core/repositories/core/persistable.js +6 -1
  49. package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
  50. package/dist/esm/relational/core/repositories/dialect/filter.d.ts +2 -2
  51. package/dist/esm/relational/core/repositories/dialect/filter.js +3 -3
  52. package/dist/esm/relational/core/repositories/dialect/filter.js.map +1 -1
  53. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  54. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  55. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js +15 -4
  56. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  57. package/dist/esm/search/core/controllers/abstract.d.ts +4 -0
  58. package/dist/esm/search/core/controllers/abstract.d.ts.map +1 -1
  59. package/dist/esm/search/core/controllers/abstract.js +15 -1
  60. package/dist/esm/search/core/controllers/abstract.js.map +1 -1
  61. package/dist/esm/search/core/controllers/factory.d.ts +14 -0
  62. package/dist/esm/search/core/controllers/factory.d.ts.map +1 -1
  63. package/dist/esm/search/core/controllers/factory.js +7 -1
  64. package/dist/esm/search/core/controllers/factory.js.map +1 -1
  65. package/dist/esm/search/core/controllers/scope.d.ts +28 -0
  66. package/dist/esm/search/core/controllers/scope.d.ts.map +1 -0
  67. package/dist/esm/search/core/controllers/scope.js +64 -0
  68. package/dist/esm/search/core/controllers/scope.js.map +1 -0
  69. package/package.json +6 -6
@@ -10,13 +10,18 @@ export class SearchControllerFactory extends BaseHelper {
10
10
  }
11
11
  /** Creates a search controller with two endpoints: `POST {basePath}/search` via `repository.search()`, and `POST {basePath}/multi-search` via `repository.dataSource.multiSearch()`. */
12
12
  static defineSearchController(defOpts) {
13
- const { controller, entity, authenticate, authorize, routes } = defOpts;
13
+ const { controller, entity, authenticate, authorize, routes, scope } = defOpts;
14
14
  const { name, basePath = 'unknown_path', isStrict = true } = controller;
15
15
  if (!basePath || basePath === 'unknown_path') {
16
16
  throw getError({
17
17
  message: `[defineSearchController] Invalid controller basePath | name: ${name} | basePath: ${basePath}`,
18
18
  });
19
19
  }
20
+ if (scope && routes?.multiSearch?.enabled !== false) {
21
+ throw getError({
22
+ message: `[defineSearchController] A scoped search controller cannot serve multi-search | name: ${name} | set routes.multiSearch.enabled to false`,
23
+ });
24
+ }
20
25
  const entityClass = isClass(entity) ? entity : entity();
21
26
  const entityInstance = new entityClass();
22
27
  const selectSchema = entityInstance.getSchema({ type: SchemaTypes.SELECT });
@@ -29,6 +34,7 @@ export class SearchControllerFactory extends BaseHelper {
29
34
  isStrict,
30
35
  repository,
31
36
  definitions: routeDefinitions,
37
+ searchScope: scope,
32
38
  });
33
39
  }
34
40
  /** Registers the search + multiSearch route handlers, honoring per-route enable flags. */
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kCAAkC,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKxF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAmCxD,wHAAwH;AACxH,MAAM,OAAO,uBAAwB,SAAQ,UAAU;IACrD;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,wLAAwL;IACxL,MAAM,CAAC,sBAAsB,CAO3B,OAA0C;QAC1C,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAExE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,cAAc,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,UAAU,CAAC;QACxE,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;YAC7C,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,gEAAgE,IAAI,gBAAgB,QAAQ,EAAE;aACxG,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACxD,MAAM,cAAc,GAAG,IAAI,WAAW,EAAE,CAAC;QAEzC,MAAM,YAAY,GAAG,cAAc,CAAC,SAAS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EAAE,eAAe;YACvB,WAAW,EAAE,wBAAwB;YACrC,cAAc,EAAE,IAAI;YACpB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;SACxC,CAAC,CAAC;QACH,OAAO,eAAe,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { TEntityDataObject } from '@venizia/ignis-kernel';\nimport type { AbstractEntity } from '@venizia/ignis-kernel';\nimport { registerFactoryRepositoryInjection, SchemaTypes } from '@venizia/ignis-kernel';\nimport type { TAuthMode, TAuthStrategy } from '@venizia/ignis-kernel';\nimport type { IAuthorizationSpec } from '@venizia/ignis-kernel';\nimport type { TAnyObjectSchema } from '@venizia/ignis-kernel';\nimport type { TClass, TResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type { ReadableSearchRepository } from '../repositories/core/readable';\nimport { AbstractSearchController } from './abstract';\nimport { defineSearchRouteConfigs } from './definition';\n\n/** Per-route enable/disable switches for the generated search controller. */\nexport interface ISearchCustomizableRoutes {\n search?: { enabled?: boolean };\n multiSearch?: { enabled?: boolean };\n}\n\n/** Configuration options for creating a search controller via SearchControllerFactory.defineSearchController. */\nexport interface ISearchControllerOptions<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n> {\n /** Entity class or resolver returning it; its SELECT schema drives the `hits[].document` shape in the generated route's response. */\n entity: TClass<TEntity> | TResolver<TClass<TEntity>>;\n\n repository: {\n name: string; // Repository binding name in the IoC container\n };\n\n controller: {\n name: string;\n basePath: string;\n isStrict?: boolean;\n };\n\n /** Authentication config applied to both generated routes. */\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n /** Authorization config applied to both generated routes. */\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n\n /** Per-route enable/disable configuration. */\n routes?: ISearchCustomizableRoutes;\n}\n\n/** Factory for generating turnkey search controllers (single-collection + cross-collection) from entity definitions. */\nexport class SearchControllerFactory extends BaseHelper {\n constructor() {\n super({ scope: SearchControllerFactory.name });\n }\n\n /** Creates a search controller with two endpoints: `POST {basePath}/search` via `repository.search()`, and `POST {basePath}/multi-search` via `repository.dataSource.multiSearch()`. */\n static defineSearchController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n >(defOpts: ISearchControllerOptions<TEntity>) {\n const { controller, entity, authenticate, authorize, routes } = defOpts;\n\n const { name, basePath = 'unknown_path', isStrict = true } = controller;\n if (!basePath || basePath === 'unknown_path') {\n throw getError({\n message: `[defineSearchController] Invalid controller basePath | name: ${name} | basePath: ${basePath}`,\n });\n }\n\n const entityClass = isClass(entity) ? entity : entity();\n const entityInstance = new entityClass();\n\n const selectSchema = entityInstance.getSchema({ type: SchemaTypes.SELECT });\n const routeDefinitions = defineSearchRouteConfigs({ selectSchema, authenticate, authorize });\n\n const controllerClass = class extends AbstractSearchController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject\n > {\n constructor(repository: ReadableSearchRepository<TDataObject>) {\n super({\n scope: name,\n path: basePath,\n isStrict,\n repository,\n definitions: routeDefinitions,\n });\n }\n\n /** Registers the search + multiSearch route handlers, honoring per-route enable flags. */\n override binding(): ValueOrPromise<void> {\n const isEnabled = (routeKey: keyof ISearchCustomizableRoutes) => {\n return routes?.[routeKey]?.enabled !== false;\n };\n\n if (isEnabled('search')) {\n this.defineRoute({\n configs: routeDefinitions.SEARCH,\n handler: async (context) => this.search({ context }),\n });\n }\n\n if (isEnabled('multiSearch')) {\n this.defineRoute({\n configs: routeDefinitions.MULTI_SEARCH,\n handler: async (context) => this.multiSearch({ context }),\n });\n }\n }\n };\n\n Object.defineProperty(controllerClass, 'name', { value: name, configurable: true });\n registerFactoryRepositoryInjection({\n target: controllerClass,\n factoryName: 'defineSearchController',\n controllerName: name,\n repositoryName: defOpts.repository.name,\n });\n return controllerClass;\n }\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kCAAkC,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKxF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAgDxD,wHAAwH;AACxH,MAAM,OAAO,uBAAwB,SAAQ,UAAU;IACrD;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,wLAAwL;IACxL,MAAM,CAAC,sBAAsB,CAO3B,OAA0C;QAC1C,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE/E,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,cAAc,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,UAAU,CAAC;QACxE,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;YAC7C,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,gEAAgE,IAAI,gBAAgB,QAAQ,EAAE;aACxG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,KAAK,IAAI,MAAM,EAAE,WAAW,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,yFAAyF,IAAI,4CAA4C;a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AI,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC;qBAC1D,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;QAEF,MAAM,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACpF,kCAAkC,CAAC;YACjC,MAAM,EAAE,eAAe;YACvB,WAAW,EAAE,wBAAwB;YACrC,cAAc,EAAE,IAAI;YACpB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;SACxC,CAAC,CAAC;QACH,OAAO,eAAe,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { TEntityDataObject } from '@venizia/ignis-kernel';\nimport type { AbstractEntity } from '@venizia/ignis-kernel';\nimport { registerFactoryRepositoryInjection, SchemaTypes } from '@venizia/ignis-kernel';\nimport type { TAuthMode, TAuthStrategy } from '@venizia/ignis-kernel';\nimport type { IAuthorizationSpec } from '@venizia/ignis-kernel';\nimport type { TAnyObjectSchema } from '@venizia/ignis-kernel';\nimport type { TClass, TResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type { ReadableSearchRepository } from '../repositories/core/readable';\nimport { AbstractSearchController } from './abstract';\nimport type { TSearchScopeResolver } from './scope';\nimport { defineSearchRouteConfigs } from './definition';\n\n/** Per-route enable/disable switches for the generated search controller. */\nexport interface ISearchCustomizableRoutes {\n search?: { enabled?: boolean };\n multiSearch?: { enabled?: boolean };\n}\n\n/** Configuration options for creating a search controller via SearchControllerFactory.defineSearchController. */\nexport interface ISearchControllerOptions<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n> {\n /** Entity class or resolver returning it; its SELECT schema drives the `hits[].document` shape in the generated route's response. */\n entity: TClass<TEntity> | TResolver<TClass<TEntity>>;\n\n repository: {\n name: string; // Repository binding name in the IoC container\n };\n\n controller: {\n name: string;\n basePath: string;\n isStrict?: boolean;\n };\n\n /** Authentication config applied to both generated routes. */\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n /** Authorization config applied to both generated routes. */\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n\n /** Per-route enable/disable configuration. */\n routes?: ISearchCustomizableRoutes;\n\n /**\n * A function of the request context returning the filter this caller may search within. It is\n * ANDed into `input.filter.where` on the server: the client's own `where` can narrow it, never\n * widen or remove it. Fails closed - a scope that is null, undefined or throws refuses the\n * request with 403. Return `ScopeFilters.UNRESTRICTED` to apply none for a trusted caller.\n *\n * `raw` mode and `engineParams` hand the engine its own wire parameters, and a multi-search entry\n * carries a raw `filterBy`; none can take a scope, so a scoped controller refuses `raw` and\n * `engineParams` (400) and must disable the multi-search route (`routes.multiSearch.enabled:\n * false`), which `defineSearchController` requires.\n */\n scope?: TSearchScopeResolver;\n}\n\n/** Factory for generating turnkey search controllers (single-collection + cross-collection) from entity definitions. */\nexport class SearchControllerFactory extends BaseHelper {\n constructor() {\n super({ scope: SearchControllerFactory.name });\n }\n\n /** Creates a search controller with two endpoints: `POST {basePath}/search` via `repository.search()`, and `POST {basePath}/multi-search` via `repository.dataSource.multiSearch()`. */\n static defineSearchController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n >(defOpts: ISearchControllerOptions<TEntity>) {\n const { controller, entity, authenticate, authorize, routes, scope } = defOpts;\n\n const { name, basePath = 'unknown_path', isStrict = true } = controller;\n if (!basePath || basePath === 'unknown_path') {\n throw getError({\n message: `[defineSearchController] Invalid controller basePath | name: ${name} | basePath: ${basePath}`,\n });\n }\n\n if (scope && routes?.multiSearch?.enabled !== false) {\n throw getError({\n message: `[defineSearchController] A scoped search controller cannot serve multi-search | name: ${name} | set routes.multiSearch.enabled to false`,\n });\n }\n\n const entityClass = isClass(entity) ? entity : entity();\n const entityInstance = new entityClass();\n\n const selectSchema = entityInstance.getSchema({ type: SchemaTypes.SELECT });\n const routeDefinitions = defineSearchRouteConfigs({ selectSchema, authenticate, authorize });\n\n const controllerClass = class extends AbstractSearchController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject\n > {\n constructor(repository: ReadableSearchRepository<TDataObject>) {\n super({\n scope: name,\n path: basePath,\n isStrict,\n repository,\n definitions: routeDefinitions,\n searchScope: scope as TSearchScopeResolver<RouteEnv> | undefined,\n });\n }\n\n /** Registers the search + multiSearch route handlers, honoring per-route enable flags. */\n override binding(): ValueOrPromise<void> {\n const isEnabled = (routeKey: keyof ISearchCustomizableRoutes) => {\n return routes?.[routeKey]?.enabled !== false;\n };\n\n if (isEnabled('search')) {\n this.defineRoute({\n configs: routeDefinitions.SEARCH,\n handler: async (context) => this.search({ context }),\n });\n }\n\n if (isEnabled('multiSearch')) {\n this.defineRoute({\n configs: routeDefinitions.MULTI_SEARCH,\n handler: async (context) => this.multiSearch({ context }),\n });\n }\n }\n };\n\n Object.defineProperty(controllerClass, 'name', { value: name, configurable: true });\n registerFactoryRepositoryInjection({\n target: controllerClass,\n factoryName: 'defineSearchController',\n controllerName: name,\n repositoryName: defOpts.repository.name,\n });\n return controllerClass;\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import type { ValueOrPromise } from '@venizia/ignis-helpers/common';
2
+ import { ScopeFilters } from '@venizia/ignis-kernel';
3
+ import type { TRouteContext, TWhere } from '@venizia/ignis-kernel';
4
+ import type { Env } from 'hono';
5
+ import type { TSearchInput } from '../repositories/common/index.js';
6
+ /**
7
+ * A per-request search scope: the filter the caller is allowed to search within (a merchant, a
8
+ * sharing rule). Return a `where`, `ScopeFilters.UNRESTRICTED` to apply none for this call, or
9
+ * null/undefined when the caller's scope is unknown - which refuses the request.
10
+ */
11
+ export type TSearchScopeResolver<RouteEnv extends Env = Env> = (opts: {
12
+ context: TRouteContext<RouteEnv>;
13
+ }) => ValueOrPromise<TWhere | typeof ScopeFilters.UNRESTRICTED | null | undefined>;
14
+ /**
15
+ * ANDs the resolved scope into `input.filter.where`, on the server, after the body was validated.
16
+ * The client's own `where` is kept inside the AND, so it can narrow the scope and never widen it.
17
+ *
18
+ * Fails closed:
19
+ * - a scope that is null, undefined, or throws refuses the request (403);
20
+ * - `raw` mode and `engineParams` hand the engine its own wire parameters (`filter_by` among them),
21
+ * which a `where` cannot be ANDed into, so a scoped controller refuses them (400).
22
+ */
23
+ export declare const applySearchScope: <RouteEnv extends Env = Env>(opts: {
24
+ resolve: TSearchScopeResolver<RouteEnv>;
25
+ context: TRouteContext<RouteEnv>;
26
+ input: TSearchInput;
27
+ }) => Promise<TSearchInput>;
28
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGtE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE;IACpE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,KAAK,cAAc,CAAC,MAAM,GAAG,OAAO,YAAY,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAUnF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,SAAS,GAAG,GAAG,GAAG,EAAE,MAAM;IACvE,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,KAAK,EAAE,YAAY,CAAC;CACrB,KAAG,OAAO,CAAC,YAAY,CAgDvB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { HTTP } from '@venizia/ignis-helpers/common';
2
+ import { getError } from '@venizia/ignis-helpers/core';
3
+ import { ScopeFilters } from '@venizia/ignis-kernel';
4
+ import { SearchModes } from '../repositories/common/index.js';
5
+ const refuse = (opts) => {
6
+ return getError({
7
+ statusCode: opts.statusCode,
8
+ message: opts.message,
9
+ cause: opts.cause,
10
+ });
11
+ };
12
+ /**
13
+ * ANDs the resolved scope into `input.filter.where`, on the server, after the body was validated.
14
+ * The client's own `where` is kept inside the AND, so it can narrow the scope and never widen it.
15
+ *
16
+ * Fails closed:
17
+ * - a scope that is null, undefined, or throws refuses the request (403);
18
+ * - `raw` mode and `engineParams` hand the engine its own wire parameters (`filter_by` among them),
19
+ * which a `where` cannot be ANDed into, so a scoped controller refuses them (400).
20
+ */
21
+ export const applySearchScope = async (opts) => {
22
+ const { resolve, context, input } = opts;
23
+ let scope;
24
+ try {
25
+ scope = await resolve({ context });
26
+ }
27
+ catch (error) {
28
+ throw refuse({
29
+ statusCode: HTTP.ResultCodes.RS_4.Forbidden,
30
+ message: '[search] the search scope could not be resolved for this request',
31
+ cause: error,
32
+ });
33
+ }
34
+ if (scope === ScopeFilters.UNRESTRICTED) {
35
+ return input;
36
+ }
37
+ if (scope === null || scope === undefined) {
38
+ throw refuse({
39
+ statusCode: HTTP.ResultCodes.RS_4.Forbidden,
40
+ message: '[search] no search scope for this request',
41
+ });
42
+ }
43
+ if (input.mode === SearchModes.RAW) {
44
+ throw refuse({
45
+ statusCode: HTTP.ResultCodes.RS_4.BadRequest,
46
+ message: "[search] mode 'raw' is not available on a scoped search controller",
47
+ });
48
+ }
49
+ if (input.engineParams !== undefined) {
50
+ throw refuse({
51
+ statusCode: HTTP.ResultCodes.RS_4.BadRequest,
52
+ message: '[search] engineParams is not available on a scoped search controller',
53
+ });
54
+ }
55
+ const clientWhere = input.filter?.where;
56
+ return {
57
+ ...input,
58
+ filter: {
59
+ ...input.filter,
60
+ where: clientWhere ? { and: [scope, clientWhere] } : scope,
61
+ },
62
+ };
63
+ };
64
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAWhE,MAAM,MAAM,GAAG,CAAC,IAA8D,EAAE,EAAE;IAChF,OAAO,QAAQ,CAAC;QACd,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAA8B,IAIlE,EAAyB,EAAE;IAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEzC,IAAI,KAA0D,CAAC;IAC/D,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC;YACX,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;YAC3C,OAAO,EAAE,kEAAkE;YAC3E,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,KAAK,YAAY,CAAC,YAAY,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,MAAM,CAAC;YACX,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;YAC3C,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;QACnC,MAAM,MAAM,CAAC;YACX,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;YAC5C,OAAO,EAAE,oEAAoE;SAC9E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,MAAM,CAAC;YACX,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;YAC5C,OAAO,EAAE,sEAAsE;SAChF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;IAExC,OAAO;QACL,GAAG,KAAK;QACR,MAAM,EAAE;YACN,GAAG,KAAK,CAAC,MAAM;YACf,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK;SAC3D;KACc,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { ScopeFilters } from '@venizia/ignis-kernel';\nimport type { TRouteContext, TWhere } from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport type { TSearchInput } from '@/search/core/repositories/common';\nimport { SearchModes } from '@/search/core/repositories/common';\n\n/**\n * A per-request search scope: the filter the caller is allowed to search within (a merchant, a\n * sharing rule). Return a `where`, `ScopeFilters.UNRESTRICTED` to apply none for this call, or\n * null/undefined when the caller's scope is unknown - which refuses the request.\n */\nexport type TSearchScopeResolver<RouteEnv extends Env = Env> = (opts: {\n context: TRouteContext<RouteEnv>;\n}) => ValueOrPromise<TWhere | typeof ScopeFilters.UNRESTRICTED | null | undefined>;\n\nconst refuse = (opts: { statusCode: number; message: string; cause?: unknown }) => {\n return getError({\n statusCode: opts.statusCode,\n message: opts.message,\n cause: opts.cause,\n });\n};\n\n/**\n * ANDs the resolved scope into `input.filter.where`, on the server, after the body was validated.\n * The client's own `where` is kept inside the AND, so it can narrow the scope and never widen it.\n *\n * Fails closed:\n * - a scope that is null, undefined, or throws refuses the request (403);\n * - `raw` mode and `engineParams` hand the engine its own wire parameters (`filter_by` among them),\n * which a `where` cannot be ANDed into, so a scoped controller refuses them (400).\n */\nexport const applySearchScope = async <RouteEnv extends Env = Env>(opts: {\n resolve: TSearchScopeResolver<RouteEnv>;\n context: TRouteContext<RouteEnv>;\n input: TSearchInput;\n}): Promise<TSearchInput> => {\n const { resolve, context, input } = opts;\n\n let scope: Awaited<ReturnType<TSearchScopeResolver<RouteEnv>>>;\n try {\n scope = await resolve({ context });\n } catch (error) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.Forbidden,\n message: '[search] the search scope could not be resolved for this request',\n cause: error,\n });\n }\n\n if (scope === ScopeFilters.UNRESTRICTED) {\n return input;\n }\n\n if (scope === null || scope === undefined) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.Forbidden,\n message: '[search] no search scope for this request',\n });\n }\n\n if (input.mode === SearchModes.RAW) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: \"[search] mode 'raw' is not available on a scoped search controller\",\n });\n }\n\n if (input.engineParams !== undefined) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[search] engineParams is not available on a scoped search controller',\n });\n }\n\n const clientWhere = input.filter?.where;\n\n return {\n ...input,\n filter: {\n ...input.filter,\n where: clientWhere ? { and: [scope, clientWhere] } : scope,\n },\n } as TSearchInput;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ignis-connectors",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Datasource and repository connectors for the IGNIS framework: the engine-neutral relational and search tiers, plus Postgres, SQLite, PGlite, Typesense and Meilisearch behind sub-paths.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -121,16 +121,16 @@
121
121
  "prepublishOnly": "make rebuild"
122
122
  },
123
123
  "dependencies": {
124
- "@venizia/ignis-filter": "0.4.1",
125
- "@venizia/ignis-helpers": "0.4.1",
126
- "@venizia/ignis-inversion": "0.4.1",
127
- "@venizia/ignis-kernel": "0.4.1",
124
+ "@venizia/ignis-filter": "0.4.2",
125
+ "@venizia/ignis-helpers": "0.4.2",
126
+ "@venizia/ignis-inversion": "0.4.2",
127
+ "@venizia/ignis-kernel": "0.4.2",
128
128
  "zod": "^4.6.7"
129
129
  },
130
130
  "devDependencies": {
131
131
  "@types/bun": "^1.4.3",
132
132
  "@types/pg": "^8.23.1",
133
- "@venizia/dev-configs": "0.4.1",
133
+ "@venizia/dev-configs": "0.4.2",
134
134
  "eslint": "^10.13.0",
135
135
  "oxlint": "1.89.0",
136
136
  "oxlint-tsgolint": "7.0.2004",