@weiliang0121/capix-changes 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +24 -2
- package/dist/buffer.d.ts +8 -0
- package/dist/buffer.js +2 -0
- package/dist/capture.d.ts +3 -0
- package/dist/capture.js +1 -0
- package/dist/consumer.d.ts +3 -0
- package/dist/consumer.js +1 -0
- package/dist/error.d.ts +6 -0
- package/dist/error.js +2 -0
- package/dist/fact.d.ts +15 -0
- package/dist/fact.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/progress.d.ts +12 -0
- package/dist/progress.js +2 -0
- package/dist/publish.d.ts +9 -0
- package/dist/publish.js +2 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wei.liang (https://github.com/weiliang0121)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weiliang0121/capix-changes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Change capture and delivery for CAPiX entities.
|
|
4
|
+
|
|
5
|
+
ES modules and TypeScript declarations. Requires Node.js 22.23.2 or newer.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @weiliang0121/capix-changes
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public entry points
|
|
12
|
+
|
|
13
|
+
- `@weiliang0121/capix-changes`
|
|
14
|
+
|
|
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
|
+
|
|
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
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT. Copyright (c) 2026 wei.liang. See [LICENSE](LICENSE).
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChangeCapture } from './capture.js';
|
|
2
|
+
export declare class ChangeBuffer<Event> implements ChangeCapture<Event> {
|
|
3
|
+
#private;
|
|
4
|
+
wait(signal: AbortSignal): Promise<void>;
|
|
5
|
+
readonly capture: (event: Event) => void;
|
|
6
|
+
get size(): number;
|
|
7
|
+
take(): readonly Event[];
|
|
8
|
+
}
|
package/dist/buffer.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});class ChangeBuffer{static{__name(this,"ChangeBuffer")}#pending=[];#waiters=new Set;wait(signal){return this.#pending.length||signal.aborted?Promise.resolve():new Promise(resolve=>{const ready=__name(()=>{this.#waiters.delete(ready),signal.removeEventListener("abort",ready),resolve()},"ready");this.#waiters.add(ready),signal.addEventListener("abort",ready,{once:!0})})}capture=__name(event=>{this.#pending.push(event);for(const ready of this.#waiters)ready()},"capture");get size(){return this.#pending.length}take(){const batch=Object.freeze(this.#pending);return this.#pending=[],batch}}export{ChangeBuffer};
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
package/dist/consumer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RuntimeError } from '@weiliang0121/capix-contracts';
|
|
2
|
+
export declare class ChangeCaptureError<Event = unknown> extends RuntimeError {
|
|
3
|
+
readonly event: Event;
|
|
4
|
+
constructor(event: Event, cause: unknown);
|
|
5
|
+
}
|
|
6
|
+
export declare function combineFaults(faults: readonly unknown[]): unknown | undefined;
|
package/dist/error.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{RuntimeError}from"@weiliang0121/capix-contracts";class ChangeCaptureError extends RuntimeError{static{__name(this,"ChangeCaptureError")}event;constructor(event,cause){super("CHANGE_CAPTURE_FAILED","\u53D8\u5316\u5DF2\u843D\u5B9E\uFF0C\u4F46\u6355\u83B7\u5931\u8D25\uFF1B\u4E0D\u5F97\u901A\u8FC7\u91CD\u505A\u5DE5\u4F5C\u8865\u507F\u3002",void 0,{cause}),this.event=event}}function combineFaults(faults){if(faults.length!==0)return faults.length===1?faults[0]:new AggregateError(faults,"Multiple publication failures",{cause:faults[0]})}__name(combineFaults,"combineFaults");export{ChangeCaptureError,combineFaults};
|
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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ChangeCapture } from './capture.js';
|
|
2
|
+
export { FactType, type Fact } from './fact.js';
|
|
3
|
+
export { ChangeBuffer } from './buffer.js';
|
|
4
|
+
export { ChangeCaptureError, combineFaults } from './error.js';
|
|
5
|
+
export { captureChange, publishFact, type ChangeProvenance } from './publish.js';
|
|
6
|
+
export type { EventConsumer } from './consumer.js';
|
|
7
|
+
export { ProgressChannel, type ProgressFailure, type ProgressReceiver } from './progress.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
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};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProgressReceiver } from '@weiliang0121/capix-contracts';
|
|
2
|
+
export type { ProgressReceiver } from '@weiliang0121/capix-contracts';
|
|
3
|
+
export interface ProgressFailure {
|
|
4
|
+
readonly error: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare class ProgressChannel<Fact> {
|
|
7
|
+
#private;
|
|
8
|
+
private readonly receiver;
|
|
9
|
+
constructor(receiver: ProgressReceiver<Fact>);
|
|
10
|
+
get failure(): ProgressFailure | undefined;
|
|
11
|
+
publish(fact: Readonly<Fact>): void;
|
|
12
|
+
}
|
package/dist/progress.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});class ProgressChannel{static{__name(this,"ProgressChannel")}receiver;#failure;constructor(receiver){this.receiver=receiver}get failure(){return this.#failure}publish(fact){if(!this.#failure)try{const returned=this.receiver.receive(fact);if(returned!==void 0)throw Promise.resolve(returned).catch(()=>{}),new TypeError("Progress receivers must return undefined synchronously")}catch(error){this.#failure=Object.freeze({error});try{const reported=this.receiver.failed?.(error);reported!==void 0&&Promise.resolve(reported).catch(()=>{})}catch{}}}}export{ProgressChannel};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InvocationOrigin } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { EventConsumer } from './consumer.js';
|
|
3
|
+
import type { ChangeCapture } from './capture.js';
|
|
4
|
+
export declare function captureChange<Event>(capture: ChangeCapture<Event> | undefined, event: Event): void;
|
|
5
|
+
export interface ChangeProvenance<Event> {
|
|
6
|
+
readonly origin?: InvocationOrigin;
|
|
7
|
+
readonly observation?: EventConsumer<Event>;
|
|
8
|
+
}
|
|
9
|
+
export declare function publishFact<Event>(event: Event, capture?: ChangeCapture<Event>, observer?: EventConsumer<Event>): void;
|
package/dist/publish.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{isUndefined}from"es-toolkit/predicate";import{combineFaults}from"./error.js";import{ChangeCaptureError}from"./error.js";function captureChange(capture,event){try{capture?.capture(event)}catch(cause){throw new ChangeCaptureError(event,cause)}}__name(captureChange,"captureChange");function publishFact(event,capture,observer){const faults=[];try{captureChange(capture,event)}catch(error2){faults.push(error2)}try{const error2=observer?.publish(event);isUndefined(error2)||faults.push(error2)}catch(error2){faults.push(error2)}const error=combineFaults(faults);if(!isUndefined(error))throw error}__name(publishFact,"publishFact");export{captureChange,publishFact};
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weiliang0121/capix-changes",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"es-toolkit": "1.52.0",
|
|
14
|
+
"@weiliang0121/capix-contracts": "0.2.0"
|
|
15
|
+
},
|
|
16
|
+
"description": "Change capture and delivery for CAPiX entities.",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "wei.liang (https://github.com/weiliang0121)",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/weiliang0121/capix.git",
|
|
22
|
+
"directory": "packages/changes"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.23.2"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*.js",
|
|
31
|
+
"dist/**/*.d.ts",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "node ../../scripts/test/run.mjs --package ."
|
|
43
|
+
}
|
|
6
44
|
}
|