@aigne/afs-world-mapping 1.11.0-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/LICENSE.md +26 -0
- package/dist/index.d.mts +246 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +992 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are proprietary
|
|
6
|
+
and confidential. Unauthorized copying, modification, distribution, or use of
|
|
7
|
+
this Software, via any medium, is strictly prohibited.
|
|
8
|
+
|
|
9
|
+
The Software is provided for internal use only within ArcBlock, Inc. and its
|
|
10
|
+
authorized affiliates.
|
|
11
|
+
|
|
12
|
+
## No License Granted
|
|
13
|
+
|
|
14
|
+
No license, express or implied, is granted to any party for any purpose.
|
|
15
|
+
All rights are reserved by ArcBlock, Inc.
|
|
16
|
+
|
|
17
|
+
## Public Artifact Distribution
|
|
18
|
+
|
|
19
|
+
Portions of this Software may be released publicly under separate open-source
|
|
20
|
+
licenses (such as MIT License) through designated public repositories. Such
|
|
21
|
+
public releases are governed by their respective licenses and do not affect
|
|
22
|
+
the proprietary nature of this repository.
|
|
23
|
+
|
|
24
|
+
## Contact
|
|
25
|
+
|
|
26
|
+
For licensing inquiries, contact: legal@arcblock.io
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { AFSEntry, AFSModule } from "@aigne/afs";
|
|
2
|
+
|
|
3
|
+
//#region src/binding/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Provider-Agnostic Binding Types
|
|
6
|
+
*
|
|
7
|
+
* Declares how a world schema maps to source AFS paths.
|
|
8
|
+
* No backend-specific details — only path templates and field renames.
|
|
9
|
+
*/
|
|
10
|
+
/** Per-kind mapping configuration */
|
|
11
|
+
interface KindMapping {
|
|
12
|
+
/** Override source path for this kind (defaults to WorldBinding.source) */
|
|
13
|
+
source?: string;
|
|
14
|
+
/** Source path template (e.g., /issues/{number}) */
|
|
15
|
+
path?: string;
|
|
16
|
+
/** World field name → source field name rename map */
|
|
17
|
+
fieldMap?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/** Top-level binding: declares source AFS and per-kind overrides */
|
|
20
|
+
interface WorldBinding {
|
|
21
|
+
/** Default source AFS path prefix */
|
|
22
|
+
source: string;
|
|
23
|
+
/** Per-kind mapping overrides */
|
|
24
|
+
mappings?: Record<string, KindMapping>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/capability.d.ts
|
|
28
|
+
type MutateAction = "create" | "update" | "delete" | "exec";
|
|
29
|
+
interface MutateResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
interface WorldStatus {
|
|
35
|
+
loaded: boolean;
|
|
36
|
+
loadedAt?: Date;
|
|
37
|
+
schemaPath?: string;
|
|
38
|
+
bindingPath?: string;
|
|
39
|
+
compiled: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
stats?: {
|
|
42
|
+
kinds: number;
|
|
43
|
+
routes: number;
|
|
44
|
+
operations: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
interface BackendOp {
|
|
48
|
+
type: "sql" | "http" | "graphql" | "mcp-tool" | "custom";
|
|
49
|
+
operation: unknown;
|
|
50
|
+
params?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
interface ProjectionContext {
|
|
53
|
+
path: string;
|
|
54
|
+
kind: string;
|
|
55
|
+
pathParams: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
interface AFSWorldMappingCapable {
|
|
58
|
+
loadWorld(schemaPath: string, bindingPath: string): Promise<void>;
|
|
59
|
+
reloadWorld(): Promise<void>;
|
|
60
|
+
getWorldStatus(): WorldStatus;
|
|
61
|
+
resolve(path: string): BackendOp | null;
|
|
62
|
+
project(backendData: unknown, context: ProjectionContext): AFSEntry[];
|
|
63
|
+
mutate(path: string, action: MutateAction, payload: unknown): Promise<MutateResult>;
|
|
64
|
+
}
|
|
65
|
+
declare function isWorldMappingCapable(module: AFSModule): module is AFSModule & AFSWorldMappingCapable;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/schema/types.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* World Schema DSL type definitions.
|
|
70
|
+
*
|
|
71
|
+
* These types represent the structure of a World Schema YAML file.
|
|
72
|
+
* They are purely declarative — no backend-specific details.
|
|
73
|
+
*/
|
|
74
|
+
/** Primitive field types + parameterized types (enum, ref, list) */
|
|
75
|
+
type FieldType = string;
|
|
76
|
+
/** Relation type — always list:KindName */
|
|
77
|
+
type RelationType = string;
|
|
78
|
+
interface UniqueConstraint {
|
|
79
|
+
unique: string[];
|
|
80
|
+
}
|
|
81
|
+
interface RequiredConstraint {
|
|
82
|
+
required: string[];
|
|
83
|
+
}
|
|
84
|
+
type Constraint = UniqueConstraint | RequiredConstraint;
|
|
85
|
+
interface ComputedFieldDef {
|
|
86
|
+
expr: string;
|
|
87
|
+
}
|
|
88
|
+
interface RepresentDef {
|
|
89
|
+
format: string;
|
|
90
|
+
template: string;
|
|
91
|
+
}
|
|
92
|
+
interface KindDef {
|
|
93
|
+
key: string;
|
|
94
|
+
path: string;
|
|
95
|
+
fields: Record<string, FieldType>;
|
|
96
|
+
relations?: Record<string, RelationType>;
|
|
97
|
+
indexes?: string[][];
|
|
98
|
+
constraints?: Constraint[];
|
|
99
|
+
computed?: Record<string, ComputedFieldDef>;
|
|
100
|
+
represent?: Record<string, RepresentDef>;
|
|
101
|
+
validate?: Array<{
|
|
102
|
+
expr: string;
|
|
103
|
+
error: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
interface WorldSchema {
|
|
107
|
+
world: string;
|
|
108
|
+
version: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
kinds: Record<string, KindDef>;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/compiler.d.ts
|
|
114
|
+
/** Result of resolving a world path */
|
|
115
|
+
interface TrieMatch {
|
|
116
|
+
kind: string;
|
|
117
|
+
params: Record<string, string>;
|
|
118
|
+
isCollection: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** Compiled kind metadata */
|
|
121
|
+
interface CompiledKind {
|
|
122
|
+
key: string;
|
|
123
|
+
source: string;
|
|
124
|
+
fieldMap: Record<string, string>;
|
|
125
|
+
}
|
|
126
|
+
/** Result of compilation */
|
|
127
|
+
interface CompiledMapping {
|
|
128
|
+
world: string;
|
|
129
|
+
version: string;
|
|
130
|
+
resolve: (path: string) => TrieMatch | null;
|
|
131
|
+
kinds: Record<string, CompiledKind>;
|
|
132
|
+
}
|
|
133
|
+
declare class WorldCompiler {
|
|
134
|
+
compile(schema: WorldSchema | any, binding: WorldBinding): CompiledMapping;
|
|
135
|
+
private validateIdentifier;
|
|
136
|
+
private validateFieldType;
|
|
137
|
+
private buildPathTrie;
|
|
138
|
+
private resolvePath;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/core.d.ts
|
|
142
|
+
declare class WorldMappingCore {
|
|
143
|
+
readonly schema: WorldSchema;
|
|
144
|
+
readonly binding: WorldBinding;
|
|
145
|
+
private compiled;
|
|
146
|
+
constructor(schema: WorldSchema | any, binding: WorldBinding);
|
|
147
|
+
/** Resolve a target world path to kind + params + isCollection */
|
|
148
|
+
resolve(path: string): TrieMatch | null;
|
|
149
|
+
/** Translate a TrieMatch to a source AFS path */
|
|
150
|
+
translatePath(match: TrieMatch): string;
|
|
151
|
+
/** Project source fields → world fields (read direction) */
|
|
152
|
+
projectFields(data: Record<string, unknown>, kindName: string, params?: Record<string, unknown>): Record<string, unknown>;
|
|
153
|
+
/** Cache for parsed expressions */
|
|
154
|
+
private exprCache;
|
|
155
|
+
private getCompiledExpr;
|
|
156
|
+
/** Reverse project world fields → source fields (write direction) */
|
|
157
|
+
reverseProjectFields(data: Record<string, unknown>, kindName: string): Record<string, unknown>;
|
|
158
|
+
/** Get kind metadata */
|
|
159
|
+
getKind(name: string): CompiledKind | undefined;
|
|
160
|
+
/** List all kind names */
|
|
161
|
+
getKindNames(): string[];
|
|
162
|
+
/** Validate data against kind's validation rules */
|
|
163
|
+
validate(data: Record<string, unknown>, kindName: string): {
|
|
164
|
+
valid: boolean;
|
|
165
|
+
errors: Array<{
|
|
166
|
+
expr: string;
|
|
167
|
+
error: string;
|
|
168
|
+
}>;
|
|
169
|
+
};
|
|
170
|
+
/** Render a representation of data for a kind in the given format */
|
|
171
|
+
getRepresentation(data: Record<string, unknown>, kindName: string, format: string): string | null;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/module.d.ts
|
|
175
|
+
/** Source AFS interface — minimal interface for delegation */
|
|
176
|
+
interface AFSSource {
|
|
177
|
+
list(path: string, options?: unknown): Promise<{
|
|
178
|
+
list: unknown[];
|
|
179
|
+
total?: number;
|
|
180
|
+
}>;
|
|
181
|
+
read(path: string, options?: unknown): Promise<unknown>;
|
|
182
|
+
write?(path: string, content: unknown, options?: unknown): Promise<unknown>;
|
|
183
|
+
delete?(path: string, options?: unknown): Promise<unknown>;
|
|
184
|
+
}
|
|
185
|
+
/** Options for WorldMappingModule */
|
|
186
|
+
interface WorldMappingModuleOptions {
|
|
187
|
+
schema: WorldSchema;
|
|
188
|
+
binding: WorldBinding;
|
|
189
|
+
source: AFSSource;
|
|
190
|
+
}
|
|
191
|
+
declare class WorldMappingModule {
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly description: string;
|
|
194
|
+
readonly core: WorldMappingCore;
|
|
195
|
+
private source;
|
|
196
|
+
constructor(options: WorldMappingModuleOptions);
|
|
197
|
+
/** List entries at a world path */
|
|
198
|
+
list(path: string): Promise<{
|
|
199
|
+
list: unknown[];
|
|
200
|
+
total?: number;
|
|
201
|
+
}>;
|
|
202
|
+
/** Read a single entry at a world path */
|
|
203
|
+
read(path: string): Promise<unknown>;
|
|
204
|
+
/** Write an entry at a world path */
|
|
205
|
+
write(path: string, content: Record<string, unknown>): Promise<unknown>;
|
|
206
|
+
/** Delete an entry at a world path */
|
|
207
|
+
delete(path: string): Promise<unknown>;
|
|
208
|
+
/** Get kind names */
|
|
209
|
+
getKindNames(): string[];
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/with-world-mapping.d.ts
|
|
213
|
+
/** Configuration for injecting world mapping into a provider */
|
|
214
|
+
interface WorldMappingConfig {
|
|
215
|
+
schema: WorldSchema;
|
|
216
|
+
binding: WorldBinding;
|
|
217
|
+
}
|
|
218
|
+
/** Status of an applied world mapping */
|
|
219
|
+
interface WorldMappingStatus {
|
|
220
|
+
schema: WorldSchema;
|
|
221
|
+
binding: WorldBinding;
|
|
222
|
+
kinds: string[];
|
|
223
|
+
appliedAt: Date;
|
|
224
|
+
}
|
|
225
|
+
/** Interface that providers implement to accept world mapping injection */
|
|
226
|
+
interface WithWorldMapping {
|
|
227
|
+
applyWorldMapping(config: WorldMappingConfig): void;
|
|
228
|
+
getWorldMapping(): WorldMappingStatus | null;
|
|
229
|
+
}
|
|
230
|
+
/** Type guard: check if an object supports world mapping injection */
|
|
231
|
+
declare function isWithWorldMapping(obj: unknown): obj is WithWorldMapping;
|
|
232
|
+
/**
|
|
233
|
+
* Helper for providers implementing WithWorldMapping.
|
|
234
|
+
* Validates config, creates WorldMappingCore, returns the mapping state.
|
|
235
|
+
* Throws if already applied or config is invalid.
|
|
236
|
+
*/
|
|
237
|
+
declare function applyWorldMappingHelper(config: WorldMappingConfig, existing: {
|
|
238
|
+
core: WorldMappingCore;
|
|
239
|
+
status: WorldMappingStatus;
|
|
240
|
+
} | null): {
|
|
241
|
+
core: WorldMappingCore;
|
|
242
|
+
status: WorldMappingStatus;
|
|
243
|
+
};
|
|
244
|
+
//#endregion
|
|
245
|
+
export { type AFSSource, type CompiledKind, type CompiledMapping, type KindMapping, type TrieMatch, type WithWorldMapping, type WorldBinding, WorldCompiler, type WorldMappingConfig, WorldMappingCore, WorldMappingModule, type WorldMappingModuleOptions, type WorldMappingStatus, type WorldSchema, applyWorldMappingHelper, isWithWorldMapping, isWorldMappingCapable };
|
|
246
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/binding/types.ts","../src/capability.ts","../src/schema/types.ts","../src/compiler.ts","../src/core.ts","../src/module.ts","../src/with-world-mapping.ts"],"mappings":";;;;;;AAQA;;;;UAAiB,WAAA;EAIf;EAFA,MAAA;EAIW;EAFX,IAAA;EAEiB;EAAjB,QAAA,GAAW,MAAA;AAAA;;UAII,YAAA;EAEf;EAAA,MAAA;EAEW;EAAX,QAAA,GAAW,MAAA,SAAe,WAAA;AAAA;;;KCpBhB,YAAA;AAAA,UAEK,YAAA;EACf,OAAA;EACA,IAAA;EACA,KAAA;AAAA;AAAA,UAGe,WAAA;EACf,MAAA;EACA,QAAA,GAAW,IAAA;EACX,UAAA;EACA,WAAA;EACA,QAAA;EACA,KAAA;EACA,KAAA;IACE,KAAA;IACA,MAAA;IACA,UAAA;EAAA;AAAA;AAAA,UAIa,SAAA;EACf,IAAA;EACA,SAAA;EACA,MAAA,GAAS,MAAA;AAAA;AAAA,UAGM,iBAAA;EACf,IAAA;EACA,IAAA;EACA,UAAA,EAAY,MAAA;AAAA;AAAA,UAGG,sBAAA;EACf,SAAA,CAAU,UAAA,UAAoB,WAAA,WAAsB,OAAA;EACpD,WAAA,IAAe,OAAA;EACf,cAAA,IAAkB,WAAA;EAClB,OAAA,CAAQ,IAAA,WAAe,SAAA;EACvB,OAAA,CAAQ,WAAA,WAAsB,OAAA,EAAS,iBAAA,GAAoB,QAAA;EAC3D,MAAA,CAAO,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