aicommunicator-plugin-check 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 +55 -0
- package/README.md +57 -2
- package/dist/bundle.d.ts +61 -0
- package/dist/bundle.js +318 -0
- package/dist/icon.d.ts +10 -0
- package/dist/icon.js +61 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10 -0
- package/dist/manifest.d.ts +76 -0
- package/dist/manifest.js +244 -0
- package/dist/messages.d.ts +60 -0
- package/dist/messages.js +256 -0
- package/dist/sample.d.ts +167 -0
- package/dist/sample.js +286 -0
- package/dist/state.d.ts +18 -0
- package/dist/state.js +49 -0
- package/dist/version.d.ts +25 -0
- package/dist/version.js +121 -0
- package/package.json +21 -4
package/dist/sample.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export declare const SAMPLE_FORMAT = "aic-sample/1";
|
|
2
|
+
/** 설명서 글의 한도(글자, 037 7절 4번). */
|
|
3
|
+
export declare const MANUAL_MAX_CHARS = 50000;
|
|
4
|
+
/** 예제 파일 하나의 한도(글자, 037 7절 4번). */
|
|
5
|
+
export declare const SAMPLE_MAX_CHARS = 200000;
|
|
6
|
+
/** 예제를 쓴 참여자. 실제 이름 대신 "사람", "AI" 이고, 같은 종류가 여럿이면 "사람 2" 처럼 번호를 붙인다. 참여자가 없는 revision 은 "코어" 다. */
|
|
7
|
+
export declare const SAMPLE_WHO: RegExp;
|
|
8
|
+
/** 예제가 쓴 플러그인 하나. version 은 그 작업에 적힌 가장 높은 버전이다. */
|
|
9
|
+
export interface SamplePlugin {
|
|
10
|
+
package: string;
|
|
11
|
+
version: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
}
|
|
14
|
+
/** 예제 작업의 인스턴스 하나. 외부 연결 인스턴스는 package 가 aic.link 이고 연결 이름만 적는다. 연결 정의와 인증 값은 넣지 않는다. */
|
|
15
|
+
export interface SampleInstance {
|
|
16
|
+
id: string;
|
|
17
|
+
package: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
connection?: string;
|
|
20
|
+
}
|
|
21
|
+
/** 원인에 남은 사람의 말. 화면에서 사람이 쓴 것(screen)과 AI 가 옮겨 적은 것(relayed_by_ai)이 있다. */
|
|
22
|
+
export interface SampleWords {
|
|
23
|
+
text: string;
|
|
24
|
+
source: 'screen' | 'relayed_by_ai';
|
|
25
|
+
}
|
|
26
|
+
/** 원인이 된 선택. 결과물에서 고른 것(artifact)과 개념 화면에서 가리킨 것(concept)이다. */
|
|
27
|
+
export interface SampleSelection {
|
|
28
|
+
kind: 'artifact' | 'concept';
|
|
29
|
+
said?: string;
|
|
30
|
+
/** 결과물에서 고른 글. */
|
|
31
|
+
text?: string;
|
|
32
|
+
artifact?: string;
|
|
33
|
+
instance?: string;
|
|
34
|
+
role?: 'change' | 'reference';
|
|
35
|
+
records?: string[];
|
|
36
|
+
}
|
|
37
|
+
/** revision 의 원인(037 5.2절). 사람의 말, 선택, 옮기기와 인스턴스의 일이다. */
|
|
38
|
+
export interface SampleCause {
|
|
39
|
+
humanWords?: SampleWords[];
|
|
40
|
+
selection?: SampleSelection;
|
|
41
|
+
/** 부딪힘이나 되돌리기에 사람이 답한 말. */
|
|
42
|
+
choice?: SampleWords;
|
|
43
|
+
switch?: {
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
mode: string;
|
|
47
|
+
};
|
|
48
|
+
artifact?: {
|
|
49
|
+
id: string;
|
|
50
|
+
keys: string[];
|
|
51
|
+
};
|
|
52
|
+
reports?: string[];
|
|
53
|
+
/** 인스턴스 더하기, 이름 바꾸기, 연결 설정 고르기(값은 넣지 않는다), 버전 올리기. */
|
|
54
|
+
instance?: {
|
|
55
|
+
action: 'add' | 'rename' | 'option' | 'upgrade';
|
|
56
|
+
instance?: string;
|
|
57
|
+
package?: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
connection?: string;
|
|
60
|
+
field?: string;
|
|
61
|
+
from?: string;
|
|
62
|
+
to?: string;
|
|
63
|
+
};
|
|
64
|
+
restore?: {
|
|
65
|
+
to: string;
|
|
66
|
+
records: string[] | null;
|
|
67
|
+
};
|
|
68
|
+
resolves?: {
|
|
69
|
+
conflicts: string[];
|
|
70
|
+
take?: 'mine' | 'theirs';
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface SampleOperation {
|
|
74
|
+
op: string;
|
|
75
|
+
as?: string;
|
|
76
|
+
input?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
export interface SampleChange {
|
|
79
|
+
record: string;
|
|
80
|
+
type: string;
|
|
81
|
+
owner: string | null;
|
|
82
|
+
before: unknown;
|
|
83
|
+
after: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface SampleRevision {
|
|
86
|
+
revision: string;
|
|
87
|
+
who: string;
|
|
88
|
+
kind: string;
|
|
89
|
+
cause?: SampleCause;
|
|
90
|
+
summary: string;
|
|
91
|
+
operations?: SampleOperation[];
|
|
92
|
+
changes: SampleChange[];
|
|
93
|
+
}
|
|
94
|
+
/** 외부 연결의 실행 기록 요약. 보낸 꾸러미, 제조사의 요청과 응답, 외부 id 와 주소는 넣지 않는다(037 5.2절). */
|
|
95
|
+
export interface SampleTransmission {
|
|
96
|
+
instance: string;
|
|
97
|
+
kind: 'send' | 'update';
|
|
98
|
+
status: string;
|
|
99
|
+
label?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 생성으로 만든 결과물 하나(037 8절, process-log 세션 요청 2026-11-18). 생성은 revision 이 아니라 revisions 에 나오지 않으므로 따로 둔다.
|
|
103
|
+
* 결과물 본문과 재료 글은 넣지 않고, 어느 상태(after)에서 어느 범위와 구간으로 만들었는지만 적는다.
|
|
104
|
+
*/
|
|
105
|
+
export interface SampleGeneration {
|
|
106
|
+
artifact: string;
|
|
107
|
+
who: string;
|
|
108
|
+
medium: string;
|
|
109
|
+
/** 생성의 출발점인 개념 인스턴스. */
|
|
110
|
+
instance?: string;
|
|
111
|
+
/** 만든 범위의 id. 없으면 전체다. */
|
|
112
|
+
scope?: string[];
|
|
113
|
+
/** 결과물의 구간 이름(차례대로). */
|
|
114
|
+
sections: string[];
|
|
115
|
+
/** 본문이 오지 않은 구간 이름. */
|
|
116
|
+
missing?: string[];
|
|
117
|
+
/** 이 revision 까지의 상태로 만들었다(만든 참여자의 끝). */
|
|
118
|
+
after: string;
|
|
119
|
+
}
|
|
120
|
+
export interface SampleFile {
|
|
121
|
+
format: typeof SAMPLE_FORMAT;
|
|
122
|
+
/** 내보낸 작업의 이름. */
|
|
123
|
+
title: string;
|
|
124
|
+
plugins: SamplePlugin[];
|
|
125
|
+
instances: SampleInstance[];
|
|
126
|
+
revisions: SampleRevision[];
|
|
127
|
+
generations?: SampleGeneration[];
|
|
128
|
+
transmissions?: SampleTransmission[];
|
|
129
|
+
}
|
|
130
|
+
/** 글자 수(코드 포인트). manifest 의 길이 한도와 같은 방법으로 잰다. */
|
|
131
|
+
export declare function charCount(s: string): number;
|
|
132
|
+
/**
|
|
133
|
+
* 예제 파일(aic-sample/1)의 검사. 문제의 설명이고 없으면 null 이다. 맨 위 층과 revision 과 원인에 모르는 칸이 있으면 거절한다.
|
|
134
|
+
* 예제는 실제 작업을 내보낸 것이어야 하고(037 7절 2번), 내보낼 때 지운 것(참여자 이름, 도구, 시각, 연결 정의)이 다시 들어가지
|
|
135
|
+
* 않게 하려는 것이다. 참여자는 "사람", "AI", "코어" 로만 적는다.
|
|
136
|
+
*/
|
|
137
|
+
export declare function checkSample(value: unknown): string | null;
|
|
138
|
+
/** 예제 파일의 글(바이트)을 풀고 검사한다. 맞으면 { ok: true, sample }, 틀리면 까닭이다. 글자 한도도 본다. */
|
|
139
|
+
export declare function parseSample(data: Uint8Array | string): {
|
|
140
|
+
ok: true;
|
|
141
|
+
sample: SampleFile;
|
|
142
|
+
} | {
|
|
143
|
+
ok: false;
|
|
144
|
+
problem: string;
|
|
145
|
+
};
|
|
146
|
+
/** 설명서 글(바이트)을 푼다. 한도를 넘거나 UTF-8 이 아니면 까닭이다. */
|
|
147
|
+
export declare function parseManual(data: Uint8Array | string): {
|
|
148
|
+
ok: true;
|
|
149
|
+
text: string;
|
|
150
|
+
} | {
|
|
151
|
+
ok: false;
|
|
152
|
+
problem: string;
|
|
153
|
+
};
|
|
154
|
+
/** 이 컴퓨터에 설치된 플러그인의 버전. 없으면 null. */
|
|
155
|
+
export type InstalledVersion = (pkg: string) => string | null;
|
|
156
|
+
/** 예제가 쓴 플러그인 가운데 이 컴퓨터에 설치되지 않은 것(037 5.2절). */
|
|
157
|
+
export declare function missingPlugins(sample: Pick<SampleFile, 'plugins'>, installed: InstalledVersion): string[];
|
|
158
|
+
/** "쓰는 플러그인" 한 줄과, 설치되지 않은 것이 있으면 "이 예제는 X 도 씁니다(설치되지 않음)." 한 줄. */
|
|
159
|
+
export declare function samplePluginLines(sample: Pick<SampleFile, 'plugins'>, installed?: InstalledVersion, self?: string): string[];
|
|
160
|
+
/**
|
|
161
|
+
* 예제를 읽기 좋은 글로 옮긴다(037 5.3절). revision 마다 "사람: (말)", "AI: (한 일의 요약)", "화면 변화" 를 차례로 적는다. 조작
|
|
162
|
+
* 원문과 변경의 내용은 넣지 않는다. 그것은 파일 자체(form: json)에 있다. installed 를 주면 설치되지 않은 플러그인을 알린다.
|
|
163
|
+
*/
|
|
164
|
+
export declare function sampleNarrative(sample: SampleFile, opts?: {
|
|
165
|
+
installed?: InstalledVersion;
|
|
166
|
+
self?: string;
|
|
167
|
+
}): string;
|
package/dist/sample.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// 플러그인 설명서와 예제 파일(037 5절). 예제는 실제 작업의 history 를 `aic export-sample` 로 내보낸 `aic-sample/1` 파일이다.
|
|
2
|
+
// 코어, aic 명령, 등록 사이트가 같은 검사와 같은 읽기 글을 쓰도록 여기 둔다. 플러그인 논리를 부르지 않고 파일의 글만 본다.
|
|
3
|
+
import { isPluginId } from "./manifest.js";
|
|
4
|
+
import { isVersion } from "./version.js";
|
|
5
|
+
export const SAMPLE_FORMAT = 'aic-sample/1';
|
|
6
|
+
/** 설명서 글의 한도(글자, 037 7절 4번). */
|
|
7
|
+
export const MANUAL_MAX_CHARS = 50_000;
|
|
8
|
+
/** 예제 파일 하나의 한도(글자, 037 7절 4번). */
|
|
9
|
+
export const SAMPLE_MAX_CHARS = 200_000;
|
|
10
|
+
/** 예제를 쓴 참여자. 실제 이름 대신 "사람", "AI" 이고, 같은 종류가 여럿이면 "사람 2" 처럼 번호를 붙인다. 참여자가 없는 revision 은 "코어" 다. */
|
|
11
|
+
export const SAMPLE_WHO = /^(사람|AI|코어)( [2-9]| [1-9]\d)?$/;
|
|
12
|
+
/** 글자 수(코드 포인트). manifest 의 길이 한도와 같은 방법으로 잰다. */
|
|
13
|
+
export function charCount(s) {
|
|
14
|
+
let n = 0;
|
|
15
|
+
for (const _ of s)
|
|
16
|
+
n += 1;
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
20
|
+
const isText = (v) => typeof v === 'string';
|
|
21
|
+
const extraKeys = (o, known) => Object.keys(o).filter((k) => !known.includes(k));
|
|
22
|
+
const CAUSE_KEYS = ['humanWords', 'selection', 'choice', 'switch', 'artifact', 'reports', 'instance', 'restore', 'resolves'];
|
|
23
|
+
const REVISION_KEYS = ['revision', 'who', 'kind', 'cause', 'summary', 'operations', 'changes'];
|
|
24
|
+
const TOP_KEYS = ['format', 'title', 'plugins', 'instances', 'revisions', 'generations', 'transmissions'];
|
|
25
|
+
function wordsProblem(where, w) {
|
|
26
|
+
if (!isObject(w) || !isText(w.text) || (w.source !== 'screen' && w.source !== 'relayed_by_ai'))
|
|
27
|
+
return `${where} 는 { text, source: "screen" | "relayed_by_ai" } 여야 한다`;
|
|
28
|
+
const extra = extraKeys(w, ['text', 'source']);
|
|
29
|
+
return extra.length ? `${where} 에 모르는 칸이 있다: ${extra.join(', ')}` : null;
|
|
30
|
+
}
|
|
31
|
+
function causeProblem(where, c) {
|
|
32
|
+
if (!isObject(c))
|
|
33
|
+
return `${where} 는 객체여야 한다`;
|
|
34
|
+
const extra = extraKeys(c, CAUSE_KEYS);
|
|
35
|
+
if (extra.length)
|
|
36
|
+
return `${where} 에 모르는 칸이 있다: ${extra.join(', ')}. 예제는 aic export-sample 로 내보낸 파일이어야 한다`;
|
|
37
|
+
if (c.humanWords !== undefined) {
|
|
38
|
+
if (!Array.isArray(c.humanWords))
|
|
39
|
+
return `${where}.humanWords 는 목록이어야 한다`;
|
|
40
|
+
for (const [i, w] of c.humanWords.entries()) {
|
|
41
|
+
const p = wordsProblem(`${where}.humanWords[${i}]`, w);
|
|
42
|
+
if (p)
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (c.choice !== undefined) {
|
|
47
|
+
const p = wordsProblem(`${where}.choice`, c.choice);
|
|
48
|
+
if (p)
|
|
49
|
+
return p;
|
|
50
|
+
}
|
|
51
|
+
if (c.selection !== undefined && (!isObject(c.selection) || (c.selection.kind !== 'artifact' && c.selection.kind !== 'concept'))) {
|
|
52
|
+
return `${where}.selection 은 kind 가 artifact 나 concept 인 객체여야 한다`;
|
|
53
|
+
}
|
|
54
|
+
if (c.switch !== undefined && (!isObject(c.switch) || !isText(c.switch.from) || !isText(c.switch.to)))
|
|
55
|
+
return `${where}.switch 는 { from, to, mode } 여야 한다`;
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 예제 파일(aic-sample/1)의 검사. 문제의 설명이고 없으면 null 이다. 맨 위 층과 revision 과 원인에 모르는 칸이 있으면 거절한다.
|
|
60
|
+
* 예제는 실제 작업을 내보낸 것이어야 하고(037 7절 2번), 내보낼 때 지운 것(참여자 이름, 도구, 시각, 연결 정의)이 다시 들어가지
|
|
61
|
+
* 않게 하려는 것이다. 참여자는 "사람", "AI", "코어" 로만 적는다.
|
|
62
|
+
*/
|
|
63
|
+
export function checkSample(value) {
|
|
64
|
+
if (!isObject(value))
|
|
65
|
+
return '예제 파일은 JSON 객체여야 한다';
|
|
66
|
+
if (value.format !== SAMPLE_FORMAT)
|
|
67
|
+
return `예제 파일의 format 은 "${SAMPLE_FORMAT}" 이어야 한다. aic export-sample 로 내보낸 파일을 쓴다`;
|
|
68
|
+
const extra = extraKeys(value, TOP_KEYS);
|
|
69
|
+
if (extra.length)
|
|
70
|
+
return `예제 파일에 모르는 칸이 있다: ${extra.join(', ')}`;
|
|
71
|
+
if (!isText(value.title) || value.title.trim() === '' || charCount(value.title) > 200)
|
|
72
|
+
return '예제 파일의 title 은 200자까지의 비어 있지 않은 글이어야 한다';
|
|
73
|
+
if (!Array.isArray(value.plugins) || value.plugins.length === 0 || value.plugins.length > 20)
|
|
74
|
+
return '예제 파일의 plugins 는 플러그인 한 개에서 스무 개의 목록이어야 한다';
|
|
75
|
+
const seen = new Set();
|
|
76
|
+
for (const [i, p] of value.plugins.entries()) {
|
|
77
|
+
if (!isObject(p) || !isPluginId(p.package) || !isVersion(p.version) || (p.title !== undefined && !isText(p.title)))
|
|
78
|
+
return `예제 파일의 plugins[${i}] 는 { package, version, title? } 이고 package 는 플러그인 id, version 은 semver 여야 한다`;
|
|
79
|
+
if (seen.has(p.package))
|
|
80
|
+
return `예제 파일의 plugins 에 ${p.package} 가 둘이다`;
|
|
81
|
+
seen.add(p.package);
|
|
82
|
+
}
|
|
83
|
+
if (!Array.isArray(value.instances))
|
|
84
|
+
return '예제 파일의 instances 는 목록이어야 한다';
|
|
85
|
+
for (const [i, s] of value.instances.entries()) {
|
|
86
|
+
if (!isObject(s) || !isText(s.id) || !isText(s.package))
|
|
87
|
+
return `예제 파일의 instances[${i}] 는 { id, package, title?, connection? } 여야 한다`;
|
|
88
|
+
const more = extraKeys(s, ['id', 'package', 'title', 'connection']);
|
|
89
|
+
if (more.length)
|
|
90
|
+
return `예제 파일의 instances[${i}] 에 모르는 칸이 있다: ${more.join(', ')}`;
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(value.revisions) || value.revisions.length === 0)
|
|
93
|
+
return '예제 파일의 revisions 는 revision 하나 이상의 목록이어야 한다';
|
|
94
|
+
for (const [i, r] of value.revisions.entries()) {
|
|
95
|
+
const where = `revisions[${i}]`;
|
|
96
|
+
if (!isObject(r))
|
|
97
|
+
return `예제 파일의 ${where} 는 객체여야 한다`;
|
|
98
|
+
const more = extraKeys(r, REVISION_KEYS);
|
|
99
|
+
if (more.length)
|
|
100
|
+
return `예제 파일의 ${where} 에 모르는 칸이 있다: ${more.join(', ')}`;
|
|
101
|
+
if (!isText(r.revision) || !isText(r.kind) || !isText(r.summary))
|
|
102
|
+
return `예제 파일의 ${where} 에 revision, kind, summary 글이 있어야 한다`;
|
|
103
|
+
if (!isText(r.who) || !SAMPLE_WHO.test(r.who))
|
|
104
|
+
return `예제 파일의 ${where}.who 는 "사람", "AI", "코어" 가운데 하나(같은 종류가 여럿이면 "사람 2" 처럼 번호)여야 한다. 참여자의 실제 이름은 넣지 않는다`;
|
|
105
|
+
if (r.cause !== undefined) {
|
|
106
|
+
const p = causeProblem(`예제 파일의 ${where}.cause`, r.cause);
|
|
107
|
+
if (p)
|
|
108
|
+
return p;
|
|
109
|
+
}
|
|
110
|
+
if (r.operations !== undefined && (!Array.isArray(r.operations) || r.operations.some((o) => !isObject(o) || !isText(o.op))))
|
|
111
|
+
return `예제 파일의 ${where}.operations 는 { op, as?, input? } 의 목록이어야 한다`;
|
|
112
|
+
if (!Array.isArray(r.changes) || r.changes.some((c) => !isObject(c) || !isText(c.record) || !isText(c.type)))
|
|
113
|
+
return `예제 파일의 ${where}.changes 는 { record, type, owner, before, after } 의 목록이어야 한다`;
|
|
114
|
+
}
|
|
115
|
+
if (value.generations !== undefined) {
|
|
116
|
+
if (!Array.isArray(value.generations))
|
|
117
|
+
return '예제 파일의 generations 는 목록이어야 한다';
|
|
118
|
+
const texts = (v) => Array.isArray(v) && v.every(isText);
|
|
119
|
+
for (const [i, g] of value.generations.entries()) {
|
|
120
|
+
const where = `예제 파일의 generations[${i}]`;
|
|
121
|
+
if (!isObject(g) || !isText(g.artifact) || !isText(g.who) || !isText(g.medium) || !isText(g.after) || !texts(g.sections))
|
|
122
|
+
return `${where} 는 { artifact, who, medium, instance?, scope?, sections, missing?, after } 여야 한다`;
|
|
123
|
+
if (!SAMPLE_WHO.test(g.who))
|
|
124
|
+
return `${where}.who 는 "사람", "AI", "코어" 가운데 하나(같은 종류가 여럿이면 번호)여야 한다`;
|
|
125
|
+
if ((g.instance !== undefined && !isText(g.instance)) || (g.scope !== undefined && !texts(g.scope)) || (g.missing !== undefined && !texts(g.missing)))
|
|
126
|
+
return `${where} 의 instance, scope, missing 모양이 맞지 않는다`;
|
|
127
|
+
const more = extraKeys(g, ['artifact', 'who', 'medium', 'instance', 'scope', 'sections', 'missing', 'after']);
|
|
128
|
+
if (more.length)
|
|
129
|
+
return `${where} 에 모르는 칸이 있다: ${more.join(', ')}. 결과물 본문과 재료 글은 넣지 않는다`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (value.transmissions !== undefined) {
|
|
133
|
+
if (!Array.isArray(value.transmissions))
|
|
134
|
+
return '예제 파일의 transmissions 는 목록이어야 한다';
|
|
135
|
+
for (const [i, t] of value.transmissions.entries()) {
|
|
136
|
+
if (!isObject(t) || !isText(t.instance) || (t.kind !== 'send' && t.kind !== 'update') || !isText(t.status))
|
|
137
|
+
return `예제 파일의 transmissions[${i}] 는 { instance, kind, status, label? } 여야 한다`;
|
|
138
|
+
const more = extraKeys(t, ['instance', 'kind', 'status', 'label']);
|
|
139
|
+
if (more.length)
|
|
140
|
+
return `예제 파일의 transmissions[${i}] 에 모르는 칸이 있다: ${more.join(', ')}. 실행 기록은 요약만 넣는다`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
/** 예제 파일의 글(바이트)을 풀고 검사한다. 맞으면 { ok: true, sample }, 틀리면 까닭이다. 글자 한도도 본다. */
|
|
146
|
+
export function parseSample(data) {
|
|
147
|
+
let text;
|
|
148
|
+
try {
|
|
149
|
+
text = typeof data === 'string' ? data : new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return { ok: false, problem: '예제 파일이 UTF-8 글이 아니다' };
|
|
153
|
+
}
|
|
154
|
+
const n = charCount(text);
|
|
155
|
+
if (n > SAMPLE_MAX_CHARS)
|
|
156
|
+
return { ok: false, problem: `예제 파일이 ${SAMPLE_MAX_CHARS.toLocaleString('en-US')}자를 넘는다(${n.toLocaleString('en-US')}자)` };
|
|
157
|
+
let value;
|
|
158
|
+
try {
|
|
159
|
+
value = JSON.parse(text.replace(/^/, ''));
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
return { ok: false, problem: `예제 파일이 JSON 이 아니다(${e.message})` };
|
|
163
|
+
}
|
|
164
|
+
const problem = checkSample(value);
|
|
165
|
+
return problem ? { ok: false, problem } : { ok: true, sample: value };
|
|
166
|
+
}
|
|
167
|
+
/** 설명서 글(바이트)을 푼다. 한도를 넘거나 UTF-8 이 아니면 까닭이다. */
|
|
168
|
+
export function parseManual(data) {
|
|
169
|
+
let text;
|
|
170
|
+
try {
|
|
171
|
+
text = typeof data === 'string' ? data : new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return { ok: false, problem: '설명서가 UTF-8 글이 아니다' };
|
|
175
|
+
}
|
|
176
|
+
text = text.replace(/^/, '');
|
|
177
|
+
const n = charCount(text);
|
|
178
|
+
if (n > MANUAL_MAX_CHARS)
|
|
179
|
+
return { ok: false, problem: `설명서가 ${MANUAL_MAX_CHARS.toLocaleString('en-US')}자를 넘는다(${n.toLocaleString('en-US')}자)` };
|
|
180
|
+
return { ok: true, text };
|
|
181
|
+
}
|
|
182
|
+
/** 쓴 플러그인 하나의 글. 설치되지 않았거나 낮은 버전이면 괄호로 붙인다. */
|
|
183
|
+
function pluginWord(p, installed) {
|
|
184
|
+
const base = `${p.package} ${p.version}`;
|
|
185
|
+
if (!installed)
|
|
186
|
+
return base;
|
|
187
|
+
const have = installed(p.package);
|
|
188
|
+
if (have === null)
|
|
189
|
+
return `${base}(설치되지 않음)`;
|
|
190
|
+
return have === p.version ? base : `${base}(이 컴퓨터에는 ${have})`;
|
|
191
|
+
}
|
|
192
|
+
/** 예제가 쓴 플러그인 가운데 이 컴퓨터에 설치되지 않은 것(037 5.2절). */
|
|
193
|
+
export function missingPlugins(sample, installed) {
|
|
194
|
+
return sample.plugins.filter((p) => installed(p.package) === null).map((p) => p.package);
|
|
195
|
+
}
|
|
196
|
+
/** "쓰는 플러그인" 한 줄과, 설치되지 않은 것이 있으면 "이 예제는 X 도 씁니다(설치되지 않음)." 한 줄. */
|
|
197
|
+
export function samplePluginLines(sample, installed, self) {
|
|
198
|
+
const lines = [`쓰는 플러그인: ${sample.plugins.map((p) => pluginWord(p, installed)).join(', ')}`];
|
|
199
|
+
if (installed) {
|
|
200
|
+
const missing = missingPlugins(sample, installed).filter((p) => p !== self);
|
|
201
|
+
if (missing.length)
|
|
202
|
+
lines.push(`이 예제는 ${missing.join(', ')} 도 씁니다(설치되지 않음).`);
|
|
203
|
+
}
|
|
204
|
+
return lines;
|
|
205
|
+
}
|
|
206
|
+
/** 화면 변화 줄에 적는 변경 수. 나머지는 수만 적는다. */
|
|
207
|
+
const CHANGES_SHOWN = 12;
|
|
208
|
+
/** 읽기 글의 요약 한 줄의 한도(글자). 전체는 파일의 summary 에 있다. */
|
|
209
|
+
const SUMMARY_SHOWN = 500;
|
|
210
|
+
function clip(s, max) {
|
|
211
|
+
const all = [...s];
|
|
212
|
+
return all.length <= max ? s : `${all.slice(0, max).join('')} ...`;
|
|
213
|
+
}
|
|
214
|
+
const indentLines = (s, pad) => s.replace(/\r?\n/g, `\n${pad}`);
|
|
215
|
+
function changeWord(c) {
|
|
216
|
+
const action = c.before === null || c.before === undefined ? '더함' : c.after === null || c.after === undefined ? '지움' : '고침';
|
|
217
|
+
return `${c.record} ${c.type} ${action}`;
|
|
218
|
+
}
|
|
219
|
+
/** 사람의 말과 선택을 "사람: ..." 줄로. 말한 사람은 revision 을 만든 참여자가 아니라 사람이다. */
|
|
220
|
+
function causeLines(c, who) {
|
|
221
|
+
if (!c)
|
|
222
|
+
return [];
|
|
223
|
+
const person = who.startsWith('사람') ? who : '사람';
|
|
224
|
+
const out = [];
|
|
225
|
+
for (const w of c.humanWords ?? [])
|
|
226
|
+
out.push(`${person}${w.source === 'relayed_by_ai' ? '(AI 가 옮겨 적음)' : ''}: "${w.text}"`);
|
|
227
|
+
const s = c.selection;
|
|
228
|
+
if (s) {
|
|
229
|
+
const said = s.said ? `: "${s.said}"` : '';
|
|
230
|
+
if (s.kind === 'artifact')
|
|
231
|
+
out.push(`${person}: 결과물${s.artifact ? ` ${s.artifact}` : ''} 에서 "${clip(s.text ?? '', 200)}" 를 고름${said}`);
|
|
232
|
+
else
|
|
233
|
+
out.push(`${person}: 화면${s.instance ? ` ${s.instance}` : ''} 에서 ${s.records?.length ? s.records.join(', ') : '한 곳'} 을 ${s.role === 'reference' ? '참고로 ' : ''}가리킴${said}`);
|
|
234
|
+
}
|
|
235
|
+
if (c.choice)
|
|
236
|
+
out.push(`${person}(답): "${c.choice.text}"`);
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
/** 생성 한 줄. 본문은 예제에 없으므로 범위와 구간 이름만 적는다. */
|
|
240
|
+
function generationLine(g, withBasis) {
|
|
241
|
+
const scope = g.scope?.length ? `범위 ${g.scope.join(', ')}` : '범위 전체';
|
|
242
|
+
const sections = g.sections.length ? `구간 ${clip(g.sections.join(', '), 300)}` : '구간 없음';
|
|
243
|
+
const missing = g.missing?.length ? `, 본문 없는 구간 ${g.missing.join(', ')}` : '';
|
|
244
|
+
return `${g.who}: ${withBasis ? `${g.after} 까지의 상태로 ` : '이 상태로 '}결과물 ${g.artifact}(${g.medium}) 을 만듦(${g.instance ? `화면 ${g.instance}, ` : ''}${scope}, ${sections}${missing})`;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* 예제를 읽기 좋은 글로 옮긴다(037 5.3절). revision 마다 "사람: (말)", "AI: (한 일의 요약)", "화면 변화" 를 차례로 적는다. 조작
|
|
248
|
+
* 원문과 변경의 내용은 넣지 않는다. 그것은 파일 자체(form: json)에 있다. installed 를 주면 설치되지 않은 플러그인을 알린다.
|
|
249
|
+
*/
|
|
250
|
+
export function sampleNarrative(sample, opts = {}) {
|
|
251
|
+
const lines = [`예제 작업: ${sample.title}`, ...samplePluginLines(sample, opts.installed, opts.self)];
|
|
252
|
+
if (sample.instances.length) {
|
|
253
|
+
const screens = sample.instances.map((i) => `${i.id} ${i.title ?? i.package}(${i.connection !== undefined ? `외부 연결 ${i.connection}` : i.package})`);
|
|
254
|
+
lines.push(`화면: ${screens.join(', ')}`);
|
|
255
|
+
}
|
|
256
|
+
lines.push('');
|
|
257
|
+
// 생성은 revision 이 아니므로 그 상태(after)의 revision 아래에 적는다. 그 revision 이 예제에 없으면 끝에 모은다.
|
|
258
|
+
const known = new Set(sample.revisions.map((r) => r.revision));
|
|
259
|
+
const made = new Map();
|
|
260
|
+
for (const g of sample.generations ?? [])
|
|
261
|
+
made.set(known.has(g.after) ? g.after : '', [...(made.get(known.has(g.after) ? g.after : '') ?? []), g]);
|
|
262
|
+
sample.revisions.forEach((r, i) => {
|
|
263
|
+
const head = `${i + 1}. (${r.revision}) `;
|
|
264
|
+
const pad = ' '.repeat(head.length);
|
|
265
|
+
const body = [...causeLines(r.cause, r.who), `${r.who}: ${indentLines(clip(r.summary, SUMMARY_SHOWN), pad)}`];
|
|
266
|
+
if (r.changes.length) {
|
|
267
|
+
const shown = r.changes.slice(0, CHANGES_SHOWN).map(changeWord);
|
|
268
|
+
body.push(`화면 변화: ${shown.join(', ')}${r.changes.length > shown.length ? ` 외 ${r.changes.length - shown.length}개` : ''}`);
|
|
269
|
+
}
|
|
270
|
+
for (const g of made.get(r.revision) ?? [])
|
|
271
|
+
body.push(generationLine(g, false));
|
|
272
|
+
lines.push(`${head}${body[0]}`, ...body.slice(1).map((b) => `${pad}${b}`));
|
|
273
|
+
});
|
|
274
|
+
const loose = made.get('') ?? [];
|
|
275
|
+
if (loose.length) {
|
|
276
|
+
lines.push('', '만든 결과물');
|
|
277
|
+
for (const g of loose)
|
|
278
|
+
lines.push(`- ${generationLine(g, true)}`);
|
|
279
|
+
}
|
|
280
|
+
if (sample.transmissions?.length) {
|
|
281
|
+
lines.push('', '외부 연결의 실행(요약)');
|
|
282
|
+
for (const t of sample.transmissions)
|
|
283
|
+
lines.push(`- ${t.instance} ${t.kind === 'send' ? '보내기' : '갱신'} ${t.status}${t.label ? `(${t.label})` : ''}`);
|
|
284
|
+
}
|
|
285
|
+
return lines.join('\n');
|
|
286
|
+
}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 상태의 항목 하나. sha256 은 묶음 파일 전체의 sha256(16진 소문자)이다. */
|
|
2
|
+
export interface StateEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
version: string;
|
|
5
|
+
sha256: string;
|
|
6
|
+
}
|
|
7
|
+
/** 상태 하나의 항목 수 한도(036 14.2절). */
|
|
8
|
+
export declare const STATE_MAX_PLUGINS = 200;
|
|
9
|
+
export declare function isStateId(s: unknown): s is string;
|
|
10
|
+
/** 상태 목록의 모양 검사. 문제의 설명이고 없으면 null 이다. 같은 id 가 둘이면 받지 않는다. 한 id 는 한 버전만 설치되기 때문이다. */
|
|
11
|
+
export declare function checkState(plugins: unknown): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* 상태 id 를 내는 글(API.md 4절). id 의 글자 순서(UTF-16 코드 단위)로 늘어놓고, 항목마다 id, version, sha256 순서의 칸만 적어
|
|
14
|
+
* {"plugins":[...]} 를 빈칸 없이 JSON 으로 적는다. 모양이 틀리면 던진다.
|
|
15
|
+
*/
|
|
16
|
+
export declare function canonicalState(plugins: readonly StateEntry[]): string;
|
|
17
|
+
/** 상태 id. canonicalState 의 글을 UTF-8 로 바꾼 sha256(16진 소문자)의 앞 16자다. */
|
|
18
|
+
export declare function stateId(plugins: readonly StateEntry[]): string;
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// 플러그인 구성의 상태와 상태 id(036 14절). 같은 구성이면 누가 어느 컴퓨터에서 내도 같은 id 가 나온다.
|
|
2
|
+
import { sha256Hex } from "./bundle.js";
|
|
3
|
+
import { isPluginId } from "./manifest.js";
|
|
4
|
+
import { isVersion } from "./version.js";
|
|
5
|
+
/** 상태 하나의 항목 수 한도(036 14.2절). */
|
|
6
|
+
export const STATE_MAX_PLUGINS = 200;
|
|
7
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
8
|
+
const STATE_ID = /^[0-9a-f]{16}$/;
|
|
9
|
+
export function isStateId(s) {
|
|
10
|
+
return typeof s === 'string' && STATE_ID.test(s);
|
|
11
|
+
}
|
|
12
|
+
/** 상태 목록의 모양 검사. 문제의 설명이고 없으면 null 이다. 같은 id 가 둘이면 받지 않는다. 한 id 는 한 버전만 설치되기 때문이다. */
|
|
13
|
+
export function checkState(plugins) {
|
|
14
|
+
if (!Array.isArray(plugins))
|
|
15
|
+
return 'plugins 는 { id, version, sha256 } 의 목록이어야 한다';
|
|
16
|
+
if (plugins.length > STATE_MAX_PLUGINS)
|
|
17
|
+
return `plugins 는 ${STATE_MAX_PLUGINS}개까지다(${plugins.length}개)`;
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
for (const [i, e] of plugins.entries()) {
|
|
20
|
+
if (typeof e !== 'object' || e === null || Array.isArray(e))
|
|
21
|
+
return `plugins[${i}] 는 객체여야 한다`;
|
|
22
|
+
const { id, version, sha256 } = e;
|
|
23
|
+
if (!isPluginId(id))
|
|
24
|
+
return `plugins[${i}].id 가 플러그인 id 모양이 아니다`;
|
|
25
|
+
if (!isVersion(version))
|
|
26
|
+
return `plugins[${i}].version 이 semver 가 아니다`;
|
|
27
|
+
if (typeof sha256 !== 'string' || !SHA256.test(sha256))
|
|
28
|
+
return `plugins[${i}].sha256 은 16진 소문자 64자여야 한다`;
|
|
29
|
+
if (seen.has(id))
|
|
30
|
+
return `plugins 에 같은 id ${id} 가 둘이다`;
|
|
31
|
+
seen.add(id);
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 상태 id 를 내는 글(API.md 4절). id 의 글자 순서(UTF-16 코드 단위)로 늘어놓고, 항목마다 id, version, sha256 순서의 칸만 적어
|
|
37
|
+
* {"plugins":[...]} 를 빈칸 없이 JSON 으로 적는다. 모양이 틀리면 던진다.
|
|
38
|
+
*/
|
|
39
|
+
export function canonicalState(plugins) {
|
|
40
|
+
const problem = checkState(plugins);
|
|
41
|
+
if (problem)
|
|
42
|
+
throw new Error(problem);
|
|
43
|
+
const sorted = [...plugins].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
44
|
+
return JSON.stringify({ plugins: sorted.map((p) => ({ id: p.id, version: p.version, sha256: p.sha256 })) });
|
|
45
|
+
}
|
|
46
|
+
/** 상태 id. canonicalState 의 글을 UTF-8 로 바꾼 sha256(16진 소문자)의 앞 16자다. */
|
|
47
|
+
export function stateId(plugins) {
|
|
48
|
+
return sha256Hex(Buffer.from(canonicalState(plugins), 'utf8')).slice(0, 16);
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** 코어의 플러그인 계약 버전(036 12절 7번). 호환되지 않게 계약을 바꿀 때 코어를 맡은 세션이 올리고 999 에 적는다. */
|
|
2
|
+
export declare const PROTOCOL_VERSION = "0.1";
|
|
3
|
+
/** semver 인가(`숫자.숫자.숫자`, 뒤에 `-미리보기이름` 가능). 빌드 꼬리(`+...`)는 받지 않는다. 64자까지. */
|
|
4
|
+
export declare function isVersion(v: unknown): v is string;
|
|
5
|
+
/**
|
|
6
|
+
* semver 로 견준다(033 4.3절). 숫자 셋을 차례로 견주고, 같으면 꼬리표(-beta.1)가 없는 쪽이 높다.
|
|
7
|
+
* 꼬리표끼리는 점으로 나눈 조각마다 숫자는 숫자로, 글자는 글자로 견준다. 모양이 틀린 글도 던지지 않고 견준다.
|
|
8
|
+
*/
|
|
9
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
10
|
+
/** 미리보기 버전인가(`-이름` 이 붙은 것). */
|
|
11
|
+
export declare function isPrerelease(v: string): boolean;
|
|
12
|
+
/** 받는 버전 범위인가. `1.2.3`(바로 그 버전), `^1.2.3`, `~1.2.3`, `>=1.2.3` 네 가지뿐이다(036 4절). */
|
|
13
|
+
export declare function isRange(range: unknown): range is string;
|
|
14
|
+
/**
|
|
15
|
+
* version 이 range 에 드는가. 뜻은 npm 과 같다. `^1.2.3` 은 2.0.0 아래, `^0.2.3` 은 0.3.0 아래, `^0.0.3` 은 0.0.4 아래,
|
|
16
|
+
* `~1.2.3` 은 1.3.0 아래까지다. 미리보기 버전은 범위의 버전이 같은 숫자 셋의 미리보기일 때만 든다. 모양이 틀리면 false 다.
|
|
17
|
+
*/
|
|
18
|
+
export declare function satisfies(version: string, range: string): boolean;
|
|
19
|
+
/** manifest 의 `protocol` 칸으로 받는 모양인가. 계약이 실험 버전인 동안은 `0.<숫자>` 한 가지다(036 4절). */
|
|
20
|
+
export declare function isProtocolRange(range: unknown): range is string;
|
|
21
|
+
/**
|
|
22
|
+
* `protocol` 범위가 코어의 계약 버전을 받는가. 0 으로 시작하는 버전에서는 가운데 숫자가 바뀌면 호환되지 않으므로 둘이 같아야 한다.
|
|
23
|
+
* 1 이상이면 앞 숫자가 같고 코어의 가운데 숫자가 범위의 것 이상이어야 한다.
|
|
24
|
+
*/
|
|
25
|
+
export declare function protocolAccepts(range: string, coreProtocol?: string): boolean;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// 버전과 버전 범위(036 4절). 코어와 aic 명령과 등록 사이트가 같은 계산을 하도록 여기 한 곳에 둔다.
|
|
2
|
+
/** 코어의 플러그인 계약 버전(036 12절 7번). 호환되지 않게 계약을 바꿀 때 코어를 맡은 세션이 올리고 999 에 적는다. */
|
|
3
|
+
export const PROTOCOL_VERSION = '0.1';
|
|
4
|
+
const VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
5
|
+
const RANGE = /^(\^|~|>=)?(.+)$/;
|
|
6
|
+
const PROTOCOL = /^(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
7
|
+
/** semver 인가(`숫자.숫자.숫자`, 뒤에 `-미리보기이름` 가능). 빌드 꼬리(`+...`)는 받지 않는다. 64자까지. */
|
|
8
|
+
export function isVersion(v) {
|
|
9
|
+
return typeof v === 'string' && v.length <= 64 && VERSION.test(v);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* semver 로 견준다(033 4.3절). 숫자 셋을 차례로 견주고, 같으면 꼬리표(-beta.1)가 없는 쪽이 높다.
|
|
13
|
+
* 꼬리표끼리는 점으로 나눈 조각마다 숫자는 숫자로, 글자는 글자로 견준다. 모양이 틀린 글도 던지지 않고 견준다.
|
|
14
|
+
*/
|
|
15
|
+
export function compareVersions(a, b) {
|
|
16
|
+
const split = (v) => {
|
|
17
|
+
const [core, ...rest] = v.split('+')[0].split('-');
|
|
18
|
+
return { nums: core.split('.').map((x) => Number(x) || 0), pre: rest.join('-') };
|
|
19
|
+
};
|
|
20
|
+
const x = split(a);
|
|
21
|
+
const y = split(b);
|
|
22
|
+
for (let i = 0; i < Math.max(x.nums.length, y.nums.length, 3); i += 1) {
|
|
23
|
+
const d = (x.nums[i] ?? 0) - (y.nums[i] ?? 0);
|
|
24
|
+
if (d !== 0)
|
|
25
|
+
return d < 0 ? -1 : 1;
|
|
26
|
+
}
|
|
27
|
+
if (x.pre === y.pre)
|
|
28
|
+
return 0;
|
|
29
|
+
if (x.pre === '')
|
|
30
|
+
return 1;
|
|
31
|
+
if (y.pre === '')
|
|
32
|
+
return -1;
|
|
33
|
+
const xs = x.pre.split('.');
|
|
34
|
+
const ys = y.pre.split('.');
|
|
35
|
+
for (let i = 0; i < Math.max(xs.length, ys.length); i += 1) {
|
|
36
|
+
if (xs[i] === undefined)
|
|
37
|
+
return -1;
|
|
38
|
+
if (ys[i] === undefined)
|
|
39
|
+
return 1;
|
|
40
|
+
const nx = /^\d+$/.test(xs[i]) ? Number(xs[i]) : null;
|
|
41
|
+
const ny = /^\d+$/.test(ys[i]) ? Number(ys[i]) : null;
|
|
42
|
+
if (nx !== null && ny !== null) {
|
|
43
|
+
if (nx !== ny)
|
|
44
|
+
return nx < ny ? -1 : 1;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (nx !== null)
|
|
48
|
+
return -1;
|
|
49
|
+
if (ny !== null)
|
|
50
|
+
return 1;
|
|
51
|
+
if (xs[i] !== ys[i])
|
|
52
|
+
return xs[i] < ys[i] ? -1 : 1;
|
|
53
|
+
}
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
/** 미리보기 버전인가(`-이름` 이 붙은 것). */
|
|
57
|
+
export function isPrerelease(v) {
|
|
58
|
+
return isVersion(v) && v.includes('-');
|
|
59
|
+
}
|
|
60
|
+
function parseRange(range) {
|
|
61
|
+
if (typeof range !== 'string')
|
|
62
|
+
return null;
|
|
63
|
+
const m = RANGE.exec(range);
|
|
64
|
+
if (!m || !isVersion(m[2]))
|
|
65
|
+
return null;
|
|
66
|
+
const nums = m[2].split('-')[0].split('.').map(Number);
|
|
67
|
+
return { op: (m[1] ?? ''), base: m[2], nums };
|
|
68
|
+
}
|
|
69
|
+
/** 받는 버전 범위인가. `1.2.3`(바로 그 버전), `^1.2.3`, `~1.2.3`, `>=1.2.3` 네 가지뿐이다(036 4절). */
|
|
70
|
+
export function isRange(range) {
|
|
71
|
+
return parseRange(range) !== null;
|
|
72
|
+
}
|
|
73
|
+
function coreLess(v, upper) {
|
|
74
|
+
const n = v.split('-')[0].split('.').map(Number);
|
|
75
|
+
for (let i = 0; i < 3; i += 1)
|
|
76
|
+
if (n[i] !== upper[i])
|
|
77
|
+
return n[i] < upper[i];
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* version 이 range 에 드는가. 뜻은 npm 과 같다. `^1.2.3` 은 2.0.0 아래, `^0.2.3` 은 0.3.0 아래, `^0.0.3` 은 0.0.4 아래,
|
|
82
|
+
* `~1.2.3` 은 1.3.0 아래까지다. 미리보기 버전은 범위의 버전이 같은 숫자 셋의 미리보기일 때만 든다. 모양이 틀리면 false 다.
|
|
83
|
+
*/
|
|
84
|
+
export function satisfies(version, range) {
|
|
85
|
+
const r = parseRange(range);
|
|
86
|
+
if (!r || !isVersion(version))
|
|
87
|
+
return false;
|
|
88
|
+
if (isPrerelease(version)) {
|
|
89
|
+
const same = version.split('-')[0] === r.base.split('-')[0];
|
|
90
|
+
if (!same || !isPrerelease(r.base))
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const cmp = compareVersions(version, r.base);
|
|
94
|
+
if (r.op === '')
|
|
95
|
+
return cmp === 0;
|
|
96
|
+
if (cmp < 0)
|
|
97
|
+
return false;
|
|
98
|
+
if (r.op === '>=')
|
|
99
|
+
return true;
|
|
100
|
+
const [ma, mi, pa] = r.nums;
|
|
101
|
+
const upper = r.op === '~' ? [ma, mi + 1, 0] : ma > 0 ? [ma + 1, 0, 0] : mi > 0 ? [0, mi + 1, 0] : [0, 0, pa + 1];
|
|
102
|
+
return coreLess(version, upper);
|
|
103
|
+
}
|
|
104
|
+
/** manifest 의 `protocol` 칸으로 받는 모양인가. 계약이 실험 버전인 동안은 `0.<숫자>` 한 가지다(036 4절). */
|
|
105
|
+
export function isProtocolRange(range) {
|
|
106
|
+
return typeof range === 'string' && PROTOCOL.test(range) && range.startsWith('0.');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `protocol` 범위가 코어의 계약 버전을 받는가. 0 으로 시작하는 버전에서는 가운데 숫자가 바뀌면 호환되지 않으므로 둘이 같아야 한다.
|
|
110
|
+
* 1 이상이면 앞 숫자가 같고 코어의 가운데 숫자가 범위의 것 이상이어야 한다.
|
|
111
|
+
*/
|
|
112
|
+
export function protocolAccepts(range, coreProtocol = PROTOCOL_VERSION) {
|
|
113
|
+
const r = PROTOCOL.exec(range);
|
|
114
|
+
const c = PROTOCOL.exec(coreProtocol);
|
|
115
|
+
if (!r || !c)
|
|
116
|
+
return false;
|
|
117
|
+
const [rMajor, rMinor, cMajor, cMinor] = [r[1], r[2], c[1], c[2]].map(Number);
|
|
118
|
+
if (rMajor !== cMajor)
|
|
119
|
+
return false;
|
|
120
|
+
return rMajor === 0 ? rMinor === cMinor : cMinor >= rMinor;
|
|
121
|
+
}
|