@anhlp/alp-core 0.0.1-beta.5 → 0.0.1-beta.6
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/dist/packaged.d.ts +2 -1
- package/dist/tasks.d.ts +2 -1
- package/dist/tasks.js +8 -2
- package/package.json +2 -2
- package/src/packaged.js +1 -1
- package/src/tasks.d.ts +2 -1
- package/src/tasks.js +16 -5
package/dist/packaged.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {{ path: string, sha256: string, size: number }} PackagedAsset
|
|
3
|
-
* @typedef {{ version: string, assets?: Record<string, PackagedAsset>, roles?: Record<string, () => Promise<unknown>> }} PackagedRegistration
|
|
3
|
+
* @typedef {{ version: string, assets?: Record<string, PackagedAsset>, roles?: Record<string, () => Promise<unknown>>, modules?: Record<string, () => Promise<unknown>> }} PackagedRegistration
|
|
4
4
|
*/
|
|
5
5
|
/** Called once by the executable's entry. @param {PackagedRegistration} registration */
|
|
6
6
|
export function registerPackaged(registration: PackagedRegistration): void;
|
|
@@ -93,4 +93,5 @@ export type PackagedRegistration = {
|
|
|
93
93
|
version: string;
|
|
94
94
|
assets?: Record<string, PackagedAsset>;
|
|
95
95
|
roles?: Record<string, () => Promise<unknown>>;
|
|
96
|
+
modules?: Record<string, () => Promise<unknown>>;
|
|
96
97
|
};
|
package/dist/tasks.d.ts
CHANGED
|
@@ -117,12 +117,13 @@ export function gatesOf(task: Task, tasks: Task[]): string[];
|
|
|
117
117
|
export const GATE_OPTIONS: number;
|
|
118
118
|
export const GATE_OPTION_CHARS: number;
|
|
119
119
|
export const GATE_CHANNELS: GateChannel[];
|
|
120
|
+
export const GATE_REJECT_LABELS: string[];
|
|
120
121
|
export function addGate(projectRoot: string, id: string, gate: { kind: GateKind; note?: string; until?: string; ref?: string | number; options?: string[] }, by: string): Promise<Task>;
|
|
121
122
|
export function resolveGate(projectRoot: string, id: string, gateId: string, resolve: { by: string; note?: string; remove?: boolean; ifRev?: number; choice?: string; channel?: GateChannel }): Promise<Task>;
|
|
122
123
|
export function rejectGate(projectRoot: string, id: string, gateId: string, reject: { by: string; reason?: string; ifRev?: number; channel?: GateChannel }): Promise<Task>;
|
|
123
124
|
export type GateDecision = { task: Task; gate: TaskGate; decision: 'approved' | 'rejected'; record: NonNullable<TaskGate['resolved'] | TaskGate['rejected']> };
|
|
124
125
|
export function gateDecisions(tasks: Task[]): GateDecision[];
|
|
125
|
-
export function markGateNotified(projectRoot: string, id: string, gateId: string, decision: 'approved' | 'rejected'): Promise<boolean>;
|
|
126
|
+
export function markGateNotified(projectRoot: string, id: string, gateId: string, decision: 'approved' | 'rejected', at?: string): Promise<boolean>;
|
|
126
127
|
export function checkGates(projectRoot: string, gh: (args: string[], options: { cwd: string }) => Promise<string>): Promise<{ cleared: Array<{ task: string; gate: string; detail: string }>; pending: Array<{ task: string; gate: string; detail: string }>; errors: Array<{ task: string; gate: string; error: string }> }>;
|
|
127
128
|
export function compactTasks(projectRoot: string, options: { days?: number; dryRun?: boolean }, by: string): Promise<Array<{ id: string; before: number; after: number }>>;
|
|
128
129
|
export type TaskBatch = {
|
package/dist/tasks.js
CHANGED
|
@@ -653,10 +653,15 @@ function addGate(projectRoot, id, { kind, note, until, ref, options } = {}, by)
|
|
|
653
653
|
var GATE_OPTIONS = 10;
|
|
654
654
|
var GATE_OPTION_CHARS = 200;
|
|
655
655
|
var GATE_CHANNELS = ["paseo", "web", "cli"];
|
|
656
|
+
var GATE_REJECT_LABELS = ["Reject", "T\u1EEB ch\u1ED1i"];
|
|
657
|
+
var labelKey = (text) => text.normalize("NFC").trim().toLowerCase();
|
|
658
|
+
var REJECT_KEYS = new Set(GATE_REJECT_LABELS.map(labelKey));
|
|
656
659
|
function gateOptions(value) {
|
|
657
660
|
if (!Array.isArray(value) || value.length > GATE_OPTIONS || !value.every((item) => typeof item === "string" && !!item.trim() && item.trim().length <= GATE_OPTION_CHARS)) {
|
|
658
661
|
fail("INVALID_TASK", `options must list at most ${GATE_OPTIONS} nonempty answers of at most ${GATE_OPTION_CHARS} characters`);
|
|
659
662
|
}
|
|
663
|
+
const reserved = value.find((item) => REJECT_KEYS.has(labelKey(item)));
|
|
664
|
+
if (reserved !== void 0) fail("INVALID_TASK", `"${reserved.trim()}" is the Reject answer every gate card already offers; name the options for approving only`);
|
|
660
665
|
return [...new Set(value.map((item) => item.trim()))];
|
|
661
666
|
}
|
|
662
667
|
var checkChannel = (channel) => {
|
|
@@ -716,13 +721,13 @@ function gateDecisions(tasks) {
|
|
|
716
721
|
}
|
|
717
722
|
return found;
|
|
718
723
|
}
|
|
719
|
-
function markGateNotified(projectRoot, id, gateId, decision) {
|
|
724
|
+
function markGateNotified(projectRoot, id, gateId, decision, at) {
|
|
720
725
|
return locked(projectRoot, async () => {
|
|
721
726
|
const { tasks } = await loadTasks(projectRoot);
|
|
722
727
|
const task = tasks.find((entry) => entry.id === id);
|
|
723
728
|
const gate = task?.gates?.find((entry) => entry.id === gateId);
|
|
724
729
|
const record = decision === "approved" ? gate?.resolved : gate?.rejected;
|
|
725
|
-
if (!task || !record?.channel || record.notified) return false;
|
|
730
|
+
if (!task || !record?.channel || record.notified || at !== void 0 && record.at !== at) return false;
|
|
726
731
|
record.notified = now();
|
|
727
732
|
await save(projectRoot, task);
|
|
728
733
|
return true;
|
|
@@ -872,6 +877,7 @@ export {
|
|
|
872
877
|
GATE_KINDS,
|
|
873
878
|
GATE_OPTIONS,
|
|
874
879
|
GATE_OPTION_CHARS,
|
|
880
|
+
GATE_REJECT_LABELS,
|
|
875
881
|
MAX_GATES,
|
|
876
882
|
MAX_LABELS,
|
|
877
883
|
MAX_LINKS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anhlp/alp-core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ALP core module",
|
|
6
6
|
"files": [
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
"node": ">=22.12"
|
|
301
301
|
},
|
|
302
302
|
"dependencies": {
|
|
303
|
-
"@anhlp/alp-protocol": "0.0.1-beta.
|
|
303
|
+
"@anhlp/alp-protocol": "0.0.1-beta.6"
|
|
304
304
|
},
|
|
305
305
|
"scripts": {
|
|
306
306
|
"build": "node ../../scripts/build-workspace.mjs core",
|
package/src/packaged.js
CHANGED
|
@@ -25,7 +25,7 @@ export const ROLE_ARGS = Object.freeze({
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @typedef {{ path: string, sha256: string, size: number }} PackagedAsset
|
|
28
|
-
* @typedef {{ version: string, assets?: Record<string, PackagedAsset>, roles?: Record<string, () => Promise<unknown>> }} PackagedRegistration
|
|
28
|
+
* @typedef {{ version: string, assets?: Record<string, PackagedAsset>, roles?: Record<string, () => Promise<unknown>>, modules?: Record<string, () => Promise<unknown>> }} PackagedRegistration
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
/** Called once by the executable's entry. @param {PackagedRegistration} registration */
|
package/src/tasks.d.ts
CHANGED
|
@@ -117,12 +117,13 @@ export function gatesOf(task: Task, tasks: Task[]): string[];
|
|
|
117
117
|
export const GATE_OPTIONS: number;
|
|
118
118
|
export const GATE_OPTION_CHARS: number;
|
|
119
119
|
export const GATE_CHANNELS: GateChannel[];
|
|
120
|
+
export const GATE_REJECT_LABELS: string[];
|
|
120
121
|
export function addGate(projectRoot: string, id: string, gate: { kind: GateKind; note?: string; until?: string; ref?: string | number; options?: string[] }, by: string): Promise<Task>;
|
|
121
122
|
export function resolveGate(projectRoot: string, id: string, gateId: string, resolve: { by: string; note?: string; remove?: boolean; ifRev?: number; choice?: string; channel?: GateChannel }): Promise<Task>;
|
|
122
123
|
export function rejectGate(projectRoot: string, id: string, gateId: string, reject: { by: string; reason?: string; ifRev?: number; channel?: GateChannel }): Promise<Task>;
|
|
123
124
|
export type GateDecision = { task: Task; gate: TaskGate; decision: 'approved' | 'rejected'; record: NonNullable<TaskGate['resolved'] | TaskGate['rejected']> };
|
|
124
125
|
export function gateDecisions(tasks: Task[]): GateDecision[];
|
|
125
|
-
export function markGateNotified(projectRoot: string, id: string, gateId: string, decision: 'approved' | 'rejected'): Promise<boolean>;
|
|
126
|
+
export function markGateNotified(projectRoot: string, id: string, gateId: string, decision: 'approved' | 'rejected', at?: string): Promise<boolean>;
|
|
126
127
|
export function checkGates(projectRoot: string, gh: (args: string[], options: { cwd: string }) => Promise<string>): Promise<{ cleared: Array<{ task: string; gate: string; detail: string }>; pending: Array<{ task: string; gate: string; detail: string }>; errors: Array<{ task: string; gate: string; error: string }> }>;
|
|
127
128
|
export function compactTasks(projectRoot: string, options: { days?: number; dryRun?: boolean }, by: string): Promise<Array<{ id: string; before: number; after: number }>>;
|
|
128
129
|
export type TaskBatch = {
|
package/src/tasks.js
CHANGED
|
@@ -743,12 +743,22 @@ export function addGate(projectRoot, id, { kind, note, until, ref, options } = {
|
|
|
743
743
|
export const GATE_OPTIONS = 10;
|
|
744
744
|
export const GATE_OPTION_CHARS = 200;
|
|
745
745
|
export const GATE_CHANNELS = ['paseo', 'web', 'cli'];
|
|
746
|
+
/**
|
|
747
|
+
* The Reject answer a gate card adds after its options, in every language ALP writes it
|
|
748
|
+
* (packages/runtime/src/language.ts, `reject`). An option that is one would hide that Reject
|
|
749
|
+
* and approve the gate instead, so no option may be one (t-595d).
|
|
750
|
+
*/
|
|
751
|
+
export const GATE_REJECT_LABELS = ['Reject', 'Từ chối'];
|
|
752
|
+
const labelKey = text => text.normalize('NFC').trim().toLowerCase();
|
|
753
|
+
const REJECT_KEYS = new Set(GATE_REJECT_LABELS.map(labelKey));
|
|
746
754
|
|
|
747
|
-
/** The answers a human gate offers its approver: at most 10 distinct, nonempty, each at most 200 characters. */
|
|
755
|
+
/** The answers a human gate offers its approver: at most 10 distinct, nonempty, each at most 200 characters, none of them Reject. */
|
|
748
756
|
function gateOptions(value) {
|
|
749
757
|
if (!Array.isArray(value) || value.length > GATE_OPTIONS || !value.every(item => typeof item === 'string' && !!item.trim() && item.trim().length <= GATE_OPTION_CHARS)) {
|
|
750
758
|
fail('INVALID_TASK', `options must list at most ${GATE_OPTIONS} nonempty answers of at most ${GATE_OPTION_CHARS} characters`);
|
|
751
759
|
}
|
|
760
|
+
const reserved = value.find(item => REJECT_KEYS.has(labelKey(item)));
|
|
761
|
+
if (reserved !== undefined) fail('INVALID_TASK', `"${reserved.trim()}" is the Reject answer every gate card already offers; name the options for approving only`);
|
|
752
762
|
return [...new Set(value.map(item => item.trim()))];
|
|
753
763
|
}
|
|
754
764
|
|
|
@@ -828,17 +838,18 @@ export function gateDecisions(tasks) {
|
|
|
828
838
|
}
|
|
829
839
|
|
|
830
840
|
/**
|
|
831
|
-
* Marks a decision reported, under the lock, and returns whether this call marked it
|
|
832
|
-
*
|
|
841
|
+
* Marks a decision reported, under the lock, and returns whether this call marked it. alpd marks
|
|
842
|
+
* it once main has taken the mail (t-595d), so a decision is reported at least once; with `at`,
|
|
843
|
+
* only the decision made then is marked, never a later one that replaced it.
|
|
833
844
|
* Marking does not change the task's rev, so an open card's ifRev stays valid.
|
|
834
845
|
*/
|
|
835
|
-
export function markGateNotified(projectRoot, id, gateId, decision) {
|
|
846
|
+
export function markGateNotified(projectRoot, id, gateId, decision, at) {
|
|
836
847
|
return locked(projectRoot, async () => {
|
|
837
848
|
const { tasks } = await loadTasks(projectRoot);
|
|
838
849
|
const task = tasks.find(entry => entry.id === id);
|
|
839
850
|
const gate = task?.gates?.find(entry => entry.id === gateId);
|
|
840
851
|
const record = decision === 'approved' ? gate?.resolved : gate?.rejected;
|
|
841
|
-
if (!task || !record?.channel || record.notified) return false;
|
|
852
|
+
if (!task || !record?.channel || record.notified || (at !== undefined && record.at !== at)) return false;
|
|
842
853
|
record.notified = now();
|
|
843
854
|
await save(projectRoot, task);
|
|
844
855
|
return true;
|