@opensaas/stack-core 0.44.0-alpha.5 → 0.44.0-alpha.7
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/CHANGELOG.md +1051 -0
- package/dist/.build-hash +1 -1
- package/dist/access/actor.d.ts +56 -0
- package/dist/access/actor.d.ts.map +1 -0
- package/dist/access/actor.js +66 -0
- package/dist/access/actor.js.map +1 -0
- package/dist/access/decide-advertisement.d.ts +55 -0
- package/dist/access/decide-advertisement.d.ts.map +1 -0
- package/dist/access/decide-advertisement.js +125 -0
- package/dist/access/decide-advertisement.js.map +1 -0
- package/dist/access/declared-dependencies.d.ts +4 -89
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +14 -84
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +2 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +2 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +1 -24
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +0 -35
- package/dist/access/engine.js.map +1 -1
- package/dist/access/field-access.d.ts +43 -19
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +206 -185
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/index.d.ts +5 -6
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -7
- package/dist/access/index.js.map +1 -1
- package/dist/access/rule-item.d.ts +42 -0
- package/dist/access/rule-item.d.ts.map +1 -0
- package/dist/access/rule-item.js +215 -0
- package/dist/access/rule-item.js.map +1 -0
- package/dist/access/session-vocabulary.d.ts +124 -0
- package/dist/access/session-vocabulary.d.ts.map +1 -0
- package/dist/access/session-vocabulary.js +366 -0
- package/dist/access/session-vocabulary.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +6 -0
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +19 -2
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +66 -0
- package/dist/access/types.d.ts.map +1 -1
- package/dist/access/vocabulary-filter-specs.d.ts +17 -0
- package/dist/access/vocabulary-filter-specs.d.ts.map +1 -0
- package/dist/access/vocabulary-filter-specs.js +27 -0
- package/dist/access/vocabulary-filter-specs.js.map +1 -0
- package/dist/client-safe.d.ts +8 -0
- package/dist/client-safe.d.ts.map +1 -0
- package/dist/client-safe.js +8 -0
- package/dist/client-safe.js.map +1 -0
- package/dist/config/field-kind.d.ts +7 -21
- package/dist/config/field-kind.d.ts.map +1 -1
- package/dist/config/field-kind.js +8 -5
- package/dist/config/field-kind.js.map +1 -1
- package/dist/config/has-access-gate.d.ts +20 -0
- package/dist/config/has-access-gate.d.ts.map +1 -0
- package/dist/config/has-access-gate.js +26 -0
- package/dist/config/has-access-gate.js.map +1 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +8 -2
- package/dist/config/index.js.map +1 -1
- package/dist/config/list-view-keys.d.ts +5 -0
- package/dist/config/list-view-keys.d.ts.map +1 -0
- package/dist/config/list-view-keys.js +18 -0
- package/dist/config/list-view-keys.js.map +1 -0
- package/dist/config/mcp-default-tools.d.ts +3 -0
- package/dist/config/mcp-default-tools.d.ts.map +1 -0
- package/dist/config/mcp-default-tools.js +14 -0
- package/dist/config/mcp-default-tools.js.map +1 -0
- package/dist/config/mcp-tool-names.d.ts +2 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -1
- package/dist/config/mcp-tool-names.js +17 -5
- package/dist/config/mcp-tool-names.js.map +1 -1
- package/dist/config/nav-count.d.ts +8 -16
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +20 -32
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +6 -0
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/preset-views.d.ts +22 -0
- package/dist/config/preset-views.d.ts.map +1 -0
- package/dist/config/preset-views.js +46 -0
- package/dist/config/preset-views.js.map +1 -0
- package/dist/config/row-action-availability.d.ts +4 -0
- package/dist/config/row-action-availability.d.ts.map +1 -0
- package/dist/config/row-action-availability.js +20 -0
- package/dist/config/row-action-availability.js.map +1 -0
- package/dist/config/types.d.ts +409 -34
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/engine-context.d.ts +2 -0
- package/dist/context/engine-context.d.ts.map +1 -1
- package/dist/context/engine-context.js +8 -0
- package/dist/context/engine-context.js.map +1 -1
- package/dist/context/hook-pipeline.d.ts +6 -1
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +6 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +10 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +217 -94
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +28 -21
- package/dist/context/junction.d.ts.map +1 -1
- package/dist/context/junction.js +74 -69
- package/dist/context/junction.js.map +1 -1
- package/dist/context/plugin-field-write.d.ts.map +1 -1
- package/dist/context/plugin-field-write.js +19 -25
- package/dist/context/plugin-field-write.js.map +1 -1
- package/dist/context/process-lifetime.d.ts +8 -0
- package/dist/context/process-lifetime.d.ts.map +1 -0
- package/dist/context/process-lifetime.js +14 -0
- package/dist/context/process-lifetime.js.map +1 -0
- package/dist/context/relationship-input.d.ts +2 -15
- package/dist/context/relationship-input.d.ts.map +1 -1
- package/dist/context/relationship-input.js +44 -85
- package/dist/context/relationship-input.js.map +1 -1
- package/dist/context/transaction-boundary.d.ts +3 -2
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +17 -2
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +5 -19
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +54 -92
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/context/write-target.d.ts +52 -0
- package/dist/context/write-target.d.ts.map +1 -0
- package/dist/context/write-target.js +118 -0
- package/dist/context/write-target.js.map +1 -0
- package/dist/contract/dependencies.d.ts +24 -10
- package/dist/contract/dependencies.d.ts.map +1 -1
- package/dist/contract/dependencies.js +120 -80
- package/dist/contract/dependencies.js.map +1 -1
- package/dist/contract/derive.d.ts +6 -11
- package/dist/contract/derive.d.ts.map +1 -1
- package/dist/contract/derive.js +256 -211
- package/dist/contract/derive.js.map +1 -1
- package/dist/contract/fixtures/contract-configs.d.ts +5 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -1
- package/dist/contract/fixtures/contract-configs.js +21 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -1
- package/dist/contract/id-boundary.js +1 -1
- package/dist/contract/id-boundary.js.map +1 -1
- package/dist/contract/prisma.js +2 -2
- package/dist/contract/prisma.js.map +1 -1
- package/dist/contract/strategy.d.ts +13 -0
- package/dist/contract/strategy.d.ts.map +1 -0
- package/dist/contract/strategy.js +38 -0
- package/dist/contract/strategy.js.map +1 -0
- package/dist/db/client-alias.d.ts +12 -0
- package/dist/db/client-alias.d.ts.map +1 -0
- package/dist/db/client-alias.js +8 -0
- package/dist/db/client-alias.js.map +1 -0
- package/dist/extend.d.ts +2 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +12 -14
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +217 -67
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +43 -25
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +107 -38
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +7 -5
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +6 -14
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +112 -20
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +271 -52
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/parse.d.ts +70 -26
- package/dist/filter/parse.d.ts.map +1 -1
- package/dist/filter/parse.js +212 -79
- package/dist/filter/parse.js.map +1 -1
- package/dist/filter/record-id.d.ts +19 -0
- package/dist/filter/record-id.d.ts.map +1 -0
- package/dist/filter/record-id.js +37 -0
- package/dist/filter/record-id.js.map +1 -0
- package/dist/filter/serialize.d.ts +45 -19
- package/dist/filter/serialize.d.ts.map +1 -1
- package/dist/filter/serialize.js +146 -50
- package/dist/filter/serialize.js.map +1 -1
- package/dist/filter/types.d.ts +132 -21
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +38 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +11 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +8 -8
- package/dist/internal.js.map +1 -1
- package/dist/lib/database-errors.d.ts +2 -1
- package/dist/lib/database-errors.d.ts.map +1 -1
- package/dist/lib/database-errors.js +5 -4
- package/dist/lib/database-errors.js.map +1 -1
- package/dist/mcp/advertise.d.ts +5 -13
- package/dist/mcp/advertise.d.ts.map +1 -1
- package/dist/mcp/advertise.js +7 -22
- package/dist/mcp/advertise.js.map +1 -1
- package/dist/mcp/arguments.d.ts.map +1 -1
- package/dist/mcp/arguments.js +8 -11
- package/dist/mcp/arguments.js.map +1 -1
- package/dist/mcp/field-schema.d.ts +4 -15
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +50 -69
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +111 -18
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +231 -87
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/procedure-tools.d.ts +63 -0
- package/dist/mcp/procedure-tools.d.ts.map +1 -0
- package/dist/mcp/procedure-tools.js +139 -0
- package/dist/mcp/procedure-tools.js.map +1 -0
- package/dist/mcp/projection.d.ts +6 -5
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +33 -38
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/reachability.d.ts +13 -0
- package/dist/mcp/reachability.d.ts.map +1 -0
- package/dist/mcp/reachability.js +51 -0
- package/dist/mcp/reachability.js.map +1 -0
- package/dist/mcp/relation-member.d.ts +15 -0
- package/dist/mcp/relation-member.d.ts.map +1 -0
- package/dist/mcp/relation-member.js +50 -0
- package/dist/mcp/relation-member.js.map +1 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.js +12 -24
- package/dist/mcp/where-id-boundary.js.map +1 -1
- package/dist/mcp/where-reachability.d.ts +10 -0
- package/dist/mcp/where-reachability.d.ts.map +1 -0
- package/dist/mcp/where-reachability.js +88 -0
- package/dist/mcp/where-reachability.js.map +1 -0
- package/dist/members/claims.d.ts +71 -0
- package/dist/members/claims.d.ts.map +1 -0
- package/dist/members/claims.js +199 -0
- package/dist/members/claims.js.map +1 -0
- package/dist/members/list-members.d.ts +87 -0
- package/dist/members/list-members.d.ts.map +1 -0
- package/dist/members/list-members.js +250 -0
- package/dist/members/list-members.js.map +1 -0
- package/dist/procedures/client.d.ts +163 -0
- package/dist/procedures/client.d.ts.map +1 -0
- package/dist/procedures/client.js +152 -0
- package/dist/procedures/client.js.map +1 -0
- package/dist/procedures/codes.d.ts +23 -0
- package/dist/procedures/codes.d.ts.map +1 -0
- package/dist/procedures/codes.js +46 -0
- package/dist/procedures/codes.js.map +1 -0
- package/dist/procedures/context-face.d.ts +4 -0
- package/dist/procedures/context-face.d.ts.map +1 -0
- package/dist/procedures/context-face.js +31 -0
- package/dist/procedures/context-face.js.map +1 -0
- package/dist/procedures/failures.d.ts +31 -0
- package/dist/procedures/failures.d.ts.map +1 -0
- package/dist/procedures/failures.js +51 -0
- package/dist/procedures/failures.js.map +1 -0
- package/dist/procedures/http.d.ts +114 -0
- package/dist/procedures/http.d.ts.map +1 -0
- package/dist/procedures/http.js +224 -0
- package/dist/procedures/http.js.map +1 -0
- package/dist/procedures/index.d.ts +7 -0
- package/dist/procedures/index.d.ts.map +1 -0
- package/dist/procedures/index.js +11 -0
- package/dist/procedures/index.js.map +1 -0
- package/dist/procedures/procedure.d.ts +204 -0
- package/dist/procedures/procedure.d.ts.map +1 -0
- package/dist/procedures/procedure.js +123 -0
- package/dist/procedures/procedure.js.map +1 -0
- package/dist/procedures/result.d.ts +42 -0
- package/dist/procedures/result.d.ts.map +1 -0
- package/dist/procedures/result.js +51 -0
- package/dist/procedures/result.js.map +1 -0
- package/dist/procedures/run.d.ts +36 -0
- package/dist/procedures/run.d.ts.map +1 -0
- package/dist/procedures/run.js +76 -0
- package/dist/procedures/run.js.map +1 -0
- package/dist/procedures/server.d.ts +131 -0
- package/dist/procedures/server.d.ts.map +1 -0
- package/dist/procedures/server.js +115 -0
- package/dist/procedures/server.js.map +1 -0
- package/dist/procedures/validate.d.ts +60 -0
- package/dist/procedures/validate.d.ts.map +1 -0
- package/dist/procedures/validate.js +254 -0
- package/dist/procedures/validate.js.map +1 -0
- package/dist/procedures/web-session.d.ts +12 -0
- package/dist/procedures/web-session.d.ts.map +1 -0
- package/dist/procedures/web-session.js +35 -0
- package/dist/procedures/web-session.js.map +1 -0
- package/dist/query/relationship-options.d.ts +8 -0
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +18 -4
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/binding.d.ts +84 -0
- package/dist/secured/binding.d.ts.map +1 -0
- package/dist/secured/binding.js +52 -0
- package/dist/secured/binding.js.map +1 -0
- package/dist/secured/declared-branch.d.ts +11 -0
- package/dist/secured/declared-branch.d.ts.map +1 -0
- package/dist/secured/declared-branch.js +17 -0
- package/dist/secured/declared-branch.js.map +1 -0
- package/dist/secured/field-visibility.d.ts +56 -0
- package/dist/secured/field-visibility.d.ts.map +1 -0
- package/dist/secured/field-visibility.js +624 -0
- package/dist/secured/field-visibility.js.map +1 -0
- package/dist/secured/include.d.ts +77 -37
- package/dist/secured/include.d.ts.map +1 -1
- package/dist/secured/include.js +228 -122
- package/dist/secured/include.js.map +1 -1
- package/dist/secured/lock.d.ts +8 -2
- package/dist/secured/lock.d.ts.map +1 -1
- package/dist/secured/lock.js +44 -15
- package/dist/secured/lock.js.map +1 -1
- package/dist/secured/lower.d.ts.map +1 -1
- package/dist/secured/lower.js +15 -4
- package/dist/secured/lower.js.map +1 -1
- package/dist/secured/read.d.ts +13 -52
- package/dist/secured/read.d.ts.map +1 -1
- package/dist/secured/read.js +88 -614
- package/dist/secured/read.js.map +1 -1
- package/dist/secured/select.d.ts +0 -24
- package/dist/secured/select.d.ts.map +1 -1
- package/dist/secured/select.js +60 -153
- package/dist/secured/select.js.map +1 -1
- package/dist/secured/vocabulary.d.ts +13 -1
- package/dist/secured/vocabulary.d.ts.map +1 -1
- package/dist/secured/vocabulary.js +173 -83
- package/dist/secured/vocabulary.js.map +1 -1
- package/dist/testing/untyped-rule.d.ts +8 -0
- package/dist/testing/untyped-rule.d.ts.map +1 -0
- package/dist/testing/untyped-rule.js +4 -0
- package/dist/testing/untyped-rule.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rows.d.ts +18 -1
- package/dist/types/rows.d.ts.map +1 -1
- package/dist/validation/config-refusal.d.ts +3 -1
- package/dist/validation/config-refusal.d.ts.map +1 -1
- package/dist/validation/database-config.d.ts +1 -15
- package/dist/validation/database-config.d.ts.map +1 -1
- package/dist/validation/database-config.js +32 -1
- package/dist/validation/database-config.js.map +1 -1
- package/dist/validation/default-value.d.ts.map +1 -1
- package/dist/validation/default-value.js +3 -8
- package/dist/validation/default-value.js.map +1 -1
- package/dist/validation/extension-packs.d.ts.map +1 -1
- package/dist/validation/extension-packs.js +1 -0
- package/dist/validation/extension-packs.js.map +1 -1
- package/dist/validation/field-config.d.ts +3 -2
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +3 -1
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +2 -1
- package/dist/validation/field-names.d.ts.map +1 -1
- package/dist/validation/field-names.js +76 -63
- package/dist/validation/field-names.js.map +1 -1
- package/dist/validation/identifier-names.d.ts +1 -0
- package/dist/validation/identifier-names.d.ts.map +1 -1
- package/dist/validation/identifier-names.js +17 -9
- package/dist/validation/identifier-names.js.map +1 -1
- package/dist/validation/needs-closure.d.ts +30 -14
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +184 -31
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts.map +1 -1
- package/dist/validation/relations.js +11 -0
- package/dist/validation/relations.js.map +1 -1
- package/dist/validation/schema.d.ts +4 -3
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +8 -6
- package/dist/validation/schema.js.map +1 -1
- package/package.json +26 -10
- package/dist/access/field-visibility.d.ts +0 -58
- package/dist/access/field-visibility.d.ts.map +0 -1
- package/dist/access/field-visibility.js +0 -383
- package/dist/access/field-visibility.js.map +0 -1
- package/dist/access/query-validation.d.ts +0 -30
- package/dist/access/query-validation.d.ts.map +0 -1
- package/dist/access/query-validation.js +0 -49
- package/dist/access/query-validation.js.map +0 -1
- package/dist/access/system-fields.d.ts +0 -2
- package/dist/access/system-fields.d.ts.map +0 -1
- package/dist/access/system-fields.js +0 -7
- package/dist/access/system-fields.js.map +0 -1
package/dist/context/index.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { checkAccess } from '../access/index.js';
|
|
2
|
-
import {
|
|
3
|
-
import { ValidationError, DatabaseError } from '../hooks/index.js';
|
|
2
|
+
import { bindSessionReadOnly, sealSession } from '../access/actor.js';
|
|
3
|
+
import { ValidationError, DatabaseError, isPlainObject } from '../hooks/index.js';
|
|
4
4
|
import { databaseErrorMessage, normalizeDatabaseError } from '../lib/prisma-errors.js';
|
|
5
5
|
import { isClientSafeError } from '../lib/client-safe-error.js';
|
|
6
6
|
import { nullPrototypeRegistry } from '../lib/null-prototype-registry.js';
|
|
7
7
|
import { warnOnce } from '../lib/warn-once.js';
|
|
8
8
|
import { createSecuredRead } from '../secured/read.js';
|
|
9
|
-
import {
|
|
9
|
+
import { invalidatesSessionVocabularyOf, withOwnSessionVocabulary, } from '../access/session-vocabulary.js';
|
|
10
|
+
import { withSingletonProbe } from './write-target.js';
|
|
11
|
+
import { createLivenessProbe, createRowLockLane, RowLockUnavailableError, RowLockLaneUnavailableError, unusableRowLockLane, } from '../secured/lock.js';
|
|
10
12
|
import { createUnsafeSurface, createUnsafeTransactionSurface, unavailableUnsafeSurface, } from '../unsafe.js';
|
|
11
13
|
import { ENGINE_FACE, engineContextOf } from './engine-context.js';
|
|
12
14
|
import { withOrigin } from '../origin.js';
|
|
13
|
-
import { getRelationshipOptions, isRelationshipLabelReadable, } from '../query/relationship-options.js';
|
|
15
|
+
import { getRelationshipOptions, isRelationshipLabelReadable, relationshipSearchWhere, } from '../query/relationship-options.js';
|
|
14
16
|
import { runWritePipeline, createWriteStrategy, updateWriteStrategy, deleteWriteStrategy, } from './write-pipeline.js';
|
|
15
|
-
import { resolveJunctionEdge,
|
|
16
|
-
import {
|
|
17
|
+
import { resolveJunctionEdge, resolveLinkableScope } from './junction.js';
|
|
18
|
+
import { assertListMembersResolve, resolveListMember, resolveListMembers, } from '../members/list-members.js';
|
|
17
19
|
import { parseListId } from '../contract/id-boundary.js';
|
|
18
20
|
import { reportAfterTransactionFailures } from './transaction-boundary.js';
|
|
21
|
+
import { isRowActionAvailable } from '../config/row-action-availability.js';
|
|
22
|
+
import { checkHasAccess } from '../config/has-access-gate.js';
|
|
19
23
|
import { TransactionRegistry, TransactionRolledBackError, } from '../access/transaction-registry.js';
|
|
20
24
|
export { TransactionRolledBackError };
|
|
25
|
+
const LINKED_TARGET_LIMIT = 1000;
|
|
21
26
|
/**
|
|
22
27
|
* Warn once per (list, operation) when a caller passes `select` to a read op
|
|
23
28
|
* that ignores it. See "Narrowing Reads" in packages/core/CLAUDE.md.
|
|
@@ -30,30 +35,30 @@ function warnIfSelectIgnored(args, listName, operation) {
|
|
|
30
35
|
`Narrow a read with \`include\`, or with \`.select()\` on the secured surface, instead. ` +
|
|
31
36
|
`See https://stack.opensaas.au/docs/concepts/queries`);
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
function classifyBackReference(listKey, fieldName, config) {
|
|
39
|
+
const member = resolveListMember(config, listKey, fieldName);
|
|
40
|
+
if (member === undefined)
|
|
41
|
+
return { kind: 'notRelationship' };
|
|
42
|
+
switch (member.kind) {
|
|
43
|
+
case 'field': {
|
|
44
|
+
const { storage } = member;
|
|
45
|
+
if (storage.kind !== 'relation')
|
|
46
|
+
return { kind: 'notRelationship' };
|
|
47
|
+
return storage.foreignKey === undefined
|
|
48
|
+
? { kind: 'nonOwning' }
|
|
49
|
+
: { kind: 'owning', relatedList: storage.relatedList, foreignKey: storage.foreignKey.name };
|
|
50
|
+
}
|
|
51
|
+
case 'syntheticBackRelation':
|
|
52
|
+
return { kind: 'nonOwning' };
|
|
53
|
+
case 'foreignKey':
|
|
54
|
+
case 'partColumn':
|
|
55
|
+
case 'systemField':
|
|
56
|
+
return { kind: 'notRelationship' };
|
|
57
|
+
default: {
|
|
58
|
+
const unhandled = member;
|
|
59
|
+
return unhandled;
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
|
-
return resolveSyntheticReverseRelation(fieldName, listKey, config) !== null
|
|
55
|
-
? { kind: 'nonOwning' }
|
|
56
|
-
: { kind: 'notRelationship' };
|
|
57
62
|
}
|
|
58
63
|
function isRawRowCollection(value) {
|
|
59
64
|
return (typeof value === 'object' &&
|
|
@@ -90,12 +95,8 @@ function assertIdentityWhere(where, listName, terminal) {
|
|
|
90
95
|
], {});
|
|
91
96
|
}
|
|
92
97
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
return false;
|
|
96
|
-
if (typeof listConfig.isSingleton === 'boolean')
|
|
97
|
-
return true;
|
|
98
|
-
return listConfig.isSingleton.autoCreate !== false;
|
|
98
|
+
function autoCreates(listConfig) {
|
|
99
|
+
return typeof listConfig.isSingleton !== 'object' || listConfig.isSingleton.autoCreate !== false;
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
102
|
* Thrown when `context.transaction()` can neither open a transaction nor join
|
|
@@ -342,13 +343,19 @@ function transactionFace(base, lock, owner) {
|
|
|
342
343
|
advisoryLock: async (key) => {
|
|
343
344
|
if (lock === undefined)
|
|
344
345
|
throw new RowLockUnavailableError('advisoryLock()');
|
|
345
|
-
|
|
346
|
+
try {
|
|
347
|
+
await lock.advisory(key);
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
owner.poison(error);
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
346
353
|
},
|
|
347
354
|
sudo: () => transactionFace(base.sudo(), lock, owner),
|
|
348
355
|
withSession: (session) => transactionFace(base.withSession(session), lock, owner),
|
|
349
356
|
transaction: (fn) => joinNested(fn, face, owner),
|
|
350
357
|
};
|
|
351
|
-
return face;
|
|
358
|
+
return bindSessionReadOnly(face);
|
|
352
359
|
}
|
|
353
360
|
// A database failure reaches the client as the stack's own message (ADR-0042),
|
|
354
361
|
// so the driver's diagnostic text — carried on `cause` — reaches no channel at
|
|
@@ -359,6 +366,7 @@ function logDatabaseFailure(error, listKey, action) {
|
|
|
359
366
|
return;
|
|
360
367
|
console.error(`Database error on "${action}" for list "${listKey}":`, error.cause ?? error);
|
|
361
368
|
}
|
|
369
|
+
const ROW_ACTION_NOT_RUN = 'This action was not run';
|
|
362
370
|
function clientFailure(error, config, listKey, action, options = {}) {
|
|
363
371
|
const classifier = config.ui?.classifyActionError;
|
|
364
372
|
if (classifier) {
|
|
@@ -443,7 +451,7 @@ function assertValidSession(session) {
|
|
|
443
451
|
if (undefinedKeys.length > 0)
|
|
444
452
|
throw new InvalidSessionError(undefinedKeys);
|
|
445
453
|
}
|
|
446
|
-
export function getContext(config, ormHandle,
|
|
454
|
+
export function getContext(config, ormHandle, givenSession, storage, _isSudo = false,
|
|
447
455
|
// Internal: when rebuilding the context against a transaction client, reuse the
|
|
448
456
|
// already-initialised plugin services rather than re-running plugin runtimes.
|
|
449
457
|
_sharedPlugins,
|
|
@@ -471,7 +479,8 @@ _unsafeTransaction,
|
|
|
471
479
|
// carried through by `sudo()`/`withSession()` unchanged; omitted for a
|
|
472
480
|
// fresh, non-transactional context, which is its own base.
|
|
473
481
|
_baseContext) {
|
|
474
|
-
assertValidSession(
|
|
482
|
+
assertValidSession(givenSession);
|
|
483
|
+
const session = givenSession === null ? null : sealSession(givenSession);
|
|
475
484
|
// Broad type to allow dynamic model access; populated by populateDbDelegate below.
|
|
476
485
|
const db = {};
|
|
477
486
|
const openTransaction = transactionOpenerFor(config, client, _unsafeTransaction);
|
|
@@ -514,6 +523,8 @@ _baseContext) {
|
|
|
514
523
|
_config: config,
|
|
515
524
|
_baseContext,
|
|
516
525
|
};
|
|
526
|
+
withOwnSessionVocabulary(context, config);
|
|
527
|
+
withSingletonProbe(context);
|
|
517
528
|
populateDbDelegate(db, config, ormHandle, context, lock);
|
|
518
529
|
// Skipped when reusing shared plugins (transaction rebind) so runtimes — and
|
|
519
530
|
// any side effects they carry — run exactly once per top-level context.
|
|
@@ -590,22 +601,15 @@ _baseContext) {
|
|
|
590
601
|
error: `Bulk action "${props.key}" not found on list "${props.listKey}"`,
|
|
591
602
|
};
|
|
592
603
|
}
|
|
604
|
+
if (!(await checkHasAccess(action, context, props.listKey, 'Bulk action'))) {
|
|
605
|
+
return { bulkAction: false, error: 'Access denied' };
|
|
606
|
+
}
|
|
593
607
|
try {
|
|
594
|
-
|
|
595
|
-
const allowed = await action.hasAccess({
|
|
596
|
-
session: context.session,
|
|
597
|
-
context,
|
|
598
|
-
listKey: props.listKey,
|
|
599
|
-
});
|
|
600
|
-
if (!allowed) {
|
|
601
|
-
return { bulkAction: false, error: 'Access denied' };
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
const result = await action.handler({
|
|
608
|
+
const result = await transaction(async (tx) => action.handler({
|
|
605
609
|
listKey: props.listKey,
|
|
606
610
|
ids: props.ids,
|
|
607
|
-
context,
|
|
608
|
-
});
|
|
611
|
+
context: engineContextOf(tx),
|
|
612
|
+
}));
|
|
609
613
|
return { bulkAction: true, message: result?.message };
|
|
610
614
|
}
|
|
611
615
|
catch (error) {
|
|
@@ -615,6 +619,56 @@ _baseContext) {
|
|
|
615
619
|
return { bulkAction: false, error: failure.error, code: failure.code };
|
|
616
620
|
}
|
|
617
621
|
}
|
|
622
|
+
// A missing row, a denied row, a failed `hasAccess` and a row that is no
|
|
623
|
+
// longer eligible all answer with this one outcome, so a caller cannot tell
|
|
624
|
+
// them apart (Silent failure).
|
|
625
|
+
if (props.action === 'rowAction') {
|
|
626
|
+
const notRun = { rowAction: false, error: ROW_ACTION_NOT_RUN };
|
|
627
|
+
const rowActions = listConfig.ui?.listView?.rowActions ?? [];
|
|
628
|
+
const action = rowActions.find((a) => a.key === props.key);
|
|
629
|
+
if (!action) {
|
|
630
|
+
return {
|
|
631
|
+
rowAction: false,
|
|
632
|
+
error: `Row action "${props.key}" not found on list "${props.listKey}"`,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
const id = parseId(props.listKey, props.id);
|
|
636
|
+
if (id === null)
|
|
637
|
+
return notRun;
|
|
638
|
+
if (!(await checkHasAccess(action, context, props.listKey, 'Row action')))
|
|
639
|
+
return notRun;
|
|
640
|
+
try {
|
|
641
|
+
return await transaction(async (tx) => {
|
|
642
|
+
const list = tx.db[props.listKey];
|
|
643
|
+
const locked = await list
|
|
644
|
+
.where({ id: { equals: id } })
|
|
645
|
+
.forUpdate()
|
|
646
|
+
.first();
|
|
647
|
+
if (locked === null)
|
|
648
|
+
return notRun;
|
|
649
|
+
const item = await list.where({ id: { equals: id } }).first();
|
|
650
|
+
if (item === null)
|
|
651
|
+
return notRun;
|
|
652
|
+
const txContext = engineContextOf(tx);
|
|
653
|
+
if (!isRowActionAvailable(action, props.listKey, item, txContext.session)) {
|
|
654
|
+
return notRun;
|
|
655
|
+
}
|
|
656
|
+
const result = await action.handler({
|
|
657
|
+
listKey: props.listKey,
|
|
658
|
+
id,
|
|
659
|
+
item,
|
|
660
|
+
context: txContext,
|
|
661
|
+
});
|
|
662
|
+
return { rowAction: true, message: result?.message };
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
const failure = clientFailure(error, config, props.listKey, props.action, {
|
|
667
|
+
genericMessage: 'Action failed',
|
|
668
|
+
});
|
|
669
|
+
return { rowAction: false, error: failure.error, code: failure.code };
|
|
670
|
+
}
|
|
671
|
+
}
|
|
618
672
|
// Runs on the RELATED row (ADR-0018 boundary — see ServerActionProps above).
|
|
619
673
|
// Honours Silent failure: an access-denied operation returns `null`, which
|
|
620
674
|
// becomes `{ removed: false }` with a generic reason — never leaking whether
|
|
@@ -639,7 +693,7 @@ _baseContext) {
|
|
|
639
693
|
if (!props.field) {
|
|
640
694
|
return { removed: false, error: 'Missing back-reference field for disconnect' };
|
|
641
695
|
}
|
|
642
|
-
const backRef = classifyBackReference(props.listKey, props.field,
|
|
696
|
+
const backRef = classifyBackReference(props.listKey, props.field, config);
|
|
643
697
|
if (backRef.kind === 'notRelationship') {
|
|
644
698
|
return {
|
|
645
699
|
removed: false,
|
|
@@ -665,9 +719,8 @@ _baseContext) {
|
|
|
665
719
|
// owning foreign-key column `<field>Id` (relationship-input.ts),
|
|
666
720
|
// which is the key a bare read (no `include`) returns it under.
|
|
667
721
|
const fieldName = props.field;
|
|
668
|
-
const foreignKeyColumn =
|
|
669
|
-
const
|
|
670
|
-
const expectedParentId = parseId(parentListKey, props.parentId);
|
|
722
|
+
const foreignKeyColumn = backRef.foreignKey;
|
|
723
|
+
const expectedParentId = parseId(backRef.relatedList, props.parentId);
|
|
671
724
|
if (expectedParentId === null) {
|
|
672
725
|
return { removed: false, error: 'Access denied or operation failed' };
|
|
673
726
|
}
|
|
@@ -764,7 +817,7 @@ _baseContext) {
|
|
|
764
817
|
}
|
|
765
818
|
const data = { ...props.data };
|
|
766
819
|
if (props.field && props.parentId) {
|
|
767
|
-
const backRef = classifyBackReference(props.listKey, props.field,
|
|
820
|
+
const backRef = classifyBackReference(props.listKey, props.field, config);
|
|
768
821
|
// The back-reference must name a relationship field on this list; a
|
|
769
822
|
// non-relationship field would otherwise receive a nonsensical
|
|
770
823
|
// { connect } value. Also hardening — the drawer only ever passes a
|
|
@@ -786,7 +839,7 @@ _baseContext) {
|
|
|
786
839
|
`Link the parent from the side that holds the column.`,
|
|
787
840
|
};
|
|
788
841
|
}
|
|
789
|
-
const parentId = parseId(backRef.
|
|
842
|
+
const parentId = parseId(backRef.relatedList, props.parentId);
|
|
790
843
|
if (parentId === null) {
|
|
791
844
|
return { created: false, error: 'Access denied or operation failed' };
|
|
792
845
|
}
|
|
@@ -862,26 +915,26 @@ _baseContext) {
|
|
|
862
915
|
// update returns `null`, surfaced as `{ linked: false }` with a generic
|
|
863
916
|
// reason.
|
|
864
917
|
if (props.action === 'linkRelated') {
|
|
865
|
-
const backRef = classifyBackReference(props.listKey, props.field, listConfig, config);
|
|
866
|
-
if (backRef.kind === 'notRelationship') {
|
|
867
|
-
return {
|
|
868
|
-
linked: false,
|
|
869
|
-
error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
if (backRef.kind === 'nonOwning') {
|
|
873
|
-
return {
|
|
874
|
-
linked: false,
|
|
875
|
-
error: `Cannot link through "${props.field}": a non-owning back-reference owns no foreign key. ` +
|
|
876
|
-
`Link the parent from the side that holds the column.`,
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
const relatedId = parseId(props.listKey, props.id);
|
|
880
|
-
const parentId = parseId(backRef.field.ref.split('.')[0], props.parentId);
|
|
881
|
-
if (relatedId === null || parentId === null) {
|
|
882
|
-
return { linked: false, error: 'Access denied or operation failed' };
|
|
883
|
-
}
|
|
884
918
|
try {
|
|
919
|
+
const backRef = classifyBackReference(props.listKey, props.field, config);
|
|
920
|
+
if (backRef.kind === 'notRelationship') {
|
|
921
|
+
return {
|
|
922
|
+
linked: false,
|
|
923
|
+
error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
if (backRef.kind === 'nonOwning') {
|
|
927
|
+
return {
|
|
928
|
+
linked: false,
|
|
929
|
+
error: `Cannot link through "${props.field}": a non-owning back-reference owns no foreign key. ` +
|
|
930
|
+
`Link the parent from the side that holds the column.`,
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
const relatedId = parseId(props.listKey, props.id);
|
|
934
|
+
const parentId = parseId(backRef.relatedList, props.parentId);
|
|
935
|
+
if (relatedId === null || parentId === null) {
|
|
936
|
+
return { linked: false, error: 'Access denied or operation failed' };
|
|
937
|
+
}
|
|
885
938
|
const result = await model.update({
|
|
886
939
|
where: { id: relatedId },
|
|
887
940
|
data: { [props.field]: { connect: { id: parentId } } },
|
|
@@ -927,15 +980,44 @@ _baseContext) {
|
|
|
927
980
|
error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
|
|
928
981
|
};
|
|
929
982
|
}
|
|
930
|
-
const
|
|
983
|
+
const linkedTargetIds = async (linkable) => {
|
|
984
|
+
const rows = await context.db[linkable.junctionListKey]
|
|
985
|
+
.where(linkable.linkedRows)
|
|
986
|
+
.limit(LINKED_TARGET_LIMIT)
|
|
987
|
+
.all();
|
|
988
|
+
return rows.flatMap((row) => {
|
|
989
|
+
const id = row[linkable.targetForeignKey];
|
|
990
|
+
return typeof id === 'string' || typeof id === 'number' ? [id] : [];
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
let relatedListKey = fieldConfig.ref.split('.')[0];
|
|
994
|
+
let scope;
|
|
995
|
+
if (props.linkableFor !== undefined) {
|
|
996
|
+
const parentId = parseId(props.listKey, props.linkableFor);
|
|
997
|
+
if (parentId === null)
|
|
998
|
+
return { options: [], searched: false };
|
|
999
|
+
const linkable = resolveLinkableScope(config, props.listKey, props.field, parentId);
|
|
1000
|
+
if (linkable === null)
|
|
1001
|
+
return { options: [], searched: false };
|
|
1002
|
+
relatedListKey = linkable.listKey;
|
|
1003
|
+
scope =
|
|
1004
|
+
linkable.kind === 'where'
|
|
1005
|
+
? linkable.where
|
|
1006
|
+
: { id: { notIn: await linkedTargetIds(linkable) } };
|
|
1007
|
+
}
|
|
931
1008
|
const labelReadable = await isRelationshipLabelReadable(context, config, relatedListKey);
|
|
932
1009
|
const options = await getRelationshipOptions(context, config, relatedListKey, {
|
|
933
1010
|
labelReadable,
|
|
934
1011
|
search: props.search,
|
|
935
1012
|
take: props.take,
|
|
936
1013
|
selectedIds: props.selectedIds,
|
|
1014
|
+
scope,
|
|
937
1015
|
});
|
|
938
|
-
|
|
1016
|
+
const searched = relationshipSearchWhere(config, relatedListKey, {
|
|
1017
|
+
search: props.search,
|
|
1018
|
+
labelReadable,
|
|
1019
|
+
}) !== undefined;
|
|
1020
|
+
return { options, searched };
|
|
939
1021
|
}
|
|
940
1022
|
let result = null;
|
|
941
1023
|
if (props.action === 'create') {
|
|
@@ -966,24 +1048,24 @@ _baseContext) {
|
|
|
966
1048
|
}
|
|
967
1049
|
// Bypasses access control; hooks and validation still run.
|
|
968
1050
|
function sudo() {
|
|
969
|
-
return getContext(config, ormHandle, session, context.storage, true, undefined,
|
|
1051
|
+
return vocabularyDerivedFrom(context, getContext(config, ormHandle, session, context.storage, true, undefined,
|
|
970
1052
|
// ADR-0028: a sudo write issued from inside an owned transaction (e.g.
|
|
971
1053
|
// `tx.sudo().db.x.create()`) must still defer to that owner.
|
|
972
1054
|
context._transactionOwner, client, _unsafeTransaction,
|
|
973
1055
|
// Carry the same base-client context forward (issue #1348) — sudo()
|
|
974
1056
|
// derives a new context, not a new transaction boundary.
|
|
975
|
-
context._baseContext);
|
|
1057
|
+
context._baseContext));
|
|
976
1058
|
}
|
|
977
1059
|
// Substitutes the session; access control and hooks still run against it
|
|
978
1060
|
// (orthogonal to `sudo`, so the receiver's sudo state is preserved).
|
|
979
1061
|
function withSession(newSession) {
|
|
980
|
-
return getContext(config, ormHandle, newSession, context.storage, _isSudo, undefined,
|
|
1062
|
+
return vocabularyDerivedFrom(context, getContext(config, ormHandle, newSession, context.storage, _isSudo, undefined,
|
|
981
1063
|
// ADR-0028: a write issued from inside an owned transaction (e.g.
|
|
982
1064
|
// `tx.withSession(s).db.x.create()`) must still defer to that owner.
|
|
983
1065
|
context._transactionOwner, client, _unsafeTransaction,
|
|
984
1066
|
// Carry the same base-client context forward (issue #1348) — withSession()
|
|
985
1067
|
// derives a new context, not a new transaction boundary.
|
|
986
|
-
context._baseContext);
|
|
1068
|
+
context._baseContext));
|
|
987
1069
|
}
|
|
988
1070
|
// Interactive, hook-firing transaction (#614). See the `transaction` doc on
|
|
989
1071
|
// `StackContext` above for the atomicity/isolation/retry contract.
|
|
@@ -1002,7 +1084,11 @@ _baseContext) {
|
|
|
1002
1084
|
}
|
|
1003
1085
|
const registry = new TransactionRegistry();
|
|
1004
1086
|
const ormClient = ormHandle;
|
|
1005
|
-
const settled = runTransactionBody(fn, registry, ormClient)
|
|
1087
|
+
const settled = runTransactionBody(fn, registry, ormClient).then((result) => {
|
|
1088
|
+
if (registry.hasWritten)
|
|
1089
|
+
context._invalidateSessionVocabulary?.();
|
|
1090
|
+
return result;
|
|
1091
|
+
});
|
|
1006
1092
|
return settleTransactionOwner(settled, registry, config);
|
|
1007
1093
|
}
|
|
1008
1094
|
function runTransactionBody(fn, registry, ormClient) {
|
|
@@ -1067,7 +1153,12 @@ _baseContext) {
|
|
|
1067
1153
|
_isSudo,
|
|
1068
1154
|
[ENGINE_FACE]: context,
|
|
1069
1155
|
};
|
|
1070
|
-
|
|
1156
|
+
bindSessionReadOnly(context);
|
|
1157
|
+
return bindSessionReadOnly(returned);
|
|
1158
|
+
}
|
|
1159
|
+
function vocabularyDerivedFrom(receiver, derived) {
|
|
1160
|
+
invalidatesSessionVocabularyOf(engineContextOf(derived), receiver);
|
|
1161
|
+
return derived;
|
|
1071
1162
|
}
|
|
1072
1163
|
/**
|
|
1073
1164
|
* Complete the normalisation the engine terminal started, for a write.
|
|
@@ -1105,6 +1196,7 @@ function resolvingConstraints(operation, config) {
|
|
|
1105
1196
|
export function populateDbDelegate(target, config, ormHandle, context,
|
|
1106
1197
|
/** The row-lock lane, on a transaction-bound context alone (ADR-0047). */
|
|
1107
1198
|
lock) {
|
|
1199
|
+
const listMembers = assertListMembersResolve(config);
|
|
1108
1200
|
for (const [listName, listConfig] of Object.entries(config.lists)) {
|
|
1109
1201
|
const createOp = resolvingConstraints(createCreate(listName, listConfig, ormHandle, context, config), config);
|
|
1110
1202
|
const updateOp = resolvingConstraints(createUpdate(listName, listConfig, ormHandle, context, config), config);
|
|
@@ -1113,9 +1205,17 @@ lock) {
|
|
|
1113
1205
|
update: updateOp,
|
|
1114
1206
|
delete: resolvingConstraints(createDelete(listName, listConfig, ormHandle, context, config), config),
|
|
1115
1207
|
};
|
|
1116
|
-
const read = createSecuredRead({
|
|
1117
|
-
|
|
1118
|
-
|
|
1208
|
+
const read = createSecuredRead({
|
|
1209
|
+
listName,
|
|
1210
|
+
listConfig,
|
|
1211
|
+
ormHandle,
|
|
1212
|
+
context,
|
|
1213
|
+
config,
|
|
1214
|
+
rebindDb: rebindDb(config),
|
|
1215
|
+
lock,
|
|
1216
|
+
});
|
|
1217
|
+
if (listMembers.get(listName)?.singleton === true) {
|
|
1218
|
+
operations.get = resolvingConstraints(createGet(listName, listConfig, read, context, createOp, lock), config);
|
|
1119
1219
|
}
|
|
1120
1220
|
else {
|
|
1121
1221
|
operations.where = read.where;
|
|
@@ -1151,6 +1251,10 @@ export function buildDbDelegate(config, ormHandle, context) {
|
|
|
1151
1251
|
populateDbDelegate(db, config, ormHandle, context, context._rowLock);
|
|
1152
1252
|
return db;
|
|
1153
1253
|
}
|
|
1254
|
+
/** The read binding's `rebindDb`: a hook's `context.db`, built against the hook's own context. */
|
|
1255
|
+
export function rebindDb(config) {
|
|
1256
|
+
return (derived) => buildDbDelegate(config, derived.ormHandle, derived);
|
|
1257
|
+
}
|
|
1154
1258
|
const WRITE_ARG_KEYS = {
|
|
1155
1259
|
create: ['data'],
|
|
1156
1260
|
update: ['where', 'data'],
|
|
@@ -1161,6 +1265,9 @@ function assertWriteArgs(args, listName, operation, isSingleton) {
|
|
|
1161
1265
|
if (args === null || typeof args !== 'object') {
|
|
1162
1266
|
throw new ValidationError([`${operation}() on "${listName}" takes an argument object with ${allowed.join(', ')}.`], {});
|
|
1163
1267
|
}
|
|
1268
|
+
if (operation !== 'delete' && !isPlainObject(Reflect.get(args, 'data'))) {
|
|
1269
|
+
throw new ValidationError([`${operation}() on "${listName}" takes \`data\` as an object of field values.`], {});
|
|
1270
|
+
}
|
|
1164
1271
|
for (const [key, value] of Object.entries(args)) {
|
|
1165
1272
|
if (allowed.includes(key) || value === undefined)
|
|
1166
1273
|
continue;
|
|
@@ -1180,7 +1287,7 @@ listConfig, ormHandle, context, config) {
|
|
|
1180
1287
|
// Thin adapter over the Write Pipeline: pick the create strategy, run the
|
|
1181
1288
|
// canonical secured write sequence, return its result.
|
|
1182
1289
|
return async (args) => {
|
|
1183
|
-
assertWriteArgs(args, listName, 'create',
|
|
1290
|
+
assertWriteArgs(args, listName, 'create', resolveListMembers(config, listName).singleton);
|
|
1184
1291
|
return runWritePipeline({
|
|
1185
1292
|
listName,
|
|
1186
1293
|
listConfig,
|
|
@@ -1188,7 +1295,7 @@ listConfig, ormHandle, context, config) {
|
|
|
1188
1295
|
context,
|
|
1189
1296
|
config,
|
|
1190
1297
|
inputData: args.data,
|
|
1191
|
-
strategy: createWriteStrategy(listName, listConfig),
|
|
1298
|
+
strategy: createWriteStrategy(listName, listConfig, config),
|
|
1192
1299
|
});
|
|
1193
1300
|
};
|
|
1194
1301
|
}
|
|
@@ -1200,7 +1307,7 @@ listConfig, ormHandle, context, config) {
|
|
|
1200
1307
|
return async (args) => {
|
|
1201
1308
|
// Runs before the pipeline's access gate — a `where` the engine cannot
|
|
1202
1309
|
// lower is the caller's own shape error, not a denial.
|
|
1203
|
-
assertWriteArgs(args, listName, 'update',
|
|
1310
|
+
assertWriteArgs(args, listName, 'update', resolveListMembers(config, listName).singleton);
|
|
1204
1311
|
assertIdentityWhere(args.where, listName, 'update');
|
|
1205
1312
|
return runWritePipeline({
|
|
1206
1313
|
listName,
|
|
@@ -1219,7 +1326,7 @@ listConfig, ormHandle, context, config) {
|
|
|
1219
1326
|
// Thin adapter over the Write Pipeline: pick the delete strategy, run the
|
|
1220
1327
|
// canonical secured write sequence, return its result.
|
|
1221
1328
|
return async (args) => {
|
|
1222
|
-
assertWriteArgs(args, listName, 'delete',
|
|
1329
|
+
assertWriteArgs(args, listName, 'delete', resolveListMembers(config, listName).singleton);
|
|
1223
1330
|
assertIdentityWhere(args.where, listName, 'delete');
|
|
1224
1331
|
return runWritePipeline({
|
|
1225
1332
|
listName,
|
|
@@ -1271,9 +1378,20 @@ function assertBooleanInclude(include, listName) {
|
|
|
1271
1378
|
* so the create is refused and `get()` answers `null` — the same `null` a
|
|
1272
1379
|
* denied or an absent row answers with.
|
|
1273
1380
|
*/
|
|
1381
|
+
async function tookSingletonLock(lock, listName) {
|
|
1382
|
+
try {
|
|
1383
|
+
await lock.advisory(`opensaas:singleton-create:${listName}`);
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
catch (error) {
|
|
1387
|
+
if (error instanceof RowLockLaneUnavailableError)
|
|
1388
|
+
return false;
|
|
1389
|
+
throw error;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1274
1392
|
function createGet(listName,
|
|
1275
1393
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
1276
|
-
listConfig, read, context, createFn) {
|
|
1394
|
+
listConfig, read, context, createFn, lock) {
|
|
1277
1395
|
return async (args) => {
|
|
1278
1396
|
warnIfSelectIgnored(args, listName, 'get');
|
|
1279
1397
|
assertBooleanInclude(args?.include, listName);
|
|
@@ -1281,7 +1399,7 @@ listConfig, read, context, createFn) {
|
|
|
1281
1399
|
const item = await scoped.first();
|
|
1282
1400
|
if (item)
|
|
1283
1401
|
return item;
|
|
1284
|
-
if (!
|
|
1402
|
+
if (!autoCreates(listConfig))
|
|
1285
1403
|
return null;
|
|
1286
1404
|
// `first()` conflates denied with absent, and auto-create must fire only on
|
|
1287
1405
|
// absent — a denied session that provoked a create would both write a row it
|
|
@@ -1298,6 +1416,11 @@ listConfig, read, context, createFn) {
|
|
|
1298
1416
|
if (readable !== true)
|
|
1299
1417
|
return null;
|
|
1300
1418
|
}
|
|
1419
|
+
if (lock !== undefined && (await tookSingletonLock(lock, listName))) {
|
|
1420
|
+
const settled = await scoped.first();
|
|
1421
|
+
if (settled)
|
|
1422
|
+
return settled;
|
|
1423
|
+
}
|
|
1301
1424
|
try {
|
|
1302
1425
|
await createFn({ data: {} });
|
|
1303
1426
|
}
|