@ordinatio/entities 1.2.0 → 1.4.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/README.md +5 -1
- package/dist/chunk-ZWID3JLL.mjs +123 -0
- package/dist/companies/index.d.mts +60 -0
- package/dist/companies/index.mjs +24 -0
- package/dist/companies/prisma/index.d.mts +58 -0
- package/dist/companies/prisma/index.mjs +276 -0
- package/dist/companies/server/index.d.mts +167 -0
- package/dist/companies/server/index.mjs +1826 -0
- package/dist/constants-DV-gn6u8.d.mts +22 -0
- package/dist/tags/prisma/index.d.mts +60 -0
- package/dist/tags/prisma/index.mjs +268 -0
- package/dist/tags/server/index.d.mts +3 -117
- package/dist/tags/server/index.mjs +11 -0
- package/dist/types-C81I1Teg.d.mts +117 -0
- package/dist/types-CbfseUAS.d.mts +169 -0
- package/package.json +22 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { C as CompanyRecord, b as CompanyMemberRecord, P as PersonCompany, a as CompanyStore } from '../../types-CbfseUAS.mjs';
|
|
2
|
+
export { c as CompanyAddMemberResult, d as CompanyCreateLimits, e as CompanyCreateResult, f as CompanyMemberLimits, g as CompanyRemoveMemberResult, h as CompanyRemoveResult, i as CompanySetRoleResult, j as CompanyUpdatePatch, k as CompanyUpdateResult, l as CompanyWebsite } from '../../types-CbfseUAS.mjs';
|
|
3
|
+
import { C as CompanyLimits } from '../../constants-DV-gn6u8.mjs';
|
|
4
|
+
|
|
5
|
+
/** Why a call did not do what was asked, with the context an app needs for its message. */
|
|
6
|
+
type CompanyFailure = {
|
|
7
|
+
reason: 'invalid-name';
|
|
8
|
+
problem: 'empty' | 'too-long';
|
|
9
|
+
length: number;
|
|
10
|
+
} | {
|
|
11
|
+
reason: 'invalid-website';
|
|
12
|
+
problem: 'invalid' | 'too-long';
|
|
13
|
+
} | {
|
|
14
|
+
reason: 'invalid-role';
|
|
15
|
+
problem: 'too-long';
|
|
16
|
+
length: number;
|
|
17
|
+
} | {
|
|
18
|
+
reason: 'person-gone';
|
|
19
|
+
} | {
|
|
20
|
+
reason: 'not-member';
|
|
21
|
+
} | {
|
|
22
|
+
reason: 'member-limit';
|
|
23
|
+
} | {
|
|
24
|
+
reason: 'duplicate';
|
|
25
|
+
} | {
|
|
26
|
+
reason: 'limit';
|
|
27
|
+
} | {
|
|
28
|
+
reason: 'not-found';
|
|
29
|
+
};
|
|
30
|
+
type CompanyResult<V> = ({
|
|
31
|
+
ok: true;
|
|
32
|
+
} & V) | ({
|
|
33
|
+
ok: false;
|
|
34
|
+
} & CompanyFailure);
|
|
35
|
+
interface CompanyOption {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
}
|
|
39
|
+
interface CompanyService<T extends CompanyRecord> {
|
|
40
|
+
/** Every company, sorted by name. */
|
|
41
|
+
list(): Promise<T[]>;
|
|
42
|
+
/** Just what a picker needs, sorted by name. */
|
|
43
|
+
options(): Promise<CompanyOption[]>;
|
|
44
|
+
get(id: string): Promise<CompanyResult<{
|
|
45
|
+
company: T;
|
|
46
|
+
}>>;
|
|
47
|
+
/** `website` empty or missing means no website. */
|
|
48
|
+
create(input: {
|
|
49
|
+
name: string;
|
|
50
|
+
website?: string | null;
|
|
51
|
+
}): Promise<CompanyResult<{
|
|
52
|
+
company: T;
|
|
53
|
+
}>>;
|
|
54
|
+
/** The existing company when the name is already taken (any case), else a new one (without a website). */
|
|
55
|
+
findOrCreate(name: string): Promise<CompanyResult<{
|
|
56
|
+
company: T;
|
|
57
|
+
created: boolean;
|
|
58
|
+
}>>;
|
|
59
|
+
/** Only what is given changes: `website: null` or an empty string clears the website (and its domain); leaving `website` out keeps it. */
|
|
60
|
+
update(id: string, input: {
|
|
61
|
+
name?: string;
|
|
62
|
+
website?: string | null;
|
|
63
|
+
}): Promise<CompanyResult<{
|
|
64
|
+
before: T;
|
|
65
|
+
after: T;
|
|
66
|
+
}>>;
|
|
67
|
+
/** `memberCount` is how many people were detached with it. */
|
|
68
|
+
remove(id: string): Promise<CompanyResult<{
|
|
69
|
+
company: T;
|
|
70
|
+
memberCount: number;
|
|
71
|
+
}>>;
|
|
72
|
+
/**
|
|
73
|
+
* Adds a person to a company. A person who is already a member is NOT an error: the result is `added: false` with the membership as it is
|
|
74
|
+
* (its role is untouched: changing a role is `setRole`). An empty role means none.
|
|
75
|
+
*/
|
|
76
|
+
addMember(companyId: string, personId: string, input: {
|
|
77
|
+
role?: string | null;
|
|
78
|
+
}, actorId: string): Promise<CompanyResult<{
|
|
79
|
+
member: CompanyMemberRecord;
|
|
80
|
+
added: boolean;
|
|
81
|
+
}>>;
|
|
82
|
+
/** `null` or an empty string clears the role. */
|
|
83
|
+
setRole(companyId: string, personId: string, role: string | null): Promise<CompanyResult<{
|
|
84
|
+
before: CompanyMemberRecord;
|
|
85
|
+
after: CompanyMemberRecord;
|
|
86
|
+
}>>;
|
|
87
|
+
removeMember(companyId: string, personId: string): Promise<CompanyResult<{
|
|
88
|
+
member: CompanyMemberRecord;
|
|
89
|
+
}>>;
|
|
90
|
+
/** The memberships of a company, in the store's order (the app sorts by the people's names, which this package does not know). */
|
|
91
|
+
members(companyId: string): Promise<CompanyResult<{
|
|
92
|
+
members: CompanyMemberRecord[];
|
|
93
|
+
}>>;
|
|
94
|
+
/** The companies of many people with each role, each list sorted by company name; only people with a company appear. */
|
|
95
|
+
forPeople(personIds: string[]): Promise<Map<string, Array<PersonCompany<T>>>>;
|
|
96
|
+
/** How many members each company has: every company of the workspace (or only `ids`), zero included; an empty `ids` is an empty map. */
|
|
97
|
+
memberCounts(ids?: string[]): Promise<Map<string, number>>;
|
|
98
|
+
/**
|
|
99
|
+
* The companies an email address SUGGESTS, sorted by name: those whose domain is exactly the address's domain. Never for a free-mail address
|
|
100
|
+
* or an address without a usable domain (the store is not even asked), and never a company `personId` already belongs to. Only ever an offer.
|
|
101
|
+
*/
|
|
102
|
+
suggest(email: string, personId?: string): Promise<T[]>;
|
|
103
|
+
}
|
|
104
|
+
declare function createCompanyService<T extends CompanyRecord>(store: CompanyStore<T>, suppliedLimits?: CompanyLimits): CompanyService<T>;
|
|
105
|
+
|
|
106
|
+
interface CompanyContractRunner {
|
|
107
|
+
describe: (name: string, body: () => void) => void;
|
|
108
|
+
it: ((name: string, body: () => Promise<void>) => void) & {
|
|
109
|
+
skip?: (name: string, body: () => Promise<void>) => void;
|
|
110
|
+
};
|
|
111
|
+
expect: (value: unknown) => {
|
|
112
|
+
toBe(expected: unknown): void;
|
|
113
|
+
toEqual(expected: unknown): void;
|
|
114
|
+
toBeNull(): void;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface CompanyStoreHarness {
|
|
118
|
+
/** A fresh, empty workspace id. Every test uses its own, so tests never see each other's rows. */
|
|
119
|
+
newWorkspace(): Promise<string>;
|
|
120
|
+
/** The store for one workspace. Called repeatedly for the same id: it must give the same data. */
|
|
121
|
+
storeFor(workspace: string): CompanyStore<CompanyRecord>;
|
|
122
|
+
/** Creates a real person (a contact, a user ...) in the workspace and returns its id. */
|
|
123
|
+
addPerson(workspace: string): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Deletes a person with everything that points at it (its memberships). NOTE: the contract also passes ids that do not exist, such as
|
|
126
|
+
* 'missing', 'ghost-1' or 'nothing', for companies and for people (an empty text, a prefix of a real id, a list of ids in one text and quotes too): an adapter with uuid or integer id
|
|
127
|
+
* columns must answer them as "not found" instead of failing the cast.
|
|
128
|
+
*/
|
|
129
|
+
removePerson(workspace: string, id: string): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* OPTIONAL test seam, for the delete-while-adding checks (./contract-hooks; no other check uses it). Arms a ONE-SHOT hook that the next `addMember` runs AFTER it has checked that the company and the person exist and BEFORE its write
|
|
132
|
+
* (the write decides `already` and `memberLimit` and inserts, atomically), so a test can delete the company or the person, or add someone, at exactly the
|
|
133
|
+
* dangerous moment. The hook is taken (cleared) BEFORE it is called, and it runs with no lock held and no transaction open: it may itself call any store method,
|
|
134
|
+
* `addMember` included, and a call made by the hook does not run the hook again. An add stopped earlier by `companyGone` or `personGone` does not run the hook and leaves it armed. Whether an add that ends in
|
|
135
|
+
* `already` or `memberLimit` runs it is up to the adapter (those answers may be decided inside the write): no check depends on it. Without it those checks will be shown as skipped when your runner has `it.skip`; if it does
|
|
136
|
+
* not, they will run and fail, so supply the hook.
|
|
137
|
+
*/
|
|
138
|
+
armBeforeMemberWrite?(hook: () => Promise<void>): void;
|
|
139
|
+
/** Removes everything the tests created. */
|
|
140
|
+
cleanup(): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface MemoryCompanyWorldOptions {
|
|
144
|
+
/** Default true. False removes the one-at-a-time chain so races become visible (for proving that concurrency tests can fail). */
|
|
145
|
+
serialise?: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface MemoryCompanyWorld {
|
|
148
|
+
store(workspace: string): CompanyStore<CompanyRecord>;
|
|
149
|
+
/** Registers a person (a contact, a user ...) of a workspace and returns its id. */
|
|
150
|
+
addPerson(workspace: string, id?: string): string;
|
|
151
|
+
/** Removes a person and every membership of it (what a database's cascading delete does). */
|
|
152
|
+
removePerson(workspace: string, id: string): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Arms a ONE-SHOT hook run by the next `addMember` IN THIS WORLD (any workspace) that gets past its first check, between that check and its write
|
|
155
|
+
* (to delete the company or the person mid-flight). An add stopped earlier (company or person gone, already a member, company full) leaves it armed.
|
|
156
|
+
*/
|
|
157
|
+
armBeforeMemberWrite(hook: () => Promise<void>): void;
|
|
158
|
+
/** Who added the membership (the `actorId` passed to `addMember`), or undefined when there is no such membership. */
|
|
159
|
+
actorOf(workspace: string, companyId: string, personId: string): string | undefined;
|
|
160
|
+
}
|
|
161
|
+
declare function createMemoryCompanyWorld(options?: MemoryCompanyWorldOptions): MemoryCompanyWorld;
|
|
162
|
+
/** A harness over a fresh in-memory world, for running `defineCompanyStoreContract` against this package's own reference store. */
|
|
163
|
+
declare function createMemoryCompanyHarness(options?: MemoryCompanyWorldOptions): CompanyStoreHarness;
|
|
164
|
+
|
|
165
|
+
declare function defineCompanyStoreContract(api: CompanyContractRunner, harness: CompanyStoreHarness): void;
|
|
166
|
+
|
|
167
|
+
export { type CompanyContractRunner, type CompanyFailure, CompanyMemberRecord, type CompanyOption, CompanyRecord, type CompanyResult, type CompanyService, CompanyStore, type CompanyStoreHarness, type MemoryCompanyWorld, type MemoryCompanyWorldOptions, PersonCompany, createCompanyService, createMemoryCompanyHarness, createMemoryCompanyWorld, defineCompanyStoreContract };
|