@yaks/effects 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +979 -2
  3. package/_dist/docs.d.ts +10 -0
  4. package/_dist/docs.d.ts.map +1 -0
  5. package/_dist/enqueue.d.ts +12 -0
  6. package/_dist/enqueue.d.ts.map +1 -0
  7. package/_dist/expire.d.ts +31 -0
  8. package/_dist/expire.d.ts.map +1 -0
  9. package/_dist/invocation.d.ts +36 -0
  10. package/_dist/invocation.d.ts.map +1 -0
  11. package/_dist/lease.d.ts +98 -0
  12. package/_dist/lease.d.ts.map +1 -0
  13. package/_dist/mod.d.ts +89 -0
  14. package/_dist/mod.d.ts.map +1 -0
  15. package/_dist/outage.d.ts +48 -0
  16. package/_dist/outage.d.ts.map +1 -0
  17. package/_dist/pool.d.ts +148 -0
  18. package/_dist/pool.d.ts.map +1 -0
  19. package/_dist/provisional.d.ts +8 -0
  20. package/_dist/provisional.d.ts.map +1 -0
  21. package/_dist/ready.d.ts +3 -0
  22. package/_dist/ready.d.ts.map +1 -0
  23. package/_dist/registration.d.ts +17 -0
  24. package/_dist/registration.d.ts.map +1 -0
  25. package/_dist/registry.d.ts +153 -0
  26. package/_dist/registry.d.ts.map +1 -0
  27. package/_dist/tools.d.ts +21 -0
  28. package/_dist/tools.d.ts.map +1 -0
  29. package/_dist/trace.d.ts +63 -0
  30. package/_dist/trace.d.ts.map +1 -0
  31. package/_dist/views.d.ts +15 -0
  32. package/_dist/views.d.ts.map +1 -0
  33. package/_dist/vocab.d.ts +11 -0
  34. package/_dist/vocab.d.ts.map +1 -0
  35. package/_dist/worker.d.ts +19 -0
  36. package/_dist/worker.d.ts.map +1 -0
  37. package/_dist/write.d.ts +25 -0
  38. package/_dist/write.d.ts.map +1 -0
  39. package/cleanup.js +75 -0
  40. package/cleanup.js.map +1 -0
  41. package/cleanup.ts +83 -0
  42. package/deno.json +1 -0
  43. package/docs.js +13 -0
  44. package/docs.js.map +1 -0
  45. package/docs.ts +13 -0
  46. package/enqueue.js +71 -0
  47. package/enqueue.js.map +1 -0
  48. package/enqueue.ts +86 -0
  49. package/expire.js +225 -0
  50. package/expire.js.map +1 -0
  51. package/expire.ts +244 -0
  52. package/invocation.js +245 -0
  53. package/invocation.js.map +1 -0
  54. package/invocation.ts +250 -0
  55. package/lease.js +343 -0
  56. package/lease.js.map +1 -0
  57. package/lease.ts +444 -0
  58. package/mod.js +89 -0
  59. package/mod.js.map +1 -0
  60. package/mod.ts +92 -0
  61. package/outage.js +77 -0
  62. package/outage.js.map +1 -0
  63. package/outage.ts +84 -0
  64. package/package.json +52 -4
  65. package/page.js +315 -0
  66. package/page.js.map +1 -0
  67. package/page.ts +524 -0
  68. package/pool.js +1474 -0
  69. package/pool.js.map +1 -0
  70. package/pool.ts +1635 -0
  71. package/provisional.js +20 -0
  72. package/provisional.js.map +1 -0
  73. package/provisional.ts +26 -0
  74. package/ready.js +48 -0
  75. package/ready.js.map +1 -0
  76. package/ready.ts +93 -0
  77. package/registration.js +21 -0
  78. package/registration.js.map +1 -0
  79. package/registration.ts +43 -0
  80. package/registry.js +872 -0
  81. package/registry.js.map +1 -0
  82. package/registry.ts +1196 -0
  83. package/tools.js +182 -0
  84. package/tools.js.map +1 -0
  85. package/tools.ts +229 -0
  86. package/trace.js +167 -0
  87. package/trace.js.map +1 -0
  88. package/trace.ts +217 -0
  89. package/views.js +18 -0
  90. package/views.js.map +1 -0
  91. package/views.ts +18 -0
  92. package/vocab.js +18 -0
  93. package/vocab.js.map +1 -0
  94. package/vocab.json +364 -0
  95. package/vocab.ts +20 -0
  96. package/worker.js +114 -0
  97. package/worker.js.map +1 -0
  98. package/worker.ts +146 -0
  99. package/write.js +38 -0
  100. package/write.js.map +1 -0
  101. package/write.ts +60 -0
package/provisional.js ADDED
@@ -0,0 +1,20 @@
1
+ // The mark an entity wears while an asynchronous step about it has not
2
+ // finished: a value being sealed into a vault after its write committed, say.
3
+ // The entity sits where it always does, whole, and wears `provisional` beside
4
+ // its other components; the effect that finishes the step removes the mark.
5
+ //
6
+ // It is generic on purpose. What the step is, and what happens when it fails,
7
+ // are the registering package's to say; this names the mark once, so every
8
+ // reader can show "not settled yet" the same way, with the `note` line the
9
+ // step left for the person looking.
10
+ import { pick } from "@yaks/vocab/runtime";
11
+ import { effectDoc } from "./docs.js";
12
+ /** The mark's component, by the name ./vocab.json declares it. */ export let PROVISIONAL = 'provisional';
13
+ /**
14
+ * The mark on its own, for a vocabulary that wants it without the pool's
15
+ * rows: `loadVocab([provisionalDoc, ...mine])`. {@link effectDoc} carries it
16
+ * too, so a host loads one or the other, never both.
17
+ */ export let provisionalDoc = pick(effectDoc, [
18
+ PROVISIONAL
19
+ ], PROVISIONAL);
20
+ //# sourceMappingURL=provisional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provisional.js","sources":["./provisional.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,oCAAoC;AAEpC,SAAS,IAAI,mCAAuD;AACpE,SAAS,SAAS,oBAAmB;AAErC,gEAAgE,GAChE,OAAO,IAAI,cAAc,cAAa;AAEtC;;;;CAIC,GACD,OAAO,IAAI,iBAA2B,KACpC,WACA;EAAC;CAAY,EACb,aACD"}
package/provisional.ts ADDED
@@ -0,0 +1,26 @@
1
+ // The mark an entity wears while an asynchronous step about it has not
2
+ // finished: a value being sealed into a vault after its write committed, say.
3
+ // The entity sits where it always does, whole, and wears `provisional` beside
4
+ // its other components; the effect that finishes the step removes the mark.
5
+ //
6
+ // It is generic on purpose. What the step is, and what happens when it fails,
7
+ // are the registering package's to say; this names the mark once, so every
8
+ // reader can show "not settled yet" the same way, with the `note` line the
9
+ // step left for the person looking.
10
+
11
+ import { pick, type VocabDoc } from '@yaks/vocab/runtime'
12
+ import { effectDoc } from './docs.js'
13
+
14
+ /** The mark's component, by the name ./vocab.json declares it. */
15
+ export let PROVISIONAL = 'provisional'
16
+
17
+ /**
18
+ * The mark on its own, for a vocabulary that wants it without the pool's
19
+ * rows: `loadVocab([provisionalDoc, ...mine])`. {@link effectDoc} carries it
20
+ * too, so a host loads one or the other, never both.
21
+ */
22
+ export let provisionalDoc: VocabDoc = pick(
23
+ effectDoc,
24
+ [PROVISIONAL],
25
+ PROVISIONAL,
26
+ )
package/ready.js ADDED
@@ -0,0 +1,48 @@
1
+ // Work discovery asks for eligibility before taking a bounded page. Relative
2
+ // time stays in the query; each pass supplies its clock at the read boundary.
3
+ import { absent, and, eq, le, limit, list, ne, or, order, time } from "@yaks/query";
4
+ /** The first outstanding run in request order, even if held or deferred. */ export let firstPending = async (g, handler)=>(await g.read(and(eq('effect.handler', handler), eq('effect.state', 'pending'), order('effect.at'), limit(1)), {
5
+ unordered: true
6
+ }))[0];
7
+ let due = or(absent('effect.next'), le('effect.next', time('now')));
8
+ let free = or(absent('effect.lease_owner'), absent('effect.lease_expiry'), le('effect.lease_expiry', time('now')));
9
+ export let available = (handlers, waiting)=>{
10
+ let named = eq('effect.handler', list(...handlers));
11
+ if (!waiting?.size) return named;
12
+ let unblocked = handlers.flatMap((name)=>{
13
+ let reason = waiting.get(name);
14
+ return reason ? [
15
+ or(ne('effect.handler', name), ne('effect.waiting', reason))
16
+ ] : [];
17
+ });
18
+ return unblocked.length ? and(named, ...unblocked) : named;
19
+ };
20
+ export let ready = (handlers, opts = {})=>{
21
+ let enabled = handlers.filter((name)=>!opts.disabled?.includes(name));
22
+ let disabled = handlers.filter((name)=>opts.disabled?.includes(name));
23
+ let claims = opts.singleOwner ? [] : [
24
+ free
25
+ ];
26
+ // A replacement owes its own startup. A peer taking that row would run its
27
+ // own closure instead, then lose the duty when the peer shuts down. Not
28
+ // equals holds where there is no kind, so absence needs no arm of its own;
29
+ // each arm of this disjunction is another seek per pass.
30
+ let owner = opts.singleOwner || !opts.owner ? [] : [
31
+ or(ne('effect.kind', 'started'), eq('effect.target', opts.owner))
32
+ ];
33
+ let active = enabled.length ? [
34
+ and(available(enabled, opts.waiting), due, ...claims, ...owner)
35
+ ] : [];
36
+ let obsolete = disabled.length ? [
37
+ and(eq('effect.handler', list(...disabled)), absent('effect.lease_owner'))
38
+ ] : [];
39
+ let branches = [
40
+ ...active,
41
+ ...obsolete
42
+ ];
43
+ return and(eq('effect.state', 'pending'), ...branches.length == 1 ? branches[0].clauses : [
44
+ or(...branches)
45
+ ]);
46
+ };
47
+ export let except = (q, ids)=>ids.length ? and(...q.clauses, ne('entity.eid', list(...ids))) : q;
48
+ //# sourceMappingURL=ready.js.map
package/ready.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ready.js","sources":["./ready.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAE9E,SACE,MAAM,EAEN,GAAG,EACH,EAAE,EACF,EAAE,EACF,KAAK,EACL,IAAI,EACJ,EAAE,EACF,EAAE,EACF,KAAK,EACL,IAAI,2BACyB;AAE/B,0EAA0E,GAC1E,OAAO,IAAI,eAAe,OACxB,GACA,UAEA,CAAC,MAAM,EAAE,IAAI,CACX,IACE,GAAG,kBAAkB,UACrB,GAAG,gBAAgB,YACnB,MAAM,cACN,MAAM,KAER;IAAE,WAAW;EAAK,EACnB,CAAC,CAAC,EAAE,CAAA;AAEP,IAAI,MAAM,GAAG,OAAO,gBAAgB,GAAG,eAAe,KAAK;AAC3D,IAAI,OAAO,GACT,OAAO,uBACP,OAAO,wBACP,GAAG,uBAAuB,KAAK;AAKjC,OAAO,IAAI,YAAY,CAAC,UAAoB;EAC1C,IAAI,QAAQ,GAAG,kBAAkB,QAAQ;EACzC,IAAI,CAAC,SAAS,MAAM,OAAO;EAC3B,IAAI,YAAY,SAAS,OAAO,CAAC,CAAC;IAChC,IAAI,SAAS,QAAQ,GAAG,CAAC;IACzB,OAAO,SACH;MAAC,GAAG,GAAG,kBAAkB,OAAO,GAAG,kBAAkB;KAAS,GAC9D,EAAE;EACR;EACA,OAAO,UAAU,MAAM,GAAG,IAAI,UAAU,aAAa;AACvD,EAAC;AAED,OAAO,IAAI,QAAQ,CACjB,UACA,OAKI,CAAC,CAAC;EAEN,IAAI,UAAU,SAAS,MAAM,CAAC,CAAC,OAAS,CAAC,KAAK,QAAQ,EAAE,SAAS;EACjE,IAAI,WAAW,SAAS,MAAM,CAAC,CAAC,OAAS,KAAK,QAAQ,EAAE,SAAS;EACjE,IAAI,SAAS,KAAK,WAAW,GAAG,EAAE,GAAG;IAAC;GAAK;EAC3C,2EAA2E;EAC3E,wEAAwE;EACxE,2EAA2E;EAC3E,yDAAyD;EACzD,IAAI,QAAQ,KAAK,WAAW,IAAI,CAAC,KAAK,KAAK,GAAG,EAAE,GAAG;IAAC,GAClD,GAAG,eAAe,YAClB,GAAG,iBAAiB,KAAK,KAAK;GAC9B;EACF,IAAI,SAAS,QAAQ,MAAM,GACvB;IAAC,IAAI,UAAU,SAAS,KAAK,OAAO,GAAG,QAAQ,WAAW;GAAO,GACjE,EAAE;EACN,IAAI,WAAW,SAAS,MAAM,GAC1B;IACA,IACE,GAAG,kBAAkB,QAAQ,YAC7B,OAAO;GAEV,GACC,EAAE;EACN,IAAI,WAAW;OAAI;OAAW;GAAS;EACvC,OAAO,IACL,GAAG,gBAAgB,eAChB,SAAS,MAAM,IAAI,IAAI,QAAQ,CAAC,EAAE,CAAC,OAAO,GAAG;IAAC,MAAM;GAAU;AAErE,EAAC;AAED,OAAO,IAAI,SAAS,CAAC,GAAQ,MAC3B,IAAI,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,QAAQ,SAAS,EAAC"}
package/ready.ts ADDED
@@ -0,0 +1,93 @@
1
+ // Work discovery asks for eligibility before taking a bounded page. Relative
2
+ // time stays in the query; each pass supplies its clock at the read boundary.
3
+ import type { Access, Bundle } from 'jsr:@yaks/graph@0.2.36'
4
+ import {
5
+ absent,
6
+ type And,
7
+ and,
8
+ eq,
9
+ le,
10
+ limit,
11
+ list,
12
+ ne,
13
+ or,
14
+ order,
15
+ time,
16
+ } from '@yaks/query'
17
+
18
+ /** The first outstanding run in request order, even if held or deferred. */
19
+ export let firstPending = async (
20
+ g: Pick<Access, 'read'>,
21
+ handler: string,
22
+ ): Promise<Bundle | undefined> =>
23
+ (await g.read(
24
+ and(
25
+ eq('effect.handler', handler),
26
+ eq('effect.state', 'pending'),
27
+ order('effect.at'),
28
+ limit(1),
29
+ ),
30
+ { unordered: true },
31
+ ))[0]
32
+
33
+ let due = or(absent('effect.next'), le('effect.next', time('now')))
34
+ let free = or(
35
+ absent('effect.lease_owner'),
36
+ absent('effect.lease_expiry'),
37
+ le('effect.lease_expiry', time('now')),
38
+ )
39
+
40
+ export type Waiting = ReadonlyMap<string, string>
41
+
42
+ export let available = (handlers: string[], waiting?: Waiting) => {
43
+ let named = eq('effect.handler', list(...handlers))
44
+ if (!waiting?.size) return named
45
+ let unblocked = handlers.flatMap((name) => {
46
+ let reason = waiting.get(name)
47
+ return reason
48
+ ? [or(ne('effect.handler', name), ne('effect.waiting', reason))]
49
+ : []
50
+ })
51
+ return unblocked.length ? and(named, ...unblocked) : named
52
+ }
53
+
54
+ export let ready = (
55
+ handlers: string[],
56
+ opts: {
57
+ singleOwner?: boolean
58
+ disabled?: string[]
59
+ owner?: string
60
+ waiting?: Waiting
61
+ } = {},
62
+ ): And => {
63
+ let enabled = handlers.filter((name) => !opts.disabled?.includes(name))
64
+ let disabled = handlers.filter((name) => opts.disabled?.includes(name))
65
+ let claims = opts.singleOwner ? [] : [free]
66
+ // A replacement owes its own startup. A peer taking that row would run its
67
+ // own closure instead, then lose the duty when the peer shuts down. Not
68
+ // equals holds where there is no kind, so absence needs no arm of its own;
69
+ // each arm of this disjunction is another seek per pass.
70
+ let owner = opts.singleOwner || !opts.owner ? [] : [or(
71
+ ne('effect.kind', 'started'),
72
+ eq('effect.target', opts.owner),
73
+ )]
74
+ let active = enabled.length
75
+ ? [and(available(enabled, opts.waiting), due, ...claims, ...owner)]
76
+ : []
77
+ let obsolete = disabled.length
78
+ ? [
79
+ and(
80
+ eq('effect.handler', list(...disabled)),
81
+ absent('effect.lease_owner'),
82
+ ),
83
+ ]
84
+ : []
85
+ let branches = [...active, ...obsolete]
86
+ return and(
87
+ eq('effect.state', 'pending'),
88
+ ...branches.length == 1 ? branches[0].clauses : [or(...branches)],
89
+ )
90
+ }
91
+
92
+ export let except = (q: And, ids: string[]) =>
93
+ ids.length ? and(...q.clauses, ne('entity.eid', list(...ids))) : q
@@ -0,0 +1,21 @@
1
+ /** Read grouped hooks back from the slots, not from a second list. */ export let describe = (slots)=>{
2
+ let groups = new Map();
3
+ for (let s of slots){
4
+ let key = s.group ?? s.id;
5
+ let d = groups.get(key);
6
+ if (!d) {
7
+ d = {
8
+ comp: s.comp,
9
+ hooks: [],
10
+ doc: s.doc
11
+ };
12
+ groups.set(key, d);
13
+ }
14
+ let props = s.props?.length ? `(${s.props.join(', ')})` : '';
15
+ d.hooks.push(`${s.kind}${props}`);
16
+ }
17
+ return [
18
+ ...groups.values()
19
+ ];
20
+ };
21
+ //# sourceMappingURL=registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.js","sources":["./registration.ts"],"names":[],"mappings":"AA4BA,oEAAoE,GACpE,OAAO,IAAI,WAAW,CAAC;EACrB,IAAI,SAAS,IAAI;EACjB,KAAK,IAAI,KAAK,MAAO;IACnB,IAAI,MAAM,EAAE,KAAK,IAAI,EAAE,EAAE;IACzB,IAAI,IAAI,OAAO,GAAG,CAAC;IACnB,IAAI,CAAC,GAAG;MACN,IAAI;QAAE,MAAM,EAAE,IAAI;QAAE,OAAO,EAAE;QAAE,KAAK,EAAE,GAAG;MAAC;MAC1C,OAAO,GAAG,CAAC,KAAK;IAClB;IACA,IAAI,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG;IAC1D,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO;EAClC;EACA,OAAO;OAAI,OAAO,MAAM;GAAG;AAC7B,EAAC"}
@@ -0,0 +1,43 @@
1
+ import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
2
+ import type { Handler, Slot } from './registry.ts'
3
+
4
+ /** What an observer says about itself. */
5
+ export type Policy = {
6
+ /** What it does, available from registry introspection. */
7
+ doc?: string
8
+ /** Additional reads to gather for it before the batch commits. */
9
+ wants?: Plugin['wants']
10
+ }
11
+
12
+ /** A component's related observers, registered and documented together. */
13
+ export type Registration = Policy & {
14
+ /** The component appeared. */
15
+ created?: Handler
16
+ /** A patch carried one of these properties. */
17
+ changed?: Record<string, Handler>
18
+ /** The component went away. */
19
+ removed?: Handler
20
+ }
21
+
22
+ /** One entry in the registry's documentation, derived from its slots. */
23
+ export type Description = {
24
+ comp: string
25
+ hooks: string[]
26
+ doc?: string
27
+ }
28
+
29
+ /** Read grouped hooks back from the slots, not from a second list. */
30
+ export let describe = (slots: Slot[]): Description[] => {
31
+ let groups = new Map<string, Description>()
32
+ for (let s of slots) {
33
+ let key = s.group ?? s.id
34
+ let d = groups.get(key)
35
+ if (!d) {
36
+ d = { comp: s.comp, hooks: [], doc: s.doc }
37
+ groups.set(key, d)
38
+ }
39
+ let props = s.props?.length ? `(${s.props.join(', ')})` : ''
40
+ d.hooks.push(`${s.kind}${props}`)
41
+ }
42
+ return [...groups.values()]
43
+ }