@lssm/lib.contracts 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217073102
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/app-config/app-config.feature.js +53 -1
- package/dist/app-config/contracts.d.ts +50 -50
- package/dist/app-config/contracts.js +396 -1
- package/dist/app-config/docs/app-config.docblock.js +22 -220
- package/dist/app-config/events.d.ts +27 -27
- package/dist/app-config/events.js +168 -1
- package/dist/app-config/index.js +8 -1
- package/dist/app-config/lifecycle-contracts.d.ts +80 -80
- package/dist/app-config/lifecycle-contracts.js +441 -1
- package/dist/app-config/runtime.js +617 -1
- package/dist/app-config/spec.js +36 -1
- package/dist/app-config/validation.js +538 -1
- package/dist/capabilities/docs/capabilities.docblock.js +22 -1
- package/dist/capabilities/openbanking.js +92 -1
- package/dist/capabilities.js +50 -1
- package/dist/client/index.js +9 -1
- package/dist/client/react/drivers/rn-reusables.js +21 -1
- package/dist/client/react/drivers/shadcn.js +11 -1
- package/dist/client/react/feature-render.js +43 -1
- package/dist/client/react/form-render.js +298 -1
- package/dist/client/react/index.js +8 -1
- package/dist/contract-registry/index.js +3 -1
- package/dist/contract-registry/schemas.js +61 -1
- package/dist/contracts-adapter-hydration.js +41 -1
- package/dist/contracts-adapter-input.js +77 -1
- package/dist/data-views/docs/data-views.docblock.js +22 -1
- package/dist/data-views/query-generator.js +48 -1
- package/dist/data-views/runtime.js +39 -1
- package/dist/data-views.js +35 -1
- package/dist/docs/PUBLISHING.docblock.js +17 -76
- package/dist/docs/accessibility_wcag_compliance_specs.docblock.js +17 -350
- package/dist/docs/index.js +33 -1
- package/dist/docs/meta.docs.js +15 -2
- package/dist/docs/presentations.js +77 -1
- package/dist/docs/registry.js +51 -1
- package/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +17 -383
- package/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +17 -68
- package/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +17 -140
- package/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +17 -86
- package/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +17 -1
- package/dist/docs/tech/auth/better-auth-nextjs.docblock.js +25 -2
- package/dist/docs/tech/contracts/README.docblock.js +21 -1
- package/dist/docs/tech/contracts/create-subscription.docblock.js +21 -1
- package/dist/docs/tech/contracts/graphql-typed-outputs.docblock.js +21 -180
- package/dist/docs/tech/contracts/migrations.docblock.js +21 -1
- package/dist/docs/tech/contracts/openapi-export.docblock.js +22 -2
- package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +19 -60
- package/dist/docs/tech/contracts/overlays.docblock.js +21 -68
- package/dist/docs/tech/contracts/tests.docblock.js +21 -132
- package/dist/docs/tech/contracts/themes.docblock.js +21 -1
- package/dist/docs/tech/contracts/vertical-pocket-family-office.docblock.js +21 -106
- package/dist/docs/tech/lifecycle-stage-system.docblock.js +17 -213
- package/dist/docs/tech/llm/llm-integration.docblock.js +74 -5
- package/dist/docs/tech/mcp-endpoints.docblock.js +38 -1
- package/dist/docs/tech/presentation-runtime.docblock.js +17 -1
- package/dist/docs/tech/schema/README.docblock.js +21 -262
- package/dist/docs/tech/studio/learning-events.docblock.js +49 -1
- package/dist/docs/tech/studio/learning-journeys.docblock.js +25 -2
- package/dist/docs/tech/studio/platform-admin-panel.docblock.js +24 -2
- package/dist/docs/tech/studio/project-access-teams.docblock.js +26 -16
- package/dist/docs/tech/studio/project-routing.docblock.js +68 -1
- package/dist/docs/tech/studio/sandbox-unlogged.docblock.js +23 -2
- package/dist/docs/tech/studio/team-invitations.docblock.js +41 -36
- package/dist/docs/tech/studio/workspace-ops.docblock.js +48 -1
- package/dist/docs/tech/studio/workspaces.docblock.js +24 -2
- package/dist/docs/tech/telemetry-ingest.docblock.js +37 -3
- package/dist/docs/tech/templates/runtime.docblock.js +21 -1
- package/dist/docs/tech/vscode-extension.docblock.js +37 -3
- package/dist/docs/tech/workflows/overview.docblock.js +21 -1
- package/dist/docs/tech-contracts.docs.js +19 -2
- package/dist/events.js +12 -1
- package/dist/experiments/docs/experiments.docblock.js +22 -128
- package/dist/experiments/evaluator.js +101 -1
- package/dist/experiments/spec.js +33 -1
- package/dist/features.js +68 -1
- package/dist/forms/docs/forms.docblock.js +22 -1
- package/dist/forms.js +119 -1
- package/dist/index.js +107 -1
- package/dist/install.js +40 -1
- package/dist/integrations/contracts.d.ts +102 -102
- package/dist/integrations/contracts.js +388 -1
- package/dist/integrations/docs/integrations.docblock.js +95 -1
- package/dist/integrations/health.js +69 -1
- package/dist/integrations/index.js +23 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
- package/dist/integrations/openbanking/contracts/accounts.js +237 -1
- package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
- package/dist/integrations/openbanking/contracts/balances.js +167 -1
- package/dist/integrations/openbanking/contracts/index.js +12 -1
- package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
- package/dist/integrations/openbanking/contracts/transactions.js +218 -1
- package/dist/integrations/openbanking/guards.js +32 -1
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/openbanking/models.js +242 -1
- package/dist/integrations/openbanking/openbanking.feature.js +68 -1
- package/dist/integrations/openbanking/telemetry.js +39 -1
- package/dist/integrations/providers/elevenlabs.js +56 -1
- package/dist/integrations/providers/gcs-storage.js +79 -1
- package/dist/integrations/providers/gmail.js +91 -1
- package/dist/integrations/providers/google-calendar.js +70 -1
- package/dist/integrations/providers/impls/elevenlabs-voice.js +95 -1
- package/dist/integrations/providers/impls/gcs-storage.js +88 -1
- package/dist/integrations/providers/impls/gmail-inbound.js +200 -1
- package/dist/integrations/providers/impls/gmail-outbound.js +104 -5
- package/dist/integrations/providers/impls/google-calendar.js +154 -1
- package/dist/integrations/providers/impls/index.js +16 -1
- package/dist/integrations/providers/impls/mistral-embedding.js +41 -1
- package/dist/integrations/providers/impls/mistral-llm.js +247 -1
- package/dist/integrations/providers/impls/postmark-email.js +55 -1
- package/dist/integrations/providers/impls/powens-client.js +171 -1
- package/dist/integrations/providers/impls/powens-openbanking.js +218 -1
- package/dist/integrations/providers/impls/provider-factory.js +142 -1
- package/dist/integrations/providers/impls/qdrant-vector.js +69 -1
- package/dist/integrations/providers/impls/stripe-payments.js +202 -1
- package/dist/integrations/providers/impls/twilio-sms.js +58 -1
- package/dist/integrations/providers/index.js +13 -1
- package/dist/integrations/providers/mistral.js +72 -1
- package/dist/integrations/providers/postmark.js +72 -1
- package/dist/integrations/providers/powens.js +120 -1
- package/dist/integrations/providers/qdrant.js +77 -1
- package/dist/integrations/providers/registry.js +34 -1
- package/dist/integrations/providers/stripe.js +87 -1
- package/dist/integrations/providers/twilio-sms.js +65 -1
- package/dist/integrations/runtime.js +186 -1
- package/dist/integrations/secrets/aws-secret-manager.js +231 -1
- package/dist/integrations/secrets/env-secret-provider.js +81 -1
- package/dist/integrations/secrets/gcp-secret-manager.js +229 -1
- package/dist/integrations/secrets/index.js +8 -1
- package/dist/integrations/secrets/manager.js +103 -1
- package/dist/integrations/secrets/provider.js +58 -1
- package/dist/integrations/secrets/scaleway-secret-manager.js +247 -1
- package/dist/integrations/spec.js +39 -1
- package/dist/jobs/define-job.js +16 -1
- package/dist/jobs/gcp-cloud-tasks.js +53 -1
- package/dist/jobs/gcp-pubsub.js +39 -1
- package/dist/jobs/handlers/gmail-sync-handler.js +9 -1
- package/dist/jobs/handlers/index.js +12 -1
- package/dist/jobs/handlers/ping-handler.js +15 -1
- package/dist/jobs/handlers/storage-document-handler.js +14 -1
- package/dist/jobs/index.js +4 -1
- package/dist/jobs/memory-queue.js +71 -1
- package/dist/jobs/queue.js +33 -1
- package/dist/jobs/scaleway-sqs-queue.js +153 -1
- package/dist/jsonschema.d.ts +3 -3
- package/dist/jsonschema.js +32 -1
- package/dist/knowledge/contracts.d.ts +66 -66
- package/dist/knowledge/contracts.js +317 -1
- package/dist/knowledge/docs/knowledge.docblock.js +22 -138
- package/dist/knowledge/index.js +10 -1
- package/dist/knowledge/ingestion/document-processor.js +54 -1
- package/dist/knowledge/ingestion/embedding-service.js +25 -1
- package/dist/knowledge/ingestion/gmail-adapter.js +50 -5
- package/dist/knowledge/ingestion/index.js +7 -1
- package/dist/knowledge/ingestion/storage-adapter.js +26 -1
- package/dist/knowledge/ingestion/vector-indexer.js +32 -1
- package/dist/knowledge/query/index.js +3 -1
- package/dist/knowledge/query/service.js +64 -2
- package/dist/knowledge/runtime.js +49 -1
- package/dist/knowledge/spaces/email-threads.js +38 -1
- package/dist/knowledge/spaces/financial-docs.js +38 -1
- package/dist/knowledge/spaces/financial-overview.js +42 -1
- package/dist/knowledge/spaces/index.js +8 -1
- package/dist/knowledge/spaces/product-canon.js +38 -1
- package/dist/knowledge/spaces/support-faq.js +41 -1
- package/dist/knowledge/spaces/uploaded-docs.js +38 -1
- package/dist/knowledge/spec.js +39 -1
- package/dist/llm/exporters.js +541 -8
- package/dist/llm/index.js +4 -1
- package/dist/llm/prompts.js +246 -56
- package/dist/markdown.js +116 -3
- package/dist/migrations.js +33 -1
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/onboarding-base.js +196 -1
- package/dist/openapi.js +75 -1
- package/dist/openbanking/docs/openbanking.docblock.js +22 -109
- package/dist/ownership.js +40 -1
- package/dist/policy/docs/policy.docblock.js +22 -1
- package/dist/policy/engine.js +223 -1
- package/dist/policy/opa-adapter.js +71 -1
- package/dist/policy/spec.js +33 -1
- package/dist/presentations/docs/presentations-conventions.docblock.js +21 -7
- package/dist/presentations.backcompat.js +47 -1
- package/dist/presentations.d.ts +3 -3
- package/dist/presentations.js +66 -1
- package/dist/presentations.v2.js +278 -6
- package/dist/prompt.js +10 -1
- package/dist/promptRegistry.js +34 -1
- package/dist/regenerator/docs/regenerator.docblock.js +22 -184
- package/dist/regenerator/executor.js +86 -1
- package/dist/regenerator/index.js +6 -1
- package/dist/regenerator/service.js +92 -1
- package/dist/regenerator/sinks.js +32 -1
- package/dist/regenerator/utils.js +51 -1
- package/dist/registry.js +208 -1
- package/dist/resources.js +47 -1
- package/dist/schema/dist/EnumType.js +2 -1
- package/dist/schema/dist/FieldType.js +49 -1
- package/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/schema/dist/SchemaModel.js +39 -1
- package/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/schema/dist/entity/index.js +2 -1
- package/dist/schema/dist/entity/types.js +1 -1
- package/dist/schema/dist/index.js +6 -1
- package/dist/schema-to-markdown.js +214 -10
- package/dist/server/graphql-pothos.js +128 -1
- package/dist/server/index.js +10 -1
- package/dist/server/mcp/createMcpServer.js +28 -1
- package/dist/server/mcp/registerPresentations.js +151 -1
- package/dist/server/mcp/registerPrompts.js +36 -2
- package/dist/server/mcp/registerResources.js +35 -1
- package/dist/server/mcp/registerTools.js +22 -1
- package/dist/server/provider-mcp.js +3 -1
- package/dist/server/rest-elysia.js +20 -1
- package/dist/server/rest-express.js +39 -1
- package/dist/server/rest-generic.js +125 -1
- package/dist/server/rest-next-app.js +38 -1
- package/dist/server/rest-next-mcp.js +45 -1
- package/dist/server/rest-next-pages.js +25 -1
- package/dist/spec.js +35 -1
- package/dist/telemetry/anomaly.js +48 -1
- package/dist/telemetry/docs/telemetry.docblock.js +22 -139
- package/dist/telemetry/index.js +5 -1
- package/dist/telemetry/spec.js +69 -1
- package/dist/telemetry/tracker.js +76 -1
- package/dist/tests/index.js +4 -1
- package/dist/tests/runner.js +150 -1
- package/dist/tests/spec.js +33 -1
- package/dist/themes.js +39 -1
- package/dist/workflow/adapters/db-adapter.js +83 -1
- package/dist/workflow/adapters/file-adapter.js +11 -1
- package/dist/workflow/adapters/index.js +5 -1
- package/dist/workflow/adapters/memory-store.js +58 -1
- package/dist/workflow/expression.js +98 -1
- package/dist/workflow/index.js +9 -1
- package/dist/workflow/runner.js +337 -1
- package/dist/workflow/sla-monitor.js +47 -1
- package/dist/workflow/spec.js +32 -1
- package/dist/workflow/validation.js +175 -1
- package/package.json +11 -4
|
@@ -1 +1,236 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { FieldType } from "./FieldType.js";
|
|
2
|
+
import * as z$1 from "zod";
|
|
3
|
+
import { Kind } from "graphql";
|
|
4
|
+
|
|
5
|
+
//#region ../schema/dist/ScalarTypeEnum.js
|
|
6
|
+
const localeRegex = /^[A-Za-z]{2}(?:-[A-Za-z0-9]{2,8})*$/;
|
|
7
|
+
const timezoneRegex = /^(?:UTC|[A-Za-z_]+\/[A-Za-z_]+)$/;
|
|
8
|
+
const phoneRegex = /^[+]?\d[\d\s().-]{3,}$/;
|
|
9
|
+
const currencyRegex = /^[A-Z]{3}$/;
|
|
10
|
+
const countryRegex = /^[A-Z]{2}$/;
|
|
11
|
+
const latMin = -90;
|
|
12
|
+
const latMax = 90;
|
|
13
|
+
const lonMin = -180;
|
|
14
|
+
const lonMax = 180;
|
|
15
|
+
/**
|
|
16
|
+
* Factory functions for common scalar FieldTypes with zod/GraphQL/JSON Schema.
|
|
17
|
+
*/
|
|
18
|
+
const ScalarTypeEnum = {
|
|
19
|
+
String_unsecure: () => new FieldType({
|
|
20
|
+
name: "String_unsecure",
|
|
21
|
+
description: "Unvalidated string scalar",
|
|
22
|
+
zod: z$1.string(),
|
|
23
|
+
parseValue: (v) => z$1.string().parse(v),
|
|
24
|
+
serialize: (v) => String(v),
|
|
25
|
+
parseLiteral: (ast) => {
|
|
26
|
+
if (ast.kind !== Kind.STRING) throw new TypeError("Invalid literal");
|
|
27
|
+
return ast.value;
|
|
28
|
+
},
|
|
29
|
+
jsonSchema: { type: "string" }
|
|
30
|
+
}),
|
|
31
|
+
Int_unsecure: () => new FieldType({
|
|
32
|
+
name: "Int_unsecure",
|
|
33
|
+
description: "Unvalidated integer scalar",
|
|
34
|
+
zod: z$1.number().int(),
|
|
35
|
+
parseValue: (v) => {
|
|
36
|
+
const num = typeof v === "number" ? v : Number(v);
|
|
37
|
+
return z$1.number().int().parse(num);
|
|
38
|
+
},
|
|
39
|
+
serialize: (v) => Math.trunc(typeof v === "number" ? v : Number(v)),
|
|
40
|
+
parseLiteral: (ast) => {
|
|
41
|
+
if (ast.kind !== Kind.INT) throw new TypeError("Invalid literal");
|
|
42
|
+
return Number(ast.value);
|
|
43
|
+
},
|
|
44
|
+
jsonSchema: { type: "integer" }
|
|
45
|
+
}),
|
|
46
|
+
Float_unsecure: () => new FieldType({
|
|
47
|
+
name: "Float_unsecure",
|
|
48
|
+
description: "Unvalidated float scalar",
|
|
49
|
+
zod: z$1.number(),
|
|
50
|
+
parseValue: (v) => {
|
|
51
|
+
const num = typeof v === "number" ? v : Number(v);
|
|
52
|
+
return z$1.number().parse(num);
|
|
53
|
+
},
|
|
54
|
+
serialize: (v) => Number(v),
|
|
55
|
+
parseLiteral: (ast) => {
|
|
56
|
+
if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT) throw new TypeError("Invalid literal");
|
|
57
|
+
return Number(ast.value);
|
|
58
|
+
},
|
|
59
|
+
jsonSchema: { type: "number" }
|
|
60
|
+
}),
|
|
61
|
+
Boolean: () => new FieldType({
|
|
62
|
+
name: "Boolean",
|
|
63
|
+
description: "Unvalidated boolean scalar",
|
|
64
|
+
zod: z$1.boolean(),
|
|
65
|
+
parseValue: (v) => z$1.coerce.boolean().parse(v),
|
|
66
|
+
serialize: (v) => Boolean(v),
|
|
67
|
+
parseLiteral: (ast) => {
|
|
68
|
+
if (ast.kind !== Kind.BOOLEAN) throw new TypeError("Invalid literal");
|
|
69
|
+
return ast.value;
|
|
70
|
+
},
|
|
71
|
+
jsonSchema: { type: "boolean" }
|
|
72
|
+
}),
|
|
73
|
+
ID: () => new FieldType({
|
|
74
|
+
name: "ID",
|
|
75
|
+
description: "Unvalidated id scalar",
|
|
76
|
+
zod: z$1.string(),
|
|
77
|
+
parseValue: (v) => z$1.string().parse(v),
|
|
78
|
+
serialize: (v) => String(v),
|
|
79
|
+
parseLiteral: (ast) => {
|
|
80
|
+
if (ast.kind !== Kind.STRING) throw new TypeError("Invalid literal");
|
|
81
|
+
return ast.value;
|
|
82
|
+
},
|
|
83
|
+
jsonSchema: { type: "string" }
|
|
84
|
+
}),
|
|
85
|
+
JSON: () => new FieldType({
|
|
86
|
+
name: "JSON",
|
|
87
|
+
zod: z$1.any(),
|
|
88
|
+
parseValue: (v) => v,
|
|
89
|
+
serialize: (v) => v,
|
|
90
|
+
jsonSchema: {}
|
|
91
|
+
}),
|
|
92
|
+
JSONObject: () => new FieldType({
|
|
93
|
+
name: "JSONObject",
|
|
94
|
+
zod: z$1.record(z$1.string(), z$1.any()),
|
|
95
|
+
parseValue: (v) => z$1.record(z$1.string(), z$1.any()).parse(v),
|
|
96
|
+
serialize: (v) => v ?? {},
|
|
97
|
+
jsonSchema: { type: "object" }
|
|
98
|
+
}),
|
|
99
|
+
Date: () => new FieldType({
|
|
100
|
+
name: "Date",
|
|
101
|
+
zod: z$1.date(),
|
|
102
|
+
parseValue: (v) => v instanceof Date ? v : new Date(String(v)),
|
|
103
|
+
serialize: (v) => v instanceof Date ? v.toISOString().split("T")[0] : String(v),
|
|
104
|
+
jsonSchema: {
|
|
105
|
+
type: "string",
|
|
106
|
+
format: "date"
|
|
107
|
+
}
|
|
108
|
+
}),
|
|
109
|
+
DateTime: () => new FieldType({
|
|
110
|
+
name: "DateTime",
|
|
111
|
+
zod: z$1.date(),
|
|
112
|
+
parseValue: (v) => v instanceof Date ? v : new Date(String(v)),
|
|
113
|
+
serialize: (v) => {
|
|
114
|
+
return v instanceof Date ? v.toISOString() : String(v);
|
|
115
|
+
},
|
|
116
|
+
jsonSchema: {
|
|
117
|
+
type: "string",
|
|
118
|
+
format: "date-time"
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
Time: () => new FieldType({
|
|
122
|
+
name: "Time",
|
|
123
|
+
zod: z$1.string().regex(/^\d{2}:\d{2}(:\d{2})?$/),
|
|
124
|
+
parseValue: (v) => z$1.string().regex(/^\d{2}:\d{2}(:\d{2})?$/).parse(v),
|
|
125
|
+
serialize: (v) => String(v),
|
|
126
|
+
jsonSchema: {
|
|
127
|
+
type: "string",
|
|
128
|
+
pattern: "^\\d{2}:\\d{2}(:\\d{2})?$"
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
EmailAddress: () => new FieldType({
|
|
132
|
+
name: "EmailAddress",
|
|
133
|
+
zod: z$1.string().email(),
|
|
134
|
+
parseValue: (v) => z$1.string().email().parse(v),
|
|
135
|
+
serialize: (v) => String(v),
|
|
136
|
+
jsonSchema: {
|
|
137
|
+
type: "string",
|
|
138
|
+
format: "email"
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
URL: () => new FieldType({
|
|
142
|
+
name: "URL",
|
|
143
|
+
zod: z$1.string().url(),
|
|
144
|
+
parseValue: (v) => z$1.string().url().parse(v),
|
|
145
|
+
serialize: (v) => String(v),
|
|
146
|
+
jsonSchema: {
|
|
147
|
+
type: "string",
|
|
148
|
+
format: "uri"
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
151
|
+
PhoneNumber: () => new FieldType({
|
|
152
|
+
name: "PhoneNumber",
|
|
153
|
+
zod: z$1.string().regex(phoneRegex),
|
|
154
|
+
parseValue: (v) => z$1.string().regex(phoneRegex).parse(v),
|
|
155
|
+
serialize: (v) => String(v),
|
|
156
|
+
jsonSchema: {
|
|
157
|
+
type: "string",
|
|
158
|
+
pattern: phoneRegex.source
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
NonEmptyString: () => new FieldType({
|
|
162
|
+
name: "NonEmptyString",
|
|
163
|
+
zod: z$1.string().min(1),
|
|
164
|
+
parseValue: (v) => z$1.string().min(1).parse(v),
|
|
165
|
+
serialize: (v) => String(v),
|
|
166
|
+
jsonSchema: {
|
|
167
|
+
type: "string",
|
|
168
|
+
minLength: 1
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
Locale: () => new FieldType({
|
|
172
|
+
name: "Locale",
|
|
173
|
+
zod: z$1.string().regex(localeRegex),
|
|
174
|
+
parseValue: (v) => z$1.string().regex(localeRegex).parse(v),
|
|
175
|
+
serialize: (v) => String(v),
|
|
176
|
+
jsonSchema: {
|
|
177
|
+
type: "string",
|
|
178
|
+
pattern: localeRegex.source
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
TimeZone: () => new FieldType({
|
|
182
|
+
name: "TimeZone",
|
|
183
|
+
zod: z$1.string().regex(timezoneRegex),
|
|
184
|
+
parseValue: (v) => z$1.string().regex(timezoneRegex).parse(v),
|
|
185
|
+
serialize: (v) => String(v),
|
|
186
|
+
jsonSchema: {
|
|
187
|
+
type: "string",
|
|
188
|
+
pattern: timezoneRegex.source
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
Latitude: () => new FieldType({
|
|
192
|
+
name: "Latitude",
|
|
193
|
+
zod: z$1.number().min(latMin).max(latMax),
|
|
194
|
+
parseValue: (v) => z$1.coerce.number().min(latMin).max(latMax).parse(v),
|
|
195
|
+
serialize: (v) => Number(v),
|
|
196
|
+
jsonSchema: {
|
|
197
|
+
type: "number",
|
|
198
|
+
minimum: latMin,
|
|
199
|
+
maximum: latMax
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
202
|
+
Longitude: () => new FieldType({
|
|
203
|
+
name: "Longitude",
|
|
204
|
+
zod: z$1.number().min(lonMin).max(lonMax),
|
|
205
|
+
parseValue: (v) => z$1.coerce.number().min(lonMin).max(lonMax).parse(v),
|
|
206
|
+
serialize: (v) => Number(v),
|
|
207
|
+
jsonSchema: {
|
|
208
|
+
type: "number",
|
|
209
|
+
minimum: lonMin,
|
|
210
|
+
maximum: lonMax
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
Currency: () => new FieldType({
|
|
214
|
+
name: "Currency",
|
|
215
|
+
zod: z$1.string().regex(currencyRegex),
|
|
216
|
+
parseValue: (v) => z$1.string().regex(currencyRegex).parse(v),
|
|
217
|
+
serialize: (v) => String(v),
|
|
218
|
+
jsonSchema: {
|
|
219
|
+
type: "string",
|
|
220
|
+
pattern: currencyRegex.source
|
|
221
|
+
}
|
|
222
|
+
}),
|
|
223
|
+
CountryCode: () => new FieldType({
|
|
224
|
+
name: "CountryCode",
|
|
225
|
+
zod: z$1.string().regex(countryRegex),
|
|
226
|
+
parseValue: (v) => z$1.string().regex(countryRegex).parse(v),
|
|
227
|
+
serialize: (v) => String(v),
|
|
228
|
+
jsonSchema: {
|
|
229
|
+
type: "string",
|
|
230
|
+
pattern: countryRegex.source
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
export { ScalarTypeEnum };
|
|
@@ -1 +1,39 @@
|
|
|
1
|
-
import"./EnumType.js";
|
|
1
|
+
import "./EnumType.js";
|
|
2
|
+
import "./FieldType.js";
|
|
3
|
+
import * as z$1 from "zod";
|
|
4
|
+
|
|
5
|
+
//#region ../schema/dist/SchemaModel.js
|
|
6
|
+
/**
|
|
7
|
+
* Named object model built from FieldType/EnumType/SchemaModel fields.
|
|
8
|
+
* Provides zod and GraphQL input helpers, and supports arrays/optional fields.
|
|
9
|
+
*/
|
|
10
|
+
var SchemaModel = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build a typed ZodObject from the model fields, preserving each field's
|
|
16
|
+
* Zod schema and optionality at the type level when possible.
|
|
17
|
+
*/
|
|
18
|
+
getZod() {
|
|
19
|
+
const shape = Object.entries(this.config.fields).reduce((acc, [key, def]) => {
|
|
20
|
+
const base = def.type.getZod();
|
|
21
|
+
const withArray = def.isArray ? z$1.array(base) : base;
|
|
22
|
+
acc[key] = def.isOptional ? withArray.optional() : withArray;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
return z$1.object(shape);
|
|
26
|
+
}
|
|
27
|
+
/** Input object name for GraphQL builder adapters. */
|
|
28
|
+
getPothosInput() {
|
|
29
|
+
return this.config.name;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Helper to define a SchemaModel with type inference.
|
|
34
|
+
* Equivalent to `new SchemaModel(config)` but with better ergonomics.
|
|
35
|
+
*/
|
|
36
|
+
const defineSchemaModel = (config) => new SchemaModel(config);
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { SchemaModel, defineSchemaModel };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"zod";
|
|
1
|
+
import "zod";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./defineEntity.js";
|
|
1
|
+
import "./defineEntity.js";
|
|
2
|
+
import "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"zod";
|
|
1
|
+
import "zod";
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import"./EnumType.js";
|
|
1
|
+
import "./EnumType.js";
|
|
2
|
+
import { FieldType } from "./FieldType.js";
|
|
3
|
+
import { ScalarTypeEnum } from "./ScalarTypeEnum.js";
|
|
4
|
+
import { SchemaModel, defineSchemaModel } from "./SchemaModel.js";
|
|
5
|
+
import "./entity/defineEntity.js";
|
|
6
|
+
import "./entity/index.js";
|
|
@@ -1,10 +1,214 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//#region src/schema-to-markdown.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate markdown from a SchemaModel and data.
|
|
4
|
+
* Automatically detects array vs object data and formats accordingly.
|
|
5
|
+
*/
|
|
6
|
+
function schemaToMarkdown(schema, data, options = {}) {
|
|
7
|
+
const { format = "auto", title, description, maxDepth = 2 } = options;
|
|
8
|
+
const lines = [];
|
|
9
|
+
if (title) lines.push(`# ${title}`, "");
|
|
10
|
+
if (description) lines.push(`> ${description}`, "");
|
|
11
|
+
const effectiveFormat = format === "auto" ? Array.isArray(data) ? "table" : "detail" : format;
|
|
12
|
+
if (effectiveFormat === "table" && Array.isArray(data)) lines.push(schemaToMarkdownTable(schema, data, options));
|
|
13
|
+
else if (effectiveFormat === "list" && Array.isArray(data)) lines.push(schemaToMarkdownList(schema, data, options));
|
|
14
|
+
else if (!Array.isArray(data) && data !== null && typeof data === "object") lines.push(schemaToMarkdownDetail(schema, data, {
|
|
15
|
+
...options,
|
|
16
|
+
maxDepth
|
|
17
|
+
}));
|
|
18
|
+
else lines.push(`**Data:** ${String(data)}`, "");
|
|
19
|
+
return lines.join("\n");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate a markdown table from array data using schema fields as columns.
|
|
23
|
+
*/
|
|
24
|
+
function schemaToMarkdownTable(schema, items, options = {}) {
|
|
25
|
+
const { maxItems = 100, includeFields, excludeFields = [] } = options;
|
|
26
|
+
const fields = getFieldMeta(schema, includeFields, excludeFields);
|
|
27
|
+
if (fields.length === 0 || items.length === 0) return "_No data available_\n";
|
|
28
|
+
const limitedItems = items.slice(0, maxItems);
|
|
29
|
+
const lines = [];
|
|
30
|
+
const headers = fields.map((f) => f.label);
|
|
31
|
+
lines.push(`| ${headers.join(" | ")} |`);
|
|
32
|
+
lines.push(`| ${headers.map(() => "---").join(" | ")} |`);
|
|
33
|
+
for (const item of limitedItems) {
|
|
34
|
+
const row = fields.map((f) => formatCellValue(getFieldValue(item, f.name)));
|
|
35
|
+
lines.push(`| ${row.join(" | ")} |`);
|
|
36
|
+
}
|
|
37
|
+
if (items.length > maxItems) lines.push("", `_Showing ${maxItems} of ${items.length} items_`);
|
|
38
|
+
lines.push("");
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generate a markdown list from array data.
|
|
43
|
+
* Uses summaryFields to create concise list items.
|
|
44
|
+
*/
|
|
45
|
+
function schemaToMarkdownList(schema, items, options = {}) {
|
|
46
|
+
const { maxItems = 50, summaryFields, includeFields, excludeFields = [] } = options;
|
|
47
|
+
const fields = getFieldMeta(schema, includeFields, excludeFields);
|
|
48
|
+
const displayFields = summaryFields ? fields.filter((f) => summaryFields.includes(f.name)) : fields.slice(0, 3);
|
|
49
|
+
if (displayFields.length === 0 || items.length === 0) return "_No data available_\n";
|
|
50
|
+
const limitedItems = items.slice(0, maxItems);
|
|
51
|
+
const lines = [];
|
|
52
|
+
for (const item of limitedItems) {
|
|
53
|
+
const primaryValue = formatCellValue(getFieldValue(item, displayFields[0]?.name ?? "id"));
|
|
54
|
+
const secondaryValues = displayFields.slice(1).map((f) => `${f.label}: ${formatCellValue(getFieldValue(item, f.name))}`).join(" · ");
|
|
55
|
+
const itemLine = secondaryValues ? `- **${primaryValue}** (${secondaryValues})` : `- **${primaryValue}**`;
|
|
56
|
+
lines.push(itemLine);
|
|
57
|
+
}
|
|
58
|
+
if (items.length > maxItems) lines.push("", `_Showing ${maxItems} of ${items.length} items_`);
|
|
59
|
+
lines.push("");
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate a markdown detail view (key-value pairs) from object data.
|
|
64
|
+
*/
|
|
65
|
+
function schemaToMarkdownDetail(schema, item, options = {}) {
|
|
66
|
+
const { includeFields, excludeFields = [], maxDepth = 2 } = options;
|
|
67
|
+
if (item === null || typeof item !== "object") return "_No data available_\n";
|
|
68
|
+
const fields = getFieldMeta(schema, includeFields, excludeFields);
|
|
69
|
+
if (fields.length === 0) return "_No fields to display_\n";
|
|
70
|
+
const lines = [];
|
|
71
|
+
for (const field of fields) {
|
|
72
|
+
const formattedValue = formatDetailValue(getFieldValue(item, field.name), maxDepth, 0);
|
|
73
|
+
lines.push(`**${field.label}:** ${formattedValue}`);
|
|
74
|
+
}
|
|
75
|
+
lines.push("");
|
|
76
|
+
return lines.join("\n");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generate markdown summary statistics for numeric fields in array data.
|
|
80
|
+
*/
|
|
81
|
+
function schemaToMarkdownSummary(schema, items, options = {}) {
|
|
82
|
+
const { numericFields = [], countByField } = options;
|
|
83
|
+
const lines = [];
|
|
84
|
+
lines.push(`**Total Items:** ${items.length}`);
|
|
85
|
+
for (const fieldName of numericFields) {
|
|
86
|
+
const values = items.map((item) => getFieldValue(item, fieldName)).filter((v) => typeof v === "number");
|
|
87
|
+
if (values.length > 0) {
|
|
88
|
+
const sum = values.reduce((a, b) => a + b, 0);
|
|
89
|
+
const avg = sum / values.length;
|
|
90
|
+
const min = Math.min(...values);
|
|
91
|
+
const max = Math.max(...values);
|
|
92
|
+
lines.push(`**${formatFieldName(fieldName)}:** Sum: ${formatNumber(sum)}, Avg: ${formatNumber(avg)}, Min: ${formatNumber(min)}, Max: ${formatNumber(max)}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (countByField) {
|
|
96
|
+
const counts = {};
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
const value = String(getFieldValue(item, countByField) ?? "Unknown");
|
|
99
|
+
counts[value] = (counts[value] ?? 0) + 1;
|
|
100
|
+
}
|
|
101
|
+
lines.push("", `**By ${formatFieldName(countByField)}:**`);
|
|
102
|
+
for (const [value, count] of Object.entries(counts)) lines.push(`- ${value}: ${count}`);
|
|
103
|
+
}
|
|
104
|
+
lines.push("");
|
|
105
|
+
return lines.join("\n");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get field metadata from schema, applying include/exclude filters
|
|
109
|
+
*/
|
|
110
|
+
function getFieldMeta(schema, includeFields, excludeFields = []) {
|
|
111
|
+
const schemaFields = schema.config.fields;
|
|
112
|
+
return Object.keys(schemaFields).filter((name) => {
|
|
113
|
+
if (excludeFields.includes(name)) return false;
|
|
114
|
+
if (includeFields && !includeFields.includes(name)) return false;
|
|
115
|
+
return true;
|
|
116
|
+
}).map((name) => {
|
|
117
|
+
const fieldConfig = schemaFields[name];
|
|
118
|
+
const isNested = Boolean(fieldConfig?.type && typeof fieldConfig.type === "object" && "config" in fieldConfig.type && typeof fieldConfig.type.config?.fields === "object");
|
|
119
|
+
return {
|
|
120
|
+
name,
|
|
121
|
+
label: formatFieldName(name),
|
|
122
|
+
isOptional: fieldConfig?.isOptional ?? false,
|
|
123
|
+
isArray: fieldConfig?.isArray === true,
|
|
124
|
+
isNested
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get value from object by field name (supports nested paths)
|
|
130
|
+
*/
|
|
131
|
+
function getFieldValue(item, fieldName) {
|
|
132
|
+
if (item === null || typeof item !== "object") return void 0;
|
|
133
|
+
const obj = item;
|
|
134
|
+
if (fieldName.includes(".")) {
|
|
135
|
+
const parts = fieldName.split(".");
|
|
136
|
+
let current = obj;
|
|
137
|
+
for (const part of parts) {
|
|
138
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
139
|
+
current = current[part];
|
|
140
|
+
}
|
|
141
|
+
return current;
|
|
142
|
+
}
|
|
143
|
+
return obj[fieldName];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Format a value for table cell display
|
|
147
|
+
*/
|
|
148
|
+
function formatCellValue(value) {
|
|
149
|
+
if (value === null || value === void 0) return "-";
|
|
150
|
+
if (typeof value === "boolean") return value ? "✓" : "✗";
|
|
151
|
+
if (typeof value === "number") return formatNumber(value);
|
|
152
|
+
if (value instanceof Date) return formatDate(value);
|
|
153
|
+
if (typeof value === "string" && isISODate(value)) return formatDate(new Date(value));
|
|
154
|
+
if (Array.isArray(value)) return `[${value.length} items]`;
|
|
155
|
+
if (typeof value === "object") return "[Object]";
|
|
156
|
+
const str = String(value);
|
|
157
|
+
return str.length > 50 ? `${str.slice(0, 47)}...` : str.replace(/\|/g, "\\|");
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Format a value for detail view (allows more space)
|
|
161
|
+
*/
|
|
162
|
+
function formatDetailValue(value, maxDepth, currentDepth) {
|
|
163
|
+
if (value === null || value === void 0) return "_none_";
|
|
164
|
+
if (typeof value === "boolean") return value ? "Yes" : "No";
|
|
165
|
+
if (typeof value === "number") return formatNumber(value);
|
|
166
|
+
if (value instanceof Date) return formatDate(value);
|
|
167
|
+
if (typeof value === "string" && isISODate(value)) return formatDate(new Date(value));
|
|
168
|
+
if (Array.isArray(value)) {
|
|
169
|
+
if (value.length === 0) return "_empty list_";
|
|
170
|
+
if (currentDepth >= maxDepth) return `[${value.length} items]`;
|
|
171
|
+
if (value.length <= 5 && value.every((v) => typeof v !== "object")) return value.map((v) => formatCellValue(v)).join(", ");
|
|
172
|
+
return `[${value.length} items]`;
|
|
173
|
+
}
|
|
174
|
+
if (typeof value === "object") {
|
|
175
|
+
if (currentDepth >= maxDepth) return "[Object]";
|
|
176
|
+
return `{${Object.keys(value).length} fields}`;
|
|
177
|
+
}
|
|
178
|
+
return String(value);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Format field name to human-readable label
|
|
182
|
+
*/
|
|
183
|
+
function formatFieldName(name) {
|
|
184
|
+
return name.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/_/g, " ").replace(/^\w/, (c) => c.toUpperCase());
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Format number with locale-aware formatting
|
|
188
|
+
*/
|
|
189
|
+
function formatNumber(value) {
|
|
190
|
+
if (Math.abs(value) >= 1e3) return new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format(value);
|
|
191
|
+
if (Number.isInteger(value)) return String(value);
|
|
192
|
+
return value.toFixed(2);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Format date to readable string
|
|
196
|
+
*/
|
|
197
|
+
function formatDate(date) {
|
|
198
|
+
return date.toLocaleDateString("en-US", {
|
|
199
|
+
year: "numeric",
|
|
200
|
+
month: "short",
|
|
201
|
+
day: "numeric"
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if string is ISO date format
|
|
206
|
+
*/
|
|
207
|
+
function isISODate(str) {
|
|
208
|
+
if (!/^\d{4}-\d{2}-\d{2}/.test(str)) return false;
|
|
209
|
+
const date = new Date(str);
|
|
210
|
+
return !isNaN(date.getTime());
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
export { schemaToMarkdown, schemaToMarkdownDetail, schemaToMarkdownList, schemaToMarkdownSummary, schemaToMarkdownTable };
|
|
@@ -1 +1,128 @@
|
|
|
1
|
-
import{hydrateResourceIfNeeded
|
|
1
|
+
import { hydrateResourceIfNeeded, parseReturns } from "../contracts-adapter-hydration.js";
|
|
2
|
+
import { createInputTypeBuilder } from "../contracts-adapter-input.js";
|
|
3
|
+
import { defaultGqlField } from "../jsonschema.js";
|
|
4
|
+
import "@pothos/plugin-prisma";
|
|
5
|
+
import "@pothos/plugin-complexity";
|
|
6
|
+
import "@pothos/plugin-relay";
|
|
7
|
+
import "@pothos/plugin-dataloader";
|
|
8
|
+
import "@pothos/plugin-tracing";
|
|
9
|
+
|
|
10
|
+
//#region src/server/graphql-pothos.ts
|
|
11
|
+
/**
|
|
12
|
+
* Registers all ContractSpecs from a SpecRegistry onto a Pothos SchemaBuilder.
|
|
13
|
+
*
|
|
14
|
+
* This adapter:
|
|
15
|
+
* 1. Discovers output types from specs and registers them as Pothos object types.
|
|
16
|
+
* 2. Maps `ContractSpec` inputs to Pothos input types.
|
|
17
|
+
* 3. Mounts `query` specs as `Query` fields and `command` specs as `Mutation` fields.
|
|
18
|
+
* 4. Wraps the resolver to:
|
|
19
|
+
* - Enforce auth policies (basic check).
|
|
20
|
+
* - Build a `HandlerCtx`.
|
|
21
|
+
* - Execute via `SpecRegistry`.
|
|
22
|
+
* - Hydrate resource references if applicable.
|
|
23
|
+
*
|
|
24
|
+
* @param builder - The Pothos SchemaBuilder instance.
|
|
25
|
+
* @param reg - The SpecRegistry containing operations.
|
|
26
|
+
* @param resources - (Optional) ResourceRegistry for hydrating resource references.
|
|
27
|
+
*/
|
|
28
|
+
function registerContractsOnBuilder(builder, reg, resources) {
|
|
29
|
+
const { buildInputFieldArgs } = createInputTypeBuilder(builder);
|
|
30
|
+
const outputTypeCache = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const spec of reg.listSpecs()) {
|
|
32
|
+
const out = spec.io.output;
|
|
33
|
+
if (out && "getZod" in out && typeof out.getZod === "function") {
|
|
34
|
+
const model = out;
|
|
35
|
+
const typeName = model.config?.name ?? "UnknownOutput";
|
|
36
|
+
if (!outputTypeCache.has(typeName)) outputTypeCache.set(typeName, model);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [typeName, model] of outputTypeCache.entries()) builder.objectType(typeName, { fields: (t) => {
|
|
40
|
+
const entries = Object.entries(model.config.fields);
|
|
41
|
+
const acc = {};
|
|
42
|
+
for (const [key, field] of entries) {
|
|
43
|
+
const fieldType = field.type;
|
|
44
|
+
let gqlType = "JSON";
|
|
45
|
+
if (fieldType && typeof fieldType.getPothos === "function") {
|
|
46
|
+
gqlType = fieldType.getPothos().name || "JSON";
|
|
47
|
+
if (gqlType === "String_unsecure") gqlType = "String";
|
|
48
|
+
if (gqlType === "Int_unsecure") gqlType = "Int";
|
|
49
|
+
if (gqlType === "Float_unsecure") gqlType = "Float";
|
|
50
|
+
if (gqlType === "Boolean_unsecure") gqlType = "Boolean";
|
|
51
|
+
if (gqlType === "ID_unsecure") gqlType = "ID";
|
|
52
|
+
}
|
|
53
|
+
const typeRef = field.isArray ? [gqlType] : gqlType;
|
|
54
|
+
acc[key] = t.field({
|
|
55
|
+
type: typeRef,
|
|
56
|
+
nullable: field.isOptional,
|
|
57
|
+
resolve: (parent) => parent[key]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return acc;
|
|
61
|
+
} });
|
|
62
|
+
function resolveGraphQLTypeName(contractSpec) {
|
|
63
|
+
const returnsName = contractSpec.transport?.gql?.returns;
|
|
64
|
+
if (returnsName) return returnsName;
|
|
65
|
+
const out = contractSpec.io.output ?? {};
|
|
66
|
+
if (out && "kind" in out && out.kind === "resource_ref" && "graphQLType" in out && out.graphQLType) return String(out.graphQLType);
|
|
67
|
+
if (out && "getZod" in out && typeof out.getZod === "function") {
|
|
68
|
+
const typeName = out.config?.name;
|
|
69
|
+
if (typeName && outputTypeCache.has(typeName)) return typeName;
|
|
70
|
+
}
|
|
71
|
+
return "JSON";
|
|
72
|
+
}
|
|
73
|
+
for (const spec of reg.listSpecs()) {
|
|
74
|
+
const fieldName = spec.transport?.gql?.field ?? defaultGqlField(spec.meta.name, spec.meta.version);
|
|
75
|
+
spec.transport?.gql?.returns;
|
|
76
|
+
const byIdField = spec.transport?.gql?.byIdField ?? "id";
|
|
77
|
+
const returnsResource = spec.transport?.gql?.resource;
|
|
78
|
+
const isQuery = spec.meta.kind === "query";
|
|
79
|
+
const graphQLTypeName = resolveGraphQLTypeName(spec);
|
|
80
|
+
const returnsDecl = spec.transport?.gql?.returns;
|
|
81
|
+
const parsed = parseReturns(returnsDecl ?? graphQLTypeName);
|
|
82
|
+
const resolveFieldFn = async (_root, args, ctx) => {
|
|
83
|
+
if (spec.policy.auth !== "anonymous" && !ctx.user) throw new Error("Unauthorized");
|
|
84
|
+
const handlerCtx = {
|
|
85
|
+
traceId: ctx.logger?.getTraceId?.() ?? void 0,
|
|
86
|
+
userId: ctx.user?.id ?? null,
|
|
87
|
+
organizationId: ctx.session?.activeOrganizationId ?? null,
|
|
88
|
+
actor: ctx.user ? "user" : "anonymous",
|
|
89
|
+
channel: "web",
|
|
90
|
+
eventPublisher: ctx.eventPublisher
|
|
91
|
+
};
|
|
92
|
+
const parsedInput = spec.io.input?.getZod().parse(args.input ?? {});
|
|
93
|
+
const result = await reg.execute(spec.meta.name, spec.meta.version, parsedInput, handlerCtx);
|
|
94
|
+
const out = spec.io.output;
|
|
95
|
+
if (resources && (returnsResource || out?.kind === "resource_ref")) {
|
|
96
|
+
const varName = byIdField ?? out?.varName ?? "id";
|
|
97
|
+
const hydrated = await hydrateResourceIfNeeded(resources, result, {
|
|
98
|
+
template: returnsResource ?? out?.uriTemplate,
|
|
99
|
+
varName,
|
|
100
|
+
returns: parsed
|
|
101
|
+
});
|
|
102
|
+
if (hydrated !== result) return hydrated;
|
|
103
|
+
}
|
|
104
|
+
if (graphQLTypeName) {
|
|
105
|
+
if (parsed.inner === "Boolean" && !parsed.isList) return Boolean(result?.ok ?? result);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
return spec.io.output.getZod().parse(result);
|
|
109
|
+
};
|
|
110
|
+
const fieldSettingsFn = (t) => {
|
|
111
|
+
const inputType = buildInputFieldArgs(spec.io.input);
|
|
112
|
+
return t.field({
|
|
113
|
+
type: parsed.isList ? [parsed.inner] : parsed.inner,
|
|
114
|
+
complexity: () => 10,
|
|
115
|
+
resolve: resolveFieldFn,
|
|
116
|
+
args: inputType ? { input: t.arg({
|
|
117
|
+
type: inputType,
|
|
118
|
+
required: true
|
|
119
|
+
}) } : void 0
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
if (isQuery) builder.queryField(fieldName, fieldSettingsFn);
|
|
123
|
+
else builder.mutationField(fieldName, fieldSettingsFn);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { registerContractsOnBuilder };
|