@derwinjs/db 0.9.0 → 0.11.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.
Files changed (42) hide show
  1. package/dist/contract-baseline-store.d.ts +21 -0
  2. package/dist/contract-baseline-store.d.ts.map +1 -0
  3. package/dist/contract-baseline-store.js +103 -0
  4. package/dist/contract-baseline-store.js.map +1 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/milestone-event-store.d.ts +35 -0
  10. package/dist/milestone-event-store.d.ts.map +1 -0
  11. package/dist/milestone-event-store.js +221 -0
  12. package/dist/milestone-event-store.js.map +1 -0
  13. package/dist/rum-sample-store.d.ts +48 -0
  14. package/dist/rum-sample-store.d.ts.map +1 -0
  15. package/dist/rum-sample-store.js +155 -0
  16. package/dist/rum-sample-store.js.map +1 -0
  17. package/dist/scripts/smoke-auto-fix.js +1 -1
  18. package/dist/scripts/smoke-auto-fix.js.map +1 -1
  19. package/dist/tenant-fuzz-config-store.d.ts +28 -0
  20. package/dist/tenant-fuzz-config-store.d.ts.map +1 -0
  21. package/dist/tenant-fuzz-config-store.js +173 -0
  22. package/dist/tenant-fuzz-config-store.js.map +1 -0
  23. package/dist/visual-baseline-store.d.ts +21 -0
  24. package/dist/visual-baseline-store.d.ts.map +1 -0
  25. package/dist/visual-baseline-store.js +87 -0
  26. package/dist/visual-baseline-store.js.map +1 -0
  27. package/package.json +3 -3
  28. package/prisma/migrations/20260501165631_init/migration.sql +407 -0
  29. package/prisma/migrations/20260503051425_0002_qap018b_qaticket_crosslink_fields/migration.sql +6 -0
  30. package/prisma/migrations/20260507130000_sprint10_visual_baselines/migration.sql +27 -0
  31. package/prisma/migrations/20260507130100_sprint10_phase3_contract_baselines/migration.sql +32 -0
  32. package/prisma/migrations/20260507130200_sprint10_phase4_tenant_fuzz/migration.sql +34 -0
  33. package/prisma/migrations/20260508000100_sprint11_phase3_rum_samples/migration.sql +31 -0
  34. package/prisma/migrations/20260508000200_sprint11_phase5_milestone_events/migration.sql +42 -0
  35. package/prisma/schema.prisma +189 -0
  36. package/prisma-client/edge.js +63 -4
  37. package/prisma-client/index-browser.js +60 -1
  38. package/prisma-client/index.d.ts +10139 -1638
  39. package/prisma-client/index.js +63 -4
  40. package/prisma-client/package.json +1 -1
  41. package/prisma-client/schema.prisma +189 -0
  42. package/prisma-client/wasm.js +60 -1
@@ -0,0 +1,21 @@
1
+ /**
2
+ * createPrismaContractBaselineStore — Prisma-backed implementation of the SDK
3
+ * ContractBaselineStore contract introduced by QAP-103.
4
+ *
5
+ * Sprint 10 Phase 3 (Test Surfaces — API contract diff). Baselines are
6
+ * stored as Postgres TEXT (model ContractBaseline) keyed by
7
+ * (projectId, specKey). One row per (projectId, specKey) — setBaseline
8
+ * upserts and is the only path to replace an approved baseline.
9
+ *
10
+ * Tenant isolation: every method scopes by projectId. Pattern D applies —
11
+ * unknown / wrong-project lookups return null rather than throwing or
12
+ * leaking existence (defense-in-depth against tenant enumeration).
13
+ */
14
+ import type { PrismaClient } from './prisma.js';
15
+ import { type ContractBaselineStore } from '@derwinjs/sdk';
16
+ export interface PrismaContractBaselineStoreConfig {
17
+ /** Generated Prisma client. Pass an instance per process. */
18
+ prisma: PrismaClient;
19
+ }
20
+ export declare function createPrismaContractBaselineStore(config: PrismaContractBaselineStoreConfig): ContractBaselineStore;
21
+ //# sourceMappingURL=contract-baseline-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-baseline-store.d.ts","sourceRoot":"","sources":["../src/contract-baseline-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,iCAAiC;IAChD,6DAA6D;IAC7D,MAAM,EAAE,YAAY,CAAC;CACtB;AAqDD,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,iCAAiC,GACxC,qBAAqB,CA0EvB"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * createPrismaContractBaselineStore — Prisma-backed implementation of the SDK
3
+ * ContractBaselineStore contract introduced by QAP-103.
4
+ *
5
+ * Sprint 10 Phase 3 (Test Surfaces — API contract diff). Baselines are
6
+ * stored as Postgres TEXT (model ContractBaseline) keyed by
7
+ * (projectId, specKey). One row per (projectId, specKey) — setBaseline
8
+ * upserts and is the only path to replace an approved baseline.
9
+ *
10
+ * Tenant isolation: every method scopes by projectId. Pattern D applies —
11
+ * unknown / wrong-project lookups return null rather than throwing or
12
+ * leaking existence (defense-in-depth against tenant enumeration).
13
+ */
14
+ import { ContractBaselineStoreError, } from '@derwinjs/sdk';
15
+ // ─── Validation ──────────────────────────────────────────────────────────
16
+ function assertNonEmpty(value, fieldName) {
17
+ if (typeof value !== 'string' || value.trim() === '') {
18
+ throw new ContractBaselineStoreError('invalid_input', `createPrismaContractBaselineStore: ${fieldName} is required and non-empty`);
19
+ }
20
+ }
21
+ function assertValidFormat(value) {
22
+ if (value !== 'openapi' && value !== 'json-schema') {
23
+ throw new ContractBaselineStoreError('invalid_format', `createPrismaContractBaselineStore: format must be 'openapi' or 'json-schema'`);
24
+ }
25
+ }
26
+ /**
27
+ * Map a Prisma row to the SDK ContractBaseline shape. Coerces the stored
28
+ * `format` string back to the SDK union — defense in depth in case a
29
+ * malformed value somehow landed (the factory's setBaseline path validates
30
+ * before write, but external writes or bad migrations could bypass it).
31
+ */
32
+ function toContractBaseline(row) {
33
+ const format = row.format === 'json-schema' ? 'json-schema' : 'openapi';
34
+ return {
35
+ id: row.id,
36
+ projectId: row.projectId,
37
+ specKey: row.specKey,
38
+ spec: row.spec,
39
+ format,
40
+ capturedAt: row.capturedAt,
41
+ capturedBy: row.capturedBy,
42
+ };
43
+ }
44
+ // ─── Factory ─────────────────────────────────────────────────────────────
45
+ export function createPrismaContractBaselineStore(config) {
46
+ const { prisma } = config;
47
+ return {
48
+ async getBaseline(input) {
49
+ assertNonEmpty(input.projectId, 'projectId');
50
+ assertNonEmpty(input.specKey, 'specKey');
51
+ const row = await prisma.contractBaseline.findUnique({
52
+ where: {
53
+ projectId_specKey: {
54
+ projectId: input.projectId,
55
+ specKey: input.specKey,
56
+ },
57
+ },
58
+ });
59
+ if (row === null)
60
+ return null;
61
+ return toContractBaseline(row);
62
+ },
63
+ async setBaseline(input) {
64
+ assertNonEmpty(input.projectId, 'projectId');
65
+ assertNonEmpty(input.specKey, 'specKey');
66
+ assertNonEmpty(input.spec, 'spec');
67
+ assertNonEmpty(input.capturedBy, 'capturedBy');
68
+ assertValidFormat(input.format);
69
+ const row = await prisma.contractBaseline.upsert({
70
+ where: {
71
+ projectId_specKey: {
72
+ projectId: input.projectId,
73
+ specKey: input.specKey,
74
+ },
75
+ },
76
+ create: {
77
+ projectId: input.projectId,
78
+ specKey: input.specKey,
79
+ spec: input.spec,
80
+ format: input.format,
81
+ capturedBy: input.capturedBy,
82
+ },
83
+ update: {
84
+ spec: input.spec,
85
+ format: input.format,
86
+ capturedBy: input.capturedBy,
87
+ capturedAt: new Date(),
88
+ },
89
+ select: { id: true },
90
+ });
91
+ return { id: row.id };
92
+ },
93
+ async listBaselines(input) {
94
+ assertNonEmpty(input.projectId, 'projectId');
95
+ const rows = await prisma.contractBaseline.findMany({
96
+ where: { projectId: input.projectId },
97
+ orderBy: { capturedAt: 'desc' },
98
+ });
99
+ return rows.map(toContractBaseline);
100
+ },
101
+ };
102
+ }
103
+ //# sourceMappingURL=contract-baseline-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-baseline-store.js","sourceRoot":"","sources":["../src/contract-baseline-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,0BAA0B,GAG3B,MAAM,eAAe,CAAC;AASvB,4EAA4E;AAE5E,SAAS,cAAc,CAAC,K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;QACxB,CAAC;QAED,KAAK,CAAC,aAAa,CAAC,KAA4B;YAC9C,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAE7C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC;gBAClD,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE;gBACrC,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE;aAChC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -33,5 +33,10 @@ export { createPrismaBudgetGate, type PrismaBudgetGateConfig } from './budget-ga
33
33
  export { createPrismaKillSwitchEvaluator, DEFAULT_KILL_SWITCH_THRESHOLDS, type PrismaKillSwitchEvaluatorConfig, } from './kill-switch-evaluator.js';
34
34
  export { createPrismaProjectModeStore, type PrismaProjectModeStoreConfig, } from './project-mode-store.js';
35
35
  export { createPrismaAutoPromotionEvaluator, DEFAULT_PROMOTION_THRESHOLDS, type PrismaAutoPromotionEvaluatorConfig, } from './auto-promotion-evaluator.js';
36
+ export { createPrismaVisualBaselineStore, type PrismaVisualBaselineStoreConfig, } from './visual-baseline-store.js';
37
+ export { createPrismaContractBaselineStore, type PrismaContractBaselineStoreConfig, } from './contract-baseline-store.js';
38
+ export { createPrismaTenantFuzzConfigStore, type PrismaTenantFuzzConfigStoreConfig, } from './tenant-fuzz-config-store.js';
39
+ export { createPrismaRumSampleStore, RumSampleStoreError, type PrismaRumSampleStoreConfig, } from './rum-sample-store.js';
40
+ export { createPrismaMilestoneEventStore, type PrismaMilestoneEventStoreConfig, } from './milestone-event-store.js';
36
41
  export * from './prisma.js';
37
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChG,OAAO,EACL,4BAA4B,EAC5B,SAAS,EACT,KAAK,4BAA4B,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,uCAAuC,EACvC,KAAK,uCAAuC,GAC7C,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,qCAAqC,EACrC,KAAK,qCAAqC,GAC3C,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,iCAAiC,EACjC,SAAS,EACT,cAAc,EACd,KAAK,iCAAiC,GACvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,EAC9B,KAAK,+BAA+B,GACrC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,4BAA4B,EAC5B,KAAK,4BAA4B,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kCAAkC,EAClC,4BAA4B,EAC5B,KAAK,kCAAkC,GACxC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,+BAA+B,EAC/B,KAAK,+BAA+B,GACrC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iCAAiC,EACjC,KAAK,iCAAiC,GACvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,iCAAiC,EACjC,KAAK,iCAAiC,GACvC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,+BAA+B,EAC/B,KAAK,+BAA+B,GACrC,MAAM,4BAA4B,CAAC;AA4BpC,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -34,6 +34,11 @@ export { createPrismaBudgetGate } from './budget-gate.js';
34
34
  export { createPrismaKillSwitchEvaluator, DEFAULT_KILL_SWITCH_THRESHOLDS, } from './kill-switch-evaluator.js';
35
35
  export { createPrismaProjectModeStore, } from './project-mode-store.js';
36
36
  export { createPrismaAutoPromotionEvaluator, DEFAULT_PROMOTION_THRESHOLDS, } from './auto-promotion-evaluator.js';
37
+ export { createPrismaVisualBaselineStore, } from './visual-baseline-store.js';
38
+ export { createPrismaContractBaselineStore, } from './contract-baseline-store.js';
39
+ export { createPrismaTenantFuzzConfigStore, } from './tenant-fuzz-config-store.js';
40
+ export { createPrismaRumSampleStore, RumSampleStoreError, } from './rum-sample-store.js';
41
+ export { createPrismaMilestoneEventStore, } from './milestone-event-store.js';
37
42
  // ─── Prisma client re-export ─────────────────────────────────────────────
38
43
  //
39
44
  // @derwinjs/db ships its OWN generated Prisma client (output: prisma-client/
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAuB,CAAC;AAEpD,4EAA4E;AAE5E,OAAO,EAAE,yBAAyB,EAAkC,MAAM,sBAAsB,CAAC;AACjG,OAAO,EACL,6BAA6B,GAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,0BAA0B,EAAmC,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAkC,MAAM,sBAAsB,CAAC;AACjG,OAAO,EACL,6BAA6B,GAE9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,iCAAiC,GAElC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,kCAAkC,GAEnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,+BAA+B,GAEhC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,8BAA8B,GAE/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAkC,MAAM,qBAAqB,CAAC;AAChG,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wE;AACxE,wEAAwE;AACxE,gDAAgD;AAChD,EAAE;AACF,+DAA+D;AAC/D,0EAA0E;AAC1E,yCAAyC;AACzC,+EAA+E;AAC/E,yCAAyC;AACzC,uEAAuE;AACvE,sEAAsE;AACtE,kEAAkE;AAClE,+BAA+B;AAC/B,EAAE;AACF,oBAAoB;AACpB,8DAA8D;AAC9D,4CAA4C;AAC5C,qEAAqE;AACrE,QAAQ;AACR,gDAAgD;AAEhD,cAAc,aAAa,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * createPrismaMilestoneEventStore — Prisma-backed implementation of the SDK
3
+ * MilestoneEventStore contract introduced by QAP-115.
4
+ *
5
+ * Sprint 11 Phase 5 (Cross-product tracking timeline). One row per
6
+ * milestone in the `milestone_events` table, project-scoped via FK. v1
7
+ * is read-mostly (CRUD); drag-to-reschedule deferred to Sprint 14.
8
+ *
9
+ * Tenant isolation: every method scopes by projectId. Pattern D applies —
10
+ * `update` / `delete` against a row owned by a different projectId
11
+ * surfaces as `not_found` rather than `tenant_mismatch` (defense-in-depth
12
+ * against tenant enumeration). The composite (id, projectId) unique-ish
13
+ * lookup on `update` / `delete` is what enforces this — Prisma's
14
+ * `update({ where: { id, projectId } })` raises P2025 when nothing
15
+ * matches, and `deleteMany({ where: { id, projectId } })` returns
16
+ * `count: 0`.
17
+ *
18
+ * Validation runs at the factory boundary BEFORE any Prisma call — empty
19
+ * `name` / `kind` / `createdBy` / `projectId` throw `invalid_input` so
20
+ * the error surfaces with a clear caller-bug code rather than as a
21
+ * Prisma constraint violation.
22
+ *
23
+ * The kind column is intentionally a free-form String (not a Prisma
24
+ * enum). The factory enforces non-empty + trims; consumers may emit
25
+ * custom kinds (the conflict-detection helpers in @derwinjs/core treat
26
+ * unknown kinds as "no conflict computed against this kind").
27
+ */
28
+ import { type PrismaClient } from './prisma.js';
29
+ import { type MilestoneEventStore } from '@derwinjs/sdk';
30
+ export interface PrismaMilestoneEventStoreConfig {
31
+ /** Generated Prisma client. Pass an instance per process. */
32
+ prisma: PrismaClient;
33
+ }
34
+ export declare function createPrismaMilestoneEventStore(config: PrismaMilestoneEventStoreConfig): MilestoneEventStore;
35
+ //# sourceMappingURL=milestone-event-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"milestone-event-store.d.ts","sourceRoot":"","sources":["../src/milestone-event-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAKL,KAAK,mBAAmB,EAEzB,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,+BAA+B;IAC9C,6DAA6D;IAC7D,MAAM,EAAE,YAAY,CAAC;CACtB;AA6ED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,+BAA+B,GACtC,mBAAmB,CAqJrB"}
@@ -0,0 +1,221 @@
1
+ /**
2
+ * createPrismaMilestoneEventStore — Prisma-backed implementation of the SDK
3
+ * MilestoneEventStore contract introduced by QAP-115.
4
+ *
5
+ * Sprint 11 Phase 5 (Cross-product tracking timeline). One row per
6
+ * milestone in the `milestone_events` table, project-scoped via FK. v1
7
+ * is read-mostly (CRUD); drag-to-reschedule deferred to Sprint 14.
8
+ *
9
+ * Tenant isolation: every method scopes by projectId. Pattern D applies —
10
+ * `update` / `delete` against a row owned by a different projectId
11
+ * surfaces as `not_found` rather than `tenant_mismatch` (defense-in-depth
12
+ * against tenant enumeration). The composite (id, projectId) unique-ish
13
+ * lookup on `update` / `delete` is what enforces this — Prisma's
14
+ * `update({ where: { id, projectId } })` raises P2025 when nothing
15
+ * matches, and `deleteMany({ where: { id, projectId } })` returns
16
+ * `count: 0`.
17
+ *
18
+ * Validation runs at the factory boundary BEFORE any Prisma call — empty
19
+ * `name` / `kind` / `createdBy` / `projectId` throw `invalid_input` so
20
+ * the error surfaces with a clear caller-bug code rather than as a
21
+ * Prisma constraint violation.
22
+ *
23
+ * The kind column is intentionally a free-form String (not a Prisma
24
+ * enum). The factory enforces non-empty + trims; consumers may emit
25
+ * custom kinds (the conflict-detection helpers in @derwinjs/core treat
26
+ * unknown kinds as "no conflict computed against this kind").
27
+ */
28
+ import { Prisma } from './prisma.js';
29
+ import { MilestoneEventStoreError, } from '@derwinjs/sdk';
30
+ // ─── Validation ──────────────────────────────────────────────────────────
31
+ function assertNonEmpty(value, fieldName) {
32
+ if (typeof value !== 'string' || value.trim() === '') {
33
+ throw new MilestoneEventStoreError('invalid_input', `createPrismaMilestoneEventStore: ${fieldName} is required and non-empty`);
34
+ }
35
+ }
36
+ function assertDate(value, fieldName) {
37
+ if (!(value instanceof Date) || Number.isNaN(value.getTime())) {
38
+ throw new MilestoneEventStoreError('invalid_input', `createPrismaMilestoneEventStore: ${fieldName} must be a valid Date`);
39
+ }
40
+ }
41
+ function assertCreateInput(input) {
42
+ assertNonEmpty(input.projectId, 'projectId');
43
+ assertNonEmpty(input.name, 'name');
44
+ assertNonEmpty(input.kind, 'kind');
45
+ assertNonEmpty(input.createdBy, 'createdBy');
46
+ assertDate(input.startsAt, 'startsAt');
47
+ if (input.endsAt !== undefined) {
48
+ assertDate(input.endsAt, 'endsAt');
49
+ if (input.endsAt.getTime() < input.startsAt.getTime()) {
50
+ throw new MilestoneEventStoreError('invalid_input', 'createPrismaMilestoneEventStore: endsAt must be greater than or equal to startsAt');
51
+ }
52
+ }
53
+ if (input.description !== undefined && typeof input.description !== 'string') {
54
+ throw new MilestoneEventStoreError('invalid_input', 'createPrismaMilestoneEventStore: description must be a string when present');
55
+ }
56
+ }
57
+ function assertUpdatePatch(patch) {
58
+ if (patch.name !== undefined)
59
+ assertNonEmpty(patch.name, 'name');
60
+ if (patch.kind !== undefined)
61
+ assertNonEmpty(patch.kind, 'kind');
62
+ if (patch.startsAt !== undefined)
63
+ assertDate(patch.startsAt, 'startsAt');
64
+ if (patch.endsAt !== undefined && patch.endsAt !== null)
65
+ assertDate(patch.endsAt, 'endsAt');
66
+ if (patch.description !== undefined &&
67
+ patch.description !== null &&
68
+ typeof patch.description !== 'string') {
69
+ throw new MilestoneEventStoreError('invalid_input', 'createPrismaMilestoneEventStore: description must be a string or null when present');
70
+ }
71
+ // Cross-field check: if BOTH startsAt and endsAt are in the patch and
72
+ // both non-null, they must satisfy startsAt <= endsAt.
73
+ if (patch.startsAt !== undefined &&
74
+ patch.endsAt !== undefined &&
75
+ patch.endsAt !== null &&
76
+ patch.endsAt.getTime() < patch.startsAt.getTime()) {
77
+ throw new MilestoneEventStoreError('invalid_input', 'createPrismaMilestoneEventStore: endsAt must be greater than or equal to startsAt');
78
+ }
79
+ }
80
+ // ─── Factory ─────────────────────────────────────────────────────────────
81
+ export function createPrismaMilestoneEventStore(config) {
82
+ const { prisma } = config;
83
+ return {
84
+ async list(filter) {
85
+ assertNonEmpty(filter.projectId, 'projectId');
86
+ const where = { projectId: filter.projectId };
87
+ const now = Date.now();
88
+ if (typeof filter.sinceMs === 'number' && Number.isFinite(filter.sinceMs)) {
89
+ const since = new Date(now - filter.sinceMs);
90
+ // A range milestone is "in window" if its startsAt OR endsAt
91
+ // falls in the trailing window. Point-in-time milestones (no
92
+ // endsAt) match on startsAt only.
93
+ where.OR = [{ startsAt: { gte: since } }, { endsAt: { gte: since } }];
94
+ }
95
+ if (typeof filter.untilMs === 'number' && Number.isFinite(filter.untilMs)) {
96
+ const until = new Date(now + filter.untilMs);
97
+ where.startsAt = { ...where.startsAt, lte: until };
98
+ }
99
+ if (Array.isArray(filter.kinds) && filter.kinds.length > 0) {
100
+ where.kind = { in: filter.kinds };
101
+ }
102
+ try {
103
+ const rows = await prisma.milestoneEvent.findMany({
104
+ where,
105
+ orderBy: { startsAt: 'asc' },
106
+ });
107
+ return rows.map(toMilestoneEvent);
108
+ }
109
+ catch (err) {
110
+ throw new MilestoneEventStoreError('storage_failed', `createPrismaMilestoneEventStore: list raised: ${err.message}`, err);
111
+ }
112
+ },
113
+ async create(input) {
114
+ assertCreateInput(input);
115
+ try {
116
+ const row = await prisma.milestoneEvent.create({
117
+ data: {
118
+ projectId: input.projectId,
119
+ name: input.name,
120
+ description: input.description ?? null,
121
+ startsAt: input.startsAt,
122
+ endsAt: input.endsAt ?? null,
123
+ kind: input.kind,
124
+ createdBy: input.createdBy,
125
+ },
126
+ });
127
+ return toMilestoneEvent(row);
128
+ }
129
+ catch (err) {
130
+ if (err instanceof Prisma.PrismaClientKnownRequestError && err.code === 'P2003') {
131
+ // FK violation on projectId — surface as invalid_input rather
132
+ // than storage_failed so the API layer can return 400 (the
133
+ // operator passed a nonexistent projectId, not a transient
134
+ // storage problem).
135
+ throw new MilestoneEventStoreError('invalid_input', `createPrismaMilestoneEventStore: projectId ${input.projectId} does not resolve to a Project row`, err);
136
+ }
137
+ throw new MilestoneEventStoreError('storage_failed', `createPrismaMilestoneEventStore: create raised: ${err.message}`, err);
138
+ }
139
+ },
140
+ async update(id, projectId, patch) {
141
+ assertNonEmpty(id, 'id');
142
+ assertNonEmpty(projectId, 'projectId');
143
+ assertUpdatePatch(patch);
144
+ // Two-step: updateMany returns count so we can distinguish
145
+ // not-found / wrong-tenant (count === 0) from a successful update
146
+ // without leaking existence via the standard `update` API's P2025.
147
+ try {
148
+ const data = {};
149
+ if (patch.name !== undefined)
150
+ data.name = patch.name;
151
+ if (patch.description !== undefined)
152
+ data.description = patch.description;
153
+ if (patch.startsAt !== undefined)
154
+ data.startsAt = patch.startsAt;
155
+ if (patch.endsAt !== undefined)
156
+ data.endsAt = patch.endsAt;
157
+ if (patch.kind !== undefined)
158
+ data.kind = patch.kind;
159
+ const result = await prisma.milestoneEvent.updateMany({
160
+ where: { id, projectId },
161
+ data,
162
+ });
163
+ if (result.count === 0) {
164
+ throw new MilestoneEventStoreError('not_found', `createPrismaMilestoneEventStore: milestone id=${id} not found in project ${projectId}`);
165
+ }
166
+ // Re-read to return the fresh row. updatedAt has been refreshed
167
+ // by Prisma's @updatedAt directive at this point.
168
+ const fresh = await prisma.milestoneEvent.findFirst({
169
+ where: { id, projectId },
170
+ });
171
+ if (fresh === null) {
172
+ // Concurrent delete between updateMany + findFirst. Rare; surface
173
+ // as not_found.
174
+ throw new MilestoneEventStoreError('not_found', `createPrismaMilestoneEventStore: milestone id=${id} disappeared after update in project ${projectId}`);
175
+ }
176
+ return toMilestoneEvent(fresh);
177
+ }
178
+ catch (err) {
179
+ if (err instanceof MilestoneEventStoreError)
180
+ throw err;
181
+ throw new MilestoneEventStoreError('storage_failed', `createPrismaMilestoneEventStore: update raised: ${err.message}`, err);
182
+ }
183
+ },
184
+ async delete(id, projectId) {
185
+ assertNonEmpty(id, 'id');
186
+ assertNonEmpty(projectId, 'projectId');
187
+ try {
188
+ const result = await prisma.milestoneEvent.deleteMany({
189
+ where: { id, projectId },
190
+ });
191
+ return result.count > 0;
192
+ }
193
+ catch (err) {
194
+ throw new MilestoneEventStoreError('storage_failed', `createPrismaMilestoneEventStore: delete raised: ${err.message}`, err);
195
+ }
196
+ },
197
+ };
198
+ }
199
+ /**
200
+ * Project a Prisma row to the SDK MilestoneEvent shape. Per memory
201
+ * rule 22, no defensive `as PrismaMilestoneEventRow` cast at the
202
+ * argument site — the inferred Prisma return type is exact after
203
+ * `prisma generate`. The inline interface above just documents the
204
+ * shape for readers; it's structurally compatible with the generated
205
+ * MilestoneEventGetPayload.
206
+ */
207
+ function toMilestoneEvent(row) {
208
+ return {
209
+ id: row.id,
210
+ projectId: row.projectId,
211
+ name: row.name,
212
+ description: row.description,
213
+ startsAt: row.startsAt,
214
+ endsAt: row.endsAt,
215
+ kind: row.kind,
216
+ createdBy: row.createdBy,
217
+ createdAt: row.createdAt,
218
+ updatedAt: row.updatedAt,
219
+ };
220
+ }
221
+ //# sourceMappingURL=milestone-event-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"milestone-event-store.js","sourceRoot":"","sources":["../src/milestone-event-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,EAAq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;;;GAOG;AACH,SAAS,gBAAgB,CAAC,GAAsB;IAC9C,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * createPrismaRumSampleStore — Prisma-backed implementation of the SDK
3
+ * RumSampleStore contract introduced by QAP-113.
4
+ *
5
+ * Sprint 11 Phase 3 (Test Surfaces — RUM ingestion). Samples are stored as
6
+ * one row per insert against the `RumSample` model. There is no uniqueness
7
+ * constraint on (projectId, metric) — a single page-load may emit multiple
8
+ * samples per metric, and operators need the full distribution to derive
9
+ * percentiles.
10
+ *
11
+ * Tenant isolation: every method scopes by projectId. Pattern D applies —
12
+ * unknown / wrong-project lookups return null from `getBaseline` rather
13
+ * than throwing or leaking existence (defense-in-depth against tenant
14
+ * enumeration). The "no samples in window" return is also null, so
15
+ * cross-tenant probes look identical to "no data this window".
16
+ *
17
+ * Percentile math: derived in-memory via array-index math after the
18
+ * `findMany` returns a value-sorted result set. No third-party stats
19
+ * library — RumSample row sets per (projectId, metric, window) cap at the
20
+ * tens-of-thousands order of magnitude, which fits comfortably in process
21
+ * memory for the percentile read.
22
+ */
23
+ import type { PrismaClient } from './prisma.js';
24
+ import type { RumSampleStore } from '@derwinjs/sdk';
25
+ export interface PrismaRumSampleStoreConfig {
26
+ /** Generated Prisma client. Pass an instance per process. */
27
+ prisma: PrismaClient;
28
+ }
29
+ /**
30
+ * Errors thrown by the Prisma-backed RumSampleStore. The store-level
31
+ * errors are kept inside @derwinjs/db (NOT promoted to @derwinjs/sdk)
32
+ * because they reflect storage-layer specifics; the route layer maps
33
+ * them to the operator-facing WebVitalsIngestorError before crossing
34
+ * the SDK boundary.
35
+ *
36
+ * The discriminating `code` field lets callers route handling:
37
+ * - `invalid_input` — caller bug rejected at the factory boundary; do
38
+ * not retry.
39
+ * - `io_failed` — underlying Prisma call raised; transient — retry
40
+ * or escalate.
41
+ */
42
+ export declare class RumSampleStoreError extends Error {
43
+ readonly code: 'invalid_input' | 'io_failed';
44
+ readonly cause?: unknown | undefined;
45
+ constructor(code: 'invalid_input' | 'io_failed', message: string, cause?: unknown | undefined);
46
+ }
47
+ export declare function createPrismaRumSampleStore(config: PrismaRumSampleStoreConfig): RumSampleStore;
48
+ //# sourceMappingURL=rum-sample-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rum-sample-store.d.ts","sourceRoot":"","sources":["../src/rum-sample-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,eAAe,CAAC;AAIjE,MAAM,WAAW,0BAA0B;IACzC,6DAA6D;IAC7D,MAAM,EAAE,YAAY,CAAC;CACtB;AAID;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,IAAI,EAAE,eAAe,GAAG,WAAW;aAE1B,KAAK,CAAC,EAAE,OAAO;gBAFxB,IAAI,EAAE,eAAe,GAAG,WAAW,EACnD,OAAO,EAAE,MAAM,EACU,KAAK,CAAC,EAAE,OAAO,YAAA;CAM3C;AAmED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,cAAc,CAwF7F"}