@weiliang0121/capix-changes 0.0.0-stage → 0.1.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 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,19 @@
1
- # Temporary Holding Version
1
+ # @weiliang0121/capix-changes
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ ## License
18
+
19
+ MIT. Copyright (c) 2026 wei.liang. See [LICENSE](./LICENSE).
@@ -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};
@@ -0,0 +1,3 @@
1
+ export interface ChangeCapture<Event> {
2
+ readonly capture: (event: Event) => void;
3
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,3 @@
1
+ export interface EventConsumer<Event> {
2
+ publish(event: Event): unknown | undefined;
3
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -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};
@@ -0,0 +1,6 @@
1
+ export type { ChangeCapture } from './capture.js';
2
+ export { ChangeBuffer } from './buffer.js';
3
+ export { ChangeCaptureError, combineFaults } from './error.js';
4
+ export { captureChange, publishFact, type ChangeProvenance } from './publish.js';
5
+ export type { EventConsumer } from './consumer.js';
6
+ 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{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};
@@ -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
+ }
@@ -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-protocol';
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;
@@ -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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.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.1.0",
15
+ "@weiliang0121/capix-protocol": "0.1.0"
16
+ },
17
+ "description": "Change capture and delivery for CAPiX entities.",
18
+ "license": "MIT",
19
+ "author": "wei.liang (https://github.com/weiliang0121)",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/weiliang0121/capix.git",
23
+ "directory": "server/changes"
24
+ },
25
+ "engines": {
26
+ "node": ">=22.23.2"
27
+ },
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "dist/**/*.js",
32
+ "dist/**/*.d.ts",
33
+ "LICENSE",
34
+ "README.md"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "registry": "https://registry.npmjs.org"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit"
43
+ }
6
44
  }