@nage-api/data 1.0.0-beta.2
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/LICENSE +202 -0
- package/README.md +160 -0
- package/dist/conformance/repository-conformance.d.ts +76 -0
- package/dist/conformance/repository-conformance.js +295 -0
- package/dist/entity/audit.d.ts +26 -0
- package/dist/entity/audit.js +60 -0
- package/dist/health/data.health.d.ts +26 -0
- package/dist/health/data.health.js +46 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +59 -0
- package/dist/memory/memory.repository.d.ts +50 -0
- package/dist/memory/memory.repository.js +231 -0
- package/dist/memory/memory.unit-of-work.d.ts +21 -0
- package/dist/memory/memory.unit-of-work.js +50 -0
- package/dist/migrations/migration.runner.d.ts +70 -0
- package/dist/migrations/migration.runner.js +138 -0
- package/dist/migrations/seed.runner.d.ts +39 -0
- package/dist/migrations/seed.runner.js +100 -0
- package/dist/module/data.module.d.ts +67 -0
- package/dist/module/data.module.js +71 -0
- package/dist/query/parse-query.d.ts +38 -0
- package/dist/query/parse-query.js +285 -0
- package/dist/query/policy.d.ts +52 -0
- package/dist/query/policy.js +80 -0
- package/dist/query/where-matcher.d.ts +12 -0
- package/dist/query/where-matcher.js +139 -0
- package/dist/service/model.service.d.ts +69 -0
- package/dist/service/model.service.js +191 -0
- package/dist/tokens.d.ts +12 -0
- package/dist/tokens.js +14 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# @nage-api/data
|
|
2
|
+
|
|
3
|
+
The engine-agnostic data layer (PLAN.md §14): one contract, pluggable drivers,
|
|
4
|
+
**one engine per project**.
|
|
5
|
+
|
|
6
|
+
The legacy framework compiled both SQL and Mongo into every application and
|
|
7
|
+
chose between them at runtime with `APP_ENGINE` — so a "SQL" deployment still
|
|
8
|
+
booted a Mongo connection it never used. Here the driver is a scaffold-time
|
|
9
|
+
choice: application code depends on `RepositoryPort`, and exactly one driver is
|
|
10
|
+
installed. `@nage-api/data-sql` is the driver that exists today; the Mongo driver
|
|
11
|
+
§8 names is not written yet.
|
|
12
|
+
|
|
13
|
+
## What it provides
|
|
14
|
+
|
|
15
|
+
| Area | Export | Notes |
|
|
16
|
+
| ---------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------- |
|
|
17
|
+
| Query DSL | `defineQueryPolicy`, `parseQuery`, `parseWhere`, `parseSort` | Allow-listed fields and operators, enforced `maxLimit` (§12) |
|
|
18
|
+
| Audit | `stampCreate`, `stampUpdate`, `stampSoftDelete`, `stampRestore` | Who and when, taken from the request context (§14.2) |
|
|
19
|
+
| Service | `ModelService<TEntity>` | The retained lifecycle hooks, typed; ownership scoping via `scopeToOwner` |
|
|
20
|
+
| In-memory driver | `MemoryRepository`, `MemoryUnitOfWork` | A real implementation, used as a test double (§19) |
|
|
21
|
+
| Migrations | `MigrationRunner`, `SeedRunner` | Versioned and recorded; replaces `synchronize` auto-sync |
|
|
22
|
+
| Health | `checkDataSourceHealth` | Feeds `/health/ready` (§21) |
|
|
23
|
+
| Conformance | `describeRepositoryConformance` | The suite **every** driver must pass |
|
|
24
|
+
|
|
25
|
+
## The query DSL
|
|
26
|
+
|
|
27
|
+
The DSL survives — it is what made the legacy framework productive — but a model
|
|
28
|
+
now declares what a client may reach:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { defineQueryPolicy, parseQuery, type RawQuery } from '@nage-api/data';
|
|
32
|
+
import type { Query } from '@nage-api/contracts';
|
|
33
|
+
|
|
34
|
+
interface Product {
|
|
35
|
+
readonly id: number;
|
|
36
|
+
name: string;
|
|
37
|
+
price: number;
|
|
38
|
+
archived: boolean;
|
|
39
|
+
created_at: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const productPolicy = defineQueryPolicy<Product>({
|
|
43
|
+
filterable: ['name', 'price', 'archived'],
|
|
44
|
+
sortable: ['name', 'price', 'created_at'],
|
|
45
|
+
selectable: ['id', 'name', 'price'],
|
|
46
|
+
searchable: ['name'],
|
|
47
|
+
maxLimit: 100,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** `request.query`, as the platform hands it over. Nothing has validated it yet. */
|
|
51
|
+
declare const request: { readonly query: RawQuery };
|
|
52
|
+
|
|
53
|
+
const query: Query<Product> = parseQuery(request.query, productPolicy); // throws INVALID_QUERY
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Nothing is filterable by default: a model with no policy exposes no fields, so
|
|
57
|
+
forgetting to write one fails closed. `limit: -1` has no representation, and a
|
|
58
|
+
page larger than the ceiling is **refused** rather than clamped — silently
|
|
59
|
+
clamping would let a client believe it received the 100 000 rows it asked for.
|
|
60
|
+
Mongo-style `$`-operators are rejected outright; only names in the operator
|
|
61
|
+
allow-list are ever emitted to a driver.
|
|
62
|
+
|
|
63
|
+
`parseQuery` is the allow-list, and a repository's own policy is not a second
|
|
64
|
+
one: a `where` clause built in server code reaches the driver whatever the
|
|
65
|
+
policy lists. Untrusted input goes through `parseQuery`; nothing else does.
|
|
66
|
+
|
|
67
|
+
## ModelService
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import type { BaseEntity, Job } from '@nage-api/contracts';
|
|
71
|
+
import { ModelService } from '@nage-api/data';
|
|
72
|
+
|
|
73
|
+
interface Note extends BaseEntity {
|
|
74
|
+
readonly id: number;
|
|
75
|
+
user_id: string;
|
|
76
|
+
body: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class NoteService extends ModelService<Note> {
|
|
80
|
+
// `audit` is the application's own collaborator; `ModelService` supplies the
|
|
81
|
+
// lifecycle and the transaction, not the side effect.
|
|
82
|
+
private readonly audit!: { record(event: string, entity: Note | undefined): Promise<void> };
|
|
83
|
+
|
|
84
|
+
protected override doBeforeRead(job: Job<Note>): void {
|
|
85
|
+
this.scopeToOwner(job, 'user_id'); // typed `job.where.user_id = job.owner.id`
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected override async doAfterCreate(job: Job<Note>): Promise<void> {
|
|
89
|
+
// Runs inside the transaction, so a failure here rolls the insert back.
|
|
90
|
+
await this.audit.record('note.created', job.record);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Hooks run **inside** the unit of work, so a failing `doAfterCreate` rolls the
|
|
96
|
+
create back. Ownership scoping applies to reads by id as well as to lists, and
|
|
97
|
+
`update` and `delete` load the record through the same path first, so a caller
|
|
98
|
+
cannot reach another owner's record by guessing an id. `restore` is the
|
|
99
|
+
exception: it runs no read hook, so a route exposing it needs its own check
|
|
100
|
+
until that is fixed (see "Not yet implemented").
|
|
101
|
+
|
|
102
|
+
## Conformance
|
|
103
|
+
|
|
104
|
+
Driver parity is this layer's risk, so it is a gate rather than a promise: every
|
|
105
|
+
driver runs the _same_ suite.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
109
|
+
import { MemoryRepository, MemoryUnitOfWork, describeRepositoryConformance } from '@nage-api/data';
|
|
110
|
+
import type { ConformanceWidget } from '@nage-api/data';
|
|
111
|
+
|
|
112
|
+
describeRepositoryConformance(
|
|
113
|
+
{ describe, it, beforeEach, afterEach, expect },
|
|
114
|
+
{
|
|
115
|
+
name: 'memory',
|
|
116
|
+
// A fresh, empty repository per test; the suite seeds what each case needs.
|
|
117
|
+
setup: () => {
|
|
118
|
+
const unitOfWork = new MemoryUnitOfWork();
|
|
119
|
+
const repository = new MemoryRepository<ConformanceWidget>('Widget', { unitOfWork });
|
|
120
|
+
|
|
121
|
+
return Promise.resolve({ repository, unitOfWork });
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The test API is injected, so the published package carries no test-framework
|
|
128
|
+
dependency and any runner can drive it. A driver that genuinely lacks a
|
|
129
|
+
capability declares it in `unsupported` — an escape hatch a reviewer can see.
|
|
130
|
+
|
|
131
|
+
The suite covers creates and audit stamping, pagination and counts, the operator
|
|
132
|
+
set, sorting, projection, soft delete and restore, hard delete, bulk operations,
|
|
133
|
+
cursor pagination, search, and transactions — including that a failure rolls back
|
|
134
|
+
every write in the unit and that the **original** error propagates rather than
|
|
135
|
+
being wrapped.
|
|
136
|
+
|
|
137
|
+
## Not yet implemented
|
|
138
|
+
|
|
139
|
+
- **`@nage-api/data-mongo`.** §8 and §14.1 both name it; only the SQL driver exists.
|
|
140
|
+
Nothing in this package assumes SQL, so the second driver is work rather than a
|
|
141
|
+
redesign — but "one engine per project" currently has one engine to choose.
|
|
142
|
+
- **Named scopes.** `defineQueryPolicy({ scopes })` and `Query.scope` are
|
|
143
|
+
validated by `parseQuery` and then read by no driver, so `?scope=active`
|
|
144
|
+
returns the unscoped collection with a 200. Express the fragment in a
|
|
145
|
+
`doBeforeRead` hook instead.
|
|
146
|
+
- **`withDeleted` is not gated.** §14.2 says including soft-deleted rows
|
|
147
|
+
"requires an explicit permission"; `parseQuery` accepts `withDeleted=true` from
|
|
148
|
+
any client. Drop the key before parsing, or overwrite it in a read hook, until
|
|
149
|
+
a permission check exists.
|
|
150
|
+
- **Ownership scoping on `restore`.** `restore` calls the driver directly, so no
|
|
151
|
+
read hook narrows it.
|
|
152
|
+
- **Optimistic locking.** `ModelDescriptor.versioned` and
|
|
153
|
+
`OptimisticLockError` exist; no driver reads or throws either.
|
|
154
|
+
- **History and trash** (§14.2, an optional plugin) and the `database.maxQueryLimit`
|
|
155
|
+
ceiling — a policy states its own `maxLimit` and nothing reads the config value.
|
|
156
|
+
- **`ModelDescriptor.timestamps`** is accepted and ignored: audit columns are
|
|
157
|
+
always stamped.
|
|
158
|
+
|
|
159
|
+
`docs/packages/data.md` is the longer guide: every policy option and its default,
|
|
160
|
+
the mistakes worth knowing about, and how to test against this package.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared `RepositoryPort` conformance suite (PLAN.md §24 Phase 5).
|
|
3
|
+
*
|
|
4
|
+
* Driver parity is the risk this phase carries, and a shared suite is the gate.
|
|
5
|
+
* Every driver runs *these* tests — not its own paraphrase of them — so a
|
|
6
|
+
* behaviour that differs between SQL and Mongo is a failing test rather than a
|
|
7
|
+
* surprise in production.
|
|
8
|
+
*
|
|
9
|
+
* The test API is injected rather than imported, so the published package does
|
|
10
|
+
* not depend on a test framework and any runner can drive the suite.
|
|
11
|
+
*/
|
|
12
|
+
import type { Id, RepositoryPort, UnitOfWork } from '@nage-api/contracts';
|
|
13
|
+
/** The entity every driver must be able to store for the suite to run. */
|
|
14
|
+
export interface ConformanceWidget {
|
|
15
|
+
readonly id: Id;
|
|
16
|
+
name: string;
|
|
17
|
+
price: number;
|
|
18
|
+
archived: boolean;
|
|
19
|
+
owner_id?: Id | null;
|
|
20
|
+
created_at?: string;
|
|
21
|
+
updated_at?: string;
|
|
22
|
+
created_by?: Id | null;
|
|
23
|
+
updated_by?: Id | null;
|
|
24
|
+
deleted_at?: string | null;
|
|
25
|
+
deleted_by?: Id | null;
|
|
26
|
+
}
|
|
27
|
+
/** What a driver supplies to run the suite. */
|
|
28
|
+
export interface ConformanceHarness {
|
|
29
|
+
/** Driver name, used in the suite's description. */
|
|
30
|
+
readonly name: string;
|
|
31
|
+
/** Fresh, empty repository per test. */
|
|
32
|
+
setup(): Promise<{
|
|
33
|
+
repository: RepositoryPort<ConformanceWidget>;
|
|
34
|
+
unitOfWork?: UnitOfWork;
|
|
35
|
+
}>;
|
|
36
|
+
/** Release whatever `setup` acquired. */
|
|
37
|
+
teardown?(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Capabilities a driver legitimately may not have. Everything not listed is
|
|
40
|
+
* required — an escape hatch that has to be declared is one a reviewer sees.
|
|
41
|
+
*/
|
|
42
|
+
readonly unsupported?: readonly ('cursor' | 'search' | 'transactions')[];
|
|
43
|
+
}
|
|
44
|
+
/** The slice of a test framework the suite uses (vitest and jest both fit). */
|
|
45
|
+
export interface TestApi {
|
|
46
|
+
describe: (name: string, fn: () => void) => void;
|
|
47
|
+
it: (name: string, fn: () => Promise<void> | void) => void;
|
|
48
|
+
beforeEach: (fn: () => Promise<void> | void) => void;
|
|
49
|
+
afterEach: (fn: () => Promise<void> | void) => void;
|
|
50
|
+
expect: (actual: unknown) => {
|
|
51
|
+
toBe(expected: unknown): void;
|
|
52
|
+
toEqual(expected: unknown): void;
|
|
53
|
+
toBeNull(): void;
|
|
54
|
+
toBeUndefined(): void;
|
|
55
|
+
toBeDefined(): void;
|
|
56
|
+
toHaveLength(length: number): void;
|
|
57
|
+
toMatchObject(expected: object): void;
|
|
58
|
+
toBeGreaterThan(value: number): void;
|
|
59
|
+
rejects: {
|
|
60
|
+
toThrow(expected?: unknown): Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
not: {
|
|
63
|
+
toBe(expected: unknown): void;
|
|
64
|
+
toBeNull(): void;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Register the conformance suite for one driver.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* describeRepositoryConformance({ describe, it, beforeEach, afterEach, expect }, harness);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function describeRepositoryConformance(api: TestApi, harness: ConformanceHarness): void;
|
|
76
|
+
//# sourceMappingURL=repository-conformance.d.ts.map
|