@pattern-stack/codegen 0.11.0 → 0.12.1
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/CHANGELOG.md +87 -0
- package/dist/runtime/subsystems/index.d.ts +7 -3
- package/dist/runtime/subsystems/index.js +993 -19
- package/dist/runtime/subsystems/index.js.map +1 -1
- package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.d.ts +25 -0
- package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js +34 -0
- package/dist/runtime/subsystems/integration/entity-change-source-registry.memory.js.map +1 -0
- package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.d.ts +53 -0
- package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js +13 -0
- package/dist/runtime/subsystems/integration/entity-change-source-registry.protocol.js.map +1 -0
- package/dist/runtime/subsystems/integration/execute-integration.use-case.js.map +1 -1
- package/dist/runtime/subsystems/integration/index.d.ts +3 -1
- package/dist/runtime/subsystems/integration/index.js +35 -0
- package/dist/runtime/subsystems/integration/index.js.map +1 -1
- package/dist/runtime/subsystems/integration/integration-cursor-store.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/integration/integration-run-recorder.drizzle-backend.js.map +1 -1
- package/dist/runtime/subsystems/integration/integration.module.js.map +1 -1
- package/dist/runtime/subsystems/integration/integration.tokens.d.ts +14 -1
- package/dist/runtime/subsystems/integration/integration.tokens.js +2 -0
- package/dist/runtime/subsystems/integration/integration.tokens.js.map +1 -1
- package/dist/runtime/subsystems/observability/index.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.module.js.map +1 -1
- package/dist/runtime/subsystems/observability/observability.service.js.map +1 -1
- package/dist/src/cli/index.js +1100 -108
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/index.d.ts +48 -0
- package/dist/src/index.js +99 -3
- package/dist/src/index.js.map +1 -1
- package/package.json +9 -1
- package/runtime/subsystems/index.ts +15 -0
- package/runtime/subsystems/integration/entity-change-source-registry.memory.ts +40 -0
- package/runtime/subsystems/integration/entity-change-source-registry.protocol.ts +59 -0
- package/runtime/subsystems/integration/index.ts +9 -0
- package/runtime/subsystems/integration/integration.tokens.ts +14 -0
- package/templates/entity/new/clean-lite-ps/entity.ejs.t +12 -3
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +212 -29
- package/templates/entity/new/backend/modules/core/integration-source.providers.ejs.t +0 -18
package/dist/src/index.d.ts
CHANGED
|
@@ -1692,6 +1692,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
1692
1692
|
value?: unknown;
|
|
1693
1693
|
}[] | undefined;
|
|
1694
1694
|
}>]>>>;
|
|
1695
|
+
surface: z.ZodOptional<z.ZodString>;
|
|
1696
|
+
context: z.ZodOptional<z.ZodString>;
|
|
1695
1697
|
events: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1696
1698
|
name: z.ZodString;
|
|
1697
1699
|
queue: z.ZodString;
|
|
@@ -1955,6 +1957,16 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
1955
1957
|
measure_packs?: string[] | undefined;
|
|
1956
1958
|
cube_name?: string | undefined;
|
|
1957
1959
|
}>>;
|
|
1960
|
+
unique_indexes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1961
|
+
fields: z.ZodArray<z.ZodString, "many">;
|
|
1962
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1963
|
+
}, "strict", z.ZodTypeAny, {
|
|
1964
|
+
fields: string[];
|
|
1965
|
+
name?: string | undefined;
|
|
1966
|
+
}, {
|
|
1967
|
+
fields: string[];
|
|
1968
|
+
name?: string | undefined;
|
|
1969
|
+
}>, "many">>;
|
|
1958
1970
|
}, "strict", z.ZodTypeAny, {
|
|
1959
1971
|
fields: Record<string, {
|
|
1960
1972
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -2100,6 +2112,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2100
2112
|
value?: unknown;
|
|
2101
2113
|
}[];
|
|
2102
2114
|
}> | undefined;
|
|
2115
|
+
surface?: string | undefined;
|
|
2116
|
+
context?: string | undefined;
|
|
2103
2117
|
events?: {
|
|
2104
2118
|
name: string;
|
|
2105
2119
|
queue: string;
|
|
@@ -2153,6 +2167,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2153
2167
|
measure_packs?: string[] | undefined;
|
|
2154
2168
|
cube_name?: string | undefined;
|
|
2155
2169
|
} | undefined;
|
|
2170
|
+
unique_indexes?: {
|
|
2171
|
+
fields: string[];
|
|
2172
|
+
name?: string | undefined;
|
|
2173
|
+
}[] | undefined;
|
|
2156
2174
|
}, {
|
|
2157
2175
|
fields: Record<string, {
|
|
2158
2176
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -2298,6 +2316,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2298
2316
|
value?: unknown;
|
|
2299
2317
|
}[] | undefined;
|
|
2300
2318
|
}> | undefined;
|
|
2319
|
+
surface?: string | undefined;
|
|
2320
|
+
context?: string | undefined;
|
|
2301
2321
|
events?: {
|
|
2302
2322
|
name: string;
|
|
2303
2323
|
queue: string;
|
|
@@ -2351,6 +2371,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2351
2371
|
measure_packs?: string[] | undefined;
|
|
2352
2372
|
cube_name?: string | undefined;
|
|
2353
2373
|
} | undefined;
|
|
2374
|
+
unique_indexes?: {
|
|
2375
|
+
fields: string[];
|
|
2376
|
+
name?: string | undefined;
|
|
2377
|
+
}[] | undefined;
|
|
2354
2378
|
}>, {
|
|
2355
2379
|
fields: Record<string, {
|
|
2356
2380
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -2496,6 +2520,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2496
2520
|
value?: unknown;
|
|
2497
2521
|
}[];
|
|
2498
2522
|
}> | undefined;
|
|
2523
|
+
surface?: string | undefined;
|
|
2524
|
+
context?: string | undefined;
|
|
2499
2525
|
events?: {
|
|
2500
2526
|
name: string;
|
|
2501
2527
|
queue: string;
|
|
@@ -2549,6 +2575,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2549
2575
|
measure_packs?: string[] | undefined;
|
|
2550
2576
|
cube_name?: string | undefined;
|
|
2551
2577
|
} | undefined;
|
|
2578
|
+
unique_indexes?: {
|
|
2579
|
+
fields: string[];
|
|
2580
|
+
name?: string | undefined;
|
|
2581
|
+
}[] | undefined;
|
|
2552
2582
|
}, {
|
|
2553
2583
|
fields: Record<string, {
|
|
2554
2584
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -2694,6 +2724,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2694
2724
|
value?: unknown;
|
|
2695
2725
|
}[] | undefined;
|
|
2696
2726
|
}> | undefined;
|
|
2727
|
+
surface?: string | undefined;
|
|
2728
|
+
context?: string | undefined;
|
|
2697
2729
|
events?: {
|
|
2698
2730
|
name: string;
|
|
2699
2731
|
queue: string;
|
|
@@ -2747,6 +2779,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2747
2779
|
measure_packs?: string[] | undefined;
|
|
2748
2780
|
cube_name?: string | undefined;
|
|
2749
2781
|
} | undefined;
|
|
2782
|
+
unique_indexes?: {
|
|
2783
|
+
fields: string[];
|
|
2784
|
+
name?: string | undefined;
|
|
2785
|
+
}[] | undefined;
|
|
2750
2786
|
}>, {
|
|
2751
2787
|
fields: Record<string, {
|
|
2752
2788
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -2892,6 +2928,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2892
2928
|
value?: unknown;
|
|
2893
2929
|
}[];
|
|
2894
2930
|
}> | undefined;
|
|
2931
|
+
surface?: string | undefined;
|
|
2932
|
+
context?: string | undefined;
|
|
2895
2933
|
events?: {
|
|
2896
2934
|
name: string;
|
|
2897
2935
|
queue: string;
|
|
@@ -2945,6 +2983,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
2945
2983
|
measure_packs?: string[] | undefined;
|
|
2946
2984
|
cube_name?: string | undefined;
|
|
2947
2985
|
} | undefined;
|
|
2986
|
+
unique_indexes?: {
|
|
2987
|
+
fields: string[];
|
|
2988
|
+
name?: string | undefined;
|
|
2989
|
+
}[] | undefined;
|
|
2948
2990
|
}, {
|
|
2949
2991
|
fields: Record<string, {
|
|
2950
2992
|
type: "string" | "boolean" | "integer" | "date" | "json" | "decimal" | "uuid" | "datetime" | "entity_ref" | "string_array" | "enum";
|
|
@@ -3090,6 +3132,8 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
3090
3132
|
value?: unknown;
|
|
3091
3133
|
}[] | undefined;
|
|
3092
3134
|
}> | undefined;
|
|
3135
|
+
surface?: string | undefined;
|
|
3136
|
+
context?: string | undefined;
|
|
3093
3137
|
events?: {
|
|
3094
3138
|
name: string;
|
|
3095
3139
|
queue: string;
|
|
@@ -3143,6 +3187,10 @@ declare const EntityDefinitionSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
|
3143
3187
|
measure_packs?: string[] | undefined;
|
|
3144
3188
|
cube_name?: string | undefined;
|
|
3145
3189
|
} | undefined;
|
|
3190
|
+
unique_indexes?: {
|
|
3191
|
+
fields: string[];
|
|
3192
|
+
name?: string | undefined;
|
|
3193
|
+
}[] | undefined;
|
|
3146
3194
|
}>;
|
|
3147
3195
|
type EntityDefinition = z.infer<typeof EntityDefinitionSchema>;
|
|
3148
3196
|
|
package/dist/src/index.js
CHANGED
|
@@ -1427,6 +1427,36 @@ var EntityDefinitionSchema = z3.object({
|
|
|
1427
1427
|
// appear in `integration.providers` — see the superRefine on
|
|
1428
1428
|
// `EntityDefinitionSchema` below.
|
|
1429
1429
|
detection: z3.record(z3.string(), DetectionConfigSchema).optional(),
|
|
1430
|
+
// RFC-0001 §1/§8: the integration *surface* this entity belongs to
|
|
1431
|
+
// (e.g. 'calendar', 'mail', 'crm'). Surfaces span provider contexts
|
|
1432
|
+
// (ADR-0006) — one Google OAuth feeds calendar+mail+transcript. The union
|
|
1433
|
+
// of `surface:` values across all entity YAML is the closed set that a
|
|
1434
|
+
// provider's `surfaces:` must be a subset of (cross-checked in
|
|
1435
|
+
// src/parser/validate-providers.ts). Optional: entities without an
|
|
1436
|
+
// integration surface omit it. The surface-package *emission* convention
|
|
1437
|
+
// is Track C (#329); this field is only the declarative input both tracks
|
|
1438
|
+
// read.
|
|
1439
|
+
surface: z3.string().optional(),
|
|
1440
|
+
// Bounded-context declaration (ADR-0004) — "which bounded context this
|
|
1441
|
+
// entity belongs to". This is the DURABLE decision; it is a plain
|
|
1442
|
+
// bounded-context slug, NOT a folder knob. Different features consume it:
|
|
1443
|
+
//
|
|
1444
|
+
// - #403 (this PR, the FIRST consumer): drives the generated code's
|
|
1445
|
+
// module output folder. clean-lite-ps nests the entity's module under
|
|
1446
|
+
// `<modules>/<context>/<entity>/` so same-context entities group
|
|
1447
|
+
// together; untagged entities stay flat (`<modules>/<entity>/`).
|
|
1448
|
+
// - ADR-0004 (deferred): a later `naming: prefix | schema` knob reads
|
|
1449
|
+
// this SAME field to drive the Postgres physical layout —
|
|
1450
|
+
// `prefix` → `pgTable('<context>__<table>')`, then the flip to
|
|
1451
|
+
// `schema` → `pgSchema('<context>').table('<table>')`. NOT wired here;
|
|
1452
|
+
// #403 makes no table/column/schema changes.
|
|
1453
|
+
//
|
|
1454
|
+
// Sibling to `surface:` and orthogonal to it (ADR-0006): context = model
|
|
1455
|
+
// cohesion (which domain), surface = vendor composition (which integration).
|
|
1456
|
+
context: z3.string().regex(
|
|
1457
|
+
/^[a-z][a-z0-9_]*$/,
|
|
1458
|
+
"context must be lowercase snake_case (e.g. 'integration')"
|
|
1459
|
+
).optional(),
|
|
1430
1460
|
// v2: Domain event declarations (CODEGEN-EVOLUTION-PLAN Phase 2)
|
|
1431
1461
|
// Generates typed event classes, handlers, and queue registration
|
|
1432
1462
|
events: z3.array(EventDeclarationSchema).optional(),
|
|
@@ -1445,7 +1475,18 @@ var EntityDefinitionSchema = z3.object({
|
|
|
1445
1475
|
).optional(),
|
|
1446
1476
|
// v2: Analytics / semantic layer configuration
|
|
1447
1477
|
// Cube.js measure packs, custom cube name, and metric definitions
|
|
1448
|
-
analytics: AnalyticsBlockSchema.optional()
|
|
1478
|
+
analytics: AnalyticsBlockSchema.optional(),
|
|
1479
|
+
// Composite (multi-column) unique indexes (#356). Single-column uniqueness
|
|
1480
|
+
// is `unique: true` on the field itself; this declares constraints that
|
|
1481
|
+
// span 2+ columns, e.g. UNIQUE (conversation_id, sequence). Emitted as a
|
|
1482
|
+
// `uniqueIndex(...).on(...)` entry in the generated entity's pgTable
|
|
1483
|
+
// extra-config callback. `name` defaults to <table>_<col1>_<col2>_uniq.
|
|
1484
|
+
unique_indexes: z3.array(
|
|
1485
|
+
z3.object({
|
|
1486
|
+
fields: z3.array(z3.string()).min(2, "unique_indexes entries span 2+ columns \u2014 use `unique: true` on the field for single-column uniqueness"),
|
|
1487
|
+
name: z3.string().optional()
|
|
1488
|
+
}).strict()
|
|
1489
|
+
).optional()
|
|
1449
1490
|
}).strict().refine(
|
|
1450
1491
|
(data) => !data.eav_value_table || typeof data.eav_definition_table === "string",
|
|
1451
1492
|
{
|
|
@@ -1882,6 +1923,56 @@ function safeValidateJunctionDefinition(data) {
|
|
|
1882
1923
|
return { success: false, error: result.error };
|
|
1883
1924
|
}
|
|
1884
1925
|
|
|
1926
|
+
// src/schema/provider-definition.schema.ts
|
|
1927
|
+
import { z as z7 } from "zod";
|
|
1928
|
+
var IMPORT_REF_RE = /^[^#\s]+#[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
1929
|
+
var ImportRefSchema = z7.string().regex(
|
|
1930
|
+
IMPORT_REF_RE,
|
|
1931
|
+
"must be an 'import-path#Export' reference (e.g. '@app/foo/bar.strategy#BarStrategy')"
|
|
1932
|
+
);
|
|
1933
|
+
var AuthTypeSchema = z7.enum(["oauth2", "api-key", "app-password"]);
|
|
1934
|
+
var AuthSchema = z7.object({
|
|
1935
|
+
type: AuthTypeSchema,
|
|
1936
|
+
// Class implementing the auth subsystem's strategy contract (ADR-031).
|
|
1937
|
+
// Pre-flight verified against a real export at codegen time.
|
|
1938
|
+
strategy: ImportRefSchema,
|
|
1939
|
+
// Required (and non-empty) iff type === 'oauth2'; see refine below.
|
|
1940
|
+
scopes: z7.array(z7.string()).optional()
|
|
1941
|
+
}).strict().refine(
|
|
1942
|
+
(a) => a.type !== "oauth2" || a.scopes !== void 0 && a.scopes.length > 0,
|
|
1943
|
+
{
|
|
1944
|
+
message: "auth.scopes is required and must be non-empty when auth.type is 'oauth2'",
|
|
1945
|
+
path: ["scopes"]
|
|
1946
|
+
}
|
|
1947
|
+
);
|
|
1948
|
+
var ClientSchema = z7.object({
|
|
1949
|
+
// API client class. Pre-flight verified against a real export.
|
|
1950
|
+
class: ImportRefSchema,
|
|
1951
|
+
base_url: z7.string().url("client.base_url must be an absolute URL")
|
|
1952
|
+
}).strict();
|
|
1953
|
+
var ProviderDefinitionSchema = z7.object({
|
|
1954
|
+
// Provider id — the canonical string used as detection: keys, audit rows,
|
|
1955
|
+
// subscription rows. kebab/lower; unique across definitions/providers/
|
|
1956
|
+
// (uniqueness is a cross-file check in validate-providers.ts).
|
|
1957
|
+
slug: z7.string().regex(
|
|
1958
|
+
/^[a-z][a-z0-9-]*$/,
|
|
1959
|
+
"slug must be kebab-case lower (e.g. 'google', 'hubspot')"
|
|
1960
|
+
),
|
|
1961
|
+
display_name: z7.string().optional(),
|
|
1962
|
+
auth: AuthSchema,
|
|
1963
|
+
client: ClientSchema,
|
|
1964
|
+
// Surfaces this provider serves (ADR-0006: surfaces span contexts — one
|
|
1965
|
+
// Google OAuth feeds calendar+mail+transcript). Each must reference a real
|
|
1966
|
+
// `surface:` declared on some entity; that cross-check is in
|
|
1967
|
+
// validate-providers.ts. Non-empty enforced here.
|
|
1968
|
+
surfaces: z7.array(z7.string()).min(1, "surfaces must list at least one surface"),
|
|
1969
|
+
// Optional auth lifecycle hints consumed by provider-module emission (D2).
|
|
1970
|
+
// `refresh_behavior` is left as a free string in D1 — its domain firms up
|
|
1971
|
+
// when D2 consumes it; carrying it now keeps the YAML lossless.
|
|
1972
|
+
token_lifetime: z7.number().int().positive().optional(),
|
|
1973
|
+
refresh_behavior: z7.string().optional()
|
|
1974
|
+
}).strict();
|
|
1975
|
+
|
|
1885
1976
|
// src/utils/yaml-loader.ts
|
|
1886
1977
|
function loadEntityFromYaml(filePath) {
|
|
1887
1978
|
if (!existsSync(filePath)) {
|
|
@@ -2389,6 +2480,11 @@ function resolveRelationshipReferences(relationshipDefs, entities) {
|
|
|
2389
2480
|
return issues;
|
|
2390
2481
|
}
|
|
2391
2482
|
|
|
2483
|
+
// src/parser/validate-providers.ts
|
|
2484
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync } from "fs";
|
|
2485
|
+
import { isAbsolute, join as join2, resolve as resolve3 } from "path";
|
|
2486
|
+
import ts from "typescript";
|
|
2487
|
+
|
|
2392
2488
|
// src/analyzer/graph-builder.ts
|
|
2393
2489
|
function inferCardinality(type) {
|
|
2394
2490
|
switch (type) {
|
|
@@ -3928,8 +4024,8 @@ var BasePattern = definePattern({
|
|
|
3928
4024
|
});
|
|
3929
4025
|
|
|
3930
4026
|
// src/patterns/library/junction.pattern.ts
|
|
3931
|
-
import { z as
|
|
3932
|
-
var JunctionPatternConfigSchema =
|
|
4027
|
+
import { z as z8 } from "zod";
|
|
4028
|
+
var JunctionPatternConfigSchema = z8.object({}).strict();
|
|
3933
4029
|
var JunctionPattern = definePattern({
|
|
3934
4030
|
name: "Junction",
|
|
3935
4031
|
description: "Explicit many-to-many junction with role + temporal + sourcing metadata",
|