@artkit-ai/core 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/dist/adapter.d.ts +119 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +45 -0
- package/dist/adapter.js.map +1 -0
- package/dist/diff.d.ts +1 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/engine.d.ts +29 -23
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +148 -197
- package/dist/engine.js.map +1 -1
- package/dist/envelope.d.ts +10 -27
- package/dist/envelope.d.ts.map +1 -1
- package/dist/envelope.js +8 -20
- package/dist/envelope.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -4
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +2 -10
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/i18n.d.ts +8 -14
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +12 -18
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/memory.d.ts +0 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +15 -109
- package/dist/memory.js.map +1 -1
- package/dist/migrations.d.ts +6 -5
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +20 -14
- package/dist/migrations.js.map +1 -1
- package/dist/projection.d.ts +22 -6
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +5 -5
- package/dist/projection.js.map +1 -1
- package/dist/registry.d.ts +17 -16
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +25 -25
- package/dist/registry.js.map +1 -1
- package/dist/service.d.ts +19 -51
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +119 -404
- package/dist/service.js.map +1 -1
- package/dist/store.d.ts +12 -61
- package/dist/store.d.ts.map +1 -1
- package/dist/testing/index.d.ts +10 -9
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +75 -136
- package/dist/testing/index.js.map +1 -1
- package/dist/theme.js +1 -1
- package/dist/ui.d.ts +18 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +5 -3
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter.ts +180 -0
- package/src/diff.ts +1 -1
- package/src/engine.ts +183 -230
- package/src/envelope.ts +11 -29
- package/src/errors.ts +4 -4
- package/src/events.ts +2 -11
- package/src/i18n.ts +14 -20
- package/src/index.ts +2 -4
- package/src/logger.ts +1 -2
- package/src/memory.ts +16 -122
- package/src/migrations.ts +24 -18
- package/src/projection.ts +25 -7
- package/src/registry.ts +45 -41
- package/src/service.ts +144 -540
- package/src/store.ts +12 -64
- package/src/testing/index.ts +89 -164
- package/src/theme.ts +1 -1
- package/src/ui.ts +24 -4
- package/dist/kind.d.ts +0 -156
- package/dist/kind.d.ts.map +0 -1
- package/dist/kind.js +0 -52
- package/dist/kind.js.map +0 -1
- package/src/kind.ts +0 -217
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ErrorIssue } from './errors.js';
|
|
3
|
+
import type { Theme } from './theme.js';
|
|
4
|
+
/** Contract every native format implements (spec §8). Adapters own all knowledge about their format. */
|
|
5
|
+
export interface FormatAdapter<Content = unknown, Operation = unknown> {
|
|
6
|
+
/** Format name stored in the envelope: `markdown`, `univer-sheet`, `openui`. */
|
|
7
|
+
format: string;
|
|
8
|
+
/** Version of the native format or third-party library the content is written with (e.g. `univer-sheet@0.x`). */
|
|
9
|
+
formatVersion: string;
|
|
10
|
+
/** Format versions this adapter can read; `formatVersion` is the one it writes. */
|
|
11
|
+
readableVersions: string[];
|
|
12
|
+
label: string;
|
|
13
|
+
/** Smallest valid content, used when an artifact is created from operations only. */
|
|
14
|
+
empty(): Content;
|
|
15
|
+
/** Validates content (already parsed from the store or from the model). Throws nothing; reports issues. */
|
|
16
|
+
validate(content: unknown, ctx: AdapterContext): ValidationResult<Content>;
|
|
17
|
+
operationSchema: z.ZodType<Operation>;
|
|
18
|
+
/**
|
|
19
|
+
* Applies a run of content operations on a draft. The draft is a private copy; mutations are kept only when the
|
|
20
|
+
* whole batch succeeds. Must not read the clock, the network or randomness.
|
|
21
|
+
*/
|
|
22
|
+
apply(content: Content, operations: Operation[], ctx: AdapterContext): Promise<ApplyResult<Content>>;
|
|
23
|
+
/** Compact reading for the model (outline, section, range, full), with budget and cursor. */
|
|
24
|
+
read(content: Content, request: ReadRequest): ReadResult;
|
|
25
|
+
diff(before: Content, after: Content, locale?: string): ChangeSummary[];
|
|
26
|
+
lint(content: Content, ctx: LintContext): LintIssue[];
|
|
27
|
+
/** Best-effort preview while the model streams; drops incomplete trailing items. Returns undefined when unusable. */
|
|
28
|
+
parsePartial(raw: string): Content | undefined;
|
|
29
|
+
migrations: FormatMigration[];
|
|
30
|
+
/** Counters checked against `limits` (same keys as `measure`). */
|
|
31
|
+
limits: FormatLimits;
|
|
32
|
+
measure?(content: Content): Record<string, number>;
|
|
33
|
+
instructions: FormatInstructions;
|
|
34
|
+
}
|
|
35
|
+
export interface AdapterContext {
|
|
36
|
+
locale: string;
|
|
37
|
+
theme: Theme;
|
|
38
|
+
/** Fails the batch with `OPERATION_FAILED`; the message and hint are written for the model to fix the call. */
|
|
39
|
+
fail(message: string, options?: {
|
|
40
|
+
hint?: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
}): never;
|
|
43
|
+
}
|
|
44
|
+
export type ValidationResult<Content> = {
|
|
45
|
+
ok: true;
|
|
46
|
+
content: Content;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
issues: ErrorIssue[];
|
|
50
|
+
};
|
|
51
|
+
export interface ApplyResult<Content> {
|
|
52
|
+
content: Content;
|
|
53
|
+
/** Anchors, declarations, ranges or sheets created by the batch (e.g. `escopo`, `kpi1`, `Resumo!A1:D3`). */
|
|
54
|
+
createdRefs: string[];
|
|
55
|
+
warnings: LintIssue[];
|
|
56
|
+
}
|
|
57
|
+
export type ReadMode = 'outline' | 'section' | 'statements' | 'range' | 'full';
|
|
58
|
+
export interface ReadRequest {
|
|
59
|
+
mode: ReadMode;
|
|
60
|
+
/** Format-specific selection: anchors, A1 range, declaration names. */
|
|
61
|
+
range?: string;
|
|
62
|
+
/** Token budget; text is cut at an item boundary and a cursor is returned. */
|
|
63
|
+
maxTokens?: number;
|
|
64
|
+
cursor?: string;
|
|
65
|
+
locale: string;
|
|
66
|
+
charsPerToken?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface ReadResult {
|
|
69
|
+
text: string;
|
|
70
|
+
truncated: boolean;
|
|
71
|
+
/** Present when truncated: pass it back to continue reading. */
|
|
72
|
+
cursor?: string;
|
|
73
|
+
}
|
|
74
|
+
export type LintSeverity = 'warning' | 'info';
|
|
75
|
+
export interface LintIssue {
|
|
76
|
+
code: string;
|
|
77
|
+
severity: LintSeverity;
|
|
78
|
+
/** `section:cronograma`, `cell:Resumo!D14`, `slide:cronograma`, `node:api`… */
|
|
79
|
+
target: string;
|
|
80
|
+
message: string;
|
|
81
|
+
hint?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface LintContext {
|
|
84
|
+
locale: string;
|
|
85
|
+
theme: Theme;
|
|
86
|
+
}
|
|
87
|
+
export type ChangeType = 'added' | 'removed' | 'changed' | 'moved';
|
|
88
|
+
export interface ChangeSummary {
|
|
89
|
+
type: ChangeType;
|
|
90
|
+
/** Same vocabulary as lint targets; the core compares these to detect rebase conflicts. */
|
|
91
|
+
target: string;
|
|
92
|
+
summary: string;
|
|
93
|
+
}
|
|
94
|
+
export interface FormatMigration {
|
|
95
|
+
from: string;
|
|
96
|
+
to: string;
|
|
97
|
+
migrate(content: unknown): unknown;
|
|
98
|
+
}
|
|
99
|
+
export type FormatLimits = Record<string, number>;
|
|
100
|
+
export interface FormatExample {
|
|
101
|
+
title: string;
|
|
102
|
+
operations?: unknown[];
|
|
103
|
+
content?: unknown;
|
|
104
|
+
}
|
|
105
|
+
export interface FormatInstructions {
|
|
106
|
+
/** What the format is and when to use it. */
|
|
107
|
+
summary: string;
|
|
108
|
+
/** Short, verifiable rules. */
|
|
109
|
+
rules: string[];
|
|
110
|
+
examples: FormatExample[];
|
|
111
|
+
}
|
|
112
|
+
export type AnyFormatAdapter = FormatAdapter<any, any>;
|
|
113
|
+
export declare class FormatDefinitionError extends Error {
|
|
114
|
+
constructor(format: string, problem: string);
|
|
115
|
+
}
|
|
116
|
+
/** Checks an adapter's shape. The registry runs it on `register`; third-party adapters can call it directly. */
|
|
117
|
+
export declare function defineFormat<Content, Operation>(adapter: FormatAdapter<Content, Operation>): FormatAdapter<Content, Operation>;
|
|
118
|
+
export declare function assertFormatContract(adapter: AnyFormatAdapter): void;
|
|
119
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,wGAAwG;AACxG,MAAM,WAAW,aAAa,CAAC,OAAO,GAAG,OAAO,EAAE,SAAS,GAAG,OAAO;IACnE,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,iHAAiH;IACjH,aAAa,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IAEd,qFAAqF;IACrF,KAAK,IAAI,OAAO,CAAC;IACjB,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Aa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,2FAA2F;IAC3F,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CACpC;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAGD,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEvD,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAG1C;CACF;AAKD,gHAAgH;AAChH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,EAC7C,OAAO,EAAE,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,GACzC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAGnC;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAoCpE"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class FormatDefinitionError extends Error {
|
|
2
|
+
constructor(format, problem) {
|
|
3
|
+
super(`Invalid format "${format}": ${problem}`);
|
|
4
|
+
this.name = 'FormatDefinitionError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const FORMAT_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
8
|
+
const VERSION_NAME = /^[a-z0-9][a-z0-9.+@-]{0,63}$/i;
|
|
9
|
+
/** Checks an adapter's shape. The registry runs it on `register`; third-party adapters can call it directly. */
|
|
10
|
+
export function defineFormat(adapter) {
|
|
11
|
+
assertFormatContract(adapter);
|
|
12
|
+
return adapter;
|
|
13
|
+
}
|
|
14
|
+
export function assertFormatContract(adapter) {
|
|
15
|
+
const name = typeof adapter?.format === 'string' ? adapter.format : '<unnamed>';
|
|
16
|
+
if (!FORMAT_NAME.test(name))
|
|
17
|
+
throw new FormatDefinitionError(name, 'format must match /^[a-z][a-z0-9-]{0,63}$/');
|
|
18
|
+
if (typeof adapter.formatVersion !== 'string' || !VERSION_NAME.test(adapter.formatVersion)) {
|
|
19
|
+
throw new FormatDefinitionError(name, 'formatVersion must be a non-empty version string');
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(adapter.readableVersions) || !adapter.readableVersions.includes(adapter.formatVersion)) {
|
|
22
|
+
throw new FormatDefinitionError(name, 'readableVersions must include formatVersion');
|
|
23
|
+
}
|
|
24
|
+
if (!(adapter.operationSchema && typeof adapter.operationSchema.safeParse === 'function')) {
|
|
25
|
+
throw new FormatDefinitionError(name, 'operationSchema must be a zod schema');
|
|
26
|
+
}
|
|
27
|
+
for (const fn of ['empty', 'validate', 'apply', 'read', 'diff', 'lint', 'parsePartial']) {
|
|
28
|
+
if (typeof adapter[fn] !== 'function')
|
|
29
|
+
throw new FormatDefinitionError(name, `${fn} must be a function`);
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(adapter.migrations))
|
|
32
|
+
throw new FormatDefinitionError(name, 'migrations must be an array');
|
|
33
|
+
for (const migration of adapter.migrations) {
|
|
34
|
+
if (!adapter.readableVersions.includes(migration.from) ||
|
|
35
|
+
!adapter.readableVersions.includes(migration.to)) {
|
|
36
|
+
throw new FormatDefinitionError(name, `migration ${migration.from}→${migration.to} must use readable versions`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!adapter.instructions ||
|
|
40
|
+
typeof adapter.instructions.summary !== 'string' ||
|
|
41
|
+
!Array.isArray(adapter.instructions.rules)) {
|
|
42
|
+
throw new FormatDefinitionError(name, 'instructions need summary, rules and examples');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AA6HA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,MAAc,EAAE,OAAe;QACzC,KAAK,CAAC,mBAAmB,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAC7C,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAC1B,OAA0C;IAE1C,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,IAAI,GAAG,OAAO,OAAO,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;IAChF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QACzB,MAAM,IAAI,qBAAqB,CAAC,IAAI,EAAE,4CAA4C,CAAC,CAAC;IACtF,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3F,MAAM,IAAI,qBAAqB,CAAC,IAAI,EAAE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ACD,IACE,CAAC,OAAO,CAAC,YAAY;QACrB,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,KAAK,QAAQ;QAChD,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAC1C,CAAC;QACD,MAAM,IAAI,qBAAqB,CAAC,IAAI,EAAE,+CAA+C,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
|
package/dist/diff.d.ts
CHANGED
package/dist/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IACpB,qCAAqC;IACrC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IACxB,wDAAwD;IACxD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC;IAC7B,kCAAkC;IAClC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAC7C,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOtD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEzD;AAID,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,aAAa,EAAE,CA8DjB;AAsCD,8DAA8D;AAC9D,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,CAAC,EAAE,MAAM,GACd,aAAa,EAAE,CAuBjB"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import type { AdapterContext, AnyFormatAdapter, ChangeSummary, LintIssue } from './adapter.js';
|
|
2
3
|
import { type Artifact } from './envelope.js';
|
|
3
4
|
import { formatPath } from './errors.js';
|
|
4
|
-
import type { AnyArtifactKind, ChangeSummary, LintIssue } from './kind.js';
|
|
5
5
|
import type { ArtifactRegistry } from './registry.js';
|
|
6
|
-
/** Envelope operations, available for every
|
|
6
|
+
/** Envelope operations, available for every format and handled by the core (spec §9.3). */
|
|
7
7
|
export declare const envelopeOperationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
8
|
op: z.ZodLiteral<"set_title">;
|
|
9
9
|
title: z.ZodString;
|
|
@@ -22,48 +22,54 @@ export declare const ENVELOPE_OPERATIONS: readonly ['set_title', 'set_theme', 's
|
|
|
22
22
|
export declare function isEnvelopeOperation(op: unknown): boolean;
|
|
23
23
|
/** Lists the `op` names of a discriminated union schema (best effort, used for hints). */
|
|
24
24
|
export declare function operationNames(schema: z.ZodType): string[];
|
|
25
|
+
/** Adapter validation + limits. Throws INVALID_CONTENT or LIMIT_EXCEEDED. Returns the normalized content. */
|
|
26
|
+
export declare function validateContent(registry: ArtifactRegistry, adapter: AnyFormatAdapter, raw: unknown, ctx: AdapterContext): unknown;
|
|
27
|
+
export declare function checkLimits(registry: ArtifactRegistry, adapter: AnyFormatAdapter, content: unknown, locale?: string): void;
|
|
25
28
|
export interface PreparedContent<Content = unknown> {
|
|
26
29
|
content: Content;
|
|
27
|
-
ids: string[];
|
|
28
30
|
lint: LintIssue[];
|
|
29
31
|
}
|
|
30
|
-
export interface EngineOptions {
|
|
31
|
-
locale?: string;
|
|
32
|
-
}
|
|
33
|
-
/** Schema + integrity + unique ids + limits. Throws INVALID_CONTENT or LIMIT_EXCEEDED. */
|
|
34
|
-
export declare function validateContent(registry: ArtifactRegistry, kind: AnyArtifactKind, raw: unknown, locale?: string): unknown;
|
|
35
|
-
export declare function checkLimits(registry: ArtifactRegistry, kind: AnyArtifactKind, content: unknown, locale?: string): void;
|
|
36
32
|
/**
|
|
37
33
|
* Turns raw content (from the model, a user or an alternative input) into valid content:
|
|
38
|
-
* sanitize →
|
|
34
|
+
* sanitize → validate → limits → lint. Pure.
|
|
39
35
|
*/
|
|
40
|
-
export declare function prepareContent(registry: ArtifactRegistry,
|
|
41
|
-
|
|
36
|
+
export declare function prepareContent(registry: ArtifactRegistry, formatName: string, raw: unknown, options?: {
|
|
37
|
+
locale?: string;
|
|
38
|
+
themeId?: string;
|
|
42
39
|
}): PreparedContent;
|
|
40
|
+
export type ParsedOperation = {
|
|
41
|
+
kind: 'envelope';
|
|
42
|
+
op: EnvelopeOperation;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'content';
|
|
45
|
+
op: unknown;
|
|
46
|
+
};
|
|
43
47
|
export interface BatchResult<Content = unknown> {
|
|
44
48
|
content: Content;
|
|
45
|
-
|
|
49
|
+
formatVersion: string;
|
|
46
50
|
title: string;
|
|
47
51
|
themeId: string;
|
|
48
52
|
locale: string;
|
|
49
|
-
/**
|
|
50
|
-
|
|
53
|
+
/** Anchors, declarations, ranges or sheets created by the batch. */
|
|
54
|
+
createdRefs: string[];
|
|
51
55
|
diff: ChangeSummary[];
|
|
52
56
|
lint: LintIssue[];
|
|
53
57
|
}
|
|
54
58
|
/** Parses and sanitizes a batch. Throws INVALID_OPERATION with the index of the first bad operation. */
|
|
55
|
-
export declare function parseOperations(registry: ArtifactRegistry,
|
|
59
|
+
export declare function parseOperations(registry: ArtifactRegistry, formatName: string, operations: unknown, locale?: string): ParsedOperation[];
|
|
56
60
|
/**
|
|
57
|
-
* Applies a batch atomically
|
|
58
|
-
*
|
|
59
|
-
*
|
|
61
|
+
* Applies a batch atomically (spec §9.1, steps 4–7). Operations run in order: runs of content operations go to the
|
|
62
|
+
* adapter, envelope operations and `replace_content` are handled here. Any failure throws and leaves the input
|
|
63
|
+
* untouched, since everything works on copies.
|
|
60
64
|
*/
|
|
61
|
-
export declare function applyOperations(registry: ArtifactRegistry, artifact: Pick<Artifact, '
|
|
65
|
+
export declare function applyOperations(registry: ArtifactRegistry, artifact: Pick<Artifact, 'format' | 'content' | 'title' | 'themeId' | 'locale'>, operations: unknown, options?: {
|
|
66
|
+
locale?: string;
|
|
67
|
+
}): Promise<BatchResult>;
|
|
62
68
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
69
|
+
* Areas a batch touches, for automatic rebase (spec §9.2). Derived from the diff produced by applying the batch on
|
|
70
|
+
* its base, plus the envelope fields it sets. `replace_content` touches everything.
|
|
65
71
|
*/
|
|
66
|
-
export declare function batchTargets(
|
|
72
|
+
export declare function batchTargets(operations: ParsedOperation[], baseDiff: ChangeSummary[]): Set<string>;
|
|
67
73
|
/** True when two target sets overlap. `*` overlaps everything. */
|
|
68
74
|
export declare function targetsOverlap(a: Set<string>, b: Set<string>): boolean;
|
|
69
75
|
export { formatPath };
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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