@astrale-os/kernel-client 0.5.1 → 0.6.0-beta.10
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/dist/auth/auth.d.ts +18 -0
- package/dist/auth/auth.js +15 -0
- package/dist/auth/authorization.d.ts +13 -0
- package/dist/auth/authorization.js +17 -0
- package/dist/auth/credential.d.ts +19 -0
- package/dist/auth/credential.js +21 -0
- package/dist/auth/identity.d.ts +14 -0
- package/dist/auth/identity.js +15 -0
- package/dist/auth/index.d.ts +6 -16
- package/dist/auth/index.js +5 -10
- package/dist/auth/provision.d.ts +8 -0
- package/dist/auth/provision.js +10 -0
- package/dist/client/admission.d.ts +4 -0
- package/dist/client/admission.js +34 -0
- package/dist/client/client.d.ts +24 -109
- package/dist/client/client.js +80 -381
- package/dist/client/credential.d.ts +12 -0
- package/dist/client/credential.js +51 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +4 -0
- package/dist/client/request.d.ts +26 -0
- package/dist/client/request.js +100 -0
- package/dist/client/result.d.ts +35 -0
- package/dist/client/result.js +28 -0
- package/dist/client/routing-control.d.ts +10 -0
- package/dist/client/routing-control.js +23 -0
- package/dist/errors/client-error.d.ts +3 -0
- package/dist/errors/client-error.js +8 -0
- package/dist/errors/index.d.ts +7 -6
- package/dist/errors/index.js +7 -4
- package/dist/errors/miss-error.d.ts +8 -0
- package/dist/errors/miss-error.js +10 -0
- package/dist/errors/protocol-error.d.ts +9 -0
- package/dist/errors/protocol-error.js +9 -0
- package/dist/errors/response-error.d.ts +11 -0
- package/dist/errors/response-error.js +16 -0
- package/dist/errors/session-error.d.ts +8 -20
- package/dist/errors/session-error.js +6 -22
- package/dist/errors/stale-route-error.d.ts +9 -0
- package/dist/errors/stale-route-error.js +12 -0
- package/dist/errors/transport-error.d.ts +30 -0
- package/dist/errors/transport-error.js +18 -0
- package/dist/graph/domain/binding.d.ts +22 -0
- package/dist/graph/domain/binding.js +123 -0
- package/dist/graph/domain/domain.typecheck.d.ts +1 -0
- package/dist/graph/domain/domain.typecheck.js +139 -0
- package/dist/graph/domain/index.d.ts +3 -0
- package/dist/graph/domain/index.js +1 -0
- package/dist/graph/domain/model.d.ts +18 -0
- package/dist/graph/domain/model.js +1 -0
- package/dist/graph/domain/page.d.ts +23 -0
- package/dist/graph/domain/page.js +42 -0
- package/dist/graph/domain/project.d.ts +8 -0
- package/dist/graph/domain/project.js +120 -0
- package/dist/graph/domain/provenance.d.ts +6 -0
- package/dist/graph/domain/provenance.js +11 -0
- package/dist/graph/errors.d.ts +8 -0
- package/dist/graph/errors.js +14 -0
- package/dist/graph/graph.d.ts +26 -0
- package/dist/graph/graph.js +18 -0
- package/dist/graph/index.d.ts +8 -26
- package/dist/graph/index.js +6 -21
- package/dist/graph/mutation.d.ts +5 -0
- package/dist/graph/mutation.js +17 -0
- package/dist/graph/page/index.d.ts +2 -0
- package/dist/graph/page/index.js +1 -0
- package/dist/graph/page/neighbors.d.ts +9 -0
- package/dist/graph/page/neighbors.js +34 -0
- package/dist/graph/page/page.d.ts +37 -0
- package/dist/graph/page/page.js +55 -0
- package/dist/graph/page-contract.d.ts +13 -0
- package/dist/graph/page-contract.js +1 -0
- package/dist/graph/provenance.d.ts +12 -0
- package/dist/graph/provenance.js +37 -0
- package/dist/graph/query.d.ts +4 -0
- package/dist/graph/query.js +69 -0
- package/dist/graph/read.d.ts +6 -0
- package/dist/graph/read.js +17 -0
- package/dist/index.d.ts +6 -25
- package/dist/index.js +6 -21
- package/dist/pacer/batcher/batcher.d.ts +7 -0
- package/dist/pacer/batcher/batcher.js +13 -0
- package/dist/pacer/batcher/defaults.d.ts +2 -0
- package/dist/pacer/batcher/defaults.js +2 -0
- package/dist/pacer/batcher/index.d.ts +1 -0
- package/dist/pacer/batcher/index.js +1 -0
- package/dist/pacer/index.d.ts +4 -10
- package/dist/pacer/index.js +4 -11
- package/dist/pacer/limiter/defaults.d.ts +2 -0
- package/dist/pacer/limiter/defaults.js +2 -0
- package/dist/pacer/limiter/index.d.ts +1 -0
- package/dist/pacer/limiter/index.js +1 -0
- package/dist/pacer/limiter/limiter.d.ts +7 -0
- package/dist/pacer/limiter/limiter.js +14 -0
- package/dist/pacer/queue/defaults.d.ts +1 -0
- package/dist/pacer/queue/defaults.js +1 -0
- package/dist/pacer/queue/index.d.ts +1 -0
- package/dist/pacer/queue/index.js +1 -0
- package/dist/pacer/queue/queue.d.ts +6 -0
- package/dist/pacer/queue/queue.js +12 -0
- package/dist/pacer/retry/defaults.d.ts +6 -0
- package/dist/pacer/retry/defaults.js +16 -0
- package/dist/pacer/retry/index.d.ts +1 -0
- package/dist/pacer/retry/index.js +1 -0
- package/dist/pacer/retry/retry.d.ts +9 -0
- package/dist/pacer/retry/retry.js +55 -0
- package/dist/pool/index.d.ts +2 -4
- package/dist/pool/index.js +0 -2
- package/dist/pool/pool.d.ts +19 -59
- package/dist/pool/pool.js +46 -64
- package/dist/pool/target.d.ts +15 -0
- package/dist/pool/target.js +49 -0
- package/dist/schema/admission.d.ts +12 -0
- package/dist/schema/admission.js +17 -0
- package/dist/schema/contracts.d.ts +12 -0
- package/dist/schema/contracts.js +1 -0
- package/dist/schema/index.d.ts +3 -16
- package/dist/schema/index.js +2 -12
- package/dist/schema/introspection.d.ts +5 -0
- package/dist/schema/introspection.js +15 -0
- package/dist/schema/operation.d.ts +5 -0
- package/dist/schema/operation.js +9 -0
- package/dist/schema/schema.d.ts +19 -0
- package/dist/schema/schema.js +43 -0
- package/dist/session/bound.d.ts +42 -9
- package/dist/session/bound.js +70 -37
- package/dist/session/context/control.d.ts +5 -0
- package/dist/session/context/control.js +17 -0
- package/dist/session/context/index.d.ts +4 -0
- package/dist/session/context/index.js +4 -0
- package/dist/session/context/limits.d.ts +7 -0
- package/dist/session/context/limits.js +18 -0
- package/dist/session/context/operation.d.ts +19 -0
- package/dist/session/context/operation.js +72 -0
- package/dist/session/context/policy.d.ts +11 -0
- package/dist/session/context/policy.js +69 -0
- package/dist/session/discovery/bundle.d.ts +17 -0
- package/dist/session/discovery/bundle.js +55 -0
- package/dist/session/discovery/discovery.d.ts +19 -0
- package/dist/session/discovery/discovery.js +55 -0
- package/dist/session/discovery/index.d.ts +20 -0
- package/dist/session/discovery/index.js +15 -0
- package/dist/session/discovery/publication.d.ts +23 -0
- package/dist/session/discovery/publication.js +123 -0
- package/dist/session/discovery/snapshot.d.ts +12 -0
- package/dist/session/discovery/snapshot.js +3 -0
- package/dist/session/discovery/transport.d.ts +6 -0
- package/dist/session/discovery/transport.js +13 -0
- package/dist/session/index.d.ts +10 -16
- package/dist/session/index.js +3 -9
- package/dist/session/reference.d.ts +36 -0
- package/dist/session/reference.js +74 -0
- package/dist/session/routing/auth.d.ts +18 -0
- package/dist/session/routing/auth.js +39 -0
- package/dist/session/routing/cache.d.ts +20 -0
- package/dist/session/routing/cache.js +115 -0
- package/dist/session/routing/dispatch.d.ts +34 -0
- package/dist/session/routing/dispatch.js +137 -0
- package/dist/session/routing/envelope.d.ts +13 -0
- package/dist/session/routing/envelope.js +35 -0
- package/dist/session/routing/expectation.d.ts +6 -0
- package/dist/session/routing/expectation.js +1 -0
- package/dist/session/routing/index.d.ts +6 -0
- package/dist/session/routing/index.js +5 -0
- package/dist/session/routing/request.d.ts +8 -0
- package/dist/session/routing/request.js +25 -0
- package/dist/session/session.d.ts +67 -0
- package/dist/session/session.js +257 -0
- package/dist/session/session.typecheck.d.ts +1 -0
- package/dist/session/session.typecheck.js +31 -0
- package/dist/session/views/catalog.d.ts +15 -0
- package/dist/session/views/catalog.js +70 -0
- package/dist/session/views/index.d.ts +2 -0
- package/dist/session/views/index.js +2 -0
- package/dist/session/views/resolve.d.ts +11 -0
- package/dist/session/views/resolve.js +13 -0
- package/dist/store/entity-index.d.ts +22 -0
- package/dist/store/entity-index.js +94 -0
- package/dist/store/index.d.ts +1 -26
- package/dist/store/index.js +1 -19
- package/dist/store/memory.d.ts +46 -97
- package/dist/store/memory.js +346 -763
- package/dist/store/mutation.d.ts +5 -0
- package/dist/store/mutation.js +34 -0
- package/dist/store/observe.d.ts +3 -0
- package/dist/store/observe.js +17 -0
- package/dist/store/optimistic.d.ts +12 -0
- package/dist/store/optimistic.js +43 -0
- package/dist/store/query-key.d.ts +5 -0
- package/dist/store/query-key.js +22 -0
- package/dist/store/shape.d.ts +25 -0
- package/dist/store/shape.js +29 -0
- package/dist/store/store.d.ts +68 -0
- package/dist/store/store.js +144 -0
- package/dist/store/store.typecheck.d.ts +1 -0
- package/dist/store/store.typecheck.js +40 -0
- package/dist/transport/auto/decision.d.ts +22 -0
- package/dist/transport/auto/decision.js +48 -0
- package/dist/transport/auto/fallback.d.ts +16 -0
- package/dist/transport/auto/fallback.js +75 -0
- package/dist/transport/auto/index.d.ts +2 -0
- package/dist/transport/auto/index.js +2 -0
- package/dist/transport/auto/transport.d.ts +37 -0
- package/dist/transport/auto/transport.js +140 -0
- package/dist/transport/auto/warning.d.ts +13 -0
- package/dist/transport/auto/warning.js +18 -0
- package/dist/transport/deadline.d.ts +11 -0
- package/dist/transport/deadline.js +39 -0
- package/dist/transport/failure.d.ts +7 -0
- package/dist/transport/failure.js +9 -0
- package/dist/transport/http/index.d.ts +1 -0
- package/dist/transport/http/index.js +1 -0
- package/dist/transport/http/response.d.ts +8 -0
- package/dist/transport/http/response.js +79 -0
- package/dist/transport/http/stream.d.ts +26 -0
- package/dist/transport/http/stream.js +214 -0
- package/dist/transport/http/transport.d.ts +32 -0
- package/dist/transport/http/transport.js +343 -0
- package/dist/transport/index.d.ts +2 -8
- package/dist/transport/index.js +1 -6
- package/dist/transport/transport.d.ts +34 -0
- package/dist/transport/transport.js +1 -0
- package/dist/transport/websocket/connection.d.ts +38 -0
- package/dist/transport/websocket/connection.js +284 -0
- package/dist/transport/websocket/exchange.d.ts +46 -0
- package/dist/transport/websocket/exchange.js +300 -0
- package/dist/transport/websocket/index.d.ts +1 -0
- package/dist/transport/websocket/index.js +1 -0
- package/dist/transport/websocket/transport.d.ts +46 -0
- package/dist/transport/websocket/transport.js +164 -0
- package/package.json +41 -35
- package/dist/auth/addressing.d.ts +0 -32
- package/dist/auth/addressing.d.ts.map +0 -1
- package/dist/auth/addressing.js +0 -36
- package/dist/auth/addressing.js.map +0 -1
- package/dist/auth/api.d.ts +0 -70
- package/dist/auth/api.d.ts.map +0 -1
- package/dist/auth/api.js +0 -36
- package/dist/auth/api.js.map +0 -1
- package/dist/auth/batch.d.ts +0 -18
- package/dist/auth/batch.d.ts.map +0 -1
- package/dist/auth/batch.js +0 -25
- package/dist/auth/batch.js.map +0 -1
- package/dist/auth/composition.d.ts +0 -27
- package/dist/auth/composition.d.ts.map +0 -1
- package/dist/auth/composition.js +0 -83
- package/dist/auth/composition.js.map +0 -1
- package/dist/auth/defaults.d.ts +0 -3
- package/dist/auth/defaults.d.ts.map +0 -1
- package/dist/auth/defaults.js +0 -3
- package/dist/auth/defaults.js.map +0 -1
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/minting.d.ts +0 -35
- package/dist/auth/minting.d.ts.map +0 -1
- package/dist/auth/minting.js +0 -31
- package/dist/auth/minting.js.map +0 -1
- package/dist/auth/permissions.d.ts +0 -55
- package/dist/auth/permissions.d.ts.map +0 -1
- package/dist/auth/permissions.js +0 -47
- package/dist/auth/permissions.js.map +0 -1
- package/dist/auth/principal.d.ts +0 -19
- package/dist/auth/principal.d.ts.map +0 -1
- package/dist/auth/principal.js +0 -46
- package/dist/auth/principal.js.map +0 -1
- package/dist/auth/shorthands.d.ts +0 -19
- package/dist/auth/shorthands.d.ts.map +0 -1
- package/dist/auth/shorthands.js +0 -27
- package/dist/auth/shorthands.js.map +0 -1
- package/dist/client/batch.d.ts +0 -26
- package/dist/client/batch.d.ts.map +0 -1
- package/dist/client/batch.js +0 -8
- package/dist/client/batch.js.map +0 -1
- package/dist/client/bound.d.ts +0 -27
- package/dist/client/bound.d.ts.map +0 -1
- package/dist/client/bound.js +0 -14
- package/dist/client/bound.js.map +0 -1
- package/dist/client/client.d.ts.map +0 -1
- package/dist/client/client.js.map +0 -1
- package/dist/client/config.d.ts +0 -112
- package/dist/client/config.d.ts.map +0 -1
- package/dist/client/config.js +0 -10
- package/dist/client/config.js.map +0 -1
- package/dist/client/fn-map.d.ts +0 -61
- package/dist/client/fn-map.d.ts.map +0 -1
- package/dist/client/fn-map.js +0 -2
- package/dist/client/fn-map.js.map +0 -1
- package/dist/client/freeze.d.ts +0 -32
- package/dist/client/freeze.d.ts.map +0 -1
- package/dist/client/freeze.js +0 -42
- package/dist/client/freeze.js.map +0 -1
- package/dist/client/hooks.d.ts +0 -49
- package/dist/client/hooks.d.ts.map +0 -1
- package/dist/client/hooks.js +0 -2
- package/dist/client/hooks.js.map +0 -1
- package/dist/errors/errors.d.ts +0 -156
- package/dist/errors/errors.d.ts.map +0 -1
- package/dist/errors/errors.js +0 -238
- package/dist/errors/errors.js.map +0 -1
- package/dist/errors/guards.d.ts +0 -39
- package/dist/errors/guards.d.ts.map +0 -1
- package/dist/errors/guards.js +0 -127
- package/dist/errors/guards.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/session-error.d.ts.map +0 -1
- package/dist/errors/session-error.js.map +0 -1
- package/dist/graph/api.d.ts +0 -85
- package/dist/graph/api.d.ts.map +0 -1
- package/dist/graph/api.js +0 -66
- package/dist/graph/api.js.map +0 -1
- package/dist/graph/index.d.ts.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/mutate/builder.d.ts +0 -108
- package/dist/graph/mutate/builder.d.ts.map +0 -1
- package/dist/graph/mutate/builder.js +0 -127
- package/dist/graph/mutate/builder.js.map +0 -1
- package/dist/graph/mutate/index.d.ts +0 -5
- package/dist/graph/mutate/index.d.ts.map +0 -1
- package/dist/graph/mutate/index.js +0 -3
- package/dist/graph/mutate/index.js.map +0 -1
- package/dist/graph/mutate/shorthands.d.ts +0 -42
- package/dist/graph/mutate/shorthands.d.ts.map +0 -1
- package/dist/graph/mutate/shorthands.js +0 -65
- package/dist/graph/mutate/shorthands.js.map +0 -1
- package/dist/graph/named.d.ts +0 -38
- package/dist/graph/named.d.ts.map +0 -1
- package/dist/graph/named.js +0 -47
- package/dist/graph/named.js.map +0 -1
- package/dist/graph/query/builder.d.ts +0 -116
- package/dist/graph/query/builder.d.ts.map +0 -1
- package/dist/graph/query/builder.js +0 -136
- package/dist/graph/query/builder.js.map +0 -1
- package/dist/graph/query/edge-ref.d.ts +0 -13
- package/dist/graph/query/edge-ref.d.ts.map +0 -1
- package/dist/graph/query/edge-ref.js +0 -56
- package/dist/graph/query/edge-ref.js.map +0 -1
- package/dist/graph/query/edges.d.ts +0 -10
- package/dist/graph/query/edges.d.ts.map +0 -1
- package/dist/graph/query/edges.js +0 -11
- package/dist/graph/query/edges.js.map +0 -1
- package/dist/graph/query/errors.d.ts +0 -31
- package/dist/graph/query/errors.d.ts.map +0 -1
- package/dist/graph/query/errors.js +0 -28
- package/dist/graph/query/errors.js.map +0 -1
- package/dist/graph/query/filter.d.ts +0 -50
- package/dist/graph/query/filter.d.ts.map +0 -1
- package/dist/graph/query/filter.js +0 -32
- package/dist/graph/query/filter.js.map +0 -1
- package/dist/graph/query/index.d.ts +0 -12
- package/dist/graph/query/index.d.ts.map +0 -1
- package/dist/graph/query/index.js +0 -7
- package/dist/graph/query/index.js.map +0 -1
- package/dist/graph/query/lower.d.ts +0 -30
- package/dist/graph/query/lower.d.ts.map +0 -1
- package/dist/graph/query/lower.js +0 -171
- package/dist/graph/query/lower.js.map +0 -1
- package/dist/graph/query/shorthands.d.ts +0 -34
- package/dist/graph/query/shorthands.d.ts.map +0 -1
- package/dist/graph/query/shorthands.js +0 -71
- package/dist/graph/query/shorthands.js.map +0 -1
- package/dist/graph/query/traverse.d.ts +0 -59
- package/dist/graph/query/traverse.d.ts.map +0 -1
- package/dist/graph/query/traverse.js +0 -144
- package/dist/graph/query/traverse.js.map +0 -1
- package/dist/graph/reconcile/execute.d.ts +0 -8
- package/dist/graph/reconcile/execute.d.ts.map +0 -1
- package/dist/graph/reconcile/execute.js +0 -56
- package/dist/graph/reconcile/execute.js.map +0 -1
- package/dist/graph/reconcile/index.d.ts +0 -5
- package/dist/graph/reconcile/index.d.ts.map +0 -1
- package/dist/graph/reconcile/index.js +0 -3
- package/dist/graph/reconcile/index.js.map +0 -1
- package/dist/graph/reconcile/input.d.ts +0 -80
- package/dist/graph/reconcile/input.d.ts.map +0 -1
- package/dist/graph/reconcile/input.js +0 -5
- package/dist/graph/reconcile/input.js.map +0 -1
- package/dist/graph/reconcile/normalize.d.ts +0 -3
- package/dist/graph/reconcile/normalize.d.ts.map +0 -1
- package/dist/graph/reconcile/normalize.js +0 -144
- package/dist/graph/reconcile/normalize.js.map +0 -1
- package/dist/graph/reconcile/result.d.ts +0 -19
- package/dist/graph/reconcile/result.d.ts.map +0 -1
- package/dist/graph/reconcile/result.js +0 -95
- package/dist/graph/reconcile/result.js.map +0 -1
- package/dist/graph/reconcile/scope.d.ts +0 -6
- package/dist/graph/reconcile/scope.d.ts.map +0 -1
- package/dist/graph/reconcile/scope.js +0 -69
- package/dist/graph/reconcile/scope.js.map +0 -1
- package/dist/graph/result/envelope.d.ts +0 -37
- package/dist/graph/result/envelope.d.ts.map +0 -1
- package/dist/graph/result/envelope.js +0 -59
- package/dist/graph/result/envelope.js.map +0 -1
- package/dist/graph/result/index.d.ts +0 -6
- package/dist/graph/result/index.d.ts.map +0 -1
- package/dist/graph/result/index.js +0 -4
- package/dist/graph/result/index.js.map +0 -1
- package/dist/graph/result/next.d.ts +0 -16
- package/dist/graph/result/next.d.ts.map +0 -1
- package/dist/graph/result/next.js +0 -77
- package/dist/graph/result/next.js.map +0 -1
- package/dist/graph/result/paged.d.ts +0 -30
- package/dist/graph/result/paged.d.ts.map +0 -1
- package/dist/graph/result/paged.js +0 -41
- package/dist/graph/result/paged.js.map +0 -1
- package/dist/graph/wire.d.ts +0 -33
- package/dist/graph/wire.d.ts.map +0 -1
- package/dist/graph/wire.js +0 -16
- package/dist/graph/wire.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pacer/batcher.d.ts +0 -11
- package/dist/pacer/batcher.d.ts.map +0 -1
- package/dist/pacer/batcher.js +0 -15
- package/dist/pacer/batcher.js.map +0 -1
- package/dist/pacer/defaults.d.ts +0 -18
- package/dist/pacer/defaults.d.ts.map +0 -1
- package/dist/pacer/defaults.js +0 -18
- package/dist/pacer/defaults.js.map +0 -1
- package/dist/pacer/index.d.ts.map +0 -1
- package/dist/pacer/index.js.map +0 -1
- package/dist/pacer/queue.d.ts +0 -11
- package/dist/pacer/queue.d.ts.map +0 -1
- package/dist/pacer/queue.js +0 -15
- package/dist/pacer/queue.js.map +0 -1
- package/dist/pacer/rate-limiter.d.ts +0 -11
- package/dist/pacer/rate-limiter.d.ts.map +0 -1
- package/dist/pacer/rate-limiter.js +0 -15
- package/dist/pacer/rate-limiter.js.map +0 -1
- package/dist/pacer/retry.d.ts +0 -14
- package/dist/pacer/retry.d.ts.map +0 -1
- package/dist/pacer/retry.js +0 -50
- package/dist/pacer/retry.js.map +0 -1
- package/dist/pool/errors.d.ts +0 -13
- package/dist/pool/errors.d.ts.map +0 -1
- package/dist/pool/errors.js +0 -16
- package/dist/pool/errors.js.map +0 -1
- package/dist/pool/index.d.ts.map +0 -1
- package/dist/pool/index.js.map +0 -1
- package/dist/pool/pool.d.ts.map +0 -1
- package/dist/pool/pool.js.map +0 -1
- package/dist/schema/bound/binder.d.ts +0 -49
- package/dist/schema/bound/binder.d.ts.map +0 -1
- package/dist/schema/bound/binder.js +0 -195
- package/dist/schema/bound/binder.js.map +0 -1
- package/dist/schema/bound/bound-node.d.ts +0 -105
- package/dist/schema/bound/bound-node.d.ts.map +0 -1
- package/dist/schema/bound/bound-node.js +0 -128
- package/dist/schema/bound/bound-node.js.map +0 -1
- package/dist/schema/bound/index.d.ts +0 -10
- package/dist/schema/bound/index.d.ts.map +0 -1
- package/dist/schema/bound/index.js +0 -5
- package/dist/schema/bound/index.js.map +0 -1
- package/dist/schema/bound/view.d.ts +0 -44
- package/dist/schema/bound/view.d.ts.map +0 -1
- package/dist/schema/bound/view.js +0 -117
- package/dist/schema/bound/view.js.map +0 -1
- package/dist/schema/bound/write-props.d.ts +0 -38
- package/dist/schema/bound/write-props.d.ts.map +0 -1
- package/dist/schema/bound/write-props.js +0 -2
- package/dist/schema/bound/write-props.js.map +0 -1
- package/dist/schema/call-args.d.ts +0 -6
- package/dist/schema/call-args.d.ts.map +0 -1
- package/dist/schema/call-args.js +0 -21
- package/dist/schema/call-args.js.map +0 -1
- package/dist/schema/class-proxy.d.ts +0 -11
- package/dist/schema/class-proxy.d.ts.map +0 -1
- package/dist/schema/class-proxy.js +0 -46
- package/dist/schema/class-proxy.js.map +0 -1
- package/dist/schema/extract.d.ts +0 -24
- package/dist/schema/extract.d.ts.map +0 -1
- package/dist/schema/extract.js +0 -45
- package/dist/schema/extract.js.map +0 -1
- package/dist/schema/from-entries.d.ts +0 -12
- package/dist/schema/from-entries.d.ts.map +0 -1
- package/dist/schema/from-entries.js +0 -39
- package/dist/schema/from-entries.js.map +0 -1
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js.map +0 -1
- package/dist/schema/known-dispatch.d.ts +0 -6
- package/dist/schema/known-dispatch.d.ts.map +0 -1
- package/dist/schema/known-dispatch.js +0 -39
- package/dist/schema/known-dispatch.js.map +0 -1
- package/dist/schema/node-proxy.d.ts +0 -21
- package/dist/schema/node-proxy.d.ts.map +0 -1
- package/dist/schema/node-proxy.js +0 -75
- package/dist/schema/node-proxy.js.map +0 -1
- package/dist/schema/persistence.d.ts +0 -31
- package/dist/schema/persistence.d.ts.map +0 -1
- package/dist/schema/persistence.js +0 -2
- package/dist/schema/persistence.js.map +0 -1
- package/dist/schema/proxy-types.d.ts +0 -131
- package/dist/schema/proxy-types.d.ts.map +0 -1
- package/dist/schema/proxy-types.js +0 -2
- package/dist/schema/proxy-types.js.map +0 -1
- package/dist/schema/registry.d.ts +0 -50
- package/dist/schema/registry.d.ts.map +0 -1
- package/dist/schema/registry.js +0 -110
- package/dist/schema/registry.js.map +0 -1
- package/dist/schema/resolve.d.ts +0 -26
- package/dist/schema/resolve.d.ts.map +0 -1
- package/dist/schema/resolve.js +0 -27
- package/dist/schema/resolve.js.map +0 -1
- package/dist/schema/typed-client.d.ts +0 -10
- package/dist/schema/typed-client.d.ts.map +0 -1
- package/dist/schema/typed-client.js +0 -26
- package/dist/schema/typed-client.js.map +0 -1
- package/dist/schema/types.d.ts +0 -9
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js +0 -2
- package/dist/schema/types.js.map +0 -1
- package/dist/session/bound.d.ts.map +0 -1
- package/dist/session/bound.js.map +0 -1
- package/dist/session/client-session.d.ts +0 -72
- package/dist/session/client-session.d.ts.map +0 -1
- package/dist/session/client-session.js +0 -673
- package/dist/session/client-session.js.map +0 -1
- package/dist/session/config.d.ts +0 -168
- package/dist/session/config.d.ts.map +0 -1
- package/dist/session/config.js +0 -2
- package/dist/session/config.js.map +0 -1
- package/dist/session/delegation/cache.d.ts +0 -139
- package/dist/session/delegation/cache.d.ts.map +0 -1
- package/dist/session/delegation/cache.js +0 -256
- package/dist/session/delegation/cache.js.map +0 -1
- package/dist/session/delegation/errors.d.ts +0 -44
- package/dist/session/delegation/errors.d.ts.map +0 -1
- package/dist/session/delegation/errors.js +0 -62
- package/dist/session/delegation/errors.js.map +0 -1
- package/dist/session/delegation/policy.d.ts +0 -183
- package/dist/session/delegation/policy.d.ts.map +0 -1
- package/dist/session/delegation/policy.js +0 -114
- package/dist/session/delegation/policy.js.map +0 -1
- package/dist/session/delegation/utils.d.ts +0 -4
- package/dist/session/delegation/utils.d.ts.map +0 -1
- package/dist/session/delegation/utils.js +0 -12
- package/dist/session/delegation/utils.js.map +0 -1
- package/dist/session/delegation-mint.d.ts +0 -13
- package/dist/session/delegation-mint.d.ts.map +0 -1
- package/dist/session/delegation-mint.js +0 -39
- package/dist/session/delegation-mint.js.map +0 -1
- package/dist/session/dispatch-routes.d.ts +0 -27
- package/dist/session/dispatch-routes.d.ts.map +0 -1
- package/dist/session/dispatch-routes.js +0 -77
- package/dist/session/dispatch-routes.js.map +0 -1
- package/dist/session/errors/index.d.ts +0 -6
- package/dist/session/errors/index.d.ts.map +0 -1
- package/dist/session/errors/index.js +0 -8
- package/dist/session/errors/index.js.map +0 -1
- package/dist/session/errors/session-errors.d.ts +0 -52
- package/dist/session/errors/session-errors.d.ts.map +0 -1
- package/dist/session/errors/session-errors.js +0 -70
- package/dist/session/errors/session-errors.js.map +0 -1
- package/dist/session/forward.d.ts +0 -15
- package/dist/session/forward.d.ts.map +0 -1
- package/dist/session/forward.js +0 -40
- package/dist/session/forward.js.map +0 -1
- package/dist/session/helpers.d.ts +0 -23
- package/dist/session/helpers.d.ts.map +0 -1
- package/dist/session/helpers.js +0 -56
- package/dist/session/helpers.js.map +0 -1
- package/dist/session/hooks.d.ts +0 -140
- package/dist/session/hooks.d.ts.map +0 -1
- package/dist/session/hooks.js +0 -2
- package/dist/session/hooks.js.map +0 -1
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js.map +0 -1
- package/dist/session/redirect/errors.d.ts +0 -45
- package/dist/session/redirect/errors.d.ts.map +0 -1
- package/dist/session/redirect/errors.js +0 -52
- package/dist/session/redirect/errors.js.map +0 -1
- package/dist/session/redirect/policy.d.ts +0 -79
- package/dist/session/redirect/policy.d.ts.map +0 -1
- package/dist/session/redirect/policy.js +0 -69
- package/dist/session/redirect/policy.js.map +0 -1
- package/dist/session/types.d.ts +0 -54
- package/dist/session/types.d.ts.map +0 -1
- package/dist/session/types.js +0 -2
- package/dist/session/types.js.map +0 -1
- package/dist/store/canonicalize.d.ts +0 -44
- package/dist/store/canonicalize.d.ts.map +0 -1
- package/dist/store/canonicalize.js +0 -0
- package/dist/store/canonicalize.js.map +0 -1
- package/dist/store/entities.d.ts +0 -81
- package/dist/store/entities.d.ts.map +0 -1
- package/dist/store/entities.js +0 -202
- package/dist/store/entities.js.map +0 -1
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js.map +0 -1
- package/dist/store/invalidate.d.ts +0 -66
- package/dist/store/invalidate.d.ts.map +0 -1
- package/dist/store/invalidate.js +0 -117
- package/dist/store/invalidate.js.map +0 -1
- package/dist/store/memory.d.ts.map +0 -1
- package/dist/store/memory.js.map +0 -1
- package/dist/store/overlay.d.ts +0 -118
- package/dist/store/overlay.d.ts.map +0 -1
- package/dist/store/overlay.js +0 -237
- package/dist/store/overlay.js.map +0 -1
- package/dist/store/schedule.d.ts +0 -31
- package/dist/store/schedule.d.ts.map +0 -1
- package/dist/store/schedule.js +0 -76
- package/dist/store/schedule.js.map +0 -1
- package/dist/store/shapes.d.ts +0 -92
- package/dist/store/shapes.d.ts.map +0 -1
- package/dist/store/shapes.js +0 -369
- package/dist/store/shapes.js.map +0 -1
- package/dist/store/types.d.ts +0 -168
- package/dist/store/types.d.ts.map +0 -1
- package/dist/store/types.js +0 -7
- package/dist/store/types.js.map +0 -1
- package/dist/transport/binary.d.ts +0 -15
- package/dist/transport/binary.d.ts.map +0 -1
- package/dist/transport/binary.js +0 -2
- package/dist/transport/binary.js.map +0 -1
- package/dist/transport/contract.d.ts +0 -58
- package/dist/transport/contract.d.ts.map +0 -1
- package/dist/transport/contract.js +0 -11
- package/dist/transport/contract.js.map +0 -1
- package/dist/transport/fetch.d.ts +0 -31
- package/dist/transport/fetch.d.ts.map +0 -1
- package/dist/transport/fetch.js +0 -78
- package/dist/transport/fetch.js.map +0 -1
- package/dist/transport/http-envelope.d.ts +0 -49
- package/dist/transport/http-envelope.d.ts.map +0 -1
- package/dist/transport/http-envelope.js +0 -418
- package/dist/transport/http-envelope.js.map +0 -1
- package/dist/transport/http-routed.d.ts +0 -61
- package/dist/transport/http-routed.d.ts.map +0 -1
- package/dist/transport/http-routed.js +0 -409
- package/dist/transport/http-routed.js.map +0 -1
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/index.js.map +0 -1
- package/dist/transport/request-id.d.ts +0 -9
- package/dist/transport/request-id.d.ts.map +0 -1
- package/dist/transport/request-id.js +0 -12
- package/dist/transport/request-id.js.map +0 -1
- package/dist/transport/ws-envelope.d.ts +0 -74
- package/dist/transport/ws-envelope.d.ts.map +0 -1
- package/dist/transport/ws-envelope.js +0 -567
- package/dist/transport/ws-envelope.js.map +0 -1
- package/dist/util/race-signal.d.ts +0 -12
- package/dist/util/race-signal.d.ts.map +0 -1
- package/dist/util/race-signal.js +0 -34
- package/dist/util/race-signal.js.map +0 -1
- package/dist/wire/controller.d.ts +0 -38
- package/dist/wire/controller.d.ts.map +0 -1
- package/dist/wire/controller.js +0 -38
- package/dist/wire/controller.js.map +0 -1
- package/dist/wire/index.d.ts +0 -7
- package/dist/wire/index.d.ts.map +0 -1
- package/dist/wire/index.js +0 -4
- package/dist/wire/index.js.map +0 -1
- package/dist/wire/meta.d.ts +0 -81
- package/dist/wire/meta.d.ts.map +0 -1
- package/dist/wire/meta.js +0 -44
- package/dist/wire/meta.js.map +0 -1
- package/dist/wire/sse.d.ts +0 -67
- package/dist/wire/sse.d.ts.map +0 -1
- package/dist/wire/sse.js +0 -170
- package/dist/wire/sse.js.map +0 -1
package/dist/store/memory.js
CHANGED
|
@@ -1,813 +1,396 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* delete misprediction is loud — a brief reappearance). The overlay is held
|
|
23
|
-
* from apply until the reconciling refetch lands, then dropped — never
|
|
24
|
-
* folded into confirmed state.
|
|
25
|
-
* - Ordering: the logical merge clock is stamped at response ARRIVAL, and a
|
|
26
|
-
* per-scope mutation EPOCH closes the read-straddles-commit window (a
|
|
27
|
-
* response older than a commit is integrated-then-restaled).
|
|
28
|
-
* - Isolation: the `with` lens partitions the ENTITY store, not just the
|
|
29
|
-
* shape key — lenses never share entities.
|
|
30
|
-
*
|
|
31
|
-
* The public surface (`GraphMemory`/`LiveResult`, `createMemory`) is stable:
|
|
32
|
-
* when seq/rev/delta/watch (§6/§7) land, this becomes "fast and never wrong"
|
|
33
|
-
* with no surface change (`commitOverlay` is already the server-delta seam).
|
|
34
|
-
*/
|
|
35
|
-
import { Graph, rawOf } from '@astrale-os/kernel-core';
|
|
36
|
-
import { edgeKey } from '../graph/index.js';
|
|
37
|
-
import { mintedId, PatchBuilderImpl } from '../graph/mutate/index.js';
|
|
38
|
-
import { HAS_PARENT_CLASS } from '../graph/query/edges.js';
|
|
39
|
-
import { shapeInputToAST, shapeKey, stripCursors } from './canonicalize.js';
|
|
40
|
-
import { EntityStore } from './entities.js';
|
|
41
|
-
import { affectedShapes } from './invalidate.js';
|
|
42
|
-
import { normalizePatch, Overlay } from './overlay.js';
|
|
43
|
-
import { TaskQueue } from './schedule.js';
|
|
44
|
-
import { integrateShape, materialize, ShapeStore, shapeViewOf } from './shapes.js';
|
|
45
|
-
/** Bind the memory onto a `GraphApi`. */
|
|
46
|
-
export function createMemory(api, opts) {
|
|
47
|
-
return new Memory(api, opts).facade(opts?.scope ?? 'default');
|
|
48
|
-
}
|
|
49
|
-
class Memory {
|
|
50
|
-
defaultApi;
|
|
51
|
-
scopes = new Map();
|
|
52
|
-
apis = new Map();
|
|
53
|
-
now;
|
|
54
|
-
ttlMs;
|
|
55
|
-
tombstoneTtlMs;
|
|
56
|
-
onError;
|
|
57
|
-
dev;
|
|
58
|
-
sweepEvery;
|
|
59
|
-
scheduler;
|
|
60
|
-
clock = 0;
|
|
61
|
-
mutationSeq = 0;
|
|
62
|
-
opCount = 0;
|
|
63
|
-
constructor(defaultApi, opts) {
|
|
64
|
-
this.defaultApi = defaultApi;
|
|
65
|
-
this.now = opts?.now ?? Date.now;
|
|
66
|
-
this.ttlMs = opts?.ttlMs ?? 30_000;
|
|
67
|
-
this.tombstoneTtlMs = opts?.tombstoneTtlMs ?? 300_000;
|
|
68
|
-
this.onError = opts?.onError;
|
|
69
|
-
this.dev = opts?.dev ?? false;
|
|
70
|
-
this.sweepEvery = opts?.sweepEvery ?? 128;
|
|
71
|
-
this.scheduler = new TaskQueue(opts?.concurrency ?? 4);
|
|
72
|
-
}
|
|
73
|
-
facade(scope) {
|
|
74
|
-
return {
|
|
75
|
-
scope,
|
|
76
|
-
api: this.apiFor(scope),
|
|
77
|
-
query: (shape, o) => this.query(scope, shape, o),
|
|
78
|
-
peek: (shape, o) => this.peek(scope, shape, o),
|
|
79
|
-
preload: (shape, o) => this.preload(scope, shape, o),
|
|
80
|
-
subscribe: (shape, cb, o) => this.subscribe(scope, shape, cb, o),
|
|
81
|
-
getSnapshot: (shape, o) => this.getSnapshot(scope, shape, o),
|
|
82
|
-
promise: (shape, o) => this.promise(scope, shape, o),
|
|
83
|
-
watch: (shape, cb, o) => this.watchShape(scope, shape, cb, o),
|
|
84
|
-
mutate: (arg, o) => this.mutate(scope, arg, o),
|
|
85
|
-
reconcile: (input) => this.runReconcile(scope, input),
|
|
86
|
-
update: (node, props, o) => this.update(scope, node, props, o),
|
|
87
|
-
create: (cls, at, props, o) => this.create(scope, cls, at, props, o),
|
|
88
|
-
remove: (node, o) => this.remove(scope, node, o),
|
|
89
|
-
link: (edge, o) => this.link(scope, edge, o),
|
|
90
|
-
unlink: (edge, o) => this.unlink(scope, edge, o),
|
|
91
|
-
overlay: (build, o) => this.openOverlay(o?.scope ?? scope, build),
|
|
92
|
-
forScope: (s, a) => {
|
|
93
|
-
if (a !== undefined)
|
|
94
|
-
this.apis.set(s, a);
|
|
95
|
-
return this.facade(s);
|
|
96
|
-
},
|
|
97
|
-
sweep: () => this.sweep(),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// ── Scope + key plumbing ────────────────────────────────────────────────────
|
|
101
|
-
apiFor(scope) {
|
|
102
|
-
return this.apis.get(scope) ?? this.defaultApi;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* The isolation key partitions the store by `(principal, with-lens)` (§5.7):
|
|
106
|
-
* two lenses over the same principal never share entities, shapes, or overlay.
|
|
107
|
-
*/
|
|
108
|
-
isoKey(principal, withPerm) {
|
|
109
|
-
return withPerm === undefined ? principal : `${principal}::with=${withPerm}`;
|
|
110
|
-
}
|
|
111
|
-
state(principal, withPerm) {
|
|
112
|
-
const key = this.isoKey(principal, withPerm);
|
|
113
|
-
let s = this.scopes.get(key);
|
|
114
|
-
if (s === undefined) {
|
|
115
|
-
s = {
|
|
116
|
-
principal,
|
|
117
|
-
isoKey: key,
|
|
118
|
-
entities: new EntityStore(),
|
|
119
|
-
shapes: new ShapeStore(),
|
|
120
|
-
overlay: new Overlay(),
|
|
121
|
-
epoch: 0,
|
|
122
|
-
};
|
|
123
|
-
this.scopes.set(key, s);
|
|
1
|
+
import { encodeEdgeKey } from '@astrale-os/kernel-core/graph/edge';
|
|
2
|
+
import { ClientError } from '../errors/index.js';
|
|
3
|
+
import { edgeIdentity, EntityIndex } from './entity-index.js';
|
|
4
|
+
import { OptimisticOverlay } from './optimistic.js';
|
|
5
|
+
import { COLD_SNAPSHOT, QueryShape } from './shape.js';
|
|
6
|
+
export class GraphMemory {
|
|
7
|
+
options;
|
|
8
|
+
entities = new EntityIndex();
|
|
9
|
+
overlay = new OptimisticOverlay();
|
|
10
|
+
shapes = new Map();
|
|
11
|
+
pending = [];
|
|
12
|
+
active = 0;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
ensure(key, ast, page) {
|
|
17
|
+
const existing = this.shapes.get(key);
|
|
18
|
+
const now = this.options.now();
|
|
19
|
+
if (existing !== undefined) {
|
|
20
|
+
this.touch(existing, now);
|
|
21
|
+
return existing;
|
|
124
22
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
keyOf(state, scope, ast) {
|
|
132
|
-
return shapeKey(ast, scope, (raw) => state.entities.resolvePathToId(raw));
|
|
133
|
-
}
|
|
134
|
-
/** Normalize an input to its AST, folding a per-read `with` onto it so it keys the shape. */
|
|
135
|
-
astFor(input, opts) {
|
|
136
|
-
const ast = shapeInputToAST(input);
|
|
137
|
-
if (opts?.with !== undefined && ast.with !== opts.with)
|
|
138
|
-
return { ...ast, with: opts.with };
|
|
139
|
-
return ast;
|
|
140
|
-
}
|
|
141
|
-
/** Resolve (and create) the entry for a shape input. */
|
|
142
|
-
entryFor(state, scope, input, opts) {
|
|
143
|
-
const ast = this.astFor(input, opts);
|
|
144
|
-
const key = this.keyOf(state, scope, ast);
|
|
145
|
-
const created = state.shapes.get(key) === undefined;
|
|
146
|
-
const entry = state.shapes.ensure(key, scope, stripCursors(ast), ast.from.map(rawOf));
|
|
147
|
-
// window is per-shape and fixed at creation — a later caller's option can't
|
|
148
|
-
// retune a shape other observers already read under.
|
|
149
|
-
if (created && opts?.window !== undefined)
|
|
150
|
-
entry.window = opts.window;
|
|
151
|
-
if (entry.observers === 0 && entry.releasedAt === null)
|
|
152
|
-
entry.releasedAt = this.now();
|
|
153
|
-
return entry;
|
|
154
|
-
}
|
|
155
|
-
/** Look up an existing entry without creating one (peek / render-pure getSnapshot). */
|
|
156
|
-
lookup(state, scope, input, opts) {
|
|
157
|
-
return state.shapes.get(this.keyOf(state, scope, this.astFor(input, opts)));
|
|
158
|
-
}
|
|
159
|
-
/** Follow the provisional→resolved alias to a subscription's live entry (post-merge). */
|
|
160
|
-
live(state, entry) {
|
|
161
|
-
return state.shapes.get(entry.key) ?? entry;
|
|
162
|
-
}
|
|
163
|
-
// ── Reads ────────────────────────────────────────────────────────────────────
|
|
164
|
-
async query(scope, input, opts) {
|
|
165
|
-
const state = this.state(scope, opts?.with);
|
|
166
|
-
let entry = this.entryFor(state, scope, input, opts);
|
|
167
|
-
this.tick();
|
|
168
|
-
if (!entry.hasData || entry.stale) {
|
|
169
|
-
try {
|
|
170
|
-
await this.revalidate(state, entry, entry.hasData ? 'reconcile' : 'fresh');
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
// Warm shape: keep last-good data + `error` (§5.5); only a cold read throws.
|
|
174
|
-
if (!this.live(state, entry).hasData)
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
entry = this.live(state, entry);
|
|
23
|
+
this.releaseExpired(now);
|
|
24
|
+
if (this.shapes.size >= this.options.maximumShapes)
|
|
25
|
+
this.evictLeastRecentlyUsed();
|
|
26
|
+
if (this.shapes.size >= this.options.maximumShapes) {
|
|
27
|
+
throw new ClientError('GraphStore shape capacity is exhausted by observed or in-flight queries.');
|
|
178
28
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.tick();
|
|
202
|
-
// Fetch when cold, and revalidate when known-stale (a prior write or a failed
|
|
203
|
-
// refresh left it stale) — §5.5. Reconcile preserves the accumulated window.
|
|
204
|
-
if ((!entry.hasData || entry.stale) && entry.inflight === null && opts?.live !== false) {
|
|
205
|
-
void this.revalidate(state, entry, entry.hasData ? 'reconcile' : 'fresh').catch(() => { });
|
|
206
|
-
}
|
|
207
|
-
return () => {
|
|
208
|
-
// A merge (rehome) may have moved this subscription onto the surviving
|
|
209
|
-
// entry — re-resolve so the count/listener land on the live one.
|
|
210
|
-
const e = this.live(state, entry);
|
|
211
|
-
e.listeners.delete(onStoreChange);
|
|
212
|
-
e.observers = Math.max(0, e.observers - 1);
|
|
213
|
-
if (e.observers === 0)
|
|
214
|
-
e.releasedAt = this.now();
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Render-pure (§5.7): reads an EXISTING entry, never creates one (entry
|
|
219
|
-
* creation is a subscribe/query concern — creating here double-mints entries
|
|
220
|
-
* under StrictMode's double render). A cold shape returns a shared, stable
|
|
221
|
-
* placeholder so useSyncExternalStore sees a referentially constant snapshot.
|
|
222
|
-
*/
|
|
223
|
-
getSnapshot(scope, input, opts) {
|
|
224
|
-
const state = this.state(scope, opts?.with);
|
|
225
|
-
const entry = this.lookup(state, scope, input, opts);
|
|
226
|
-
if (entry === undefined)
|
|
227
|
-
return COLD;
|
|
228
|
-
return this.snapshot(state, entry);
|
|
229
|
-
}
|
|
230
|
-
promise(scope, input, opts) {
|
|
231
|
-
const state = this.state(scope, opts?.with);
|
|
232
|
-
const entry = this.entryFor(state, scope, input, opts);
|
|
233
|
-
if (entry.hasData)
|
|
234
|
-
return Promise.resolve(this.snapshot(state, entry));
|
|
235
|
-
return this.revalidate(state, entry, 'fresh').then(() => this.snapshot(state, this.live(state, entry)));
|
|
236
|
-
}
|
|
237
|
-
watchShape(scope, input, cb, opts) {
|
|
238
|
-
const state = this.state(scope, opts?.with);
|
|
239
|
-
const entry = this.entryFor(state, scope, input, opts);
|
|
240
|
-
const unsub = this.subscribe(scope, input, () => cb(this.snapshot(state, this.live(state, entry))), opts);
|
|
241
|
-
cb(this.snapshot(state, this.live(state, entry)));
|
|
242
|
-
return unsub;
|
|
243
|
-
}
|
|
244
|
-
// ── Fetch / integrate ─────────────────────────────────────────────────────────
|
|
245
|
-
/** The AST + membership mode a revalidation intent requests (§5.7 window-preserving). */
|
|
246
|
-
fetchPlan(entry, intent) {
|
|
247
|
-
if (intent === 'more') {
|
|
248
|
-
return {
|
|
249
|
-
ast: entry.contAst ?? entry.baseAst,
|
|
250
|
-
mode: entry.window === 'paged' ? 'replace' : 'append',
|
|
251
|
-
};
|
|
29
|
+
const shape = new QueryShape(key, ast, page, now);
|
|
30
|
+
shape.releasedAt = now;
|
|
31
|
+
this.shapes.set(key, shape);
|
|
32
|
+
return shape;
|
|
33
|
+
}
|
|
34
|
+
get(key) {
|
|
35
|
+
const shape = this.shapes.get(key);
|
|
36
|
+
if (shape !== undefined)
|
|
37
|
+
this.touch(shape, this.options.now());
|
|
38
|
+
return shape;
|
|
39
|
+
}
|
|
40
|
+
async read(shape, options) {
|
|
41
|
+
this.options.requireOpen();
|
|
42
|
+
requireReadLive(options.signal, this.options.lifecycle);
|
|
43
|
+
const reusable = shape.response !== undefined &&
|
|
44
|
+
shape.state === 'ready' &&
|
|
45
|
+
shape.refreshedAt !== undefined &&
|
|
46
|
+
this.options.now() - shape.refreshedAt < this.options.ttlMs;
|
|
47
|
+
if (options.freshness !== 'refresh' && reusable)
|
|
48
|
+
return shape.response;
|
|
49
|
+
if (shape.inflight !== undefined) {
|
|
50
|
+
return observeRead(shape.inflight, options, this.options.lifecycle);
|
|
252
51
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
.then((result) => {
|
|
273
|
-
const wire = result.wire;
|
|
274
|
-
const seq = ++this.clock; // ARRIVAL order (§5.7), not dispatch order
|
|
275
|
-
state.entities.integrate(wire, seq);
|
|
276
|
-
const resolvedKey = this.keyOf(state, entry.scope, entry.baseAst);
|
|
277
|
-
const live = state.shapes.rehome(entry, resolvedKey);
|
|
278
|
-
live.inflight = null;
|
|
279
|
-
if (intent === 'more' && mode === 'append')
|
|
280
|
-
live.windowPages++;
|
|
281
|
-
else if (intent === 'fresh')
|
|
282
|
-
live.windowPages = 1;
|
|
283
|
-
integrateShape(live, wire, seq, mode);
|
|
284
|
-
if (dispatchEpoch < state.epoch) {
|
|
285
|
-
// Read straddled a commit: integrate (so a cold shape still gets data
|
|
286
|
-
// and continuous writes can't starve it) THEN restale (so it converges
|
|
287
|
-
// — at quiescence the last refetch's epoch matches). Chosen over
|
|
288
|
-
// discard for those two reasons.
|
|
289
|
-
live.stale = true;
|
|
290
|
-
void this.scheduleReconcile(state, live);
|
|
52
|
+
const prior = shape.response;
|
|
53
|
+
this.publish(shape, prior === undefined ? 'loading' : this.overlay.hasAny() ? 'optimistic' : 'refreshing');
|
|
54
|
+
const inflight = this.schedule(async () => {
|
|
55
|
+
const result = await this.options.graph.query(shape.ast, queryOptions(shape.page, this.options.lifecycle));
|
|
56
|
+
this.options.requireOpen();
|
|
57
|
+
const integration = this.entities.integrate(result.result);
|
|
58
|
+
shape.references = integration.references;
|
|
59
|
+
shape.confirmed = result;
|
|
60
|
+
shape.response = this.materialize(result, integration.references);
|
|
61
|
+
shape.refreshedAt = this.options.now();
|
|
62
|
+
this.touch(shape, shape.refreshedAt);
|
|
63
|
+
this.publish(shape, this.overlay.hasAny() ? 'optimistic' : 'ready');
|
|
64
|
+
for (const other of this.shapes.values()) {
|
|
65
|
+
if (other === shape || other.response === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
if (other.referencesAny(integration.changedNodes, integration.changedEdges)) {
|
|
68
|
+
other.response = this.materialize(other.confirmed, other.references);
|
|
69
|
+
this.publish(other, other.state);
|
|
70
|
+
}
|
|
291
71
|
}
|
|
292
|
-
|
|
293
|
-
this.audit(state);
|
|
294
|
-
return wire;
|
|
72
|
+
return shape.response;
|
|
295
73
|
})
|
|
296
74
|
.catch((error) => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this.notify(live);
|
|
75
|
+
if (prior === undefined)
|
|
76
|
+
this.publish(shape, 'failed', error);
|
|
77
|
+
else {
|
|
78
|
+
shape.response = prior;
|
|
79
|
+
this.publish(shape, this.overlay.hasAny() ? 'optimistic' : 'stale');
|
|
80
|
+
}
|
|
304
81
|
throw error;
|
|
82
|
+
})
|
|
83
|
+
.finally(() => {
|
|
84
|
+
if (shape.inflight === inflight)
|
|
85
|
+
shape.inflight = undefined;
|
|
305
86
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.notify(entry);
|
|
309
|
-
return p;
|
|
87
|
+
shape.inflight = inflight;
|
|
88
|
+
return observeRead(inflight, options, this.options.lifecycle);
|
|
310
89
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return this.scheduler.request(entry, () => this.revalidate(state, this.live(state, entry), 'reconcile').then(() => undefined, () => undefined));
|
|
90
|
+
snapshot(shape) {
|
|
91
|
+
return shape?.snapshot ?? COLD_SNAPSHOT;
|
|
314
92
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
nodes: mat.nodes,
|
|
325
|
-
first: mat.first,
|
|
326
|
-
node: mat.first,
|
|
327
|
-
children: mat.children,
|
|
328
|
-
gathered: (alias) => mat.gathered(alias),
|
|
329
|
-
pending: entry.inflight !== null,
|
|
330
|
-
stale: entry.stale,
|
|
331
|
-
error: entry.error,
|
|
332
|
-
live: entry.observers > 0,
|
|
333
|
-
seq: 0,
|
|
334
|
-
more: {
|
|
335
|
-
has: !entry.exhausted && entry.contAst !== null,
|
|
336
|
-
pending: entry.inflight !== null,
|
|
337
|
-
load: async () => {
|
|
338
|
-
const e = this.live(state, entry);
|
|
339
|
-
if (e.exhausted || e.contAst === null)
|
|
340
|
-
return;
|
|
341
|
-
await this.revalidate(state, e, 'more');
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
refetch: async () => {
|
|
345
|
-
const e = this.live(state, entry);
|
|
346
|
-
e.stale = true;
|
|
347
|
-
await this.revalidate(state, e, 'reconcile'); // window-preserving
|
|
348
|
-
},
|
|
93
|
+
subscribe(shape, listener) {
|
|
94
|
+
this.options.requireOpen();
|
|
95
|
+
shape.listeners.add(listener);
|
|
96
|
+
shape.accessedAt = this.options.now();
|
|
97
|
+
shape.releasedAt = undefined;
|
|
98
|
+
return () => {
|
|
99
|
+
shape.listeners.delete(listener);
|
|
100
|
+
if (!shape.observed)
|
|
101
|
+
shape.releasedAt = this.options.now();
|
|
349
102
|
};
|
|
350
|
-
entry.result = result;
|
|
351
|
-
entry.dirty = false;
|
|
352
|
-
return result;
|
|
353
103
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
for (const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
await arg(builder);
|
|
364
|
-
const patch = builder.build();
|
|
365
|
-
const result = await this.applyWrite(scope, patch, opts);
|
|
366
|
-
builder.resolve(result.createdNodes);
|
|
367
|
-
return result;
|
|
368
|
-
}
|
|
369
|
-
return this.applyWrite(scope, arg, opts);
|
|
370
|
-
}
|
|
371
|
-
async runReconcile(scope, input) {
|
|
372
|
-
const result = await this.apiFor(scope).reconcile(input);
|
|
373
|
-
if (!result.applied)
|
|
374
|
-
return result;
|
|
375
|
-
const dispatched = normalizePatch(result.patch);
|
|
376
|
-
if (!patchHasOperations(dispatched))
|
|
377
|
-
return result;
|
|
378
|
-
for (const part of this.partitionsOf(scope)) {
|
|
379
|
-
part.epoch++;
|
|
380
|
-
for (const p of this.markStaleByPatch(part, dispatched))
|
|
381
|
-
void p;
|
|
104
|
+
invalidate(shape) {
|
|
105
|
+
this.options.requireOpen();
|
|
106
|
+
for (const candidate of shape === undefined ? this.shapes.values() : [shape]) {
|
|
107
|
+
if (candidate.response === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
this.publish(candidate, this.overlay.hasAny() ? 'optimistic' : 'stale');
|
|
110
|
+
if (candidate.observed && candidate.inflight === undefined) {
|
|
111
|
+
void this.read(candidate, { page: candidate.page }).catch((error) => this.report(error));
|
|
112
|
+
}
|
|
382
113
|
}
|
|
383
|
-
return result;
|
|
384
|
-
}
|
|
385
|
-
async update(scope, node, props, opts) {
|
|
386
|
-
const state = this.state(scope);
|
|
387
|
-
const patch = {
|
|
388
|
-
nodes: { update: [{ class: this.classOf(state, node), path: refPathRaw(node), props }] },
|
|
389
|
-
};
|
|
390
|
-
await this.applyWrite(scope, patch, opts);
|
|
391
114
|
}
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return mintedId(result.createdNodes, atRaw, 'node');
|
|
399
|
-
}
|
|
400
|
-
async remove(scope, node, opts) {
|
|
401
|
-
const state = this.state(scope);
|
|
402
|
-
const patch = {
|
|
403
|
-
nodes: { delete: [{ class: this.classOf(state, node), path: refPathRaw(node) }] },
|
|
404
|
-
};
|
|
405
|
-
await this.applyWrite(scope, patch, opts);
|
|
406
|
-
}
|
|
407
|
-
async link(scope, edge, opts) {
|
|
408
|
-
const { props, ...identity } = edge;
|
|
409
|
-
const patch = {
|
|
410
|
-
edges: { create: [{ ...rawIdentity(identity), props: props ?? {} }] },
|
|
411
|
-
};
|
|
412
|
-
const result = await this.applyWrite(scope, patch, opts);
|
|
413
|
-
return mintedId(result.createdEdges, edgeKey(identity), 'edge');
|
|
414
|
-
}
|
|
415
|
-
async unlink(scope, edge, opts) {
|
|
416
|
-
const patch = { edges: { delete: [rawIdentity(edge)] } };
|
|
417
|
-
await this.applyWrite(scope, patch, opts);
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* SAFE MODE write (§5.7): dispatch, then reconcile the touched shapes by
|
|
421
|
-
* refetch. `optimistic` selects the DISPLAY overlay (never folded): `'auto'`
|
|
422
|
-
* (default) overlays the display-safe arms of the authored patch (prop updates
|
|
423
|
-
* on cached nodes + deletes); a function overlays a manually-built patch's
|
|
424
|
-
* display-safe arms; `false` skips the overlay. Creates/links/unlinks are
|
|
425
|
-
* always reconcile-only — no structural membership is ever predicted.
|
|
426
|
-
*/
|
|
427
|
-
async applyWrite(scope, patch, opts) {
|
|
428
|
-
const home = this.state(scope);
|
|
429
|
-
const mode = opts?.optimistic ?? 'auto';
|
|
430
|
-
const dispatched = normalizePatch(patch);
|
|
431
|
-
const display = mode === false
|
|
432
|
-
? null
|
|
433
|
-
: this.displayArms(home, mode === 'auto' ? dispatched : normalizePatch(this.buildPatch(mode)));
|
|
434
|
-
const txn = display !== null && display.has ? this.beginOverlay(home, display.patch) : null;
|
|
435
|
-
this.tick();
|
|
436
|
-
try {
|
|
437
|
-
const result = await this.apiFor(scope).mutate(patch);
|
|
438
|
-
// Commit acked (§5.7 ordering): bump every lens partition's epoch so any
|
|
439
|
-
// read now in flight (dispatched pre-commit) is caught as a straddle.
|
|
440
|
-
for (const part of this.partitionsOf(scope))
|
|
441
|
-
part.epoch++;
|
|
442
|
-
this.reconcile(scope, dispatched, home, txn);
|
|
443
|
-
opts?.onCommit?.(result);
|
|
444
|
-
return result;
|
|
445
|
-
}
|
|
446
|
-
catch (error) {
|
|
447
|
-
if (txn !== null && opts?.rollback !== false)
|
|
448
|
-
this.rollbackOverlay(home, txn);
|
|
449
|
-
opts?.onError?.(error);
|
|
450
|
-
this.emit({ kind: 'mutation', mutationId: txn?.mutationId ?? '(none)', error });
|
|
451
|
-
throw error;
|
|
115
|
+
optimistic() {
|
|
116
|
+
for (const shape of this.shapes.values()) {
|
|
117
|
+
if (shape.response === undefined)
|
|
118
|
+
continue;
|
|
119
|
+
shape.response = this.materialize(shape.confirmed, shape.references);
|
|
120
|
+
this.publish(shape, 'optimistic');
|
|
452
121
|
}
|
|
453
122
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
*/
|
|
461
|
-
displayArms(state, dispatched) {
|
|
462
|
-
const update = [];
|
|
463
|
-
for (const u of dispatched.nodes.update) {
|
|
464
|
-
const id = state.entities.resolvePathToId(u.path);
|
|
465
|
-
if (id === undefined)
|
|
466
|
-
continue; // not cached → reconcile-only (can't predict blind)
|
|
467
|
-
const ref = state.entities.node(id)?.wire.props;
|
|
468
|
-
const q = qualifyKeys(u.props, ref);
|
|
469
|
-
if (q.unresolved)
|
|
470
|
-
continue; // ambiguous/unqualifiable key → reconcile-only
|
|
471
|
-
update.push({ ...u, props: q.props });
|
|
123
|
+
settleOptimistic() {
|
|
124
|
+
for (const shape of this.shapes.values()) {
|
|
125
|
+
if (shape.response === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
shape.response = this.materialize(shape.confirmed, shape.references);
|
|
128
|
+
this.publish(shape, this.overlay.hasAny() ? 'optimistic' : 'stale');
|
|
472
129
|
}
|
|
473
|
-
const del = dispatched.nodes.delete;
|
|
474
|
-
const patch = {
|
|
475
|
-
nodes: { create: [], update, delete: del },
|
|
476
|
-
edges: { create: [], update: [], delete: [] },
|
|
477
|
-
};
|
|
478
|
-
return { patch, has: update.length > 0 || del.length > 0 };
|
|
479
130
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
state.overlay.add({
|
|
484
|
-
mutationId,
|
|
485
|
-
patch: displayPatch,
|
|
486
|
-
provisionalNodes: new Map(),
|
|
487
|
-
provisionalEdges: new Map(),
|
|
488
|
-
});
|
|
489
|
-
const affected = this.affectedEntries(state, displayPatch);
|
|
490
|
-
for (const entry of affected)
|
|
491
|
-
this.notify(entry);
|
|
492
|
-
this.audit(state);
|
|
493
|
-
return { mutationId, patch: displayPatch, affected };
|
|
494
|
-
}
|
|
495
|
-
/** Drop a rolled-back display overlay (the dispatch failed). No membership to undo. */
|
|
496
|
-
rollbackOverlay(state, txn) {
|
|
497
|
-
state.overlay.drop(txn.mutationId);
|
|
498
|
-
for (const entry of txn.affected)
|
|
499
|
-
this.notify(entry);
|
|
500
|
-
this.audit(state);
|
|
131
|
+
sweep() {
|
|
132
|
+
this.options.requireOpen();
|
|
133
|
+
this.releaseExpired(this.options.now());
|
|
501
134
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
*/
|
|
508
|
-
reconcile(scope, dispatched, home, txn) {
|
|
509
|
-
const promises = [];
|
|
510
|
-
for (const part of this.partitionsOf(scope)) {
|
|
511
|
-
for (const p of this.markStaleByPatch(part, dispatched))
|
|
512
|
-
promises.push(p);
|
|
135
|
+
releaseExpired(now) {
|
|
136
|
+
for (const [key, shape] of this.shapes) {
|
|
137
|
+
if (this.releasable(shape) && now - shape.releasedAt >= this.options.ttlMs) {
|
|
138
|
+
this.shapes.delete(key);
|
|
139
|
+
}
|
|
513
140
|
}
|
|
514
|
-
|
|
515
|
-
return;
|
|
516
|
-
void Promise.allSettled(promises).then(() => this.dropOverlay(home, txn));
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Drop a held overlay once its reconciling refetch has landed, emitting a
|
|
520
|
-
* DIVERGENCE event if what it displayed differs from the refetched truth
|
|
521
|
-
* (a delete whose node the server still returns; an update the server didn't
|
|
522
|
-
* apply). This is the Tier-0 tripwire that a prediction was wrong.
|
|
523
|
-
*/
|
|
524
|
-
dropOverlay(state, txn) {
|
|
525
|
-
this.detectDivergence(state, txn);
|
|
526
|
-
state.overlay.drop(txn.mutationId);
|
|
527
|
-
for (const entry of txn.affected)
|
|
528
|
-
this.notify(entry);
|
|
529
|
-
this.audit(state);
|
|
141
|
+
this.sweepEntities();
|
|
530
142
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const eff = state.overlay.effects(state.entities);
|
|
536
|
-
for (const u of txn.patch.nodes.update) {
|
|
537
|
-
const id = state.entities.resolvePathToId(u.path);
|
|
538
|
-
if (id === undefined)
|
|
143
|
+
evictLeastRecentlyUsed() {
|
|
144
|
+
let oldest;
|
|
145
|
+
for (const shape of this.shapes.values()) {
|
|
146
|
+
if (!this.releasable(shape))
|
|
539
147
|
continue;
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
for (const key of Object.keys(u.props)) {
|
|
543
|
-
if (!Object.is(predicted?.props[key], confirmed?.props[key])) {
|
|
544
|
-
this.emit({ kind: 'divergence', shape, id: String(id), detail: `update:${key}` });
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
148
|
+
if (oldest === undefined || shape.accessedAt < oldest.accessedAt)
|
|
149
|
+
oldest = shape;
|
|
548
150
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (id !== undefined && [...txn.affected].some((e) => e.memberSet.has(id))) {
|
|
553
|
-
this.emit({ kind: 'divergence', shape, id: String(id), detail: 'delete:still-present' });
|
|
554
|
-
}
|
|
151
|
+
if (oldest !== undefined) {
|
|
152
|
+
this.shapes.delete(oldest.key);
|
|
153
|
+
this.sweepEntities();
|
|
555
154
|
}
|
|
556
155
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
const ctx = {
|
|
560
|
-
hasParentClass: HAS_PARENT_CLASS,
|
|
561
|
-
resolve: (raw) => state.entities.resolvePathToId(raw),
|
|
562
|
-
};
|
|
563
|
-
const entries = [...state.shapes.all()];
|
|
564
|
-
const ids = affectedShapes(patch, entries.map((e) => shapeViewOf(e, state.entities)), ctx);
|
|
565
|
-
return new Set(entries.filter((e) => ids.has(e.key)));
|
|
156
|
+
releasable(shape) {
|
|
157
|
+
return !shape.observed && shape.inflight === undefined && shape.releasedAt !== undefined;
|
|
566
158
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
this.notify(entry);
|
|
579
|
-
if (entry.observers > 0)
|
|
580
|
-
promises.push(this.scheduleReconcile(state, entry));
|
|
159
|
+
touch(shape, now) {
|
|
160
|
+
shape.accessedAt = now;
|
|
161
|
+
if (!shape.observed)
|
|
162
|
+
shape.releasedAt = now;
|
|
163
|
+
}
|
|
164
|
+
sweepEntities() {
|
|
165
|
+
const nodes = new Set();
|
|
166
|
+
const edges = new Set();
|
|
167
|
+
for (const shape of this.shapes.values()) {
|
|
168
|
+
shape.references?.nodes.forEach((id) => nodes.add(id));
|
|
169
|
+
shape.references?.edges.forEach((key) => edges.add(key));
|
|
581
170
|
}
|
|
582
|
-
|
|
171
|
+
this.entities.sweep(nodes, edges);
|
|
583
172
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
173
|
+
close(error) {
|
|
174
|
+
for (const shape of this.shapes.values()) {
|
|
175
|
+
shape.listeners.clear();
|
|
176
|
+
shape.inflight?.catch(() => undefined);
|
|
177
|
+
}
|
|
178
|
+
this.shapes.clear();
|
|
179
|
+
this.entities.clear();
|
|
180
|
+
this.overlay.clear();
|
|
181
|
+
while (this.pending.length > 0)
|
|
182
|
+
this.pending.shift()?.reject(error);
|
|
183
|
+
}
|
|
184
|
+
materialize(template, references) {
|
|
185
|
+
return Object.freeze({
|
|
186
|
+
result: this.materializeResult(template.result, references),
|
|
187
|
+
page: template.page,
|
|
188
|
+
});
|
|
589
189
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const display = this.displayArms(state, normalizePatch(this.buildPatch(build)));
|
|
598
|
-
const txn = display.has ? this.beginOverlay(state, display.patch) : null;
|
|
599
|
-
let settled = false;
|
|
600
|
-
return {
|
|
601
|
-
commit: (_result) => {
|
|
602
|
-
if (settled)
|
|
603
|
-
return;
|
|
604
|
-
settled = true;
|
|
605
|
-
for (const part of this.partitionsOf(scope))
|
|
606
|
-
part.epoch++;
|
|
607
|
-
if (txn === null)
|
|
608
|
-
return;
|
|
609
|
-
const promises = [];
|
|
610
|
-
for (const entry of txn.affected) {
|
|
611
|
-
entry.stale = true;
|
|
612
|
-
this.notify(entry);
|
|
613
|
-
if (entry.observers > 0)
|
|
614
|
-
promises.push(this.scheduleReconcile(state, entry));
|
|
190
|
+
materializeResult(template, references) {
|
|
191
|
+
if (template.kind === 'nodes') {
|
|
192
|
+
const nodes = [];
|
|
193
|
+
for (const projection of template.nodes) {
|
|
194
|
+
if (projection.kind === 'reference') {
|
|
195
|
+
nodes.push(projection);
|
|
196
|
+
continue;
|
|
615
197
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
},
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
classOf(state, node) {
|
|
628
|
-
if (isNodeValue(node))
|
|
629
|
-
return rawOf(node.class);
|
|
630
|
-
const id = state.entities.resolvePathToId(rawOf(node));
|
|
631
|
-
const cls = id !== undefined ? state.entities.node(id)?.wire.class : undefined;
|
|
632
|
-
if (cls === undefined) {
|
|
633
|
-
throw new Error(`memory: cannot resolve the class of "${rawOf(node)}" for a write — ` +
|
|
634
|
-
'pass the Node value (not a bare path) for a node not yet in the memory.');
|
|
198
|
+
const node = this.overlay.node(projection.value.id, this.entities);
|
|
199
|
+
if (node !== undefined)
|
|
200
|
+
nodes.push(Object.freeze({ kind: 'value', value: node }));
|
|
201
|
+
}
|
|
202
|
+
return Object.freeze({
|
|
203
|
+
kind: 'nodes',
|
|
204
|
+
nodes: Object.freeze(nodes),
|
|
205
|
+
});
|
|
635
206
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
207
|
+
if (template.kind === 'edges') {
|
|
208
|
+
const edges = [];
|
|
209
|
+
for (const item of template.edges) {
|
|
210
|
+
const edge = item.edge.kind === 'reference'
|
|
211
|
+
? item.edge
|
|
212
|
+
: (() => {
|
|
213
|
+
const value = this.entities.edge(edgeIdentity(item.edge.value));
|
|
214
|
+
return value === undefined
|
|
215
|
+
? undefined
|
|
216
|
+
: Object.freeze({ kind: 'value', value });
|
|
217
|
+
})();
|
|
218
|
+
const source = item.source.kind === 'reference'
|
|
219
|
+
? item.source
|
|
220
|
+
: (() => {
|
|
221
|
+
const value = this.overlay.node(item.source.value.id, this.entities);
|
|
222
|
+
return value === undefined
|
|
223
|
+
? undefined
|
|
224
|
+
: Object.freeze({ kind: 'value', value });
|
|
225
|
+
})();
|
|
226
|
+
const target = item.target.kind === 'reference'
|
|
227
|
+
? item.target
|
|
228
|
+
: (() => {
|
|
229
|
+
const value = this.overlay.node(item.target.value.id, this.entities);
|
|
230
|
+
return value === undefined
|
|
231
|
+
? undefined
|
|
232
|
+
: Object.freeze({ kind: 'value', value });
|
|
233
|
+
})();
|
|
234
|
+
if (edge !== undefined && source !== undefined && target !== undefined) {
|
|
235
|
+
edges.push(Object.freeze({ edge, source, target }));
|
|
653
236
|
}
|
|
654
237
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
238
|
+
return Object.freeze({
|
|
239
|
+
kind: 'edges',
|
|
240
|
+
edges: Object.freeze(edges),
|
|
241
|
+
});
|
|
659
242
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
243
|
+
const nodes = references.nodes
|
|
244
|
+
.map((id) => this.overlay.node(id, this.entities))
|
|
245
|
+
.filter((node) => node !== undefined);
|
|
246
|
+
const visibleNodeIds = new Set(nodes.map(({ id }) => id));
|
|
247
|
+
const edges = references.edges
|
|
248
|
+
.map((key) => this.entities.edge(key))
|
|
249
|
+
.filter((edge) => edge !== undefined && visibleNodeIds.has(edge.source) && visibleNodeIds.has(edge.target));
|
|
250
|
+
const graph = Object.freeze({ nodes: Object.freeze(nodes), edges: Object.freeze(edges) });
|
|
251
|
+
const selection = materializeSelection(template.selection, visibleNodeIds, edges);
|
|
252
|
+
return selection.kind === 'node'
|
|
253
|
+
? Object.freeze({ kind: 'graph', graph, selection })
|
|
254
|
+
: Object.freeze({ kind: 'graph', graph, selection });
|
|
255
|
+
}
|
|
256
|
+
publish(shape, state, error) {
|
|
257
|
+
const next = snapshotFor(state, shape.response, error);
|
|
258
|
+
if (sameSnapshot(shape.snapshot, next))
|
|
669
259
|
return;
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
detail: `listeners ${entry.listeners.size} != observers ${entry.observers}`,
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
if (entry.inflight !== null)
|
|
679
|
-
continue; // only settled shapes are checked
|
|
680
|
-
for (const id of entry.nodeMembers) {
|
|
681
|
-
if (String(id).startsWith('optimistic:')) {
|
|
682
|
-
this.emit({
|
|
683
|
-
kind: 'invariant',
|
|
684
|
-
shape: entry.key,
|
|
685
|
-
detail: `optimistic id ${id} in membership`,
|
|
686
|
-
});
|
|
687
|
-
}
|
|
260
|
+
shape.state = state;
|
|
261
|
+
shape.snapshot = next;
|
|
262
|
+
for (const listener of Array.from(shape.listeners)) {
|
|
263
|
+
try {
|
|
264
|
+
listener();
|
|
688
265
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
if (state.entities.node(id) === undefined && !state.entities.isNodeTombstoned(id)) {
|
|
692
|
-
this.emit({
|
|
693
|
-
kind: 'invariant',
|
|
694
|
-
shape: entry.key,
|
|
695
|
-
detail: `dangling membership id ${id}`,
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
this.report(error);
|
|
699
268
|
}
|
|
700
269
|
}
|
|
701
270
|
}
|
|
702
|
-
|
|
703
|
-
|
|
271
|
+
schedule(task) {
|
|
272
|
+
return new Promise((resolve, reject) => {
|
|
273
|
+
const run = () => {
|
|
274
|
+
this.active += 1;
|
|
275
|
+
void task()
|
|
276
|
+
.then(resolve, reject)
|
|
277
|
+
.finally(() => {
|
|
278
|
+
this.active -= 1;
|
|
279
|
+
this.drain();
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
this.pending.push({ run, reject });
|
|
283
|
+
this.drain();
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
drain() {
|
|
287
|
+
while (this.active < this.options.concurrency && this.pending.length > 0) {
|
|
288
|
+
this.pending.shift().run();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
report(error) {
|
|
292
|
+
try {
|
|
293
|
+
this.options.onError?.(error);
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
// Error observers cannot replace the operation's public outcome.
|
|
297
|
+
}
|
|
704
298
|
}
|
|
705
299
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
node: null,
|
|
719
|
-
children: [],
|
|
720
|
-
gathered: () => ({ nodes: [], first: null }),
|
|
721
|
-
pending: false,
|
|
722
|
-
stale: false,
|
|
723
|
-
error: undefined,
|
|
724
|
-
live: false,
|
|
725
|
-
seq: 0,
|
|
726
|
-
more: Object.freeze({ has: false, pending: false, load: async () => { } }),
|
|
727
|
-
refetch: async () => { },
|
|
728
|
-
});
|
|
729
|
-
// ── ref helpers ────────────────────────────────────────────────────────────────
|
|
730
|
-
function firstKey(entries) {
|
|
731
|
-
for (const e of entries)
|
|
732
|
-
return e.key;
|
|
733
|
-
return '';
|
|
734
|
-
}
|
|
735
|
-
function isNodeValue(x) {
|
|
736
|
-
return typeof x === 'object' && x !== null && 'id' in x && 'class' in x && 'path' in x;
|
|
737
|
-
}
|
|
738
|
-
function refPathRaw(x) {
|
|
739
|
-
return isNodeValue(x) ? rawOf(x.path) : rawOf(x);
|
|
740
|
-
}
|
|
741
|
-
function rawIdentity(edge) {
|
|
742
|
-
return {
|
|
743
|
-
class: rawOf(edge.class),
|
|
744
|
-
source: rawOf(edge.source),
|
|
745
|
-
...(edge.slug !== undefined ? { slug: edge.slug } : {}),
|
|
746
|
-
target: rawOf(edge.target),
|
|
747
|
-
};
|
|
300
|
+
function materializeSelection(selection, visibleNodes, visibleEdges) {
|
|
301
|
+
if (selection.kind === 'node') {
|
|
302
|
+
return Object.freeze({
|
|
303
|
+
kind: selection.kind,
|
|
304
|
+
ids: Object.freeze(selection.ids.filter((id) => visibleNodes.has(id))),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const edges = new Set(visibleEdges.map(encodeEdgeKey));
|
|
308
|
+
return Object.freeze({
|
|
309
|
+
kind: selection.kind,
|
|
310
|
+
keys: Object.freeze(selection.keys.filter((key) => edges.has(encodeEdgeKey(key)))),
|
|
311
|
+
});
|
|
748
312
|
}
|
|
749
|
-
function
|
|
750
|
-
return (
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
patch.edges.update.length > 0 ||
|
|
755
|
-
patch.edges.delete.length > 0);
|
|
313
|
+
function queryOptions(page, lifecycle) {
|
|
314
|
+
return Object.freeze({
|
|
315
|
+
signal: lifecycle,
|
|
316
|
+
page,
|
|
317
|
+
});
|
|
756
318
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
319
|
+
function observeRead(pending, options, lifecycle) {
|
|
320
|
+
try {
|
|
321
|
+
requireReadLive(options.signal, lifecycle);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
return Promise.reject(error);
|
|
325
|
+
}
|
|
326
|
+
return new Promise((resolve, reject) => {
|
|
327
|
+
let timeout;
|
|
328
|
+
const callerCancelled = () => settleReject(cancellation(options.signal.reason));
|
|
329
|
+
const storeClosed = () => settleReject(cancellation(lifecycle.reason));
|
|
330
|
+
let settled = false;
|
|
331
|
+
const cleanup = () => {
|
|
332
|
+
if (timeout !== undefined)
|
|
333
|
+
clearTimeout(timeout);
|
|
334
|
+
options.signal?.removeEventListener('abort', callerCancelled);
|
|
335
|
+
lifecycle.removeEventListener('abort', storeClosed);
|
|
336
|
+
};
|
|
337
|
+
const settleResolve = (result) => {
|
|
338
|
+
if (settled)
|
|
339
|
+
return;
|
|
340
|
+
settled = true;
|
|
341
|
+
cleanup();
|
|
342
|
+
resolve(result);
|
|
343
|
+
};
|
|
344
|
+
function settleReject(error) {
|
|
345
|
+
if (settled)
|
|
346
|
+
return;
|
|
347
|
+
settled = true;
|
|
348
|
+
cleanup();
|
|
349
|
+
reject(error);
|
|
350
|
+
}
|
|
351
|
+
options.signal?.addEventListener('abort', callerCancelled, { once: true });
|
|
352
|
+
lifecycle.addEventListener('abort', storeClosed, { once: true });
|
|
353
|
+
if (options.timeoutMs !== undefined) {
|
|
354
|
+
timeout = setTimeout(() => settleReject(new ClientError('Store read timed out.')), options.timeoutMs);
|
|
355
|
+
}
|
|
356
|
+
void pending.then(settleResolve, settleReject);
|
|
773
357
|
});
|
|
774
|
-
return { ...base, steps };
|
|
775
358
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
359
|
+
function requireReadLive(signal, lifecycle) {
|
|
360
|
+
if (lifecycle.aborted)
|
|
361
|
+
throw cancellation(lifecycle.reason);
|
|
362
|
+
if (signal?.aborted === true)
|
|
363
|
+
throw cancellation(signal.reason);
|
|
780
364
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
365
|
+
function cancellation(reason) {
|
|
366
|
+
return reason instanceof Error
|
|
367
|
+
? reason
|
|
368
|
+
: new ClientError('Store read was cancelled.', { cause: reason });
|
|
784
369
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
unresolved = true; // 0 matches OR >1 (ambiguous) → reconcile, don't guess
|
|
370
|
+
function snapshotFor(state, response, error) {
|
|
371
|
+
switch (state) {
|
|
372
|
+
case 'cold':
|
|
373
|
+
return Object.freeze({ state });
|
|
374
|
+
case 'loading':
|
|
375
|
+
return Object.freeze({ state });
|
|
376
|
+
case 'failed':
|
|
377
|
+
return Object.freeze({ state, error, ...(response === undefined ? {} : { response }) });
|
|
378
|
+
case 'ready':
|
|
379
|
+
case 'stale':
|
|
380
|
+
case 'refreshing':
|
|
381
|
+
case 'optimistic':
|
|
382
|
+
if (response === undefined)
|
|
383
|
+
throw new TypeError(`Store ${state} snapshot requires a response.`);
|
|
384
|
+
return Object.freeze({ state, response });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function sameSnapshot(left, right) {
|
|
388
|
+
if (left.state !== right.state)
|
|
389
|
+
return false;
|
|
390
|
+
if ('response' in left || 'response' in right) {
|
|
391
|
+
if (!('response' in left) || !('response' in right) || left.response !== right.response) {
|
|
392
|
+
return false;
|
|
809
393
|
}
|
|
810
394
|
}
|
|
811
|
-
return
|
|
395
|
+
return left.state !== 'failed' || right.state !== 'failed' || left.error === right.error;
|
|
812
396
|
}
|
|
813
|
-
//# sourceMappingURL=memory.js.map
|