@weiliang0121/capix-changes 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -14,6 +14,12 @@ npm install @weiliang0121/capix-changes
14
14
 
15
15
  This package is part of CAPiX. The npm distribution contains compiled JavaScript, type declarations, and this package's MIT license. Reference services and client applications are not included in this package or the initial npm release.
16
16
 
17
+ ## Typed facts
18
+
19
+ `FactType<Event>` creates an opaque, frozen `Fact` for local forwarding. Only the exact token's `match(fact, consume)` reads its deeply fixed `Stable<Event>` body; names describe tokens and do not establish identity.
20
+
21
+ `Fact` is an in-process carrier with a private symbol marker and WeakMap evidence. It is not a formal delivery value or checkpoint payload: `stableValue(fact)` rejects it rather than cloning away its identity. Read the body through `match` and explicitly encode that stable data when saving it. Copying the marker does not grant access to a fact's body.
22
+
17
23
  ## License
18
24
 
19
- MIT. Copyright (c) 2026 wei.liang. See [LICENSE](./LICENSE).
25
+ MIT. Copyright (c) 2026 wei.liang. See [LICENSE](LICENSE).
package/dist/fact.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type Stable } from '@weiliang0121/capix-contracts';
2
+ declare const factBrand: unique symbol;
3
+ declare const factTypeSignature: unique symbol;
4
+ export interface Fact {
5
+ readonly name?: string;
6
+ readonly [factBrand]: true;
7
+ }
8
+ export declare class FactType<Event> {
9
+ readonly [factTypeSignature]: (event: Event) => Event;
10
+ readonly name?: string;
11
+ constructor(name?: string);
12
+ create(event: Event): Fact;
13
+ match(fact: Fact, consume: (event: Stable<Event>) => void): boolean;
14
+ }
15
+ export {};
package/dist/fact.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{stableValue}from"@weiliang0121/capix-contracts";const factBrand=Symbol("Fact"),facts=new WeakMap,types=new WeakSet;class FactType{static{__name(this,"FactType")}name;constructor(name){if(name!==void 0&&typeof name!="string")throw new TypeError("FactType name must be a string or undefined");this.name=name,types.add(this),Object.freeze(this)}create(event){if(!types.has(this))throw new TypeError("Fact creation requires an authentic FactType");const value=stableValue(event),fact=Object.freeze({name:this.name,[factBrand]:!0});return facts.set(fact,{type:this,value}),fact}match(fact,consume){if(!types.has(this))throw new TypeError("Fact matching requires an authentic FactType");const fixed=facts.get(fact);if(!fixed)throw new TypeError("Fact matching requires an authentic Fact");if(fixed.type!==this)return!1;const returned=consume(fixed.value);if(returned!==null&&(typeof returned=="object"||typeof returned=="function")&&typeof returned.then=="function")throw Promise.resolve(returned).catch(()=>{}),new TypeError("Fact consumers must complete synchronously");return!0}}export{FactType};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { ChangeCapture } from './capture.js';
2
+ export { FactType, type Fact } from './fact.js';
2
3
  export { ChangeBuffer } from './buffer.js';
3
4
  export { ChangeCaptureError, combineFaults } from './error.js';
4
5
  export { captureChange, publishFact, type ChangeProvenance } from './publish.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
- import{ChangeBuffer}from"./buffer.js";import{ChangeCaptureError,combineFaults}from"./error.js";import{captureChange,publishFact}from"./publish.js";import{ProgressChannel}from"./progress.js";export{ChangeBuffer,ChangeCaptureError,ProgressChannel,captureChange,combineFaults,publishFact};
2
+ import{FactType}from"./fact.js";import{ChangeBuffer}from"./buffer.js";import{ChangeCaptureError,combineFaults}from"./error.js";import{captureChange,publishFact}from"./publish.js";import{ProgressChannel}from"./progress.js";export{ChangeBuffer,ChangeCaptureError,FactType,ProgressChannel,captureChange,combineFaults,publishFact};
package/dist/publish.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { InvocationOrigin } from '@weiliang0121/capix-protocol';
1
+ import type { InvocationOrigin } from '@weiliang0121/capix-contracts';
2
2
  import type { EventConsumer } from './consumer.js';
3
3
  import type { ChangeCapture } from './capture.js';
4
4
  export declare function captureChange<Event>(capture: ChangeCapture<Event> | undefined, event: Event): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weiliang0121/capix-changes",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,8 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "es-toolkit": "1.52.0",
14
- "@weiliang0121/capix-contracts": "0.1.0",
15
- "@weiliang0121/capix-protocol": "0.1.0"
14
+ "@weiliang0121/capix-contracts": "0.2.0"
16
15
  },
17
16
  "description": "Change capture and delivery for CAPiX entities.",
18
17
  "license": "MIT",
@@ -20,7 +19,7 @@
20
19
  "repository": {
21
20
  "type": "git",
22
21
  "url": "git+https://github.com/weiliang0121/capix.git",
23
- "directory": "server/changes"
22
+ "directory": "packages/changes"
24
23
  },
25
24
  "engines": {
26
25
  "node": ">=22.23.2"
@@ -39,6 +38,7 @@
39
38
  },
40
39
  "scripts": {
41
40
  "build": "tsc -p tsconfig.json",
42
- "typecheck": "tsc -p tsconfig.json --noEmit"
41
+ "typecheck": "tsc -p tsconfig.json --noEmit",
42
+ "test": "node ../../scripts/test/run.mjs --package ."
43
43
  }
44
44
  }