@kelpie/server 0.12.0 → 0.13.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.
- package/dist/app.d.ts +13 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +8 -1
- package/dist/app.js.map +1 -1
- package/dist/boot.d.ts.map +1 -1
- package/dist/boot.js +1 -0
- package/dist/boot.js.map +1 -1
- package/dist/lib/apiKeyScopes.d.ts.map +1 -1
- package/dist/lib/apiKeyScopes.js +6 -0
- package/dist/lib/apiKeyScopes.js.map +1 -1
- package/dist/lib/columns.d.ts +6 -0
- package/dist/lib/columns.d.ts.map +1 -1
- package/dist/lib/columns.js +5 -3
- package/dist/lib/columns.js.map +1 -1
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +3 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/egress.d.ts.map +1 -1
- package/dist/lib/egress.js +8 -4
- package/dist/lib/egress.js.map +1 -1
- package/dist/lib/errors.d.ts +3 -3
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +13 -5
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/ids.d.ts +11 -0
- package/dist/lib/ids.d.ts.map +1 -1
- package/dist/lib/ids.js +11 -0
- package/dist/lib/ids.js.map +1 -1
- package/dist/lib/kelpieConfigFile.d.ts +15 -1
- package/dist/lib/kelpieConfigFile.d.ts.map +1 -1
- package/dist/lib/kelpieConfigFile.js +33 -1
- package/dist/lib/kelpieConfigFile.js.map +1 -1
- package/dist/modules/agent-tasks/catalog.d.ts.map +1 -1
- package/dist/modules/agent-tasks/catalog.js +32 -1
- package/dist/modules/agent-tasks/catalog.js.map +1 -1
- package/dist/modules/agent-tasks/index.d.ts.map +1 -1
- package/dist/modules/agent-tasks/index.js +1 -0
- package/dist/modules/agent-tasks/index.js.map +1 -1
- package/dist/modules/agent-tasks/resolve.d.ts.map +1 -1
- package/dist/modules/agent-tasks/resolve.js +5 -0
- package/dist/modules/agent-tasks/resolve.js.map +1 -1
- package/dist/modules/agent-tasks/routes.d.ts +2 -0
- package/dist/modules/agent-tasks/routes.d.ts.map +1 -1
- package/dist/modules/attachedRecords.d.ts +22 -8
- package/dist/modules/attachedRecords.d.ts.map +1 -1
- package/dist/modules/attachedRecords.js +42 -5
- package/dist/modules/attachedRecords.js.map +1 -1
- package/dist/modules/auth/index.d.ts.map +1 -1
- package/dist/modules/auth/index.js +1 -0
- package/dist/modules/auth/index.js.map +1 -1
- package/dist/modules/auth/repository.d.ts +14 -0
- package/dist/modules/auth/repository.d.ts.map +1 -1
- package/dist/modules/auth/repository.js +20 -2
- package/dist/modules/auth/repository.js.map +1 -1
- package/dist/modules/auth/routes.d.ts.map +1 -1
- package/dist/modules/auth/routes.js +30 -0
- package/dist/modules/auth/routes.js.map +1 -1
- package/dist/modules/auth/service.d.ts +28 -0
- package/dist/modules/auth/service.d.ts.map +1 -1
- package/dist/modules/auth/service.js +72 -4
- package/dist/modules/auth/service.js.map +1 -1
- package/dist/modules/companies/repository.d.ts.map +1 -1
- package/dist/modules/companies/repository.js +1 -1
- package/dist/modules/companies/repository.js.map +1 -1
- package/dist/modules/companies/routes.d.ts +2 -4
- package/dist/modules/companies/routes.d.ts.map +1 -1
- package/dist/modules/companies/routes.js +6 -11
- package/dist/modules/companies/routes.js.map +1 -1
- package/dist/modules/companies/schema.d.ts +13 -28
- package/dist/modules/companies/schema.d.ts.map +1 -1
- package/dist/modules/companies/schema.js +2 -2
- package/dist/modules/companies/schema.js.map +1 -1
- package/dist/modules/companies/service.d.ts +2 -3
- package/dist/modules/companies/service.d.ts.map +1 -1
- package/dist/modules/companies/service.js +4 -7
- package/dist/modules/companies/service.js.map +1 -1
- package/dist/modules/core.d.ts.map +1 -1
- package/dist/modules/core.js +2 -0
- package/dist/modules/core.js.map +1 -1
- package/dist/modules/custom-fields/repository.d.ts.map +1 -1
- package/dist/modules/custom-fields/repository.js +2 -0
- package/dist/modules/custom-fields/repository.js.map +1 -1
- package/dist/modules/custom-fields/routes.d.ts +1 -0
- package/dist/modules/custom-fields/routes.d.ts.map +1 -1
- package/dist/modules/dashboard/index.d.ts.map +1 -1
- package/dist/modules/dashboard/index.js +1 -0
- package/dist/modules/dashboard/index.js.map +1 -1
- package/dist/modules/dashboard/repository.d.ts +13 -0
- package/dist/modules/dashboard/repository.d.ts.map +1 -1
- package/dist/modules/dashboard/repository.js +36 -0
- package/dist/modules/dashboard/repository.js.map +1 -1
- package/dist/modules/dashboard/routes.d.ts.map +1 -1
- package/dist/modules/dashboard/routes.js +13 -0
- package/dist/modules/dashboard/routes.js.map +1 -1
- package/dist/modules/dashboard/service.d.ts +11 -0
- package/dist/modules/dashboard/service.d.ts.map +1 -1
- package/dist/modules/dashboard/service.js +24 -1
- package/dist/modules/dashboard/service.js.map +1 -1
- package/dist/modules/decisions/repository.d.ts.map +1 -1
- package/dist/modules/decisions/repository.js +2 -0
- package/dist/modules/decisions/repository.js.map +1 -1
- package/dist/modules/decisions/routes.d.ts +2 -0
- package/dist/modules/decisions/routes.d.ts.map +1 -1
- package/dist/modules/events/attendances.d.ts +35 -0
- package/dist/modules/events/attendances.d.ts.map +1 -0
- package/dist/modules/events/attendances.js +157 -0
- package/dist/modules/events/attendances.js.map +1 -0
- package/dist/modules/events/catalog.d.ts +35 -0
- package/dist/modules/events/catalog.d.ts.map +1 -0
- package/dist/modules/events/catalog.js +11 -0
- package/dist/modules/events/catalog.js.map +1 -0
- package/dist/modules/events/index.d.ts +10 -0
- package/dist/modules/events/index.d.ts.map +1 -0
- package/dist/modules/events/index.js +47 -0
- package/dist/modules/events/index.js.map +1 -0
- package/dist/modules/events/repository.d.ts +67 -0
- package/dist/modules/events/repository.d.ts.map +1 -0
- package/dist/modules/events/repository.js +212 -0
- package/dist/modules/events/repository.js.map +1 -0
- package/dist/modules/events/routes.d.ts +136 -0
- package/dist/modules/events/routes.d.ts.map +1 -0
- package/dist/modules/events/routes.js +280 -0
- package/dist/modules/events/routes.js.map +1 -0
- package/dist/modules/events/schema.d.ts +626 -0
- package/dist/modules/events/schema.d.ts.map +1 -0
- package/dist/modules/events/schema.js +93 -0
- package/dist/modules/events/schema.js.map +1 -0
- package/dist/modules/events/service.d.ts +68 -0
- package/dist/modules/events/service.d.ts.map +1 -0
- package/dist/modules/events/service.js +262 -0
- package/dist/modules/events/service.js.map +1 -0
- package/dist/modules/events/tools.d.ts +8 -0
- package/dist/modules/events/tools.d.ts.map +1 -0
- package/dist/modules/events/tools.js +80 -0
- package/dist/modules/events/tools.js.map +1 -0
- package/dist/modules/forms/applySubmissionFields.d.ts.map +1 -1
- package/dist/modules/forms/applySubmissionFields.js +7 -5
- package/dist/modules/forms/applySubmissionFields.js.map +1 -1
- package/dist/modules/forms/fillAddresses.d.ts +4 -0
- package/dist/modules/forms/fillAddresses.d.ts.map +1 -0
- package/dist/modules/forms/fillAddresses.js +93 -0
- package/dist/modules/forms/fillAddresses.js.map +1 -0
- package/dist/modules/forms/repository.d.ts +2 -2
- package/dist/modules/forms/repository.d.ts.map +1 -1
- package/dist/modules/forms/repository.js.map +1 -1
- package/dist/modules/forms/routes.d.ts +2 -0
- package/dist/modules/forms/routes.d.ts.map +1 -1
- package/dist/modules/forms/routes.js +2 -2
- package/dist/modules/forms/routes.js.map +1 -1
- package/dist/modules/forms/schema.js +2 -2
- package/dist/modules/forms/schema.js.map +1 -1
- package/dist/modules/forms/service.js +2 -2
- package/dist/modules/forms/service.js.map +1 -1
- package/dist/modules/forms/submission.d.ts +1 -0
- package/dist/modules/forms/submission.d.ts.map +1 -1
- package/dist/modules/forms/submission.js +27 -4
- package/dist/modules/forms/submission.js.map +1 -1
- package/dist/modules/hiring/roles.d.ts.map +1 -1
- package/dist/modules/hiring/roles.js +2 -1
- package/dist/modules/hiring/roles.js.map +1 -1
- package/dist/modules/import-export/addresses.d.ts +22 -0
- package/dist/modules/import-export/addresses.d.ts.map +1 -0
- package/dist/modules/import-export/addresses.js +83 -0
- package/dist/modules/import-export/addresses.js.map +1 -0
- package/dist/modules/import-export/drafts.d.ts +3 -4
- package/dist/modules/import-export/drafts.d.ts.map +1 -1
- package/dist/modules/import-export/drafts.js +4 -5
- package/dist/modules/import-export/drafts.js.map +1 -1
- package/dist/modules/import-export/exportRows.d.ts.map +1 -1
- package/dist/modules/import-export/exportRows.js +3 -3
- package/dist/modules/import-export/exportRows.js.map +1 -1
- package/dist/modules/import-export/plan.d.ts.map +1 -1
- package/dist/modules/import-export/plan.js +17 -2
- package/dist/modules/import-export/plan.js.map +1 -1
- package/dist/modules/import-export/presets.d.ts.map +1 -1
- package/dist/modules/import-export/presets.js +52 -7
- package/dist/modules/import-export/presets.js.map +1 -1
- package/dist/modules/import-export/repository.d.ts +3 -4
- package/dist/modules/import-export/repository.d.ts.map +1 -1
- package/dist/modules/import-export/repository.js +2 -3
- package/dist/modules/import-export/repository.js.map +1 -1
- package/dist/modules/import-export/writes.d.ts.map +1 -1
- package/dist/modules/import-export/writes.js +8 -4
- package/dist/modules/import-export/writes.js.map +1 -1
- package/dist/modules/lists/routes.d.ts +4 -0
- package/dist/modules/lists/routes.d.ts.map +1 -1
- package/dist/modules/notes/routes.d.ts +2 -0
- package/dist/modules/notes/routes.d.ts.map +1 -1
- package/dist/modules/people/repository.d.ts.map +1 -1
- package/dist/modules/people/repository.js +1 -1
- package/dist/modules/people/repository.js.map +1 -1
- package/dist/modules/people/routes.d.ts +2 -2
- package/dist/modules/people/routes.js +6 -6
- package/dist/modules/people/routes.js.map +1 -1
- package/dist/modules/people/schema.d.ts +17 -14
- package/dist/modules/people/schema.d.ts.map +1 -1
- package/dist/modules/people/schema.js +6 -4
- package/dist/modules/people/schema.js.map +1 -1
- package/dist/modules/people/service.d.ts +2 -2
- package/dist/modules/people/service.d.ts.map +1 -1
- package/dist/modules/people/service.js +5 -4
- package/dist/modules/people/service.js.map +1 -1
- package/dist/modules/plans/repository.d.ts +2 -2
- package/dist/modules/plans/repository.d.ts.map +1 -1
- package/dist/modules/plans/routes.d.ts +1 -0
- package/dist/modules/plans/routes.d.ts.map +1 -1
- package/dist/modules/plans/routes.js +4 -4
- package/dist/modules/plans/routes.js.map +1 -1
- package/dist/modules/plans/schema.d.ts +2 -2
- package/dist/modules/plans/schema.d.ts.map +1 -1
- package/dist/modules/plans/schema.js +3 -3
- package/dist/modules/plans/schema.js.map +1 -1
- package/dist/modules/plans/service.d.ts +2 -2
- package/dist/modules/plans/service.d.ts.map +1 -1
- package/dist/modules/plans/service.js.map +1 -1
- package/dist/modules/plans/tools.js +2 -2
- package/dist/modules/plans/tools.js.map +1 -1
- package/dist/modules/recordTargets.d.ts.map +1 -1
- package/dist/modules/recordTargets.js +11 -0
- package/dist/modules/recordTargets.js.map +1 -1
- package/dist/modules/references.d.ts.map +1 -1
- package/dist/modules/references.js +2 -0
- package/dist/modules/references.js.map +1 -1
- package/dist/modules/sample-data/fixture.d.ts +26 -4
- package/dist/modules/sample-data/fixture.d.ts.map +1 -1
- package/dist/modules/sample-data/fixture.js +157 -23
- package/dist/modules/sample-data/fixture.js.map +1 -1
- package/dist/modules/sample-data/index.d.ts +5 -2
- package/dist/modules/sample-data/index.d.ts.map +1 -1
- package/dist/modules/sample-data/index.js +7 -2
- package/dist/modules/sample-data/index.js.map +1 -1
- package/dist/modules/sample-data/routes.d.ts.map +1 -1
- package/dist/modules/sample-data/routes.js +2 -0
- package/dist/modules/sample-data/routes.js.map +1 -1
- package/dist/modules/sample-data/service.d.ts +11 -3
- package/dist/modules/sample-data/service.d.ts.map +1 -1
- package/dist/modules/sample-data/service.js +452 -363
- package/dist/modules/sample-data/service.js.map +1 -1
- package/dist/modules/sample-data/tools.d.ts.map +1 -1
- package/dist/modules/sample-data/tools.js +4 -3
- package/dist/modules/sample-data/tools.js.map +1 -1
- package/dist/modules/search/index.d.ts +1 -1
- package/dist/modules/search/index.d.ts.map +1 -1
- package/dist/modules/search/index.js +2 -1
- package/dist/modules/search/index.js.map +1 -1
- package/dist/modules/search/repository.d.ts +1 -0
- package/dist/modules/search/repository.d.ts.map +1 -1
- package/dist/modules/search/repository.js +22 -0
- package/dist/modules/search/repository.js.map +1 -1
- package/dist/modules/search/service.d.ts +2 -2
- package/dist/modules/search/service.d.ts.map +1 -1
- package/dist/modules/search/service.js +4 -3
- package/dist/modules/search/service.js.map +1 -1
- package/dist/modules/smtp-email/index.d.ts +12 -4
- package/dist/modules/smtp-email/index.d.ts.map +1 -1
- package/dist/modules/smtp-email/index.js +25 -5
- package/dist/modules/smtp-email/index.js.map +1 -1
- package/dist/modules/workspace/repository.d.ts +2 -0
- package/dist/modules/workspace/repository.d.ts.map +1 -1
- package/dist/modules/workspace/repository.js +12 -0
- package/dist/modules/workspace/repository.js.map +1 -1
- package/dist/modules/workspace/routes.d.ts.map +1 -1
- package/dist/modules/workspace/routes.js +13 -0
- package/dist/modules/workspace/routes.js.map +1 -1
- package/dist/modules/workspace/service.d.ts +10 -0
- package/dist/modules/workspace/service.d.ts.map +1 -1
- package/dist/modules/workspace/service.js +34 -10
- package/dist/modules/workspace/service.js.map +1 -1
- package/dist/modules/workspace/starters.d.ts +17 -2
- package/dist/modules/workspace/starters.d.ts.map +1 -1
- package/dist/modules/workspace/starters.js +141 -14
- package/dist/modules/workspace/starters.js.map +1 -1
- package/dist/modules/workspace/workspaceAccessMiddleware.d.ts.map +1 -1
- package/dist/modules/workspace/workspaceAccessMiddleware.js +3 -4
- package/dist/modules/workspace/workspaceAccessMiddleware.js.map +1 -1
- package/dist/runtime/events.d.ts +1 -1
- package/dist/runtime/events.d.ts.map +1 -1
- package/dist/runtime/events.js +2 -0
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/module.d.ts +8 -0
- package/dist/runtime/module.d.ts.map +1 -1
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +102 -7
- package/dist/runtime/registry.js.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/testing/app.d.ts +8 -0
- package/dist/testing/app.d.ts.map +1 -1
- package/dist/testing/app.js +6 -1
- package/dist/testing/app.js.map +1 -1
- package/dist/testing/client.d.ts.map +1 -1
- package/dist/testing/client.js +9 -1
- package/dist/testing/client.js.map +1 -1
- package/migrations/0044_events.sql +79 -0
- package/migrations/0045_addresses.sql +66 -0
- package/migrations/0046_drop_company_website.sql +66 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +3 -3
- package/src/app.ts +25 -1
- package/src/boot.ts +1 -0
- package/src/lib/apiKeyScopes.ts +6 -0
- package/src/lib/columns.ts +12 -3
- package/src/lib/config.ts +21 -0
- package/src/lib/egress.ts +8 -4
- package/src/lib/errors.ts +16 -9
- package/src/lib/ids.ts +11 -0
- package/src/lib/kelpieConfigFile.ts +69 -1
- package/src/modules/agent-tasks/catalog.ts +33 -1
- package/src/modules/agent-tasks/index.ts +1 -0
- package/src/modules/agent-tasks/resolve.ts +11 -0
- package/src/modules/attachedRecords.ts +85 -13
- package/src/modules/auth/index.ts +1 -0
- package/src/modules/auth/repository.ts +34 -3
- package/src/modules/auth/routes.ts +44 -1
- package/src/modules/auth/service.ts +118 -4
- package/src/modules/companies/repository.ts +1 -0
- package/src/modules/companies/routes.ts +6 -11
- package/src/modules/companies/schema.ts +3 -3
- package/src/modules/companies/service.ts +6 -10
- package/src/modules/core.ts +2 -0
- package/src/modules/custom-fields/repository.ts +2 -0
- package/src/modules/dashboard/index.ts +1 -0
- package/src/modules/dashboard/repository.ts +64 -0
- package/src/modules/dashboard/routes.ts +15 -0
- package/src/modules/dashboard/service.ts +48 -0
- package/src/modules/decisions/repository.ts +2 -0
- package/src/modules/events/attendances.ts +245 -0
- package/src/modules/events/catalog.ts +36 -0
- package/src/modules/events/index.ts +54 -0
- package/src/modules/events/repository.ts +396 -0
- package/src/modules/events/routes.ts +405 -0
- package/src/modules/events/schema.ts +148 -0
- package/src/modules/events/service.ts +443 -0
- package/src/modules/events/tools.ts +118 -0
- package/src/modules/forms/applySubmissionFields.ts +7 -5
- package/src/modules/forms/fillAddresses.ts +185 -0
- package/src/modules/forms/repository.ts +3 -3
- package/src/modules/forms/routes.ts +2 -2
- package/src/modules/forms/schema.ts +2 -2
- package/src/modules/forms/service.ts +2 -2
- package/src/modules/forms/submission.ts +34 -4
- package/src/modules/hiring/roles.ts +2 -1
- package/src/modules/import-export/addresses.ts +150 -0
- package/src/modules/import-export/drafts.ts +7 -9
- package/src/modules/import-export/exportRows.ts +3 -3
- package/src/modules/import-export/plan.ts +30 -2
- package/src/modules/import-export/presets.ts +55 -7
- package/src/modules/import-export/repository.ts +5 -7
- package/src/modules/import-export/writes.ts +8 -4
- package/src/modules/people/repository.ts +1 -0
- package/src/modules/people/routes.ts +6 -6
- package/src/modules/people/schema.ts +7 -5
- package/src/modules/people/service.ts +7 -5
- package/src/modules/plans/repository.ts +2 -2
- package/src/modules/plans/routes.ts +6 -6
- package/src/modules/plans/schema.ts +4 -4
- package/src/modules/plans/service.ts +3 -3
- package/src/modules/plans/tools.ts +2 -2
- package/src/modules/recordTargets.ts +14 -0
- package/src/modules/references.ts +2 -0
- package/src/modules/sample-data/fixture.ts +208 -27
- package/src/modules/sample-data/index.ts +7 -2
- package/src/modules/sample-data/routes.ts +2 -0
- package/src/modules/sample-data/service.ts +166 -49
- package/src/modules/sample-data/tools.ts +4 -3
- package/src/modules/search/index.ts +2 -1
- package/src/modules/search/repository.ts +32 -1
- package/src/modules/search/service.ts +6 -4
- package/src/modules/smtp-email/index.ts +32 -10
- package/src/modules/workspace/repository.ts +18 -0
- package/src/modules/workspace/routes.ts +16 -0
- package/src/modules/workspace/service.ts +59 -14
- package/src/modules/workspace/starters.ts +275 -14
- package/src/modules/workspace/workspaceAccessMiddleware.ts +3 -4
- package/src/runtime/events.ts +2 -0
- package/src/runtime/module.ts +8 -0
- package/src/runtime/registry.ts +122 -8
- package/src/schema/index.ts +1 -0
- package/src/testing/app.ts +14 -1
- package/src/testing/client.ts +11 -1
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { and, asc, eq, gte, ilike, inArray, lte, or, sql } from 'drizzle-orm'
|
|
2
|
+
import type { SQL } from 'drizzle-orm'
|
|
3
|
+
|
|
4
|
+
import type { IdFactory } from '../../lib/ids.ts'
|
|
5
|
+
import { keysetCondition, orderByWindow, textSort, timestampSort } from '../../lib/pagination.ts'
|
|
6
|
+
import type { ListWindow, SortableFields } from '../../lib/pagination.ts'
|
|
7
|
+
import { arrayContainsPattern, containsPattern } from '../../lib/search.ts'
|
|
8
|
+
import type { Queryable } from '../../runtime/transaction.ts'
|
|
9
|
+
import { workspaceMembers } from '../workspace/schema.ts'
|
|
10
|
+
import { attendances, eventAssociations, events } from './schema.ts'
|
|
11
|
+
import type { EventAssociationTargetType } from './schema.ts'
|
|
12
|
+
|
|
13
|
+
export type EventRecord = typeof events.$inferSelect
|
|
14
|
+
export type EventColumns = typeof events.$inferInsert
|
|
15
|
+
export type AttendanceRecord = typeof attendances.$inferSelect
|
|
16
|
+
export type AttendanceColumns = typeof attendances.$inferInsert
|
|
17
|
+
export type EventAssociationRecord = typeof eventAssociations.$inferSelect
|
|
18
|
+
|
|
19
|
+
export const EVENT_SORTS: SortableFields<EventRecord> = {
|
|
20
|
+
name: textSort(events.name, (event) => event.name),
|
|
21
|
+
starts_at: timestampSort(events.startsAt, (event) => event.startsAt),
|
|
22
|
+
created_at: timestampSort(events.createdAt, (event) => event.createdAt),
|
|
23
|
+
updated_at: timestampSort(events.updatedAt, (event) => event.updatedAt),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DEFAULT_EVENT_SORT = 'starts_at'
|
|
27
|
+
|
|
28
|
+
export interface EventFilters {
|
|
29
|
+
readonly term?: string | undefined
|
|
30
|
+
readonly statuses?: readonly string[] | undefined
|
|
31
|
+
readonly formats?: readonly string[] | undefined
|
|
32
|
+
readonly ownerIds?: readonly string[] | undefined
|
|
33
|
+
readonly from?: Date | undefined
|
|
34
|
+
readonly to?: Date | undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function matchesTerm(term: string): SQL | undefined {
|
|
38
|
+
const pattern = containsPattern(term)
|
|
39
|
+
|
|
40
|
+
return or(
|
|
41
|
+
ilike(events.name, pattern),
|
|
42
|
+
ilike(events.summary, pattern),
|
|
43
|
+
ilike(events.kind, pattern),
|
|
44
|
+
ilike(events.location, pattern),
|
|
45
|
+
ilike(events.details, pattern),
|
|
46
|
+
arrayContainsPattern(events.tags, pattern),
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function eventConditionsFor(workspaceId: string, filters: EventFilters): (SQL | undefined)[] {
|
|
51
|
+
return [
|
|
52
|
+
eq(events.workspaceId, workspaceId),
|
|
53
|
+
filters.term === undefined ? undefined : matchesTerm(filters.term),
|
|
54
|
+
filters.statuses === undefined ? undefined : inArray(events.status, filters.statuses),
|
|
55
|
+
filters.formats === undefined ? undefined : inArray(events.format, filters.formats),
|
|
56
|
+
filters.ownerIds === undefined ? undefined : inArray(events.ownerId, filters.ownerIds),
|
|
57
|
+
filters.from === undefined ? undefined : gte(events.startsAt, filters.from),
|
|
58
|
+
filters.to === undefined ? undefined : lte(events.startsAt, filters.to),
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function listEvents(
|
|
63
|
+
db: Queryable,
|
|
64
|
+
workspaceId: string,
|
|
65
|
+
filters: EventFilters,
|
|
66
|
+
window: ListWindow<EventRecord>,
|
|
67
|
+
): Promise<EventRecord[]> {
|
|
68
|
+
return db
|
|
69
|
+
.select()
|
|
70
|
+
.from(events)
|
|
71
|
+
.where(and(...eventConditionsFor(workspaceId, filters), keysetCondition(window, events.id)))
|
|
72
|
+
.orderBy(...orderByWindow(window, events.id))
|
|
73
|
+
.limit(window.fetchLimit)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function findEvent(
|
|
77
|
+
db: Queryable,
|
|
78
|
+
workspaceId: string,
|
|
79
|
+
id: string,
|
|
80
|
+
): Promise<EventRecord | undefined> {
|
|
81
|
+
const [found] = await db
|
|
82
|
+
.select()
|
|
83
|
+
.from(events)
|
|
84
|
+
.where(and(eq(events.workspaceId, workspaceId), eq(events.id, id)))
|
|
85
|
+
.limit(1)
|
|
86
|
+
|
|
87
|
+
return found
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function insertEvent(db: Queryable, values: EventColumns): Promise<EventRecord> {
|
|
91
|
+
const [created] = await db.insert(events).values(values).returning()
|
|
92
|
+
|
|
93
|
+
if (created === undefined) {
|
|
94
|
+
throw new Error(`Inserting event ${values.id} returned no row`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return created
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function updateEvent(
|
|
101
|
+
db: Queryable,
|
|
102
|
+
workspaceId: string,
|
|
103
|
+
id: string,
|
|
104
|
+
changes: Partial<EventColumns>,
|
|
105
|
+
): Promise<EventRecord | undefined> {
|
|
106
|
+
const [updated] = await db
|
|
107
|
+
.update(events)
|
|
108
|
+
.set(changes)
|
|
109
|
+
.where(and(eq(events.workspaceId, workspaceId), eq(events.id, id)))
|
|
110
|
+
.returning()
|
|
111
|
+
|
|
112
|
+
return updated
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function deleteEvent(db: Queryable, workspaceId: string, id: string): Promise<number> {
|
|
116
|
+
const deleted = await db
|
|
117
|
+
.delete(events)
|
|
118
|
+
.where(and(eq(events.workspaceId, workspaceId), eq(events.id, id)))
|
|
119
|
+
.returning({ id: events.id })
|
|
120
|
+
|
|
121
|
+
return deleted.length
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function memberExists(
|
|
125
|
+
db: Queryable,
|
|
126
|
+
workspaceId: string,
|
|
127
|
+
memberId: string,
|
|
128
|
+
): Promise<boolean> {
|
|
129
|
+
const [found] = await db
|
|
130
|
+
.select({ id: workspaceMembers.id })
|
|
131
|
+
.from(workspaceMembers)
|
|
132
|
+
.where(and(eq(workspaceMembers.workspaceId, workspaceId), eq(workspaceMembers.id, memberId)))
|
|
133
|
+
.limit(1)
|
|
134
|
+
|
|
135
|
+
return found !== undefined
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface AssociationRef {
|
|
139
|
+
readonly targetType: EventAssociationTargetType
|
|
140
|
+
readonly targetId: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function listAssociations(
|
|
144
|
+
db: Queryable,
|
|
145
|
+
workspaceId: string,
|
|
146
|
+
eventId: string,
|
|
147
|
+
): Promise<readonly AssociationRef[]> {
|
|
148
|
+
const rows = await db
|
|
149
|
+
.select({
|
|
150
|
+
targetType: eventAssociations.targetType,
|
|
151
|
+
targetId: eventAssociations.targetId,
|
|
152
|
+
})
|
|
153
|
+
.from(eventAssociations)
|
|
154
|
+
.where(
|
|
155
|
+
and(eq(eventAssociations.workspaceId, workspaceId), eq(eventAssociations.eventId, eventId)),
|
|
156
|
+
)
|
|
157
|
+
.orderBy(asc(eventAssociations.targetType), asc(eventAssociations.targetId))
|
|
158
|
+
|
|
159
|
+
return rows.map((row) => ({
|
|
160
|
+
targetType: row.targetType as EventAssociationTargetType,
|
|
161
|
+
targetId: row.targetId,
|
|
162
|
+
}))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function listAssociationsByTarget(
|
|
166
|
+
db: Queryable,
|
|
167
|
+
workspaceId: string,
|
|
168
|
+
targetType: EventAssociationTargetType,
|
|
169
|
+
targetId: string,
|
|
170
|
+
): Promise<readonly { readonly eventId: string; readonly eventName: string }[]> {
|
|
171
|
+
return db
|
|
172
|
+
.select({ eventId: events.id, eventName: events.name })
|
|
173
|
+
.from(eventAssociations)
|
|
174
|
+
.innerJoin(events, eq(events.id, eventAssociations.eventId))
|
|
175
|
+
.where(
|
|
176
|
+
and(
|
|
177
|
+
eq(eventAssociations.workspaceId, workspaceId),
|
|
178
|
+
eq(eventAssociations.targetType, targetType),
|
|
179
|
+
eq(eventAssociations.targetId, targetId),
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
.orderBy(asc(events.startsAt), asc(events.id))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function replaceAssociations(
|
|
186
|
+
db: Queryable,
|
|
187
|
+
createId: IdFactory,
|
|
188
|
+
workspaceId: string,
|
|
189
|
+
eventId: string,
|
|
190
|
+
next: readonly AssociationRef[],
|
|
191
|
+
): Promise<void> {
|
|
192
|
+
await db
|
|
193
|
+
.delete(eventAssociations)
|
|
194
|
+
.where(
|
|
195
|
+
and(eq(eventAssociations.workspaceId, workspaceId), eq(eventAssociations.eventId, eventId)),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
if (next.length === 0) {
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
await db.insert(eventAssociations).values(
|
|
203
|
+
next.map((row) => ({
|
|
204
|
+
id: createId('eventAssociation'),
|
|
205
|
+
workspaceId,
|
|
206
|
+
eventId,
|
|
207
|
+
targetType: row.targetType,
|
|
208
|
+
targetId: row.targetId,
|
|
209
|
+
})),
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function deleteAssociationsForTarget(
|
|
214
|
+
db: Queryable,
|
|
215
|
+
workspaceId: string,
|
|
216
|
+
targetType: string,
|
|
217
|
+
targetId: string,
|
|
218
|
+
): Promise<number> {
|
|
219
|
+
const deleted = await db
|
|
220
|
+
.delete(eventAssociations)
|
|
221
|
+
.where(
|
|
222
|
+
and(
|
|
223
|
+
eq(eventAssociations.workspaceId, workspaceId),
|
|
224
|
+
eq(eventAssociations.targetType, targetType),
|
|
225
|
+
eq(eventAssociations.targetId, targetId),
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
.returning({ id: eventAssociations.id })
|
|
229
|
+
|
|
230
|
+
return deleted.length
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export const ATTENDANCE_SORTS: SortableFields<AttendanceRecord> = {
|
|
234
|
+
created_at: timestampSort(attendances.createdAt, (row) => row.createdAt),
|
|
235
|
+
updated_at: timestampSort(attendances.updatedAt, (row) => row.updatedAt),
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export const DEFAULT_ATTENDANCE_SORT = '-created_at'
|
|
239
|
+
|
|
240
|
+
export interface AttendanceFilters {
|
|
241
|
+
readonly eventIds?: readonly string[] | undefined
|
|
242
|
+
readonly personIds?: readonly string[] | undefined
|
|
243
|
+
readonly statuses?: readonly string[] | undefined
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function attendanceConditionsFor(
|
|
247
|
+
workspaceId: string,
|
|
248
|
+
filters: AttendanceFilters,
|
|
249
|
+
): (SQL | undefined)[] {
|
|
250
|
+
return [
|
|
251
|
+
eq(attendances.workspaceId, workspaceId),
|
|
252
|
+
filters.eventIds === undefined ? undefined : inArray(attendances.eventId, filters.eventIds),
|
|
253
|
+
filters.personIds === undefined ? undefined : inArray(attendances.personId, filters.personIds),
|
|
254
|
+
filters.statuses === undefined ? undefined : inArray(attendances.status, filters.statuses),
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function listAttendances(
|
|
259
|
+
db: Queryable,
|
|
260
|
+
workspaceId: string,
|
|
261
|
+
filters: AttendanceFilters,
|
|
262
|
+
window: ListWindow<AttendanceRecord>,
|
|
263
|
+
): Promise<AttendanceRecord[]> {
|
|
264
|
+
return db
|
|
265
|
+
.select()
|
|
266
|
+
.from(attendances)
|
|
267
|
+
.where(
|
|
268
|
+
and(
|
|
269
|
+
...attendanceConditionsFor(workspaceId, filters),
|
|
270
|
+
keysetCondition(window, attendances.id),
|
|
271
|
+
),
|
|
272
|
+
)
|
|
273
|
+
.orderBy(...orderByWindow(window, attendances.id))
|
|
274
|
+
.limit(window.fetchLimit)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export async function findAttendance(
|
|
278
|
+
db: Queryable,
|
|
279
|
+
workspaceId: string,
|
|
280
|
+
id: string,
|
|
281
|
+
): Promise<AttendanceRecord | undefined> {
|
|
282
|
+
const [found] = await db
|
|
283
|
+
.select()
|
|
284
|
+
.from(attendances)
|
|
285
|
+
.where(and(eq(attendances.workspaceId, workspaceId), eq(attendances.id, id)))
|
|
286
|
+
.limit(1)
|
|
287
|
+
|
|
288
|
+
return found
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export async function insertAttendance(
|
|
292
|
+
db: Queryable,
|
|
293
|
+
values: AttendanceColumns,
|
|
294
|
+
): Promise<AttendanceRecord> {
|
|
295
|
+
const [created] = await db.insert(attendances).values(values).returning()
|
|
296
|
+
|
|
297
|
+
if (created === undefined) {
|
|
298
|
+
throw new Error(`Inserting attendance ${values.id} returned no row`)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return created
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Insert or return the existing row. Used by form submit so a retry is ok.
|
|
306
|
+
*
|
|
307
|
+
* Uses `ON CONFLICT DO NOTHING` rather than catching a unique violation: a
|
|
308
|
+
* caught 23505 still aborts the surrounding savepoint, and the follow-up
|
|
309
|
+
* select would then fail.
|
|
310
|
+
*
|
|
311
|
+
* @returns The row and whether it was newly inserted.
|
|
312
|
+
*/
|
|
313
|
+
export async function insertAttendanceIfAbsent(
|
|
314
|
+
db: Queryable,
|
|
315
|
+
values: AttendanceColumns,
|
|
316
|
+
): Promise<{ readonly record: AttendanceRecord; readonly inserted: boolean }> {
|
|
317
|
+
const inserted = await db
|
|
318
|
+
.insert(attendances)
|
|
319
|
+
.values(values)
|
|
320
|
+
.onConflictDoNothing({ target: [attendances.eventId, attendances.personId] })
|
|
321
|
+
.returning()
|
|
322
|
+
|
|
323
|
+
if (inserted[0] !== undefined) {
|
|
324
|
+
return { record: inserted[0], inserted: true }
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const [existing] = await db
|
|
328
|
+
.select()
|
|
329
|
+
.from(attendances)
|
|
330
|
+
.where(
|
|
331
|
+
and(eq(attendances.eventId, values.eventId), eq(attendances.personId, values.personId)),
|
|
332
|
+
)
|
|
333
|
+
.limit(1)
|
|
334
|
+
|
|
335
|
+
if (existing === undefined) {
|
|
336
|
+
throw new Error(`Attendance for ${values.eventId} and ${values.personId} was neither inserted nor found`)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return { record: existing, inserted: false }
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export async function updateAttendance(
|
|
343
|
+
db: Queryable,
|
|
344
|
+
workspaceId: string,
|
|
345
|
+
id: string,
|
|
346
|
+
changes: Partial<AttendanceColumns>,
|
|
347
|
+
): Promise<AttendanceRecord | undefined> {
|
|
348
|
+
const [updated] = await db
|
|
349
|
+
.update(attendances)
|
|
350
|
+
.set(changes)
|
|
351
|
+
.where(and(eq(attendances.workspaceId, workspaceId), eq(attendances.id, id)))
|
|
352
|
+
.returning()
|
|
353
|
+
|
|
354
|
+
return updated
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export async function deleteAttendance(
|
|
358
|
+
db: Queryable,
|
|
359
|
+
workspaceId: string,
|
|
360
|
+
id: string,
|
|
361
|
+
): Promise<number> {
|
|
362
|
+
const deleted = await db
|
|
363
|
+
.delete(attendances)
|
|
364
|
+
.where(and(eq(attendances.workspaceId, workspaceId), eq(attendances.id, id)))
|
|
365
|
+
.returning({ id: attendances.id })
|
|
366
|
+
|
|
367
|
+
return deleted.length
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export async function listAttendanceIdsForEvent(
|
|
371
|
+
db: Queryable,
|
|
372
|
+
workspaceId: string,
|
|
373
|
+
eventId: string,
|
|
374
|
+
): Promise<readonly string[]> {
|
|
375
|
+
const rows = await db
|
|
376
|
+
.select({ id: attendances.id })
|
|
377
|
+
.from(attendances)
|
|
378
|
+
.where(and(eq(attendances.workspaceId, workspaceId), eq(attendances.eventId, eventId)))
|
|
379
|
+
|
|
380
|
+
return rows.map((row) => row.id)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export async function listAttendanceIdsForPerson(
|
|
384
|
+
db: Queryable,
|
|
385
|
+
workspaceId: string,
|
|
386
|
+
personId: string,
|
|
387
|
+
): Promise<readonly string[]> {
|
|
388
|
+
const rows = await db
|
|
389
|
+
.select({ id: attendances.id })
|
|
390
|
+
.from(attendances)
|
|
391
|
+
.where(and(eq(attendances.workspaceId, workspaceId), eq(attendances.personId, personId)))
|
|
392
|
+
|
|
393
|
+
return rows.map((row) => row.id)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { sql }
|