rev-dal 0.0.0-stage → 0.2.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/AGENTS.md +242 -0
- package/CONTRIBUTING.md +83 -0
- package/LICENSE +121 -0
- package/README.md +67 -2
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/clone.d.ts +24 -0
- package/dist/lib/clone.d.ts.map +1 -0
- package/dist/lib/clone.js +83 -0
- package/dist/lib/clone.js.map +1 -0
- package/dist/lib/create-model.d.ts +207 -0
- package/dist/lib/create-model.d.ts.map +1 -0
- package/dist/lib/create-model.js +230 -0
- package/dist/lib/create-model.js.map +1 -0
- package/dist/lib/data-access-layer.d.ts +140 -0
- package/dist/lib/data-access-layer.d.ts.map +1 -0
- package/dist/lib/data-access-layer.js +389 -0
- package/dist/lib/data-access-layer.js.map +1 -0
- package/dist/lib/errors.d.ts +139 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +206 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/filter-where.d.ts +199 -0
- package/dist/lib/filter-where.d.ts.map +1 -0
- package/dist/lib/filter-where.js +563 -0
- package/dist/lib/filter-where.js.map +1 -0
- package/dist/lib/ml-string.d.ts +63 -0
- package/dist/lib/ml-string.d.ts.map +1 -0
- package/dist/lib/ml-string.js +331 -0
- package/dist/lib/ml-string.js.map +1 -0
- package/dist/lib/model-factory.d.ts +25 -0
- package/dist/lib/model-factory.d.ts.map +1 -0
- package/dist/lib/model-factory.js +57 -0
- package/dist/lib/model-factory.js.map +1 -0
- package/dist/lib/model-handle.d.ts +67 -0
- package/dist/lib/model-handle.d.ts.map +1 -0
- package/dist/lib/model-handle.js +182 -0
- package/dist/lib/model-handle.js.map +1 -0
- package/dist/lib/model-initializer.d.ts +96 -0
- package/dist/lib/model-initializer.d.ts.map +1 -0
- package/dist/lib/model-initializer.js +182 -0
- package/dist/lib/model-initializer.js.map +1 -0
- package/dist/lib/model-manifest.d.ts +112 -0
- package/dist/lib/model-manifest.d.ts.map +1 -0
- package/dist/lib/model-manifest.js +2 -0
- package/dist/lib/model-manifest.js.map +1 -0
- package/dist/lib/model-registry.d.ts +81 -0
- package/dist/lib/model-registry.d.ts.map +1 -0
- package/dist/lib/model-registry.js +139 -0
- package/dist/lib/model-registry.js.map +1 -0
- package/dist/lib/model-types.d.ts +380 -0
- package/dist/lib/model-types.d.ts.map +1 -0
- package/dist/lib/model-types.js +2 -0
- package/dist/lib/model-types.js.map +1 -0
- package/dist/lib/model.d.ts +503 -0
- package/dist/lib/model.d.ts.map +1 -0
- package/dist/lib/model.js +1423 -0
- package/dist/lib/model.js.map +1 -0
- package/dist/lib/postgres-config.d.ts +3 -0
- package/dist/lib/postgres-config.d.ts.map +1 -0
- package/dist/lib/postgres-config.js +2 -0
- package/dist/lib/postgres-config.js.map +1 -0
- package/dist/lib/query-builder.d.ts +607 -0
- package/dist/lib/query-builder.d.ts.map +1 -0
- package/dist/lib/query-builder.js +1734 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/revision.d.ts +55 -0
- package/dist/lib/revision.d.ts.map +1 -0
- package/dist/lib/revision.js +307 -0
- package/dist/lib/revision.js.map +1 -0
- package/dist/lib/runtime.d.ts +18 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/lib/runtime.js +134 -0
- package/dist/lib/runtime.js.map +1 -0
- package/dist/lib/transaction.d.ts +17 -0
- package/dist/lib/transaction.d.ts.map +1 -0
- package/dist/lib/transaction.js +30 -0
- package/dist/lib/transaction.js.map +1 -0
- package/dist/lib/type.d.ts +130 -0
- package/dist/lib/type.d.ts.map +1 -0
- package/dist/lib/type.js +376 -0
- package/dist/lib/type.js.map +1 -0
- package/docs/models.md +406 -0
- package/docs/multilingual-text.md +142 -0
- package/docs/queries.md +374 -0
- package/docs/revisions.md +61 -0
- package/package.json +60 -4
- package/releases/0.2.0.md +18 -0
- package/releases/0.2.1.md +22 -0
- package/releases/0.2.2.md +11 -0
- package/releases/README.md +7 -0
- package/setup-db-grants.sql +51 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Local agent instructions
|
|
2
|
+
|
|
3
|
+
## Documentation maintenance
|
|
4
|
+
|
|
5
|
+
Keep documentation up to date in the same change as the implementation. When
|
|
6
|
+
changing public APIs, behavior, configuration, or development workflows, update
|
|
7
|
+
the relevant documentation:
|
|
8
|
+
|
|
9
|
+
- `README.md`: overview, requirements, installation, quick start, and links.
|
|
10
|
+
- `docs/models.md`: bootstrap, manifests, model methods, typing, cross-model
|
|
11
|
+
references, logging, database grants, and runtime architecture.
|
|
12
|
+
- `docs/queries.md`: filtering, projections, aggregates, joins, deletion, and
|
|
13
|
+
relation loading and writes.
|
|
14
|
+
- `docs/revisions.md`: revision workflows, edit conflicts, and transactions.
|
|
15
|
+
- `docs/multilingual-text.md`: schemas, language providers, escaping, cleanup,
|
|
16
|
+
and rendering responsibilities.
|
|
17
|
+
- `CONTRIBUTING.md`: development setup, test database configuration, checks,
|
|
18
|
+
and the source directory map.
|
|
19
|
+
|
|
20
|
+
Keep the README concise and link to the topic guides for details. Give each
|
|
21
|
+
behavior one authoritative explanation and link to it instead of duplicating
|
|
22
|
+
the contract across pages. Distinguish guarantees made by rev-dal from
|
|
23
|
+
conventions or helpers supplied by consuming applications.
|
|
24
|
+
|
|
25
|
+
Check examples against the implementation and types. Verify affected relative
|
|
26
|
+
links and heading anchors after moving or renaming documentation. Keep new
|
|
27
|
+
documentation included in the package through `package.json`'s `files` list.
|
|
28
|
+
Update `TODO.md` when implementing an item listed there.
|
|
29
|
+
|
|
30
|
+
## Releases
|
|
31
|
+
|
|
32
|
+
Release automation lives in this repository and uses our own scripts, official
|
|
33
|
+
`actions/*` GitHub actions, and the standard `npm`, `git`, and `gh` CLIs. Do not
|
|
34
|
+
introduce Release Please, semantic-release, Changesets, or third-party release
|
|
35
|
+
actions. Use `mise exec --` for local Node/npm commands.
|
|
36
|
+
|
|
37
|
+
### Version and API policy
|
|
38
|
+
|
|
39
|
+
- Release stable versions only. The first npm release is `0.2.1`; `0.1.0` was
|
|
40
|
+
a development placeholder and `0.2.0` failed before publication.
|
|
41
|
+
- Before 1.0, compatible fixes and additions increment the patch version;
|
|
42
|
+
breaking changes increment the minor version. Choose `1.0.0` explicitly when
|
|
43
|
+
committing to a stable API. Afterwards use normal major/minor/patch semantics.
|
|
44
|
+
- Compatibility includes runtime behavior, TypeScript declarations, all exported
|
|
45
|
+
`rev-dal/lib/*` subpaths, the SQL setup export, and database requirements.
|
|
46
|
+
- Record changes and migration instructions in `releases/<version>.md`. Explain
|
|
47
|
+
database or grant changes explicitly; declaring models does not migrate tables.
|
|
48
|
+
- Versions, released notes, and `v<version>` tags are immutable. Fix an already
|
|
49
|
+
published package with a new release. Never force a tag or unpublish to retry.
|
|
50
|
+
- Keep the Git-install `prepare` build until consumers have migrated. Registry
|
|
51
|
+
packages contain built JavaScript and declarations and require no consumer build.
|
|
52
|
+
|
|
53
|
+
### One-time setup
|
|
54
|
+
|
|
55
|
+
1. Merge the workflow setup into `main` so manual dispatch is available. No npm
|
|
56
|
+
package is published merely by merging the setup: the version stays `0.1.0`.
|
|
57
|
+
2. Enable Actions and allow GitHub Actions to create pull requests in repository
|
|
58
|
+
Settings → Actions → General. Workflows explicitly request their permissions;
|
|
59
|
+
no PAT, GitHub App, or cross-repository write token is required. Only the first
|
|
60
|
+
npm publication needs a temporary npm bootstrap token; routine releases use OIDC.
|
|
61
|
+
3. Protect `main` against direct pushes and require the `lint`, `test`,
|
|
62
|
+
`consumers (lib.reviews)`, and `consumers (agpwiki)` checks. Permit the chosen
|
|
63
|
+
merge method (squash or merge commits both work). Confirm the check names in
|
|
64
|
+
the first run before adding requirements. The release PR is the review point;
|
|
65
|
+
do not add a recurring environment approval if unattended publishing is wanted.
|
|
66
|
+
4. Establish ownership of the unscoped npm package `rev-dal` using the owner's
|
|
67
|
+
npm account. A registry 404 does not reserve the name. If it is unavailable,
|
|
68
|
+
change the package name and scripts consistently before releasing; do not
|
|
69
|
+
silently publish under another name.
|
|
70
|
+
5. For a brand-new package, the npm account owner creates a temporary granular
|
|
71
|
+
access token on npmjs.com (account menu → Access Tokens → Generate New Token).
|
|
72
|
+
Use package permission **Read and write (publish and stage)**, enable **Bypass
|
|
73
|
+
two-factor authentication**, and choose the shortest practical expiry (one day
|
|
74
|
+
suffices). An unscoped package that does not exist cannot be selected individually;
|
|
75
|
+
use **All Packages** for this bootstrap token. Organization-management access
|
|
76
|
+
is unnecessary. The owner must complete npm's account authentication personally.
|
|
77
|
+
Agents must not request the token value in chat, print it, or commit it.
|
|
78
|
+
|
|
79
|
+
Store it as the repository Actions secret `NPM_BOOTSTRAP_TOKEN`, using GitHub
|
|
80
|
+
Settings → Secrets and variables → Actions, or this interactive command:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
gh secret set NPM_BOOTSTRAP_TOKEN --repo permacommons/rev-dal
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Prepare the first release (`0.2.1`), verify its PR checks, and merge when authorized.
|
|
87
|
+
Only its final publish step receives this secret as `NODE_AUTH_TOKEN`; neither
|
|
88
|
+
package tests nor consumer jobs receive it. npm attempts OIDC first and falls
|
|
89
|
+
back to the token before a trusted publisher exists. The workflow publishes the
|
|
90
|
+
exact tested tarball, with provenance, then creates its tag and GitHub release.
|
|
91
|
+
The secret is eligible only for version `0.2.1`; later versions cannot use it.
|
|
92
|
+
If publication already failed before the secret was added, use the retry procedure.
|
|
93
|
+
6. After the first publication succeeds, remove the GitHub secret and revoke the
|
|
94
|
+
temporary token in npm. Agents can remove the repository secret without reading
|
|
95
|
+
its value; the account owner can revoke the npm token:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
gh secret delete NPM_BOOTSTRAP_TOKEN --repo permacommons/rev-dal
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
7. Shortly before the next release, configure npm's `rev-dal` package Settings →
|
|
102
|
+
Trusted Publisher to authorize GitHub Actions:
|
|
103
|
+
owner `permacommons`, repository `rev-dal`, workflow filename `publish.yml`,
|
|
104
|
+
no environment. Enable direct `npm publish`; staged-only authorization would
|
|
105
|
+
require interactive approvals. The workflow uses GitHub-hosted runners, npm 11,
|
|
106
|
+
and `id-token: write`. Routine OIDC publication includes provenance.
|
|
107
|
+
A new trusted publisher must successfully publish within two days or it expires;
|
|
108
|
+
configure it when the next release is ready. A retry of an existing version only
|
|
109
|
+
verifies registry integrity and does not validate the OIDC configuration. Later
|
|
110
|
+
versions publish through OIDC without the bootstrap secret.
|
|
111
|
+
|
|
112
|
+
References: [npm token setup](https://docs.npmjs.com/creating-and-viewing-access-tokens/)
|
|
113
|
+
and [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
|
114
|
+
|
|
115
|
+
### Prepare and release
|
|
116
|
+
|
|
117
|
+
Run from this repository, or supply `--repo permacommons/rev-dal` to `gh`:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
gh workflow run prepare-release.yml --ref main \
|
|
121
|
+
-f version=0.2.1 \
|
|
122
|
+
-f notes='First versioned release. Existing rev-dal imports remain supported.'
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`version` accepts `patch`, `minor`, `major`, or an explicit increasing `X.Y.Z`.
|
|
126
|
+
Choose the bump based on the policy above; no commit-message parser decides it.
|
|
127
|
+
The `notes` input accepts multiline Markdown and must describe the actual release.
|
|
128
|
+
Do not use the example notes without reviewing the changes since the consumer pins.
|
|
129
|
+
|
|
130
|
+
`prepare-release.yml` reads current `main`, updates package.json and package-lock.json
|
|
131
|
+
without lifecycle scripts, writes release notes, pushes `release/v<version>`, and
|
|
132
|
+
opens a PR. It explicitly dispatches `lint.yml` and `tests.yml` on that branch.
|
|
133
|
+
This avoids relying on PR events generated by `GITHUB_TOKEN`. The dispatched runs
|
|
134
|
+
attach to the branch's current commit; verify the checks refer to the PR head SHA.
|
|
135
|
+
|
|
136
|
+
Inspect the diff, notes, workflow results, and any migration instructions, then
|
|
137
|
+
merge the passing PR when authorized to release. `publish.yml` detects a version
|
|
138
|
+
change on `main` and validates the exact merged commit before publishing. Non-version
|
|
139
|
+
package metadata changes do not publish. Both workflows only start on `main`.
|
|
140
|
+
|
|
141
|
+
### Validation and artifacts
|
|
142
|
+
|
|
143
|
+
`tests.yml` is both ordinary CI and a reusable release validation workflow:
|
|
144
|
+
|
|
145
|
+
1. Run rev-dal's runtime/PostgreSQL tests, type tests, release-tool tests, lint,
|
|
146
|
+
typecheck, and build on Node 22.
|
|
147
|
+
2. Pack once with `npm pack --ignore-scripts`. Install the tarball in a clean
|
|
148
|
+
temporary project with install scripts disabled; check runtime exports, SQL
|
|
149
|
+
resolution, and declaration imports.
|
|
150
|
+
3. Upload `rev-dal-package` containing `rev-dal.tgz` (retained for 14 days), with a
|
|
151
|
+
SHA-512 in the job summary.
|
|
152
|
+
4. Test that same tarball against lib.reviews and agpwiki `main` in disposable
|
|
153
|
+
runner checkouts using Node 24 and PostgreSQL 16. Record each checkout SHA,
|
|
154
|
+
run full typechecks and tests, and block publication if either fails.
|
|
155
|
+
|
|
156
|
+
The consumer jobs do not push changes, edit consumer repositories, or use local
|
|
157
|
+
consumer checkouts. Their temporary dependency install affects only the runner.
|
|
158
|
+
Consumer `main` is resolved per validation run; retries record any newly tested SHAs.
|
|
159
|
+
Their required database setup currently mirrors their own CI. Update this workflow
|
|
160
|
+
when consumer requirements change. A consumer CI failure is a release blocker;
|
|
161
|
+
do not bypass it or change consumer code as part of a release without authorization.
|
|
162
|
+
|
|
163
|
+
Resolve tarball paths to absolute paths before invoking npm; a bare relative
|
|
164
|
+
`directory/file.tgz` can be interpreted as a GitHub dependency.
|
|
165
|
+
|
|
166
|
+
Publication downloads the validated artifact, uses `npm publish` with OIDC (or the
|
|
167
|
+
temporary token for the first `0.2.1` publication) and provenance, verifies registry
|
|
168
|
+
integrity, then creates the immutable tag and GitHub
|
|
169
|
+
release from the checked-in notes. The publish job does not rebuild the package.
|
|
170
|
+
The summary includes version, commit, integrity, and publication URLs. No consumer
|
|
171
|
+
dependency update or deployment happens automatically in this initial setup.
|
|
172
|
+
|
|
173
|
+
npm can accept a publication and process it for several minutes before the version
|
|
174
|
+
becomes readable. The publish script waits up to five minutes for visibility before
|
|
175
|
+
verifying integrity; it does not resubmit the accepted package while polling.
|
|
176
|
+
|
|
177
|
+
### Recovery
|
|
178
|
+
|
|
179
|
+
Preparation and publication each serialize their runs. Different unpublished
|
|
180
|
+
release PRs can still exist: merge them in version order and close stale ones.
|
|
181
|
+
|
|
182
|
+
- If preparation fails after pushing its branch or opening the PR, preserve that
|
|
183
|
+
work. Locate the existing `release/v<version>` branch/PR; do not force-push or
|
|
184
|
+
blindly rerun preparation. Dispatch any missing checks on that branch:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
gh workflow run lint.yml --ref release/v0.2.1
|
|
188
|
+
gh workflow run tests.yml --ref release/v0.2.1
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
- After editing a bot-created PR, dispatch both checks again at its new head.
|
|
192
|
+
Never treat passing checks on an earlier SHA as sufficient.
|
|
193
|
+
- To retry publication, use the full SHA of the merged main commit that introduced
|
|
194
|
+
the version, not the release branch head or current main after later changes:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
gh workflow run publish.yml --ref main -f commit=<40-character-merged-sha>
|
|
198
|
+
gh run list --workflow publish.yml
|
|
199
|
+
gh run watch <original-push-run-id> --exit-status
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Manual dispatch queues a complete rerun of the original push workflow for that
|
|
203
|
+
commit; its summary links to that original run. Watch the original run after its
|
|
204
|
+
new attempt starts, rather than only watching the short dispatch run. This
|
|
205
|
+
preserves the original `GITHUB_SHA` for accurate npm provenance even if main
|
|
206
|
+
has advanced. A checkout of an older commit in a new main run would attest the
|
|
207
|
+
wrong source identity, so the publish script rejects such mismatches.
|
|
208
|
+
|
|
209
|
+
The target must belong to main's first-parent history, introduce an increasing
|
|
210
|
+
version, and have matching manifests and version-specific notes. Validation runs again. Existing
|
|
211
|
+
tags must point to that exact commit; an existing registry package must match
|
|
212
|
+
the tested tarball's SHA-512. Matching publication steps are skipped and missing
|
|
213
|
+
steps are completed. Conflicting bytes or tags fail rather than overwrite.
|
|
214
|
+
Revalidation replaces the earlier run artifact with the newly tested tarball.
|
|
215
|
+
A retry cannot publish an absent older version over a newer npm `latest`.
|
|
216
|
+
- If the tarball cannot be reproduced, investigate the build inputs; never waive
|
|
217
|
+
the integrity check. If publication failed before npm accepted the package and
|
|
218
|
+
source changes are required, prepare a new version.
|
|
219
|
+
- If npm reports that it accepted the publication but visibility still times out,
|
|
220
|
+
wait for the version to appear in the registry, then retry the original run to
|
|
221
|
+
verify its bytes and finish the tag and GitHub release. Do not create a new
|
|
222
|
+
version merely because an accepted publication is still processing.
|
|
223
|
+
- Consumer updates are deferred. When authorized, migrate each consumer to an
|
|
224
|
+
exact published version and commit its lockfile; keep deployment on `npm ci`.
|
|
225
|
+
|
|
226
|
+
### Local checks
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
mise exec -- npm run test:release
|
|
230
|
+
mise exec -- npm run lint
|
|
231
|
+
mise exec -- npm run typecheck
|
|
232
|
+
mise exec -- npm run test:types
|
|
233
|
+
mise exec -- npm test
|
|
234
|
+
mise exec -- npm run build
|
|
235
|
+
artifact_dir=$(mktemp -d)
|
|
236
|
+
mise exec -- npm pack --ignore-scripts --pack-destination "$artifact_dir"
|
|
237
|
+
mise exec -- node scripts/check-package.mjs "$artifact_dir/rev-dal-0.2.1.tgz"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Use the current package version in the tarball filename. The package smoke check
|
|
241
|
+
installs runtime dependencies from npm into a temporary directory, then removes it.
|
|
242
|
+
The runtime tests require the test database configuration in CONTRIBUTING.md.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
See the [README](README.md) for an introduction and the [model guide](docs/models.md)
|
|
4
|
+
for bootstrap and runtime architecture.
|
|
5
|
+
|
|
6
|
+
## Development setup
|
|
7
|
+
|
|
8
|
+
Use Node.js 22 or later and PostgreSQL for integration tests. Install dependencies
|
|
9
|
+
and build the library:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install
|
|
13
|
+
npm run build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Before submitting changes, run:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm run lint
|
|
20
|
+
npm run typecheck
|
|
21
|
+
npm run test:types
|
|
22
|
+
npm run test:release
|
|
23
|
+
npm test
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Testing
|
|
27
|
+
|
|
28
|
+
rev-dal uses Node's built-in test runner with `tsx` to execute TypeScript tests.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm test
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Test Database Setup
|
|
35
|
+
|
|
36
|
+
Integration tests require PostgreSQL with the `pgcrypto` extension available. The test harness
|
|
37
|
+
creates a fresh schema per run and cleans it up afterwards.
|
|
38
|
+
|
|
39
|
+
Provide a connection string via `REV_DAL_TEST_DATABASE_URL`:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export REV_DAL_TEST_DATABASE_URL="postgres://rev_dal_test_user:rev_dal_password@localhost:5432/rev_dal_test"
|
|
43
|
+
npm test
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If your test user cannot create extensions, run this once as a superuser:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
psql -d rev_dal_test -c 'CREATE EXTENSION IF NOT EXISTS "pgcrypto";'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Revision Tests
|
|
53
|
+
|
|
54
|
+
The shared `revisions` fixture in `test/helpers/revision-helpers.ts` includes JSONB,
|
|
55
|
+
array and timestamp columns, and `createTestDocumentWithRevisions()` edits them in
|
|
56
|
+
place the way applications do. When changing how rows are read, written or copied,
|
|
57
|
+
check history with `assertArchivedRevisionMatches()`, which compares an archived
|
|
58
|
+
revision with the stored row from before the edit.
|
|
59
|
+
|
|
60
|
+
### Type Tests
|
|
61
|
+
|
|
62
|
+
The source, declaration build, and type tests enable `strictNullChecks`. Other
|
|
63
|
+
strict-mode checks are not yet enabled.
|
|
64
|
+
|
|
65
|
+
Type-level checks live under `test/types/` and are compiled with a dedicated config:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run test:types
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Directory Reference
|
|
72
|
+
|
|
73
|
+
- `src/index.ts` – Public entry point that re-exports constructors, types, and helpers.
|
|
74
|
+
- `src/lib/` – Core implementation (connection management, manifests, query builder, filters, revision system, schema types).
|
|
75
|
+
- `setup-db-grants.sql` – Grants applied to shared environments.
|
|
76
|
+
|
|
77
|
+
## Releases
|
|
78
|
+
|
|
79
|
+
Use the repository's own GitHub Actions workflows to prepare a release PR, test
|
|
80
|
+
the packed library against both consumers, and publish through npm trusted
|
|
81
|
+
publishing. See the [release runbook](AGENTS.md#releases) for the version policy,
|
|
82
|
+
one-time npm setup, dispatch commands, and retry procedures. Release-tool tests
|
|
83
|
+
run with `npm run test:release` and do not require PostgreSQL.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rev-dal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
rev-dal is a TypeScript-first PostgreSQL data access layer with built-in revision support and
|
|
4
|
+
rich model typing (including multilingual string helpers).
|
|
5
|
+
|
|
6
|
+
It is currently internally used in the [Permacommons](https://permacommons.org/)
|
|
7
|
+
project family for two projects:
|
|
8
|
+
|
|
9
|
+
- https://lib.reviews/ - review anything in any language
|
|
10
|
+
- https://agpedia.org/ - an encyclopedia and knowledge repository managed
|
|
11
|
+
via MCP (AI agents)
|
|
12
|
+
|
|
13
|
+
The need for consistent wiki-style revision metadata motivated the creation
|
|
14
|
+
of a custom DAL.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
Node.js 22 or later and PostgreSQL.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save-exact rev-dal@0.2.1
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Use an exact release and commit your package lockfile. For unreleased development
|
|
27
|
+
changes, Git installations remain supported.
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
Create a DAL with your application's PostgreSQL connection settings:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import createDataAccessLayer from 'rev-dal';
|
|
35
|
+
|
|
36
|
+
const dal = createDataAccessLayer({
|
|
37
|
+
connectionString: process.env.DATABASE_URL,
|
|
38
|
+
});
|
|
39
|
+
await dal.connect();
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const result = await dal.query('SELECT NOW() AS now');
|
|
43
|
+
console.log(result.rows[0].now);
|
|
44
|
+
} finally {
|
|
45
|
+
await dal.disconnect();
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For typed model operations, follow [Models and bootstrap](docs/models.md) to
|
|
50
|
+
register manifests and configure model resolution. Database tables must already
|
|
51
|
+
exist; declaring a model does not create them.
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
- [Models and bootstrap](docs/models.md) — lifecycle, per-DAL model lookup,
|
|
56
|
+
manifests, methods, typing, cross-model references, logging, and database grants.
|
|
57
|
+
- [Queries and relations](docs/queries.md) — filtering, projections, aggregates,
|
|
58
|
+
joins, deletion, and loading or writing associations.
|
|
59
|
+
- [Revisions](docs/revisions.md) — revision history, edit conflicts, and transactions.
|
|
60
|
+
- [Multilingual text](docs/multilingual-text.md) — schemas, language providers,
|
|
61
|
+
escaping, cleanup, and rendering responsibilities.
|
|
62
|
+
|
|
63
|
+
## Development
|
|
64
|
+
|
|
65
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, test database configuration,
|
|
66
|
+
checks, and the source directory map.
|
|
67
|
+
See the [release runbook](AGENTS.md#releases) for versioning, automated releases,
|
|
68
|
+
and npm publisher setup.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import DataAccessLayer from './lib/data-access-layer.js';
|
|
2
|
+
import Errors from './lib/errors.js';
|
|
3
|
+
import mlString from './lib/ml-string.js';
|
|
4
|
+
import Model from './lib/model.js';
|
|
5
|
+
import type { PostgresConfig } from './lib/postgres-config.js';
|
|
6
|
+
import type { JoinApplyBuilder, JoinOptions, JoinRelationOptions } from './lib/query-builder.js';
|
|
7
|
+
import QueryBuilder from './lib/query-builder.js';
|
|
8
|
+
import revision from './lib/revision.js';
|
|
9
|
+
import type { DalDebugLogger, DalLanguageProvider } from './lib/runtime.js';
|
|
10
|
+
import { setDebugLogger, setLanguageProvider, setRevisionSummaryEnabled } from './lib/runtime.js';
|
|
11
|
+
import types from './lib/type.js';
|
|
12
|
+
/**
|
|
13
|
+
* Data Access Layer (DAL) for PostgreSQL
|
|
14
|
+
*
|
|
15
|
+
* This module provides the main entry point for the PostgreSQL DAL,
|
|
16
|
+
* abstracting database operations and providing a consistent interface
|
|
17
|
+
* for all database interactions.
|
|
18
|
+
*/
|
|
19
|
+
type DataAccessLayerClass = typeof DataAccessLayer;
|
|
20
|
+
type DataAccessLayerInstance = InstanceType<DataAccessLayerClass>;
|
|
21
|
+
export type DalContext = DataAccessLayerInstance & {
|
|
22
|
+
cleanup?: (options?: {
|
|
23
|
+
dropSchema?: boolean;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
schemaNamespace?: string;
|
|
26
|
+
};
|
|
27
|
+
type CreateDataAccessLayer = ((config?: Partial<PostgresConfig>) => DataAccessLayerInstance) & {
|
|
28
|
+
DataAccessLayer: DataAccessLayerClass;
|
|
29
|
+
Model: typeof Model;
|
|
30
|
+
QueryBuilder: typeof QueryBuilder;
|
|
31
|
+
types: typeof types;
|
|
32
|
+
Errors: typeof Errors;
|
|
33
|
+
mlString: typeof mlString;
|
|
34
|
+
revision: typeof revision;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Create a PostgreSQL Data Access Layer (DAL) instance.
|
|
38
|
+
*
|
|
39
|
+
* @param config Optional PostgreSQL configuration overrides used to initialize the DAL instance.
|
|
40
|
+
* @returns A ready-to-use DAL instance bound to the provided configuration.
|
|
41
|
+
*/
|
|
42
|
+
declare const createDataAccessLayer: CreateDataAccessLayer;
|
|
43
|
+
export { DataAccessLayer, Model, QueryBuilder, types, Errors, mlString, revision, setLanguageProvider, setDebugLogger, setRevisionSummaryEnabled, createDataAccessLayer, };
|
|
44
|
+
export type { JoinApplyBuilder, JoinOptions, JoinRelationOptions };
|
|
45
|
+
export type { DalDebugLogger, DalLanguageProvider };
|
|
46
|
+
export type { ProjectedQuery, SelectableData } from './lib/model-types.js';
|
|
47
|
+
export default createDataAccessLayer;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,4BAA4B,CAAC;AACzD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,KAAK,MAAM,eAAe,CAAC;AAElC;;;;;;GAMG;AAEH,KAAK,oBAAoB,GAAG,OAAO,eAAe,CAAC;AAEnD,KAAK,uBAAuB,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG,uBAAuB,GAAG;IACjD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,uBAAuB,CAAC,GAAG;IAC7F,eAAe,EAAE,oBAAoB,CAAC;IACtC,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,YAAY,EAAE,OAAO,YAAY,CAAC;IAClC,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,MAAM,EAAE,OAAO,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,QAAQ,CAAC;IAC1B,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,qBAAqB,EACW,qBAAqB,CAAC;AAU5D,OAAO,EACL,eAAe,EACf,KAAK,EACL,YAAY,EACZ,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzB,qBAAqB,GACtB,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AACnE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3E,eAAe,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import DataAccessLayer from './lib/data-access-layer.js';
|
|
2
|
+
import Errors from './lib/errors.js';
|
|
3
|
+
import mlString from './lib/ml-string.js';
|
|
4
|
+
import Model from './lib/model.js';
|
|
5
|
+
import QueryBuilder from './lib/query-builder.js';
|
|
6
|
+
import revision from './lib/revision.js';
|
|
7
|
+
import { setDebugLogger, setLanguageProvider, setRevisionSummaryEnabled } from './lib/runtime.js';
|
|
8
|
+
import types from './lib/type.js';
|
|
9
|
+
const DataAccessLayerCtor = DataAccessLayer;
|
|
10
|
+
/**
|
|
11
|
+
* Create a PostgreSQL Data Access Layer (DAL) instance.
|
|
12
|
+
*
|
|
13
|
+
* @param config Optional PostgreSQL configuration overrides used to initialize the DAL instance.
|
|
14
|
+
* @returns A ready-to-use DAL instance bound to the provided configuration.
|
|
15
|
+
*/
|
|
16
|
+
const createDataAccessLayer = ((config) => new DataAccessLayerCtor(config));
|
|
17
|
+
createDataAccessLayer.DataAccessLayer = DataAccessLayerCtor;
|
|
18
|
+
createDataAccessLayer.Model = Model;
|
|
19
|
+
createDataAccessLayer.QueryBuilder = QueryBuilder;
|
|
20
|
+
createDataAccessLayer.types = types;
|
|
21
|
+
createDataAccessLayer.Errors = Errors;
|
|
22
|
+
createDataAccessLayer.mlString = mlString;
|
|
23
|
+
createDataAccessLayer.revision = revision;
|
|
24
|
+
export { DataAccessLayer, Model, QueryBuilder, types, Errors, mlString, revision, setLanguageProvider, setDebugLogger, setRevisionSummaryEnabled, createDataAccessLayer, };
|
|
25
|
+
export default createDataAccessLayer;
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,4BAA4B,CAAC;AACzD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAGnC,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,KAAK,MAAM,eAAe,CAAC;AAmBlC,MAAM,mBAAmB,GAAG,eAAkD,CAAC;AAY/E;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAgC,EAAE,EAAE,CAClE,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAA0B,CAAC;AAE5D,qBAAqB,CAAC,eAAe,GAAG,mBAAmB,CAAC;AAC5D,qBAAqB,CAAC,KAAK,GAAG,KAAK,CAAC;AACpC,qBAAqB,CAAC,YAAY,GAAG,YAAY,CAAC;AAClD,qBAAqB,CAAC,KAAK,GAAG,KAAK,CAAC;AACpC,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC;AACtC,qBAAqB,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC1C,qBAAqB,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAE1C,OAAO,EACL,eAAe,EACf,KAAK,EACL,YAAY,EACZ,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzB,qBAAqB,GACtB,CAAC;AAMF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-copy a row value so the copy shares no mutable state with the
|
|
3
|
+
* original, while keeping every type `pg` serializes differently:
|
|
4
|
+
*
|
|
5
|
+
* - primitives, `null`, `undefined` and functions are returned as-is
|
|
6
|
+
* - `Date` → new `Date`; `Buffer` → new `Buffer`; other typed arrays and
|
|
7
|
+
* `DataView`s → copies of the same class
|
|
8
|
+
* - arrays, `Map` and `Set` → new containers with copied contents
|
|
9
|
+
* - other objects → a copy with the same prototype and copied own
|
|
10
|
+
* properties, so plain JSON objects stay plain and class instances keep
|
|
11
|
+
* methods such as `toJSON()` / `toPostgres()` that `pg` relies on
|
|
12
|
+
*
|
|
13
|
+
* `structuredClone` is not used because it turns a `Buffer` into a plain
|
|
14
|
+
* `Uint8Array`, drops prototypes, and throws on functions.
|
|
15
|
+
*
|
|
16
|
+
* Cycles are preserved. Objects whose state lives in internal slots or
|
|
17
|
+
* `#private` fields (other than the built-ins handled above) cannot be copied
|
|
18
|
+
* faithfully by any generic routine; they don't come out of PostgreSQL rows.
|
|
19
|
+
*
|
|
20
|
+
* @param value Value to copy
|
|
21
|
+
* @returns An independent copy of `value`
|
|
22
|
+
*/
|
|
23
|
+
export declare function cloneRowValue<T>(value: T): T;
|
|
24
|
+
//# sourceMappingURL=clone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/lib/clone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAE5C"}
|