@danielfgray/pg-sourcerer 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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +104 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +133 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +47 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +129 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +41 -0
- package/dist/errors.js.map +1 -0
- package/dist/generate.d.ts +75 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +183 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +4 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +229 -0
- package/dist/init.js.map +1 -0
- package/dist/ir/index.d.ts +7 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +7 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/relation-graph.d.ts +113 -0
- package/dist/ir/relation-graph.d.ts.map +1 -0
- package/dist/ir/relation-graph.js +232 -0
- package/dist/ir/relation-graph.js.map +1 -0
- package/dist/ir/semantic-ir.d.ts +448 -0
- package/dist/ir/semantic-ir.d.ts.map +1 -0
- package/dist/ir/semantic-ir.js +138 -0
- package/dist/ir/semantic-ir.js.map +1 -0
- package/dist/ir/smart-tags.d.ts +24 -0
- package/dist/ir/smart-tags.d.ts.map +1 -0
- package/dist/ir/smart-tags.js +30 -0
- package/dist/ir/smart-tags.js.map +1 -0
- package/dist/lib/conjure.d.ts +431 -0
- package/dist/lib/conjure.d.ts.map +1 -0
- package/dist/lib/conjure.js +697 -0
- package/dist/lib/conjure.js.map +1 -0
- package/dist/lib/field-utils.d.ts +61 -0
- package/dist/lib/field-utils.d.ts.map +1 -0
- package/dist/lib/field-utils.js +132 -0
- package/dist/lib/field-utils.js.map +1 -0
- package/dist/lib/hex.d.ts +117 -0
- package/dist/lib/hex.d.ts.map +1 -0
- package/dist/lib/hex.js +185 -0
- package/dist/lib/hex.js.map +1 -0
- package/dist/plugins/arktype.d.ts +11 -0
- package/dist/plugins/arktype.d.ts.map +1 -0
- package/dist/plugins/arktype.js +207 -0
- package/dist/plugins/arktype.js.map +1 -0
- package/dist/plugins/effect-model.d.ts +10 -0
- package/dist/plugins/effect-model.d.ts.map +1 -0
- package/dist/plugins/effect-model.js +261 -0
- package/dist/plugins/effect-model.js.map +1 -0
- package/dist/plugins/kysely-queries.d.ts +7 -0
- package/dist/plugins/kysely-queries.d.ts.map +1 -0
- package/dist/plugins/kysely-queries.js +380 -0
- package/dist/plugins/kysely-queries.js.map +1 -0
- package/dist/plugins/sql-queries.d.ts +6 -0
- package/dist/plugins/sql-queries.d.ts.map +1 -0
- package/dist/plugins/sql-queries.js +249 -0
- package/dist/plugins/sql-queries.js.map +1 -0
- package/dist/plugins/types.d.ts +18 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +263 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/zod.d.ts +11 -0
- package/dist/plugins/zod.d.ts.map +1 -0
- package/dist/plugins/zod.js +180 -0
- package/dist/plugins/zod.js.map +1 -0
- package/dist/services/artifact-store.d.ts +55 -0
- package/dist/services/artifact-store.d.ts.map +1 -0
- package/dist/services/artifact-store.js +51 -0
- package/dist/services/artifact-store.js.map +1 -0
- package/dist/services/config-loader.d.ts +45 -0
- package/dist/services/config-loader.d.ts.map +1 -0
- package/dist/services/config-loader.js +113 -0
- package/dist/services/config-loader.js.map +1 -0
- package/dist/services/emissions.d.ts +89 -0
- package/dist/services/emissions.d.ts.map +1 -0
- package/dist/services/emissions.js +194 -0
- package/dist/services/emissions.js.map +1 -0
- package/dist/services/file-builder.d.ts +81 -0
- package/dist/services/file-builder.d.ts.map +1 -0
- package/dist/services/file-builder.js +112 -0
- package/dist/services/file-builder.js.map +1 -0
- package/dist/services/file-writer.d.ts +57 -0
- package/dist/services/file-writer.d.ts.map +1 -0
- package/dist/services/file-writer.js +76 -0
- package/dist/services/file-writer.js.map +1 -0
- package/dist/services/inflection.d.ts +227 -0
- package/dist/services/inflection.d.ts.map +1 -0
- package/dist/services/inflection.js +350 -0
- package/dist/services/inflection.js.map +1 -0
- package/dist/services/introspection.d.ts +46 -0
- package/dist/services/introspection.d.ts.map +1 -0
- package/dist/services/introspection.js +99 -0
- package/dist/services/introspection.js.map +1 -0
- package/dist/services/ir-builder.d.ts +46 -0
- package/dist/services/ir-builder.d.ts.map +1 -0
- package/dist/services/ir-builder.js +923 -0
- package/dist/services/ir-builder.js.map +1 -0
- package/dist/services/ir.d.ts +28 -0
- package/dist/services/ir.d.ts.map +1 -0
- package/dist/services/ir.js +25 -0
- package/dist/services/ir.js.map +1 -0
- package/dist/services/pg-types.d.ts +197 -0
- package/dist/services/pg-types.d.ts.map +1 -0
- package/dist/services/pg-types.js +274 -0
- package/dist/services/pg-types.js.map +1 -0
- package/dist/services/plugin-meta.d.ts +33 -0
- package/dist/services/plugin-meta.d.ts.map +1 -0
- package/dist/services/plugin-meta.js +24 -0
- package/dist/services/plugin-meta.js.map +1 -0
- package/dist/services/plugin-runner.d.ts +52 -0
- package/dist/services/plugin-runner.d.ts.map +1 -0
- package/dist/services/plugin-runner.js +182 -0
- package/dist/services/plugin-runner.js.map +1 -0
- package/dist/services/plugin.d.ts +286 -0
- package/dist/services/plugin.d.ts.map +1 -0
- package/dist/services/plugin.js +132 -0
- package/dist/services/plugin.js.map +1 -0
- package/dist/services/smart-tags-parser.d.ts +37 -0
- package/dist/services/smart-tags-parser.d.ts.map +1 -0
- package/dist/services/smart-tags-parser.js +79 -0
- package/dist/services/smart-tags-parser.js.map +1 -0
- package/dist/services/symbols.d.ts +85 -0
- package/dist/services/symbols.d.ts.map +1 -0
- package/dist/services/symbols.js +128 -0
- package/dist/services/symbols.js.map +1 -0
- package/dist/services/type-hints.d.ts +62 -0
- package/dist/services/type-hints.d.ts.map +1 -0
- package/dist/services/type-hints.js +117 -0
- package/dist/services/type-hints.js.map +1 -0
- package/dist/testing.d.ts +77 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +84 -0
- package/dist/testing.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod Plugin - Generate Zod schemas for entities
|
|
3
|
+
*
|
|
4
|
+
* Generates Zod schemas for Row, Insert, Update, and Patch shapes,
|
|
5
|
+
* with inferred TypeScript types.
|
|
6
|
+
*/
|
|
7
|
+
import { Schema as S } from "effect";
|
|
8
|
+
import { definePlugin } from "../services/plugin.js";
|
|
9
|
+
import { TsType } from "../services/pg-types.js";
|
|
10
|
+
import { getTableEntities, getEnumEntities } from "../ir/semantic-ir.js";
|
|
11
|
+
import { conjure } from "../lib/conjure.js";
|
|
12
|
+
import { isUuidType, isDateType, resolveFieldType } from "../lib/field-utils.js";
|
|
13
|
+
const { ts, exp, obj } = conjure;
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Configuration
|
|
16
|
+
// ============================================================================
|
|
17
|
+
const ZodPluginConfig = S.Struct({
|
|
18
|
+
/** Output directory relative to main outputDir */
|
|
19
|
+
outputDir: S.String,
|
|
20
|
+
/** Export inferred types alongside schemas */
|
|
21
|
+
exportTypes: S.Boolean,
|
|
22
|
+
});
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Zod Schema Builders (pure functions)
|
|
25
|
+
// ============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Build z.<method>() and chain additional methods
|
|
28
|
+
*/
|
|
29
|
+
const buildZodChain = (baseMethod, chainMethods) => chainMethods
|
|
30
|
+
.reduce((chain, method) => chain.method(method), conjure.id("z").method(baseMethod))
|
|
31
|
+
.build();
|
|
32
|
+
/**
|
|
33
|
+
* Build z.enum([...values])
|
|
34
|
+
*/
|
|
35
|
+
const buildZodEnum = (values) => conjure
|
|
36
|
+
.id("z")
|
|
37
|
+
.method("enum", [conjure.arr(...values.map(v => conjure.str(v))).build()])
|
|
38
|
+
.build();
|
|
39
|
+
/**
|
|
40
|
+
* Build z.array(<inner>)
|
|
41
|
+
*/
|
|
42
|
+
const buildZodArray = (inner) => conjure.id("z").method("array", [inner]).build();
|
|
43
|
+
/**
|
|
44
|
+
* Add method calls to an existing expression
|
|
45
|
+
*/
|
|
46
|
+
const chainZodMethods = (expr, methods) => methods.reduce((chain, method) => chain.method(method), conjure.chain(expr)).build();
|
|
47
|
+
/**
|
|
48
|
+
* Map TypeScript type to Zod method name
|
|
49
|
+
*/
|
|
50
|
+
const tsTypeToZodMethod = (tsType) => {
|
|
51
|
+
switch (tsType) {
|
|
52
|
+
case TsType.String:
|
|
53
|
+
return "string";
|
|
54
|
+
case TsType.Number:
|
|
55
|
+
return "number";
|
|
56
|
+
case TsType.Boolean:
|
|
57
|
+
return "boolean";
|
|
58
|
+
case TsType.BigInt:
|
|
59
|
+
return "bigint";
|
|
60
|
+
case TsType.Date:
|
|
61
|
+
return "date";
|
|
62
|
+
case TsType.Buffer:
|
|
63
|
+
case TsType.Unknown:
|
|
64
|
+
default:
|
|
65
|
+
return "unknown";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Apply nullable/optional/array modifiers to a base schema
|
|
70
|
+
*/
|
|
71
|
+
const applyFieldModifiers = (schema, field) => {
|
|
72
|
+
const modifiers = [];
|
|
73
|
+
if (field.nullable)
|
|
74
|
+
modifiers.push("nullable");
|
|
75
|
+
if (field.optional)
|
|
76
|
+
modifiers.push("optional");
|
|
77
|
+
const withArray = field.isArray ? buildZodArray(schema) : schema;
|
|
78
|
+
return modifiers.length > 0 ? chainZodMethods(withArray, modifiers) : withArray;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Resolve a field to its Zod schema expression
|
|
82
|
+
*/
|
|
83
|
+
const resolveFieldZodSchema = (field, ctx) => {
|
|
84
|
+
const resolved = resolveFieldType(field, ctx.enums, ctx.extensions);
|
|
85
|
+
// Enum → z.enum([...values])
|
|
86
|
+
if (resolved.enumDef) {
|
|
87
|
+
return applyFieldModifiers(buildZodEnum(resolved.enumDef.values), field);
|
|
88
|
+
}
|
|
89
|
+
// UUID → z.string().uuid()
|
|
90
|
+
if (isUuidType(field)) {
|
|
91
|
+
return applyFieldModifiers(buildZodChain("string", ["uuid"]), field);
|
|
92
|
+
}
|
|
93
|
+
// Date/timestamp → z.coerce.date()
|
|
94
|
+
if (isDateType(field)) {
|
|
95
|
+
const dateSchema = conjure.id("z").prop("coerce").method("date").build();
|
|
96
|
+
return applyFieldModifiers(dateSchema, field);
|
|
97
|
+
}
|
|
98
|
+
// Standard type mapping
|
|
99
|
+
return applyFieldModifiers(buildZodChain(tsTypeToZodMethod(resolved.tsType), []), field);
|
|
100
|
+
};
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// Shape → Statement Generation
|
|
103
|
+
// ============================================================================
|
|
104
|
+
/**
|
|
105
|
+
* Build z.object({...}) expression from shape fields
|
|
106
|
+
*/
|
|
107
|
+
const buildShapeZodObject = (shape, ctx) => {
|
|
108
|
+
const objBuilder = shape.fields.reduce((builder, field) => builder.prop(field.name, resolveFieldZodSchema(field, ctx)), obj());
|
|
109
|
+
return conjure.id("z").method("object", [objBuilder.build()]).build();
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Generate schema const + optional inferred type for a shape
|
|
113
|
+
*/
|
|
114
|
+
const generateShapeStatements = (shape, entityName, shapeKind, ctx, exportTypes) => {
|
|
115
|
+
const symbolCtx = { capability: "schemas:zod", entity: entityName, shape: shapeKind };
|
|
116
|
+
const schemaExpr = buildShapeZodObject(shape, ctx);
|
|
117
|
+
const schemaStatement = exp.const(shape.name, symbolCtx, schemaExpr);
|
|
118
|
+
if (!exportTypes) {
|
|
119
|
+
return [schemaStatement];
|
|
120
|
+
}
|
|
121
|
+
// Generate: export type ShapeName = z.infer<typeof ShapeName>
|
|
122
|
+
const inferType = ts.qualifiedRef("z", "infer", [ts.typeof(shape.name)]);
|
|
123
|
+
const typeStatement = exp.type(shape.name, symbolCtx, inferType);
|
|
124
|
+
return [schemaStatement, typeStatement];
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Collect all defined shapes from an entity as [kind, shape] pairs
|
|
128
|
+
*/
|
|
129
|
+
const collectShapes = (entity) => [
|
|
130
|
+
["row", entity.shapes.row],
|
|
131
|
+
["insert", entity.shapes.insert],
|
|
132
|
+
["update", entity.shapes.update],
|
|
133
|
+
].filter((entry) => entry[1] != null);
|
|
134
|
+
/**
|
|
135
|
+
* Generate all statements for an entity's shapes
|
|
136
|
+
*/
|
|
137
|
+
const generateEntityStatements = (entity, ctx, exportTypes) => collectShapes(entity).flatMap(([kind, shape]) => generateShapeStatements(shape, entity.name, kind, ctx, exportTypes));
|
|
138
|
+
// ============================================================================
|
|
139
|
+
// Plugin Definition
|
|
140
|
+
// ============================================================================
|
|
141
|
+
/**
|
|
142
|
+
* Zod Plugin
|
|
143
|
+
*
|
|
144
|
+
* Generates Zod schemas for each entity's shapes (base, Insert, Update)
|
|
145
|
+
* with inferred TypeScript types.
|
|
146
|
+
*/
|
|
147
|
+
export const zodPlugin = definePlugin({
|
|
148
|
+
name: "zod",
|
|
149
|
+
provides: ["schemas:zod", "schemas"],
|
|
150
|
+
configSchema: ZodPluginConfig,
|
|
151
|
+
inflection: {
|
|
152
|
+
outputFile: ctx => `${ctx.entityName}.ts`,
|
|
153
|
+
symbolName: (entityName, artifactKind) => `${entityName}${artifactKind}`,
|
|
154
|
+
},
|
|
155
|
+
run: (ctx, config) => {
|
|
156
|
+
const enumEntities = getEnumEntities(ctx.ir);
|
|
157
|
+
const fieldCtx = { enums: enumEntities, extensions: ctx.ir.extensions };
|
|
158
|
+
getTableEntities(ctx.ir)
|
|
159
|
+
.filter(entity => entity.tags.omit !== true)
|
|
160
|
+
.forEach(entity => {
|
|
161
|
+
const statements = generateEntityStatements(entity, fieldCtx, config.exportTypes);
|
|
162
|
+
const entityName = ctx.inflection.entityName(entity.pgClass, entity.tags);
|
|
163
|
+
const fileNameCtx = {
|
|
164
|
+
entityName,
|
|
165
|
+
pgName: entity.pgName,
|
|
166
|
+
schema: entity.schemaName,
|
|
167
|
+
inflection: ctx.inflection,
|
|
168
|
+
entity,
|
|
169
|
+
};
|
|
170
|
+
const fileName = ctx.pluginInflection.outputFile(fileNameCtx);
|
|
171
|
+
const filePath = `${config.outputDir}/${fileName}`;
|
|
172
|
+
ctx
|
|
173
|
+
.file(filePath)
|
|
174
|
+
.import({ kind: "package", names: ["z"], from: "zod" })
|
|
175
|
+
.ast(conjure.symbolProgram(...statements))
|
|
176
|
+
.emit();
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=zod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/plugins/zod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAQjD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AAEjC,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,C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EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1E,MAAM,WAAW,GAAoB;gBACnC,UAAU;gBACV,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,MAAM,CAAC,UAAU;gBACzB,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,MAAM;aACP,CAAC;YACF,MAAM,QAAQ,GAAG,GAAG,CAAC,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC9D,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,SAAS,IAAI,QAAQ,EAAE,CAAC;YAEnD,GAAG;iBACA,IAAI,CAAC,QAAQ,CAAC;iBACd,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;iBACtD,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,CAAC;iBACzC,IAAI,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Store Service
|
|
3
|
+
*
|
|
4
|
+
* Provides plugin-to-plugin data passing via artifacts.
|
|
5
|
+
* Plugins can store artifacts keyed by capability, and downstream
|
|
6
|
+
* plugins can retrieve them.
|
|
7
|
+
*
|
|
8
|
+
* This service is stateful - created once per run and shared across plugins.
|
|
9
|
+
*/
|
|
10
|
+
import { Context, Layer } from "effect";
|
|
11
|
+
import type { Artifact, CapabilityKey } from "../ir/semantic-ir.js";
|
|
12
|
+
/**
|
|
13
|
+
* Artifact store interface
|
|
14
|
+
*/
|
|
15
|
+
export interface ArtifactStoreImpl {
|
|
16
|
+
/**
|
|
17
|
+
* Get an artifact by capability key
|
|
18
|
+
*/
|
|
19
|
+
readonly get: (capability: CapabilityKey) => Artifact | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Store an artifact for a capability
|
|
22
|
+
* @param capability - The capability key
|
|
23
|
+
* @param plugin - The plugin name (for attribution)
|
|
24
|
+
* @param data - The artifact data
|
|
25
|
+
*/
|
|
26
|
+
readonly set: (capability: CapabilityKey, plugin: string, data: unknown) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Get all artifacts as a readonly map
|
|
29
|
+
*/
|
|
30
|
+
readonly getAll: () => ReadonlyMap<CapabilityKey, Artifact>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new artifact store instance.
|
|
34
|
+
* Used by PluginRunner to create a single shared instance per run.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createArtifactStore(): ArtifactStoreImpl;
|
|
37
|
+
declare const ArtifactStore_base: Context.TagClass<ArtifactStore, "ArtifactStore", ArtifactStoreImpl>;
|
|
38
|
+
/**
|
|
39
|
+
* ArtifactStore service tag
|
|
40
|
+
*
|
|
41
|
+
* Usage in plugins:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const store = yield* ArtifactStore
|
|
44
|
+
* const prev = store.get("types")
|
|
45
|
+
* store.set("schemas", pluginName, myData)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class ArtifactStore extends ArtifactStore_base {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Live layer - creates a fresh artifact store
|
|
52
|
+
*/
|
|
53
|
+
export declare const ArtifactStoreLive: Layer.Layer<ArtifactStore, never, never>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=artifact-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.d.ts","sourceRoot":"","sources":["../../src/services/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAgB,OAAO,EAAE,KAAK,EAAwB,MAAM,QAAQ,CAAA;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEnE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,KAAK,QAAQ,GAAG,SAAS,CAAA;IAEjE;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IAEhF;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,WAAW,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;CAC5D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,iBAAiB,CA2BvD;;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,kBAGhC;CAAG;AAEN;;GAEG;AACH,eAAO,MAAM,iBAAiB,0CAAiD,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Store Service
|
|
3
|
+
*
|
|
4
|
+
* Provides plugin-to-plugin data passing via artifacts.
|
|
5
|
+
* Plugins can store artifacts keyed by capability, and downstream
|
|
6
|
+
* plugins can retrieve them.
|
|
7
|
+
*
|
|
8
|
+
* This service is stateful - created once per run and shared across plugins.
|
|
9
|
+
*/
|
|
10
|
+
import { Array as Arr, Context, Layer, MutableHashMap, pipe } from "effect";
|
|
11
|
+
/**
|
|
12
|
+
* Create a new artifact store instance.
|
|
13
|
+
* Used by PluginRunner to create a single shared instance per run.
|
|
14
|
+
*/
|
|
15
|
+
export function createArtifactStore() {
|
|
16
|
+
const artifacts = MutableHashMap.empty();
|
|
17
|
+
return {
|
|
18
|
+
get: (capability) => {
|
|
19
|
+
const result = MutableHashMap.get(artifacts, capability);
|
|
20
|
+
return result._tag === "Some" ? result.value : undefined;
|
|
21
|
+
},
|
|
22
|
+
set: (capability, plugin, data) => {
|
|
23
|
+
MutableHashMap.set(artifacts, capability, {
|
|
24
|
+
capability,
|
|
25
|
+
plugin,
|
|
26
|
+
data,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
getAll: () => pipe([...artifacts], Arr.reduce(new Map(), (map, [key, value]) => {
|
|
30
|
+
map.set(key, value);
|
|
31
|
+
return map;
|
|
32
|
+
}), (map) => map),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ArtifactStore service tag
|
|
37
|
+
*
|
|
38
|
+
* Usage in plugins:
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const store = yield* ArtifactStore
|
|
41
|
+
* const prev = store.get("types")
|
|
42
|
+
* store.set("schemas", pluginName, myData)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class ArtifactStore extends Context.Tag("ArtifactStore")() {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Live layer - creates a fresh artifact store
|
|
49
|
+
*/
|
|
50
|
+
export const ArtifactStoreLive = Layer.sync(ArtifactStore, createArtifactStore);
|
|
51
|
+
//# sourceMappingURL=artifact-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.js","sourceRoot":"","sources":["../../src/services/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AA0B3E;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,SAAS,GAAG,cAAc,CAAC,KAAK,EAA2B,CAAA;IAEjE,OAAO;QACL,GAAG,EAAE,CAAC,UAAyB,EAAE,EAAE;YACjC,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;YACxD,OAAO,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAC1D,CAAC;QAED,GAAG,EAAE,CAAC,UAAyB,EAAE,MAAc,EAAE,IAAa,EAAE,EAAE;YAChE,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE;gBACxC,UAAU;gBACV,MAAM;gBACN,IAAI;aACL,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,CACX,IAAI,CACF,CAAC,GAAG,SAAS,CAAC,EACd,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,EAA2B,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACnE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACnB,OAAO,GAAG,CAAA;QACZ,CAAC,CAAC,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAA2C,CACrD;KACJ,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAG5D;CAAG;AAEN;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Loader Service
|
|
3
|
+
*
|
|
4
|
+
* Loads and validates pgsourcerer.config.{ts,js,mjs} using lilconfig.
|
|
5
|
+
* Wraps the async config loading in Effect for proper error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { Context, Effect, Layer } from "effect";
|
|
8
|
+
import { type ConfigInput, type ResolvedConfig } from "../config.js";
|
|
9
|
+
import { ConfigNotFound, ConfigInvalid } from "../errors.js";
|
|
10
|
+
/**
|
|
11
|
+
* Config Loader service interface
|
|
12
|
+
*/
|
|
13
|
+
export interface ConfigLoader {
|
|
14
|
+
/**
|
|
15
|
+
* Load configuration from file.
|
|
16
|
+
* @param configPath - Optional explicit path to config file
|
|
17
|
+
* @param searchFrom - Directory to search from (default: cwd)
|
|
18
|
+
*/
|
|
19
|
+
readonly load: (options?: {
|
|
20
|
+
readonly configPath?: string;
|
|
21
|
+
readonly searchFrom?: string;
|
|
22
|
+
}) => Effect.Effect<ResolvedConfig, ConfigNotFound | ConfigInvalid>;
|
|
23
|
+
}
|
|
24
|
+
declare const ConfigLoaderService_base: Context.TagClass<ConfigLoaderService, "ConfigLoader", ConfigLoader>;
|
|
25
|
+
/**
|
|
26
|
+
* ConfigLoader service tag
|
|
27
|
+
*/
|
|
28
|
+
export declare class ConfigLoaderService extends ConfigLoaderService_base {
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a ConfigLoader implementation
|
|
32
|
+
*/
|
|
33
|
+
export declare function createConfigLoader(): ConfigLoader;
|
|
34
|
+
/**
|
|
35
|
+
* Live layer for ConfigLoader
|
|
36
|
+
*/
|
|
37
|
+
export declare const ConfigLoaderLive: Layer.Layer<ConfigLoaderService, never, never>;
|
|
38
|
+
/**
|
|
39
|
+
* Helper to define a config (provides type safety for users)
|
|
40
|
+
*
|
|
41
|
+
* Uses `ConfigInput` which properly types `inflection` and `plugins`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function defineConfig(config: ConfigInput): ConfigInput;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/services/config-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAkC,MAAM,QAAQ,CAAC;AAEhF,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE;QACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KAC9B,KAAK,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa,CAAC,CAAC;CACrE;;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,wBAGtC;CAAG;AAsCN;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAkEjD;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,gDAA2D,CAAC;AAEzF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE7D"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Loader Service
|
|
3
|
+
*
|
|
4
|
+
* Loads and validates pgsourcerer.config.{ts,js,mjs} using lilconfig.
|
|
5
|
+
* Wraps the async config loading in Effect for proper error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { Context, Effect, Layer, Schema as S, pipe } from "effect";
|
|
8
|
+
import { lilconfig } from "lilconfig";
|
|
9
|
+
import { Config } from "../config.js";
|
|
10
|
+
import { ConfigNotFound, ConfigInvalid } from "../errors.js";
|
|
11
|
+
/**
|
|
12
|
+
* ConfigLoader service tag
|
|
13
|
+
*/
|
|
14
|
+
export class ConfigLoaderService extends Context.Tag("ConfigLoader")() {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Default config file names to search for
|
|
18
|
+
*/
|
|
19
|
+
const CONFIG_FILE_NAMES = [
|
|
20
|
+
"pgsourcerer.config.ts",
|
|
21
|
+
"pgsourcerer.config.js",
|
|
22
|
+
"pgsourcerer.config.mjs",
|
|
23
|
+
"pgsourcerer.config.cjs",
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Dynamic import loader for TypeScript files (Bun handles natively)
|
|
27
|
+
*/
|
|
28
|
+
const dynamicImport = async (filepath) => {
|
|
29
|
+
const mod = (await import(filepath));
|
|
30
|
+
return mod.default ?? mod;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Create the lilconfig instance with TypeScript support
|
|
34
|
+
*/
|
|
35
|
+
function createLilconfig() {
|
|
36
|
+
return lilconfig("pgsourcerer", {
|
|
37
|
+
searchPlaces: CONFIG_FILE_NAMES,
|
|
38
|
+
loaders: { ".ts": dynamicImport },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format Schema decode errors into readable strings
|
|
43
|
+
*/
|
|
44
|
+
function formatSchemaErrors(error) {
|
|
45
|
+
// Use the error message which is already formatted
|
|
46
|
+
return [error.message];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a ConfigLoader implementation
|
|
50
|
+
*/
|
|
51
|
+
export function createConfigLoader() {
|
|
52
|
+
const lc = createLilconfig();
|
|
53
|
+
return {
|
|
54
|
+
load: options => Effect.gen(function* () {
|
|
55
|
+
const searchFrom = options?.searchFrom ?? process.cwd();
|
|
56
|
+
const configPath = options?.configPath;
|
|
57
|
+
// Search for or load specific config file
|
|
58
|
+
const result = yield* Effect.tryPromise({
|
|
59
|
+
try: async () => {
|
|
60
|
+
if (configPath) {
|
|
61
|
+
return await lc.load(configPath);
|
|
62
|
+
}
|
|
63
|
+
return await lc.search(searchFrom);
|
|
64
|
+
},
|
|
65
|
+
catch: error => new ConfigInvalid({
|
|
66
|
+
message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,
|
|
67
|
+
path: configPath ?? searchFrom,
|
|
68
|
+
errors: [String(error)],
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
// Check if config was found
|
|
72
|
+
if (!result || result.isEmpty) {
|
|
73
|
+
return yield* Effect.fail(new ConfigNotFound({
|
|
74
|
+
message: "No configuration file found",
|
|
75
|
+
searchPaths: CONFIG_FILE_NAMES.map(name => `${searchFrom}/${name}`),
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
const filepath = result.filepath;
|
|
79
|
+
// Validate with Effect Schema
|
|
80
|
+
const parseResult = yield* pipe(S.decodeUnknown(Config)(result.config), Effect.mapError(parseError => new ConfigInvalid({
|
|
81
|
+
message: `Invalid configuration in ${filepath}`,
|
|
82
|
+
path: filepath,
|
|
83
|
+
errors: formatSchemaErrors(parseError),
|
|
84
|
+
})));
|
|
85
|
+
// Return resolved config
|
|
86
|
+
const resolved = {
|
|
87
|
+
connectionString: parseResult.connectionString,
|
|
88
|
+
schemas: parseResult.schemas,
|
|
89
|
+
outputDir: parseResult.outputDir,
|
|
90
|
+
role: parseResult.role,
|
|
91
|
+
typeHints: parseResult.typeHints,
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- inflection is S.Any in schema, validated by plugin system
|
|
93
|
+
inflection: parseResult.inflection,
|
|
94
|
+
plugins: parseResult.plugins,
|
|
95
|
+
formatter: parseResult.formatter,
|
|
96
|
+
};
|
|
97
|
+
return resolved;
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Live layer for ConfigLoader
|
|
103
|
+
*/
|
|
104
|
+
export const ConfigLoaderLive = Layer.succeed(ConfigLoaderService, createConfigLoader());
|
|
105
|
+
/**
|
|
106
|
+
* Helper to define a config (provides type safety for users)
|
|
107
|
+
*
|
|
108
|
+
* Uses `ConfigInput` which properly types `inflection` and `plugins`.
|
|
109
|
+
*/
|
|
110
|
+
export function defineConfig(config) {
|
|
111
|
+
return config;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/services/config-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,IAAI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;gBACd,MAAM,EAAE,kBAAkB,CAAC,UAAU,CAAC;aACvC,CAAC,CACL,CACF,CAAC;YAEF,yBAAyB;YACzB,MAAM,QAAQ,GAAmB;gBAC/B,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;gBAC9C,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,gIAAgI;gBAChI,UAAU,EAAE,WAAW,CAAC,UAAU;gBAClC,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,SAAS,EAAE,WAAW,CAAC,SAAS;aACjC,CAAC;YAEF,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC;KACL,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAmB;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emission Buffer Service
|
|
3
|
+
*
|
|
4
|
+
* Buffers code emissions from plugins before writing to disk.
|
|
5
|
+
* Supports both string content and AST nodes (serialized by the plugin runner).
|
|
6
|
+
* AST emissions to the same file are merged automatically.
|
|
7
|
+
*/
|
|
8
|
+
import { Context, Effect, Layer } from "effect";
|
|
9
|
+
import type { namedTypes as n } from "ast-types";
|
|
10
|
+
import { EmitConflict } from "../errors.js";
|
|
11
|
+
import type { ImportRef } from "./file-builder.js";
|
|
12
|
+
import type { SymbolRegistry } from "./symbols.js";
|
|
13
|
+
/**
|
|
14
|
+
* Emission entry - a single file to be written
|
|
15
|
+
*/
|
|
16
|
+
export interface EmissionEntry {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly content: string;
|
|
19
|
+
readonly plugin: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* AST emission entry - buffered until serialization
|
|
23
|
+
*/
|
|
24
|
+
export interface AstEmissionEntry {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly ast: n.Program;
|
|
27
|
+
readonly plugin: string;
|
|
28
|
+
/** Optional header to prepend (e.g., comments) */
|
|
29
|
+
readonly header?: string;
|
|
30
|
+
/** Import requests to resolve during serialization */
|
|
31
|
+
readonly imports?: readonly ImportRef[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Emission buffer interface
|
|
35
|
+
*/
|
|
36
|
+
export interface EmissionBuffer {
|
|
37
|
+
/**
|
|
38
|
+
* Emit string content to a file (buffered)
|
|
39
|
+
*/
|
|
40
|
+
readonly emit: (path: string, content: string, plugin: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Emit an AST program to a file (buffered, serialized later by runner)
|
|
43
|
+
* Multiple emissions to the same path are merged automatically.
|
|
44
|
+
*/
|
|
45
|
+
readonly emitAst: (path: string, ast: n.Program, plugin: string, header?: string, imports?: readonly ImportRef[]) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Append to an already-emitted file (same plugin only, string emissions only)
|
|
48
|
+
*/
|
|
49
|
+
readonly appendEmit: (path: string, content: string, plugin: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Get all string emissions
|
|
52
|
+
*/
|
|
53
|
+
readonly getAll: () => readonly EmissionEntry[];
|
|
54
|
+
/**
|
|
55
|
+
* Get all AST emissions (for serialization by runner)
|
|
56
|
+
*/
|
|
57
|
+
readonly getAstEmissions: () => readonly AstEmissionEntry[];
|
|
58
|
+
/**
|
|
59
|
+
* Serialize all AST emissions to string emissions.
|
|
60
|
+
* Called by the plugin runner after all plugins have run.
|
|
61
|
+
* Resolves imports via the provided SymbolRegistry.
|
|
62
|
+
*/
|
|
63
|
+
readonly serializeAst: (serialize: (ast: n.Program) => string, symbols: SymbolRegistry) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Check for conflicts (same path from different plugins for string emissions)
|
|
66
|
+
* Note: AST emissions are merged, not conflicted.
|
|
67
|
+
*/
|
|
68
|
+
readonly validate: () => Effect.Effect<void, EmitConflict>;
|
|
69
|
+
/**
|
|
70
|
+
* Clear all emissions
|
|
71
|
+
*/
|
|
72
|
+
readonly clear: () => void;
|
|
73
|
+
}
|
|
74
|
+
declare const Emissions_base: Context.TagClass<Emissions, "Emissions", EmissionBuffer>;
|
|
75
|
+
/**
|
|
76
|
+
* EmissionBuffer service tag
|
|
77
|
+
*/
|
|
78
|
+
export declare class Emissions extends Emissions_base {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new emission buffer
|
|
82
|
+
*/
|
|
83
|
+
export declare function createEmissionBuffer(): EmissionBuffer;
|
|
84
|
+
/**
|
|
85
|
+
* Live layer - creates fresh emission buffer per use
|
|
86
|
+
*/
|
|
87
|
+
export declare const EmissionsLive: Layer.Layer<Emissions, never, never>;
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=emissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emissions.d.ts","sourceRoot":"","sources":["../../src/services/emissions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAgB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAgD,MAAM,QAAQ,CAAA;AAC3G,OAAO,KAAK,EAAE,UAAU,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AAOhD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAA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