@hablala/schema 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 +21 -0
- package/README.md +53 -2
- package/dist/chunk-NPRLVZEM.js +424 -0
- package/dist/chunk-NPRLVZEM.js.map +1 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest-CGY_48sA.d.ts +838 -0
- package/dist/synth/index.d.ts +170 -0
- package/dist/synth/index.js +359 -0
- package/dist/synth/index.js.map +1 -0
- package/generated/data-type.schema.json +17 -0
- package/generated/manifest.schema.json +2121 -0
- package/package.json +64 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { D as DataType, S as SectionMode, A as AccountKind, M as Manifest, C as Cardinality, j as ManifestRelationship, o as ManifestWorkflow, e as ManifestAgent, m as ManifestTransaction, g as ManifestPolicy, n as ManifestWebhookEndpoint, f as ManifestEgressConnection, k as ManifestRole, l as ManifestSettings } from '../manifest-CGY_48sA.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/** Flags comunes de almacenamiento/entrada de un campo no derivado. */
|
|
5
|
+
interface CommonFlags {
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
synonyms?: string[];
|
|
9
|
+
isRequired?: boolean;
|
|
10
|
+
isUnique?: boolean;
|
|
11
|
+
isIndexed?: boolean;
|
|
12
|
+
embedInVector?: boolean;
|
|
13
|
+
defaultValue?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** El fragmento emitido por un helper: todo lo de un campo MENOS su `apiName` (lo pone el builder). */
|
|
16
|
+
interface FieldSpec {
|
|
17
|
+
dataType: DataType;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
synonyms?: string[];
|
|
21
|
+
isRequired?: boolean;
|
|
22
|
+
isUnique?: boolean;
|
|
23
|
+
isIndexed?: boolean;
|
|
24
|
+
embedInVector?: boolean;
|
|
25
|
+
defaultValue?: unknown;
|
|
26
|
+
config?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
declare function text(opts?: CommonFlags): FieldSpec;
|
|
29
|
+
declare function number(opts?: CommonFlags & {
|
|
30
|
+
min?: number;
|
|
31
|
+
max?: number;
|
|
32
|
+
decimals?: number;
|
|
33
|
+
}): FieldSpec;
|
|
34
|
+
declare function boolean(opts?: CommonFlags): FieldSpec;
|
|
35
|
+
declare function date(opts?: CommonFlags): FieldSpec;
|
|
36
|
+
declare function timestamp(opts?: CommonFlags): FieldSpec;
|
|
37
|
+
type Option = string | {
|
|
38
|
+
value: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
};
|
|
41
|
+
declare function select(opts: CommonFlags & {
|
|
42
|
+
options: Option[];
|
|
43
|
+
}): FieldSpec;
|
|
44
|
+
declare function multiselect(opts: CommonFlags & {
|
|
45
|
+
options: Option[];
|
|
46
|
+
}): FieldSpec;
|
|
47
|
+
type ReferenceConfig = {
|
|
48
|
+
targetObject: string;
|
|
49
|
+
relationship?: never;
|
|
50
|
+
} | {
|
|
51
|
+
relationship: string;
|
|
52
|
+
targetObject?: never;
|
|
53
|
+
};
|
|
54
|
+
declare function reference(opts: CommonFlags & ReferenceConfig): FieldSpec;
|
|
55
|
+
declare function file(opts?: CommonFlags & {
|
|
56
|
+
maxCount?: number;
|
|
57
|
+
maxSizeBytes?: number;
|
|
58
|
+
acceptedContentTypes?: string[];
|
|
59
|
+
visibility?: "public" | "private";
|
|
60
|
+
}): FieldSpec;
|
|
61
|
+
type DerivedMeta = Pick<CommonFlags, "title" | "description" | "synonyms">;
|
|
62
|
+
declare function formula(opts: DerivedMeta & {
|
|
63
|
+
expression: string;
|
|
64
|
+
resultType?: "number" | "text" | "boolean";
|
|
65
|
+
}): FieldSpec;
|
|
66
|
+
declare function rollup(opts: DerivedMeta & {
|
|
67
|
+
relationship: string;
|
|
68
|
+
aggregate: "sum" | "count" | "avg" | "min" | "max";
|
|
69
|
+
target?: string;
|
|
70
|
+
}): FieldSpec;
|
|
71
|
+
declare const fieldHelpers: Record<DataType, (...args: never[]) => FieldSpec>;
|
|
72
|
+
|
|
73
|
+
interface ObjectMeta {
|
|
74
|
+
title?: string;
|
|
75
|
+
titleSingular?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
synonyms?: string[];
|
|
78
|
+
titleFieldApiName?: string;
|
|
79
|
+
config?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
interface RelationshipMeta {
|
|
82
|
+
target: string;
|
|
83
|
+
cardinality: Cardinality;
|
|
84
|
+
apiName?: string;
|
|
85
|
+
title?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
}
|
|
88
|
+
/** Builder de UN object: acumula sus campos (orden declarado) y sus relationships salientes. */
|
|
89
|
+
declare class ObjectBuilder {
|
|
90
|
+
private readonly account;
|
|
91
|
+
readonly apiName: string;
|
|
92
|
+
private readonly meta;
|
|
93
|
+
private readonly fields;
|
|
94
|
+
private readonly referenceRecords;
|
|
95
|
+
constructor(apiName: string, meta: ObjectMeta, account: Account);
|
|
96
|
+
/** Añade un campo por su `apiName` y el spec de un helper (`text()`, `select()`, …). Encadenable. */
|
|
97
|
+
field(apiName: string, spec: FieldSpec): this;
|
|
98
|
+
/**
|
|
99
|
+
* Declara una relationship SALIENTE desde este object. El `source` se inyecta solo (es este object).
|
|
100
|
+
* Encadenable.
|
|
101
|
+
*/
|
|
102
|
+
relationship(apiNameOrMeta: string | RelationshipMeta, meta?: Omit<RelationshipMeta, "apiName">): this;
|
|
103
|
+
/** Añade un record de reference data (managed/desired-state por la clave de negocio del object). */
|
|
104
|
+
reference(properties: Record<string, unknown>): this;
|
|
105
|
+
/** @internal — emite el object con sus campos/reference embebidos. */
|
|
106
|
+
toJSON(): Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
/** El construct raíz. El tenant exporta una instancia como `default`; el CLI llama `synth()`. */
|
|
109
|
+
declare class Account {
|
|
110
|
+
private readonly kind?;
|
|
111
|
+
private readonly objects;
|
|
112
|
+
private readonly relationships;
|
|
113
|
+
private readonly workflows;
|
|
114
|
+
private readonly agents;
|
|
115
|
+
private readonly transactions;
|
|
116
|
+
private readonly policies;
|
|
117
|
+
private readonly webhooks;
|
|
118
|
+
private readonly egressConnections;
|
|
119
|
+
private readonly roles;
|
|
120
|
+
private settingsValue?;
|
|
121
|
+
private packagesValue?;
|
|
122
|
+
readonly modes: Record<string, SectionMode>;
|
|
123
|
+
constructor(opts?: {
|
|
124
|
+
kind?: AccountKind;
|
|
125
|
+
});
|
|
126
|
+
/** Fija el modo de una sección (`additive` para no archivar lo no declarado). Encadenable. */
|
|
127
|
+
mode(section: keyof Manifest, mode: SectionMode): this;
|
|
128
|
+
object(apiName: string, meta?: ObjectMeta): ObjectBuilder;
|
|
129
|
+
/** @internal — un ObjectBuilder registra aquí su relationship saliente (con source ya inyectado). */
|
|
130
|
+
addRelationship(relationship: Record<string, unknown>): void;
|
|
131
|
+
/**
|
|
132
|
+
* Declara una relationship a nivel de cuenta, con `source`/`target` explícitos. La forma idiomática es
|
|
133
|
+
* `object(...).relationship(...)` (inyecta el source); este método existe para el reverse-synth de
|
|
134
|
+
* `pull`, que re-emite las relationships tal cual vienen del servidor. Encadenable.
|
|
135
|
+
*/
|
|
136
|
+
relationship(relationship: ManifestRelationship): this;
|
|
137
|
+
workflow(workflow: ManifestWorkflow): this;
|
|
138
|
+
agent(agent: ManifestAgent): this;
|
|
139
|
+
transaction(transaction: ManifestTransaction): this;
|
|
140
|
+
policy(policy: ManifestPolicy): this;
|
|
141
|
+
webhook(webhook: ManifestWebhookEndpoint): this;
|
|
142
|
+
/**
|
|
143
|
+
* Declara una egress connection: el destino externo allowlisted + el tipo de auth al que un
|
|
144
|
+
* `http_request` puede salir. El SECRET no se declara aquí (se setea out-of-band). Encadenable.
|
|
145
|
+
*/
|
|
146
|
+
egressConnection(egressConnection: ManifestEgressConnection): this;
|
|
147
|
+
role(role: ManifestRole): this;
|
|
148
|
+
settings(settings: ManifestSettings): this;
|
|
149
|
+
packages(...names: string[]): this;
|
|
150
|
+
/**
|
|
151
|
+
* Compila el construct al manifiesto JSON canónico y lo VALIDA contra el schema (fail-fast: lanza con
|
|
152
|
+
* los problemas legibles si algo no cuadra). Es el `app.synth()` del modelo CDK.
|
|
153
|
+
*/
|
|
154
|
+
synth(): Manifest;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Genera el source de `hablala.config.ts` a partir de un manifiesto. Objects y relationships se emiten
|
|
159
|
+
* con los builders (autoría idiomática); las demás secciones, con los métodos crudos `account.X({...})`.
|
|
160
|
+
*/
|
|
161
|
+
declare function manifestToConfigSource(manifest: Manifest): string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* ¿El estado local declarado está CONTENIDO en el del server? (drift check de `pull --check`): cada
|
|
165
|
+
* campo/elemento declarado localmente debe tener su gemelo en el server con el mismo valor. El server
|
|
166
|
+
* PUEDE tener más (elementos o claves no declarados) — eso no es drift.
|
|
167
|
+
*/
|
|
168
|
+
declare function manifestsMatch(local: Manifest, server: Manifest): boolean;
|
|
169
|
+
|
|
170
|
+
export { Account, type FieldSpec, ObjectBuilder, boolean, date, fieldHelpers, file, formula, manifestToConfigSource, manifestsMatch, multiselect, number, reference, rollup, select, text, timestamp };
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dataTypeEnum,
|
|
3
|
+
validateManifest
|
|
4
|
+
} from "../chunk-NPRLVZEM.js";
|
|
5
|
+
|
|
6
|
+
// src/synth/account.ts
|
|
7
|
+
function compact(obj) {
|
|
8
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
9
|
+
}
|
|
10
|
+
var ObjectBuilder = class {
|
|
11
|
+
constructor(apiName, meta, account) {
|
|
12
|
+
this.account = account;
|
|
13
|
+
this.apiName = apiName;
|
|
14
|
+
this.meta = meta;
|
|
15
|
+
}
|
|
16
|
+
account;
|
|
17
|
+
apiName;
|
|
18
|
+
meta;
|
|
19
|
+
fields = [];
|
|
20
|
+
referenceRecords = [];
|
|
21
|
+
/** Añade un campo por su `apiName` y el spec de un helper (`text()`, `select()`, …). Encadenable. */
|
|
22
|
+
field(apiName, spec) {
|
|
23
|
+
this.fields.push(compact({ apiName, ...spec }));
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Declara una relationship SALIENTE desde este object. El `source` se inyecta solo (es este object).
|
|
28
|
+
* Encadenable.
|
|
29
|
+
*/
|
|
30
|
+
relationship(apiNameOrMeta, meta) {
|
|
31
|
+
const r = typeof apiNameOrMeta === "string" ? { apiName: apiNameOrMeta, ...meta } : apiNameOrMeta;
|
|
32
|
+
this.account.addRelationship(
|
|
33
|
+
compact({
|
|
34
|
+
apiName: r.apiName ?? `${this.apiName}_${r.target}`,
|
|
35
|
+
source: this.apiName,
|
|
36
|
+
target: r.target,
|
|
37
|
+
cardinality: r.cardinality,
|
|
38
|
+
title: r.title,
|
|
39
|
+
description: r.description
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/** Añade un record de reference data (managed/desired-state por la clave de negocio del object). */
|
|
45
|
+
reference(properties) {
|
|
46
|
+
this.referenceRecords.push({ properties });
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/** @internal — emite el object con sus campos/reference embebidos. */
|
|
50
|
+
toJSON() {
|
|
51
|
+
return compact({
|
|
52
|
+
apiName: this.apiName,
|
|
53
|
+
...this.meta,
|
|
54
|
+
fields: this.fields.length ? this.fields : void 0,
|
|
55
|
+
reference: this.referenceRecords.length ? this.referenceRecords : void 0
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var Account = class {
|
|
60
|
+
kind;
|
|
61
|
+
objects = [];
|
|
62
|
+
relationships = [];
|
|
63
|
+
workflows = [];
|
|
64
|
+
agents = [];
|
|
65
|
+
transactions = [];
|
|
66
|
+
policies = [];
|
|
67
|
+
webhooks = [];
|
|
68
|
+
egressConnections = [];
|
|
69
|
+
roles = [];
|
|
70
|
+
settingsValue;
|
|
71
|
+
packagesValue;
|
|
72
|
+
// Modos de sección (`additive`/`authoritative`), por nombre de sección. Por defecto cada sección es
|
|
73
|
+
// autoritativa; declarar `additive` evita que lo no declarado se archive. El CLI lo traduce a la
|
|
74
|
+
// envoltura `{mode, items}` en la frontera HTTP.
|
|
75
|
+
modes = {};
|
|
76
|
+
constructor(opts = {}) {
|
|
77
|
+
this.kind = opts.kind;
|
|
78
|
+
}
|
|
79
|
+
/** Fija el modo de una sección (`additive` para no archivar lo no declarado). Encadenable. */
|
|
80
|
+
mode(section, mode) {
|
|
81
|
+
this.modes[section] = mode;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
object(apiName, meta = {}) {
|
|
85
|
+
const builder = new ObjectBuilder(apiName, meta, this);
|
|
86
|
+
this.objects.push(builder);
|
|
87
|
+
return builder;
|
|
88
|
+
}
|
|
89
|
+
/** @internal — un ObjectBuilder registra aquí su relationship saliente (con source ya inyectado). */
|
|
90
|
+
addRelationship(relationship) {
|
|
91
|
+
this.relationships.push(relationship);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Declara una relationship a nivel de cuenta, con `source`/`target` explícitos. La forma idiomática es
|
|
95
|
+
* `object(...).relationship(...)` (inyecta el source); este método existe para el reverse-synth de
|
|
96
|
+
* `pull`, que re-emite las relationships tal cual vienen del servidor. Encadenable.
|
|
97
|
+
*/
|
|
98
|
+
relationship(relationship) {
|
|
99
|
+
this.relationships.push(relationship);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
workflow(workflow) {
|
|
103
|
+
this.workflows.push(workflow);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
agent(agent) {
|
|
107
|
+
this.agents.push(agent);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
transaction(transaction) {
|
|
111
|
+
this.transactions.push(transaction);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
policy(policy) {
|
|
115
|
+
this.policies.push(policy);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
webhook(webhook) {
|
|
119
|
+
this.webhooks.push(webhook);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Declara una egress connection: el destino externo allowlisted + el tipo de auth al que un
|
|
124
|
+
* `http_request` puede salir. El SECRET no se declara aquí (se setea out-of-band). Encadenable.
|
|
125
|
+
*/
|
|
126
|
+
egressConnection(egressConnection) {
|
|
127
|
+
this.egressConnections.push(egressConnection);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
role(role) {
|
|
131
|
+
this.roles.push(role);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
settings(settings) {
|
|
135
|
+
this.settingsValue = settings;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
packages(...names) {
|
|
139
|
+
this.packagesValue = names;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Compila el construct al manifiesto JSON canónico y lo VALIDA contra el schema (fail-fast: lanza con
|
|
144
|
+
* los problemas legibles si algo no cuadra). Es el `app.synth()` del modelo CDK.
|
|
145
|
+
*/
|
|
146
|
+
synth() {
|
|
147
|
+
const draft = compact({
|
|
148
|
+
kind: this.kind,
|
|
149
|
+
objects: this.objects.length ? this.objects.map((o) => o.toJSON()) : void 0,
|
|
150
|
+
relationships: this.relationships.length ? this.relationships : void 0,
|
|
151
|
+
workflows: this.workflows.length ? this.workflows : void 0,
|
|
152
|
+
agents: this.agents.length ? this.agents : void 0,
|
|
153
|
+
transactions: this.transactions.length ? this.transactions : void 0,
|
|
154
|
+
policies: this.policies.length ? this.policies : void 0,
|
|
155
|
+
webhooks: this.webhooks.length ? this.webhooks : void 0,
|
|
156
|
+
egressConnections: this.egressConnections.length ? this.egressConnections : void 0,
|
|
157
|
+
roles: this.roles.length ? this.roles : void 0,
|
|
158
|
+
settings: this.settingsValue,
|
|
159
|
+
packages: this.packagesValue
|
|
160
|
+
});
|
|
161
|
+
const result = validateManifest(draft);
|
|
162
|
+
if (!result.ok) {
|
|
163
|
+
const detail = result.problems.map((p) => ` - ${p.path}: ${p.message}`).join("\n");
|
|
164
|
+
throw new Error(`El manifiesto generado por synth() es inv\xE1lido:
|
|
165
|
+
${detail}`);
|
|
166
|
+
}
|
|
167
|
+
return result.manifest;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/synth/field.ts
|
|
172
|
+
function compact2(obj) {
|
|
173
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
174
|
+
}
|
|
175
|
+
function flagsOf(opts) {
|
|
176
|
+
return compact2({
|
|
177
|
+
title: opts.title,
|
|
178
|
+
description: opts.description,
|
|
179
|
+
synonyms: opts.synonyms,
|
|
180
|
+
isRequired: opts.isRequired,
|
|
181
|
+
isUnique: opts.isUnique,
|
|
182
|
+
isIndexed: opts.isIndexed,
|
|
183
|
+
embedInVector: opts.embedInVector,
|
|
184
|
+
defaultValue: opts.defaultValue
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function text(opts = {}) {
|
|
188
|
+
return { dataType: "text", ...flagsOf(opts) };
|
|
189
|
+
}
|
|
190
|
+
function number(opts = {}) {
|
|
191
|
+
const config = compact2({ min: opts.min, max: opts.max, decimals: opts.decimals });
|
|
192
|
+
return { dataType: "number", ...flagsOf(opts), ...Object.keys(config).length ? { config } : {} };
|
|
193
|
+
}
|
|
194
|
+
function boolean(opts = {}) {
|
|
195
|
+
return { dataType: "boolean", ...flagsOf(opts) };
|
|
196
|
+
}
|
|
197
|
+
function date(opts = {}) {
|
|
198
|
+
return { dataType: "date", ...flagsOf(opts) };
|
|
199
|
+
}
|
|
200
|
+
function timestamp(opts = {}) {
|
|
201
|
+
return { dataType: "timestamp", ...flagsOf(opts) };
|
|
202
|
+
}
|
|
203
|
+
function select(opts) {
|
|
204
|
+
return { dataType: "select", ...flagsOf(opts), config: { options: opts.options } };
|
|
205
|
+
}
|
|
206
|
+
function multiselect(opts) {
|
|
207
|
+
return { dataType: "multiselect", ...flagsOf(opts), config: { options: opts.options } };
|
|
208
|
+
}
|
|
209
|
+
function reference(opts) {
|
|
210
|
+
const config = compact2({ targetObject: opts.targetObject, relationship: opts.relationship });
|
|
211
|
+
return { dataType: "reference", ...flagsOf(opts), config };
|
|
212
|
+
}
|
|
213
|
+
function file(opts = {}) {
|
|
214
|
+
const config = compact2({
|
|
215
|
+
maxCount: opts.maxCount,
|
|
216
|
+
maxSizeBytes: opts.maxSizeBytes,
|
|
217
|
+
acceptedContentTypes: opts.acceptedContentTypes,
|
|
218
|
+
visibility: opts.visibility
|
|
219
|
+
});
|
|
220
|
+
return { dataType: "file", ...flagsOf(opts), ...Object.keys(config).length ? { config } : {} };
|
|
221
|
+
}
|
|
222
|
+
function formula(opts) {
|
|
223
|
+
const config = compact2({ expression: opts.expression, resultType: opts.resultType });
|
|
224
|
+
return { dataType: "formula", ...flagsOf(opts), config };
|
|
225
|
+
}
|
|
226
|
+
function rollup(opts) {
|
|
227
|
+
const config = compact2({ relationship: opts.relationship, aggregate: opts.aggregate, target: opts.target });
|
|
228
|
+
return { dataType: "rollup", ...flagsOf(opts), config };
|
|
229
|
+
}
|
|
230
|
+
var fieldHelpers = {
|
|
231
|
+
text,
|
|
232
|
+
number,
|
|
233
|
+
boolean,
|
|
234
|
+
date,
|
|
235
|
+
timestamp,
|
|
236
|
+
select,
|
|
237
|
+
multiselect,
|
|
238
|
+
reference,
|
|
239
|
+
file,
|
|
240
|
+
formula,
|
|
241
|
+
rollup
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/synth/codegen.ts
|
|
245
|
+
function itemsOf(section) {
|
|
246
|
+
if (!section) return [];
|
|
247
|
+
return Array.isArray(section) ? section : section.items;
|
|
248
|
+
}
|
|
249
|
+
var FIELD_FLAGS = ["title", "description", "synonyms", "isRequired", "isUnique", "isIndexed", "embedInVector", "defaultValue"];
|
|
250
|
+
function helperArgs(dataType, field) {
|
|
251
|
+
const args = {};
|
|
252
|
+
for (const flag of FIELD_FLAGS) if (field[flag] !== void 0) args[flag] = field[flag];
|
|
253
|
+
const config = field.config ?? {};
|
|
254
|
+
for (const [k, v] of Object.entries(config)) args[k] = v;
|
|
255
|
+
return args;
|
|
256
|
+
}
|
|
257
|
+
function literal(value) {
|
|
258
|
+
return JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : ` ${line}`).join("\n");
|
|
259
|
+
}
|
|
260
|
+
function objectSource(obj) {
|
|
261
|
+
const { apiName, fields, reference: reference2, ...meta } = obj;
|
|
262
|
+
const metaLiteral = Object.keys(meta).length ? `, ${literal(meta)}` : "";
|
|
263
|
+
let src = ` account.object(${JSON.stringify(apiName)}${metaLiteral})`;
|
|
264
|
+
for (const field of fields ?? []) {
|
|
265
|
+
const dataType = field.dataType;
|
|
266
|
+
const helper = dataTypeEnum.options.includes(dataType) ? dataType : "text";
|
|
267
|
+
const args = helperArgs(dataType, field);
|
|
268
|
+
const argLiteral = Object.keys(args).length ? literal(args) : "";
|
|
269
|
+
src += `
|
|
270
|
+
.field(${JSON.stringify(field.apiName)}, ${helper}(${argLiteral}))`;
|
|
271
|
+
}
|
|
272
|
+
for (const ref of reference2 ?? []) {
|
|
273
|
+
src += `
|
|
274
|
+
.reference(${literal(ref.properties)})`;
|
|
275
|
+
}
|
|
276
|
+
return src + ";";
|
|
277
|
+
}
|
|
278
|
+
function manifestToConfigSource(manifest) {
|
|
279
|
+
const lines = [
|
|
280
|
+
`// Generado por \`hablala pull\`. Es config as code: ed\xEDtalo como TypeScript.`,
|
|
281
|
+
`import {`,
|
|
282
|
+
` Account,`,
|
|
283
|
+
` text, number, boolean, date, timestamp,`,
|
|
284
|
+
` select, multiselect, reference, file, formula, rollup,`,
|
|
285
|
+
`} from "@hablala/schema/synth";`,
|
|
286
|
+
``,
|
|
287
|
+
`const account = new Account(${manifest.kind ? `{ kind: ${JSON.stringify(manifest.kind)} }` : ""});`,
|
|
288
|
+
``
|
|
289
|
+
];
|
|
290
|
+
for (const obj of itemsOf(manifest.objects)) lines.push(objectSource(obj), "");
|
|
291
|
+
const rawSections = [
|
|
292
|
+
["relationships", "relationship"],
|
|
293
|
+
["workflows", "workflow"],
|
|
294
|
+
["agents", "agent"],
|
|
295
|
+
["transactions", "transaction"],
|
|
296
|
+
["policies", "policy"],
|
|
297
|
+
["webhooks", "webhook"],
|
|
298
|
+
["roles", "role"]
|
|
299
|
+
];
|
|
300
|
+
for (const [section, method] of rawSections) {
|
|
301
|
+
for (const item of itemsOf(manifest[section])) {
|
|
302
|
+
lines.push(`account.${method}(${literal(item)});`, "");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (manifest.settings) lines.push(`account.settings(${literal(manifest.settings)});`, "");
|
|
306
|
+
if (manifest.packages?.length) {
|
|
307
|
+
lines.push(`account.packages(${manifest.packages.map((p) => JSON.stringify(p)).join(", ")});`, "");
|
|
308
|
+
}
|
|
309
|
+
lines.push(`export default account;`, "");
|
|
310
|
+
return lines.join("\n");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/synth/match.ts
|
|
314
|
+
var MATCH_KEYS = ["apiName", "slug", "handle", "name", "protocol", "domain", "email", "url"];
|
|
315
|
+
function manifestsMatch(local, server) {
|
|
316
|
+
return isSubset(local, server);
|
|
317
|
+
}
|
|
318
|
+
function isSubset(local, server) {
|
|
319
|
+
if (Array.isArray(local)) {
|
|
320
|
+
if (!Array.isArray(server)) return false;
|
|
321
|
+
return local.every((item) => server.some((candidate) => matchesElement(item, candidate)));
|
|
322
|
+
}
|
|
323
|
+
if (local && typeof local === "object") {
|
|
324
|
+
if (!server || typeof server !== "object" || Array.isArray(server)) return false;
|
|
325
|
+
const s = server;
|
|
326
|
+
return Object.entries(local).every(
|
|
327
|
+
([key, value]) => key in s && isSubset(value, s[key])
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return local === server;
|
|
331
|
+
}
|
|
332
|
+
function matchesElement(local, candidate) {
|
|
333
|
+
if (local && typeof local === "object" && candidate && typeof candidate === "object") {
|
|
334
|
+
const l = local;
|
|
335
|
+
const c = candidate;
|
|
336
|
+
const key = MATCH_KEYS.find((k) => k in l);
|
|
337
|
+
if (key) return l[key] === c[key] && isSubset(local, candidate);
|
|
338
|
+
}
|
|
339
|
+
return isSubset(local, candidate);
|
|
340
|
+
}
|
|
341
|
+
export {
|
|
342
|
+
Account,
|
|
343
|
+
ObjectBuilder,
|
|
344
|
+
boolean,
|
|
345
|
+
date,
|
|
346
|
+
fieldHelpers,
|
|
347
|
+
file,
|
|
348
|
+
formula,
|
|
349
|
+
manifestToConfigSource,
|
|
350
|
+
manifestsMatch,
|
|
351
|
+
multiselect,
|
|
352
|
+
number,
|
|
353
|
+
reference,
|
|
354
|
+
rollup,
|
|
355
|
+
select,
|
|
356
|
+
text,
|
|
357
|
+
timestamp
|
|
358
|
+
};
|
|
359
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/synth/account.ts","../../src/synth/field.ts","../../src/synth/codegen.ts","../../src/synth/match.ts"],"sourcesContent":["import type {\n AccountKind,\n Cardinality,\n Manifest,\n SectionMode,\n ManifestTransaction,\n ManifestAgent,\n ManifestPolicy,\n ManifestRelationship,\n ManifestRole,\n ManifestSettings,\n ManifestWebhookEndpoint,\n ManifestEgressConnection,\n ManifestWorkflow,\n} from \"../index.js\";\nimport { validateManifest } from \"../validate.js\";\nimport type { FieldSpec } from \"./field.js\";\n\n// Construct raíz del modelo \"config as actual code\" (patrón CDK/Pulumi): el tenant compone objects y\n// secciones en TS, y `synth()` COMPILA todo al manifiesto JSON canónico que `PUT /v1/account-config`\n// acepta — igual que `cdk synth` emite CloudFormation. El backend NO cambia; solo cambia la autoría.\n//\n// SRP: `Account` posee las colecciones de secciones y las drena en synth(); `ObjectBuilder` posee UN\n// object con sus campos y sus relationships salientes. DIP: los builders dependen del contrato\n// emitido (el `Manifest` de Zod), nunca de la capa HTTP.\n\ninterface ObjectMeta {\n title?: string;\n titleSingular?: string;\n description?: string;\n synonyms?: string[];\n titleFieldApiName?: string;\n config?: Record<string, unknown>;\n}\n\ninterface RelationshipMeta {\n target: string;\n cardinality: Cardinality;\n apiName?: string;\n title?: string;\n description?: string;\n}\n\nfunction compact<T extends Record<string, unknown>>(obj: T): T {\n return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as T;\n}\n\n/** Builder de UN object: acumula sus campos (orden declarado) y sus relationships salientes. */\nexport class ObjectBuilder {\n readonly apiName: string;\n private readonly meta: ObjectMeta;\n private readonly fields: Array<Record<string, unknown>> = [];\n private readonly referenceRecords: Array<{ properties: Record<string, unknown> }> = [];\n\n constructor(\n apiName: string,\n meta: ObjectMeta,\n private readonly account: Account,\n ) {\n this.apiName = apiName;\n this.meta = meta;\n }\n\n /** Añade un campo por su `apiName` y el spec de un helper (`text()`, `select()`, …). Encadenable. */\n field(apiName: string, spec: FieldSpec): this {\n this.fields.push(compact({ apiName, ...spec }));\n return this;\n }\n\n /**\n * Declara una relationship SALIENTE desde este object. El `source` se inyecta solo (es este object).\n * Encadenable.\n */\n relationship(\n apiNameOrMeta: string | RelationshipMeta,\n meta?: Omit<RelationshipMeta, \"apiName\">,\n ): this {\n const r = typeof apiNameOrMeta === \"string\" ? { apiName: apiNameOrMeta, ...meta! } : apiNameOrMeta;\n this.account.addRelationship(\n compact({\n apiName: r.apiName ?? `${this.apiName}_${r.target}`,\n source: this.apiName,\n target: r.target,\n cardinality: r.cardinality,\n title: r.title,\n description: r.description,\n }),\n );\n return this;\n }\n\n /** Añade un record de reference data (managed/desired-state por la clave de negocio del object). */\n reference(properties: Record<string, unknown>): this {\n this.referenceRecords.push({ properties });\n return this;\n }\n\n /** @internal — emite el object con sus campos/reference embebidos. */\n toJSON(): Record<string, unknown> {\n return compact({\n apiName: this.apiName,\n ...this.meta,\n fields: this.fields.length ? this.fields : undefined,\n reference: this.referenceRecords.length ? this.referenceRecords : undefined,\n });\n }\n}\n\n/** El construct raíz. El tenant exporta una instancia como `default`; el CLI llama `synth()`. */\nexport class Account {\n private readonly kind?: AccountKind;\n private readonly objects: ObjectBuilder[] = [];\n private readonly relationships: Array<Record<string, unknown>> = [];\n private readonly workflows: ManifestWorkflow[] = [];\n private readonly agents: ManifestAgent[] = [];\n private readonly transactions: ManifestTransaction[] = [];\n private readonly policies: ManifestPolicy[] = [];\n private readonly webhooks: ManifestWebhookEndpoint[] = [];\n private readonly egressConnections: ManifestEgressConnection[] = [];\n private readonly roles: ManifestRole[] = [];\n private settingsValue?: ManifestSettings;\n private packagesValue?: string[];\n // Modos de sección (`additive`/`authoritative`), por nombre de sección. Por defecto cada sección es\n // autoritativa; declarar `additive` evita que lo no declarado se archive. El CLI lo traduce a la\n // envoltura `{mode, items}` en la frontera HTTP.\n readonly modes: Record<string, SectionMode> = {};\n\n constructor(opts: { kind?: AccountKind } = {}) {\n this.kind = opts.kind;\n }\n\n /** Fija el modo de una sección (`additive` para no archivar lo no declarado). Encadenable. */\n mode(section: keyof Manifest, mode: SectionMode): this {\n this.modes[section as string] = mode;\n return this;\n }\n\n object(apiName: string, meta: ObjectMeta = {}): ObjectBuilder {\n const builder = new ObjectBuilder(apiName, meta, this);\n this.objects.push(builder);\n return builder;\n }\n\n /** @internal — un ObjectBuilder registra aquí su relationship saliente (con source ya inyectado). */\n addRelationship(relationship: Record<string, unknown>): void {\n this.relationships.push(relationship);\n }\n\n /**\n * Declara una relationship a nivel de cuenta, con `source`/`target` explícitos. La forma idiomática es\n * `object(...).relationship(...)` (inyecta el source); este método existe para el reverse-synth de\n * `pull`, que re-emite las relationships tal cual vienen del servidor. Encadenable.\n */\n relationship(relationship: ManifestRelationship): this {\n this.relationships.push(relationship as unknown as Record<string, unknown>);\n return this;\n }\n\n workflow(workflow: ManifestWorkflow): this {\n this.workflows.push(workflow);\n return this;\n }\n\n agent(agent: ManifestAgent): this {\n this.agents.push(agent);\n return this;\n }\n\n transaction(transaction: ManifestTransaction): this {\n this.transactions.push(transaction);\n return this;\n }\n\n policy(policy: ManifestPolicy): this {\n this.policies.push(policy);\n return this;\n }\n\n webhook(webhook: ManifestWebhookEndpoint): this {\n this.webhooks.push(webhook);\n return this;\n }\n\n /**\n * Declara una egress connection: el destino externo allowlisted + el tipo de auth al que un\n * `http_request` puede salir. El SECRET no se declara aquí (se setea out-of-band). Encadenable.\n */\n egressConnection(egressConnection: ManifestEgressConnection): this {\n this.egressConnections.push(egressConnection);\n return this;\n }\n\n role(role: ManifestRole): this {\n this.roles.push(role);\n return this;\n }\n\n settings(settings: ManifestSettings): this {\n this.settingsValue = settings;\n return this;\n }\n\n packages(...names: string[]): this {\n this.packagesValue = names;\n return this;\n }\n\n /**\n * Compila el construct al manifiesto JSON canónico y lo VALIDA contra el schema (fail-fast: lanza con\n * los problemas legibles si algo no cuadra). Es el `app.synth()` del modelo CDK.\n */\n synth(): Manifest {\n const draft = compact({\n kind: this.kind,\n objects: this.objects.length ? this.objects.map((o) => o.toJSON()) : undefined,\n relationships: this.relationships.length ? this.relationships : undefined,\n workflows: this.workflows.length ? this.workflows : undefined,\n agents: this.agents.length ? this.agents : undefined,\n transactions: this.transactions.length ? this.transactions : undefined,\n policies: this.policies.length ? this.policies : undefined,\n webhooks: this.webhooks.length ? this.webhooks : undefined,\n egressConnections: this.egressConnections.length ? this.egressConnections : undefined,\n roles: this.roles.length ? this.roles : undefined,\n settings: this.settingsValue,\n packages: this.packagesValue,\n });\n\n const result = validateManifest(draft);\n if (!result.ok) {\n const detail = result.problems.map((p) => ` - ${p.path}: ${p.message}`).join(\"\\n\");\n throw new Error(`El manifiesto generado por synth() es inválido:\\n${detail}`);\n }\n return result.manifest;\n }\n}\n","import type { DataType, PolicyAction } from \"../index.js\";\n\n// Helpers de campo tipados (config as code). Uno por `data_type`: el tenant nunca escribe el string\n// crudo `dataType` ni arma el `config` a mano — lo construye un helper que fija el tipo y tipa su config.\n//\n// OCP: añadir un `data_type` = un helper nuevo aquí (+ el enum en data-type.ts + su refine en\n// field.ts). El `ObjectBuilder` no cambia. SRP: cada helper solo arma el fragmento de UN campo.\n\n/** Flags comunes de almacenamiento/entrada de un campo no derivado. */\ninterface CommonFlags {\n title?: string;\n description?: string;\n synonyms?: string[];\n isRequired?: boolean;\n isUnique?: boolean;\n isIndexed?: boolean;\n embedInVector?: boolean;\n defaultValue?: unknown;\n}\n\n/** El fragmento emitido por un helper: todo lo de un campo MENOS su `apiName` (lo pone el builder). */\nexport interface FieldSpec {\n dataType: DataType;\n title?: string;\n description?: string;\n synonyms?: string[];\n isRequired?: boolean;\n isUnique?: boolean;\n isIndexed?: boolean;\n embedInVector?: boolean;\n defaultValue?: unknown;\n config?: Record<string, unknown>;\n}\n\n// Quita claves `undefined` para que el JSON emitido sea mínimo (igual que el `clean` del CLI viejo).\nfunction compact<T extends Record<string, unknown>>(obj: T): T {\n return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as T;\n}\n\nfunction flagsOf(opts: CommonFlags): Partial<FieldSpec> {\n return compact({\n title: opts.title,\n description: opts.description,\n synonyms: opts.synonyms,\n isRequired: opts.isRequired,\n isUnique: opts.isUnique,\n isIndexed: opts.isIndexed,\n embedInVector: opts.embedInVector,\n defaultValue: opts.defaultValue,\n });\n}\n\nexport function text(opts: CommonFlags = {}): FieldSpec {\n return { dataType: \"text\", ...flagsOf(opts) };\n}\n\nexport function number(opts: CommonFlags & { min?: number; max?: number; decimals?: number } = {}): FieldSpec {\n const config = compact({ min: opts.min, max: opts.max, decimals: opts.decimals });\n return { dataType: \"number\", ...flagsOf(opts), ...(Object.keys(config).length ? { config } : {}) };\n}\n\nexport function boolean(opts: CommonFlags = {}): FieldSpec {\n return { dataType: \"boolean\", ...flagsOf(opts) };\n}\n\nexport function date(opts: CommonFlags = {}): FieldSpec {\n return { dataType: \"date\", ...flagsOf(opts) };\n}\n\nexport function timestamp(opts: CommonFlags = {}): FieldSpec {\n return { dataType: \"timestamp\", ...flagsOf(opts) };\n}\n\ntype Option = string | { value: string; label?: string };\n\nexport function select(opts: CommonFlags & { options: Option[] }): FieldSpec {\n return { dataType: \"select\", ...flagsOf(opts), config: { options: opts.options } };\n}\n\nexport function multiselect(opts: CommonFlags & { options: Option[] }): FieldSpec {\n return { dataType: \"multiselect\", ...flagsOf(opts), config: { options: opts.options } };\n}\n\n// `reference`: linked record (targetObject) XOR belongs_to (relationship). El tipo lo fuerza vía unión.\ntype ReferenceConfig = { targetObject: string; relationship?: never } | { relationship: string; targetObject?: never };\n\nexport function reference(opts: CommonFlags & ReferenceConfig): FieldSpec {\n const config = compact({ targetObject: opts.targetObject, relationship: opts.relationship });\n return { dataType: \"reference\", ...flagsOf(opts), config };\n}\n\nexport function file(\n opts: CommonFlags & {\n maxCount?: number;\n maxSizeBytes?: number;\n acceptedContentTypes?: string[];\n visibility?: \"public\" | \"private\";\n } = {},\n): FieldSpec {\n const config = compact({\n maxCount: opts.maxCount,\n maxSizeBytes: opts.maxSizeBytes,\n acceptedContentTypes: opts.acceptedContentTypes,\n visibility: opts.visibility,\n });\n return { dataType: \"file\", ...flagsOf(opts), ...(Object.keys(config).length ? { config } : {}) };\n}\n\n// Tipos DERIVADOS: no aceptan flags de entrada/almacenamiento (el tipo lo impide — solo `title`/`desc`).\ntype DerivedMeta = Pick<CommonFlags, \"title\" | \"description\" | \"synonyms\">;\n\nexport function formula(opts: DerivedMeta & { expression: string; resultType?: \"number\" | \"text\" | \"boolean\" }): FieldSpec {\n const config = compact({ expression: opts.expression, resultType: opts.resultType });\n return { dataType: \"formula\", ...flagsOf(opts), config };\n}\n\nexport function rollup(\n opts: DerivedMeta & { relationship: string; aggregate: \"sum\" | \"count\" | \"avg\" | \"min\" | \"max\"; target?: string },\n): FieldSpec {\n const config = compact({ relationship: opts.relationship, aggregate: opts.aggregate, target: opts.target });\n return { dataType: \"rollup\", ...flagsOf(opts), config };\n}\n\n// Mapa de helpers por tipo — usado por el test de cobertura OCP (todo tipo del enum tiene su helper).\nexport const fieldHelpers: Record<DataType, (...args: never[]) => FieldSpec> = {\n text,\n number,\n boolean,\n date,\n timestamp,\n select: select as never,\n multiselect: multiselect as never,\n reference: reference as never,\n file,\n formula: formula as never,\n rollup: rollup as never,\n};\n\n// Re-export para que el builder de policy tipe sus acciones sin un import extra del tenant.\nexport type { PolicyAction };\n","import type { DataType, Manifest, ManifestObject } from \"../index.js\";\nimport { dataTypeEnum } from \"../index.js\";\n\n// Reverse synth: de un `Manifest` (lo que devuelve `pull` del servidor) genera el SOURCE de un\n// `hablala.config.ts` equivalente — el análogo TS del `terraform import` que emite HCL. Así `pull`\n// mantiene UN solo formato de autoría (TS), sin bifurcar a JSON. El round-trip\n// `synth(import(manifestToConfigSource(m)))` debe reproducir `m` (lo cubre el test).\n\n/** Desenvuelve una sección (array desnudo o `{mode, items}`) a su lista de items. */\nfunction itemsOf<T>(section: T[] | { mode: string; items: T[] } | undefined): T[] {\n if (!section) return [];\n return Array.isArray(section) ? section : section.items;\n}\n\n// Los flags que un helper de campo acepta además de su config propia.\nconst FIELD_FLAGS = [\"title\", \"description\", \"synonyms\", \"isRequired\", \"isUnique\", \"isIndexed\", \"embedInVector\", \"defaultValue\"] as const;\n\n// Config propio de cada tipo → argumentos del helper (aplanados al mismo nivel que los flags).\nfunction helperArgs(dataType: DataType, field: Record<string, unknown>): Record<string, unknown> {\n const args: Record<string, unknown> = {};\n for (const flag of FIELD_FLAGS) if (field[flag] !== undefined) args[flag] = field[flag];\n const config = (field.config ?? {}) as Record<string, unknown>;\n for (const [k, v] of Object.entries(config)) args[k] = v;\n return args;\n}\n\nfunction literal(value: unknown): string {\n return JSON.stringify(value, null, 2)\n .split(\"\\n\")\n .map((line, i) => (i === 0 ? line : ` ${line}`))\n .join(\"\\n\");\n}\n\nfunction objectSource(obj: ManifestObject): string {\n const { apiName, fields, reference, ...meta } = obj as Record<string, unknown> & {\n apiName: string;\n };\n const metaLiteral = Object.keys(meta).length ? `, ${literal(meta)}` : \"\";\n let src = ` account.object(${JSON.stringify(apiName)}${metaLiteral})`;\n\n for (const field of (fields as Array<Record<string, unknown>>) ?? []) {\n const dataType = field.dataType as DataType;\n const helper = dataTypeEnum.options.includes(dataType) ? dataType : \"text\";\n const args = helperArgs(dataType, field);\n const argLiteral = Object.keys(args).length ? literal(args) : \"\";\n src += `\\n .field(${JSON.stringify(field.apiName)}, ${helper}(${argLiteral}))`;\n }\n for (const ref of (reference as Array<{ properties: unknown }>) ?? []) {\n src += `\\n .reference(${literal(ref.properties)})`;\n }\n return src + \";\";\n}\n\n/**\n * Genera el source de `hablala.config.ts` a partir de un manifiesto. Objects y relationships se emiten\n * con los builders (autoría idiomática); las demás secciones, con los métodos crudos `account.X({...})`.\n */\nexport function manifestToConfigSource(manifest: Manifest): string {\n const lines: string[] = [\n `// Generado por \\`hablala pull\\`. Es config as code: edítalo como TypeScript.`,\n `import {`,\n ` Account,`,\n ` text, number, boolean, date, timestamp,`,\n ` select, multiselect, reference, file, formula, rollup,`,\n `} from \"@hablala/schema/synth\";`,\n ``,\n `const account = new Account(${manifest.kind ? `{ kind: ${JSON.stringify(manifest.kind)} }` : \"\"});`,\n ``,\n ];\n\n for (const obj of itemsOf(manifest.objects)) lines.push(objectSource(obj), \"\");\n\n // Relationships a nivel de cuenta (con source/target explícitos) y las demás secciones, como métodos\n // crudos `account.X({...})` — autoría fiel y round-trip exacto.\n const rawSections: Array<[keyof Manifest, string]> = [\n [\"relationships\", \"relationship\"],\n [\"workflows\", \"workflow\"],\n [\"agents\", \"agent\"],\n [\"transactions\", \"transaction\"],\n [\"policies\", \"policy\"],\n [\"webhooks\", \"webhook\"],\n [\"roles\", \"role\"],\n ];\n for (const [section, method] of rawSections) {\n for (const item of itemsOf(manifest[section] as never)) {\n lines.push(`account.${method}(${literal(item)});`, \"\");\n }\n }\n\n if (manifest.settings) lines.push(`account.settings(${literal(manifest.settings)});`, \"\");\n if (manifest.packages?.length) {\n lines.push(`account.packages(${manifest.packages.map((p) => JSON.stringify(p)).join(\", \")});`, \"\");\n }\n\n lines.push(`export default account;`, \"\");\n return lines.join(\"\\n\");\n}\n","import type { Manifest } from \"../index.js\";\n\n// Comparación SEMÁNTICA de manifiestos (para `pull --check`): ¿el estado local declarado está contenido\n// en el del servidor? El schema fija la forma y el casing, así que basta un subset-match estructural\n// sobre el JSON canónico (sin normalización de texto).\n\n// Claves de negocio por las que se casa un elemento de una lista con su contraparte del server (match\n// key de cada sección). Un elemento local debe encontrar su gemelo en el server por esta clave.\nconst MATCH_KEYS = [\"apiName\", \"slug\", \"handle\", \"name\", \"protocol\", \"domain\", \"email\", \"url\"];\n\n/**\n * ¿El estado local declarado está CONTENIDO en el del server? (drift check de `pull --check`): cada\n * campo/elemento declarado localmente debe tener su gemelo en el server con el mismo valor. El server\n * PUEDE tener más (elementos o claves no declarados) — eso no es drift.\n */\nexport function manifestsMatch(local: Manifest, server: Manifest): boolean {\n return isSubset(local as unknown, server as unknown);\n}\n\nfunction isSubset(local: unknown, server: unknown): boolean {\n if (Array.isArray(local)) {\n if (!Array.isArray(server)) return false;\n // Cada elemento local debe casar con ALGÚN elemento del server (por match key si lo hay, si no por\n // subset estructural). El server puede tener elementos extra (no es drift).\n return local.every((item) => server.some((candidate) => matchesElement(item, candidate)));\n }\n if (local && typeof local === \"object\") {\n if (!server || typeof server !== \"object\" || Array.isArray(server)) return false;\n const s = server as Record<string, unknown>;\n return Object.entries(local as Record<string, unknown>).every(\n ([key, value]) => key in s && isSubset(value, s[key]),\n );\n }\n return local === server;\n}\n\n// Dos elementos de lista casan si comparten su match key (y entonces el local es subset del server), o,\n// si no hay match key, por subset estructural directo.\nfunction matchesElement(local: unknown, candidate: unknown): boolean {\n if (local && typeof local === \"object\" && candidate && typeof candidate === \"object\") {\n const l = local as Record<string, unknown>;\n const c = candidate as Record<string, unknown>;\n const key = MATCH_KEYS.find((k) => k in l);\n if (key) return l[key] === c[key] && isSubset(local, candidate);\n }\n return isSubset(local, candidate);\n}\n"],"mappings":";;;;;;AA2CA,SAAS,QAA2C,KAAW;AAC7D,SAAO,OAAO,YAAY,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,CAAC;AAClF;AAGO,IAAM,gBAAN,MAAoB;AAAA,EAMzB,YACE,SACA,MACiB,SACjB;AADiB;AAEjB,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAJmB;AAAA,EARV;AAAA,EACQ;AAAA,EACA,SAAyC,CAAC;AAAA,EAC1C,mBAAmE,CAAC;AAAA;AAAA,EAYrF,MAAM,SAAiB,MAAuB;AAC5C,SAAK,OAAO,KAAK,QAAQ,EAAE,SAAS,GAAG,KAAK,CAAC,CAAC;AAC9C,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aACE,eACA,MACM;AACN,UAAM,IAAI,OAAO,kBAAkB,WAAW,EAAE,SAAS,eAAe,GAAG,KAAM,IAAI;AACrF,SAAK,QAAQ;AAAA,MACX,QAAQ;AAAA,QACN,SAAS,EAAE,WAAW,GAAG,KAAK,OAAO,IAAI,EAAE,MAAM;AAAA,QACjD,QAAQ,KAAK;AAAA,QACb,QAAQ,EAAE;AAAA,QACV,aAAa,EAAE;AAAA,QACf,OAAO,EAAE;AAAA,QACT,aAAa,EAAE;AAAA,MACjB,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,UAAU,YAA2C;AACnD,SAAK,iBAAiB,KAAK,EAAE,WAAW,CAAC;AACzC,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,SAAkC;AAChC,WAAO,QAAQ;AAAA,MACb,SAAS,KAAK;AAAA,MACd,GAAG,KAAK;AAAA,MACR,QAAQ,KAAK,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