@venizia/ignis-connectors 0.4.1 → 0.4.3

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 (170) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/common/scope-filter.d.ts +1 -1
  3. package/dist/cjs/common/scope-filter.d.ts.map +1 -1
  4. package/dist/cjs/common/scope-filter.js +33 -7
  5. package/dist/cjs/common/scope-filter.js.map +1 -1
  6. package/dist/cjs/http/common/constants.d.ts +11 -0
  7. package/dist/cjs/http/common/constants.d.ts.map +1 -0
  8. package/dist/cjs/http/common/constants.js +14 -0
  9. package/dist/cjs/http/common/constants.js.map +1 -0
  10. package/dist/cjs/http/common/wire.d.ts +2 -1
  11. package/dist/cjs/http/common/wire.d.ts.map +1 -1
  12. package/dist/cjs/http/common/wire.js +2 -1
  13. package/dist/cjs/http/common/wire.js.map +1 -1
  14. package/dist/cjs/http/datasource.d.ts +2 -1
  15. package/dist/cjs/http/datasource.d.ts.map +1 -1
  16. package/dist/cjs/http/datasource.js +2 -1
  17. package/dist/cjs/http/datasource.js.map +1 -1
  18. package/dist/cjs/http/index.d.ts +1 -0
  19. package/dist/cjs/http/index.d.ts.map +1 -1
  20. package/dist/cjs/http/index.js +1 -0
  21. package/dist/cjs/http/index.js.map +1 -1
  22. package/dist/cjs/http/repository.d.ts.map +1 -1
  23. package/dist/cjs/http/repository.js +5 -4
  24. package/dist/cjs/http/repository.js.map +1 -1
  25. package/dist/cjs/relational/core/repositories/common/constants.d.ts +11 -0
  26. package/dist/cjs/relational/core/repositories/common/constants.d.ts.map +1 -0
  27. package/dist/cjs/relational/core/repositories/common/constants.js +14 -0
  28. package/dist/cjs/relational/core/repositories/common/constants.js.map +1 -0
  29. package/dist/cjs/relational/core/repositories/common/index.d.ts +1 -0
  30. package/dist/cjs/relational/core/repositories/common/index.d.ts.map +1 -1
  31. package/dist/cjs/relational/core/repositories/common/index.js +1 -0
  32. package/dist/cjs/relational/core/repositories/common/index.js.map +1 -1
  33. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts +71 -0
  34. package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  35. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js +377 -0
  36. package/dist/cjs/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  37. package/dist/cjs/relational/core/repositories/core/base.d.ts +22 -4
  38. package/dist/cjs/relational/core/repositories/core/base.d.ts.map +1 -1
  39. package/dist/cjs/relational/core/repositories/core/base.js +49 -10
  40. package/dist/cjs/relational/core/repositories/core/base.js.map +1 -1
  41. package/dist/cjs/relational/core/repositories/core/persistable.d.ts.map +1 -1
  42. package/dist/cjs/relational/core/repositories/core/persistable.js +8 -1
  43. package/dist/cjs/relational/core/repositories/core/persistable.js.map +1 -1
  44. package/dist/cjs/relational/core/repositories/dialect/filter.d.ts +2 -2
  45. package/dist/cjs/relational/core/repositories/dialect/filter.js +3 -3
  46. package/dist/cjs/relational/core/repositories/dialect/filter.js.map +1 -1
  47. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  48. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  49. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js +14 -3
  50. package/dist/cjs/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  51. package/dist/cjs/relational/postgres/models/common/constants.d.ts +11 -0
  52. package/dist/cjs/relational/postgres/models/common/constants.d.ts.map +1 -0
  53. package/dist/cjs/relational/postgres/models/common/constants.js +14 -0
  54. package/dist/cjs/relational/postgres/models/common/constants.js.map +1 -0
  55. package/dist/cjs/relational/postgres/models/common/index.d.ts +1 -0
  56. package/dist/cjs/relational/postgres/models/common/index.d.ts.map +1 -1
  57. package/dist/cjs/relational/postgres/models/common/index.js +1 -0
  58. package/dist/cjs/relational/postgres/models/common/index.js.map +1 -1
  59. package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts +5 -3
  60. package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
  61. package/dist/cjs/relational/postgres/models/common/types/enrichers.js.map +1 -1
  62. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
  63. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
  64. package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
  65. package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
  66. package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
  67. package/dist/cjs/relational/sqlite/models/common/types/enrichers.js.map +1 -1
  68. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
  69. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
  70. package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
  71. package/dist/cjs/search/core/controllers/abstract.d.ts +4 -0
  72. package/dist/cjs/search/core/controllers/abstract.d.ts.map +1 -1
  73. package/dist/cjs/search/core/controllers/abstract.js +15 -1
  74. package/dist/cjs/search/core/controllers/abstract.js.map +1 -1
  75. package/dist/cjs/search/core/controllers/factory.d.ts +15 -1
  76. package/dist/cjs/search/core/controllers/factory.d.ts.map +1 -1
  77. package/dist/cjs/search/core/controllers/factory.js +7 -1
  78. package/dist/cjs/search/core/controllers/factory.js.map +1 -1
  79. package/dist/cjs/search/core/controllers/index.d.ts +1 -0
  80. package/dist/cjs/search/core/controllers/index.d.ts.map +1 -1
  81. package/dist/cjs/search/core/controllers/index.js.map +1 -1
  82. package/dist/cjs/search/core/controllers/scope.d.ts +28 -0
  83. package/dist/cjs/search/core/controllers/scope.d.ts.map +1 -0
  84. package/dist/cjs/search/core/controllers/scope.js +68 -0
  85. package/dist/cjs/search/core/controllers/scope.js.map +1 -0
  86. package/dist/esm/common/scope-filter.d.ts +1 -1
  87. package/dist/esm/common/scope-filter.d.ts.map +1 -1
  88. package/dist/esm/common/scope-filter.js +34 -8
  89. package/dist/esm/common/scope-filter.js.map +1 -1
  90. package/dist/esm/http/common/constants.d.ts +11 -0
  91. package/dist/esm/http/common/constants.d.ts.map +1 -0
  92. package/dist/esm/http/common/constants.js +10 -0
  93. package/dist/esm/http/common/constants.js.map +1 -0
  94. package/dist/esm/http/common/wire.d.ts +2 -1
  95. package/dist/esm/http/common/wire.d.ts.map +1 -1
  96. package/dist/esm/http/common/wire.js +2 -1
  97. package/dist/esm/http/common/wire.js.map +1 -1
  98. package/dist/esm/http/datasource.d.ts +2 -1
  99. package/dist/esm/http/datasource.d.ts.map +1 -1
  100. package/dist/esm/http/datasource.js +2 -1
  101. package/dist/esm/http/datasource.js.map +1 -1
  102. package/dist/esm/http/index.d.ts +1 -0
  103. package/dist/esm/http/index.d.ts.map +1 -1
  104. package/dist/esm/http/index.js +1 -0
  105. package/dist/esm/http/index.js.map +1 -1
  106. package/dist/esm/http/repository.d.ts.map +1 -1
  107. package/dist/esm/http/repository.js +5 -4
  108. package/dist/esm/http/repository.js.map +1 -1
  109. package/dist/esm/relational/core/repositories/common/constants.d.ts +11 -0
  110. package/dist/esm/relational/core/repositories/common/constants.d.ts.map +1 -0
  111. package/dist/esm/relational/core/repositories/common/constants.js +10 -0
  112. package/dist/esm/relational/core/repositories/common/constants.js.map +1 -0
  113. package/dist/esm/relational/core/repositories/common/index.d.ts +1 -0
  114. package/dist/esm/relational/core/repositories/common/index.d.ts.map +1 -1
  115. package/dist/esm/relational/core/repositories/common/index.js +1 -0
  116. package/dist/esm/relational/core/repositories/common/index.js.map +1 -1
  117. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +71 -0
  118. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -0
  119. package/dist/esm/relational/core/repositories/common/scope-write-guard.js +373 -0
  120. package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -0
  121. package/dist/esm/relational/core/repositories/core/base.d.ts +22 -4
  122. package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
  123. package/dist/esm/relational/core/repositories/core/base.js +49 -10
  124. package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
  125. package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +1 -1
  126. package/dist/esm/relational/core/repositories/core/persistable.js +8 -1
  127. package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
  128. package/dist/esm/relational/core/repositories/dialect/filter.d.ts +2 -2
  129. package/dist/esm/relational/core/repositories/dialect/filter.js +3 -3
  130. package/dist/esm/relational/core/repositories/dialect/filter.js.map +1 -1
  131. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +9 -0
  132. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +1 -1
  133. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js +15 -4
  134. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  135. package/dist/esm/relational/postgres/models/common/constants.d.ts +11 -0
  136. package/dist/esm/relational/postgres/models/common/constants.d.ts.map +1 -0
  137. package/dist/esm/relational/postgres/models/common/constants.js +10 -0
  138. package/dist/esm/relational/postgres/models/common/constants.js.map +1 -0
  139. package/dist/esm/relational/postgres/models/common/index.d.ts +1 -0
  140. package/dist/esm/relational/postgres/models/common/index.d.ts.map +1 -1
  141. package/dist/esm/relational/postgres/models/common/index.js +1 -0
  142. package/dist/esm/relational/postgres/models/common/index.js.map +1 -1
  143. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts +5 -3
  144. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
  145. package/dist/esm/relational/postgres/models/common/types/enrichers.js.map +1 -1
  146. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
  147. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
  148. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
  149. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
  150. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
  151. package/dist/esm/relational/sqlite/models/common/types/enrichers.js.map +1 -1
  152. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
  153. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
  154. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
  155. package/dist/esm/search/core/controllers/abstract.d.ts +4 -0
  156. package/dist/esm/search/core/controllers/abstract.d.ts.map +1 -1
  157. package/dist/esm/search/core/controllers/abstract.js +15 -1
  158. package/dist/esm/search/core/controllers/abstract.js.map +1 -1
  159. package/dist/esm/search/core/controllers/factory.d.ts +15 -1
  160. package/dist/esm/search/core/controllers/factory.d.ts.map +1 -1
  161. package/dist/esm/search/core/controllers/factory.js +7 -1
  162. package/dist/esm/search/core/controllers/factory.js.map +1 -1
  163. package/dist/esm/search/core/controllers/index.d.ts +1 -0
  164. package/dist/esm/search/core/controllers/index.d.ts.map +1 -1
  165. package/dist/esm/search/core/controllers/index.js.map +1 -1
  166. package/dist/esm/search/core/controllers/scope.d.ts +28 -0
  167. package/dist/esm/search/core/controllers/scope.d.ts.map +1 -0
  168. package/dist/esm/search/core/controllers/scope.js +64 -0
  169. package/dist/esm/search/core/controllers/scope.js.map +1 -0
  170. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"principal.enricher.js","sourceRoot":"","sources":["../../../../../../src/relational/postgres/models/enrichers/principal.enricher.ts"],"names":[],"mappings":";;;AAAA,sDAAuD;AAEvD,iDAAoD;AA4B7C,MAAM,2BAA2B,GAAG,CAMzC,IAAuF,EACV,EAAE;IAC/E,MAAM,EACJ,aAAa,GAAG,WAAW,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,GAAG,KAAK,EACpB,uBAAuB,GAAG,IAAI,GAC/B,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,GAAG,aAAa,MAAM,CAAC;IACzC,MAAM,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AO7B,UAA6B,EAC7B,IAAuF,EACvF,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;AACpC,CAAC,CAAC;AAZW,QAAA,eAAe,mBAY1B","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport type { PgIntegerBuilderInitial, PgTextBuilderInitial } from 'drizzle-orm/pg-core';\nimport { integer, text } from 'drizzle-orm/pg-core';\nimport type { TColumnDefinitions, TPrincipalEnricherOptions } from '../common/types';\nimport type { HasDefault, NotNull } from 'drizzle-orm';\n\n// A widened `boolean` flag takes the NOT NULL branch: the insert type then requires the value, which\n// is safe whichever way the flag resolves at runtime. With `isNullableDiscriminator: false` the type\n// column is required in the insert type even when a `defaultPolymorphic` gives it a runtime default.\ntype TPrincipalColumnDef<\n Discriminator extends string,\n IdType extends 'number' | 'string',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = (IdType extends 'number'\n ? {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? PgIntegerBuilderInitial<string>\n : NotNull<PgIntegerBuilderInitial<string>>;\n }\n : {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? PgTextBuilderInitial<string, [string, ...string[]]>\n : NotNull<PgTextBuilderInitial<string, [string, ...string[]]>>;\n }) & {\n [K in `${Discriminator}Type`]: [NullableDiscriminator] extends [true]\n ? HasDefault<PgTextBuilderInitial<string, [string, ...string[]]>>\n : NotNull<PgTextBuilderInitial<string, [string, ...string[]]>>;\n};\n\nexport const generatePrincipalColumnDefs = <\n Discriminator extends string = 'principal',\n IdType extends 'number' | 'string' = 'number',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n): TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator> => {\n const {\n discriminator = 'principal',\n defaultPolymorphic,\n polymorphicIdType,\n isNullableId = false,\n isNullableDiscriminator = true,\n } = opts;\n\n const typeField = `${discriminator}Type`;\n const idField = `${discriminator}Id`;\n const idColumnName = `${discriminator}_id`;\n\n // `false` is the only value that makes the type column required: it drops the '' default unless\n // the caller named one, so an insert without the type fails instead of storing ''.\n const typeColumn = text(`${discriminator}_type`);\n const typeDef =\n isNullableDiscriminator === false\n ? defaultPolymorphic === undefined\n ? typeColumn.notNull()\n : typeColumn.default(defaultPolymorphic).notNull()\n : typeColumn.default(defaultPolymorphic ?? '');\n\n switch (polymorphicIdType) {\n case 'number': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? integer(idColumnName) : integer(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n case 'string': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? text(idColumnName) : text(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n default: {\n throw getError({\n message: `[generatePrincipalColumnDefs] Invalid polymorphicIdType | value: ${polymorphicIdType} | valid: ['number', 'string']`,\n });\n }\n }\n};\n\nexport const enrichPrincipal = <\n ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions,\n Discriminator extends string = string,\n IdType extends 'number' | 'string' = 'number' | 'string',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n baseSchema: ColumnDefinitions,\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n) => {\n const defs = generatePrincipalColumnDefs(opts);\n return { ...baseSchema, ...defs };\n};\n"]}
1
+ {"version":3,"file":"principal.enricher.js","sourceRoot":"","sources":["../../../../../../src/relational/postgres/models/enrichers/principal.enricher.ts"],"names":[],"mappings":";;;AACA,sDAAuD;AAEvD,iDAAoD;AA4B7C,MAAM,2BAA2B,GAAG,CAMzC,IAAuF,EACV,EAAE;IAC/E,MAAM,EACJ,a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AAM,IAAA,eAAQ,EAAC;gBACb,OAAO,EAAE,oEAAoE,iBAAiB,gCAAgC;aAC/H,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAjDW,QAAA,2BAA2B,+BAiDtC;AAEK,MAAM,eAAe,GAAG,CAO7B,UAA6B,EAC7B,IAAuF,EACvF,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;AACpC,CAAC,CAAC;AAZW,QAAA,eAAe,mBAY1B","sourcesContent":["import type { TIdSchemaType } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { PgIntegerBuilderInitial, PgTextBuilderInitial } from 'drizzle-orm/pg-core';\nimport { integer, text } from 'drizzle-orm/pg-core';\nimport type { TColumnDefinitions, TPrincipalEnricherOptions } from '../common/types';\nimport type { HasDefault, NotNull } from 'drizzle-orm';\n\n// A widened `boolean` flag takes the NOT NULL branch: the insert type then requires the value, which\n// is safe whichever way the flag resolves at runtime. With `isNullableDiscriminator: false` the type\n// column is required in the insert type even when a `defaultPolymorphic` gives it a runtime default.\ntype TPrincipalColumnDef<\n Discriminator extends string,\n IdType extends TIdSchemaType,\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = (IdType extends 'number'\n ? {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? PgIntegerBuilderInitial<string>\n : NotNull<PgIntegerBuilderInitial<string>>;\n }\n : {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? PgTextBuilderInitial<string, [string, ...string[]]>\n : NotNull<PgTextBuilderInitial<string, [string, ...string[]]>>;\n }) & {\n [K in `${Discriminator}Type`]: [NullableDiscriminator] extends [true]\n ? HasDefault<PgTextBuilderInitial<string, [string, ...string[]]>>\n : NotNull<PgTextBuilderInitial<string, [string, ...string[]]>>;\n};\n\nexport const generatePrincipalColumnDefs = <\n Discriminator extends string = 'principal',\n IdType extends TIdSchemaType = 'number',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n): TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator> => {\n const {\n discriminator = 'principal',\n defaultPolymorphic,\n polymorphicIdType,\n isNullableId = false,\n isNullableDiscriminator = true,\n } = opts;\n\n const typeField = `${discriminator}Type`;\n const idField = `${discriminator}Id`;\n const idColumnName = `${discriminator}_id`;\n\n // `false` is the only value that makes the type column required: it drops the '' default unless\n // the caller named one, so an insert without the type fails instead of storing ''.\n const typeColumn = text(`${discriminator}_type`);\n const typeDef =\n isNullableDiscriminator === false\n ? defaultPolymorphic === undefined\n ? typeColumn.notNull()\n : typeColumn.default(defaultPolymorphic).notNull()\n : typeColumn.default(defaultPolymorphic ?? '');\n\n switch (polymorphicIdType) {\n case 'number': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? integer(idColumnName) : integer(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n case 'string': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? text(idColumnName) : text(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n default: {\n throw getError({\n message: `[generatePrincipalColumnDefs] Invalid polymorphicIdType | value: ${polymorphicIdType} | valid: ['number', 'string']`,\n });\n }\n }\n};\n\nexport const enrichPrincipal = <\n ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions,\n Discriminator extends string = string,\n IdType extends TIdSchemaType = TIdSchemaType,\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n baseSchema: ColumnDefinitions,\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n) => {\n const defs = generatePrincipalColumnDefs(opts);\n return { ...baseSchema, ...defs };\n};\n"]}
@@ -1,3 +1,4 @@
1
+ import type { TIdSchemaType } from '@venizia/ignis-kernel';
1
2
  export type TDataTypeEnricherOptions = {
2
3
  defaultValue: Partial<{
3
4
  dataType: string;
@@ -22,7 +23,7 @@ export type TIdEnricherOptions = {
22
23
  autoIncrement?: boolean;
23
24
  };
24
25
  };
25
- export type TPrincipalEnricherOptions<Discriminator extends string = string, PolymorphicIdType extends 'number' | 'string' = 'number' | 'string', Nullable extends boolean = false, NullableDiscriminator extends boolean = true> = {
26
+ export type TPrincipalEnricherOptions<Discriminator extends string = string, PolymorphicIdType extends TIdSchemaType = TIdSchemaType, Nullable extends boolean = false, NullableDiscriminator extends boolean = true> = {
26
27
  discriminator?: Discriminator;
27
28
  defaultPolymorphic?: string;
28
29
  polymorphicIdType: PolymorphicIdType;
@@ -57,7 +58,7 @@ export type TTzEnricherOptions = {
57
58
  };
58
59
  };
59
60
  export type TUserAuditColumnOpts = {
60
- dataType: 'string' | 'number';
61
+ dataType: TIdSchemaType;
61
62
  columnName: string;
62
63
  allowAnonymous?: boolean;
63
64
  };
@@ -1 +1 @@
1
- {"version":3,"file":"enrichers.d.ts","sourceRoot":"","sources":["../../../../../../../src/relational/sqlite/models/common/types/enrichers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,OAAO,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC,CAAC;CACJ,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EACC;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE,GAChD;QAAE,QAAQ,EAAE,QA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AM,CAAC,EAAE,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,GAAG;QAAE,MAAM,CAAC,EAAE,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"enrichers.js","sourceRoot":"","sources":["../../../../../../../src/relational/sqlite/models/common/types/enrichers.ts"],"names":[],"mappings":"","sourcesContent":["export type TDataTypeEnricherOptions = {\n defaultValue: Partial<{\n dataType: string;\n nValue: number;\n tValue: string;\n bValue: Buffer;\n jValue: object;\n boValue: boolean;\n }>;\n};\n\n/**\n * SQLite has no sequences or identity columns - an integer primary key is the table's rowid, which\n * the engine assigns. `autoIncrement` maps to `AUTOINCREMENT`, which additionally forbids reusing a\n * deleted row's id, matching Postgres `generatedAlwaysAsIdentity`.\n */\nexport type TIdEnricherOptions = {\n id?:\n | { dataType: 'string'; generator?: () => string }\n | { dataType: 'number'; autoIncrement?: boolean };\n};\n\nexport type TPrincipalEnricherOptions<\n Discriminator extends string = string,\n PolymorphicIdType extends 'number' | 'string' = 'number' | 'string',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = {\n discriminator?: Discriminator;\n defaultPolymorphic?: string;\n polymorphicIdType: PolymorphicIdType;\n isNullableId?: Nullable;\n /**\n * `true` (default) leaves the `{discriminator}Type` column nullable with a `''` default. `false`\n * makes it `NOT NULL` with no default, so an insert must give the type; a `defaultPolymorphic`\n * keeps that default.\n */\n isNullableDiscriminator?: NullableDiscriminator;\n};\n\n/**\n * No `withTimezone` twin of the Postgres options: with no `timestamptz`, every timestamp is an ISO\n * 8601 UTC string carrying its own offset. Omitting `enable` opts the column IN - only\n * `enable: false` drops it. Omitting the key keeps the default: `modified` on, `deleted` off.\n */\nexport type TTzEnricherOptions = {\n created?: { columnName: string };\n modified?: { enable: false } | { enable?: true; columnName: string };\n deleted?: { enable: false } | { enable?: true; columnName: string };\n};\n\nexport type TUserAuditColumnOpts = {\n dataType: 'string' | 'number';\n columnName: string;\n allowAnonymous?: boolean;\n};\n\nexport type TUserAuditEnricherOptions = {\n created?: TUserAuditColumnOpts;\n modified?: TUserAuditColumnOpts;\n};\n"]}
1
+ {"version":3,"file":"enrichers.js","sourceRoot":"","sources":["../../../../../../../src/relational/sqlite/models/common/types/enrichers.ts"],"names":[],"mappings":"","sourcesContent":["import type { TIdSchemaType } from '@venizia/ignis-kernel';\n\nexport type TDataTypeEnricherOptions = {\n defaultValue: Partial<{\n dataType: string;\n nValue: number;\n tValue: string;\n bValue: Buffer;\n jValue: object;\n boValue: boolean;\n }>;\n};\n\n/**\n * SQLite has no sequences or identity columns - an integer primary key is the table's rowid, which\n * the engine assigns. `autoIncrement` maps to `AUTOINCREMENT`, which additionally forbids reusing a\n * deleted row's id, matching Postgres `generatedAlwaysAsIdentity`.\n */\nexport type TIdEnricherOptions = {\n id?:\n | { dataType: 'string'; generator?: () => string }\n | { dataType: 'number'; autoIncrement?: boolean };\n};\n\nexport type TPrincipalEnricherOptions<\n Discriminator extends string = string,\n PolymorphicIdType extends TIdSchemaType = TIdSchemaType,\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = {\n discriminator?: Discriminator;\n defaultPolymorphic?: string;\n polymorphicIdType: PolymorphicIdType;\n isNullableId?: Nullable;\n /**\n * `true` (default) leaves the `{discriminator}Type` column nullable with a `''` default. `false`\n * makes it `NOT NULL` with no default, so an insert must give the type; a `defaultPolymorphic`\n * keeps that default.\n */\n isNullableDiscriminator?: NullableDiscriminator;\n};\n\n/**\n * No `withTimezone` twin of the Postgres options: with no `timestamptz`, every timestamp is an ISO\n * 8601 UTC string carrying its own offset. Omitting `enable` opts the column IN - only\n * `enable: false` drops it. Omitting the key keeps the default: `modified` on, `deleted` off.\n */\nexport type TTzEnricherOptions = {\n created?: { columnName: string };\n modified?: { enable: false } | { enable?: true; columnName: string };\n deleted?: { enable: false } | { enable?: true; columnName: string };\n};\n\nexport type TUserAuditColumnOpts = {\n dataType: TIdSchemaType;\n columnName: string;\n allowAnonymous?: boolean;\n};\n\nexport type TUserAuditEnricherOptions = {\n created?: TUserAuditColumnOpts;\n modified?: TUserAuditColumnOpts;\n};\n"]}
@@ -1,15 +1,16 @@
1
+ import type { TIdSchemaType } from '@venizia/ignis-kernel';
1
2
  import type { HasDefault, NotNull } from 'drizzle-orm';
2
3
  import type { SQLiteIntegerBuilderInitial, SQLiteTextBuilderInitial } from 'drizzle-orm/sqlite-core';
3
4
  import type { TColumnDefinitions, TPrincipalEnricherOptions } from '../common/types';
4
5
  type TSQLiteTextColumn = SQLiteTextBuilderInitial<string, [string, ...string[]], undefined>;
5
- type TPrincipalColumnDef<Discriminator extends string, IdType extends 'number' | 'string', Nullable extends boolean = false, NullableDiscriminator extends boolean = true> = (IdType extends 'number' ? {
6
+ type TPrincipalColumnDef<Discriminator extends string, IdType extends TIdSchemaType, Nullable extends boolean = false, NullableDiscriminator extends boolean = true> = (IdType extends 'number' ? {
6
7
  [K in `${Discriminator}Id`]: [Nullable] extends [true] ? SQLiteIntegerBuilderInitial<string> : NotNull<SQLiteIntegerBuilderInitial<string>>;
7
8
  } : {
8
9
  [K in `${Discriminator}Id`]: [Nullable] extends [true] ? TSQLiteTextColumn : NotNull<TSQLiteTextColumn>;
9
10
  }) & {
10
11
  [K in `${Discriminator}Type`]: [NullableDiscriminator] extends [true] ? HasDefault<TSQLiteTextColumn> : NotNull<TSQLiteTextColumn>;
11
12
  };
12
- export declare const generatePrincipalColumnDefs: <Discriminator extends string = "principal", IdType extends "number" | "string" = "number", Nullable extends boolean = false, NullableDiscriminator extends boolean = true>(opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>) => TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;
13
- export declare const enrichPrincipal: <ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions, Discriminator extends string = string, IdType extends "number" | "string" = "number" | "string", Nullable extends boolean = false, NullableDiscriminator extends boolean = true>(baseSchema: ColumnDefinitions, opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>) => ColumnDefinitions & (IdType extends "number" ? { [K in `${Discriminator}Id`]: [Nullable] extends [true] ? SQLiteIntegerBuilderInitial<string> : NotNull<SQLiteIntegerBuilderInitial<string>>; } : { [K_1 in `${Discriminator}Id`]: [Nullable] extends [true] ? TSQLiteTextColumn : NotNull<TSQLiteTextColumn>; }) & { [K_2 in `${Discriminator}Type`]: [NullableDiscriminator] extends [true] ? HasDefault<TSQLiteTextColumn> : NotNull<TSQLiteTextColumn>; };
13
+ export declare const generatePrincipalColumnDefs: <Discriminator extends string = "principal", IdType extends TIdSchemaType = "number", Nullable extends boolean = false, NullableDiscriminator extends boolean = true>(opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>) => TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;
14
+ export declare const enrichPrincipal: <ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions, Discriminator extends string = string, IdType extends TIdSchemaType = TIdSchemaType, Nullable extends boolean = false, NullableDiscriminator extends boolean = true>(baseSchema: ColumnDefinitions, opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>) => ColumnDefinitions & (IdType extends "number" ? { [K in `${Discriminator}Id`]: [Nullable] extends [true] ? SQLiteIntegerBuilderInitial<string> : NotNull<SQLiteIntegerBuilderInitial<string>>; } : { [K_1 in `${Discriminator}Id`]: [Nullable] extends [true] ? TSQLiteTextColumn : NotNull<TSQLiteTextColumn>; }) & { [K_2 in `${Discriminator}Type`]: [NullableDiscriminator] extends [true] ? HasDefault<TSQLiteTextColumn> : NotNull<TSQLiteTextColumn>; };
14
15
  export {};
15
16
  //# sourceMappingURL=principal.enricher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"principal.enricher.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/sqlite/models/enrichers/principal.enricher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EACV,2BAA2B,EAC3B,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAErF,KAAK,iBAAiB,GAAG,wBAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;AAK5F,KAAK,mBAAmB,CACtB,aAAa,SAAS,MAAM,EAC5B,MAAM,SAAS,QAAQ,GAAG,QAAQ,EAClC,QAAQ,SAAS,OAAO,GAAG,KAAK,EAChC,qBAAqB,SAAS,OAAO,GAAG,IAAI,IAC1C,CAAC,MAAM,SAAS,QAAQ,GACxB;KACG,CAAC,IAAI,GAAG,aAAa,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAClD,2BAA2B,CAAC,MAAM,CAAC,GACnC,OAAO,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;CACjD,GACD;KACG,CAAC,IAAI,GAAG,aAAa,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAClD,iBAAiB,GACjB,OAAO,CAAC,iBAAiB,CAAC;CAC/B,CAAC,GAAG;KACN,CAAC,IAAI,GAAG,aAAa,MAAM,G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AG,MAAM,EACrC,MAAM,SAAS,aAAa,GAAG,aAAa,EAC5C,QAAQ,SAAS,OAAO,GAAG,KAAK,EAChC,qBAAqB,SAAS,OAAO,GAAG,IAAI,EAE5C,YAAY,iBAAiB,EAC7B,MAAM,yBAAyB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,CAAC,uDA3ElF,CAAC,0YAgFP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"principal.enricher.js","sourceRoot":"","sources":["../../../../../../src/relational/sqlite/models/enrichers/principal.enricher.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,sDAAuD;AACvD,0DAAqD;AAMrD,yDAAwD;AA6BjD,MAAM,2BAA2B,GAAG,CAMzC,IAAuF,EACV,EAAE;IAC/E,MAAM,EACJ,aAAa,GAAG,WAAW,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,GAAG,KAAK,EACpB,uBAAuB,GAAG,IAAI,GAC/B,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,GAAG,aAAa,MAAM,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,aAAa,IAAI,CAAC;IACrC,MAAM,YAAY,GAAG,GAAG,aAAa,KAAK,CAAC;IAE3C,gGAAgG;IAChG,mFAAmF;IACnF,MAAM,UAAU,GAAG,IAAA,kBAAI,EAAC,GAAG,aAAa,OAAO,CAAC,CAAC;IACjD,MAAM,OAAO,GACX,uBAAuB,KAAK,KAAK;QAC/B,CAAC,CAAC,kBAAkB,KAAK,SAAS;YAChC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE;YACtB,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,OAAO,EAAE;QACpD,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;IAEnD,QAAQ,iBAAiB,EAAE,CAAC;QAC1B,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO;gBACL,CAAC,SAAS,CAAC,EAAE,OAAO;gBACpB,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,IAAA,qBAAO,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAO,EAAC,YAAY,CAAC,CAAC,OAAO,EAAE;aACH,CAAC;QACnF,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO;gBACL,CAAC,SAAS,CAAC,EAAE,OAAO;gBACpB,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,IAAA,kBAAI,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAI,EAAC,YAAY,CAAC,CAAC,OAAO,EAAE;aACG,CAAC;QACnF,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,IAAA,eAAQ,EAAC;gBACb,UAAU,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc;gBAChD,WAAW,EAAE,6BAAc,CAAC,aAAa;gBACzC,OAAO,EAAE,oEAAoE,iBAAiB,gCAAgC;aAC/H,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAnDW,QAAA,2BAA2B,+BAmDtC;AAEK,MAAM,eAAe,GAAG,CAO7B,UAA6B,EAC7B,IAAuF,EACvF,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;AACpC,CAAC,CAAC;AAbW,QAAA,eAAe,mBAa1B","sourcesContent":["import { CoreErrorCodes } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { HasDefault, NotNull } from 'drizzle-orm';\nimport type {\n SQLiteIntegerBuilderInitial,\n SQLiteTextBuilderInitial,\n} from 'drizzle-orm/sqlite-core';\nimport { integer, text } from 'drizzle-orm/sqlite-core';\nimport type { TColumnDefinitions, TPrincipalEnricherOptions } from '../common/types';\n\ntype TSQLiteTextColumn = SQLiteTextBuilderInitial<string, [string, ...string[]], undefined>;\n\n// A widened `boolean` flag takes the NOT NULL branch: the insert type then requires the value, which\n// is safe whichever way the flag resolves at runtime. With `isNullableDiscriminator: false` the type\n// column is required in the insert type even when a `defaultPolymorphic` gives it a runtime default.\ntype TPrincipalColumnDef<\n Discriminator extends string,\n IdType extends 'number' | 'string',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = (IdType extends 'number'\n ? {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? SQLiteIntegerBuilderInitial<string>\n : NotNull<SQLiteIntegerBuilderInitial<string>>;\n }\n : {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? TSQLiteTextColumn\n : NotNull<TSQLiteTextColumn>;\n }) & {\n [K in `${Discriminator}Type`]: [NullableDiscriminator] extends [true]\n ? HasDefault<TSQLiteTextColumn>\n : NotNull<TSQLiteTextColumn>;\n};\n\nexport const generatePrincipalColumnDefs = <\n Discriminator extends string = 'principal',\n IdType extends 'number' | 'string' = 'number',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n): TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator> => {\n const {\n discriminator = 'principal',\n defaultPolymorphic,\n polymorphicIdType,\n isNullableId = false,\n isNullableDiscriminator = true,\n } = opts;\n\n const typeField = `${discriminator}Type`;\n const idField = `${discriminator}Id`;\n const idColumnName = `${discriminator}_id`;\n\n // `false` is the only value that makes the type column required: it drops the '' default unless\n // the caller named one, so an insert without the type fails instead of storing ''.\n const typeColumn = text(`${discriminator}_type`);\n const typeDef =\n isNullableDiscriminator === false\n ? defaultPolymorphic === undefined\n ? typeColumn.notNull()\n : typeColumn.default(defaultPolymorphic).notNull()\n : typeColumn.default(defaultPolymorphic ?? '');\n\n switch (polymorphicIdType) {\n case 'number': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? integer(idColumnName) : integer(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n case 'string': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? text(idColumnName) : text(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.NotImplemented,\n messageCode: CoreErrorCodes.NOT_SUPPORTED,\n message: `[generatePrincipalColumnDefs] Invalid polymorphicIdType | value: ${polymorphicIdType} | valid: ['number', 'string']`,\n });\n }\n }\n};\n\nexport const enrichPrincipal = <\n ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions,\n Discriminator extends string = string,\n IdType extends 'number' | 'string' = 'number' | 'string',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n baseSchema: ColumnDefinitions,\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n) => {\n const defs = generatePrincipalColumnDefs(opts);\n\n return { ...baseSchema, ...defs };\n};\n"]}
1
+ {"version":3,"file":"principal.enricher.js","sourceRoot":"","sources":["../../../../../../src/relational/sqlite/models/enrichers/principal.enricher.ts"],"names":[],"mappings":";;;AACA,wDAAuD;AACvD,sDAAuD;AACvD,0DAAqD;AAMrD,yDAAwD;AA6BjD,MAAM,2BAA2B,GAAG,CAMzC,IAAuF,EACV,EAAE;IAC/E,MAAM,EACJ,aAAa,GAAG,WAAW,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,GAAG,KAAK,EACpB,uBAAuB,GAAG,IAAI,GAC/B,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,GAAG,aAAa,MAAM,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,aAAa,IAAI,CAAC;IACrC,MAAM,YAAY,GAAG,GAAG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2B,+BAmDtC;AAEK,MAAM,eAAe,GAAG,CAO7B,UAA6B,EAC7B,IAAuF,EACvF,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;AACpC,CAAC,CAAC;AAbW,QAAA,eAAe,mBAa1B","sourcesContent":["import type { TIdSchemaType } from '@venizia/ignis-kernel';\nimport { CoreErrorCodes } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { HasDefault, NotNull } from 'drizzle-orm';\nimport type {\n SQLiteIntegerBuilderInitial,\n SQLiteTextBuilderInitial,\n} from 'drizzle-orm/sqlite-core';\nimport { integer, text } from 'drizzle-orm/sqlite-core';\nimport type { TColumnDefinitions, TPrincipalEnricherOptions } from '../common/types';\n\ntype TSQLiteTextColumn = SQLiteTextBuilderInitial<string, [string, ...string[]], undefined>;\n\n// A widened `boolean` flag takes the NOT NULL branch: the insert type then requires the value, which\n// is safe whichever way the flag resolves at runtime. With `isNullableDiscriminator: false` the type\n// column is required in the insert type even when a `defaultPolymorphic` gives it a runtime default.\ntype TPrincipalColumnDef<\n Discriminator extends string,\n IdType extends TIdSchemaType,\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n> = (IdType extends 'number'\n ? {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? SQLiteIntegerBuilderInitial<string>\n : NotNull<SQLiteIntegerBuilderInitial<string>>;\n }\n : {\n [K in `${Discriminator}Id`]: [Nullable] extends [true]\n ? TSQLiteTextColumn\n : NotNull<TSQLiteTextColumn>;\n }) & {\n [K in `${Discriminator}Type`]: [NullableDiscriminator] extends [true]\n ? HasDefault<TSQLiteTextColumn>\n : NotNull<TSQLiteTextColumn>;\n};\n\nexport const generatePrincipalColumnDefs = <\n Discriminator extends string = 'principal',\n IdType extends TIdSchemaType = 'number',\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n): TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator> => {\n const {\n discriminator = 'principal',\n defaultPolymorphic,\n polymorphicIdType,\n isNullableId = false,\n isNullableDiscriminator = true,\n } = opts;\n\n const typeField = `${discriminator}Type`;\n const idField = `${discriminator}Id`;\n const idColumnName = `${discriminator}_id`;\n\n // `false` is the only value that makes the type column required: it drops the '' default unless\n // the caller named one, so an insert without the type fails instead of storing ''.\n const typeColumn = text(`${discriminator}_type`);\n const typeDef =\n isNullableDiscriminator === false\n ? defaultPolymorphic === undefined\n ? typeColumn.notNull()\n : typeColumn.default(defaultPolymorphic).notNull()\n : typeColumn.default(defaultPolymorphic ?? '');\n\n switch (polymorphicIdType) {\n case 'number': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? integer(idColumnName) : integer(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n case 'string': {\n return {\n [typeField]: typeDef,\n [idField]: isNullableId ? text(idColumnName) : text(idColumnName).notNull(),\n } as TPrincipalColumnDef<Discriminator, IdType, Nullable, NullableDiscriminator>;\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.NotImplemented,\n messageCode: CoreErrorCodes.NOT_SUPPORTED,\n message: `[generatePrincipalColumnDefs] Invalid polymorphicIdType | value: ${polymorphicIdType} | valid: ['number', 'string']`,\n });\n }\n }\n};\n\nexport const enrichPrincipal = <\n ColumnDefinitions extends TColumnDefinitions = TColumnDefinitions,\n Discriminator extends string = string,\n IdType extends TIdSchemaType = TIdSchemaType,\n Nullable extends boolean = false,\n NullableDiscriminator extends boolean = true,\n>(\n baseSchema: ColumnDefinitions,\n opts: TPrincipalEnricherOptions<Discriminator, IdType, Nullable, NullableDiscriminator>,\n) => {\n const defs = generatePrincipalColumnDefs(opts);\n\n return { ...baseSchema, ...defs };\n};\n"]}
@@ -5,15 +5,19 @@ import type { TAnyObjectSchema } from '@venizia/ignis-kernel';
5
5
  import type { AnyType } from '@venizia/ignis-helpers/common';
6
6
  import type { Env, Schema } from 'hono';
7
7
  import type { ReadableSearchRepository } from '../repositories/core/readable';
8
+ import type { TSearchScopeResolver } from './scope';
8
9
  /** Base tier of a generated search controller: the repository handle plus the search / multi-search verbs; SearchControllerFactory returns a thin subclass that only builds route configs and wires them. */
9
10
  export declare abstract class AbstractSearchController<TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>, RouteEnv extends Env = Env, RouteSchema extends Schema = {}, BasePath extends string = '/', ConfigurableOptions extends object = {}, TDataObject extends object = TEntityDataObject<TEntity>> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {
10
11
  repository: ReadableSearchRepository<TDataObject>;
12
+ searchScope?: TSearchScopeResolver<RouteEnv>;
11
13
  constructor(opts: {
12
14
  scope: string;
13
15
  path: string;
14
16
  isStrict?: boolean;
15
17
  repository: ReadableSearchRepository<TDataObject>;
16
18
  definitions: AnyType;
19
+ /** Per-request search scope; see {@link TSearchScopeResolver}. */
20
+ searchScope?: TSearchScopeResolver<RouteEnv>;
17
21
  });
18
22
  /** POST /search - single-collection keyword/semantic/hybrid/raw search. Carries the list headers of every IGNIS list endpoint; the body keeps `{ found, isFoundExact, hits }` because `isFoundExact` has no place in a `{ count, data }` envelope, and it is the only carrier of "found is an estimate". */
19
23
  search(opts: {
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/abstract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC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,CAAC,CAAC;KAC9C;IAOD,4SAA4S;IACtS,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;KAAE;IA2BvD,sFAAsF;IAChF,WAAW,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;KAAE;CAqB7D"}
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractSearchController = void 0;
4
4
  const ignis_kernel_1 = require("@venizia/ignis-kernel");
5
+ const core_1 = require("@venizia/ignis-helpers/core");
5
6
  const common_1 = require("@venizia/ignis-helpers/common");
6
7
  const common_2 = require("../repositories/common");
8
+ const scope_1 = require("./scope");
7
9
  /** Where the page starts, for `Content-Range`. Friendly modes carry `filter.skip` or `filter.offset`; raw mode carries the engine's own `offset`, or a 1-based `page` with `per_page`/`perPage`. A raw request that names a page but no page size is measured against this page's hit count, so only its last page can be off. */
8
10
  const resolveSearchStart = (opts) => {
9
11
  const { input, hitCount } = opts;
@@ -29,12 +31,16 @@ class AbstractSearchController extends ignis_kernel_1.BaseRestController {
29
31
  constructor(opts) {
30
32
  super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });
31
33
  this.repository = opts.repository;
34
+ this.searchScope = opts.searchScope;
32
35
  this.definitions = opts.definitions;
33
36
  }
34
37
  /** POST /search - single-collection keyword/semantic/hybrid/raw search. Carries the list headers of every IGNIS list endpoint; the body keeps `{ found, isFoundExact, hits }` because `isFoundExact` has no place in a `{ count, data }` envelope, and it is the only carrier of "found is an estimate". */
35
38
  async search(opts) {
36
39
  const { context } = opts;
37
- const input = context.req.valid('json');
40
+ const body = context.req.valid('json');
41
+ const input = this.searchScope
42
+ ? await (0, scope_1.applySearchScope)({ resolve: this.searchScope, context, input: body })
43
+ : body;
38
44
  const rs = await this.measure({
39
45
  scope: 'search',
40
46
  args: input,
@@ -55,6 +61,14 @@ class AbstractSearchController extends ignis_kernel_1.BaseRestController {
55
61
  /** POST /multi-search - cross-collection search, forwarded verbatim to the engine. */
56
62
  async multiSearch(opts) {
57
63
  const { context } = opts;
64
+ // A multi-search entry carries the engine's own `filterBy` string, which a `where` scope cannot
65
+ // be ANDed into: a scoped controller does not serve it.
66
+ if (this.searchScope) {
67
+ throw (0, core_1.getError)({
68
+ statusCode: common_1.HTTP.ResultCodes.RS_4.BadRequest,
69
+ message: '[multiSearch] multi-search is not available on a scoped search controller',
70
+ });
71
+ }
58
72
  const input = context.req.valid('json');
59
73
  const rs = await this.measure({
60
74
  scope: 'multiSearch',
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/abstract.ts"],"names":[],"mappings":";;;AACA,wDAA2E;AAI3E,0DAAqD;AAGrD,8DAAgE;AAGhE,kUAAkU;AAClU,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE;IACrF,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAEjC,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAW,CAAC,GAAG,EAAE,CAAC;QACnC,mFAAmF;QACnF,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,2FAA2F;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CA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,CAAC;QACtE,IAAI,CAAC,cAAc,CAAC;YAClB,OAAO;YACP,KAAK,EAAE,IAAA,6BAAc,EAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC;YACrF,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM;SACtB,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,sFAAsF;IACtF,KAAK,CAAC,WAAW,CAAC,IAA0C;QAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAoB,MAAM,CAAC,CAAC;QAE3D,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC;SAC/C,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AA5DD,4DA4DC","sourcesContent":["import type { TEntityDataObject, TRouteContext } from '@venizia/ignis-kernel';\nimport { BaseRestController, buildDataRange } from '@venizia/ignis-kernel';\nimport type { AbstractEntity } from '@venizia/ignis-kernel';\nimport type { TAnyObjectSchema } from '@venizia/ignis-kernel';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TMultiSearchInput, TSearchInput } from '@/search/core/repositories/common';\nimport { SearchModes } from '@/search/core/repositories/common';\nimport type { ReadableSearchRepository } from '../repositories/core/readable';\n\n/** Where the page starts, for `Content-Range`. Friendly modes carry `filter.skip` or `filter.offset`; raw mode carries the engine's own `offset`, or a 1-based `page` with `per_page`/`perPage`. A raw request that names a page but no page size is measured against this page's hit count, so only its last page can be off. */\nconst resolveSearchStart = (opts: { input: TSearchInput; hitCount: number }): number => {\n const { input, hitCount } = opts;\n\n if (input.mode !== SearchModes.RAW) {\n // Same precedence as buildDataRange: the repository filter carries skip or offset.\n return input.filter?.skip ?? input.filter?.offset ?? 0;\n }\n\n // Engine wire names are read through string keys only; `params` is an untyped passthrough.\n const params = input.params;\n const offset = params['offset'];\n if (typeof offset === 'number') {\n return offset;\n }\n\n const page = params['page'];\n if (typeof page !== 'number' || page < 1) {\n return 0;\n }\n\n const pageSize = params['per_page'] ?? params['perPage'];\n return (page - 1) * (typeof pageSize === 'number' ? pageSize : hitCount);\n};\n\n/** Base tier of a generated search controller: the repository handle plus the search / multi-search verbs; SearchControllerFactory returns a thin subclass that only builds route configs and wires them. */\nexport abstract class AbstractSearchController<\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> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: ReadableSearchRepository<TDataObject>;\n\n constructor(opts: {\n scope: string;\n path: string;\n isStrict?: boolean;\n repository: ReadableSearchRepository<TDataObject>;\n definitions: AnyType;\n }) {\n super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.definitions = opts.definitions;\n }\n\n /** POST /search - single-collection keyword/semantic/hybrid/raw search. Carries the list headers of every IGNIS list endpoint; the body keeps `{ found, isFoundExact, hits }` because `isFoundExact` has no place in a `{ count, data }` envelope, and it is the only carrier of \"found is an estimate\". */\n async search(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const input = context.req.valid<TSearchInput>('json');\n\n const rs = await this.measure({\n scope: 'search',\n args: input,\n task: async () => {\n // `isFoundExact` travels to the caller so an engine whose `found` is an estimate never looks exhaustive across the HTTP boundary.\n const { found, isFoundExact, hits } = await this.repository.search(input);\n return { found, isFoundExact, hits: hits ?? [] };\n },\n });\n\n const start = resolveSearchStart({ input, hitCount: rs.hits.length });\n this.setListHeaders({\n context,\n range: buildDataRange({ offset: start, dataLength: rs.hits.length, total: rs.found }),\n count: rs.hits.length,\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** POST /multi-search - cross-collection search, forwarded verbatim to the engine. */\n async multiSearch(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const input = context.req.valid<TMultiSearchInput>('json');\n\n const rs = await this.measure({\n scope: 'multiSearch',\n args: input,\n task: () => this.repository.multiSearch(input),\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
1
+ {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/abstract.ts"],"names":[],"mappings":";;;AACA,wDAA2E;AAI3E,sDAAuD;AACvD,0DAAqD;AAGrD,8DAAgE;AAEhE,mCAA2C;AAG3C,kUAAkU;AAClU,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE;IACrF,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAEjC,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAW,CAAC,GAAG,EAAE,CAAC;QACnC,mFAAmF;QACnF,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,2FAA2F;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAA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AC;QACL,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAoB,MAAM,CAAC,CAAC;QAE3D,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC;SAC/C,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AA5ED,4DA4EC","sourcesContent":["import type { TEntityDataObject, TRouteContext } from '@venizia/ignis-kernel';\nimport { BaseRestController, buildDataRange } from '@venizia/ignis-kernel';\nimport type { AbstractEntity } from '@venizia/ignis-kernel';\nimport type { TAnyObjectSchema } from '@venizia/ignis-kernel';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TMultiSearchInput, TSearchInput } from '@/search/core/repositories/common';\nimport { SearchModes } from '@/search/core/repositories/common';\nimport type { ReadableSearchRepository } from '../repositories/core/readable';\nimport { applySearchScope } from './scope';\nimport type { TSearchScopeResolver } from './scope';\n\n/** Where the page starts, for `Content-Range`. Friendly modes carry `filter.skip` or `filter.offset`; raw mode carries the engine's own `offset`, or a 1-based `page` with `per_page`/`perPage`. A raw request that names a page but no page size is measured against this page's hit count, so only its last page can be off. */\nconst resolveSearchStart = (opts: { input: TSearchInput; hitCount: number }): number => {\n const { input, hitCount } = opts;\n\n if (input.mode !== SearchModes.RAW) {\n // Same precedence as buildDataRange: the repository filter carries skip or offset.\n return input.filter?.skip ?? input.filter?.offset ?? 0;\n }\n\n // Engine wire names are read through string keys only; `params` is an untyped passthrough.\n const params = input.params;\n const offset = params['offset'];\n if (typeof offset === 'number') {\n return offset;\n }\n\n const page = params['page'];\n if (typeof page !== 'number' || page < 1) {\n return 0;\n }\n\n const pageSize = params['per_page'] ?? params['perPage'];\n return (page - 1) * (typeof pageSize === 'number' ? pageSize : hitCount);\n};\n\n/** Base tier of a generated search controller: the repository handle plus the search / multi-search verbs; SearchControllerFactory returns a thin subclass that only builds route configs and wires them. */\nexport abstract class AbstractSearchController<\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> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: ReadableSearchRepository<TDataObject>;\n searchScope?: TSearchScopeResolver<RouteEnv>;\n\n constructor(opts: {\n scope: string;\n path: string;\n isStrict?: boolean;\n repository: ReadableSearchRepository<TDataObject>;\n definitions: AnyType;\n /** Per-request search scope; see {@link TSearchScopeResolver}. */\n searchScope?: TSearchScopeResolver<RouteEnv>;\n }) {\n super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.searchScope = opts.searchScope;\n this.definitions = opts.definitions;\n }\n\n /** POST /search - single-collection keyword/semantic/hybrid/raw search. Carries the list headers of every IGNIS list endpoint; the body keeps `{ found, isFoundExact, hits }` because `isFoundExact` has no place in a `{ count, data }` envelope, and it is the only carrier of \"found is an estimate\". */\n async search(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const body = context.req.valid<TSearchInput>('json');\n const input = this.searchScope\n ? await applySearchScope({ resolve: this.searchScope, context, input: body })\n : body;\n\n const rs = await this.measure({\n scope: 'search',\n args: input,\n task: async () => {\n // `isFoundExact` travels to the caller so an engine whose `found` is an estimate never looks exhaustive across the HTTP boundary.\n const { found, isFoundExact, hits } = await this.repository.search(input);\n return { found, isFoundExact, hits: hits ?? [] };\n },\n });\n\n const start = resolveSearchStart({ input, hitCount: rs.hits.length });\n this.setListHeaders({\n context,\n range: buildDataRange({ offset: start, dataLength: rs.hits.length, total: rs.found }),\n count: rs.hits.length,\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** POST /multi-search - cross-collection search, forwarded verbatim to the engine. */\n async multiSearch(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n\n // A multi-search entry carries the engine's own `filterBy` string, which a `where` scope cannot\n // be ANDed into: a scoped controller does not serve it.\n if (this.searchScope) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[multiSearch] multi-search is not available on a scoped search controller',\n });\n }\n const input = context.req.valid<TMultiSearchInput>('json');\n\n const rs = await this.measure({\n scope: 'multiSearch',\n args: input,\n task: () => this.repository.multiSearch(input),\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
@@ -7,6 +7,7 @@ import type { TClass, TResolver, ValueOrPromise } from '@venizia/ignis-helpers/c
7
7
  import { BaseHelper } from '@venizia/ignis-helpers/core';
8
8
  import type { Env, Schema } from 'hono';
9
9
  import type { ReadableSearchRepository } from '../repositories/core/readable';
10
+ import type { TSearchScopeResolver } from './scope';
10
11
  /** Per-route enable/disable switches for the generated search controller. */
11
12
  export interface ISearchCustomizableRoutes {
12
13
  search?: {
@@ -37,6 +38,18 @@ export interface ISearchControllerOptions<TEntity extends AbstractEntity<TAnyObj
37
38
  authorize?: IAuthorizationSpec | IAuthorizationSpec[];
38
39
  /** Per-route enable/disable configuration. */
39
40
  routes?: ISearchCustomizableRoutes;
41
+ /**
42
+ * A function of the request context returning the filter this caller may search within. It is
43
+ * ANDed into `input.filter.where` on the server: the client's own `where` can narrow it, never
44
+ * widen or remove it. Fails closed - a scope that is null, undefined or throws refuses the
45
+ * request with 403. Return `ScopeFilters.UNRESTRICTED` to apply none for a trusted caller.
46
+ *
47
+ * `raw` mode and `engineParams` hand the engine its own wire parameters, and a multi-search entry
48
+ * carries a raw `filterBy`; none can take a scope, so a scoped controller refuses `raw` and
49
+ * `engineParams` (400) and must disable the multi-search route (`routes.multiSearch.enabled:
50
+ * false`), which `defineSearchController` requires.
51
+ */
52
+ scope?: TSearchScopeResolver;
40
53
  }
41
54
  /** Factory for generating turnkey search controllers (single-collection + cross-collection) from entity definitions. */
42
55
  export declare class SearchControllerFactory extends BaseHelper {
@@ -47,6 +60,7 @@ export declare class SearchControllerFactory extends BaseHelper {
47
60
  /** Registers the search + multiSearch route handlers, honoring per-route enable flags. */
48
61
  binding(): ValueOrPromise<void>;
49
62
  repository: ReadableSearchRepository<TDataObject, import("..").AbstractSearchDataSource<{}>>;
63
+ searchScope?: TSearchScopeResolver<RouteEnv> | undefined;
50
64
  search(opts: {
51
65
  context: import("@venizia/ignis-kernel").TRouteContext<RouteEnv>;
52
66
  }): Promise<import("@venizia/ignis-kernel").TJsonResponse<unknown, 200>>;
@@ -165,7 +179,7 @@ export declare class SearchControllerFactory extends BaseHelper {
165
179
  definitions: Record<string, import("@venizia/ignis-kernel").IAuthRouteConfig>;
166
180
  getRouter(): import("@hono/zod-openapi").OpenAPIHono<RouteEnv, RouteSchema, BasePath>;
167
181
  registerRoutesFromRegistry(opts?: {
168
- paths?: "static" | "param" | "all";
182
+ paths?: import("@venizia/ignis-kernel").TRoutePathScope;
169
183
  }): void;
170
184
  configure(opts?: ConfigurableOptions | undefined): Promise<import("@hono/zod-openapi").OpenAPIHono<RouteEnv, RouteSchema, BasePath>>;
171
185
  buildRouteMiddlewares<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig>(opts: {
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE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AwB,SAAQ,UAAU;;IAKrD,wLAAwL;IACxL,MAAM,CAAC,sBAAsB,CAC3B,OAAO,SAAS,cAAc,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,EACnF,QAAQ,SAAS,GAAG,GAAG,GAAG,EAC1B,WAAW,SAAS,MAAM,GAAG,EAAE,EAC/B,QAAQ,SAAS,MAAM,GAAG,GAAG,EAC7B,mBAAmB,SAAS,MAAM,GAAG,EAAE,EACvC,WAAW,SAAS,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,EACvD,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC;yBA8BhB,wBAAwB,CAAC,WAAW,CAAC;YAW7D,0FAA0F;uBACtE,cAAc,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA5FwE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0HtH"}
@@ -13,13 +13,18 @@ class SearchControllerFactory extends core_1.BaseHelper {
13
13
  }
14
14
  /** Creates a search controller with two endpoints: `POST {basePath}/search` via `repository.search()`, and `POST {basePath}/multi-search` via `repository.dataSource.multiSearch()`. */
15
15
  static defineSearchController(defOpts) {
16
- const { controller, entity, authenticate, authorize, routes } = defOpts;
16
+ const { controller, entity, authenticate, authorize, routes, scope } = defOpts;
17
17
  const { name, basePath = 'unknown_path', isStrict = true } = controller;
18
18
  if (!basePath || basePath === 'unknown_path') {
19
19
  throw (0, core_1.getError)({
20
20
  message: `[defineSearchController] Invalid controller basePath | name: ${name} | basePath: ${basePath}`,
21
21
  });
22
22
  }
23
+ if (scope && routes?.multiSearch?.enabled !== false) {
24
+ throw (0, core_1.getError)({
25
+ message: `[defineSearchController] A scoped search controller cannot serve multi-search | name: ${name} | set routes.multiSearch.enabled to false`,
26
+ });
27
+ }
23
28
  const entityClass = (0, ignis_inversion_1.isClass)(entity) ? entity : entity();
24
29
  const entityInstance = new entityClass();
25
30
  const selectSchema = entityInstance.getSchema({ type: ignis_kernel_1.SchemaTypes.SELECT });
@@ -32,6 +37,7 @@ class SearchControllerFactory extends core_1.BaseHelper {
32
37
  isStrict,
33
38
  repository,
34
39
  definitions: routeDefinitions,
40
+ searchScope: scope,
35
41
  });
36
42
  }
37
43
  /** 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,wDAAwF;AAKxF,sDAAmE;AACnE,8DAAmD;AAGnD,yCAAsD;AACtD,6CAAwD;AAmCxD,wHAAwH;AACxH,MAAa,uBAAwB,SAAQ,iBAAU;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,IAAA,eAAQ,EAAC;gBACb,OAAO,EAAE,gEAAgE,IAAI,gBAAgB,QAAQ,EAAE;aACxG,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,IAAA,yBAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACxD,MAAM,cAAc,GAAG,IAAI,WAAW,EAAE,CAAC;QAEzC,MAAM,YAAY,GAA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IAAA,iDAAkC,EAAC;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;AA9ED,0DA8EC","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,wDAAwF;AAKxF,sDAAmE;AACnE,8DAAmD;AAGnD,yCAAsD;AAEtD,6CAAwD;AAgDxD,wHAAwH;AACxH,MAAa,uBAAwB,SAAQ,iBAAU;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,IAAA,eAAQ,EAAC;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,IAAA,eAAQ,EAAC;gBACb,OAAO,EAAE,yFAAyF,IAAI,4CAA4C;aACnJ,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,IAAA,yBAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACxD,M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EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACpF,IAAA,iDAAkC,EAAC;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;AArFD,0DAqFC","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"]}
@@ -1,4 +1,5 @@
1
1
  export * from './abstract';
2
2
  export * from './definition';
3
3
  export * from './factory';
4
+ export type { TSearchScopeResolver } from './scope';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,4CAA0B","sourcesContent":["export * from './abstract';\nexport * from './definition';\nexport * from './factory';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,4CAA0B","sourcesContent":["export * from './abstract';\nexport * from './definition';\nexport * from './factory';\nexport type { TSearchScopeResolver } from './scope';\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';
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,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applySearchScope = void 0;
4
+ const common_1 = require("@venizia/ignis-helpers/common");
5
+ const core_1 = require("@venizia/ignis-helpers/core");
6
+ const ignis_kernel_1 = require("@venizia/ignis-kernel");
7
+ const common_2 = require("../repositories/common");
8
+ const refuse = (opts) => {
9
+ return (0, core_1.getError)({
10
+ statusCode: opts.statusCode,
11
+ message: opts.message,
12
+ cause: opts.cause,
13
+ });
14
+ };
15
+ /**
16
+ * ANDs the resolved scope into `input.filter.where`, on the server, after the body was validated.
17
+ * The client's own `where` is kept inside the AND, so it can narrow the scope and never widen it.
18
+ *
19
+ * Fails closed:
20
+ * - a scope that is null, undefined, or throws refuses the request (403);
21
+ * - `raw` mode and `engineParams` hand the engine its own wire parameters (`filter_by` among them),
22
+ * which a `where` cannot be ANDed into, so a scoped controller refuses them (400).
23
+ */
24
+ const applySearchScope = async (opts) => {
25
+ const { resolve, context, input } = opts;
26
+ let scope;
27
+ try {
28
+ scope = await resolve({ context });
29
+ }
30
+ catch (error) {
31
+ throw refuse({
32
+ statusCode: common_1.HTTP.ResultCodes.RS_4.Forbidden,
33
+ message: '[search] the search scope could not be resolved for this request',
34
+ cause: error,
35
+ });
36
+ }
37
+ if (scope === ignis_kernel_1.ScopeFilters.UNRESTRICTED) {
38
+ return input;
39
+ }
40
+ if (scope === null || scope === undefined) {
41
+ throw refuse({
42
+ statusCode: common_1.HTTP.ResultCodes.RS_4.Forbidden,
43
+ message: '[search] no search scope for this request',
44
+ });
45
+ }
46
+ if (input.mode === common_2.SearchModes.RAW) {
47
+ throw refuse({
48
+ statusCode: common_1.HTTP.ResultCodes.RS_4.BadRequest,
49
+ message: "[search] mode 'raw' is not available on a scoped search controller",
50
+ });
51
+ }
52
+ if (input.engineParams !== undefined) {
53
+ throw refuse({
54
+ statusCode: common_1.HTTP.ResultCodes.RS_4.BadRequest,
55
+ message: '[search] engineParams is not available on a scoped search controller',
56
+ });
57
+ }
58
+ const clientWhere = input.filter?.where;
59
+ return {
60
+ ...input,
61
+ filter: {
62
+ ...input.filter,
63
+ where: clientWhere ? { and: [scope, clientWhere] } : scope,
64
+ },
65
+ };
66
+ };
67
+ exports.applySearchScope = applySearchScope;
68
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAErD,sDAAuD;AACvD,wDAAqD;AAIrD,8DAAgE;AAWhE,MAAM,MAAM,GAAG,CAAC,IAA8D,EAAE,EAAE;IAChF,OAAO,IAAA,eAAQ,EAAC;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;AACI,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,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;YAC3C,OAAO,EAAE,kEAAkE;YAC3E,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,KAAK,2BAAY,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,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;YAC3C,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAW,CAAC,GAAG,EAAE,CAAC;QACnC,MAAM,MAAM,CAAC;YACX,UAAU,EAAE,aAAI,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,aAAI,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;AApDW,QAAA,gBAAgB,oBAoD3B","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"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Refuses to boot when `settings.scopeFilter` is declared where it cannot be honoured. Both cases
2
+ * Refuses to boot when `settings.access` is declared where it cannot be honoured. Both cases
3
3
  * are silent at runtime and fail in OPPOSITE directions: a search-backed model returns more rows,
4
4
  * a context-less one returns none. The caller supplies `asyncContextEnabled` so no application
5
5
  * config type reaches into this tier.
@@ -1 +1 @@
1
- {"version":3,"file":"scope-filter.d.ts","sourceRoot":"","sources":["../../../src/common/scope-filter.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM;IAAE,mBAAmB,EAAE,OAAO,CAAA;CAAE,KAAG,IA4CnF,CAAC"}
1
+ {"version":3,"file":"scope-filter.d.ts","sourceRoot":"","sources":["../../../src/common/scope-filter.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM;IAAE,mBAAmB,EAAE,OAAO,CAAA;CAAE,KAAG,IA2EnF,CAAC"}