Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions apps/telemetry-backend/src/prisma/contract.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions apps/telemetry-backend/src/prisma/contract.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/telemetry-backend/src/prisma/contract.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ model TelemetryEvent {
installationId String
version String
command String
flags String[]
flags Json
runtimeName String
runtimeVersion String
os String
Expand All @@ -15,7 +15,7 @@ model TelemetryEvent {
databaseTarget String?
tsVersion String?
agent String?
extensions String[]
extensions Json

@@index([ingestedAt])
@@map("telemetry_event")
Expand Down
6 changes: 2 additions & 4 deletions apps/telemetry-backend/test/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ describe('telemetry POST /events', () => {
const row = await fetchSingleRow();
expect(row.installationId).toBe(maxString);
expect(row.command).toBe(maxString);
expect(row.flags).toHaveLength(64);
expect(row.flags[0]).toBe(maxArrayItem);
expect(row.extensions).toHaveLength(64);
expect(row.extensions[0]).toBe(maxArrayItem);
expect(row.flags).toEqual(manyArrayItems);
expect(row.extensions).toEqual(manyArrayItems);
});

it('rejects strings beyond the configured schema bounds with 400', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Contract } from '@prisma-next/contract/types';
import type { CodecLookup } from '@prisma-next/framework-components/codec';
import type { CapabilityMatrix } from '@prisma-next/framework-components/components';
import type {
AssembledAuthoringContributions,
ControlMutationDefaults,
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface ContractSourceContext {
readonly codecLookup: CodecLookup;
readonly controlMutationDefaults: ControlMutationDefaults;
readonly resolvedInputs: readonly string[];
readonly capabilities: CapabilityMatrix;
}

/** Lets format-aware tooling avoid file-extension sniffing and opaque loader introspection. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { JsonValue } from '@prisma-next/contract/types';
import { blindCast } from '@prisma-next/utils/casts';
import type { CapabilityMatrix } from '../shared/capabilities';
import { mergeCapabilityMatrices } from '../shared/capabilities';
import type { Codec } from '../shared/codec';
import type { AnyCodecDescriptor } from '../shared/codec-descriptor';
import type { CodecLookup, CodecMeta, CodecRef, CodecRegistry } from '../shared/codec-types';
Expand Down Expand Up @@ -62,6 +64,7 @@ export interface ControlStack<
readonly authoringContributions: AssembledAuthoringContributions;
readonly scalarTypeDescriptors: ReadonlyMap<string, string>;
readonly controlMutationDefaults: ControlMutationDefaults;
readonly capabilities: CapabilityMatrix;
}

export interface CreateControlStackInput<
Expand Down Expand Up @@ -522,5 +525,10 @@ export function createControlStack<TFamilyId extends string, TTargetId extends s
authoringContributions: assembleAuthoringContributions(allDescriptors),
scalarTypeDescriptors,
controlMutationDefaults: assembleControlMutationDefaults(allDescriptors),
capabilities: mergeCapabilityMatrices({}, [
target,
...(adapter ? [adapter] : []),
...orderedExtensionPacks,
]),
};
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { CapabilityMatrix } from '../shared/capabilities';
export { mergeCapabilityMatrices } from '../shared/capabilities';
export type {
AdapterDescriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { blindCast } from '@prisma-next/utils/casts';

type CapabilityMatrix = Record<string, Record<string, boolean>>;
export type CapabilityMatrix = Record<string, Record<string, boolean>>;

function isPlainObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ResolvedAttributeArg {
readonly kind: 'positional' | 'named';
readonly name?: string;
readonly value: string;
Comment thread
SevInf marked this conversation as resolved.
readonly expression?: ExpressionAst;
readonly span: PslSpan;
}

Expand Down Expand Up @@ -69,10 +70,12 @@ function readResolvedArgList(
const args: ResolvedAttributeArg[] = [];
for (const arg of argList.args()) {
const name = arg.name()?.name();
const expression = arg.value();
args.push({
kind: name !== undefined ? 'named' : 'positional',
...(name !== undefined ? { name } : {}),
value: renderExpression(arg.value()),
value: renderExpression(expression),
...(expression !== undefined ? { expression } : {}),
span: nodePslSpan(arg.syntax, sourceFile),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ class ControlClientImpl implements ControlClient {
codecLookup: stack.codecLookup,
controlMutationDefaults: stack.controlMutationDefaults,
resolvedInputs: contractConfig.source.inputs ?? [],
capabilities: stack.capabilities,
};
const providerResult = await contractConfig.source.load(sourceContext);
if (!providerResult.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export async function executeContractEmit(
codecLookup: stack.codecLookup,
controlMutationDefaults: stack.controlMutationDefaults,
resolvedInputs: contractConfig.source.inputs ?? [],
capabilities: stack.capabilities,
};

startSpan(onProgress, 'resolveSource', 'Resolving contract source...');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe('defineConfig', () => {
},
controlMutationDefaults: { defaultFunctionRegistry: new Map(), generatorDescriptors: [] },
resolvedInputs: [],
capabilities: {},
});

expect(config.output).toBe('output/contract.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function createMongoTestContext(overrides?: Partial<ContractSourceContext>): Con
generatorDescriptors: [],
},
resolvedInputs: [],
capabilities: {},
...overrides,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const emptyContext: ContractSourceContext = {
generatorDescriptors: [],
},
resolvedInputs: [],
capabilities: {},
};

function minimalMongoContract(overrides?: {
Expand Down
13 changes: 12 additions & 1 deletion packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
isAuthoringPslBlockDescriptor,
} from '@prisma-next/framework-components/authoring';
import type { CodecLookup } from '@prisma-next/framework-components/codec';
import type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-components/components';
import type {
CapabilityMatrix,
ExtensionPackRef,
TargetPackRef,
} from '@prisma-next/framework-components/components';
import type {
ControlMutationDefaultRegistry,
ControlMutationDefaults,
Expand Down Expand Up @@ -129,6 +133,7 @@ export interface InterpretPslDocumentToSqlContractInput {
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
readonly codecLookup?: CodecLookup;
readonly seedDiagnostics?: readonly ContractSourceDiagnostic[];
readonly capabilities: CapabilityMatrix;
}

function buildComposedExtensionPackRefs(
Expand Down Expand Up @@ -443,6 +448,7 @@ interface BuildModelNodeInput {
/** Resolved namespace id keyed by model name — used to stamp the target namespace on FKs. */
readonly modelNamespaceIds: ReadonlyMap<string, string>;
readonly enumHandles?: ReadonlyMap<string, EnumTypeHandle>;
readonly capabilities: CapabilityMatrix;
}

interface BuildModelNodeResult {
Expand Down Expand Up @@ -475,6 +481,7 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
sourceId,
scalarTypeDescriptors: input.scalarTypeDescriptors,
...ifDefined('enumHandles', input.enumHandles),
capabilities: input.capabilities,
});

const inlineIdFields = resolvedFields.filter((field) => field.isId);
Expand Down Expand Up @@ -1151,6 +1158,9 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
columnName: resolvedField.columnName,
descriptor: resolvedField.descriptor,
nullable: resolvedField.nullable,
...(resolvedField.many && resolvedField.valueObjectTypeName === undefined
? { many: true as const }
: {}),
...ifDefined('default', resolvedField.defaultValue),
...ifDefined('executionDefaults', resolvedField.executionDefaults),
...ifDefined('enumTypeHandle', enumHandle),
Expand Down Expand Up @@ -1917,6 +1927,7 @@ export function interpretPslDocumentToSqlContract(
diagnostics,
modelNamespaceIds,
...(enumHandlesByName.size > 0 ? { enumHandles: enumHandlesByName } : {}),
capabilities: input.capabilities,
});
modelNodes.push(
namespaceId !== undefined ? { ...result.modelNode, namespaceId } : result.modelNode,
Expand Down
1 change: 1 addition & 0 deletions packages/2-sql/2-authoring/contract-psl/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function prismaContract(schemaPath: string, options: PrismaContractOption
),
controlMutationDefaults: context.controlMutationDefaults,
createNamespace: options.createNamespace,
capabilities: context.capabilities,
codecLookup: context.codecLookup,
});
if (!interpreted.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ContractSourceDiagnostic } from '@prisma-next/config/config-types'
import type { ControlPolicy } from '@prisma-next/contract/types';
import type { PslSpan, ResolvedAttribute } from '@prisma-next/psl-parser';
import { parseQuotedStringLiteral } from '@prisma-next/psl-parser';
import type { ExpressionAst } from '@prisma-next/psl-parser/syntax';

export { parseQuotedStringLiteral };

Expand Down Expand Up @@ -32,14 +33,15 @@ export function getNamedArgument(attribute: ResolvedAttribute, name: string): st
export function getPositionalArgumentEntry(
attribute: ResolvedAttribute,
index = 0,
): { value: string; span: PslSpan } | undefined {
): { value: string; expression?: ExpressionAst; span: PslSpan } | undefined {
const entries = attribute.args.filter((arg) => arg.kind === 'positional');
const entry = entries[index];
if (!entry || entry.kind !== 'positional') {
return undefined;
}
return {
value: entry.value,
...(entry.expression !== undefined ? { expression: entry.expression } : {}),
span: entry.span,
};
}
Expand Down
Loading
Loading