@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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReservedFailureCode } from './codes.js';
|
|
2
|
+
export { FAILURE_STATUS, isReservedFailureCode, RESERVED_FAILURE_CODES, type ReservedFailureCode, } from './codes.js';
|
|
3
|
+
/**
|
|
4
|
+
* A failed call. `code` is a reserved code or one the procedure declares.
|
|
5
|
+
* `fieldErrors` is present when the failure names fields: on `INVALID_INPUT`
|
|
6
|
+
* and `VALIDATION`, and on a `CONFLICT` raised by a unique constraint the
|
|
7
|
+
* generator emitted, where it names the fields that collided. A `CONFLICT`'s
|
|
8
|
+
* keys are the list's field names, which need not be keys of the procedure's
|
|
9
|
+
* input.
|
|
10
|
+
*
|
|
11
|
+
* `RETRY` says the transaction that lost a race was rolled back. It does not
|
|
12
|
+
* say that work outside the transaction was undone, and nothing retries the
|
|
13
|
+
* call automatically: the caller decides whether running it again is safe.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam TCode - the failure codes the procedure declares.
|
|
16
|
+
*/
|
|
17
|
+
export interface ProcedureFailure<TCode extends string = never> {
|
|
18
|
+
code: ReservedFailureCode | TCode;
|
|
19
|
+
message: string;
|
|
20
|
+
fieldErrors?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/** The result of calling a procedure, on every surface. */
|
|
23
|
+
export type ProcedureResult<TData, TCode extends string = never> = {
|
|
24
|
+
success: true;
|
|
25
|
+
data: TData;
|
|
26
|
+
} | {
|
|
27
|
+
success: false;
|
|
28
|
+
error: ProcedureFailure<TCode>;
|
|
29
|
+
};
|
|
30
|
+
export declare function failure(code: ReservedFailureCode, detail?: {
|
|
31
|
+
message?: string;
|
|
32
|
+
fieldErrors?: Record<string, string>;
|
|
33
|
+
}): {
|
|
34
|
+
success: false;
|
|
35
|
+
error: ProcedureFailure;
|
|
36
|
+
};
|
|
37
|
+
/** The failure a thrown error becomes, with `report` told of what an operator should see. See ADR-0086. */
|
|
38
|
+
export declare function failureFromError(error: unknown, report: (error: unknown) => void): {
|
|
39
|
+
success: false;
|
|
40
|
+
error: ProcedureFailure;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/procedures/result.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK;IAC5D,IAAI,EAAE,mBAAmB,GAAG,KAAK,CAAA;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;AAED,2DAA2D;AAC3D,MAAM,MAAM,eAAe,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,GAAG,KAAK,IAC7D;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;CAAE,CAAA;AAYrF,wBAAgB,OAAO,CACrB,IAAI,EAAE,mBAAmB,EACzB,MAAM,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GACtE;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAM7C;AAYD,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAC/B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAgB7C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AccessScopeDepthExceededError, ResolveOutputCycleError } from '../access/errors.js';
|
|
2
|
+
import { MalformedRelationInputError, NestedRelationInputError, NonOwningRelationInputError, } from '../context/relationship-input.js';
|
|
3
|
+
import { ValidationError } from '../hooks/index.js';
|
|
4
|
+
import { isClientSafeError } from '../lib/client-safe-error.js';
|
|
5
|
+
import { DatabaseError, isSerializationFailure, isUniqueConstraintViolation, } from '../lib/database-errors.js';
|
|
6
|
+
export { FAILURE_STATUS, isReservedFailureCode, RESERVED_FAILURE_CODES, } from './codes.js';
|
|
7
|
+
const MESSAGES = {
|
|
8
|
+
UNAUTHENTICATED: 'Authentication required',
|
|
9
|
+
DENIED: 'Access denied',
|
|
10
|
+
INVALID_INPUT: 'Invalid input',
|
|
11
|
+
VALIDATION: 'Validation failed',
|
|
12
|
+
RETRY: 'The operation conflicted with a concurrent change and was rolled back',
|
|
13
|
+
CONFLICT: 'The operation conflicted with existing data',
|
|
14
|
+
INTERNAL: 'Internal error',
|
|
15
|
+
};
|
|
16
|
+
export function failure(code, detail = {}) {
|
|
17
|
+
const error = { code, message: detail.message ?? MESSAGES[code] };
|
|
18
|
+
if (detail.fieldErrors !== undefined && Object.keys(detail.fieldErrors).length > 0) {
|
|
19
|
+
error.fieldErrors = detail.fieldErrors;
|
|
20
|
+
}
|
|
21
|
+
return { success: false, error };
|
|
22
|
+
}
|
|
23
|
+
function isEngineRefusal(error) {
|
|
24
|
+
return (error instanceof NonOwningRelationInputError ||
|
|
25
|
+
error instanceof MalformedRelationInputError ||
|
|
26
|
+
error instanceof NestedRelationInputError ||
|
|
27
|
+
error instanceof AccessScopeDepthExceededError ||
|
|
28
|
+
error instanceof ResolveOutputCycleError);
|
|
29
|
+
}
|
|
30
|
+
/** The failure a thrown error becomes, with `report` told of what an operator should see. See ADR-0086. */
|
|
31
|
+
export function failureFromError(error, report) {
|
|
32
|
+
if (error instanceof ValidationError) {
|
|
33
|
+
return failure('VALIDATION', { message: error.message, fieldErrors: error.fieldErrors });
|
|
34
|
+
}
|
|
35
|
+
if (error instanceof DatabaseError) {
|
|
36
|
+
if (isSerializationFailure(error))
|
|
37
|
+
return failure('RETRY');
|
|
38
|
+
const { message, fieldErrors } = error;
|
|
39
|
+
if (!isUniqueConstraintViolation(error))
|
|
40
|
+
report(error);
|
|
41
|
+
return failure('CONFLICT', { message, fieldErrors });
|
|
42
|
+
}
|
|
43
|
+
if (isClientSafeError(error)) {
|
|
44
|
+
if (isEngineRefusal(error))
|
|
45
|
+
report(error);
|
|
46
|
+
return failure('INVALID_INPUT', { message: error.message });
|
|
47
|
+
}
|
|
48
|
+
report(error);
|
|
49
|
+
return failure('INTERNAL');
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/procedures/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAC5F,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,YAAY,CAAA;AA0BnB,MAAM,QAAQ,GAAkD;IAC9D,eAAe,EAAE,yBAAyB;IAC1C,MAAM,EAAE,eAAe;IACvB,aAAa,EAAE,eAAe;IAC9B,UAAU,EAAE,mBAAmB;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,CAAC,KAAK,CAAC,CAAA;QACtD,OAAO,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,eAAe,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QACzC,OAAO,OAAO,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAC7D,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,CAAA;IACb,OAAO,OAAO,CAAC,UAAU,CAAC,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Procedure, ProcedureHostContext } from './procedure.js';
|
|
2
|
+
import { type ProcedureResult } from './result.js';
|
|
3
|
+
/** The caller's raw input, or `ok: false` when it could not be decoded. */
|
|
4
|
+
export type RawInput = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads the caller's raw input. Called only once access has admitted the
|
|
12
|
+
* call, so a host that reads lazily consumes nothing for a refused one. A
|
|
13
|
+
* rejection is reported as `INTERNAL`.
|
|
14
|
+
*/
|
|
15
|
+
export type InputReader = () => RawInput | Promise<RawInput>;
|
|
16
|
+
/** Everything one call needs once a host has resolved the name and the identity. */
|
|
17
|
+
export interface ProcedureCall<C extends ProcedureHostContext> {
|
|
18
|
+
name: string;
|
|
19
|
+
procedure: Procedure<C>;
|
|
20
|
+
/** The context the call runs in. Its `session` is the caller's identity. */
|
|
21
|
+
context: () => Promise<C>;
|
|
22
|
+
readInput: InputReader;
|
|
23
|
+
onUnexpectedError: UnexpectedErrorReporter;
|
|
24
|
+
/**
|
|
25
|
+
* Handed every error the pipeline catches before it becomes a failure. A
|
|
26
|
+
* host that lets an error propagate, as the in-process caller does with a
|
|
27
|
+
* framework's control flow, rethrows it from here.
|
|
28
|
+
*/
|
|
29
|
+
propagate?: (error: unknown) => void;
|
|
30
|
+
}
|
|
31
|
+
export type UnexpectedErrorReporter = (error: unknown, procedureName: string) => void;
|
|
32
|
+
/** A reporter that cannot throw or leave a rejection unhandled: a failing one falls back to `console.error`. */
|
|
33
|
+
export declare function guardReporter(report: UnexpectedErrorReporter): UnexpectedErrorReporter;
|
|
34
|
+
/** The pipeline every host shares. See ADR-0086. */
|
|
35
|
+
export declare function runProcedure<C extends ProcedureHostContext>(call: ProcedureCall<C>): Promise<ProcedureResult<unknown, string>>;
|
|
36
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/procedures/run.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7E,2EAA2E;AAC3E,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAA;AAEnE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE5D,oFAAoF;AACpF,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,oBAAoB;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IACvB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;IACzB,SAAS,EAAE,WAAW,CAAA;IACtB,iBAAiB,EAAE,uBAAuB,CAAA;IAC1C;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACrC;AAED,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAA;AAErF,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,MAAM,EAAE,uBAAuB,GAAG,uBAAuB,CAgBtF;AAoBD,oDAAoD;AACpD,wBAAsB,YAAY,CAAC,CAAC,SAAS,oBAAoB,EAC/D,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CA2C3C"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { declaredFailureOf, throwReturnedFailure } from './failures.js';
|
|
2
|
+
import { failure, failureFromError } from './result.js';
|
|
3
|
+
/** A reporter that cannot throw or leave a rejection unhandled: a failing one falls back to `console.error`. */
|
|
4
|
+
export function guardReporter(report) {
|
|
5
|
+
return (error, procedureName) => {
|
|
6
|
+
const fallback = (reporterError) => {
|
|
7
|
+
console.error(`onUnexpectedError threw while reporting procedure "${procedureName}":`, reporterError, error);
|
|
8
|
+
};
|
|
9
|
+
try {
|
|
10
|
+
const returned = report(error, procedureName);
|
|
11
|
+
if (isThenable(returned))
|
|
12
|
+
void Promise.resolve(returned).catch(fallback);
|
|
13
|
+
}
|
|
14
|
+
catch (reporterError) {
|
|
15
|
+
fallback(reporterError);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function isThenable(value) {
|
|
20
|
+
return (typeof value === 'object' &&
|
|
21
|
+
value !== null &&
|
|
22
|
+
'then' in value &&
|
|
23
|
+
typeof value.then === 'function');
|
|
24
|
+
}
|
|
25
|
+
function fieldErrorsOf(error) {
|
|
26
|
+
const fieldErrors = new Map();
|
|
27
|
+
for (const issue of error.issues) {
|
|
28
|
+
const key = issue.path.map(String).join('.') || '(root)';
|
|
29
|
+
if (!fieldErrors.has(key))
|
|
30
|
+
fieldErrors.set(key, issue.message);
|
|
31
|
+
}
|
|
32
|
+
return Object.fromEntries(fieldErrors);
|
|
33
|
+
}
|
|
34
|
+
/** The pipeline every host shares. See ADR-0086. */
|
|
35
|
+
export async function runProcedure(call) {
|
|
36
|
+
const { name, procedure } = call;
|
|
37
|
+
const internal = (error) => call.onUnexpectedError(error, name);
|
|
38
|
+
try {
|
|
39
|
+
const context = await call.context();
|
|
40
|
+
const admitted = await procedure.access({ context });
|
|
41
|
+
if (admitted !== true) {
|
|
42
|
+
return failure(context.session === null ? 'UNAUTHENTICATED' : 'DENIED');
|
|
43
|
+
}
|
|
44
|
+
const raw = await call.readInput();
|
|
45
|
+
if (!raw.ok)
|
|
46
|
+
return failure('INVALID_INPUT');
|
|
47
|
+
const input = await procedure.input.safeParseAsync(raw.value);
|
|
48
|
+
if (!input.success) {
|
|
49
|
+
return failure('INVALID_INPUT', { fieldErrors: fieldErrorsOf(input.error) });
|
|
50
|
+
}
|
|
51
|
+
let returned;
|
|
52
|
+
try {
|
|
53
|
+
returned = await procedure.run({ input: input.data, context });
|
|
54
|
+
throwReturnedFailure(returned);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const declared = declaredFailureOf(error, procedure.failures);
|
|
58
|
+
if (declared !== undefined)
|
|
59
|
+
return { success: false, error: declared };
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
const output = await procedure.output.safeParseAsync(returned);
|
|
63
|
+
if (!output.success) {
|
|
64
|
+
internal(new Error(`Procedure "${name}" returned output that does not match its output schema`, {
|
|
65
|
+
cause: output.error,
|
|
66
|
+
}));
|
|
67
|
+
return failure('INTERNAL');
|
|
68
|
+
}
|
|
69
|
+
return { success: true, data: output.data };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
call.propagate?.(error);
|
|
73
|
+
return failureFromError(error, internal);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMapping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AiB,CAAA;QACrB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;YAC9D,oBAAoB,CAAC,QAAQ,CAAC,CAAA;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAA;YAC7D,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;YACtE,MAAM,KAAK,CAAA;QACb,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;QAC9D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,QAAQ,CACN,IAAI,KAAK,CAAC,cAAc,IAAI,yDAAyD,EAAE;gBACrF,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC,CACH,CAAA;YACD,OAAO,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAA;QACvB,OAAO,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC1C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { OpenSaasConfig } from '../config/types.js';
|
|
2
|
+
import type { ProcedureArgsFor, ProcedureCodeOf, ProcedureDataOf, ProcedureNameOf } from './client.js';
|
|
3
|
+
import type { SessionOf } from './http.js';
|
|
4
|
+
import type { Procedure, ProcedureHostContext, ProcedureRegistry } from './procedure.js';
|
|
5
|
+
import { type ProcedureResult } from './result.js';
|
|
6
|
+
import { type UnexpectedErrorReporter } from './run.js';
|
|
7
|
+
/** The application context the procedures of `TRegistry` are typed to. */
|
|
8
|
+
export type RegistryContextOf<TRegistry> = TRegistry[keyof TRegistry] extends Procedure<infer C extends ProcedureHostContext, infer _TIn, infer _TOut, infer _TCode> ? C : never;
|
|
9
|
+
/** Options for {@link createServerCaller}. */
|
|
10
|
+
export interface ServerCallerOptions<TRegistry extends ProcedureRegistry<ProcedureHostContext>> {
|
|
11
|
+
/** The application's procedure registry. Only procedures exposing `'web'` are callable. */
|
|
12
|
+
procedures: TRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* The resolved config, checked against the registry as `createProcedureHandler`
|
|
15
|
+
* checks it. Pass `await config` from `.opensaas/context.ts`. A framework's
|
|
16
|
+
* control flow is recognised by the built-in check and by the
|
|
17
|
+
* `isFrameworkControlFlow` of the config the context carries; this config's
|
|
18
|
+
* is the fallback, and the only one consulted for a throw from `getSession`,
|
|
19
|
+
* which happens before there is a context.
|
|
20
|
+
*/
|
|
21
|
+
config?: OpenSaasConfig;
|
|
22
|
+
/** The generated `getContext`: called with the resolved session, or with nothing when anonymous. */
|
|
23
|
+
getContext: (session?: SessionOf<RegistryContextOf<TRegistry>>) => Promise<RegistryContextOf<TRegistry>>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the current request's session from the server, as from the
|
|
26
|
+
* request's cookies, and never from anything a caller passes. Called once
|
|
27
|
+
* per call and once per `context()`, and never cached, so two requests
|
|
28
|
+
* never share a session; wrapping it in React's `cache()` to share one
|
|
29
|
+
* lookup across a render is safe, since that cache is per request.
|
|
30
|
+
* Resolving `null` or `undefined` means anonymous.
|
|
31
|
+
*
|
|
32
|
+
* The caller sets `session.actor` to a human actor carrying the session's
|
|
33
|
+
* own `userId`, exactly as `createProcedureHandler` does: `userId` must be
|
|
34
|
+
* an own data property, not a getter, holding a non-empty string or a finite number.
|
|
35
|
+
*
|
|
36
|
+
* **The caller performs no cookie or `Origin` check.** Whatever this
|
|
37
|
+
* resolves is acted on as the signed-in person. In a Next.js server action
|
|
38
|
+
* the cross-site protection is Next's own server-action `Origin` check, and
|
|
39
|
+
* only there; widening `serverActions.allowedOrigins` widens this caller's
|
|
40
|
+
* exposure too. A route handler that calls `call` for a mutation must not
|
|
41
|
+
* answer `GET` and must check the request's origin itself, or serve the
|
|
42
|
+
* procedure through `createProcedureHandler` instead. Outside a request (a
|
|
43
|
+
* job, a script) there is no person to act for: this must resolve `null`,
|
|
44
|
+
* because any session it resolves there still gets
|
|
45
|
+
* `{ kind: 'human', userId, via: 'web' }`.
|
|
46
|
+
*/
|
|
47
|
+
getSession: () => Promise<SessionOf<RegistryContextOf<TRegistry>> | null | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Told of every failure the operator should see, with the procedure's name,
|
|
50
|
+
* as `createProcedureHandler`'s option of the same name is. Default
|
|
51
|
+
* `console.error`.
|
|
52
|
+
*/
|
|
53
|
+
onUnexpectedError?: UnexpectedErrorReporter;
|
|
54
|
+
}
|
|
55
|
+
/** The in-process caller {@link createServerCaller} returns. */
|
|
56
|
+
export interface ServerCaller<TRegistry extends ProcedureRegistry<ProcedureHostContext>> {
|
|
57
|
+
/**
|
|
58
|
+
* Call a procedure exposed to `'web'` by name, as the session `getSession`
|
|
59
|
+
* resolves for the current request. Never throws for an outcome of the
|
|
60
|
+
* pipeline: it resolves to `{ success: true, data }` or
|
|
61
|
+
* `{ success: false, error: { code, message, fieldErrors? } }`. A
|
|
62
|
+
* framework's control flow (`redirect()`, `notFound()`) thrown from the
|
|
63
|
+
* session resolver, the access rule or `run` is rethrown, so the framework
|
|
64
|
+
* acts on it; a transaction it leaves is rolled back first.
|
|
65
|
+
*
|
|
66
|
+
* The name's type is every key of the registry and does not reflect
|
|
67
|
+
* exposure: a procedure exposed only to `'mcp'` type-checks here, and at
|
|
68
|
+
* runtime answers `INTERNAL`, reported, as an unknown name does.
|
|
69
|
+
*/
|
|
70
|
+
call: <TName extends ProcedureNameOf<TRegistry>>(name: TName, ...args: ProcedureArgsFor<TRegistry, TName>) => Promise<ProcedureResult<ProcedureDataOf<TRegistry[TName]>, ProcedureCodeOf<TRegistry[TName]>>>;
|
|
71
|
+
/**
|
|
72
|
+
* The context for the current request's session, for a server component's
|
|
73
|
+
* reads through `context.db`. The session carries the same human actor a
|
|
74
|
+
* call does. Rejects with what resolving the session threw, a
|
|
75
|
+
* `ProcedureHostError` for a session with no usable `userId`, or the
|
|
76
|
+
* `InvalidSessionError` `getContext` throws.
|
|
77
|
+
*/
|
|
78
|
+
context: () => Promise<RegistryContextOf<TRegistry>>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The in-process host for server code running inside a request: a Next.js
|
|
82
|
+
* server action, and a server component through `context`. `call` runs a procedure through the same
|
|
83
|
+
* pipeline as `createProcedureHandler`, with the same exposure, access rule,
|
|
84
|
+
* input and output parsing, declared failures, result and redaction, and
|
|
85
|
+
* `context` gives a server component the context for the same session.
|
|
86
|
+
*
|
|
87
|
+
* Neither takes a session. Each resolves it with `getSession` on every call,
|
|
88
|
+
* and the session carries a human actor the caller sets itself. A procedure
|
|
89
|
+
* not exposed to `'web'` answers exactly as an unknown name does: `INTERNAL`,
|
|
90
|
+
* reported to `onUnexpectedError`. Unlike the HTTP host, a framework's control
|
|
91
|
+
* flow propagates, so a procedure may `redirect()`; over HTTP it is `INTERNAL`.
|
|
92
|
+
*
|
|
93
|
+
* **It performs no cookie or `Origin` check of its own.** A server action is
|
|
94
|
+
* protected by Next's server-action `Origin` check and nothing else, and
|
|
95
|
+
* widening `serverActions.allowedOrigins` widens this caller too. A route
|
|
96
|
+
* handler calling `call` for a mutation must answer only non-`GET` methods
|
|
97
|
+
* and check the origin itself, or serve the procedure through
|
|
98
|
+
* `createProcedureHandler`. A job or script outside a request must have
|
|
99
|
+
* `getSession` resolve `null`: any session it resolves there is acted on as
|
|
100
|
+
* a human on the web.
|
|
101
|
+
*
|
|
102
|
+
* Keep the module that creates the caller the one place that imports the
|
|
103
|
+
* generated `getContext`, and export `call` and `context` from it.
|
|
104
|
+
*
|
|
105
|
+
* @typeParam TRegistry - the registry's own type. Declare the registry with
|
|
106
|
+
* `satisfies ProcedureRegistry<Context>` rather than annotating it, so each
|
|
107
|
+
* name keeps its own procedure type.
|
|
108
|
+
*
|
|
109
|
+
* @throws {ProcedureHostError} for a registry a host refuses. See {@link assertProcedureRegistry}.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // lib/server.ts
|
|
114
|
+
* import { createServerCaller } from '@opensaas/stack-core/procedures'
|
|
115
|
+
* import { config, getContext } from '@/.opensaas/context'
|
|
116
|
+
* import { procedures } from '@/lib/procedures'
|
|
117
|
+
* import { getSession } from '@/lib/auth'
|
|
118
|
+
*
|
|
119
|
+
* const server = createServerCaller({
|
|
120
|
+
* procedures,
|
|
121
|
+
* config: await config,
|
|
122
|
+
* getContext,
|
|
123
|
+
* getSession,
|
|
124
|
+
* })
|
|
125
|
+
*
|
|
126
|
+
* export const callProcedure = server.call
|
|
127
|
+
* export const getServerContext = server.context
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function createServerCaller<TRegistry extends ProcedureRegistry<ProcedureHostContext>>(options: ServerCallerOptions<TRegistry>): ServerCaller<TRegistry>;
|
|
131
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/procedures/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,S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eAAe,CAAC,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CACtF,CAAA;IACD;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAA;CACrD;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,iBAAiB,CAAC,oBAAoB,CAAC,EAC1F,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GACtC,YAAY,CAAC,SAAS,CAAC,CAwEzB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { controlFlowPredicateOf, rethrowControlFlow } from '../access/decide-advertisement.js';
|
|
2
|
+
import { engineFaceOf } from '../context/engine-context.js';
|
|
3
|
+
import { failure, isReservedFailureCode } from './result.js';
|
|
4
|
+
import { guardReporter, runProcedure } from './run.js';
|
|
5
|
+
import { assertProcedureRegistry, ProcedureHostError } from './validate.js';
|
|
6
|
+
import { webProcedureOf, webSessionOf } from './web-session.js';
|
|
7
|
+
function defaultUnexpectedError(error, procedureName) {
|
|
8
|
+
console.error(`Procedure "${procedureName}" failed:`, error);
|
|
9
|
+
}
|
|
10
|
+
function isOutcomeOf(procedure, result) {
|
|
11
|
+
if (result.success)
|
|
12
|
+
return true;
|
|
13
|
+
const { code } = result.error;
|
|
14
|
+
return isReservedFailureCode(code) || Object.hasOwn(procedure.failures, code);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The in-process host for server code running inside a request: a Next.js
|
|
18
|
+
* server action, and a server component through `context`. `call` runs a procedure through the same
|
|
19
|
+
* pipeline as `createProcedureHandler`, with the same exposure, access rule,
|
|
20
|
+
* input and output parsing, declared failures, result and redaction, and
|
|
21
|
+
* `context` gives a server component the context for the same session.
|
|
22
|
+
*
|
|
23
|
+
* Neither takes a session. Each resolves it with `getSession` on every call,
|
|
24
|
+
* and the session carries a human actor the caller sets itself. A procedure
|
|
25
|
+
* not exposed to `'web'` answers exactly as an unknown name does: `INTERNAL`,
|
|
26
|
+
* reported to `onUnexpectedError`. Unlike the HTTP host, a framework's control
|
|
27
|
+
* flow propagates, so a procedure may `redirect()`; over HTTP it is `INTERNAL`.
|
|
28
|
+
*
|
|
29
|
+
* **It performs no cookie or `Origin` check of its own.** A server action is
|
|
30
|
+
* protected by Next's server-action `Origin` check and nothing else, and
|
|
31
|
+
* widening `serverActions.allowedOrigins` widens this caller too. A route
|
|
32
|
+
* handler calling `call` for a mutation must answer only non-`GET` methods
|
|
33
|
+
* and check the origin itself, or serve the procedure through
|
|
34
|
+
* `createProcedureHandler`. A job or script outside a request must have
|
|
35
|
+
* `getSession` resolve `null`: any session it resolves there is acted on as
|
|
36
|
+
* a human on the web.
|
|
37
|
+
*
|
|
38
|
+
* Keep the module that creates the caller the one place that imports the
|
|
39
|
+
* generated `getContext`, and export `call` and `context` from it.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam TRegistry - the registry's own type. Declare the registry with
|
|
42
|
+
* `satisfies ProcedureRegistry<Context>` rather than annotating it, so each
|
|
43
|
+
* name keeps its own procedure type.
|
|
44
|
+
*
|
|
45
|
+
* @throws {ProcedureHostError} for a registry a host refuses. See {@link assertProcedureRegistry}.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // lib/server.ts
|
|
50
|
+
* import { createServerCaller } from '@opensaas/stack-core/procedures'
|
|
51
|
+
* import { config, getContext } from '@/.opensaas/context'
|
|
52
|
+
* import { procedures } from '@/lib/procedures'
|
|
53
|
+
* import { getSession } from '@/lib/auth'
|
|
54
|
+
*
|
|
55
|
+
* const server = createServerCaller({
|
|
56
|
+
* procedures,
|
|
57
|
+
* config: await config,
|
|
58
|
+
* getContext,
|
|
59
|
+
* getSession,
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* export const callProcedure = server.call
|
|
63
|
+
* export const getServerContext = server.context
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function createServerCaller(options) {
|
|
67
|
+
const { procedures, getContext, getSession } = options;
|
|
68
|
+
const onUnexpectedError = guardReporter(options.onUnexpectedError ?? defaultUnexpectedError);
|
|
69
|
+
const isFrameworkControlFlow = options.config?.isFrameworkControlFlow;
|
|
70
|
+
assertProcedureRegistry(procedures, { config: options.config });
|
|
71
|
+
const contextFor = (session) => session === null ? getContext() : getContext(session);
|
|
72
|
+
const context = async () => contextFor(webSessionOf(await getSession()));
|
|
73
|
+
async function invoke(name, input) {
|
|
74
|
+
const procedure = webProcedureOf(procedures, name);
|
|
75
|
+
if (procedure === undefined) {
|
|
76
|
+
onUnexpectedError(new ProcedureHostError(`No procedure named "${name}" is exposed to 'web'.`), name);
|
|
77
|
+
return failure('INTERNAL');
|
|
78
|
+
}
|
|
79
|
+
let session;
|
|
80
|
+
try {
|
|
81
|
+
session = webSessionOf(await getSession());
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
rethrowControlFlow(error, isFrameworkControlFlow);
|
|
85
|
+
onUnexpectedError(error, name);
|
|
86
|
+
return failure('INTERNAL');
|
|
87
|
+
}
|
|
88
|
+
let resolved;
|
|
89
|
+
const result = await runProcedure({
|
|
90
|
+
name,
|
|
91
|
+
procedure,
|
|
92
|
+
context: async () => {
|
|
93
|
+
resolved = await contextFor(session);
|
|
94
|
+
return resolved;
|
|
95
|
+
},
|
|
96
|
+
readInput: () => ({ ok: true, value: input }),
|
|
97
|
+
onUnexpectedError,
|
|
98
|
+
propagate: (error) => {
|
|
99
|
+
const engine = resolved === undefined ? undefined : engineFaceOf(resolved);
|
|
100
|
+
rethrowControlFlow(error, engine === undefined
|
|
101
|
+
? isFrameworkControlFlow
|
|
102
|
+
: controlFlowPredicateOf(engine, options.config));
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (isOutcomeOf(procedure, result))
|
|
106
|
+
return result;
|
|
107
|
+
onUnexpectedError(new ProcedureHostError(`Procedure "${name}" failed with a code it does not declare.`), name);
|
|
108
|
+
return failure('INTERNAL');
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
call: (name, ...args) => invoke(name, args[0]),
|
|
112
|
+
context,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/procedures/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAS3D,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAwB,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAA;AACpF,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA6F/D,SAAS,sBAAsB,CAAC,KAAc,EAAE,aAAqB;IACnE,OAAO,CAAC,KAAK,CAAC,cAAc,aAAa,WAAW,EAAE,KAAK,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,WAAW,CAClB,SAA0C,EAC1C,MAAwC;IAExC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAA;IAC7B,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG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AI,QAAkD,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;YAChC,IAAI;YACJ,SAAS;YACT,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAA;gBACpC,OAAO,QAAQ,CAAA;YACjB,CAAC;YACD,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YAC7C,iBAAiB;YACjB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;gBACnB,MAAM,MAAM,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;gBAC1E,kBAAkB,CAChB,KAAK,EACL,MAAM,KAAK,SAAS;oBAClB,CAAC,CAAC,sBAAsB;oBACxB,CAAC,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CACnD,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,IAAI,WAAW,CAAe,SAAS,EAAE,MAAM,CAAC;YAAE,OAAO,MAAM,CAAA;QAC/D,iBAAiB,CACf,IAAI,kBAAkB,CAAC,cAAc,IAAI,2CAA2C,CAAC,EACrF,IAAI,CACL,CAAA;QACD,OAAO,OAAO,CAAC,UAAU,CAAC,CAAA;IAC5B,CAAC;IAED,OAAO;QACL,IAAI,EAAE,CACJ,IAAW,EACX,GAAG,IAAwC,EAC3C,EAAE,CACF,MAAM,CAAuE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7F,OAAO;KACR,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import type { OpenSaasConfig } from '../config/types.js';
|
|
3
|
+
/** Thrown when a host is created over options or a registry it cannot serve. */
|
|
4
|
+
export declare class ProcedureHostError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Which of a procedure's two schemas a refusal is about. */
|
|
8
|
+
export type ProcedureSchemaSide = 'input' | 'output';
|
|
9
|
+
/** The schemas a host checks. Every procedure the builder defines carries them. */
|
|
10
|
+
export interface ProcedureSchemas {
|
|
11
|
+
readonly input: z.ZodType;
|
|
12
|
+
readonly output: z.ZodType;
|
|
13
|
+
}
|
|
14
|
+
/** What {@link assertProcedureRegistry} checks a registry against. */
|
|
15
|
+
export interface ProcedureRegistryChecks {
|
|
16
|
+
/**
|
|
17
|
+
* The resolved config. With it, a procedure named like one of its list
|
|
18
|
+
* custom tools or plugin-registered MCP tools is refused. Without it only
|
|
19
|
+
* the reserved generated-tool pattern is checked.
|
|
20
|
+
*/
|
|
21
|
+
config?: OpenSaasConfig;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Refuses a procedure whose schemas cannot be carried on the wire: `input`
|
|
25
|
+
* must convert to JSON Schema on its input side and `output` on its output
|
|
26
|
+
* side, which rules out dates, bigints and output transforms, and neither may
|
|
27
|
+
* hold `z.file()` or one of the open-ended shapes Zod provides, at any depth:
|
|
28
|
+
* `z.any()`, `z.unknown()`, `z.json()`, a loose object, a `z.looseRecord` or a
|
|
29
|
+
* `z.record` of `any`/`unknown`. An output object with a `.catchall()` is
|
|
30
|
+
* refused too, because it returns keys the schema does not declare.
|
|
31
|
+
*
|
|
32
|
+
* A hand-written schema that accepts as much as those do, such as a recursive
|
|
33
|
+
* union of every JSON type under another shape, is not recognised.
|
|
34
|
+
*
|
|
35
|
+
* Every host calls this when it is created.
|
|
36
|
+
*
|
|
37
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertProcedureSchemas(name: string, procedure: ProcedureSchemas): void;
|
|
40
|
+
/**
|
|
41
|
+
* Refuses a procedure name that collides in the namespace procedures share
|
|
42
|
+
* with MCP tools. A name matching the reserved `list_<list>_<operation>`
|
|
43
|
+
* pattern is refused whether or not that generated tool is enabled, or its
|
|
44
|
+
* list exists. With a `config`, a name a list custom tool or a
|
|
45
|
+
* plugin-registered tool already carries is refused as well.
|
|
46
|
+
*
|
|
47
|
+
* @throws {ProcedureHostError} naming the procedure, what it clashes with and the fix.
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertProcedureNamesAvailable(names: Iterable<string>, config?: OpenSaasConfig): void;
|
|
50
|
+
/**
|
|
51
|
+
* Everything a host checks about a registry when it is created: each name is
|
|
52
|
+
* well formed, each entry was defined by the generated `procedure` builder,
|
|
53
|
+
* each procedure's schemas can be carried on the wire
|
|
54
|
+
* ({@link assertProcedureSchemas}) and no name collides with an MCP tool
|
|
55
|
+
* ({@link assertProcedureNamesAvailable}).
|
|
56
|
+
*
|
|
57
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertProcedureRegistry(procedures: Readonly<Record<string, ProcedureSchemas>>, checks?: ProcedureRegistryChecks): void;
|
|
60
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/procedures/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAKxD,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,6DAA6D;AAC7D,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEpD,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAA;CAC3B;AAED,sEAAsE;AACtE,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;CACxB;AA4MD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAGtF;AAQD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,MAAM,CAAC,EAAE,cAAc,GACtB,IAAI,CAmBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EACtD,MAAM,GAAE,uBAA4B,GACnC,IAAI,CAuBN"}
|