@things-factory/guild-overlay 10.1.314 → 10.1.316

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.
@@ -0,0 +1,38 @@
1
+ import './components/guild-coin-layer.js';
2
+ import './components/guild-overlay-setting-let.js';
3
+ import { html } from 'lit';
4
+ import { store } from '@operato/shell';
5
+ import { ADD_SETTING } from '@things-factory/setting-base/dist-client/index.js';
6
+ import { overlayState } from './overlay-state.js';
7
+ /*
8
+ * **One line in a product's client boot** (operato-guild design §14-1) - `await setupGuildOverlay()` once the person is
9
+ * known. It reads `Guild::enabled` through the person's own overlay read; off, or no guild right, nothing is attached and
10
+ * the product's screens are as they were. On: a layer that shows nothing until one's own work earns, and the setting.
11
+ */
12
+ let attached = false;
13
+ const MISSED_AFTER_MS = 1500;
14
+ export async function setupGuildOverlay() {
15
+ await overlayState.loadChoices();
16
+ /* A device that never saw a coin starts from now - nothing old comes in a pile. */
17
+ const since = await overlayState.seenAt();
18
+ const overlay = await overlayState.load(since);
19
+ if (!overlay.enabled)
20
+ return false;
21
+ if (attached)
22
+ return true;
23
+ attached = true;
24
+ store.dispatch({
25
+ type: ADD_SETTING,
26
+ setting: { seq: 40, template: html `<guild-overlay-setting-let></guild-overlay-setting-let>` }
27
+ });
28
+ document.body.appendChild(document.createElement('guild-coin-layer'));
29
+ await overlayState.listen();
30
+ /* What was confirmed while away - one gathered note, a moment after the screen settles (ADR-0238 decision 15). */
31
+ const missed = since ? overlay.missed : undefined;
32
+ if (missed?.count) {
33
+ setTimeout(() => overlayState.dispatchEvent(new CustomEvent('pulse', { detail: { kind: 'verified', contributionKind: missed.kind, label: missed.label, count: missed.count, at: new Date().toISOString() } })), MISSED_AFTER_MS);
34
+ }
35
+ overlayState.seen();
36
+ return true;
37
+ }
38
+ //# sourceMappingURL=setup-guild-overlay.js.map
@@ -0,0 +1,7 @@
1
+ import { type EntityManager, type EntitySubscriberInterface, type TransactionCommitEvent, type TransactionRollbackEvent } from 'typeorm';
2
+ /** Run `job` when `tx` commits - at once when it is not in a transaction. */
3
+ export declare function afterCommitOf(tx: EntityManager | undefined, job: () => unknown): void;
4
+ export declare class GuildCommitSubscriber implements EntitySubscriberInterface {
5
+ afterTransactionCommit(event: TransactionCommitEvent): void;
6
+ afterTransactionRollback(event: TransactionRollbackEvent): void;
7
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildCommitSubscriber = void 0;
4
+ exports.afterCommitOf = afterCommitOf;
5
+ const tslib_1 = require("tslib");
6
+ const typeorm_1 = require("typeorm");
7
+ const env_1 = require("@things-factory/env");
8
+ /*
9
+ * **After the work commits** (design §3-2) - a coin a person sees must not stand for a save that rolled back. What is
10
+ * queued here runs once the transaction it was queued in commits at its top level, and is dropped if it rolls back.
11
+ * Outside a transaction it runs at once. Kept per transaction runner, as the captured facts are (`capture.ts`).
12
+ */
13
+ const QUEUED = new WeakMap();
14
+ const depthOf = (runner) => runner.transactionDepth ?? 0;
15
+ function run(job) {
16
+ Promise.resolve()
17
+ .then(job)
18
+ .catch(error => env_1.logger.warn(`[guild-overlay] after-commit work failed: ${error?.message ?? error}`));
19
+ }
20
+ /** Run `job` when `tx` commits - at once when it is not in a transaction. */
21
+ function afterCommitOf(tx, job) {
22
+ const runner = tx?.queryRunner;
23
+ if (!runner?.isTransactionActive)
24
+ return run(job);
25
+ const list = QUEUED.get(runner) ?? [];
26
+ list.push(job);
27
+ QUEUED.set(runner, list);
28
+ }
29
+ let GuildCommitSubscriber = class GuildCommitSubscriber {
30
+ afterTransactionCommit(event) {
31
+ if (depthOf(event.queryRunner) > 0)
32
+ return;
33
+ const jobs = QUEUED.get(event.queryRunner) ?? [];
34
+ QUEUED.delete(event.queryRunner);
35
+ for (const job of jobs)
36
+ run(job);
37
+ }
38
+ afterTransactionRollback(event) {
39
+ if (depthOf(event.queryRunner) > 0)
40
+ return;
41
+ QUEUED.delete(event.queryRunner);
42
+ }
43
+ };
44
+ exports.GuildCommitSubscriber = GuildCommitSubscriber;
45
+ exports.GuildCommitSubscriber = GuildCommitSubscriber = tslib_1.__decorate([
46
+ (0, typeorm_1.EventSubscriber)()
47
+ ], GuildCommitSubscriber);
48
+ //# sourceMappingURL=committed.js.map
@@ -1,10 +1,62 @@
1
1
  import type { EntityManager } from 'typeorm';
2
- import { type ContributionRecord } from './contract.js';
2
+ import { type ContributionPerson, type ContributionRecord } from './contract.js';
3
3
  export interface LocalGuildHub {
4
4
  /** Take these records for the application in this transaction - what the intake door does with a remote batch. */
5
5
  accept(tx: EntityManager, domain: {
6
6
  id: string;
7
7
  }, application: string, records: ContributionRecord[]): Promise<unknown>;
8
+ /** What a save would earn once confirmed, by the rule in force and the person's counts today (design §3-2). */
9
+ prospect?(domain: {
10
+ id: string;
11
+ }, application: string, input: GuildProspectInput): Promise<GuildProspectReply | undefined>;
12
+ /** One person's wallet, level, badges and the GP each kind is worth (design §14-1). */
13
+ overlayOf?(domain: {
14
+ id: string;
15
+ }, user: {
16
+ id: string;
17
+ }, since?: Date): Promise<GuildOverlayDigest>;
18
+ }
19
+ export interface GuildProspectInput {
20
+ kind: string;
21
+ contributor: ContributionPerson;
22
+ eventAt?: string;
23
+ signals?: Record<string, number>;
24
+ }
25
+ /** A range of GP, or why it would earn nothing (`cap`, `no-rule`, `once` …). */
26
+ export type GuildProspectReply = {
27
+ gpLow: number;
28
+ gpHigh: number;
29
+ } | {
30
+ skipped: string;
31
+ };
32
+ export interface GuildWalletDigest {
33
+ balance: number;
34
+ spendable: number;
35
+ pendingGp: number;
36
+ maturedGp: number;
37
+ everGp: number;
38
+ level: number;
39
+ levelFloor: number;
40
+ nextLevelAt?: number;
41
+ }
42
+ export interface GuildBadgeDigest {
43
+ kind: string;
44
+ count: number;
45
+ step: number;
46
+ nextStep?: number;
47
+ }
48
+ export interface GuildOverlayDigest {
49
+ /** false - the host says this person does not earn (office: not an employee at work today); the overlay stays away. */
50
+ eligible?: boolean;
51
+ /** What was confirmed since the person last saw a coin on this device - shown once, gathered (design §14-1). */
52
+ missed?: {
53
+ count: number;
54
+ kind: string;
55
+ };
56
+ wallet?: GuildWalletDigest;
57
+ badges: GuildBadgeDigest[];
58
+ /** The contributor's GP for one of each kind by the rule in force - what a quest says one is worth. */
59
+ baseGp: Record<string, number>;
8
60
  }
9
61
  export declare function registerLocalGuildHub(hub: LocalGuildHub): void;
10
62
  /** For tests. */
@@ -18,7 +70,7 @@ export type HubRoad = {
18
70
  kind: 'remote';
19
71
  peer: string;
20
72
  };
21
- export declare function hubRoadOf(tx: EntityManager, domain: {
73
+ export declare function hubRoadOf(tx: EntityManager | undefined, domain: {
22
74
  id: string;
23
75
  }): Promise<HubRoad>;
24
76
  /** Hand records over on the road the domain's settings name. */
@@ -27,15 +27,12 @@ async function hubRoadOf(tx, domain) {
27
27
  const place = await (0, settings_js_1.guildPlaceOf)(domain, tx);
28
28
  if (!place.enabled)
29
29
  return { kind: 'off' };
30
- if (place.hub && localHub) {
31
- if (place.hubPeer)
32
- warnOnce(`both:${domain.id}`, `domain ${domain.id}: Guild::hub and Guild::hubPeer are both set - the hub on this server is used`);
33
- return { kind: 'local', hub: localHub };
34
- }
35
- if (place.hub && !localHub)
36
- warnOnce(`nohub:${domain.id}`, `domain ${domain.id}: Guild::hub is on but this server carries no guild hub module`);
30
+ /* Another server named - the rewards are kept there. None - kept here, where the hub module is loaded. */
37
31
  if (place.hubPeer)
38
32
  return { kind: 'remote', peer: place.hubPeer };
33
+ if (localHub)
34
+ return { kind: 'local', hub: localHub };
35
+ warnOnce(`nohub:${domain.id}`, `domain ${domain.id}: Guild::enabled is on, but this server carries no guild hub module and Guild::hubPeer names no other server`);
39
36
  return { kind: 'off' };
40
37
  }
41
38
  /** Hand records over on the road the domain's settings name. */
@@ -1,4 +1,6 @@
1
1
  import { GuildCaptureSubscriber } from './capture.js';
2
+ import { GuildCommitSubscriber } from './committed.js';
3
+ import { GuildOverlayResolver } from './overlay-resolver.js';
2
4
  import { GuildFactChangeSeam } from './seams/fact-change-seam.js';
3
5
  export * from './contract.js';
4
6
  export * from './settings.js';
@@ -6,9 +8,18 @@ export * from './define-kinds.js';
6
8
  export * from './hub-route.js';
7
9
  export * from './emit.js';
8
10
  export * from './capture.js';
11
+ export * from './committed.js';
12
+ export * from './pulse.js';
13
+ export * from './prospect.js';
14
+ export * from './opportunities.js';
15
+ export * from './overlay-resolver.js';
9
16
  export * from './manifest-boot.js';
10
17
  export * from './seams/fact-change-seam.js';
11
18
  export * from './seams/activity-callback-seam.js';
12
19
  export { contributionFactId, revertFactId, manifestOf, keptSignals, stableJson } from './record-rules.js';
13
- /** Loaded by the shell from every module: a transaction's captured facts reset, and the fact-change seam (§3-3). */
14
- export declare const subscribers: (typeof GuildCaptureSubscriber | typeof GuildFactChangeSeam)[];
20
+ /** Loaded by the shell from every module: a transaction's captured facts reset, work run after commit, and the fact-change seam (§3-3). */
21
+ export declare const subscribers: (typeof GuildCaptureSubscriber | typeof GuildCommitSubscriber | typeof GuildFactChangeSeam)[];
22
+ /** The overlay's read and its coins (design §14-1) - on the person's own server. */
23
+ export declare const schema: {
24
+ resolverClasses: (typeof GuildOverlayResolver)[];
25
+ };
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.subscribers = exports.stableJson = exports.keptSignals = exports.manifestOf = exports.revertFactId = exports.contributionFactId = void 0;
3
+ exports.schema = exports.subscribers = exports.stableJson = exports.keptSignals = exports.manifestOf = exports.revertFactId = exports.contributionFactId = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const env_1 = require("@things-factory/env");
6
6
  const capture_js_1 = require("./capture.js");
7
+ const committed_js_1 = require("./committed.js");
8
+ const overlay_resolver_js_1 = require("./overlay-resolver.js");
7
9
  const manifest_boot_js_1 = require("./manifest-boot.js");
8
10
  const fact_change_seam_js_1 = require("./seams/fact-change-seam.js");
9
11
  tslib_1.__exportStar(require("./contract.js"), exports);
@@ -12,6 +14,11 @@ tslib_1.__exportStar(require("./define-kinds.js"), exports);
12
14
  tslib_1.__exportStar(require("./hub-route.js"), exports);
13
15
  tslib_1.__exportStar(require("./emit.js"), exports);
14
16
  tslib_1.__exportStar(require("./capture.js"), exports);
17
+ tslib_1.__exportStar(require("./committed.js"), exports);
18
+ tslib_1.__exportStar(require("./pulse.js"), exports);
19
+ tslib_1.__exportStar(require("./prospect.js"), exports);
20
+ tslib_1.__exportStar(require("./opportunities.js"), exports);
21
+ tslib_1.__exportStar(require("./overlay-resolver.js"), exports);
15
22
  tslib_1.__exportStar(require("./manifest-boot.js"), exports);
16
23
  tslib_1.__exportStar(require("./seams/fact-change-seam.js"), exports);
17
24
  tslib_1.__exportStar(require("./seams/activity-callback-seam.js"), exports);
@@ -21,8 +28,10 @@ Object.defineProperty(exports, "revertFactId", { enumerable: true, get: function
21
28
  Object.defineProperty(exports, "manifestOf", { enumerable: true, get: function () { return record_rules_js_1.manifestOf; } });
22
29
  Object.defineProperty(exports, "keptSignals", { enumerable: true, get: function () { return record_rules_js_1.keptSignals; } });
23
30
  Object.defineProperty(exports, "stableJson", { enumerable: true, get: function () { return record_rules_js_1.stableJson; } });
24
- /** Loaded by the shell from every module: a transaction's captured facts reset, and the fact-change seam (§3-3). */
25
- exports.subscribers = [capture_js_1.GuildCaptureSubscriber, fact_change_seam_js_1.GuildFactChangeSeam];
31
+ /** Loaded by the shell from every module: a transaction's captured facts reset, work run after commit, and the fact-change seam (§3-3). */
32
+ exports.subscribers = [capture_js_1.GuildCaptureSubscriber, committed_js_1.GuildCommitSubscriber, fact_change_seam_js_1.GuildFactChangeSeam];
33
+ /** The overlay's read and its coins (design §14-1) - on the person's own server. */
34
+ exports.schema = { resolverClasses: [overlay_resolver_js_1.GuildOverlayResolver] };
26
35
  /*
27
36
  * The guild overlay (operato-guild design §3): every application loads it; a product declares its contribution kinds in
28
37
  * its own `server/guild/` and emits facts from the work that confirms them. Off (`Guild::enabled`), nothing happens.
@@ -0,0 +1,23 @@
1
+ export interface GuildOpportunity {
2
+ /** The contribution kind doing it earns. */
3
+ kind: string;
4
+ /** How many are waiting for this person. */
5
+ count: number;
6
+ /** Where to do it - defaults to the kind's route. */
7
+ route?: string;
8
+ }
9
+ export type OpportunityCounter = (domain: {
10
+ id: string;
11
+ }, user: {
12
+ id: string;
13
+ }) => Promise<GuildOpportunity[]>;
14
+ /** Once at boot - how this product counts a person's waiting work. Registering a product again replaces it. */
15
+ export declare function registerOpportunityCounter(product: string, counter: OpportunityCounter): void;
16
+ /** Every product's opportunities for this person. A counter that fails is left out - the panel shows what it can. */
17
+ export declare function opportunitiesOf(domain: {
18
+ id: string;
19
+ }, user: {
20
+ id: string;
21
+ }): Promise<GuildOpportunity[]>;
22
+ /** For tests. */
23
+ export declare function forgetOpportunityCounters(): void;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /*
3
+ * **Today's quests** (design §14-1 · §15-5) - what a person could do right now that the guild would pay for. Each product
4
+ * counts its own, by the person and by what they may do: a quest the person cannot act on is never shown. The overlay asks
5
+ * on this server; the counts are the product's, the GP each is worth is the hub's rule digest.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.registerOpportunityCounter = registerOpportunityCounter;
9
+ exports.opportunitiesOf = opportunitiesOf;
10
+ exports.forgetOpportunityCounters = forgetOpportunityCounters;
11
+ const COUNTERS = new Map();
12
+ /** Once at boot - how this product counts a person's waiting work. Registering a product again replaces it. */
13
+ function registerOpportunityCounter(product, counter) {
14
+ if (!product)
15
+ throw new Error('registerOpportunityCounter needs the product name');
16
+ COUNTERS.set(product, counter);
17
+ }
18
+ /** Every product's opportunities for this person. A counter that fails is left out - the panel shows what it can. */
19
+ async function opportunitiesOf(domain, user) {
20
+ const all = [];
21
+ for (const counter of COUNTERS.values()) {
22
+ try {
23
+ for (const one of await counter(domain, user))
24
+ if (one.count > 0)
25
+ all.push(one);
26
+ }
27
+ catch {
28
+ /* One product's count failing does not empty the panel. */
29
+ }
30
+ }
31
+ return all;
32
+ }
33
+ /** For tests. */
34
+ function forgetOpportunityCounters() {
35
+ COUNTERS.clear();
36
+ }
37
+ //# sourceMappingURL=opportunities.js.map
@@ -0,0 +1,64 @@
1
+ import { type GuildPulseMessage } from './pulse.js';
2
+ export declare class GuildOverlayWallet {
3
+ balance: number;
4
+ spendable: number;
5
+ pendingGp: number;
6
+ maturedGp: number;
7
+ everGp: number;
8
+ level: number;
9
+ levelFloor: number;
10
+ nextLevelAt?: number;
11
+ }
12
+ export declare class GuildOverlayBadge {
13
+ kind: string;
14
+ label?: any;
15
+ count: number;
16
+ step: number;
17
+ nextStep?: number;
18
+ }
19
+ export declare class GuildOverlayQuest {
20
+ kind: string;
21
+ label?: any;
22
+ count: number;
23
+ route?: string;
24
+ gpEach?: number;
25
+ }
26
+ export declare class GuildOverlayKind {
27
+ kind: string;
28
+ label?: any;
29
+ route?: string;
30
+ hint?: any;
31
+ gpEach?: number;
32
+ }
33
+ export declare class GuildOverlayMissed {
34
+ count: number;
35
+ kind: string;
36
+ label?: any;
37
+ }
38
+ export declare class GuildOverlay {
39
+ enabled: boolean;
40
+ missed?: GuildOverlayMissed;
41
+ wallet?: GuildOverlayWallet;
42
+ badges: GuildOverlayBadge[];
43
+ quests: GuildOverlayQuest[];
44
+ kinds: GuildOverlayKind[];
45
+ }
46
+ export declare class GuildPulseNote {
47
+ kind: string;
48
+ contributionKind?: string;
49
+ label?: any;
50
+ title?: string;
51
+ path?: string;
52
+ gp?: number;
53
+ gpLow?: number;
54
+ gpHigh?: number;
55
+ gt?: number;
56
+ count?: number;
57
+ reason?: string;
58
+ hint?: any;
59
+ at: string;
60
+ }
61
+ export declare class GuildOverlayResolver {
62
+ guildOverlay(since: Date | undefined, context: ResolverContext): Promise<GuildOverlay>;
63
+ guildPulse(message: GuildPulseMessage): GuildPulseNote;
64
+ }