@pipeline-builder/pipeline-data 4.4.4 → 5.0.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 (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/api/crud-service.d.ts +48 -3
  3. package/lib/api/crud-service.js +117 -43
  4. package/lib/api/ecosystem-privacy.d.ts +2 -4
  5. package/lib/api/ecosystem-privacy.js +8 -10
  6. package/lib/api/org-data-ownership.d.ts +41 -0
  7. package/lib/api/org-data-ownership.js +127 -0
  8. package/lib/api/org-data-purge.d.ts +34 -0
  9. package/lib/api/org-data-purge.js +74 -0
  10. package/lib/api/plugin-advisories.js +4 -4
  11. package/lib/api/plugin-resolution.js +6 -6
  12. package/lib/api/public-directory.js +3 -3
  13. package/lib/api/reporting/analytics-queries.d.ts +5 -0
  14. package/lib/api/reporting/analytics-queries.js +7 -1
  15. package/lib/api/reporting/daily-rollup.js +33 -15
  16. package/lib/api/reporting/deploy-rollup.js +7 -1
  17. package/lib/api/reporting/dora.js +5 -2
  18. package/lib/api/reporting/sql-helpers.d.ts +48 -0
  19. package/lib/api/reporting/sql-helpers.js +60 -1
  20. package/lib/api/reporting/types.d.ts +4 -0
  21. package/lib/api/reporting/types.js +1 -1
  22. package/lib/api/reporting-service.d.ts +8 -5
  23. package/lib/api/reporting-service.js +48 -17
  24. package/lib/api/semver-range.d.ts +1 -58
  25. package/lib/api/semver-range.js +10 -171
  26. package/lib/api/soft-delete-sweep.d.ts +1 -1
  27. package/lib/api/soft-delete-sweep.js +1 -1
  28. package/lib/core/query-filters.d.ts +2 -134
  29. package/lib/core/query-filters.js +1 -1
  30. package/lib/database/drizzle-schema.d.ts +202 -0
  31. package/lib/database/drizzle-schema.js +3 -2
  32. package/lib/database/index.d.ts +2 -1
  33. package/lib/database/index.js +2 -2
  34. package/lib/database/postgres-connection.js +13 -1
  35. package/lib/database/read-lag.js +8 -31
  36. package/lib/database/schema/alert.d.ts +203 -0
  37. package/lib/database/schema/alert.js +39 -4
  38. package/lib/database/schema/dashboard.d.ts +1 -1
  39. package/lib/database/schema/dashboard.js +4 -4
  40. package/lib/database/schema/message.d.ts +17 -0
  41. package/lib/database/schema/message.js +6 -1
  42. package/lib/database/schema/pipeline.js +5 -5
  43. package/lib/database/schema/plugin.d.ts +2 -43
  44. package/lib/database/schema/plugin.js +3 -1
  45. package/lib/index.d.ts +4 -2
  46. package/lib/index.js +4 -2
  47. package/package.json +13 -4
  48. package/lib/testing/exports.json +0 -311
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog — @pipeline-builder/pipeline-data
2
+
3
+ Release versions are stamped by `nx release` (conventional commits). This file records
4
+ breaking changes in the public surface only.
5
+
6
+ ## 5.0.0 (unreleased)
7
+
8
+ ### BREAKING CHANGES — `./lib/*` removed; `./testing` is workspace-only.
9
+
10
+ The package's public surface is now exactly its `exports` map. Anything not listed below cannot be imported (`ERR_PACKAGE_PATH_NOT_EXPORTED`).
11
+
12
+ - **Entries:** `.`, `./package.json`.
13
+ - The `./lib/*` wildcard is gone, so `@pipeline-builder/pipeline-data/lib/...` deep imports no longer resolve.
14
+ - `./testing` is no longer in the published map. The tarball never contained `lib/testing/` (it needs the PGlite devDependency and the repo's `deploy/` init script), so the old entry pointed at nothing. It stays a workspace-only entry for this repo's test suites.
@@ -17,6 +17,34 @@ export declare function drizzleCount(rows: unknown): [{
17
17
  * `onBeforePurge` so a subclass's dependent teardown runs in the SAME purge
18
18
  * transaction (atomic with the parent DELETE), not a fresh connection. */
19
19
  export type CrudTx = Parameters<Parameters<typeof withTenantTx>[0]>[0];
20
+ /**
21
+ * What an in-transaction mutation hook ({@link CrudService.onCreateInTx} and
22
+ * friends) is told about the write: who made it, and (for update/delete) the
23
+ * org the write was pinned to.
24
+ */
25
+ export interface CrudMutationContext {
26
+ /** The acting user (the system actor id for background work). */
27
+ userId: string;
28
+ /** The org the write was scoped to (update/delete); absent on create. */
29
+ orgId?: string;
30
+ /** Which write fired the hook. */
31
+ operation: 'create' | 'update' | 'updateMany' | 'delete' | 'bulkDelete';
32
+ }
33
+ /** Options for {@link CrudService.update}. */
34
+ export interface UpdateOptions {
35
+ /**
36
+ * Optimistic concurrency: write only if the row's `updated_at` still equals
37
+ * this (compared at millisecond precision — what a JSON round-trip of the
38
+ * read keeps). When the row exists but has moved on, the update throws
39
+ * `ConcurrencyConflictError` (412 PRECONDITION_FAILED) instead of returning
40
+ * null. An unparseable value is a 400 ValidationError.
41
+ *
42
+ * The token is `updated_at` (stamped from the app clock on every write), so
43
+ * two writes within the same millisecond are indistinguishable — adequate
44
+ * for human-paced edits, not a substitute for a lock on hot rows.
45
+ */
46
+ expectedUpdatedAt?: Date | string;
47
+ }
20
48
  /**
21
49
  * Base interface for entities with common fields
22
50
  */
@@ -178,6 +206,12 @@ export declare abstract class CrudService<TEntity extends BaseEntity, TFilter, T
178
206
  * `onAfterPurge` handles external side-effects best-effort. Returns the ids.
179
207
  */
180
208
  private purgeWhere;
209
+ /** Called inside the create transaction, after the INSERT. */
210
+ protected onCreateInTx(_entity: TEntity, _tx: CrudTx, _ctx: CrudMutationContext): Promise<void>;
211
+ /** Called inside the update transaction for each updated row (update / updateMany). */
212
+ protected onUpdateInTx(_entity: TEntity, _tx: CrudTx, _ctx: CrudMutationContext): Promise<void>;
213
+ /** Called inside the soft-delete transaction for each deleted row (delete / bulkDelete). */
214
+ protected onDeleteInTx(_entity: TEntity, _tx: CrudTx, _ctx: CrudMutationContext): Promise<void>;
181
215
  /** Called after a new entity is created */
182
216
  protected onAfterCreate(_entity: TEntity, _userId: string): Promise<void>;
183
217
  /** Called after an entity is updated */
@@ -191,8 +225,11 @@ export declare abstract class CrudService<TEntity extends BaseEntity, TFilter, T
191
225
  * transaction (`tx`) so the subclass's check and the restore are atomic —
192
226
  * e.g. a plugin tombstone that was the default must not come back as a
193
227
  * second live default. Unlike the after-hooks this is NOT best-effort:
194
- * throwing aborts the restore. */
195
- protected restoreExtraSet(_id: string, _tx: CrudTx): Promise<Record<string, unknown>>;
228
+ * throwing aborts the restore. `orgId` is the org pin the restore UPDATE
229
+ * applies (undefined = a cross-org sysadmin restore) and `userId` the
230
+ * restoring actor, so a subclass doing dependent writes can apply the same
231
+ * scope and audit stamp the root restore will. */
232
+ protected restoreExtraSet(_id: string, _tx: CrudTx, _orgId?: string, _userId?: string): Promise<Record<string, unknown>>;
196
233
  /** Called with the ids about to be hard-purged, BEFORE the delete, inside the
197
234
  * purge transaction (`tx`) — a subclass tearing down dependents that lack ON
198
235
  * DELETE CASCADE MUST use `tx` so the teardown is atomic with the parent
@@ -315,7 +352,15 @@ export declare abstract class CrudService<TEntity extends BaseEntity, TFilter, T
315
352
  /**
316
353
  * Update an existing entity
317
354
  */
318
- update(id: string, data: Partial<TUpdate>, orgId: string, userId: string): Promise<TEntity | null>;
355
+ update(id: string, data: Partial<TUpdate>, orgId: string, userId: string, options?: UpdateOptions): Promise<TEntity | null>;
356
+ /** Parse an `expectedUpdatedAt` option; an invalid value is the caller's 400. */
357
+ private expectedTimestamp;
358
+ /**
359
+ * `updated_at` equals `expected` at MILLISECOND precision. Postgres keeps
360
+ * microseconds (a `defaultNow()` insert), a client's copy of the timestamp
361
+ * (JSON, a JS Date) keeps milliseconds — an exact compare would always fail.
362
+ */
363
+ private updatedAtMatches;
319
364
  /**
320
365
  * Delete an entity (soft delete by setting isActive = false)
321
366
  */