@venizia/ignis-connectors 0.4.2 → 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.
- package/README.md +2 -2
- package/dist/cjs/http/common/constants.d.ts +11 -0
- package/dist/cjs/http/common/constants.d.ts.map +1 -0
- package/dist/cjs/http/common/constants.js +14 -0
- package/dist/cjs/http/common/constants.js.map +1 -0
- package/dist/cjs/http/common/wire.d.ts +2 -1
- package/dist/cjs/http/common/wire.d.ts.map +1 -1
- package/dist/cjs/http/common/wire.js +2 -1
- package/dist/cjs/http/common/wire.js.map +1 -1
- package/dist/cjs/http/datasource.d.ts +2 -1
- package/dist/cjs/http/datasource.d.ts.map +1 -1
- package/dist/cjs/http/datasource.js +2 -1
- package/dist/cjs/http/datasource.js.map +1 -1
- package/dist/cjs/http/index.d.ts +1 -0
- package/dist/cjs/http/index.d.ts.map +1 -1
- package/dist/cjs/http/index.js +1 -0
- package/dist/cjs/http/index.js.map +1 -1
- package/dist/cjs/http/repository.d.ts.map +1 -1
- package/dist/cjs/http/repository.js +5 -4
- package/dist/cjs/http/repository.js.map +1 -1
- package/dist/cjs/relational/core/repositories/common/constants.d.ts +11 -0
- package/dist/cjs/relational/core/repositories/common/constants.d.ts.map +1 -0
- package/dist/cjs/relational/core/repositories/common/constants.js +14 -0
- package/dist/cjs/relational/core/repositories/common/constants.js.map +1 -0
- package/dist/cjs/relational/core/repositories/common/index.d.ts +1 -0
- package/dist/cjs/relational/core/repositories/common/index.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/common/index.js +1 -0
- package/dist/cjs/relational/core/repositories/common/index.js.map +1 -1
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts +22 -1
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.js +130 -1
- package/dist/cjs/relational/core/repositories/common/scope-write-guard.js.map +1 -1
- package/dist/cjs/relational/core/repositories/core/base.d.ts +7 -4
- package/dist/cjs/relational/core/repositories/core/base.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/core/base.js +24 -9
- package/dist/cjs/relational/core/repositories/core/base.js.map +1 -1
- package/dist/cjs/relational/core/repositories/core/persistable.d.ts.map +1 -1
- package/dist/cjs/relational/core/repositories/core/persistable.js +2 -0
- package/dist/cjs/relational/core/repositories/core/persistable.js.map +1 -1
- package/dist/cjs/relational/postgres/models/common/constants.d.ts +11 -0
- package/dist/cjs/relational/postgres/models/common/constants.d.ts.map +1 -0
- package/dist/cjs/relational/postgres/models/common/constants.js +14 -0
- package/dist/cjs/relational/postgres/models/common/constants.js.map +1 -0
- package/dist/cjs/relational/postgres/models/common/index.d.ts +1 -0
- package/dist/cjs/relational/postgres/models/common/index.d.ts.map +1 -1
- package/dist/cjs/relational/postgres/models/common/index.js +1 -0
- package/dist/cjs/relational/postgres/models/common/index.js.map +1 -1
- package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts +5 -3
- package/dist/cjs/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
- package/dist/cjs/relational/postgres/models/common/types/enrichers.js.map +1 -1
- package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
- package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/cjs/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
- package/dist/cjs/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
- package/dist/cjs/relational/sqlite/models/common/types/enrichers.js.map +1 -1
- package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
- package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/cjs/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/cjs/search/core/controllers/factory.d.ts +1 -1
- package/dist/cjs/search/core/controllers/factory.d.ts.map +1 -1
- package/dist/cjs/search/core/controllers/index.d.ts +1 -0
- package/dist/cjs/search/core/controllers/index.d.ts.map +1 -1
- package/dist/cjs/search/core/controllers/index.js.map +1 -1
- package/dist/esm/http/common/constants.d.ts +11 -0
- package/dist/esm/http/common/constants.d.ts.map +1 -0
- package/dist/esm/http/common/constants.js +10 -0
- package/dist/esm/http/common/constants.js.map +1 -0
- package/dist/esm/http/common/wire.d.ts +2 -1
- package/dist/esm/http/common/wire.d.ts.map +1 -1
- package/dist/esm/http/common/wire.js +2 -1
- package/dist/esm/http/common/wire.js.map +1 -1
- package/dist/esm/http/datasource.d.ts +2 -1
- package/dist/esm/http/datasource.d.ts.map +1 -1
- package/dist/esm/http/datasource.js +2 -1
- package/dist/esm/http/datasource.js.map +1 -1
- package/dist/esm/http/index.d.ts +1 -0
- package/dist/esm/http/index.d.ts.map +1 -1
- package/dist/esm/http/index.js +1 -0
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/http/repository.d.ts.map +1 -1
- package/dist/esm/http/repository.js +5 -4
- package/dist/esm/http/repository.js.map +1 -1
- package/dist/esm/relational/core/repositories/common/constants.d.ts +11 -0
- package/dist/esm/relational/core/repositories/common/constants.d.ts.map +1 -0
- package/dist/esm/relational/core/repositories/common/constants.js +10 -0
- package/dist/esm/relational/core/repositories/common/constants.js.map +1 -0
- package/dist/esm/relational/core/repositories/common/index.d.ts +1 -0
- package/dist/esm/relational/core/repositories/common/index.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/common/index.js +1 -0
- package/dist/esm/relational/core/repositories/common/index.js.map +1 -1
- package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +22 -1
- package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/common/scope-write-guard.js +130 -1
- package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -1
- package/dist/esm/relational/core/repositories/core/base.d.ts +7 -4
- package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/base.js +24 -9
- package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
- package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/persistable.js +2 -0
- package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
- package/dist/esm/relational/postgres/models/common/constants.d.ts +11 -0
- package/dist/esm/relational/postgres/models/common/constants.d.ts.map +1 -0
- package/dist/esm/relational/postgres/models/common/constants.js +10 -0
- package/dist/esm/relational/postgres/models/common/constants.js.map +1 -0
- package/dist/esm/relational/postgres/models/common/index.d.ts +1 -0
- package/dist/esm/relational/postgres/models/common/index.d.ts.map +1 -1
- package/dist/esm/relational/postgres/models/common/index.js +1 -0
- package/dist/esm/relational/postgres/models/common/index.js.map +1 -1
- package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts +5 -3
- package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts.map +1 -1
- package/dist/esm/relational/postgres/models/common/types/enrichers.js.map +1 -1
- package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts +4 -3
- package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/esm/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts +3 -2
- package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts.map +1 -1
- package/dist/esm/relational/sqlite/models/common/types/enrichers.js.map +1 -1
- package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts +4 -3
- package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/esm/search/core/controllers/factory.d.ts +1 -1
- package/dist/esm/search/core/controllers/factory.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/index.d.ts +1 -0
- package/dist/esm/search/core/controllers/index.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/http/repository.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AACrD,sDAAuD;AAcvD,iEAAkF;AAqBlF,wDAAwD;AACxD,MAAa,kBAAmB,SAAQ,2BAAc;IACpD,SAAS,CAAc,KAA4B;QACjD,OAAO,EAAO,CAAC;IACjB,CAAC;CACF;AAJD,gDAIC;AAED;;;;GAIG;AACH,MAAa,cAAc;IAmBzB,YAAY,IAOX;QACC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAE9B,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;YACxF,MAAM,IAAA,eAAQ,EAAC;gBACb,UAAU,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,mDAAmD,YAAY,EAAE;aAC5F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,QAAQ,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IA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C,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AAniBD,wCAmiBC","sourcesContent":["import type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type {\n IDeletableRepository,\n IReadableRepository,\n IUpdatableRepository,\n TCount,\n TDataWithRange,\n TByIdFilter,\n TFields,\n TFilter,\n TRow,\n TSchemaType,\n TWhere,\n} from '@venizia/ignis-kernel/repository';\nimport { AbstractEntity, buildDataRange } from '@venizia/ignis-kernel/repository';\nimport type { TSearchInput } from '../search/core/repositories/common/constants';\nimport type {\n IHttpCallOptions,\n IHttpSearchResult,\n IHttpWriteResult,\n THttpExtraQuery,\n TExtraRequest,\n TExtraResult,\n} from './common/types';\nimport type { HttpDataSource } from './datasource';\n\n/**\n * What a repository call takes. Only `headers` and `signal` cross HTTP; the shared repository\n * options (`transaction`, `log`, ...) are accepted for the common contract and have no effect.\n */\nexport type THttpRepositoryOptions = NonNullable<\n Parameters<IReadableRepository['existsWith']>[0]['options']\n> &\n IHttpCallOptions;\n\n/** A remote resource has a name but no local schema. */\nexport class HttpResourceEntity extends AbstractEntity {\n getSchema<T = unknown>(_opts: { type: TSchemaType }): T {\n return {} as T;\n }\n}\n\n/**\n * One remote resource, read and written through the IGNIS CRUD routes, in the `@venizia/ignis-filter`\n * vocabulary. `P` is what a write sends - a partial row by default, since the server fills ids and\n * defaults. There is no `createAll`: the IGNIS REST contract has no bulk-create route.\n */\nexport class HttpRepository<E extends object = AnyType, P extends object = Partial<E>>\n implements\n IReadableRepository<E, THttpRepositoryOptions>,\n IUpdatableRepository<E, P, THttpRepositoryOptions>,\n IDeletableRepository<E, THttpRepositoryOptions>\n{\n dataSource: HttpDataSource;\n entity: AbstractEntity;\n\n protected resource: string;\n /** A count route, if the API has one. Absent, the total comes from `Content-Range`. */\n protected countPath?: string;\n /** The segment after the resource that names the IGNIS find-one route. Absent, `findOne` asks the list route for one row. */\n protected findOnePath?: string;\n /** The page size `find` asks for when its filter names no limit. Absent, the server's own default applies. */\n protected defaultLimit?: number;\n /** The segment after the resource that names the IGNIS search route. */\n protected searchPath: string;\n\n constructor(opts: {\n dataSource: HttpDataSource;\n resource: string;\n countPath?: string;\n findOnePath?: string;\n defaultLimit?: number;\n searchPath?: string;\n }) {\n const { defaultLimit } = opts;\n\n if (defaultLimit !== undefined && !(Number.isInteger(defaultLimit) && defaultLimit > 0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${opts.resource}] defaultLimit must be a positive integer | Got ${defaultLimit}`,\n });\n }\n\n this.dataSource = opts.dataSource;\n this.resource = opts.resource;\n this.countPath = opts.countPath;\n this.findOnePath = opts.findOnePath;\n this.defaultLimit = defaultLimit;\n this.searchPath = opts.searchPath ?? 'search';\n this.entity = new HttpResourceEntity({ name: opts.resource });\n }\n\n getEntity(): AbstractEntity {\n return this.entity;\n }\n\n /**\n * The query string of a read: the caller's extra `query` with the call's own `params` (`filter`,\n * `where`) over it. `method` names the repository verb, so a subclass can reshape one route - a\n * keyword into the object its server reads - and leave the others.\n */\n protected buildQuery(opts: {\n method: string;\n query?: THttpExtraQuery;\n params: Record<string, unknown>;\n }): Record<string, unknown> {\n return { ...opts.query, ...opts.params };\n }\n\n /** The filter `find` sends: the caller's, with `defaultLimit` filled in when it names no limit. */\n protected resolveFindFilter(opts: { filter?: TFilter<E> }): TFilter<E> {\n const filter = opts.filter ?? {};\n\n return this.defaultLimit === undefined || filter.limit !== undefined\n ? filter\n : { ...filter, limit: this.defaultLimit };\n }\n\n /** `<resource>/<searchPath>`; override to move the route. */\n protected getSearchPaths(): Array<string> {\n return [this.resource, this.searchPath];\n }\n\n /** No header and an unreadable one (`/*`) have different fixes, so different messages. */\n protected getMissingTotalError(opts: {\n method: string;\n contentRange?: string;\n noHeader: string;\n }) {\n const { method, contentRange, noHeader } = opts;\n const message = contentRange\n ? `Content-Range \"${contentRange}\" carries no readable total - an unknown \"/*\" or an unparseable value. Check the server's count query.`\n : noHeader;\n\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][${method}] ${message}`,\n });\n }\n\n /** From `Content-Range`, or `countPath`. No total throws rather than reporting the page size. */\n async count(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TCount> {\n if (this.countPath) {\n const rs = await this.dataSource.read<{ count: number }>({\n paths: [this.resource, this.countPath],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { where: opts.where },\n }),\n shape: 'one',\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const counted = rs.data?.count;\n if (typeof counted !== 'number' || !Number.isFinite(counted)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][count] The count route answered no numeric count - answering 0 would read as an empty table. Body: ${JSON.stringify(rs.data)?.slice(0, 120)}`,\n });\n }\n\n return { count: counted };\n }\n\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'count',\n contentRange: rs.contentRange,\n noHeader: `The response carried no Content-Range, so there is no total to report - answering with the page size would claim ${rs.dataLength}. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers; otherwise give this repository a countPath if the API publishes a count route.`,\n });\n }\n\n return { count: rs.total ?? 0 };\n }\n\n async existsWith(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<boolean> {\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'existsWith',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.dataLength > 0;\n }\n\n /** With `extra`: what the route answered beside the rows, typed by what was asked for. */\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true; extra: Extra };\n }): Promise<TDataWithRange<TRow<E, R, F>> & { extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true };\n }): Promise<TDataWithRange<TRow<E, R, F>>>;\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { extra: Extra };\n }): Promise<{ data: Array<TRow<E, R, F>>; extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<Array<TRow<E, R, F>>>;\n /** `extra` or the range decided at run time: the caller narrows the union. */\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions & { shouldQueryRange?: boolean; extra?: TExtraRequest };\n }): Promise<\n | Array<TRow<E, R, F>>\n | TDataWithRange<TRow<E, R, F>>\n | { data: Array<TRow<E, R, F>>; extra: TExtraResult<TExtraRequest> }\n >;\n async find<R = E>(opts: {\n filter?: TFilter<E>;\n query?: THttpExtraQuery;\n options?: AnyType;\n }): Promise<Array<R> | TDataWithRange<R> | { data: Array<R>; extra?: Record<string, unknown> }> {\n const filter = this.resolveFindFilter({ filter: opts.filter });\n const rs = await this.dataSource.read<Array<R>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'find',\n query: opts.query,\n params: { filter },\n }),\n extra: opts.options?.extra,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const data = rs.data ?? [];\n\n if (!opts.options?.shouldQueryRange) {\n return opts.options?.extra ? { data, extra: rs.extra ?? {} } : data;\n }\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'find',\n contentRange: rs.contentRange,\n noHeader: `A range was asked for and the response carried no Content-Range. Deriving it from the page would report ${data.length} as the total. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers.`,\n });\n }\n\n return {\n data,\n // An empty page names no start: take it from the filter, as the server did.\n range: buildDataRange({\n skip: rs.skip ?? filter.skip,\n offset: filter.offset,\n dataLength: data.length,\n total: rs.total ?? 0,\n }),\n // Asked for, `extra` is always there - empty when the route offered none.\n ...(opts.options?.extra ? { extra: rs.extra ?? {} } : {}),\n };\n }\n\n async findOne<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n if (this.findOnePath) {\n const one = await this.dataSource.read<TRow<E, R, F> | null>({\n paths: [this.resource, this.findOnePath],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: 'one',\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return one.data ?? null;\n }\n\n const rs = await this.dataSource.read<Array<TRow<E, R, F>>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: { ...(opts.filter ?? {}), limit: 1 } },\n }),\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return rs.data?.[0] ?? null;\n }\n\n /** The server answers `null`, never 404, for a missing id. A `where` would be replaced by the id. */\n async findById<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n id: string | number;\n filter?: TByIdFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n const rs = await this.dataSource.read<TRow<E, R, F>>({\n paths: this.getIdPaths({ id: opts.id }),\n query: this.buildQuery({\n method: 'findById',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: 'one',\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.data ?? null;\n }\n\n /**\n * POST `<resource>/search`, the IGNIS search route: `input` is its body (a keyword, semantic, hybrid\n * or raw search), the answer its `{ found, isFoundExact, hits }`. `found` is the total - there is no\n * count route for a search, and `isFoundExact` says when it is an estimate.\n */\n async search<R extends object = E>(opts: {\n input: TSearchInput;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<IHttpSearchResult<R>> {\n const rs = await this.dataSource.read<IHttpSearchResult<R> | null>({\n paths: this.getSearchPaths(),\n method: HTTP.Methods.POST,\n body: opts.input,\n query: this.buildQuery({ method: 'search', query: opts.query, params: {} }),\n shape: 'one',\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const answer = rs.data;\n if (!answer || typeof answer.found !== 'number' || !Array.isArray(answer.hits)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.BadGateway,\n message: `[${this.resource}][search] The search route answered no { found, hits } envelope - answering an empty page would read as no match. Body: ${JSON.stringify(answer)?.slice(0, 120)}`,\n });\n }\n\n return answer;\n }\n\n /**\n * `<resource>/<id>`, the id encoded: an id carrying `/` or `?` would otherwise name another route.\n * An empty, `.` or `..` id is refused: a URL resolves it, encoded or not, to `/<resource>/` or the\n * parent - a router or proxy that ignores the trailing slash then serves the list or bulk route.\n */\n protected getIdPaths(opts: { id: string | number }): Array<string> {\n const id = String(opts.id);\n\n if (id === '' || id === '.' || id === '..') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}] Invalid id '${id}' | An empty, '.' or '..' id names another route`,\n });\n }\n\n return [this.resource, encodeURIComponent(id)];\n }\n\n /** What a call adds to its request: headers and an abort signal. Every other option stays local. */\n protected toCallOptions(opts: { options?: THttpRepositoryOptions }): IHttpCallOptions {\n return { headers: opts.options?.headers, signal: opts.options?.signal };\n }\n\n /** The IGNIS bulk routes answer an empty `where` with a 400; refused here before a request is spent. */\n protected assertBulkWhere(opts: { method: string; where?: TWhere<E> }): TWhere<E> {\n const { method, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}][${method}] where is required for a bulk write | The IGNIS bulk routes refuse an empty where, and force cannot cross HTTP`,\n });\n }\n\n return where;\n }\n\n /** The server always answers the rows; `shouldReturn: false` drops them here, as a database repository would not fetch them. */\n protected toWriteResult<R>(opts: {\n result: IHttpWriteResult<R>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): TCount & { data: R | null } {\n const { result, options } = opts;\n return { count: result.count, data: options?.shouldReturn === false ? null : result.data };\n }\n\n /** POST `/<resource>`. */\n async create<R = E>(opts: {\n data: P;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }> {\n const result = await this.dataSource.write<R>({\n paths: [this.resource],\n method: HTTP.Methods.POST,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return { count: result.count, data: result.data };\n }\n\n async updateById(opts: {\n id: string | number;\n data: Partial<P>;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** PATCH `/<resource>/<id>`. */\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.PATCH,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateAll<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** PATCH `/<resource>`, the `where` in the body beside the data - a long id list outgrows a URL. */\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateAll' });\n }\n\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateBy<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `updateAll`. */\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateBy' });\n }\n\n protected async patchWhere(opts: {\n method: string;\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.PATCH,\n body: { ...opts.data, where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteById(opts: {\n id: string | number;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** DELETE `/<resource>/<id>`. */\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.DELETE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteAll(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteAll<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** DELETE `/<resource>`, the `where` in the body. */\n async deleteAll(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteAll' });\n }\n\n async deleteBy(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteBy<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `deleteAll`. */\n async deleteBy(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteBy' });\n }\n\n protected async deleteWhere(opts: {\n method: string;\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.DELETE,\n body: { where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/http/repository.ts"],"names":[],"mappings":";;;AAAA,kDAAoD;AAEpD,0DAAqD;AACrD,sDAAuD;AAcvD,iEAAkF;AAqBlF,wDAAwD;AACxD,MAAa,kBAAmB,SAAQ,2BAAc;IACpD,SAAS,CAAc,KAA4B;QACjD,OAAO,EAAO,CAAC;IACjB,CAAC;CACF;AAJD,gDAIC;AAED;;;;GAIG;AACH,MAAa,cAAc;IAmBzB,YAAY,IAOX;QACC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAE9B,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;YACxF,MAAM,IAAA,eAAQ,EAAC;gBACb,UAAU,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,mDAAmD,YAAY,EAAE;aAC5F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CA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AM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAW;YACnD,KAAK,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;YACtB,MAAM,EAAE,aAAI,CAAC,OAAO,CAAC,MAAM;YAC3B,IAAI,EAAE,EAAE,KAAK,EAAE;YACf,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;SACjD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AAniBD,wCAmiBC","sourcesContent":["import { HttpReadShapes } from './common/constants';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type {\n IDeletableRepository,\n IReadableRepository,\n IUpdatableRepository,\n TCount,\n TDataWithRange,\n TByIdFilter,\n TFields,\n TFilter,\n TRow,\n TSchemaType,\n TWhere,\n} from '@venizia/ignis-kernel/repository';\nimport { AbstractEntity, buildDataRange } from '@venizia/ignis-kernel/repository';\nimport type { TSearchInput } from '../search/core/repositories/common/constants';\nimport type {\n IHttpCallOptions,\n IHttpSearchResult,\n IHttpWriteResult,\n THttpExtraQuery,\n TExtraRequest,\n TExtraResult,\n} from './common/types';\nimport type { HttpDataSource } from './datasource';\n\n/**\n * What a repository call takes. Only `headers` and `signal` cross HTTP; the shared repository\n * options (`transaction`, `log`, ...) are accepted for the common contract and have no effect.\n */\nexport type THttpRepositoryOptions = NonNullable<\n Parameters<IReadableRepository['existsWith']>[0]['options']\n> &\n IHttpCallOptions;\n\n/** A remote resource has a name but no local schema. */\nexport class HttpResourceEntity extends AbstractEntity {\n getSchema<T = unknown>(_opts: { type: TSchemaType }): T {\n return {} as T;\n }\n}\n\n/**\n * One remote resource, read and written through the IGNIS CRUD routes, in the `@venizia/ignis-filter`\n * vocabulary. `P` is what a write sends - a partial row by default, since the server fills ids and\n * defaults. There is no `createAll`: the IGNIS REST contract has no bulk-create route.\n */\nexport class HttpRepository<E extends object = AnyType, P extends object = Partial<E>>\n implements\n IReadableRepository<E, THttpRepositoryOptions>,\n IUpdatableRepository<E, P, THttpRepositoryOptions>,\n IDeletableRepository<E, THttpRepositoryOptions>\n{\n dataSource: HttpDataSource;\n entity: AbstractEntity;\n\n protected resource: string;\n /** A count route, if the API has one. Absent, the total comes from `Content-Range`. */\n protected countPath?: string;\n /** The segment after the resource that names the IGNIS find-one route. Absent, `findOne` asks the list route for one row. */\n protected findOnePath?: string;\n /** The page size `find` asks for when its filter names no limit. Absent, the server's own default applies. */\n protected defaultLimit?: number;\n /** The segment after the resource that names the IGNIS search route. */\n protected searchPath: string;\n\n constructor(opts: {\n dataSource: HttpDataSource;\n resource: string;\n countPath?: string;\n findOnePath?: string;\n defaultLimit?: number;\n searchPath?: string;\n }) {\n const { defaultLimit } = opts;\n\n if (defaultLimit !== undefined && !(Number.isInteger(defaultLimit) && defaultLimit > 0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${opts.resource}] defaultLimit must be a positive integer | Got ${defaultLimit}`,\n });\n }\n\n this.dataSource = opts.dataSource;\n this.resource = opts.resource;\n this.countPath = opts.countPath;\n this.findOnePath = opts.findOnePath;\n this.defaultLimit = defaultLimit;\n this.searchPath = opts.searchPath ?? 'search';\n this.entity = new HttpResourceEntity({ name: opts.resource });\n }\n\n getEntity(): AbstractEntity {\n return this.entity;\n }\n\n /**\n * The query string of a read: the caller's extra `query` with the call's own `params` (`filter`,\n * `where`) over it. `method` names the repository verb, so a subclass can reshape one route - a\n * keyword into the object its server reads - and leave the others.\n */\n protected buildQuery(opts: {\n method: string;\n query?: THttpExtraQuery;\n params: Record<string, unknown>;\n }): Record<string, unknown> {\n return { ...opts.query, ...opts.params };\n }\n\n /** The filter `find` sends: the caller's, with `defaultLimit` filled in when it names no limit. */\n protected resolveFindFilter(opts: { filter?: TFilter<E> }): TFilter<E> {\n const filter = opts.filter ?? {};\n\n return this.defaultLimit === undefined || filter.limit !== undefined\n ? filter\n : { ...filter, limit: this.defaultLimit };\n }\n\n /** `<resource>/<searchPath>`; override to move the route. */\n protected getSearchPaths(): Array<string> {\n return [this.resource, this.searchPath];\n }\n\n /** No header and an unreadable one (`/*`) have different fixes, so different messages. */\n protected getMissingTotalError(opts: {\n method: string;\n contentRange?: string;\n noHeader: string;\n }) {\n const { method, contentRange, noHeader } = opts;\n const message = contentRange\n ? `Content-Range \"${contentRange}\" carries no readable total - an unknown \"/*\" or an unparseable value. Check the server's count query.`\n : noHeader;\n\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][${method}] ${message}`,\n });\n }\n\n /** From `Content-Range`, or `countPath`. No total throws rather than reporting the page size. */\n async count(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TCount> {\n if (this.countPath) {\n const rs = await this.dataSource.read<{ count: number }>({\n paths: [this.resource, this.countPath],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { where: opts.where },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const counted = rs.data?.count;\n if (typeof counted !== 'number' || !Number.isFinite(counted)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][count] The count route answered no numeric count - answering 0 would read as an empty table. Body: ${JSON.stringify(rs.data)?.slice(0, 120)}`,\n });\n }\n\n return { count: counted };\n }\n\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'count',\n contentRange: rs.contentRange,\n noHeader: `The response carried no Content-Range, so there is no total to report - answering with the page size would claim ${rs.dataLength}. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers; otherwise give this repository a countPath if the API publishes a count route.`,\n });\n }\n\n return { count: rs.total ?? 0 };\n }\n\n async existsWith(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<boolean> {\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'existsWith',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.dataLength > 0;\n }\n\n /** With `extra`: what the route answered beside the rows, typed by what was asked for. */\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true; extra: Extra };\n }): Promise<TDataWithRange<TRow<E, R, F>> & { extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true };\n }): Promise<TDataWithRange<TRow<E, R, F>>>;\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { extra: Extra };\n }): Promise<{ data: Array<TRow<E, R, F>>; extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<Array<TRow<E, R, F>>>;\n /** `extra` or the range decided at run time: the caller narrows the union. */\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions & { shouldQueryRange?: boolean; extra?: TExtraRequest };\n }): Promise<\n | Array<TRow<E, R, F>>\n | TDataWithRange<TRow<E, R, F>>\n | { data: Array<TRow<E, R, F>>; extra: TExtraResult<TExtraRequest> }\n >;\n async find<R = E>(opts: {\n filter?: TFilter<E>;\n query?: THttpExtraQuery;\n options?: AnyType;\n }): Promise<Array<R> | TDataWithRange<R> | { data: Array<R>; extra?: Record<string, unknown> }> {\n const filter = this.resolveFindFilter({ filter: opts.filter });\n const rs = await this.dataSource.read<Array<R>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'find',\n query: opts.query,\n params: { filter },\n }),\n extra: opts.options?.extra,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const data = rs.data ?? [];\n\n if (!opts.options?.shouldQueryRange) {\n return opts.options?.extra ? { data, extra: rs.extra ?? {} } : data;\n }\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'find',\n contentRange: rs.contentRange,\n noHeader: `A range was asked for and the response carried no Content-Range. Deriving it from the page would report ${data.length} as the total. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers.`,\n });\n }\n\n return {\n data,\n // An empty page names no start: take it from the filter, as the server did.\n range: buildDataRange({\n skip: rs.skip ?? filter.skip,\n offset: filter.offset,\n dataLength: data.length,\n total: rs.total ?? 0,\n }),\n // Asked for, `extra` is always there - empty when the route offered none.\n ...(opts.options?.extra ? { extra: rs.extra ?? {} } : {}),\n };\n }\n\n async findOne<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n if (this.findOnePath) {\n const one = await this.dataSource.read<TRow<E, R, F> | null>({\n paths: [this.resource, this.findOnePath],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return one.data ?? null;\n }\n\n const rs = await this.dataSource.read<Array<TRow<E, R, F>>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: { ...(opts.filter ?? {}), limit: 1 } },\n }),\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return rs.data?.[0] ?? null;\n }\n\n /** The server answers `null`, never 404, for a missing id. A `where` would be replaced by the id. */\n async findById<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n id: string | number;\n filter?: TByIdFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n const rs = await this.dataSource.read<TRow<E, R, F>>({\n paths: this.getIdPaths({ id: opts.id }),\n query: this.buildQuery({\n method: 'findById',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.data ?? null;\n }\n\n /**\n * POST `<resource>/search`, the IGNIS search route: `input` is its body (a keyword, semantic, hybrid\n * or raw search), the answer its `{ found, isFoundExact, hits }`. `found` is the total - there is no\n * count route for a search, and `isFoundExact` says when it is an estimate.\n */\n async search<R extends object = E>(opts: {\n input: TSearchInput;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<IHttpSearchResult<R>> {\n const rs = await this.dataSource.read<IHttpSearchResult<R> | null>({\n paths: this.getSearchPaths(),\n method: HTTP.Methods.POST,\n body: opts.input,\n query: this.buildQuery({ method: 'search', query: opts.query, params: {} }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const answer = rs.data;\n if (!answer || typeof answer.found !== 'number' || !Array.isArray(answer.hits)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.BadGateway,\n message: `[${this.resource}][search] The search route answered no { found, hits } envelope - answering an empty page would read as no match. Body: ${JSON.stringify(answer)?.slice(0, 120)}`,\n });\n }\n\n return answer;\n }\n\n /**\n * `<resource>/<id>`, the id encoded: an id carrying `/` or `?` would otherwise name another route.\n * An empty, `.` or `..` id is refused: a URL resolves it, encoded or not, to `/<resource>/` or the\n * parent - a router or proxy that ignores the trailing slash then serves the list or bulk route.\n */\n protected getIdPaths(opts: { id: string | number }): Array<string> {\n const id = String(opts.id);\n\n if (id === '' || id === '.' || id === '..') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}] Invalid id '${id}' | An empty, '.' or '..' id names another route`,\n });\n }\n\n return [this.resource, encodeURIComponent(id)];\n }\n\n /** What a call adds to its request: headers and an abort signal. Every other option stays local. */\n protected toCallOptions(opts: { options?: THttpRepositoryOptions }): IHttpCallOptions {\n return { headers: opts.options?.headers, signal: opts.options?.signal };\n }\n\n /** The IGNIS bulk routes answer an empty `where` with a 400; refused here before a request is spent. */\n protected assertBulkWhere(opts: { method: string; where?: TWhere<E> }): TWhere<E> {\n const { method, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}][${method}] where is required for a bulk write | The IGNIS bulk routes refuse an empty where, and force cannot cross HTTP`,\n });\n }\n\n return where;\n }\n\n /** The server always answers the rows; `shouldReturn: false` drops them here, as a database repository would not fetch them. */\n protected toWriteResult<R>(opts: {\n result: IHttpWriteResult<R>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): TCount & { data: R | null } {\n const { result, options } = opts;\n return { count: result.count, data: options?.shouldReturn === false ? null : result.data };\n }\n\n /** POST `/<resource>`. */\n async create<R = E>(opts: {\n data: P;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }> {\n const result = await this.dataSource.write<R>({\n paths: [this.resource],\n method: HTTP.Methods.POST,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return { count: result.count, data: result.data };\n }\n\n async updateById(opts: {\n id: string | number;\n data: Partial<P>;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** PATCH `/<resource>/<id>`. */\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.PATCH,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateAll<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** PATCH `/<resource>`, the `where` in the body beside the data - a long id list outgrows a URL. */\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateAll' });\n }\n\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateBy<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `updateAll`. */\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateBy' });\n }\n\n protected async patchWhere(opts: {\n method: string;\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.PATCH,\n body: { ...opts.data, where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteById(opts: {\n id: string | number;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** DELETE `/<resource>/<id>`. */\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.DELETE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteAll(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteAll<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** DELETE `/<resource>`, the `where` in the body. */\n async deleteAll(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteAll' });\n }\n\n async deleteBy(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteBy<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `deleteAll`. */\n async deleteBy(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteBy' });\n }\n\n protected async deleteWhere(opts: {\n method: string;\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.DELETE,\n body: { where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
/** The writes the row scope holds a payload to: CREATE and UPDATE. */
|
|
3
|
+
export declare class ScopeWriteOperations {
|
|
4
|
+
static readonly CREATE = "create";
|
|
5
|
+
static readonly UPDATE = "update";
|
|
6
|
+
static readonly SCHEME_SET: Set<string>;
|
|
7
|
+
static isValid(value: string): boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Valid scope write operation values. */
|
|
10
|
+
export type TScopeWriteOperation = TConstValue<typeof ScopeWriteOperations>;
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,sEAAsE;AACtE,qBAAa,oBAAoB;IAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAElC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA+C;IAEzE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,0CAA0C;AAC1C,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeWriteOperations = void 0;
|
|
4
|
+
/** The writes the row scope holds a payload to: CREATE and UPDATE. */
|
|
5
|
+
class ScopeWriteOperations {
|
|
6
|
+
static { this.CREATE = 'create'; }
|
|
7
|
+
static { this.UPDATE = 'update'; }
|
|
8
|
+
static { this.SCHEME_SET = new Set([this.CREATE, this.UPDATE]); }
|
|
9
|
+
static isValid(value) {
|
|
10
|
+
return this.SCHEME_SET.has(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ScopeWriteOperations = ScopeWriteOperations;
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/constants.ts"],"names":[],"mappings":";;;AAEA,sEAAsE;AACtE,MAAa,oBAAoB;aACf,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AARH,oDASC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\n\n/** The writes the row scope holds a payload to: CREATE and UPDATE. */\nexport class ScopeWriteOperations {\n static readonly CREATE = 'create';\n static readonly UPDATE = 'update';\n\n static readonly SCHEME_SET = new Set<string>([this.CREATE, this.UPDATE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid scope write operation values. */\nexport type TScopeWriteOperation = TConstValue<typeof ScopeWriteOperations>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
18
19
|
__exportStar(require("./executor"), exports);
|
|
19
20
|
__exportStar(require("./shared"), exports);
|
|
20
21
|
__exportStar(require("./scope-filter"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,iDAA+B","sourcesContent":["export * from './types';\nexport * from './executor';\nexport * from './shared';\nexport * from './scope-filter';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,iDAA+B","sourcesContent":["export * from './types';\nexport * from './constants';\nexport * from './executor';\nexport * from './shared';\nexport * from './scope-filter';\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TScopeWriteOperation } from './constants';
|
|
1
2
|
import type { IModelAccessSettings, TWhere } from '@venizia/ignis-kernel';
|
|
2
3
|
/** The allowed values per scope column, each normalised so `1` and `'1'` and equal dates compare equal. */
|
|
3
4
|
type TConstraints = Map<string, Set<string | null>>;
|
|
@@ -32,6 +33,26 @@ export declare class ScopeWriteGuard {
|
|
|
32
33
|
private static unionOfBranches;
|
|
33
34
|
/** The values one column's condition allows, or a string naming why it cannot be checked. */
|
|
34
35
|
private static allowedValues;
|
|
36
|
+
/**
|
|
37
|
+
* The scope as a MUTATION `where` (update, delete, soft delete, restore). A scope with a `null`
|
|
38
|
+
* branch - `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }` - lets the caller READ the
|
|
39
|
+
* shared rows. Changing or deleting one is the same permission as creating one, `write.sharedRows`,
|
|
40
|
+
* so without it the `null` branch is removed and only the caller's own rows match. With
|
|
41
|
+
* `sharedRows` the scope is returned as it is.
|
|
42
|
+
*
|
|
43
|
+
* Only the shapes the write guard can read are narrowed. Any other shape cannot be shown to exclude
|
|
44
|
+
* the shared rows, so the mutation is refused, as an update with a payload already is.
|
|
45
|
+
*/
|
|
46
|
+
static mutationWhere(opts: {
|
|
47
|
+
settings: IModelAccessSettings;
|
|
48
|
+
model: string;
|
|
49
|
+
operation: string;
|
|
50
|
+
scopeWhere: TWhere;
|
|
51
|
+
}): TWhere;
|
|
52
|
+
/** `where` with every `null` the scope allows removed; `none` when nothing but `null` was allowed. */
|
|
53
|
+
private static withoutShared;
|
|
54
|
+
/** One column's condition without its `null` values, reading the same shapes `allowedValues` reads. */
|
|
55
|
+
private static conditionWithoutNull;
|
|
35
56
|
/**
|
|
36
57
|
* Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same
|
|
37
58
|
* objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and
|
|
@@ -41,7 +62,7 @@ export declare class ScopeWriteGuard {
|
|
|
41
62
|
settings: IModelAccessSettings;
|
|
42
63
|
model: string;
|
|
43
64
|
rows: Row[];
|
|
44
|
-
operation:
|
|
65
|
+
operation: TScopeWriteOperation;
|
|
45
66
|
}): Row[];
|
|
46
67
|
/** Names the model and the column, never a value: the caller may be a request. */
|
|
47
68
|
private static denied;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-write-guard.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scope-write-guard.d.ts","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAS9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAM1E,2GAA2G;AAC3G,KAAK,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAEpD,KAAK,WAAW,GACZ;IAAE,YAAY,EAAE,IAAI,CAAC;IAAC,WAAW,EAAE,YAAY,CAAA;CAAE,GACjD;IAAE,YAAY,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAkC5C;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,WAAW;IAY/D,uGAAuG;IACvG,OAAO,CAAC,MAAM,CAAC,OAAO;IAuDtB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuC9B,6FAA6F;IAC7F,OAAO,CAAC,MAAM,CAAC,aAAa;IAyC5B;;;;;;;;;OASG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QACzB,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,MAAM;IAoBV,sGAAsG;IACtG,OAAO,CAAC,MAAM,CAAC,aAAa;IAiE5B,uGAAuG;IACvG,OAAO,CAAC,MAAM,CAAC,oBAAoB;IA8DnC;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;QACtD,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,EAAE,oBAAoB,CAAC;KACjC,GAAG,GAAG,EAAE;IAqGT,kFAAkF;IAClF,OAAO,CAAC,MAAM,CAAC,MAAM;CAkBtB"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScopeWriteGuard = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
const core_1 = require("@venizia/ignis-helpers/core");
|
|
5
6
|
const ignis_kernel_1 = require("@venizia/ignis-kernel");
|
|
6
7
|
const common_1 = require("@venizia/ignis-helpers/common");
|
|
8
|
+
const scope_filter_1 = require("./scope-filter");
|
|
7
9
|
const WRITE_DENIED_STATUS = common_1.HTTP.ResultCodes.RS_4.Forbidden;
|
|
8
10
|
const isScalar = (value) => {
|
|
9
11
|
return (value === null ||
|
|
10
12
|
value instanceof Date ||
|
|
11
13
|
['string', 'number', 'bigint', 'boolean'].includes(typeof value));
|
|
12
14
|
};
|
|
15
|
+
const isRecord = (value) => {
|
|
16
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
};
|
|
13
18
|
const normalise = (value) => {
|
|
14
19
|
if (value === null) {
|
|
15
20
|
return null;
|
|
@@ -144,6 +149,129 @@ class ScopeWriteGuard {
|
|
|
144
149
|
}
|
|
145
150
|
return `the operator '${operator}' cannot be checked on a write`;
|
|
146
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* The scope as a MUTATION `where` (update, delete, soft delete, restore). A scope with a `null`
|
|
154
|
+
* branch - `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }` - lets the caller READ the
|
|
155
|
+
* shared rows. Changing or deleting one is the same permission as creating one, `write.sharedRows`,
|
|
156
|
+
* so without it the `null` branch is removed and only the caller's own rows match. With
|
|
157
|
+
* `sharedRows` the scope is returned as it is.
|
|
158
|
+
*
|
|
159
|
+
* Only the shapes the write guard can read are narrowed. Any other shape cannot be shown to exclude
|
|
160
|
+
* the shared rows, so the mutation is refused, as an update with a payload already is.
|
|
161
|
+
*/
|
|
162
|
+
static mutationWhere(opts) {
|
|
163
|
+
const { settings, model, operation, scopeWhere } = opts;
|
|
164
|
+
if (settings.write?.sharedRows === true) {
|
|
165
|
+
return scopeWhere;
|
|
166
|
+
}
|
|
167
|
+
const narrowed = ScopeWriteGuard.withoutShared({ where: scopeWhere });
|
|
168
|
+
if (narrowed.kind === 'unverifiable') {
|
|
169
|
+
throw ScopeWriteGuard.denied({
|
|
170
|
+
model,
|
|
171
|
+
operation,
|
|
172
|
+
detail: `the resolved scope cannot be verified on a write | ${narrowed.reason}`,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return narrowed.kind === 'none' ? scope_filter_1.ScopeFilterDenial.where() : narrowed.where;
|
|
176
|
+
}
|
|
177
|
+
/** `where` with every `null` the scope allows removed; `none` when nothing but `null` was allowed. */
|
|
178
|
+
static withoutShared(opts) {
|
|
179
|
+
const result = {};
|
|
180
|
+
for (const [key, value] of Object.entries(opts.where)) {
|
|
181
|
+
if (key === 'and' || key === 'or') {
|
|
182
|
+
if (!Array.isArray(value) || (key === 'or' && value.length === 0)) {
|
|
183
|
+
return { kind: 'unverifiable', reason: `'${key}' is not a list` };
|
|
184
|
+
}
|
|
185
|
+
// An 'or' is read only when every branch constrains the same column, as the guard reads it: a branch over another column
|
|
186
|
+
// could match a shared row without a null in sight.
|
|
187
|
+
if (key === 'or') {
|
|
188
|
+
const union = ScopeWriteGuard.unionOfBranches({ branches: value });
|
|
189
|
+
if (typeof union === 'string') {
|
|
190
|
+
return { kind: 'unverifiable', reason: union };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const kept = [];
|
|
194
|
+
for (const part of value) {
|
|
195
|
+
const narrowed = ScopeWriteGuard.withoutShared({ where: isRecord(part) ? part : {} });
|
|
196
|
+
if (narrowed.kind === 'unverifiable') {
|
|
197
|
+
return narrowed;
|
|
198
|
+
}
|
|
199
|
+
if (narrowed.kind === 'none') {
|
|
200
|
+
// One impossible 'and' part makes the whole 'and' impossible; an impossible 'or' branch just drops out.
|
|
201
|
+
if (key === 'and') {
|
|
202
|
+
return narrowed;
|
|
203
|
+
}
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
kept.push(narrowed.where);
|
|
207
|
+
}
|
|
208
|
+
if (key === 'or' && kept.length === 0) {
|
|
209
|
+
return { kind: 'none' };
|
|
210
|
+
}
|
|
211
|
+
result[key] = kept;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (key.includes('.')) {
|
|
215
|
+
return {
|
|
216
|
+
kind: 'unverifiable',
|
|
217
|
+
reason: `the nested path '${key}' cannot be checked on a write`,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const narrowed = ScopeWriteGuard.conditionWithoutNull({ value });
|
|
221
|
+
if (narrowed.kind !== 'condition') {
|
|
222
|
+
return narrowed.kind === 'none'
|
|
223
|
+
? { kind: 'none' }
|
|
224
|
+
: { kind: 'unverifiable', reason: `column '${key}': ${narrowed.reason}` };
|
|
225
|
+
}
|
|
226
|
+
result[key] = narrowed.value;
|
|
227
|
+
}
|
|
228
|
+
return { kind: 'where', where: result };
|
|
229
|
+
}
|
|
230
|
+
/** One column's condition without its `null` values, reading the same shapes `allowedValues` reads. */
|
|
231
|
+
static conditionWithoutNull(opts) {
|
|
232
|
+
const { value } = opts;
|
|
233
|
+
const list = (entries) => {
|
|
234
|
+
if (!entries.every(isScalar)) {
|
|
235
|
+
return { kind: 'unverifiable', reason: 'a list with a non-scalar entry' };
|
|
236
|
+
}
|
|
237
|
+
const kept = entries.filter((entry) => entry !== null);
|
|
238
|
+
return kept.length === 0
|
|
239
|
+
? { kind: 'none' }
|
|
240
|
+
: { kind: 'condition', value: kept };
|
|
241
|
+
};
|
|
242
|
+
if (isScalar(value)) {
|
|
243
|
+
return value === null ? { kind: 'none' } : { kind: 'condition', value };
|
|
244
|
+
}
|
|
245
|
+
if (Array.isArray(value)) {
|
|
246
|
+
return list(value);
|
|
247
|
+
}
|
|
248
|
+
if (!isRecord(value)) {
|
|
249
|
+
return { kind: 'unverifiable', reason: 'an unsupported condition' };
|
|
250
|
+
}
|
|
251
|
+
const operators = Object.keys(value);
|
|
252
|
+
if (operators.length !== 1) {
|
|
253
|
+
return {
|
|
254
|
+
kind: 'unverifiable',
|
|
255
|
+
reason: `a condition with ${operators.length} operators cannot be checked on a write`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const [operator] = operators;
|
|
259
|
+
const operand = value[operator];
|
|
260
|
+
if (operator === ignis_kernel_1.QueryOperators.EQ && isScalar(operand)) {
|
|
261
|
+
return operand === null ? { kind: 'none' } : { kind: 'condition', value };
|
|
262
|
+
}
|
|
263
|
+
if ((operator === ignis_kernel_1.QueryOperators.INQ || operator === ignis_kernel_1.QueryOperators.IN) &&
|
|
264
|
+
Array.isArray(operand)) {
|
|
265
|
+
const narrowed = list(operand);
|
|
266
|
+
return narrowed.kind === 'condition'
|
|
267
|
+
? { kind: 'condition', value: { [operator]: narrowed.value } }
|
|
268
|
+
: narrowed;
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
kind: 'unverifiable',
|
|
272
|
+
reason: `the operator '${operator}' cannot be checked on a write`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
147
275
|
/**
|
|
148
276
|
* Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same
|
|
149
277
|
* objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and
|
|
@@ -158,7 +286,8 @@ class ScopeWriteGuard {
|
|
|
158
286
|
if (scope === null || scope === undefined) {
|
|
159
287
|
// An update is already confined by the scoped `where`, which under `deny` matches no row; the
|
|
160
288
|
// guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.
|
|
161
|
-
if (settings.onMissing === ignis_kernel_1.ScopeFilterMissingBehaviors.ALLOW ||
|
|
289
|
+
if (settings.onMissing === ignis_kernel_1.ScopeFilterMissingBehaviors.ALLOW ||
|
|
290
|
+
operation === constants_1.ScopeWriteOperations.UPDATE) {
|
|
162
291
|
return rows;
|
|
163
292
|
}
|
|
164
293
|
throw ScopeWriteGuard.denied({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-write-guard.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":";;;AAAA,sDAAuD;AACvD,wDAM+B;AAE/B,0DAAqD;AAWrD,MAAM,mBAAmB,GAAG,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoB,EAAE;IACpD,OAAO,CACL,K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QAChB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kFAAkF;IAC1E,MAAM,CAAC,MAAM,CAAC,IAKrB;QACC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAElD,OAAO,IAAA,eAAQ,EAAC;YACd,UAAU,EAAE,mBAAmB;YAC/B,WAAW,EAAE,mCAAoB,CAAC,kBAAkB;YACpD,OAAO,EAAE;gBACP,IAAI,SAAS,iDAAiD,KAAK,EAAE;gBACrE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxC,MAAM;aACP,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;CACF;AA3RD,0CA2RC","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport {\n QueryOperators,\n RepositoryErrorCodes,\n ScopeFilterMissingBehaviors,\n ScopeFilters,\n ScopeWriteGuards,\n} from '@venizia/ignis-kernel';\nimport type { IModelAccessSettings, TWhere } from '@venizia/ignis-kernel';\nimport { HTTP } from '@venizia/ignis-helpers/common';\n\ntype TScalar = string | number | bigint | boolean | Date | null;\n\n/** The allowed values per scope column, each normalised so `1` and `'1'` and equal dates compare equal. */\ntype TConstraints = Map<string, Set<string | null>>;\n\ntype TExtraction =\n | { isVerifiable: true; constraints: TConstraints }\n | { isVerifiable: false; reason: string };\n\nconst WRITE_DENIED_STATUS = HTTP.ResultCodes.RS_4.Forbidden;\n\nconst isScalar = (value: unknown): value is TScalar => {\n return (\n value === null ||\n value instanceof Date ||\n ['string', 'number', 'bigint', 'boolean'].includes(typeof value)\n );\n};\n\nconst normalise = (value: TScalar): string | null => {\n if (value === null) {\n return null;\n }\n\n return value instanceof Date ? value.toISOString() : String(value);\n};\n\nconst intersect = (opts: { left: Set<string | null>; right: Set<string | null> }) => {\n return new Set([...opts.left].filter((value) => opts.right.has(value)));\n};\n\n/**\n * The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads\n * from it the columns it constrains and the values it allows, and holds every written row to them.\n *\n * Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`\n * (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything\n * else - an `or` over several columns, ranges, `like`, a nested path - makes\n * the scope unverifiable, and the write is refused with its own message instead of being skipped.\n */\nexport class ScopeWriteGuard {\n static extractConstraints(opts: { where: TWhere }): TExtraction {\n const constraints: TConstraints = new Map();\n const reason = ScopeWriteGuard.collect({\n where: opts.where as Record<string, unknown>,\n constraints,\n });\n\n return reason === undefined\n ? { isVerifiable: true, constraints }\n : { isVerifiable: false, reason };\n }\n\n /** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */\n private static collect(opts: {\n where: Record<string, unknown>;\n constraints: TConstraints;\n }): string | undefined {\n const { where, constraints } = opts;\n\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and') {\n if (!Array.isArray(value)) {\n return \"'and' is not a list\";\n }\n\n for (const part of value) {\n const reason = ScopeWriteGuard.collect({\n where: part as Record<string, unknown>,\n constraints,\n });\n if (reason !== undefined) {\n return reason;\n }\n }\n\n continue;\n }\n\n if (key === 'or') {\n const union = ScopeWriteGuard.unionOfBranches({ branches: value });\n if (typeof union === 'string') {\n return union;\n }\n\n const existing = constraints.get(union.column);\n constraints.set(\n union.column,\n existing ? intersect({ left: existing, right: union.allowed }) : union.allowed,\n );\n continue;\n }\n\n if (key.includes('.')) {\n return `the nested path '${key}' cannot be checked on a write`;\n }\n\n const allowed = ScopeWriteGuard.allowedValues({ value });\n if (typeof allowed === 'string') {\n return `column '${key}': ${allowed}`;\n }\n\n const existing = constraints.get(key);\n constraints.set(key, existing ? intersect({ left: existing, right: allowed }) : allowed);\n }\n\n return undefined;\n }\n\n /**\n * An `or` is checkable only when every branch constrains the same single column with a scalar,\n * `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the\n * shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`\n * (several columns, ranges, nested `and` or `or`) cannot be checked.\n */\n private static unionOfBranches(opts: {\n branches: unknown;\n }): { column: string; allowed: Set<string | null> } | string {\n const { branches } = opts;\n\n if (!Array.isArray(branches) || branches.length === 0) {\n return \"'or' is not a list\";\n }\n\n let column: string | undefined;\n const allowed = new Set<string | null>();\n\n for (const branch of branches) {\n const entries = Object.entries((branch ?? {}) as Record<string, unknown>);\n if (entries.length !== 1) {\n return \"an 'or' branch with several conditions cannot be checked on a write\";\n }\n\n const [key, value] = entries[0];\n if (key === 'and' || key === 'or' || key.includes('.')) {\n return `an 'or' branch over '${key}' cannot be checked on a write`;\n }\n\n if (column !== undefined && column !== key) {\n return \"an 'or' over different columns cannot be checked on a write\";\n }\n\n column = key;\n const values = ScopeWriteGuard.allowedValues({ value });\n if (typeof values === 'string') {\n return `column '${key}': ${values}`;\n }\n\n values.forEach((entry) => allowed.add(entry));\n }\n\n return { column: column as string, allowed };\n }\n\n /** The values one column's condition allows, or a string naming why it cannot be checked. */\n private static allowedValues(opts: { value: unknown }): Set<string | null> | string {\n const { value } = opts;\n\n if (isScalar(value)) {\n return new Set([normalise(value)]);\n }\n\n if (Array.isArray(value)) {\n return value.every(isScalar)\n ? new Set(value.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n if (typeof value !== 'object' || value === undefined) {\n return 'an unsupported condition';\n }\n\n const operators = Object.keys(value as object);\n if (operators.length !== 1) {\n return `a condition with ${operators.length} operators cannot be checked on a write`;\n }\n\n const [operator] = operators;\n const operand = (value as Record<string, unknown>)[operator];\n\n if (operator === QueryOperators.EQ && isScalar(operand)) {\n return new Set([normalise(operand)]);\n }\n\n if (\n (operator === QueryOperators.INQ || operator === QueryOperators.IN) &&\n Array.isArray(operand)\n ) {\n return operand.every(isScalar)\n ? new Set(operand.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n return `the operator '${operator}' cannot be checked on a write`;\n }\n\n /**\n * Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same\n * objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and\n * so writes nothing, when any row is outside the scope.\n */\n static apply<Row extends Record<string, unknown>>(opts: {\n settings: IModelAccessSettings;\n model: string;\n rows: Row[];\n operation: 'create' | 'update';\n }): Row[] {\n const { settings, model, rows, operation } = opts;\n const scope = settings.resolve();\n\n if (scope === ScopeFilters.UNRESTRICTED) {\n return rows;\n }\n\n if (scope === null || scope === undefined) {\n // An update is already confined by the scoped `where`, which under `deny` matches no row; the\n // guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.\n if (settings.onMissing === ScopeFilterMissingBehaviors.ALLOW || operation === 'update') {\n return rows;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: 'no scope could be resolved for this caller',\n });\n }\n\n const extraction = ScopeWriteGuard.extractConstraints({ where: scope });\n if (!extraction.isVerifiable) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope cannot be verified on a write | ${extraction.reason}`,\n });\n }\n\n const { constraints } = extraction;\n const declared = settings.columns;\n\n if (declared) {\n const undeclared = [...constraints.keys()].find((column) => !declared.includes(column));\n if (undeclared !== undefined) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope constrains column '${undeclared}', which access.columns does not declare`,\n });\n }\n }\n\n const isAssign = settings.write?.mode === ScopeWriteGuards.ASSIGN && operation === 'create';\n const sharedRows = settings.write?.sharedRows === true;\n\n return rows.map((row) => {\n let result = row;\n\n for (const [column, allowed] of constraints) {\n const value = (row as Record<string, unknown>)[column];\n\n if (value === undefined) {\n if (operation === 'update') {\n continue;\n }\n\n // `assign` first: stamping gives the row an owner, which is safer than leaving it shared.\n const only = allowed.size === 1 ? [...allowed][0] : undefined;\n if (isAssign && only !== undefined && only !== null) {\n result = { ...result, [column]: only };\n continue;\n }\n\n // Absent means the database default, usually `null`, so it is held to the `null` rule.\n if (sharedRows) {\n continue;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the scope column is missing',\n });\n }\n\n const normalised = isScalar(value) ? normalise(value) : undefined;\n // A `null` branch in the scope lets this caller READ shared rows. Writing one (or moving a\n // row into the shared set) is a separate permission: only `sharedRows` grants it.\n const isOutside = normalised === null ? !sharedRows : !allowed.has(normalised as string);\n\n if (normalised === undefined || isOutside) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the value is outside the resolved scope',\n });\n }\n }\n\n return result;\n });\n }\n\n /** Names the model and the column, never a value: the caller may be a request. */\n private static denied(opts: {\n model: string;\n operation: string;\n column?: string;\n detail: string;\n }) {\n const { model, operation, column, detail } = opts;\n\n return getError({\n statusCode: WRITE_DENIED_STATUS,\n messageCode: RepositoryErrorCodes.SCOPE_WRITE_DENIED,\n message: [\n `[${operation}] write refused by the access scope | entity: ${model}`,\n ...(column ? [`column: ${column}`] : []),\n detail,\n ].join(' | '),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scope-write-guard.js","sourceRoot":"","sources":["../../../../../../src/relational/core/repositories/common/scope-write-guard.ts"],"names":[],"mappings":";;;AAAA,2CAA8E;AAC9E,sDAAuD;AACvD,wDAM+B;AAE/B,0DAAqD;AACrD,iDAAmD;AAiBnD,MAAM,mBAAmB,GAAG,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoB,EAAE;IACpD,OAAO,CACL,KAAK,KAAK,IAAI;QACd,KAAK,YAAY,IAAI;QACrB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CACjE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI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M,eAAe,CAAC,MAAM,CAAC;wBAC3B,KAAK;wBACL,SAAS;wBACT,MAAM;wBACN,MAAM,EAAE,yCAAyC;qBAClD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kFAAkF;IAC1E,MAAM,CAAC,MAAM,CAAC,IAKrB;QACC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAElD,OAAO,IAAA,eAAQ,EAAC;YACd,UAAU,EAAE,mBAAmB;YAC/B,WAAW,EAAE,mCAAoB,CAAC,kBAAkB;YACpD,OAAO,EAAE;gBACP,IAAI,SAAS,iDAAiD,KAAK,EAAE;gBACrE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxC,MAAM;aACP,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC;CACF;AAlcD,0CAkcC","sourcesContent":["import { ScopeWriteOperations, type TScopeWriteOperation } from './constants';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n QueryOperators,\n RepositoryErrorCodes,\n ScopeFilterMissingBehaviors,\n ScopeFilters,\n ScopeWriteGuards,\n} from '@venizia/ignis-kernel';\nimport type { IModelAccessSettings, TWhere } from '@venizia/ignis-kernel';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { ScopeFilterDenial } from './scope-filter';\n\ntype TScalar = string | number | bigint | boolean | Date | null;\n\n/** The allowed values per scope column, each normalised so `1` and `'1'` and equal dates compare equal. */\ntype TConstraints = Map<string, Set<string | null>>;\n\ntype TExtraction =\n | { isVerifiable: true; constraints: TConstraints }\n | { isVerifiable: false; reason: string };\n\n/** What the scope becomes for a write: a `where`, no row at all, or a shape that cannot be narrowed. */\ntype TNarrowed =\n | { kind: 'where'; where: TWhere }\n | { kind: 'none' }\n | { kind: 'unverifiable'; reason: string };\n\nconst WRITE_DENIED_STATUS = HTTP.ResultCodes.RS_4.Forbidden;\n\nconst isScalar = (value: unknown): value is TScalar => {\n return (\n value === null ||\n value instanceof Date ||\n ['string', 'number', 'bigint', 'boolean'].includes(typeof value)\n );\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\nconst normalise = (value: TScalar): string | null => {\n if (value === null) {\n return null;\n }\n\n return value instanceof Date ? value.toISOString() : String(value);\n};\n\nconst intersect = (opts: { left: Set<string | null>; right: Set<string | null> }) => {\n return new Set([...opts.left].filter((value) => opts.right.has(value)));\n};\n\n/**\n * The write side of `@model` settings.access. The resolved scope is a `where`; the guard reads\n * from it the columns it constrains and the values it allows, and holds every written row to them.\n *\n * Only shapes that can be checked are read: a column equal to a scalar or `null`, `{ eq }`, `{ inq }`\n * (or `in`), an array, `and` of those, and an `or` whose branches all constrain the same column. Anything\n * else - an `or` over several columns, ranges, `like`, a nested path - makes\n * the scope unverifiable, and the write is refused with its own message instead of being skipped.\n */\nexport class ScopeWriteGuard {\n static extractConstraints(opts: { where: TWhere }): TExtraction {\n const constraints: TConstraints = new Map();\n const reason = ScopeWriteGuard.collect({\n where: opts.where as Record<string, unknown>,\n constraints,\n });\n\n return reason === undefined\n ? { isVerifiable: true, constraints }\n : { isVerifiable: false, reason };\n }\n\n /** Adds the where's constraints to `constraints`; returns the reason it cannot be verified, if any. */\n private static collect(opts: {\n where: Record<string, unknown>;\n constraints: TConstraints;\n }): string | undefined {\n const { where, constraints } = opts;\n\n for (const [key, value] of Object.entries(where)) {\n if (key === 'and') {\n if (!Array.isArray(value)) {\n return \"'and' is not a list\";\n }\n\n for (const part of value) {\n const reason = ScopeWriteGuard.collect({\n where: part as Record<string, unknown>,\n constraints,\n });\n if (reason !== undefined) {\n return reason;\n }\n }\n\n continue;\n }\n\n if (key === 'or') {\n const union = ScopeWriteGuard.unionOfBranches({ branches: value });\n if (typeof union === 'string') {\n return union;\n }\n\n const existing = constraints.get(union.column);\n constraints.set(\n union.column,\n existing ? intersect({ left: existing, right: union.allowed }) : union.allowed,\n );\n continue;\n }\n\n if (key.includes('.')) {\n return `the nested path '${key}' cannot be checked on a write`;\n }\n\n const allowed = ScopeWriteGuard.allowedValues({ value });\n if (typeof allowed === 'string') {\n return `column '${key}': ${allowed}`;\n }\n\n const existing = constraints.get(key);\n constraints.set(key, existing ? intersect({ left: existing, right: allowed }) : allowed);\n }\n\n return undefined;\n }\n\n /**\n * An `or` is checkable only when every branch constrains the same single column with a scalar,\n * `null`, `eq`, `in` or `inq`: the allowed values are then the union of the branches. This is the\n * shared-rows scope, `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }`. Any other `or`\n * (several columns, ranges, nested `and` or `or`) cannot be checked.\n */\n private static unionOfBranches(opts: {\n branches: unknown;\n }): { column: string; allowed: Set<string | null> } | string {\n const { branches } = opts;\n\n if (!Array.isArray(branches) || branches.length === 0) {\n return \"'or' is not a list\";\n }\n\n let column: string | undefined;\n const allowed = new Set<string | null>();\n\n for (const branch of branches) {\n const entries = Object.entries((branch ?? {}) as Record<string, unknown>);\n if (entries.length !== 1) {\n return \"an 'or' branch with several conditions cannot be checked on a write\";\n }\n\n const [key, value] = entries[0];\n if (key === 'and' || key === 'or' || key.includes('.')) {\n return `an 'or' branch over '${key}' cannot be checked on a write`;\n }\n\n if (column !== undefined && column !== key) {\n return \"an 'or' over different columns cannot be checked on a write\";\n }\n\n column = key;\n const values = ScopeWriteGuard.allowedValues({ value });\n if (typeof values === 'string') {\n return `column '${key}': ${values}`;\n }\n\n values.forEach((entry) => allowed.add(entry));\n }\n\n return { column: column as string, allowed };\n }\n\n /** The values one column's condition allows, or a string naming why it cannot be checked. */\n private static allowedValues(opts: { value: unknown }): Set<string | null> | string {\n const { value } = opts;\n\n if (isScalar(value)) {\n return new Set([normalise(value)]);\n }\n\n if (Array.isArray(value)) {\n return value.every(isScalar)\n ? new Set(value.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n if (typeof value !== 'object' || value === undefined) {\n return 'an unsupported condition';\n }\n\n const operators = Object.keys(value as object);\n if (operators.length !== 1) {\n return `a condition with ${operators.length} operators cannot be checked on a write`;\n }\n\n const [operator] = operators;\n const operand = (value as Record<string, unknown>)[operator];\n\n if (operator === QueryOperators.EQ && isScalar(operand)) {\n return new Set([normalise(operand)]);\n }\n\n if (\n (operator === QueryOperators.INQ || operator === QueryOperators.IN) &&\n Array.isArray(operand)\n ) {\n return operand.every(isScalar)\n ? new Set(operand.map(normalise))\n : 'a list with a non-scalar entry';\n }\n\n return `the operator '${operator}' cannot be checked on a write`;\n }\n\n /**\n * The scope as a MUTATION `where` (update, delete, soft delete, restore). A scope with a `null`\n * branch - `{ or: [{ merchantId: { in: ids } }, { merchantId: null }] }` - lets the caller READ the\n * shared rows. Changing or deleting one is the same permission as creating one, `write.sharedRows`,\n * so without it the `null` branch is removed and only the caller's own rows match. With\n * `sharedRows` the scope is returned as it is.\n *\n * Only the shapes the write guard can read are narrowed. Any other shape cannot be shown to exclude\n * the shared rows, so the mutation is refused, as an update with a payload already is.\n */\n static mutationWhere(opts: {\n settings: IModelAccessSettings;\n model: string;\n operation: string;\n scopeWhere: TWhere;\n }): TWhere {\n const { settings, model, operation, scopeWhere } = opts;\n\n if (settings.write?.sharedRows === true) {\n return scopeWhere;\n }\n\n const narrowed = ScopeWriteGuard.withoutShared({ where: scopeWhere });\n\n if (narrowed.kind === 'unverifiable') {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope cannot be verified on a write | ${narrowed.reason}`,\n });\n }\n\n return narrowed.kind === 'none' ? ScopeFilterDenial.where() : narrowed.where;\n }\n\n /** `where` with every `null` the scope allows removed; `none` when nothing but `null` was allowed. */\n private static withoutShared(opts: { where: TWhere }): TNarrowed {\n const result: TWhere = {};\n\n for (const [key, value] of Object.entries(opts.where)) {\n if (key === 'and' || key === 'or') {\n if (!Array.isArray(value) || (key === 'or' && value.length === 0)) {\n return { kind: 'unverifiable', reason: `'${key}' is not a list` };\n }\n\n // An 'or' is read only when every branch constrains the same column, as the guard reads it: a branch over another column\n // could match a shared row without a null in sight.\n if (key === 'or') {\n const union = ScopeWriteGuard.unionOfBranches({ branches: value });\n if (typeof union === 'string') {\n return { kind: 'unverifiable', reason: union };\n }\n }\n\n const kept: TWhere[] = [];\n for (const part of value) {\n const narrowed = ScopeWriteGuard.withoutShared({ where: isRecord(part) ? part : {} });\n\n if (narrowed.kind === 'unverifiable') {\n return narrowed;\n }\n\n if (narrowed.kind === 'none') {\n // One impossible 'and' part makes the whole 'and' impossible; an impossible 'or' branch just drops out.\n if (key === 'and') {\n return narrowed;\n }\n continue;\n }\n\n kept.push(narrowed.where);\n }\n\n if (key === 'or' && kept.length === 0) {\n return { kind: 'none' };\n }\n\n result[key] = kept;\n continue;\n }\n\n if (key.includes('.')) {\n return {\n kind: 'unverifiable',\n reason: `the nested path '${key}' cannot be checked on a write`,\n };\n }\n\n const narrowed = ScopeWriteGuard.conditionWithoutNull({ value });\n if (narrowed.kind !== 'condition') {\n return narrowed.kind === 'none'\n ? { kind: 'none' }\n : { kind: 'unverifiable', reason: `column '${key}': ${narrowed.reason}` };\n }\n\n result[key] = narrowed.value;\n }\n\n return { kind: 'where', where: result };\n }\n\n /** One column's condition without its `null` values, reading the same shapes `allowedValues` reads. */\n private static conditionWithoutNull(opts: {\n value: unknown;\n }):\n | { kind: 'condition'; value: unknown }\n | { kind: 'none' }\n | { kind: 'unverifiable'; reason: string } {\n const { value } = opts;\n\n const list = (entries: unknown[]) => {\n if (!entries.every(isScalar)) {\n return { kind: 'unverifiable' as const, reason: 'a list with a non-scalar entry' };\n }\n\n const kept = entries.filter((entry) => entry !== null);\n return kept.length === 0\n ? { kind: 'none' as const }\n : { kind: 'condition' as const, value: kept };\n };\n\n if (isScalar(value)) {\n return value === null ? { kind: 'none' } : { kind: 'condition', value };\n }\n\n if (Array.isArray(value)) {\n return list(value);\n }\n\n if (!isRecord(value)) {\n return { kind: 'unverifiable', reason: 'an unsupported condition' };\n }\n\n const operators = Object.keys(value);\n if (operators.length !== 1) {\n return {\n kind: 'unverifiable',\n reason: `a condition with ${operators.length} operators cannot be checked on a write`,\n };\n }\n\n const [operator] = operators;\n const operand = value[operator];\n\n if (operator === QueryOperators.EQ && isScalar(operand)) {\n return operand === null ? { kind: 'none' } : { kind: 'condition', value };\n }\n\n if (\n (operator === QueryOperators.INQ || operator === QueryOperators.IN) &&\n Array.isArray(operand)\n ) {\n const narrowed = list(operand);\n return narrowed.kind === 'condition'\n ? { kind: 'condition', value: { [operator]: narrowed.value } }\n : narrowed;\n }\n\n return {\n kind: 'unverifiable',\n reason: `the operator '${operator}' cannot be checked on a write`,\n };\n }\n\n /**\n * Holds `rows` to the scope `settings.resolve()` returns now. Returns the rows to write: the same\n * objects when nothing changes, copies with the scope columns filled in for `assign`. Throws, and\n * so writes nothing, when any row is outside the scope.\n */\n static apply<Row extends Record<string, unknown>>(opts: {\n settings: IModelAccessSettings;\n model: string;\n rows: Row[];\n operation: TScopeWriteOperation;\n }): Row[] {\n const { settings, model, rows, operation } = opts;\n const scope = settings.resolve();\n\n if (scope === ScopeFilters.UNRESTRICTED) {\n return rows;\n }\n\n if (scope === null || scope === undefined) {\n // An update is already confined by the scoped `where`, which under `deny` matches no row; the\n // guard adds nothing there. A create has no such `where`, so an unresolved scope refuses it.\n if (\n settings.onMissing === ScopeFilterMissingBehaviors.ALLOW ||\n operation === ScopeWriteOperations.UPDATE\n ) {\n return rows;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: 'no scope could be resolved for this caller',\n });\n }\n\n const extraction = ScopeWriteGuard.extractConstraints({ where: scope });\n if (!extraction.isVerifiable) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope cannot be verified on a write | ${extraction.reason}`,\n });\n }\n\n const { constraints } = extraction;\n const declared = settings.columns;\n\n if (declared) {\n const undeclared = [...constraints.keys()].find((column) => !declared.includes(column));\n if (undeclared !== undefined) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n detail: `the resolved scope constrains column '${undeclared}', which access.columns does not declare`,\n });\n }\n }\n\n const isAssign = settings.write?.mode === ScopeWriteGuards.ASSIGN && operation === 'create';\n const sharedRows = settings.write?.sharedRows === true;\n\n return rows.map((row) => {\n let result = row;\n\n for (const [column, allowed] of constraints) {\n const value = (row as Record<string, unknown>)[column];\n\n if (value === undefined) {\n if (operation === 'update') {\n continue;\n }\n\n // `assign` first: stamping gives the row an owner, which is safer than leaving it shared.\n const only = allowed.size === 1 ? [...allowed][0] : undefined;\n if (isAssign && only !== undefined && only !== null) {\n result = { ...result, [column]: only };\n continue;\n }\n\n // Absent means the database default, usually `null`, so it is held to the `null` rule.\n if (sharedRows) {\n continue;\n }\n\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the scope column is missing',\n });\n }\n\n const normalised = isScalar(value) ? normalise(value) : undefined;\n // A `null` branch in the scope lets this caller READ shared rows. Writing one (or moving a\n // row into the shared set) is a separate permission: only `sharedRows` grants it.\n const isOutside = normalised === null ? !sharedRows : !allowed.has(normalised as string);\n\n if (normalised === undefined || isOutside) {\n throw ScopeWriteGuard.denied({\n model,\n operation,\n column,\n detail: 'the value is outside the resolved scope',\n });\n }\n }\n\n return result;\n });\n }\n\n /** Names the model and the column, never a value: the caller may be a request. */\n private static denied(opts: {\n model: string;\n operation: string;\n column?: string;\n detail: string;\n }) {\n const { model, operation, column, detail } = opts;\n\n return getError({\n statusCode: WRITE_DENIED_STATUS,\n messageCode: RepositoryErrorCodes.SCOPE_WRITE_DENIED,\n message: [\n `[${operation}] write refused by the access scope | entity: ${model}`,\n ...(column ? [`column: ${column}`] : []),\n detail,\n ].join(' | '),\n });\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TScopeWriteOperation } from '../common/constants';
|
|
1
2
|
import type { IdType, IExtraOptions, IPersistableRepository, IModelAccessSettings, ITransaction, TCount, TByIdFilter, TDataRange, TDrizzleQueryOptions, TFields, TFilter, TFindOneOptions, TFindOptions, TFindRangeOptions, TLockOptions, TRepositoryOperationScope, TRow, TWhere } from '@venizia/ignis-kernel';
|
|
2
3
|
import { AbstractRepository } from '@venizia/ignis-kernel';
|
|
3
4
|
import type { IRelationalDataSource } from '../../datasources/common';
|
|
@@ -48,10 +49,9 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
|
|
|
48
49
|
/**
|
|
49
50
|
* The model's `access` settings. Same override seam as `getDefaultFilter()` - a repository with no
|
|
50
51
|
* resolvable `@model` entity (a synthetic test double, a hand-built stub) overrides this to avoid
|
|
51
|
-
* touching `modelSettings`/`entity` at all.
|
|
52
|
-
* `access`, so an existing override keeps working.
|
|
52
|
+
* touching `modelSettings`/`entity` at all.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
getAccessSettings(): IModelAccessSettings | undefined;
|
|
55
55
|
/**
|
|
56
56
|
* Holds written rows to the resolved row scope (`access.write`): refuses a row outside
|
|
57
57
|
* it, and for `assign` returns copies with the scope columns filled in. Nothing is written when it
|
|
@@ -60,7 +60,7 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
|
|
|
60
60
|
*/
|
|
61
61
|
protected guardScopedWrite<Row extends Record<string, unknown>>(opts: {
|
|
62
62
|
rows: Row[];
|
|
63
|
-
operation:
|
|
63
|
+
operation: TScopeWriteOperation;
|
|
64
64
|
}): Row[];
|
|
65
65
|
/**
|
|
66
66
|
* Row scope from `@model` settings.access - AND-composed like a default filter, but never
|
|
@@ -75,12 +75,15 @@ export declare abstract class RelationalBaseRepository<EntitySchema extends TTab
|
|
|
75
75
|
protected applyScopeFilter<DO = any>(opts: {
|
|
76
76
|
userFilter?: TFilter<DO>;
|
|
77
77
|
dangerouslySkipScopeFilter?: boolean;
|
|
78
|
+
mutation?: string;
|
|
78
79
|
}): TFilter<DO>;
|
|
79
80
|
/** Merges default filter with user filter. Skippable via shouldSkipDefaultFilter - the row scope from applyScopeFilter is not. */
|
|
80
81
|
applyDefaultFilter<DO = any>(opts: {
|
|
81
82
|
userFilter?: TFilter<DO>;
|
|
82
83
|
shouldSkipDefaultFilter?: boolean;
|
|
83
84
|
dangerouslySkipScopeFilter?: boolean;
|
|
85
|
+
/** The name of the write (`update`, `delete`) when the filter selects rows to change: the row scope then leaves out the shared rows unless `write.sharedRows`. */
|
|
86
|
+
mutation?: string;
|
|
84
87
|
}): TFilter<DO>;
|
|
85
88
|
beginTransaction(opts?: TRelationalTransactionOptionsOf<TDataSource>): Promise<TRelationalTransactionOf<TDataSource>>;
|
|
86
89
|
/**
|